3
2
forked from Dniel97/artemis

change how allnet uri/host is generated

This commit is contained in:
Hay1tsme 2023-03-04 21:27:52 -05:00
parent f5d4f519d3
commit a340bcf1dd
7 changed files with 101 additions and 59 deletions

View File

@ -48,49 +48,58 @@ class AllnetServlet:
self.logger.error("No games detected!") self.logger.error("No games detected!")
for _, mod in plugins.items(): for _, mod in plugins.items():
for code in mod.game_codes: if hasattr(mod.index, "get_allnet_info"):
if hasattr(mod, "use_default_title") and mod.use_default_title: for code in mod.game_codes:
if hasattr(mod, "include_protocol") and mod.include_protocol: enabled, uri, host = mod.index.get_allnet_info(code, self.config, self.config_folder)
if hasattr(mod, "title_secure") and mod.title_secure:
uri = "https://" if enabled:
self.uri_registry[code] = (uri, host)
else:
for code in mod.game_codes:
if hasattr(mod, "use_default_title") and mod.use_default_title:
if hasattr(mod, "include_protocol") and mod.include_protocol:
if hasattr(mod, "title_secure") and mod.title_secure:
uri = "https://"
else:
uri = "http://"
else:
uri = ""
if core_cfg.server.is_develop:
uri += f"{core_cfg.title.hostname}:{core_cfg.title.port}"
else: else:
uri = "http://" uri += f"{core_cfg.title.hostname}"
uri += f"/{code}/$v"
else: if hasattr(mod, "trailing_slash") and mod.trailing_slash:
uri = "" uri += "/"
if core_cfg.server.is_develop:
uri += f"{core_cfg.title.hostname}:{core_cfg.title.port}"
else: else:
uri += f"{core_cfg.title.hostname}" if hasattr(mod, "uri"):
uri = mod.uri
uri += f"/{code}/$v" else:
uri = ""
if hasattr(mod, "trailing_slash") and mod.trailing_slash: if hasattr(mod, "host"):
uri += "/" host = mod.host
else: elif hasattr(mod, "use_default_host") and mod.use_default_host:
if hasattr(mod, "uri"): if core_cfg.server.is_develop:
uri = mod.uri host = f"{core_cfg.title.hostname}:{core_cfg.title.port}"
else:
uri = "" else:
host = f"{core_cfg.title.hostname}"
if hasattr(mod, "host"):
host = mod.host
elif hasattr(mod, "use_default_host") and mod.use_default_host:
if core_cfg.server.is_develop:
host = f"{core_cfg.title.hostname}:{core_cfg.title.port}"
else: else:
host = f"{core_cfg.title.hostname}" host = ""
else: self.uri_registry[code] = (uri, host)
host = ""
self.uri_registry[code] = (uri, host)
self.logger.info(f"Allnet serving {len(self.uri_registry)} games on port {core_cfg.allnet.port}") self.logger.info(f"Allnet serving {len(self.uri_registry)} games on port {core_cfg.allnet.port}")
def handle_poweron(self, request: Request, _: Dict): def handle_poweron(self, request: Request, _: Dict):

View File

@ -37,16 +37,26 @@ class TitleServlet():
for folder, mod in plugins.items(): for folder, mod in plugins.items():
if hasattr(mod, "game_codes") and hasattr(mod, "index"): if hasattr(mod, "game_codes") and hasattr(mod, "index"):
handler_cls = mod.index(self.config, self.config_folder) should_call_setup = True
if hasattr(handler_cls, "setup"):
handler_cls.setup()
for code in mod.game_codes: for code in mod.game_codes:
self.title_registry[code] = handler_cls if hasattr(mod.index, "get_allnet_info"):
enabled, _, _ = mod.index.get_allnet_info(code, self.config, self.config_folder)
else:
enabled = True
if enabled:
handler_cls = mod.index(self.config, self.config_folder)
if hasattr(handler_cls, "setup") and should_call_setup:
handler_cls.setup()
should_call_setup = False
self.title_registry[code] = handler_cls
else: else:
self.logger.error(f"{folder} missing game_code or index in __init__.py") self.logger.error(f"{folder} missing game_code or index in __init__.py")
self.logger.info(f"Serving {len(self.title_registry)} game codes on port {core_cfg.title.port}") self.logger.info(f"Serving {len(self.title_registry)} game codes on port {core_cfg.title.port}")
def render_GET(self, request: Request, endpoints: dict) -> bytes: def render_GET(self, request: Request, endpoints: dict) -> bytes:

