2019-12-08 22:43:49 +01:00
|
|
|
from bemani.backend.base import Base, Status
|
|
|
|
from bemani.protocol import Node
|
|
|
|
from bemani.common import Model
|
|
|
|
|
|
|
|
|
|
|
|
class CardManagerHandler(Base):
|
|
|
|
"""
|
|
|
|
The class that handles card management. This assumes it is attached as a mixin to a game
|
|
|
|
class so that it can understand if there's a profile for a game or not.
|
2021-09-03 06:34:51 +02:00
|
|
|
|
2021-09-07 19:55:53 +02:00
|
|
|
Handle a request for card management. This is independent of a game's profile handling,
|
|
|
|
but still gives the game information as to whether or not a profile exists for a game.
|
|
|
|
These methods handle looking up a card, handling binding a profile to a game version,
|
|
|
|
returning whether a game profile exists or should be migrated, and creating a new account
|
|
|
|
when no account is associated with a card.
|
|
|
|
"""
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-07 19:55:53 +02:00
|
|
|
def handle_cardmng_inquire_request(self, request: Node) -> Node:
|
|
|
|
# Given a cardid, look up the dataid/refid (same thing in this system).
|
|
|
|
# If the card doesn't exist or isn't allowed, return a status specifying this
|
|
|
|
# instead of the results of the dataid/refid lookup.
|
2022-10-15 20:56:30 +02:00
|
|
|
cardid = request.attribute("cardid")
|
|
|
|
modelstring = request.attribute("model")
|
2021-09-07 19:55:53 +02:00
|
|
|
userid = self.data.local.user.from_cardid(cardid)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-07 19:55:53 +02:00
|
|
|
if userid is None:
|
|
|
|
# This user doesn't exist, force system to create new account
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
|
|
|
root.set_attribute("status", str(Status.NOT_REGISTERED))
|
2019-12-08 22:43:49 +01:00
|
|
|
return root
|
|
|
|
|
2021-09-07 19:55:53 +02:00
|
|
|
# Special handling for looking up whether the previous game's profile existed. If we
|
|
|
|
# don't do this then some games won't present the user with a migration.
|
|
|
|
bound = self.has_profile(userid)
|
|
|
|
expired = False
|
|
|
|
if bound is False:
|
|
|
|
if modelstring is not None:
|
|
|
|
model = Model.from_modelstring(modelstring)
|
|
|
|
oldgame = Base.create(self.data, self.config, model, self.model)
|
|
|
|
if oldgame is not None:
|
|
|
|
bound = oldgame.has_profile(userid)
|
|
|
|
expired = self.supports_expired_profiles
|
|
|
|
|
|
|
|
refid = self.data.local.user.get_refid(self.game, self.version, userid)
|
|
|
|
paseli_enabled = self.supports_paseli and self.config.paseli.enabled
|
2022-10-15 20:56:30 +02:00
|
|
|
newflag = (
|
|
|
|
self.data.remote.user.get_any_profile(self.game, self.version, userid)
|
|
|
|
is None
|
|
|
|
)
|
2021-09-07 19:55:53 +02:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
|
|
|
root.set_attribute("refid", refid)
|
|
|
|
root.set_attribute("dataid", refid)
|
2021-09-07 19:55:53 +02:00
|
|
|
|
|
|
|
# Unsure what this does, but it appears not to matter so we set it to my best guess.
|
2022-10-15 20:56:30 +02:00
|
|
|
root.set_attribute("newflag", "1" if newflag else "0")
|
2021-09-07 19:55:53 +02:00
|
|
|
|
|
|
|
# Whether we've bound a profile to this refid/dataid or not. This includes current profiles and any
|
|
|
|
# older game profiles that might exist that we should do a conversion from.
|
2022-10-15 20:56:30 +02:00
|
|
|
root.set_attribute("binded", "1" if bound else "0")
|
2021-09-07 19:55:53 +02:00
|
|
|
|
|
|
|
# Whether this version of the profile is expired (was converted to newer version). We support forwards
|
|
|
|
# and backwards compatibility so some games will always set this to 0.
|
2022-10-15 20:56:30 +02:00
|
|
|
root.set_attribute("expired", "1" if expired else "0")
|
2021-09-07 19:55:53 +02:00
|
|
|
|
|
|
|
# Whether to allow paseli, as enabled by the operator and arcade owner.
|
2022-10-15 20:56:30 +02:00
|
|
|
root.set_attribute("ecflag", "1" if paseli_enabled else "0")
|
2021-09-07 19:55:53 +02:00
|
|
|
|
|
|
|
# I have absolutely no idea what these do.
|
2022-10-15 20:56:30 +02:00
|
|
|
root.set_attribute("useridflag", "1")
|
|
|
|
root.set_attribute("extidflag", "1")
|
2021-09-07 19:55:53 +02:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_cardmng_authpass_request(self, request: Node) -> Node:
|
|
|
|
# Given a dataid/refid previously found via inquire, verify the pin
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
|
|
|
pin = request.attribute("pass")
|
2021-09-07 19:55:53 +02:00
|
|
|
userid = self.data.local.user.from_refid(self.game, self.version, refid)
|
|
|
|
if userid is not None:
|
|
|
|
valid = self.data.local.user.validate_pin(userid, pin)
|
|
|
|
else:
|
|
|
|
valid = False
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
|
|
|
root.set_attribute(
|
|
|
|
"status", str(Status.SUCCESS if valid else Status.INVALID_PIN)
|
|
|
|
)
|
2021-09-07 19:55:53 +02:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_cardmng_getrefid_request(self, request: Node) -> Node:
|
|
|
|
# Given a cardid and a pin, register the card with the system and generate a new dataid/refid + extid
|
2022-10-15 20:56:30 +02:00
|
|
|
cardid = request.attribute("cardid")
|
|
|
|
pin = request.attribute("passwd")
|
2021-09-07 19:55:53 +02:00
|
|
|
userid = self.data.local.user.create_account(cardid, pin)
|
|
|
|
if userid is None:
|
|
|
|
# This user can't be created
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
|
|
|
root.set_attribute("status", str(Status.NOT_ALLOWED))
|
2019-12-08 22:43:49 +01:00
|
|
|
return root
|
|
|
|
|
2021-09-07 19:55:53 +02:00
|
|
|
refid = self.data.local.user.create_refid(self.game, self.version, userid)
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
|
|
|
root.set_attribute("dataid", refid)
|
|
|
|
root.set_attribute("refid", refid)
|
2021-09-07 19:55:53 +02:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_cardmng_bindmodel_request(self, request: Node) -> Node:
|
|
|
|
# Given a refid, bind the user's card to the current version of the game
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
2021-09-07 19:55:53 +02:00
|
|
|
userid = self.data.local.user.from_refid(self.game, self.version, refid)
|
|
|
|
self.bind_profile(userid)
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
|
|
|
root.set_attribute("dataid", refid)
|
2021-09-07 19:55:53 +02:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_cardmng_getkeepspan_request(self, request: Node) -> Node:
|
|
|
|
# Unclear what this method does, return an arbitrary span
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
|
|
|
root.set_attribute("keepspan", "30")
|
2021-09-07 19:55:53 +02:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_cardmng_getdatalist_request(self, request: Node) -> Node:
|
|
|
|
# Unclear what this method does, return a dummy response
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("cardmng")
|
2021-09-07 19:55:53 +02:00
|
|
|
return root
|