aimedb: fix idm zfill issue

This commit is contained in:
Hay1tsme 2024-06-24 22:28:22 -04:00
parent 8e39b56bae
commit 6ae11f96a2

View File

@ -240,18 +240,19 @@ class AimedbServlette():
used on the big boy networks.
"""
req = ADBFelicaLookupRequest(data)
card = await self.data.card.get_card_by_idm(req.idm)
idm = req.idm.zfill(16)
card = await self.data.card.get_card_by_idm(idm)
if not card:
ac = self.data.card.to_access_code(req.idm)
ac = self.data.card.to_access_code(idm)
test = await self.data.card.get_card_by_access_code(ac)
if test:
await self.data.card.set_idm_by_access_code(ac, req.idm)
await self.data.card.set_idm_by_access_code(ac, idm)
else:
ac = card['access_code']
self.logger.info(
f"idm {req.idm} ipm {req.pmm} -> access_code {ac}"
f"idm {idm} ipm {req.pmm.zfill(16)} -> access_code {ac}"
)
return ADBFelicaLookupResponse.from_req(req.head, ac)
@ -293,13 +294,14 @@ class AimedbServlette():
async def handle_felica_lookup_ex(self, data: bytes, resp_code: int) -> bytes:
req = ADBFelicaLookup2Request(data)
user_id = None
card = await self.data.card.get_card_by_idm(req.idm)
idm = req.idm.zfill(16)
card = await self.data.card.get_card_by_idm(idm)
if not card:
access_code = self.data.card.to_access_code(req.idm)
access_code = self.data.card.to_access_code(idm)
card = await self.data.card.get_card_by_access_code(access_code)
if card:
user_id = card['user']
await self.data.card.set_idm_by_access_code(access_code, req.idm)
await self.data.card.set_idm_by_access_code(access_code, idm)
else:
user_id = card['user']
@ -309,7 +311,7 @@ class AimedbServlette():
user_id = -1
self.logger.info(
f"idm {req.idm} ipm {req.pmm} -> access_code {access_code} user_id {user_id}"
f"idm {idm} ipm {req.pmm} -> access_code {access_code} user_id {user_id}"
)
resp = ADBFelicaLookup2Response.from_req(req.head, user_id, access_code)