from django.db import models class Game(models.Model): name = models.CharField(max_length=255) friendly_name = models.CharField(max_length=255) command_line = models.CharField(max_length=255, null=True, blank=True) description = models.TextField(null=True, blank=True) def __str__(self): return self.friendly_name class Server(models.Model): game = models.ForeignKey(Game, on_delete=models.CASCADE) port = models.IntegerField() game_type = models.CharField(max_length=255) mod = models.ForeignKey('Mod', on_delete=models.CASCADE) players = models.ManyToManyField('Player') spawned_at_utc = models.DateTimeField(auto_now_add=True) last_collection_utc = models.DateTimeField(null=True, blank=True) last_heartbeat_utc = models.DateTimeField(null=True, blank=True) process_id = models.IntegerField(null=True) port = models.IntegerField(default=69) is_started = models.BooleanField(default=False) is_private = models.BooleanField(default=False) current_players = models.IntegerField(default=0) maximum_players = models.IntegerField(default=0) container_id = models.CharField(max_length=255, null=True, blank=True) class Player(models.Model): name = models.CharField(max_length=255) score = models.IntegerField(default=0) class Mod(models.Model): name = models.CharField(max_length=255) friendly_name = models.CharField(max_length=255) command_line = models.CharField(max_length=255, null=True, blank=True) class SpawnedServerInfo(models.Model): process_id = models.IntegerField() port = models.IntegerField() mod = models.ForeignKey('Mod', on_delete=models.CASCADE) class StateResponse(models.Model): servers = models.ManyToManyField('Server') man_minutes_played = models.IntegerField() running_since_utc = models.DateTimeField() class State(models.Model): servers = models.ManyToManyField('Server') created_at_utc = models.DateTimeField(auto_now_add=True) playtime = models.DurationField(default='00:00:00') def increase_playtime(self, time_to_add): self.playtime += time_to_add