11import secrets
2- import string
32
43from django .db import models
54from django .db .models .signals import pre_save
98
109
1110class CodeScanInformation (models .Model ):
11+ """Information regarding the CodeScan that will be used to scan the code for this build after downloading on clients"""
12+
1213 version = models .TextField (primary_key = True )
1314
1415 def __str__ (self ):
1516 return self .version
1617
1718
1819def 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 )
2122
2223
2324class ServerInformation (models .Model ):
25+ """Basic information that describes and identifies a server"""
26+
2427 owner = models .ForeignKey (
2528 verbose_name = "Owner" ,
2629 to = Account ,
2730 on_delete = models .CASCADE ,
2831 help_text = "Who created and/or is responsible for this server" ,
2932 )
30- name = models .TextField (
33+ name = models .CharField (
3134 verbose_name = "Name" ,
3235 max_length = 50 ,
3336 help_text = "Name this server uses to present itself in the servers list" ,
3437 )
35- description = models .TextField (
38+ description = models .CharField (
3639 verbose_name = "Description" ,
3740 max_length = 200 ,
3841 help_text = "A brief description of what this server is about" ,
@@ -47,9 +50,10 @@ class ServerInformation(models.Model):
4750 blank = True ,
4851 help_text = "The rules that players must follow on this server" ,
4952 )
50- motd = models .TextField (
53+ motd = models .CharField (
5154 verbose_name = "Message of the Day (MOTD)" ,
5255 help_text = "Message displayed to players when they join the server" ,
56+ max_length = 255 ,
5357 )
5458 is_18_plus = models .BooleanField (
5559 verbose_name = "18+" ,
@@ -66,18 +70,20 @@ class ServerInformation(models.Model):
6670 verbose_name = "Is Delisted" ,
6771 help_text = "Indicates if this server is delisted from the servers list" ,
6872 )
69- listing_key = models .TextField (
73+ listing_key = models .CharField (
7074 unique = True ,
7175 verbose_name = "Listing Key" ,
7276 null = True ,
7377 blank = True ,
78+ max_length = 30 ,
7479 help_text = "A unique key used for listing this server. Do not lose this key!" ,
7580 )
7681
7782 def __str__ (self ):
7883 return f"Server: { self .name } by: { self .owner .unique_identifier } "
7984
8085
86+ # Binds the save event of ServerInformation model to this function so that the key is generated every time a new ServerInformation is created
8187@receiver (pre_save , sender = ServerInformation )
8288def set_listing_key (sender , instance : ServerInformation , ** kwargs ):
8389 if not instance .listing_key :
@@ -89,28 +95,39 @@ def set_listing_key(sender, instance: ServerInformation, **kwargs):
8995 unique_key_found = True
9096
9197
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
111126
112127
113128class AccountModerationInfo (models .Model ):
129+ """Information an account has permanently attached to it for the purpose of moderating their behaviour on the hub"""
130+
114131 account = models .OneToOneField (to = Account , related_name = "moderation_info" , on_delete = models .CASCADE )
115132 can_create_servers = models .BooleanField (default = True )
116133 can_list_servers = models .BooleanField (default = True )
@@ -120,6 +137,8 @@ def __str__(self):
120137
121138
122139class ServerAdmonition (models .Model ):
140+ """Represents a warning or reprimand an account received for their misbehaviour or mismanagement of their server"""
141+
123142 SEVERITY_LEVELS = [
124143 ("low" , "Low" ),
125144 ("medium" , "Medium" ),
0 commit comments