From 71489c1272fbafde46aadea1384130b0d0c87b22 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Sun, 20 Aug 2023 19:55:26 -0400 Subject: [PATCH] adb: fix log_ex --- core/adb_handlers/log.py | 43 +++++++++++++++++++++++++++++++++++----- core/aimedb.py | 6 +++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/core/adb_handlers/log.py b/core/adb_handlers/log.py index 8be36f9..28fbdf3 100644 --- a/core/adb_handlers/log.py +++ b/core/adb_handlers/log.py @@ -1,7 +1,15 @@ -from construct import Struct, Int32sl, Padding, Int8sl -from typing import Union +from construct import Struct, Padding, Int8sl +from typing import Final, List from .base import * +NUM_LOGS: Final[int] = 20 +NUM_LEN_LOG_EX: Final[int] = 48 + +class AmLogEx: + def __init__(self, data: bytes) -> None: + self.aime_id, status, self.user_id, self.credit_ct, self.bet_ct, self.won_ct, self.local_time, \ + self.tseq, self.place_id = struct.unpack(" None: @@ -18,6 +26,31 @@ class ADBLogRequest(ADBBaseRequest): class ADBLogExRequest(ADBBaseRequest): def __init__(self, data: bytes) -> None: super().__init__(data) - self.aime_id, status, self.user_id, self.credit_ct, self.bet_ct, self.won_ct, self.local_time, \ - self.tseq, self.place_id, self.num_logs = struct.unpack_from(" None: + super().__init__(code, length, status, game_id, store_id, keychip_id, protocol_ver) + + @classmethod + def from_req(cls, req: ADBHeader) -> "ADBLogExResponse": + c = cls(req.game_id, req.store_id, req.keychip_id, req.protocol_ver) + return c + + def make(self) -> bytes: + resp_struct = Struct( + "log_result" / Int8sl[NUM_LOGS], + Padding(12) + ) + + body = resp_struct.build(dict( + log_result = [1] * NUM_LOGS + )) + + self.head.length = HEADER_SIZE + len(body) + return self.head.make() + body diff --git a/core/aimedb.py b/core/aimedb.py index 552205f..0a1b4f5 100644 --- a/core/aimedb.py +++ b/core/aimedb.py @@ -277,7 +277,11 @@ class AimedbProtocol(Protocol): def handle_log_ex(self, data: bytes, resp_code: int) -> bytes: req = ADBLogExRequest(data) - self.logger.info(f"User {req.aime_id} logged {req.status.name} event, credit_ct: {req.credit_ct} bet_ct: {req.bet_ct} won_ct: {req.won_ct}") + strs = [] + self.logger.info(f"Recieved {req.num_logs} or {len(req.logs)} logs") + + for x in range(req.num_logs): + self.logger.debug(f"User {req.logs[x].aime_id} logged {req.logs[x].status.name} event, credit_ct: {req.logs[x].credit_ct} bet_ct: {req.logs[x].bet_ct} won_ct: {req.logs[x].won_ct}") return ADBBaseResponse(resp_code, 0x20, 1, req.head.game_id, req.head.store_id, req.head.keychip_id, req.head.protocol_ver) def handle_goodbye(self, data: bytes, resp_code: int) -> None: