forked from Dniel97/artemis
pokken: add matching server skeleton
This commit is contained in:
parent
eb51fc315c
commit
e4b7809e34
@ -3,7 +3,6 @@ server:
|
||||
enable: True
|
||||
loglevel: "info"
|
||||
port: 9000
|
||||
port_matching: 9001
|
||||
port_stun: 9002
|
||||
port_turn: 9003
|
||||
port_admission: 9004
|
||||
port_stun: 9001
|
||||
port_turn: 9002
|
||||
port_admission: 9003
|
@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
from typing import Any
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.config import CoreConfig
|
||||
from titles.pokken.config import PokkenConfig
|
||||
@ -37,8 +37,8 @@ class PokkenBase:
|
||||
biwa_setting = {
|
||||
"MatchingServer": {
|
||||
"host": f"https://{self.game_cfg.server.hostname}",
|
||||
"port": self.game_cfg.server.port_matching,
|
||||
"url": "SDAK/100/matching",
|
||||
"port": self.game_cfg.server.port,
|
||||
"url": "/SDAK/100/matching",
|
||||
},
|
||||
"StunServer": {
|
||||
"addr": self.game_cfg.server.hostname,
|
||||
@ -108,3 +108,36 @@ class PokkenBase:
|
||||
res.load_client_settings.CopyFrom(settings)
|
||||
|
||||
return res.SerializeToString()
|
||||
|
||||
def handle_load_ranking(self, request: jackal_pb2.CheckDiagnosisRequestData) -> bytes:
|
||||
res = jackal_pb2.Response()
|
||||
res.result = 1
|
||||
res.type = jackal_pb2.MessageType.LOAD_RANKING
|
||||
ranking = jackal_pb2.LoadRankingResponseData()
|
||||
|
||||
ranking.ranking_id = 1
|
||||
ranking.ranking_start = 0
|
||||
ranking.ranking_end = 1
|
||||
ranking.event_end = True
|
||||
ranking.modify_date = int(datetime.now().timestamp() / 1000)
|
||||
res.load_ranking.CopyFrom(ranking)
|
||||
|
||||
def handle_matching_noop(self, data: Dict = {}, client_ip: str = "127.0.0.1") -> Dict:
|
||||
return {}
|
||||
|
||||
def handle_matching_start_matching(self, data: Dict = {}, client_ip: str = "127.0.0.1") -> Dict:
|
||||
return {}
|
||||
|
||||
def handle_matching_is_matching(self, data: Dict = {}, client_ip: str = "127.0.0.1") -> Dict:
|
||||
"""
|
||||
"sessionId":"12345678",
|
||||
"A":{
|
||||
"pcb_id": data["data"]["must"]["pcb_id"],
|
||||
"gip": client_ip
|
||||
},
|
||||
"list":[]
|
||||
"""
|
||||
return {}
|
||||
|
||||
def handle_matching_stop_matching(self, data: Dict = {}, client_ip: str = "127.0.0.1") -> Dict:
|
||||
return {}
|
@ -31,28 +31,22 @@ class PokkenServerConfig:
|
||||
self.__config, "pokken", "server", "port", default=9000
|
||||
)
|
||||
|
||||
@property
|
||||
def port_matching(self) -> int:
|
||||
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
|
||||
self.__config, "pokken", "server", "port_stun", default=9001
|
||||
)
|
||||
|
||||
@property
|
||||
def port_turn(self) -> int:
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "pokken", "server", "port_turn", default=9003
|
||||
self.__config, "pokken", "server", "port_turn", default=9002
|
||||
)
|
||||
|
||||
@property
|
||||
def port_admission(self) -> int:
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "pokken", "server", "port_admission", default=9004
|
||||
self.__config, "pokken", "server", "port_admission", default=9003
|
||||
)
|
||||
|
||||
class PokkenConfig(dict):
|
||||
|
@ -1,11 +1,12 @@
|
||||
from typing import Tuple
|
||||
from twisted.web.http import Request
|
||||
from twisted.web import resource, server
|
||||
from twisted.internet import reactor, endpoints
|
||||
from twisted.web import resource
|
||||
import json, ast
|
||||
from datetime import datetime
|
||||
import yaml
|
||||
import logging, coloredlogs
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
from titles.pokken.proto import jackal_pb2
|
||||
import inflection
|
||||
from os import path
|
||||
from google.protobuf.message import DecodeError
|
||||
|
||||
@ -13,6 +14,7 @@ from core.config import CoreConfig
|
||||
from titles.pokken.config import PokkenConfig
|
||||
from titles.pokken.base import PokkenBase
|
||||
from titles.pokken.const import PokkenConstants
|
||||
from titles.pokken.proto import jackal_pb2
|
||||
|
||||
|
||||
class PokkenServlet(resource.Resource):
|
||||
@ -88,15 +90,14 @@ class PokkenServlet(resource.Resource):
|
||||
return (True, "PKF2")
|
||||
|
||||
def setup(self) -> None:
|
||||
# TODO: Setup matching, stun, turn and admission servers
|
||||
# TODO: Setup stun, turn (UDP) and admission (WSS) servers
|
||||
pass
|
||||
|
||||
def render_POST(
|
||||
self, request: Request, version: int = 0, endpoints: str = ""
|
||||
) -> bytes:
|
||||
if endpoints.startswith("/matching"):
|
||||
self.logger.info("Matching request")
|
||||
self.logger.debug(request.content)
|
||||
if endpoints == "matching":
|
||||
return self.handle_matching(request)
|
||||
|
||||
content = request.content.getvalue()
|
||||
if content == b"":
|
||||
@ -122,5 +123,37 @@ class PokkenServlet(resource.Resource):
|
||||
return self.base.handle_noop(pokken_request)
|
||||
|
||||
ret = handler(pokken_request)
|
||||
self.logger.debug(f"Response: {ret}")
|
||||
#self.logger.debug(f"Response: {ret}")
|
||||
return ret
|
||||
|
||||
def handle_matching(self, request: Request) -> bytes:
|
||||
content = request.content.getvalue()
|
||||
client_ip = request.getClientAddress().host
|
||||
|
||||
if content is None or content == b"":
|
||||
self.logger.info("Empty matching request")
|
||||
return json.dumps(self.base.handle_matching_noop()).encode()
|
||||
|
||||
json_content = ast.literal_eval(content.decode().replace('null', 'None').replace('true', 'True').replace('false', 'False'))
|
||||
self.logger.info(f"Matching {json_content['call']} request")
|
||||
self.logger.debug(json_content)
|
||||
|
||||
handler = getattr(self.base, f"handle_matching_{inflection.underscore(json_content['call'])}", None)
|
||||
if handler is None:
|
||||
self.logger.warn(f"No handler found for message type {json_content['call']}")
|
||||
return json.dumps(self.base.handle_matching_noop()).encode()
|
||||
|
||||
ret = handler(json_content, client_ip)
|
||||
|
||||
if ret is None:
|
||||
ret = {}
|
||||
if "result" not in ret:
|
||||
ret["result"] = "true"
|
||||
if "data" not in ret:
|
||||
ret["data"] = {}
|
||||
if "timestamp" not in ret:
|
||||
ret["timestamp"] = int(datetime.now().timestamp() * 1000)
|
||||
|
||||
self.logger.debug(f"Response {ret}")
|
||||
|
||||
return json.dumps(ret).encode()
|
||||
|
Loading…
Reference in New Issue
Block a user