2019-12-08 22:43:49 +01:00
|
|
|
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:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Got invalid card back when converting from UserID!")
|
2019-12-08 22:43:49 +01:00
|
|
|
if len(cardid) < 16:
|
2022-10-15 20:56:30 +02:00
|
|
|
cardid = ("0" * (16 - len(cardid))) + cardid
|
2019-12-08 22:43:49 +01:00
|
|
|
return cardid
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_remote(userid: UserID) -> bool:
|
|
|
|
return userid > (2**32 - 1)
|