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 feed727
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 93 deletions.
10 changes: 3 additions & 7 deletions dev-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ services:
ports:
- "5432:5432"

redis:
image: redis:7.2.5-alpine
memcached:
image: memcached:1.6-alpine
ports:
- "6379:6379"
environment:
REDIS_PORT: 6379
- "11211:11211"

web:
depends_on:
Expand All @@ -30,5 +28,3 @@ services:

volumes:
db-data:
static-volume:
media-volume:
6 changes: 2 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ services:
volumes:
- db-data:/var/lib/postgresql/data

redis:
image: redis:7.2.5-alpine
environment:
REDIS_PORT: 6379
memcached:
image: memcached:1.6-alpine

web:
image: unitystation/central-command:latest
Expand Down
3 changes: 2 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ DB_ENGINE=django.db.backends.postgresql
DB_NAME=postgres
DB_HOST=db
DB_PORT=5432
REDIS_HOST=redis
MEMCACHED_LOCATION=127.0.0.1
MEMCACHED_PORT=11211

# Links to stuff
WEBSITE_URL = http://localhost:8000
Expand Down
60 changes: 12 additions & 48 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ python-dotenv = "^0.19.2"
whitenoise = "^6.2.0"
django-post-office = "^3.8.0"
drf-spectacular = "^0.27.1"
django-redis = "^5.4.0"
pymemcache = "^4.0.0"

[tool.poetry.group.lint.dependencies]
pre-commit = "3.*"
Expand Down
10 changes: 4 additions & 6 deletions src/central_command/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@
}
}

REDIS_LOCATION = f"redis://{os.environ.get('REDIS_HOST')}:6379/1"
MEMCACHED_HOST = os.environ.get("MEMCACHED_HOST", "127.0.0.1")
MEMCACHED_PORT = os.environ.get("MEMCACHED_PORT", 11211)

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": REDIS_LOCATION,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache",
"LOCATION": f"{MEMCACHED_HOST}:{MEMCACHED_PORT}",
}
}

Expand Down
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 feed727

Please sign in to comment.