View File

@ -1,7 +1,11 @@
server: server:
hostname: "localhost"
enable: True enable: True
loglevel: "info" loglevel: "info"
port: 9000 port: 9000
port_matching: 9001 port_matching: 9001
port_stun: 9002
port_turn: 9003
port_admission: 9004
ssl_cert: cert/pokken.crt ssl_cert: cert/pokken.crt
ssl_key: cert/pokken.key ssl_key: cert/pokken.key

View File

@ -4,16 +4,5 @@ from titles.pokken.database import PokkenData
index = PokkenServlet index = PokkenServlet
database = PokkenData database = PokkenData
use_default_title = True
include_protocol = True
title_secure = True
game_codes = [PokkenConstants.GAME_CODE] game_codes = [PokkenConstants.GAME_CODE]
trailing_slash = True
use_default_host = False
include_port = True
uri="https://$h:$p/"
host="$h:$p/"
current_schema_version = 1 current_schema_version = 1

View File

@ -35,19 +35,19 @@ class PokkenBase():
regist_pcb.server_time = int(datetime.now().timestamp() / 1000) regist_pcb.server_time = int(datetime.now().timestamp() / 1000)
biwa_setting = { biwa_setting = {
"MatchingServer": { "MatchingServer": {
"host": f"https://{self.core_cfg.title.hostname}", "host": f"https://{self.game_cfg.server.hostname}",
"port": 9000, "port": self.game_cfg.server.port_matching,
"url": "/matching" "url": "/matching"
}, },
"StunServer": { "StunServer": {
"addr": self.core_cfg.title.hostname, "addr": self.game_cfg.server.hostname,
"port": 3333 "port": self.game_cfg.server.port_stun
}, },
"TurnServer": { "TurnServer": {
"addr": self.core_cfg.title.hostname, "addr": self.game_cfg.server.hostname,
"port": 4444 "port": self.game_cfg.server.port_turn
}, },
"AdmissionUrl": f"ws://{self.core_cfg.title.hostname}:1111", "AdmissionUrl": f"ws://{self.game_cfg.server.hostname}:{self.game_cfg.server.port_admission}",
"locationId": 123, "locationId": 123,
"logfilename": "JackalMatchingLibrary.log", "logfilename": "JackalMatchingLibrary.log",
"biwalogfilename": "./biwa.log" "biwalogfilename": "./biwa.log"

View File

@ -4,6 +4,10 @@ class PokkenServerConfig():
def __init__(self, parent_config: "PokkenConfig"): def __init__(self, parent_config: "PokkenConfig"):
self.__config = parent_config self.__config = parent_config
@property
def hostname(self) -> str:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'hostname', default="localhost")
@property @property
def enable(self) -> bool: def enable(self) -> bool:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'enable', default=True) return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'enable', default=True)
@ -18,7 +22,19 @@ class PokkenServerConfig():
@property @property
def port_matching(self) -> int: def port_matching(self) -> int:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'port', default=9001) return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'port_matching', default=9001)
@property
def port_stun(self) -> int:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'port_stun', default=9002)
@property
def port_turn(self) -> int:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'port_turn', default=9003)
@property
def port_admission(self) -> int:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'port_admission', default=9004)
@property @property
def ssl_cert(self) -> str: def ssl_cert(self) -> str:

View File

@ -1,3 +1,4 @@
from typing import Tuple
from twisted.web.http import Request from twisted.web.http import Request
from twisted.web import resource, server from twisted.web import resource, server
from twisted.internet import reactor, endpoints from twisted.internet import reactor, endpoints
@ -40,6 +41,19 @@ class PokkenServlet(resource.Resource):
self.logger.inited = True self.logger.inited = True
self.base = PokkenBase(core_cfg, self.game_cfg) self.base = PokkenBase(core_cfg, self.game_cfg)
@classmethod
def get_allnet_info(cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str) -> Tuple[bool, str, str]:
game_cfg = PokkenConfig()
game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/pokken.yaml")))
if not game_cfg.server.enable:
return (False, "", "")
if core_cfg.server.is_develop:
return (True, f"https://{game_cfg.server.hostname}:{game_cfg.server.port}/{game_code}/$v/", f"{game_cfg.server.hostname}:{game_cfg.server.port}/")
return (True, f"https://{game_cfg.server.hostname}/{game_code}/$v/", f"{game_cfg.server.hostname}/")
def setup(self): def setup(self):
""" """