forked from Hay1tsme/artemis
add idm and chip_id fields to card table
This commit is contained in:
@ -194,6 +194,9 @@ class AimedbServlette():
|
||||
|
||||
if user_id and user_id > 0:
|
||||
await self.data.card.update_card_last_login(req.access_code)
|
||||
if req.access_code.startswith("010") or req.access_code.startswith("3"):
|
||||
await self.data.card.set_chip_id_by_access_code(req.access_code, req.serial_number)
|
||||
self.logger.info(f"Attempt to set chip id to {req.serial_number} for access code {req.access_code}")
|
||||
return ret
|
||||
|
||||
async def handle_lookup_ex(self, data: bytes, resp_code: int) -> ADBBaseResponse:
|
||||
@ -229,15 +232,24 @@ class AimedbServlette():
|
||||
|
||||
async def handle_felica_lookup(self, data: bytes, resp_code: int) -> bytes:
|
||||
"""
|
||||
On official, I think a card has to be registered for this to actually work, but
|
||||
I'm making the executive decision to not implement that and just kick back our
|
||||
faux generated access code. The real felica IDm -> access code conversion is done
|
||||
on the ADB server, which we do not and will not ever have access to. Because we can
|
||||
assure that all IDms will be unique, this basic 0-padded hex -> int conversion will
|
||||
be fine.
|
||||
On official, the IDm is used as a key to look up the stored access code in a large
|
||||
database. We do not have access to that database so we have to make due with what we got.
|
||||
Interestingly, namco games are able to read S_PAD0 and send the server the correct access
|
||||
code, but aimedb doesn't. Until somebody either enters the correct code manually, or scans
|
||||
on a game that reads it correctly from the card, this will have to do. It's the same conversion
|
||||
used on the big boy networks.
|
||||
"""
|
||||
req = ADBFelicaLookupRequest(data)
|
||||
ac = self.data.card.to_access_code(req.idm)
|
||||
card = await self.data.card.get_card_by_idm(req.idm)
|
||||
if not card:
|
||||
ac = self.data.card.to_access_code(req.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)
|
||||
|
||||
else:
|
||||
ac = card['access_code']
|
||||
|
||||
self.logger.info(
|
||||
f"idm {req.idm} ipm {req.pmm} -> access_code {ac}"
|
||||
)
|
||||
@ -245,7 +257,8 @@ class AimedbServlette():
|
||||
|
||||
async def handle_felica_register(self, data: bytes, resp_code: int) -> bytes:
|
||||
"""
|
||||
I've never seen this used.
|
||||
Used to register felica moble access codes. Will never be used on our network
|
||||
because we don't implement felica_lookup properly.
|
||||
"""
|
||||
req = ADBFelicaLookupRequest(data)
|
||||
ac = self.data.card.to_access_code(req.idm)
|
||||
@ -279,8 +292,18 @@ class AimedbServlette():
|
||||
|
||||
async def handle_felica_lookup_ex(self, data: bytes, resp_code: int) -> bytes:
|
||||
req = ADBFelicaLookup2Request(data)
|
||||
access_code = self.data.card.to_access_code(req.idm)
|
||||
user_id = await self.data.card.get_user_id_from_card(access_code=access_code)
|
||||
user_id = None
|
||||
card = await self.data.card.get_card_by_idm(req.idm)
|
||||
if not card:
|
||||
access_code = self.data.card.to_access_code(req.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)
|
||||
|
||||
else:
|
||||
user_id = card['user']
|
||||
access_code = card['access_code']
|
||||
|
||||
if user_id is None:
|
||||
user_id = -1
|
||||
@ -290,6 +313,14 @@ class AimedbServlette():
|
||||
)
|
||||
|
||||
resp = ADBFelicaLookup2Response.from_req(req.head, user_id, access_code)
|
||||
|
||||
if user_id > 0:
|
||||
if card['is_banned'] and card['is_locked']:
|
||||
resp.head.status = ADBStatus.BAN_SYS_USER
|
||||
elif card['is_banned']:
|
||||
resp.head.status = ADBStatus.BAN_SYS
|
||||
elif card['is_locked']:
|
||||
resp.head.status = ADBStatus.LOCK_USER
|
||||
|
||||
if user_id and user_id > 0 and self.config.aimedb.id_secret:
|
||||
auth_key = create_sega_auth_key(user_id, req.head.game_id, req.head.store_id, req.head.keychip_id, self.config.aimedb.id_secret, self.config.aimedb.id_lifetime_seconds)
|
||||
@ -337,6 +368,16 @@ class AimedbServlette():
|
||||
self.logger.info(
|
||||
f"Registration blocked!: access code {req.access_code}"
|
||||
)
|
||||
|
||||
if user_id > 0:
|
||||
if req.access_code.startswith("010") or req.access_code.startswith("3"):
|
||||
await self.data.card.set_chip_id_by_access_code(req.access_code, req.serial_number)
|
||||
self.logger.info(f"Attempt to set chip id to {req.serial_number} for access code {req.access_code}")
|
||||
|
||||
elif req.access_code.startswith("0008"):
|
||||
idm = self.data.card.to_idm(req.access_code)
|
||||
await self.data.card.set_idm_by_access_code(req.access_code, idm)
|
||||
self.logger.info(f"Attempt to set IDm to {idm} for access code {req.access_code}")
|
||||
|
||||
resp = ADBLookupResponse.from_req(req.head, user_id)
|
||||
if resp.user_id <= 0:
|
||||
|
Reference in New Issue
Block a user