2019-12-08 22:43:49 +01:00
|
|
|
|
import base64
|
|
|
|
|
import time
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
from bemani.client.base import BaseClient
|
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TheStarBishiBashiClient(BaseClient):
|
2022-10-15 20:56:30 +02:00
|
|
|
|
NAME = "TEST"
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
def verify_eventlog_write(self, location: str) -> None:
|
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
|
eventlog = Node.void("eventlog")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
call.add_child(eventlog)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
eventlog.set_attribute("method", "write")
|
|
|
|
|
eventlog.add_child(Node.u32("retrycnt", 0))
|
|
|
|
|
data = Node.void("data")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
eventlog.add_child(data)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
data.add_child(Node.string("eventid", "S_PWRON"))
|
|
|
|
|
data.add_child(Node.s32("eventorder", 0))
|
|
|
|
|
data.add_child(Node.u64("pcbtime", int(time.time() * 1000)))
|
|
|
|
|
data.add_child(Node.s64("gamesession", -1))
|
|
|
|
|
data.add_child(Node.string("strdata1", "1.7.6"))
|
|
|
|
|
data.add_child(Node.string("strdata2", ""))
|
|
|
|
|
data.add_child(Node.s64("numdata1", 1))
|
|
|
|
|
data.add_child(Node.s64("numdata2", 0))
|
|
|
|
|
data.add_child(Node.string("locationid", location))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
|
self.assert_path(resp, "response/eventlog/gamesession")
|
|
|
|
|
self.assert_path(resp, "response/eventlog/logsendflg")
|
|
|
|
|
self.assert_path(resp, "response/eventlog/logerrlevel")
|
|
|
|
|
self.assert_path(resp, "response/eventlog/evtidnosendflg")
|
|
|
|
|
|
|
|
|
|
def verify_system_getmaster(self) -> None:
|
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
|
system = Node.void("system")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
call.add_child(system)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
system.set_attribute("method", "getmaster")
|
|
|
|
|
data = Node.void("data")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
system.add_child(data)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
data.add_child(Node.string("gamekind", "IBB"))
|
|
|
|
|
data.add_child(Node.string("datatype", "S_SRVMSG"))
|
|
|
|
|
data.add_child(Node.string("datakey", "INFO"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
|
self.assert_path(resp, "response/system/result")
|
|
|
|
|
|
|
|
|
|
def verify_usergamedata_send(self, ref_id: str, msg_type: str) -> None:
|
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
|
|
# Set up profile write
|
|
|
|
|
profiledata = [
|
2022-10-15 20:56:30 +02:00
|
|
|
|
b"ffffffff",
|
|
|
|
|
b"IBBDAT00",
|
|
|
|
|
b"1",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"e474c1b",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"ff",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"0.000000",
|
|
|
|
|
b"",
|
|
|
|
|
b"",
|
|
|
|
|
b"",
|
|
|
|
|
b"\x96\xa2\x90\xdd\x92\xe8",
|
|
|
|
|
b"\x8d\x81\x8d`",
|
|
|
|
|
b"",
|
|
|
|
|
b"",
|
|
|
|
|
b"",
|
2019-12-08 22:43:49 +01:00
|
|
|
|
]
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
if msg_type == "new":
|
2019-12-08 22:43:49 +01:00
|
|
|
|
# New profile gets blank name, because we save over it at the end of the round.
|
2022-10-15 20:56:30 +02:00
|
|
|
|
profiledata[27] = b""
|
|
|
|
|
elif msg_type == "existing":
|
2019-12-08 22:43:49 +01:00
|
|
|
|
# Exiting profile gets our hardcoded name saved.
|
2022-10-15 20:56:30 +02:00
|
|
|
|
profiledata[27] = self.NAME.encode("shift-jis")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
|
playerdata = Node.void("playerdata")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
call.add_child(playerdata)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
playerdata.set_attribute("method", "usergamedata_send")
|
|
|
|
|
playerdata.add_child(Node.u32("retrycnt", 0))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
data = Node.void("data")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
playerdata.add_child(data)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
data.add_child(Node.string("eaid", ref_id))
|
|
|
|
|
data.add_child(Node.string("gamekind", "IBB"))
|
|
|
|
|
data.add_child(Node.u32("datanum", 1))
|
|
|
|
|
record = Node.void("record")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
data.add_child(record)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
d = Node.string("d", base64.b64encode(b",".join(profiledata)).decode("ascii"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
record.add_child(d)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
d.add_child(Node.string("bin1", ""))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
self.assert_path(resp, "response/playerdata/result")
|
|
|
|
|
|
|
|
|
|
def verify_usergamedata_recv(self, ref_id: str) -> str:
|
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
|
playerdata = Node.void("playerdata")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
call.add_child(playerdata)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
playerdata.set_attribute("method", "usergamedata_recv")
|
|
|
|
|
data = Node.void("data")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
playerdata.add_child(data)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
data.add_child(Node.string("eaid", ref_id))
|
|
|
|
|
data.add_child(Node.string("gamekind", "IBB"))
|
|
|
|
|
data.add_child(Node.u32("recv_num", 1))
|
|
|
|
|
data.add_child(Node.string("recv_csv", "IBBDAT00,3fffffffff"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
self.assert_path(resp, "response/playerdata/result")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/player/record/d/bin1")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/player/record_num")
|
|
|
|
|
|
|
|
|
|
# Grab binary data, parse out name
|
2022-10-15 20:56:30 +02:00
|
|
|
|
bindata = resp.child_value("playerdata/player/record/d")
|
|
|
|
|
profiledata = base64.b64decode(bindata).split(b",")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# We lob off the first two values in returning profile, so the name is offset by two
|
2022-10-15 20:56:30 +02:00
|
|
|
|
return profiledata[25].decode("shift-jis")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
def verify(self, cardid: Optional[str]) -> None:
|
|
|
|
|
# Verify boot sequence is okay
|
|
|
|
|
self.verify_services_get(
|
|
|
|
|
expected_services=[
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"pcbtracker",
|
|
|
|
|
"pcbevent",
|
|
|
|
|
"local",
|
|
|
|
|
"message",
|
|
|
|
|
"facility",
|
|
|
|
|
"cardmng",
|
|
|
|
|
"package",
|
|
|
|
|
"posevent",
|
|
|
|
|
"pkglist",
|
|
|
|
|
"dlstatus",
|
|
|
|
|
"eacoin",
|
|
|
|
|
"lobby",
|
|
|
|
|
"ntp",
|
|
|
|
|
"keepalive",
|
2019-12-08 22:43:49 +01:00
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
paseli_enabled = self.verify_pcbtracker_alive()
|
|
|
|
|
self.verify_message_get()
|
|
|
|
|
self.verify_package_list()
|
|
|
|
|
location = self.verify_facility_get()
|
|
|
|
|
self.verify_pcbevent_put()
|
|
|
|
|
self.verify_eventlog_write(location)
|
|
|
|
|
self.verify_system_getmaster()
|
|
|
|
|
|
|
|
|
|
# Verify card registration and profile lookup
|
|
|
|
|
if cardid is not None:
|
|
|
|
|
card = cardid
|
|
|
|
|
else:
|
|
|
|
|
card = self.random_card()
|
2020-01-07 22:29:07 +01:00
|
|
|
|
print(f"Generated random card ID {card} for use.")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
if cardid is None:
|
2024-01-02 03:46:24 +01:00
|
|
|
|
self.verify_cardmng_inquire(card, msg_type="unregistered", paseli_enabled=paseli_enabled)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
ref_id = self.verify_cardmng_getrefid(card)
|
|
|
|
|
if len(ref_id) != 16:
|
2024-01-02 03:46:24 +01:00
|
|
|
|
raise Exception(f"Invalid refid '{ref_id}' returned when registering card")
|
|
|
|
|
if ref_id != self.verify_cardmng_inquire(card, msg_type="new", paseli_enabled=paseli_enabled):
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Invalid refid '{ref_id}' returned when querying card")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
# Bishi doesn't read a new profile, it just writes out CSV for a blank one
|
2022-10-15 20:56:30 +02:00
|
|
|
|
self.verify_usergamedata_send(ref_id, msg_type="new")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
else:
|
|
|
|
|
print("Skipping new card checks for existing card")
|
2024-01-02 03:46:24 +01:00
|
|
|
|
ref_id = self.verify_cardmng_inquire(card, msg_type="query", paseli_enabled=paseli_enabled)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Verify pin handling and return card handling
|
|
|
|
|
self.verify_cardmng_authpass(ref_id, correct=True)
|
|
|
|
|
self.verify_cardmng_authpass(ref_id, correct=False)
|
2024-01-02 03:46:24 +01:00
|
|
|
|
if ref_id != self.verify_cardmng_inquire(card, msg_type="query", paseli_enabled=paseli_enabled):
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Invalid refid '{ref_id}' returned when querying card")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
if cardid is None:
|
|
|
|
|
# Verify profile saving
|
|
|
|
|
name = self.verify_usergamedata_recv(ref_id)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
if name != "":
|
|
|
|
|
raise Exception("New profile has a name associated with it!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
self.verify_usergamedata_send(ref_id, msg_type="existing")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
name = self.verify_usergamedata_recv(ref_id)
|
|
|
|
|
if name != self.NAME:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception("Existing profile has no name associated with it!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
else:
|
|
|
|
|
print("Skipping score checks for existing card")
|