58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from datetime import datetime
 | |
| from uuid import UUID, uuid4
 | |
| from pony.orm import *
 | |
| 
 | |
| db = Database()
 | |
| 
 | |
| STATE_QUEUED = 0
 | |
| STATE_STARTED = 1
 | |
| STATE_ERROR = -1
 | |
| 
 | |
| 
 | |
| class Slot(db.Entity):
 | |
|     id = PrimaryKey(int, auto=True)
 | |
|     player_id = Required(int)
 | |
|     player_name = Required(str, 16)
 | |
|     data = Optional(bytes, lazy=True)
 | |
|     seed = Optional('Seed')
 | |
|     game = Required(str)
 | |
| 
 | |
| 
 | |
| class Room(db.Entity):
 | |
|     id = PrimaryKey(UUID, default=uuid4)
 | |
|     last_activity = Required(datetime, default=lambda: datetime.utcnow(), index=True)
 | |
|     creation_time = Required(datetime, default=lambda: datetime.utcnow())
 | |
|     owner = Required(UUID, index=True)
 | |
|     commands = Set('Command')
 | |
|     seed = Required('Seed', index=True)
 | |
|     multisave = Optional(buffer, lazy=True)
 | |
|     show_spoiler = Required(int, default=0)  # 0 -> never, 1 -> after completion, -> 2 always
 | |
|     timeout = Required(int, default=lambda: 6 * 60 * 60)  # seconds since last activity to shutdown
 | |
|     tracker = Optional(UUID, index=True)
 | |
|     last_port = Optional(int, default=lambda: 0)
 | |
| 
 | |
| 
 | |
| class Seed(db.Entity):
 | |
|     id = PrimaryKey(UUID, default=uuid4)
 | |
|     rooms = Set(Room)
 | |
|     multidata = Required(bytes, lazy=True)
 | |
|     owner = Required(UUID, index=True)
 | |
|     creation_time = Required(datetime, default=lambda: datetime.utcnow())
 | |
|     slots = Set(Slot)
 | |
|     spoiler = Optional(LongStr, lazy=True)
 | |
|     meta = Required(str, default=lambda: "{\"race\": false}")  # additional meta information/tags
 | |
| 
 | |
| 
 | |
| class Command(db.Entity):
 | |
|     id = PrimaryKey(int, auto=True)
 | |
|     room = Required(Room)
 | |
|     commandtext = Required(str)
 | |
| 
 | |
| 
 | |
| class Generation(db.Entity):
 | |
|     id = PrimaryKey(UUID, default=uuid4)
 | |
|     owner = Required(UUID)
 | |
|     options = Required(buffer, lazy=True)
 | |
|     meta = Required(str, default=lambda: "{\"race\": false}")
 | |
|     state = Required(int, default=0, index=True)
 | 
