From 8c1d272c72b6c1bc2571375b2d9e38286a527778 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Tue, 4 Oct 2022 03:31:52 +0000 Subject: [PATCH] Rename whole-service route handler, get rid of legacy eacoin handler that's broken due to evaluation order, fix eacoin disable bug that I just discovered. --- bemani/backend/base.py | 5 +-- bemani/backend/core/eacoin.py | 52 +++++++++++++++++++++++++------ bemani/backend/dispatch.py | 2 +- bemani/backend/popn/common.py | 2 +- bemani/backend/popn/eclale.py | 2 +- bemani/backend/popn/fantasia.py | 2 +- bemani/backend/popn/lapistoria.py | 2 +- bemani/backend/popn/sunnypark.py | 2 +- bemani/backend/popn/tunestreet.py | 2 +- 9 files changed, 52 insertions(+), 19 deletions(-) diff --git a/bemani/backend/base.py b/bemani/backend/base.py index ca9c001..4ca7b44 100644 --- a/bemani/backend/base.py +++ b/bemani/backend/base.py @@ -26,8 +26,9 @@ class Factory(ABC): """ The base class every game factory inherits from. Defines a create method which should return some game class which can handle packets. Game classes - inherit from Base, and have handle__request methods on them that - Dispatch will look up in order to handle calls. + inherit from Base, and have handle__requests service methods or + handle___request methods on them that Dispatch will look up + in order to handle calls. """ MANAGED_CLASSES: List[Type["Base"]] diff --git a/bemani/backend/core/eacoin.py b/bemani/backend/core/eacoin.py index 084902e..c852265 100644 --- a/bemani/backend/core/eacoin.py +++ b/bemani/backend/core/eacoin.py @@ -1,4 +1,3 @@ -from typing import Optional from typing_extensions import Final from bemani.backend.base import Base, Status @@ -24,11 +23,7 @@ class PASELIHandler(Base): """ paseli_padding: int = 1 - def handle_eacoin_request(self, request: Node) -> Optional[Node]: - """ - First, a generic handler to catch if paseli is not enabled, so that each - individual method below doesn't need to handle it. - """ + def handle_eacoin_checkin_request(self, request: Node) -> Node: if not self.config.paseli.enabled: # Refuse to respond, we don't have PASELI enabled print("PASELI not enabled, ignoring eacoin request") @@ -36,10 +31,6 @@ class PASELIHandler(Base): root.set_attribute('status', str(Status.NOT_ALLOWED)) return root - # This is fine, let the individual request handlers handle this packet. - return None - - def handle_eacoin_checkin_request(self, request: Node) -> Node: root = Node.void('eacoin') cardid = request.child_value('cardid') pin = request.child_value('passwd') @@ -85,6 +76,13 @@ class PASELIHandler(Base): return root def handle_eacoin_opcheckin_request(self, request: Node) -> Node: + if not self.config.paseli.enabled: + # Refuse to respond, we don't have PASELI enabled + print("PASELI not enabled, ignoring eacoin request") + root = Node.void('eacoin') + root.set_attribute('status', str(Status.NOT_ALLOWED)) + return root + root = Node.void('eacoin') passwd = request.child_value('passwd') @@ -118,6 +116,12 @@ class PASELIHandler(Base): return root def handle_eacoin_consume_request(self, request: Node) -> Node: + if not self.config.paseli.enabled: + # Refuse to respond, we don't have PASELI enabled + print("PASELI not enabled, ignoring eacoin request") + root = Node.void('eacoin') + root.set_attribute('status', str(Status.NOT_ALLOWED)) + return root def make_resp(status: int, balance: int) -> Node: root = Node.void('eacoin') @@ -174,6 +178,13 @@ class PASELIHandler(Base): return make_resp(0, balance) def handle_eacoin_getlog_request(self, request: Node) -> Node: + if not self.config.paseli.enabled: + # Refuse to respond, we don't have PASELI enabled + print("PASELI not enabled, ignoring eacoin request") + root = Node.void('eacoin') + root.set_attribute('status', str(Status.NOT_ALLOWED)) + return root + root = Node.void('eacoin') sessid = request.child_value('sessid') logtype = request.child_value('logtype') @@ -389,6 +400,13 @@ class PASELIHandler(Base): return root def handle_eacoin_opchpass_request(self, request: Node) -> Node: + if not self.config.paseli.enabled: + # Refuse to respond, we don't have PASELI enabled + print("PASELI not enabled, ignoring eacoin request") + root = Node.void('eacoin') + root.set_attribute('status', str(Status.NOT_ALLOWED)) + return root + root = Node.void('eacoin') oldpass = request.child_value('passwd') newpass = request.child_value('newpasswd') @@ -423,6 +441,13 @@ class PASELIHandler(Base): return root def handle_eacoin_checkout_request(self, request: Node) -> Node: + if not self.config.paseli.enabled: + # Refuse to respond, we don't have PASELI enabled + print("PASELI not enabled, ignoring eacoin request") + root = Node.void('eacoin') + root.set_attribute('status', str(Status.NOT_ALLOWED)) + return root + session = request.child_value('sessid') if session is not None: # Destroy the session so it can't be used for any other purchases @@ -432,6 +457,13 @@ class PASELIHandler(Base): return root def handle_eacoin_opcheckout_request(self, request: Node) -> Node: + if not self.config.paseli.enabled: + # Refuse to respond, we don't have PASELI enabled + print("PASELI not enabled, ignoring eacoin request") + root = Node.void('eacoin') + root.set_attribute('status', str(Status.NOT_ALLOWED)) + return root + session = request.child_value('sessid') if session is not None: # Destroy the session so it can't be used for any other purchases diff --git a/bemani/backend/dispatch.py b/bemani/backend/dispatch.py index 97eb031..28aa409 100644 --- a/bemani/backend/dispatch.py +++ b/bemani/backend/dispatch.py @@ -147,7 +147,7 @@ class Dispatch: if response is None: # Now, try to pass it off to a generic service handler try: - handler = getattr(game, f'handle_{request.name}_request') + handler = getattr(game, f'handle_{request.name}_requests') except AttributeError: handler = None if handler is not None: diff --git a/bemani/backend/popn/common.py b/bemani/backend/popn/common.py index 7244c29..c748be7 100644 --- a/bemani/backend/popn/common.py +++ b/bemani/backend/popn/common.py @@ -106,7 +106,7 @@ class PopnMusicModernBase(PopnMusicBase, ABC): return self.GAME_PLAY_RANK_AAA return self.GAME_PLAY_RANK_S - def handle_lobby24_request(self, request: Node) -> Node: + def handle_lobby24_requests(self, request: Node) -> Node: # Stub out the entire lobby24 service return Node.void('lobby24') diff --git a/bemani/backend/popn/eclale.py b/bemani/backend/popn/eclale.py index 7d1babb..6420f0b 100644 --- a/bemani/backend/popn/eclale.py +++ b/bemani/backend/popn/eclale.py @@ -254,7 +254,7 @@ class PopnMusicEclale(PopnMusicBase): self.__construct_common_info(info) return info - def handle_lobby22_request(self, request: Node) -> Node: + def handle_lobby22_requests(self, request: Node) -> Node: # Stub out the entire lobby22 service (yes, its lobby22 in Pop'n 23) return Node.void('lobby22') diff --git a/bemani/backend/popn/fantasia.py b/bemani/backend/popn/fantasia.py index 3f7e85d..0b58c99 100644 --- a/bemani/backend/popn/fantasia.py +++ b/bemani/backend/popn/fantasia.py @@ -636,6 +636,6 @@ class PopnMusicFantasia(PopnMusicBase): self.update_machine(machine) return Node.void('game') - def handle_lobby_request(self, request: Node) -> Node: + def handle_lobby_requests(self, request: Node) -> Node: # Stub out the entire lobby service return Node.void('lobby') diff --git a/bemani/backend/popn/lapistoria.py b/bemani/backend/popn/lapistoria.py index 9b50dfc..cb53530 100644 --- a/bemani/backend/popn/lapistoria.py +++ b/bemani/backend/popn/lapistoria.py @@ -249,7 +249,7 @@ class PopnMusicLapistoria(PopnMusicBase): self.update_machine_name(request.child_value('pcb_setting/name')) return Node.void('pcb22') - def handle_lobby22_request(self, request: Node) -> Node: + def handle_lobby22_requests(self, request: Node) -> Node: # Stub out the entire lobby22 service return Node.void('lobby22') diff --git a/bemani/backend/popn/sunnypark.py b/bemani/backend/popn/sunnypark.py index b35e35e..389ac25 100644 --- a/bemani/backend/popn/sunnypark.py +++ b/bemani/backend/popn/sunnypark.py @@ -699,6 +699,6 @@ class PopnMusicSunnyPark(PopnMusicBase): return root - def handle_lobby_request(self, request: Node) -> Node: + def handle_lobby_requests(self, request: Node) -> Node: # Stub out the entire lobby service return Node.void('lobby') diff --git a/bemani/backend/popn/tunestreet.py b/bemani/backend/popn/tunestreet.py index c4059fa..1e257b4 100644 --- a/bemani/backend/popn/tunestreet.py +++ b/bemani/backend/popn/tunestreet.py @@ -616,6 +616,6 @@ class PopnMusicTuneStreet(PopnMusicBase): return root - def handle_lobby_request(self, request: Node) -> Node: + def handle_lobby_requests(self, request: Node) -> Node: # Stub out the entire lobby service return Node.void('lobby')