From 066f92d94b7ab517a6d5a53258b9a8a117229be7 Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Tue, 28 Feb 2023 00:41:32 -0500 Subject: [PATCH] pokken index fixes --- example_config/pokken.yaml | 2 -- titles/pokken/config.py | 8 ------ titles/pokken/index.py | 55 +++++++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/example_config/pokken.yaml b/example_config/pokken.yaml index 967cca6..5523996 100644 --- a/example_config/pokken.yaml +++ b/example_config/pokken.yaml @@ -1,8 +1,6 @@ server: enable: True loglevel: "info" - hostname: "localhost" - ssl_enable: False port: 9000 port_matching: 9001 ssl_cert: cert/pokken.crt diff --git a/titles/pokken/config.py b/titles/pokken/config.py index 4eb07c6..b6596f2 100644 --- a/titles/pokken/config.py +++ b/titles/pokken/config.py @@ -12,14 +12,6 @@ class PokkenServerConfig(): def loglevel(self) -> int: return CoreConfig.str_to_loglevel(CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'loglevel', default="info")) - @property - def hostname(self) -> str: - return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'hostname', default="localhost") - - @property - def ssl_enable(self) -> bool: - return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'ssl_enable', default=False) - @property def port(self) -> int: return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'port', default=9000) diff --git a/titles/pokken/index.py b/titles/pokken/index.py index 5180399..a47cac7 100644 --- a/titles/pokken/index.py +++ b/titles/pokken/index.py @@ -6,6 +6,7 @@ import logging, coloredlogs from logging.handlers import TimedRotatingFileHandler from titles.pokken.proto import jackal_pb2 from os import path +from google.protobuf.message import DecodeError from core.config import CoreConfig from titles.pokken.config import PokkenConfig @@ -41,34 +42,46 @@ class PokkenServlet(resource.Resource): self.base = PokkenBase(core_cfg, self.game_cfg) def setup(self): - if self.game_cfg.server.enable: + """ + There's currently no point in having this server on because Twisted + won't play ball with both the fact that it's TLSv1.1, and because the + types of certs that pokken will accept are too flimsy for Twisted + so it will throw a fit. Currently leaving this here in case a bypass + is discovered in the future, but it's unlikly. For now, just use NGINX. + """ + if self.game_cfg.server.enable and self.core_cfg.server.is_develop: key_exists = path.exists(self.game_cfg.server.ssl_key) cert_exists = path.exists(self.game_cfg.server.ssl_cert) - - if self.core_cfg.server.is_develop and self.game_cfg.server.ssl_enable and key_exists and cert_exists: - endpoints.serverFromString(reactor, f"ssl:{self.game_cfg.server.port}"\ - f":interface={self.game_cfg.server.hostname}:privateKey={self.game_cfg.server.ssl_key}:"\ - f"certKey={self.game_cfg.server.ssl_cert}")\ - .listen(server.Site(PokkenServlet(self.core_cfg, self.config_dir))) - - elif self.core_cfg.server.is_develop and self.game_cfg.server.ssl_enable: - self.logger.error(f"Could not find cert at {self.game_cfg.server.ssl_key} or key at {self.game_cfg.server.ssl_cert}, Pokken not running.") - return - else: - endpoints.serverFromString(reactor, f"tcp:{self.game_cfg.server.port}"\ - f":interface={self.game_cfg.server.hostname}")\ - .listen(server.Site(PokkenServlet(self.core_cfg, self.config_dir))) + if key_exists and cert_exists: + endpoints.serverFromString(reactor, f"ssl:{self.game_cfg.server.port}"\ + f":interface={self.core_cfg.server.listen_address}:privateKey={self.game_cfg.server.ssl_key}:"\ + f"certKey={self.game_cfg.server.ssl_cert}")\ + .listen(server.Site(self)) + + self.logger.info(f"Pokken title server ready on port {self.game_cfg.server.port}") - self.logger.info(f"Pokken title server ready on port {self.game_cfg.server.port}") - - def render_POST(self, request: Request, version: int, endpoints: str) -> bytes: - req_url = request.uri.decode() - if req_url == "/matching": + else: + self.logger.error(f"Could not find cert at {self.game_cfg.server.ssl_key} or key at {self.game_cfg.server.ssl_cert}, Pokken not running.") + + def render_POST(self, request: Request, version: int = 0, endpoints: str = "") -> bytes: + if endpoints == "": + endpoints = request.uri.decode() + if endpoints.startswith("/matching"): self.logger.info("Matching request") + + content = request.content.getvalue() + if content == b"": + self.logger.info("Empty request") + return b"" pokken_request = jackal_pb2.Request() - pokken_request.ParseFromString(request.content.getvalue()) + try: + pokken_request.ParseFromString(content) + except DecodeError as e: + self.logger.warn(f"{e} {content}") + return b"" + endpoint = jackal_pb2.MessageType(pokken_request.type).name.lower() self.logger.info(f"{endpoint} request")