1
1
import secrets
2
- import string
3
2
4
3
from django .db import models
5
4
from django .db .models .signals import pre_save
9
8
10
9
11
10
class CodeScanInformation (models .Model ):
11
+ """Information regarding the CodeScan that will be used to scan the code for this build after downloading on clients"""
12
+
12
13
version = models .TextField (primary_key = True )
13
14
14
15
def __str__ (self ):
15
16
return self .version
16
17
17
18
18
19
def generate_listing_key ():
19
- alphabet = string . ascii_letters + string . digits + "-_"
20
- return "" . join ( secrets .choice ( alphabet ) for _ in range ( 30 ) )
20
+ # 22 bytes produce 30 characters
21
+ return secrets .token_urlsafe ( 22 )
21
22
22
23
23
24
class ServerInformation (models .Model ):
25
+ """Basic information that describes and identifies a server"""
26
+
24
27
owner = models .ForeignKey (
25
28
verbose_name = "Owner" ,
26
29
to = Account ,
27
30
on_delete = models .CASCADE ,
28
31
help_text = "Who created and/or is responsible for this server" ,
29
32
)
30
- name = models .TextField (
33
+ name = models .CharField (
31
34
verbose_name = "Name" ,
32
35
max_length = 50 ,
33
36
help_text = "Name this server uses to present itself in the servers list" ,
34
37
)
35
- description = models .TextField (
38
+ description = models .CharField (
36
39
verbose_name = "Description" ,
37
40
max_length = 200 ,
38
41
help_text = "A brief description of what this server is about" ,
@@ -47,9 +50,10 @@ class ServerInformation(models.Model):
47
50
blank = True ,
48
51
help_text = "The rules that players must follow on this server" ,
49
52
)
50
- motd = models .TextField (
53
+ motd = models .CharField (
51
54
verbose_name = "Message of the Day (MOTD)" ,
52
55
help_text = "Message displayed to players when they join the server" ,
56
+ max_length = 255 ,
53
57
)
54
58
is_18_plus = models .BooleanField (
55
59
verbose_name = "18+" ,
@@ -66,18 +70,20 @@ class ServerInformation(models.Model):
66
70
verbose_name = "Is Delisted" ,
67
71
help_text = "Indicates if this server is delisted from the servers list" ,
68
72
)
69
- listing_key = models .TextField (
73
+ listing_key = models .CharField (
70
74
unique = True ,
71
75
verbose_name = "Listing Key" ,
72
76
null = True ,
73
77
blank = True ,
78
+ max_length = 30 ,
74
79
help_text = "A unique key used for listing this server. Do not lose this key!" ,
75
80
)
76
81
77
82
def __str__ (self ):
78
83
return f"Server: { self .name } by: { self .owner .unique_identifier } "
79
84
80
85
86
+ # Binds the save event of ServerInformation model to this function so that the key is generated every time a new ServerInformation is created
81
87
@receiver (pre_save , sender = ServerInformation )
82
88
def set_listing_key (sender , instance : ServerInformation , ** kwargs ):
83
89
if not instance .listing_key :
@@ -89,28 +95,39 @@ def set_listing_key(sender, instance: ServerInformation, **kwargs):
89
95
unique_key_found = True
90
96
91
97
92
- # class ServerStatus(models.Model):
93
- # server = models.ForeignKey(
94
- # ServerInformation, related_name="status", on_delete=models.CASCADE
95
- # )
96
- # is_passworded = models.BooleanField()
97
- # fork_name = models.TextField()
98
- # build_version = models.TextField()
99
- # current_map = models.TextField()
100
- # game_mode = models.TextField()
101
- # ingame_time = models.TextField()
102
- # round_time = models.TextField()
103
- # player_count = models.PositiveSmallIntegerField()
104
- # player_count_max = models.PositiveSmallIntegerField()
105
- # ip = models.TextField()
106
- # port = models.PositiveSmallIntegerField()
107
- # windows_download = models.URLField()
108
- # osx_download = models.URLField()
109
- # linux_download = models.URLField()
110
- # fps = models.PositiveSmallIntegerField()
98
+ class ServerTag (models .Model ):
99
+ """Represents an individual tag a server could have attached to it to make them easier to find by categories"""
100
+
101
+ server = models .ForeignKey (to = ServerInformation , related_name = "tags" , on_delete = models .CASCADE )
102
+ name = models .TextField (verbose_name = "Name" , max_length = 50 )
103
+
104
+ # class ServerStatus(models.Model):
105
+ # server = models.ForeignKey(
106
+ # ServerInformation, related_name="status", on_delete=models.CASCADE
107
+ # )
108
+ # is_passworded = models.BooleanField()
109
+ # fork_name = models.TextField()
110
+ # build_version = models.TextField()
111
+ # current_map = models.TextField()
112
+ # game_mode = models.TextField()
113
+ # ingame_time = models.TextField()
114
+ # round_time = models.TextField()
115
+ # player_count = models.PositiveSmallIntegerField()
116
+ # player_count_max = models.PositiveSmallIntegerField()
117
+ # ip = models.TextField()
118
+ # port = models.PositiveSmallIntegerField()
119
+ # windows_download = models.URLField()
120
+ # osx_download = models.URLField()
121
+ # linux_download = models.URLField()
122
+ # fps = models.PositiveSmallIntegerField()
123
+
124
+ def __str__ (self ) -> str :
125
+ return self .name
111
126
112
127
113
128
class AccountModerationInfo (models .Model ):
129
+ """Information an account has permanently attached to it for the purpose of moderating their behaviour on the hub"""
130
+
114
131
account = models .OneToOneField (to = Account , related_name = "moderation_info" , on_delete = models .CASCADE )
115
132
can_create_servers = models .BooleanField (default = True )
116
133
can_list_servers = models .BooleanField (default = True )
@@ -120,6 +137,8 @@ def __str__(self):
120
137
121
138
122
139
class ServerAdmonition (models .Model ):
140
+ """Represents a warning or reprimand an account received for their misbehaviour or mismanagement of their server"""
141
+
123
142
SEVERITY_LEVELS = [
124
143
("low" , "Low" ),
125
144
("medium" , "Medium" ),
0 commit comments