1
0
mirror of synced 2024-11-15 02:17:36 +01:00
bemaniutils/bemani/data/remoteuser.py
2019-12-08 21:43:49 +00:00

29 lines
1021 B
Python

from bemani.data.types import UserID
class RemoteUser:
"""
We use a nasty trick to tell the difference between a local and remote user.
Local users are assumed to be in the range of 1 to 2^32-1. Remote users therefore
are anything above that range. We cast card IDs to user IDs by treating them as
raw integers and then wrapping them in the UserID type. This is how we can
store local information in our DB for remote users, such as rival settings/etc.
"""
@staticmethod
def card_to_userid(cardid: str) -> UserID:
return UserID(int(cardid, 16))
@staticmethod
def userid_to_card(userid: UserID) -> str:
cardid = hex(abs(userid))[2:].upper()
if len(cardid) <= 8:
raise Exception('Got invalid card back when converting from UserID!')
if len(cardid) < 16:
cardid = ('0' * (16 - len(cardid))) + cardid
return cardid
@staticmethod
def is_remote(userid: UserID) -> bool:
return userid > (2**32 - 1)