2020-06-20 20:03:06 +02:00
|
|
|
from datetime import datetime
|
|
|
|
from uuid import UUID, uuid4
|
|
|
|
from pony.orm import *
|
|
|
|
|
|
|
|
db = Database()
|
|
|
|
|
2020-08-18 01:18:37 +02:00
|
|
|
STATE_QUEUED = 0
|
|
|
|
STATE_STARTED = 1
|
|
|
|
STATE_ERROR = -1
|
|
|
|
|
2020-06-20 20:03:06 +02:00
|
|
|
|
|
|
|
class Patch(db.Entity):
|
|
|
|
id = PrimaryKey(int, auto=True)
|
2020-10-26 00:04:58 +01:00
|
|
|
player_id = Required(int)
|
|
|
|
player_name = Required(str, 16)
|
|
|
|
data = Required(bytes, lazy=True)
|
2020-06-26 19:29:33 +02:00
|
|
|
seed = Optional('Seed')
|
2020-06-20 20:03:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Room(db.Entity):
|
2020-06-26 19:29:33 +02:00
|
|
|
id = PrimaryKey(UUID, default=uuid4)
|
2020-06-24 08:52:02 +02:00
|
|
|
last_activity = Required(datetime, default=lambda: datetime.utcnow(), index=True)
|
2020-06-26 19:29:33 +02:00
|
|
|
creation_time = Required(datetime, default=lambda: datetime.utcnow())
|
2020-06-24 08:52:02 +02:00
|
|
|
owner = Required(UUID, index=True)
|
2020-06-20 20:03:06 +02:00
|
|
|
commands = Set('Command')
|
2020-06-24 08:52:02 +02:00
|
|
|
seed = Required('Seed', index=True)
|
2020-10-26 00:04:58 +01:00
|
|
|
multisave = Optional(buffer, lazy=True)
|
2020-06-26 19:29:33 +02:00
|
|
|
show_spoiler = Required(int, default=0) # 0 -> never, 1 -> after completion, -> 2 always
|
2020-07-10 17:42:22 +02:00
|
|
|
timeout = Required(int, default=lambda: 6 * 60 * 60) # seconds since last activity to shutdown
|
2020-06-26 19:29:33 +02:00
|
|
|
tracker = Optional(UUID, index=True)
|
2020-06-21 15:32:31 +02:00
|
|
|
last_port = Optional(int, default=lambda: 0)
|
2020-06-20 20:03:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Seed(db.Entity):
|
2020-06-26 19:29:33 +02:00
|
|
|
id = PrimaryKey(UUID, default=uuid4)
|
2020-06-20 20:03:06 +02:00
|
|
|
rooms = Set(Room)
|
2020-10-26 00:04:58 +01:00
|
|
|
multidata = Required(bytes, lazy=True)
|
2020-06-26 19:29:33 +02:00
|
|
|
owner = Required(UUID, index=True)
|
2020-06-20 20:03:06 +02:00
|
|
|
creation_time = Required(datetime, default=lambda: datetime.utcnow())
|
|
|
|
patches = Set(Patch)
|
2020-08-03 04:19:36 +02:00
|
|
|
spoiler = Optional(LongStr, lazy=True)
|
2020-10-26 00:04:58 +01:00
|
|
|
meta = Required(Json, lazy=True, default=lambda: {}) # additional meta information/tags
|
2020-06-20 20:03:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Command(db.Entity):
|
|
|
|
id = PrimaryKey(int, auto=True)
|
|
|
|
room = Required(Room)
|
|
|
|
commandtext = Required(str)
|
2020-08-18 01:18:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Generation(db.Entity):
|
|
|
|
id = PrimaryKey(UUID, default=uuid4)
|
|
|
|
owner = Required(UUID)
|
2021-01-03 14:32:32 +01:00
|
|
|
options = Required(Json, lazy=True)
|
|
|
|
meta = Required(Json, lazy=True)
|
2020-08-18 01:18:37 +02:00
|
|
|
state = Required(int, default=0, index=True)
|