2023-02-17 07:09:26 +00:00
|
|
|
from datetime import datetime, timedelta
|
2023-03-12 20:30:57 +00:00
|
|
|
import json, logging
|
2023-03-12 04:42:12 +00:00
|
|
|
from typing import Any, Dict
|
2023-02-17 07:09:26 +00:00
|
|
|
|
|
|
|
from core.config import CoreConfig
|
|
|
|
from titles.pokken.config import PokkenConfig
|
|
|
|
from titles.pokken.proto import jackal_pb2
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
|
|
|
class PokkenBase:
|
2023-02-17 07:09:26 +00:00
|
|
|
def __init__(self, core_cfg: CoreConfig, game_cfg: PokkenConfig) -> None:
|
|
|
|
self.core_cfg = core_cfg
|
|
|
|
self.game_cfg = game_cfg
|
|
|
|
self.version = 0
|
2023-03-12 20:30:57 +00:00
|
|
|
self.logger = logging.getLogger("pokken")
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-02-17 07:09:26 +00:00
|
|
|
def handle_noop(self, request: Any) -> bytes:
|
|
|
|
res = jackal_pb2.Response()
|
|
|
|
res.result = 1
|
|
|
|
res.type = request.type
|
|
|
|
|
|
|
|
return res.SerializeToString()
|
|
|
|
|
2023-03-12 20:30:57 +00:00
|
|
|
def handle_ping(self, request: jackal_pb2.Request) -> bytes:
|
2023-02-17 07:09:26 +00:00
|
|
|
res = jackal_pb2.Response()
|
|
|
|
res.result = 1
|
|
|
|
res.type = jackal_pb2.MessageType.PING
|
|
|
|
|
2023-03-12 20:30:57 +00:00
|
|
|
self.logger.debug(res)
|
2023-02-17 07:09:26 +00:00
|
|
|
return res.SerializeToString()
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-03-12 20:30:57 +00:00
|
|
|
def handle_register_pcb(self, request: jackal_pb2.Request) -> bytes:
|
2023-02-17 07:09:26 +00:00
|
|
|
res = jackal_pb2.Response()
|
|
|
|
res.result = 1
|
|
|
|
res.type = jackal_pb2.MessageType.REGISTER_PCB
|
2023-03-12 20:30:57 +00:00
|
|
|
self.logger.info(f"Register PCB {request.register_pcb.pcb_id}")
|
2023-02-17 07:09:26 +00:00
|
|
|
|
|
|
|
regist_pcb = jackal_pb2.RegisterPcbResponseData()
|
2023-03-12 20:30:57 +00:00
|
|
|
regist_pcb.server_time = int(datetime.now().timestamp())
|
2023-02-17 07:09:26 +00:00
|
|
|
biwa_setting = {
|
|
|
|
"MatchingServer": {
|
2023-03-05 02:27:52 +00:00
|
|
|
"host": f"https://{self.game_cfg.server.hostname}",
|
2023-03-12 04:42:12 +00:00
|
|
|
"port": self.game_cfg.server.port,
|
|
|
|
"url": "/SDAK/100/matching",
|
2023-02-17 07:09:26 +00:00
|
|
|
},
|
|
|
|
"StunServer": {
|
2023-03-05 02:27:52 +00:00
|
|
|
"addr": self.game_cfg.server.hostname,
|
2023-03-09 16:38:58 +00:00
|
|
|
"port": self.game_cfg.server.port_stun,
|
2023-02-17 07:09:26 +00:00
|
|
|
},
|
|
|
|
"TurnServer": {
|
2023-03-05 02:27:52 +00:00
|
|
|
"addr": self.game_cfg.server.hostname,
|
2023-03-09 16:38:58 +00:00
|
|
|
"port": self.game_cfg.server.port_turn,
|
2023-02-17 07:09:26 +00:00
|
|
|
},
|
2023-03-05 02:27:52 +00:00
|
|
|
"AdmissionUrl": f"ws://{self.game_cfg.server.hostname}:{self.game_cfg.server.port_admission}",
|
2023-02-17 07:09:26 +00:00
|
|
|
"locationId": 123,
|
|
|
|
"logfilename": "JackalMatchingLibrary.log",
|
2023-03-09 16:38:58 +00:00
|
|
|
"biwalogfilename": "./biwa.log",
|
2023-02-17 07:09:26 +00:00
|
|
|
}
|
|
|
|
regist_pcb.bnp_baseuri = f"{self.core_cfg.title.hostname}/bna"
|
|
|
|
regist_pcb.biwa_setting = json.dumps(biwa_setting)
|
|
|
|
|
|
|
|
res.register_pcb.CopyFrom(regist_pcb)
|
|
|
|
|
|
|
|
return res.SerializeToString()
|
|
|
|
|
2023-03-12 20:30:57 +00:00
|
|
|
def handle_save_ads(self, request: jackal_pb2.Request) -> bytes:
|
2023-02-17 07:09:26 +00:00
|
|
|
res = jackal_pb2.Response()
|
|
|
|
res.result = 1
|
|
|
|
res.type = jackal_pb2.MessageType.SAVE_ADS
|
|
|
|
|
|
|
|
return res.SerializeToString()
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
def handle_save_client_log(
|
2023-03-12 20:30:57 +00:00
|
|
|
self, request: jackal_pb2.Request
|
2023-03-09 16:38:58 +00:00
|
|
|
) -> bytes:
|
2023-02-17 07:09:26 +00:00
|
|
|
res = jackal_pb2.Response()
|
|
|
|
res.result = 1
|
|
|
|
res.type = jackal_pb2.MessageType.SAVE_CLIENT_LOG
|
|
|
|
|
|
|
|
return res.SerializeToString()
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
def handle_check_diagnosis(
|
2023-03-12 20:30:57 +00:00
|
|
|
self, request: jackal_pb2.Request
|
2023-03-09 16:38:58 +00:00
|
|
|
) -> bytes:
|
2023-02-17 07:09:26 +00:00
|
|
|
res = jackal_pb2.Response()
|
|
|
|
res.result = 1
|
|
|
|
res.type = jackal_pb2.MessageType.CHECK_DIAGNOSIS
|
|
|
|
|
|
|
|
return res.SerializeToString()
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
def handle_load_client_settings(
|
2023-03-12 20:30:57 +00:00
|
|
|
self, request: jackal_pb2.Request
|
2023-03-09 16:38:58 +00:00
|
|
|
) -> bytes:
|
2023-02-17 07:09:26 +00:00
|
|
|
res = jackal_pb2.Response()
|
|
|
|
res.result = 1
|
|
|
|
res.type = jackal_pb2.MessageType.LOAD_CLIENT_SETTINGS
|
|
|
|
settings = jackal_pb2.LoadClientSettingsResponseData()
|
|
|
|
|
|
|
|
settings.money_magnification = 0
|
|
|
|
settings.continue_bonus_exp = 100
|
|
|
|
settings.continue_fight_money = 100
|
|
|
|
settings.event_bonus_exp = 100
|
|
|
|
settings.level_cap = 999
|
|
|
|
settings.op_movie_flag = 0xFFFFFFFF
|
|
|
|
settings.lucky_bonus_rate = 1
|
|
|
|
settings.fail_support_num = 10
|
|
|
|
settings.chara_open_flag = 0xFFFFFFFF
|
|
|
|
settings.chara_open_date = int(datetime.now().timestamp() / 1000)
|
|
|
|
settings.chara_pre_open_date = int(datetime.now().timestamp() / 1000)
|
|
|
|
settings.search_id = 123
|
|
|
|
res.load_client_settings.CopyFrom(settings)
|
|
|
|
|
|
|
|
return res.SerializeToString()
|
2023-03-12 04:42:12 +00:00
|
|
|
|
2023-03-12 20:30:57 +00:00
|
|
|
def handle_load_ranking(self, request: jackal_pb2.Request) -> bytes:
|
2023-03-12 04:42:12 +00:00
|
|
|
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 {}
|