from django.db import models from django.db.models import Q from django.shortcuts import reverse from django.contrib.auth.models import User from datetime import datetime from django_coreprotect.utils import safe_int class CoreProtectUser(User): class Meta: proxy = True permissions = ( ('gui', 'Can use CoreProtect GUI'), ('gui_extra', 'Can search Chat/Commands'), ('activity', 'Can use CoreProtect Activity Monitor'), ) class CoArtMap(models.Model): id = models.IntegerField(primary_key=True) art = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_art_map' verbose_name = 'Art Map' verbose_name_plural = 'Art Maps' def __str__(self): return self.art class CoBlock(models.Model): time = models.IntegerField(blank=True, null=True) user = models.IntegerField(blank=True, null=True) wid = models.IntegerField(blank=True, null=True) x = models.IntegerField(blank=True, null=True) y = models.IntegerField(blank=True, null=True) z = models.IntegerField(blank=True, null=True) type = models.IntegerField(blank=True, null=True) data = models.IntegerField(blank=True, null=True) meta = models.BinaryField(blank=True, null=True) blockdata = models.BinaryField(blank=True, null=True) action = models.IntegerField(blank=True, null=True) rolled_back = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'co_block' verbose_name = 'Block' verbose_name_plural = 'Blocks' def __str__(self): return self.type class CoBlockdataMap(models.Model): id = models.IntegerField(primary_key=True) data = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_blockdata_map' verbose_name = 'BlockData Map' verbose_name_plural = 'BlockData Maps' def __str__(self): return self.data class CoChat(models.Model): time = models.IntegerField(blank=True, null=True) user = models.IntegerField(blank=True, null=True) message = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_chat' verbose_name = 'Chat Message' verbose_name_plural = 'Chat Messages' def __str__(self): return self.message class CoCommand(models.Model): time = models.IntegerField(blank=True, null=True) user = models.IntegerField(blank=True, null=True) message = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_command' verbose_name = 'Command' verbose_name_plural = 'Commands' def __str__(self): return self.message class CoContainer(models.Model): time = models.IntegerField(blank=True, null=True) user = models.IntegerField(blank=True, null=True) wid = models.IntegerField(blank=True, null=True) x = models.IntegerField(blank=True, null=True) y = models.IntegerField(blank=True, null=True) z = models.IntegerField(blank=True, null=True) type = models.IntegerField(blank=True, null=True) data = models.IntegerField(blank=True, null=True) amount = models.IntegerField(blank=True, null=True) metadata = models.BinaryField(blank=True, null=True) action = models.IntegerField(blank=True, null=True) rolled_back = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'co_container' verbose_name = 'Container Transaction' verbose_name_plural = 'Container Transactions' def __str__(self): return self.user class CoDatabaseLock(models.Model): status = models.IntegerField(blank=True, null=True) time = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'co_database_lock' verbose_name = 'Database Lock' verbose_name_plural = 'Database Locks' def __str__(self): return self.status class CoEntity(models.Model): time = models.IntegerField(blank=True, null=True) data = models.BinaryField(blank=True, null=True) class Meta: managed = False db_table = 'co_entity' verbose_name = 'Entity' verbose_name_plural = 'Entities' def __str__(self): return self.time class CoEntityMap(models.Model): id = models.IntegerField(primary_key=True) entity = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_entity_map' verbose_name = 'Entity Mapping' verbose_name_plural = 'Entity Mappings' def __str__(self): return self.entity class CoMaterialMap(models.Model): id = models.IntegerField(primary_key=True) material = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_material_map' verbose_name = 'Material Mapping' verbose_name_plural = 'Material Mappings' def __str__(self): return self.material class CoSession(models.Model): time = models.IntegerField(blank=True, null=True) user = models.IntegerField(blank=True, null=True) wid = models.IntegerField(blank=True, null=True) x = models.IntegerField(blank=True, null=True) y = models.IntegerField(blank=True, null=True) z = models.IntegerField(blank=True, null=True) action = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'co_session' verbose_name = 'Session' verbose_name_plural = 'Sessions' def __str__(self): return self.user class CoSign(models.Model): time = models.IntegerField(blank=True, null=True) user = models.IntegerField(blank=True, null=True) wid = models.IntegerField(blank=True, null=True) x = models.IntegerField(blank=True, null=True) y = models.IntegerField(blank=True, null=True) z = models.IntegerField(blank=True, null=True) color = models.IntegerField(blank=True, null=True) line_1 = models.TextField(blank=True, null=True) line_2 = models.TextField(blank=True, null=True) line_3 = models.TextField(blank=True, null=True) line_4 = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_sign' verbose_name = 'Sign' verbose_name_plural = 'Signs' def __str__(self): return "{} | {} | {} | {}".format(self.line_1, self.line_2, self.line_3, self.line_4) class CoSkull(models.Model): time = models.IntegerField(blank=True, null=True) owner = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_skull' verbose_name = 'Skull' verbose_name_plural = 'Skulls' def __str__(self): return self.owner class CoUser(models.Model): time = models.IntegerField(blank=True, null=True) user = models.TextField(blank=True, null=True) uuid = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_user' verbose_name = 'User' verbose_name_plural = 'Users' def __str__(self): return self.user class CoUsernameLog(models.Model): time = models.IntegerField(blank=True, null=True) uuid = models.TextField(blank=True, null=True) user = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_username_log' verbose_name = 'Username' verbose_name_plural = 'Usernames' def __str__(self): return self.user class CoVersion(models.Model): time = models.IntegerField(blank=True, null=True) version = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_version' verbose_name = 'Version' verbose_name_plural = 'Versions' def __str__(self): return self.version class CoWorld(models.Model): id = models.IntegerField(primary_key=True) world = models.TextField(blank=True, null=True) class Meta: managed = False db_table = 'co_world' verbose_name = 'World' verbose_name_plural = 'Worlds' def __str__(self): return self.world class Preset(models.Model): name = models.CharField(max_length=50) block_break = models.BooleanField(default=False) block_place = models.BooleanField(default=False) chat = models.BooleanField(default=False) chest_use = models.BooleanField(default=False) command = models.BooleanField(default=False) interact = models.BooleanField(default=False) login_logout = models.BooleanField(default=False) sign_place = models.BooleanField(default=False) worlds = models.CharField(max_length=20, default="", blank=True) ignore_environment = models.BooleanField(default=False) oldest_first = models.BooleanField(default=False) players = models.CharField(max_length=50, blank=True) x = models.CharField(max_length=10, default="", blank=True) y = models.CharField(max_length=10, default="", blank=True) z = models.CharField(max_length=10, default="", blank=True) radius = models.CharField(max_length=10, default="", blank=True) blocks = models.CharField(max_length=50, default="", blank=True) date_from = models.CharField(max_length=10, default="", blank=True) date_to = models.CharField(max_length=10, default="", blank=True) enabled = models.BooleanField(default=True) @property def link(self): url = reverse("coreprotect_gui") + "?" params = [] if self.block_break: params.append("block_break=on") if self.block_place: params.append("block_place=on") if self.chat: params.append("chat=on") if self.chest_use: params.append("chest_use=on") if self.command: params.append("command=on") if self.interact: params.append("interact=on") if self.login_logout: params.append("login_logout=on") if self.sign_place: params.append("sign_place=on") if self.worlds: params.append("world=" + self.worlds) if self.ignore_environment: params.append("ignore_environment=on") if self.oldest_first: params.append("oldest_first=on") if self.players: params.append("players=" + self.players) if self.x: params.append("x=" + self.x) if self.y: params.append("y=" + self.y) if self.z: params.append("z=" + self.z) if self.radius: params.append("radius=" + self.radius) if self.blocks: params.append("blocks=" + self.blocks) if self.date_from: params.append("date_from=" + self.date_from) if self.date_to: params.append("date_to=" + self.date_to) return url + "&".join(params) class GUIResult(models.Model): type = models.TextField() unix = models.TextField() player = models.TextField() action = models.TextField() data = models.TextField() x = models.TextField() y = models.TextField() z = models.TextField() world = models.TextField() @property def display_time(self): dt = datetime.fromtimestamp(float(self.unix)) return dt.strftime("%b %d, %Y at %I:%M:%S %p") @property def display_action(self): if self.type == "block": return "Block Break" if str(self.action) == "0" else "Block Place" if str(self.action) == "1" else "Interact/Used" if self.type == "chat": return "Chat" if self.type == "container": return "Took from Container" if str(self.action) == "0" else "Placed in Container" if self.type == "command": return "Command" if self.type == "session": return "Logout" if str(self.action) == "0" else "Login" if self.type == "sign": return "Sign" return self.action @property def display_data(self): def material_name(namespace): m = namespace.replace("minecraft:", "") pp = m.split("_") return " ".join([p.capitalize() for p in pp]) if self.type == "block": return material_name(self.data) if self.type == "container": parts = self.data.split() return "{} {}".format(parts[0], material_name(parts[1])) return self.data class Meta: managed = False verbose_name = "GUI Result" verbose_name_plural = "GUI Results" class SessionResult(models.Model): unix = models.TextField() player = models.TextField() action = models.TextField() class Meta: managed = False verbose_name = "Session Result" verbose_name_plural = "Session Results" class ActivityResult: def __init__(self, player, time): self.player = player self.time = time @property def time_display(self): time = safe_int(self.time) seconds = time % 60 time //= 60 minutes = time % 60 time //= 60 hours = time % 24 time //= 24 days = time return "{}d, {}h, {}m, {}s".format(days, hours, minutes, seconds)