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!")
for _, mod in plugins.items():
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://"
if hasattr(mod.index, "get_allnet_info"):
for code in mod.game_codes:
enabled, uri, host = mod.index.get_allnet_info(code, self.config, self.config_folder)
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 = "http://"
uri = ""
if core_cfg.server.is_develop:
uri += f"{core_cfg.title.hostname}:{core_cfg.title.port}"
else:
uri += f"{core_cfg.title.hostname}"
uri += f"/{code}/$v"
if hasattr(mod, "trailing_slash") and mod.trailing_slash:
uri += "/"
else:
uri = ""
if hasattr(mod, "uri"):
uri = mod.uri
else:
uri = ""
if core_cfg.server.is_develop:
uri += f"{core_cfg.title.hostname}:{core_cfg.title.port}"
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:
host = f"{core_cfg.title.hostname}"
else:
uri += f"{core_cfg.title.hostname}"
host = ""
uri += f"/{code}/$v"
self.uri_registry[code] = (uri, host)
if hasattr(mod, "trailing_slash") and mod.trailing_slash:
uri += "/"
else:
if hasattr(mod, "uri"):
uri = mod.uri
else:
uri = ""
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:
host = f"{core_cfg.title.hostname}"
else:
host = ""
self.uri_registry[code] = (uri, host)
self.logger.info(f"Allnet serving {len(self.uri_registry)} games on port {core_cfg.allnet.port}")
def handle_poweron(self, request: Request, _: Dict):

View File

@ -37,12 +37,22 @@ class TitleServlet():
for folder, mod in plugins.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()
should_call_setup = True
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:
self.logger.error(f"{folder} missing game_code or index in __init__.py")

View File

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

View File

@ -4,16 +4,5 @@ from titles.pokken.database import PokkenData
index = PokkenServlet
database = PokkenData
use_default_title = True
include_protocol = True
title_secure = True
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

View File

@ -35,19 +35,19 @@ class PokkenBase():
regist_pcb.server_time = int(datetime.now().timestamp() / 1000)
biwa_setting = {
"MatchingServer": {
"host": f"https://{self.core_cfg.title.hostname}",
"port": 9000,
"host": f"https://{self.game_cfg.server.hostname}",
"port": self.game_cfg.server.port_matching,
"url": "/matching"
},
"StunServer": {
"addr": self.core_cfg.title.hostname,
"port": 3333
"addr": self.game_cfg.server.hostname,
"port": self.game_cfg.server.port_stun
},
"TurnServer": {
"addr": self.core_cfg.title.hostname,
"port": 4444
"addr": self.game_cfg.server.hostname,
"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,
"logfilename": "JackalMatchingLibrary.log",
"biwalogfilename": "./biwa.log"

View File

@ -4,6 +4,10 @@ class PokkenServerConfig():
def __init__(self, parent_config: "PokkenConfig"):
self.__config = parent_config
@property
def hostname(self) -> str:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'hostname', default="localhost")
@property
def enable(self) -> bool:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'enable', default=True)
@ -18,7 +22,19 @@ class PokkenServerConfig():
@property
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
def ssl_cert(self) -> str:

View File

@ -1,3 +1,4 @@
from typing import Tuple
from twisted.web.http import Request
from twisted.web import resource, server
from twisted.internet import reactor, endpoints
@ -41,6 +42,19 @@ class PokkenServlet(resource.Resource):
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):
"""
There's currently no point in having this server on because Twisted