2020-06-20 20:03:06 +02:00
|
|
|
from datetime import datetime
|
|
|
|
from uuid import UUID, uuid4
|
2022-10-17 01:08:31 +02:00
|
|
|
from pony.orm import Database, PrimaryKey, Required, Set, Optional, buffer, LongStr
|
2020-06-20 20:03:06 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-05-14 15:25:57 +02:00
|
|
|
class Slot(db.Entity):
|
2020-06-20 20:03:06 +02:00
|
|
|
id = PrimaryKey(int, auto=True)
|
2020-10-26 00:04:58 +01:00
|
|
|
player_id = Required(int)
|
2022-02-23 04:02:11 +01:00
|
|
|
player_name = Required(str)
|
2021-05-14 15:25:57 +02:00
|
|
|
data = Optional(bytes, lazy=True)
|
2020-06-26 19:29:33 +02:00
|
|
|
seed = Optional('Seed')
|
2021-05-14 15:25:57 +02:00
|
|
|
game = Required(str)
|
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)
|
2023-05-19 21:18:15 +02:00
|
|
|
creation_time = Required(datetime, default=lambda: datetime.utcnow(), index=True) # index used by landing page
|
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
|
2022-07-18 21:10:29 +02:00
|
|
|
timeout = Required(int, default=lambda: 2 * 60 * 60) # seconds since last activity to shutdown
|
2020-06-26 19:29:33 +02:00
|
|
|
tracker = Optional(UUID, index=True)
|
2022-11-04 19:19:04 +01:00
|
|
|
# Port special value -1 means the server errored out. Another attempt can be made with a page refresh
|
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)
|
2023-05-19 21:18:15 +02:00
|
|
|
creation_time = Required(datetime, default=lambda: datetime.utcnow(), index=True) # index used by landing page
|
2021-05-14 15:25:57 +02:00
|
|
|
slots = Set(Slot)
|
2020-08-03 04:19:36 +02:00
|
|
|
spoiler = Optional(LongStr, lazy=True)
|
2021-11-16 23:59:40 +01:00
|
|
|
meta = Required(LongStr, default=lambda: "{\"race\": false}") # 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-05-13 21:57:11 +02:00
|
|
|
options = Required(buffer, lazy=True)
|
2021-11-16 23:59:40 +01:00
|
|
|
meta = Required(LongStr, default=lambda: "{\"race\": false}")
|
2020-08-18 01:18:37 +02:00
|
|
|
state = Required(int, default=0, index=True)
|
2023-03-20 11:01:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
class GameDataPackage(db.Entity):
|
|
|
|
checksum = PrimaryKey(str)
|
|
|
|
data = Required(bytes)
|