django_coreprotect/models.py

374 lines
10 KiB
Python

from django.db import models
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 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 self.action == 0 else "Block Place" if self.action == 1 else "Interact/Used"
if self.type == "chat":
return "Chat"
if self.type == "container":
return "Took from Container" if self.action == 0 else "Placed in Container"
if self.type == "command":
return "Command"
if self.type == "session":
return "Logout" if 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)