add back games, conform them to new title dispatch

This commit is contained in:
Hay1tsme
2023-02-17 01:02:21 -05:00
parent f18e939dd0
commit 7e3396a7ff
214 changed files with 19412 additions and 23 deletions

View File

@ -1,4 +1,4 @@
from twisted.web import resource
from typing import Dict, Any
import logging, coloredlogs
from logging.handlers import TimedRotatingFileHandler
from twisted.web.http import Request
@ -13,6 +13,7 @@ class TitleServlet():
self.config = core_cfg
self.config_folder = cfg_folder
self.data = Data(core_cfg)
self.title_registry: Dict[str, Any] = {}
self.logger = logging.getLogger("title")
if not hasattr(self.logger, "initialized"):
@ -34,9 +35,32 @@ class TitleServlet():
if "game_registry" not in globals():
globals()["game_registry"] = Utils.get_all_titles()
for folder, mod in globals()["game_registry"].items():
if hasattr(mod, "game_codes") and hasattr(mod, "index"):
handler_cls = mod.index(self.config, self.config_folder)
if hasattr(handler_cls, "setup"):
handler_cls.setup()
for code in mod.game_codes:
self.title_registry[code] = handler_cls
else:
self.logger.error(f"{folder} missing game_code or index in __init__.py")
self.logger.info(f"Serving {len(globals()['game_registry'])} game codes")
def render_GET(self, request: Request, endpoints: dict) -> bytes:
print(endpoints)
def handle_GET(self, request: Request):
pass
def handle_POST(self, request: Request):
pass
def render_POST(self, request: Request, endpoints: dict) -> bytes:
print(endpoints)
code = endpoints["game"]
if code not in self.title_registry:
self.logger.warn(f"Unknown game code {code}")
index = self.title_registry[code]
if not hasattr(index, "render_POST"):
self.logger.warn(f"{code} does not dispatch on POST")
return index.render_POST(request, endpoints["version"], endpoints["endpoint"])

View File

@ -18,4 +18,5 @@ class Utils:
except ImportError as e:
print(f"{dir} - {e}")
raise
return ret