Skip to content

Commit

Permalink
feat: wip definition of models for new server management
Browse files Browse the repository at this point in the history
  • Loading branch information
corp-0 committed Sep 20, 2024
1 parent 3509ace commit 54eba5e
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions src/server/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import secrets
import string

from django.db import models
from django.db.models.signals import pre_save
Expand All @@ -9,30 +8,34 @@


class CodeScanInformation(models.Model):
"""Information regarding the CodeScan that will be used to scan the code for this build after downloading on clients"""

version = models.TextField(primary_key=True)

def __str__(self):
return self.version


def generate_listing_key():
alphabet = string.ascii_letters + string.digits + "-_"
return "".join(secrets.choice(alphabet) for _ in range(30))
# 22 bytes produce 30 characters
return secrets.token_urlsafe(22)


class ServerInformation(models.Model):
"""Basic information that describes and identifies a server"""

owner = models.ForeignKey(
verbose_name="Owner",
to=Account,
on_delete=models.CASCADE,
help_text="Who created and/or is responsible for this server",
)
name = models.TextField(
name = models.CharField(
verbose_name="Name",
max_length=50,
help_text="Name this server uses to present itself in the servers list",
)
description = models.TextField(
description = models.CharField(
verbose_name="Description",
max_length=200,
help_text="A brief description of what this server is about",
Expand All @@ -47,9 +50,10 @@ class ServerInformation(models.Model):
blank=True,
help_text="The rules that players must follow on this server",
)
motd = models.TextField(
motd = models.CharField(
verbose_name="Message of the Day (MOTD)",
help_text="Message displayed to players when they join the server",
max_length=255,
)
is_18_plus = models.BooleanField(
verbose_name="18+",
Expand All @@ -66,18 +70,20 @@ class ServerInformation(models.Model):
verbose_name="Is Delisted",
help_text="Indicates if this server is delisted from the servers list",
)
listing_key = models.TextField(
listing_key = models.CharField(
unique=True,
verbose_name="Listing Key",
null=True,
blank=True,
max_length=30,
help_text="A unique key used for listing this server. Do not lose this key!",
)

def __str__(self):
return f"Server: {self.name} by: {self.owner.unique_identifier}"


# Binds the save event of ServerInformation model to this function so that the key is generated every time a new ServerInformation is created
@receiver(pre_save, sender=ServerInformation)
def set_listing_key(sender, instance: ServerInformation, **kwargs):
if not instance.listing_key:
Expand All @@ -89,28 +95,39 @@ def set_listing_key(sender, instance: ServerInformation, **kwargs):
unique_key_found = True


# class ServerStatus(models.Model):
# server = models.ForeignKey(
# ServerInformation, related_name="status", on_delete=models.CASCADE
# )
# is_passworded = models.BooleanField()
# fork_name = models.TextField()
# build_version = models.TextField()
# current_map = models.TextField()
# game_mode = models.TextField()
# ingame_time = models.TextField()
# round_time = models.TextField()
# player_count = models.PositiveSmallIntegerField()
# player_count_max = models.PositiveSmallIntegerField()
# ip = models.TextField()
# port = models.PositiveSmallIntegerField()
# windows_download = models.URLField()
# osx_download = models.URLField()
# linux_download = models.URLField()
# fps = models.PositiveSmallIntegerField()
class ServerTag(models.Model):
"""Represents an individual tag a server could have attached to it to make them easier to find by categories"""

server = models.ForeignKey(to=ServerInformation, related_name="tags", on_delete=models.CASCADE)
name = models.TextField(verbose_name="Name", max_length=50)

# class ServerStatus(models.Model):
# server = models.ForeignKey(
# ServerInformation, related_name="status", on_delete=models.CASCADE
# )
# is_passworded = models.BooleanField()
# fork_name = models.TextField()
# build_version = models.TextField()
# current_map = models.TextField()
# game_mode = models.TextField()
# ingame_time = models.TextField()
# round_time = models.TextField()
# player_count = models.PositiveSmallIntegerField()
# player_count_max = models.PositiveSmallIntegerField()
# ip = models.TextField()
# port = models.PositiveSmallIntegerField()
# windows_download = models.URLField()
# osx_download = models.URLField()
# linux_download = models.URLField()
# fps = models.PositiveSmallIntegerField()

def __str__(self) -> str:
return self.name


class AccountModerationInfo(models.Model):
"""Information an account has permanently attached to it for the purpose of moderating their behaviour on the hub"""

account = models.OneToOneField(to=Account, related_name="moderation_info", on_delete=models.CASCADE)
can_create_servers = models.BooleanField(default=True)
can_list_servers = models.BooleanField(default=True)
Expand All @@ -120,6 +137,8 @@ def __str__(self):


class ServerAdmonition(models.Model):
"""Represents a warning or reprimand an account received for their misbehaviour or mismanagement of their server"""

SEVERITY_LEVELS = [
("low", "Low"),
("medium", "Medium"),
Expand Down

0 comments on commit 54eba5e

Please sign in to comment.