From bd356af2726dfdc05f0278a23d866ba7d7b4b6c0 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Wed, 12 Apr 2023 02:34:29 -0400 Subject: [PATCH] pokken: restructure database --- .gitignore | 1 + core/allnet.py | 2 +- titles/pokken/base.py | 7 ++++ titles/pokken/index.py | 5 ++- titles/pokken/schema/match.py | 5 ++- titles/pokken/schema/profile.py | 69 ++++++--------------------------- 6 files changed, 27 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 825729f..b5a0e6e 100644 --- a/.gitignore +++ b/.gitignore @@ -158,5 +158,6 @@ cert/* !cert/server.pem config/* deliver/* +*.gz dbdump-*.json \ No newline at end of file diff --git a/core/allnet.py b/core/allnet.py index 0d4fbf7..b7cc4c6 100644 --- a/core/allnet.py +++ b/core/allnet.py @@ -55,7 +55,7 @@ class AllnetServlet: self.logger.error("No games detected!") for _, mod in plugins.items(): - if hasattr(mod.index, "get_allnet_info"): + if hasattr(mod, "index") and 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 diff --git a/titles/pokken/base.py b/titles/pokken/base.py index 96d5efd..0e87397 100644 --- a/titles/pokken/base.py +++ b/titles/pokken/base.py @@ -17,6 +17,7 @@ class PokkenBase: self.version = 0 self.logger = logging.getLogger("pokken") self.data = PokkenData(core_cfg) + self.SUPPORT_SET_NONE = 4294967295 def handle_noop(self, request: Any) -> bytes: res = jackal_pb2.Response() @@ -281,6 +282,12 @@ class PokkenBase: res.type = jackal_pb2.MessageType.SAVE_INGAME_LOG return res.SerializeToString() + def handle_save_charge(self, data: jackal_pb2.Request) -> bytes: + res = jackal_pb2.Response() + res.result = 1 + res.type = jackal_pb2.MessageType.SAVE_CHARGE + return res.SerializeToString() + def handle_matching_noop(self, data: Dict = {}, client_ip: str = "127.0.0.1") -> Dict: return {} diff --git a/titles/pokken/index.py b/titles/pokken/index.py index a7a328f..adfde88 100644 --- a/titles/pokken/index.py +++ b/titles/pokken/index.py @@ -87,7 +87,7 @@ class PokkenServlet(resource.Resource): if not game_cfg.server.enable: return (False, "") - return (True, "PKF2") + return (True, "PKF1") def setup(self) -> None: # TODO: Setup stun, turn (UDP) and admission (WSS) servers @@ -114,6 +114,8 @@ class PokkenServlet(resource.Resource): endpoint = jackal_pb2.MessageType.DESCRIPTOR.values_by_number[ pokken_request.type ].name.lower() + + self.logger.debug(pokken_request) handler = getattr(self.base, f"handle_{endpoint}", None) if handler is None: @@ -121,7 +123,6 @@ class PokkenServlet(resource.Resource): return self.base.handle_noop(pokken_request) self.logger.info(f"{endpoint} request from {Utils.get_ip_addr(request)}") - self.logger.debug(pokken_request) ret = handler(pokken_request) return ret diff --git a/titles/pokken/schema/match.py b/titles/pokken/schema/match.py index afe61f7..aec6bd3 100644 --- a/titles/pokken/schema/match.py +++ b/titles/pokken/schema/match.py @@ -14,8 +14,9 @@ match_data = Table( metadata, Column('id', Integer, primary_key=True, nullable=False), Column('user', ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False), - Column('play_mode', Integer), - Column('result', Integer), + Column('num_games', Integer), + Column('play_modes', JSON), + Column('results', JSON), Column('ex_ko_num', Integer), Column('wko_num', Integer), Column('timeup_win_num', Integer), diff --git a/titles/pokken/schema/profile.py b/titles/pokken/schema/profile.py index da6736c..bab53de 100644 --- a/titles/pokken/schema/profile.py +++ b/titles/pokken/schema/profile.py @@ -28,8 +28,10 @@ profile = Table( Column('score_point', Integer), Column('grade_max_num', Integer), Column('extra_counter', Integer), # Optional + Column('tutorial_progress_flag', JSON), # Repeated, Integer Column('total_play_days', Integer), Column('play_date_time', Integer), + Column('achievement_flag', JSON), # Repeated, Integer Column('lucky_box_fail_num', Integer), Column('event_reward_get_flag', Integer), Column('rank_pvp_all', Integer), @@ -41,15 +43,19 @@ profile = Table( Column('use_support_num', Integer), Column('rankmatch_flag', Integer), Column('rankmatch_max', Integer), # Optional + Column('rankmatch_progress', JSON), # Repeated, Integer Column('rankmatch_success', Integer), # Optional Column('beat_num', Integer), # Optional Column('title_text_id', Integer), Column('title_plate_id', Integer), Column('title_decoration_id', Integer), Column('support_pokemon_list', JSON), # Repeated, Integer - Column('support_set_1', JSON), # Repeated, Integer - Column('support_set_2', JSON), # Repeated, Integer - Column('support_set_3', JSON), # Repeated, Integer + Column('support_set_1_1', Integer), # Repeated, Integer + Column('support_set_1_2', Integer), + Column('support_set_2_1', Integer), # Repeated, Integer + Column('support_set_2_2', Integer), + Column('support_set_3_1', Integer), # Repeated, Integer + Column('support_set_3_2', Integer), Column('navi_trainer', Integer), Column('navi_version_id', Integer), Column('aid_skill_list', JSON), # Repeated, Integer @@ -84,56 +90,8 @@ profile = Table( Column('sp_bonus_category_id_2', Integer), Column('sp_bonus_key_value_2', Integer), Column('last_play_event_id', Integer), # Optional - mysql_charset="utf8mb4", -) - -tutorial_progress = Table( - 'pokken_tutorial_progress', - metadata, - Column('id', Integer, primary_key=True, nullable=False), - Column('user', ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False), - Column('flag', Integer), - UniqueConstraint('user', 'flag', name='pokken_tutorial_progress_uk'), - mysql_charset="utf8mb4", -) - -rankmatch_progress = Table( - 'pokken_rankmatch_progress', - metadata, - Column('id', Integer, primary_key=True, nullable=False), - Column('user', ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False), - Column('progress', Integer), - UniqueConstraint('user', 'progress', name='pokken_rankmatch_progress_uk'), - mysql_charset="utf8mb4", -) - -achievement_flag = Table( - 'pokken_achievement_flag', - metadata, - Column('id', Integer, primary_key=True, nullable=False), - Column('user', ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False), - Column('flag', Integer), - UniqueConstraint('user', 'flag', name='pokken_achievement_flag_uk'), - mysql_charset="utf8mb4", -) - -event_achievement_flag = Table( - 'pokken_event_achievement_flag', - metadata, - Column('id', Integer, primary_key=True, nullable=False), - Column('user', ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False), - Column('flag', Integer), - UniqueConstraint('user', 'flag', name='pokken_event_achievement_flag_uk'), - mysql_charset="utf8mb4", -) - -event_achievement_param = Table( - 'pokken_event_achievement_param', - metadata, - Column('id', Integer, primary_key=True, nullable=False), - Column('user', ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False), - Column('param', Integer), - UniqueConstraint('user', 'param', name='pokken_event_achievement_param_uk'), + Column('event_achievement_flag', JSON), # Repeated, Integer + Column('event_achievement_param', JSON), # Repeated, Integer mysql_charset="utf8mb4", ) @@ -176,10 +134,7 @@ class PokkenProfileData(BaseData): if result is None: self.logger.error(f"Failed to update pokken profile name for user {user_id}!") - def update_profile(self, user_id: int, profile_data: Dict) -> None: - """ - TODO: Find out what comes in on the SaveUserRequestData protobuf and save it! - """ + def update_profile_tutorial_flags(self, user_id: int, tutorial_flags: Dict) -> None: pass def get_profile(self, user_id: int) -> Optional[Row]: