2019-12-08 22:43:49 +01:00
|
|
|
|
import random
|
|
|
|
|
import time
|
|
|
|
|
from typing import Optional, Dict, List, Tuple, Any
|
|
|
|
|
|
|
|
|
|
from bemani.client.base import BaseClient
|
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PopnMusicFantasiaClient(BaseClient):
|
2022-10-15 20:56:30 +02:00
|
|
|
|
NAME = "TEST"
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
def verify_game_active(self) -> None:
|
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
call.add_child(game)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
game.set_attribute("method", "active")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Add what Pop'n 20 would add after full unlock
|
2022-10-15 20:56:30 +02:00
|
|
|
|
game.set_attribute("method", "active")
|
|
|
|
|
game.add_child(Node.s8("event", 0))
|
|
|
|
|
game.add_child(Node.s8("card_use", 0))
|
|
|
|
|
game.add_child(Node.string("name", ""))
|
|
|
|
|
game.add_child(Node.string("location_id", "JP-1"))
|
|
|
|
|
game.add_child(Node.string("shop_name_facility", "."))
|
|
|
|
|
game.add_child(Node.s8("pref", 50))
|
|
|
|
|
game.add_child(Node.string("shop_addr", "127.0.0.1 10000"))
|
|
|
|
|
game.add_child(Node.string("shop_name", ""))
|
|
|
|
|
game.add_child(Node.string("eacoin_price", "200,260,200,200"))
|
|
|
|
|
game.add_child(Node.s8("eacoin_available", 1))
|
|
|
|
|
game.add_child(Node.s8("dipswitch", 0))
|
|
|
|
|
game.add_child(Node.u8("max_stage", 1))
|
|
|
|
|
game.add_child(Node.u8("difficult", 4))
|
|
|
|
|
game.add_child(Node.s8("free_play", 1))
|
|
|
|
|
game.add_child(Node.s8("event_mode", 0))
|
|
|
|
|
game.add_child(Node.s8("popn_card", 0))
|
|
|
|
|
game.add_child(Node.s16("close_time", -1))
|
|
|
|
|
game.add_child(Node.s32("game_phase", 2))
|
|
|
|
|
game.add_child(Node.s32("net_phase", 0))
|
|
|
|
|
game.add_child(Node.s32("event_phase", 0))
|
|
|
|
|
game.add_child(Node.s32("card_phase", 3))
|
|
|
|
|
game.add_child(Node.s32("ir_phase", 0))
|
|
|
|
|
game.add_child(Node.u8("coin_to_credit", 1))
|
|
|
|
|
game.add_child(Node.u8("credit_to_start", 2))
|
|
|
|
|
game.add_child(Node.s32("sound_attract", 100))
|
|
|
|
|
game.add_child(Node.s8("bookkeeping", 0))
|
|
|
|
|
game.add_child(Node.s8("set_clock", 0))
|
|
|
|
|
game.add_child(Node.s32("local_clock_sec", 80011))
|
|
|
|
|
game.add_child(Node.s32("revision_sec", 0))
|
|
|
|
|
game.add_child(Node.string("crash_log", ""))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("pnm20/game", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
|
self.assert_path(resp, "response/game/@status")
|
|
|
|
|
|
|
|
|
|
def verify_game_get(self) -> None:
|
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
call.add_child(game)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
game.set_attribute("location_id", "JP-1")
|
|
|
|
|
game.set_attribute("method", "get")
|
|
|
|
|
game.add_child(Node.s8("card_enable", 0))
|
|
|
|
|
game.add_child(Node.s8("card_soldout", 1))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("pnm20/game", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
|
self.assert_path(resp, "response/game")
|
|
|
|
|
|
|
|
|
|
for name in [
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"game_phase",
|
|
|
|
|
"ir_phase",
|
|
|
|
|
"event_phase",
|
|
|
|
|
"netvs_phase",
|
|
|
|
|
"illust_phase",
|
|
|
|
|
"psp_phase",
|
|
|
|
|
"other_phase",
|
|
|
|
|
"jubeat_phase",
|
|
|
|
|
"public_phase",
|
|
|
|
|
"kac_phase",
|
|
|
|
|
"local_matching_enable",
|
|
|
|
|
"n_matching_sec",
|
|
|
|
|
"l_matching_sec",
|
|
|
|
|
"is_check_cpu",
|
|
|
|
|
"week_no",
|
2019-12-08 22:43:49 +01:00
|
|
|
|
]:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
node = resp.child("game").child(name)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
if node is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Missing node '{name}' in response!")
|
|
|
|
|
if node.data_type != "s32":
|
|
|
|
|
raise Exception(f"Node '{name}' has wrong data type!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
sel_ranking = resp.child("game").child("sel_ranking")
|
|
|
|
|
up_ranking = resp.child("game").child("up_ranking")
|
|
|
|
|
ng_illust = resp.child("game").child("ng_illust")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2021-09-03 06:35:13 +02:00
|
|
|
|
for name, node, dtype, length in [
|
2022-10-15 20:56:30 +02:00
|
|
|
|
("sel_ranking", sel_ranking, "s16", 10),
|
|
|
|
|
("up_ranking", up_ranking, "s16", 10),
|
|
|
|
|
("ng_illust", ng_illust, "s32", 64),
|
2019-12-08 22:43:49 +01:00
|
|
|
|
]:
|
|
|
|
|
if node is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Missing node '{name}' in response!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if node.data_type != dtype:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Node '{name}' has wrong data type!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if not node.is_array:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Node '{name}' is not array!")
|
2021-09-03 06:35:13 +02:00
|
|
|
|
if len(node.value) != length:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Node '{name}' is wrong array length!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2024-01-02 03:46:24 +01:00
|
|
|
|
def verify_playerdata_get(self, ref_id: str, msg_type: str) -> Optional[Dict[str, Any]]:
|
2019-12-08 22:43:49 +01:00
|
|
|
|
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", "get")
|
|
|
|
|
if msg_type == "new":
|
2024-01-02 03:46:24 +01:00
|
|
|
|
playerdata.set_attribute("model", self.config["old_profile_model"].split(":")[0])
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
playerdata.add_child(Node.string("ref_id", ref_id))
|
|
|
|
|
playerdata.add_child(Node.string("shop_name", ""))
|
|
|
|
|
playerdata.add_child(Node.s8("pref", 50))
|
|
|
|
|
playerdata.add_child(Node.s32("navigate", 1))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("pnm20/playerdata", call)
|
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
|
|
|
|
# Verify that response is correct
|
|
|
|
|
self.assert_path(resp, "response/playerdata/@status")
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
status = int(resp.child("playerdata").attribute("status"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if status != 109:
|
2024-01-02 03:46:24 +01:00
|
|
|
|
raise Exception(f"Reference ID '{ref_id}' returned invalid status '{status}'")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# No score data
|
|
|
|
|
return None
|
2022-10-15 20:56:30 +02:00
|
|
|
|
elif msg_type == "query":
|
2019-12-08 22:43:49 +01:00
|
|
|
|
# Verify that the response is correct
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/g_pm_id")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/name")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/my_best")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/latest_music")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/clear_medal")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/clear_medal_sub")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/player_card")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/player_card_ex")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/hiscore")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/netvs")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/sp_data")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/reflec_data")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/navigate")
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
name = resp.child("playerdata").child("base").child("name").value
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if name != self.NAME:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Invalid name '{name}' returned for Ref ID '{ref_id}'")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Extract and return score data
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/clear_medal")
|
|
|
|
|
|
|
|
|
|
def transform_medals(medal: int) -> Tuple[int, int, int, int]:
|
|
|
|
|
return (
|
|
|
|
|
(medal >> 0) & 0xF,
|
|
|
|
|
(medal >> 4) & 0xF,
|
|
|
|
|
(medal >> 8) & 0xF,
|
|
|
|
|
(medal >> 12) & 0xF,
|
|
|
|
|
)
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
medals = [
|
2024-01-02 03:46:24 +01:00
|
|
|
|
transform_medals(medal) for medal in resp.child("playerdata").child("base").child("clear_medal").value
|
2022-10-15 20:56:30 +02:00
|
|
|
|
]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
hiscore = resp.child("playerdata").child("hiscore").value
|
2019-12-08 22:43:49 +01:00
|
|
|
|
hiscores = []
|
|
|
|
|
for i in range(0, len(hiscore) * 8, 17):
|
|
|
|
|
byte_offset = int(i / 8)
|
|
|
|
|
bit_offset = int(i % 8)
|
|
|
|
|
|
|
|
|
|
value = hiscore[byte_offset]
|
|
|
|
|
value = value + (hiscore[byte_offset + 1] << 8)
|
|
|
|
|
value = value + (hiscore[byte_offset + 2] << 16)
|
|
|
|
|
|
|
|
|
|
value = value >> bit_offset
|
|
|
|
|
hiscores.append(value & 0x1FFFF)
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
scores = [
|
2024-01-02 03:46:24 +01:00
|
|
|
|
(hiscores[x], hiscores[x + 1], hiscores[x + 2], hiscores[x + 3]) for x in range(0, len(hiscores), 4)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
return {"medals": medals, "scores": scores}
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Unrecognized message type '{msg_type}'")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
def verify_playerdata_set(self, ref_id: str, scores: List[Dict[str, Any]]) -> None:
|
|
|
|
|
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", "set")
|
|
|
|
|
playerdata.set_attribute("ref_id", ref_id)
|
|
|
|
|
playerdata.set_attribute("shop_name", "")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Add required children
|
2022-10-15 20:56:30 +02:00
|
|
|
|
playerdata.add_child(Node.s16("chara", 1543))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Add requested scores
|
|
|
|
|
for score in scores:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
stage = Node.void("stage")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
playerdata.add_child(stage)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
stage.add_child(Node.s16("no", score["id"]))
|
|
|
|
|
stage.add_child(
|
|
|
|
|
Node.u8(
|
|
|
|
|
"sheet",
|
|
|
|
|
{
|
|
|
|
|
0: 2,
|
|
|
|
|
1: 0,
|
|
|
|
|
2: 1,
|
|
|
|
|
3: 3,
|
|
|
|
|
}[score["chart"]],
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-01-02 03:46:24 +01:00
|
|
|
|
stage.add_child(Node.u16("n_data", (score["medal"] << (4 * score["chart"]))))
|
2022-10-15 20:56:30 +02:00
|
|
|
|
stage.add_child(Node.u8("e_data", 0))
|
|
|
|
|
stage.add_child(Node.s32("score", score["score"]))
|
|
|
|
|
stage.add_child(Node.u8("ojama_1", 0))
|
|
|
|
|
stage.add_child(Node.u8("ojama_2", 0))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("pnm20/playerdata", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Verify nodes that cause crashes if they don't exist
|
|
|
|
|
self.assert_path(resp, "response/playerdata/name")
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
name = resp.child("playerdata").child("name").value
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if name != self.NAME:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(f"Invalid name '{name}' returned for Ref ID '{ref_id}'")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
def verify_playerdata_new(self, ref_id: str) -> None:
|
|
|
|
|
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", "new")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
playerdata.add_child(Node.string("ref_id", ref_id))
|
|
|
|
|
playerdata.add_child(Node.string("name", self.NAME))
|
|
|
|
|
playerdata.add_child(Node.string("shop_name", ""))
|
|
|
|
|
playerdata.add_child(Node.s8("pref", 51))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
|
resp = self.exchange("pnm20/playerdata", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Verify nodes that cause crashes if they don't exist
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/g_pm_id")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/name")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/my_best")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/latest_music")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/clear_medal")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/base/clear_medal_sub")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/player_card")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/player_card_ex")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/hiscore")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/netvs")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/sp_data")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/reflec_data")
|
|
|
|
|
self.assert_path(resp, "response/playerdata/navigate")
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
self.verify_facility_get()
|
|
|
|
|
self.verify_pcbevent_put()
|
|
|
|
|
self.verify_game_active()
|
|
|
|
|
self.verify_game_get()
|
|
|
|
|
|
|
|
|
|
# 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")
|
|
|
|
|
self.verify_playerdata_get(ref_id, msg_type="new")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
self.verify_playerdata_new(ref_id)
|
|
|
|
|
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 score handling
|
2022-10-15 20:56:30 +02:00
|
|
|
|
scores = self.verify_playerdata_get(ref_id, msg_type="query")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if scores is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception("Expected to get scores back, didn't get anything!")
|
|
|
|
|
for medal in scores["medals"]:
|
2019-12-08 22:43:49 +01:00
|
|
|
|
for i in range(4):
|
|
|
|
|
if medal[i] != 0:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception("Got nonzero medals count on a new card!")
|
|
|
|
|
for score in scores["scores"]:
|
2019-12-08 22:43:49 +01:00
|
|
|
|
for i in range(4):
|
|
|
|
|
if score[i] != 0:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception("Got nonzero scores count on a new card!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
for phase in [1, 2]:
|
|
|
|
|
if phase == 1:
|
|
|
|
|
dummyscores = [
|
|
|
|
|
# An okay score on a chart
|
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"id": 987,
|
|
|
|
|
"chart": 2,
|
|
|
|
|
"medal": 5,
|
|
|
|
|
"score": 76543,
|
2019-12-08 22:43:49 +01:00
|
|
|
|
},
|
|
|
|
|
# A good score on an easier chart of the same song
|
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"id": 987,
|
|
|
|
|
"chart": 0,
|
|
|
|
|
"medal": 6,
|
|
|
|
|
"score": 99999,
|
2019-12-08 22:43:49 +01:00
|
|
|
|
},
|
|
|
|
|
# A bad score on a hard chart
|
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"id": 741,
|
|
|
|
|
"chart": 3,
|
|
|
|
|
"medal": 2,
|
|
|
|
|
"score": 45000,
|
2019-12-08 22:43:49 +01:00
|
|
|
|
},
|
|
|
|
|
# A terrible score on an easy chart
|
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"id": 742,
|
|
|
|
|
"chart": 1,
|
|
|
|
|
"medal": 2,
|
|
|
|
|
"score": 1,
|
2019-12-08 22:43:49 +01:00
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
# Random score to add in
|
|
|
|
|
songid = random.randint(907, 950)
|
|
|
|
|
chartid = random.randint(0, 3)
|
|
|
|
|
score = random.randint(0, 100000)
|
|
|
|
|
medal = random.choice([1, 2, 3, 5, 6, 7, 9, 10, 11, 15])
|
2022-10-15 20:56:30 +02:00
|
|
|
|
dummyscores.append(
|
|
|
|
|
{
|
|
|
|
|
"id": songid,
|
|
|
|
|
"chart": chartid,
|
|
|
|
|
"medal": medal,
|
|
|
|
|
"score": score,
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if phase == 2:
|
|
|
|
|
dummyscores = [
|
|
|
|
|
# A better score on the same chart
|
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"id": 987,
|
|
|
|
|
"chart": 2,
|
|
|
|
|
"medal": 5,
|
|
|
|
|
"score": 98765,
|
2019-12-08 22:43:49 +01:00
|
|
|
|
},
|
|
|
|
|
# A worse score on another same chart
|
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
|
"id": 987,
|
|
|
|
|
"chart": 0,
|
|
|
|
|
"medal": 3,
|
|
|
|
|
"score": 12345,
|
|
|
|
|
"expected_score": 99999,
|
|
|
|
|
"expected_medal": 6,
|
2019-12-08 22:43:49 +01:00
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.verify_playerdata_set(ref_id, dummyscores)
|
2022-10-15 20:56:30 +02:00
|
|
|
|
scores = self.verify_playerdata_get(ref_id, msg_type="query")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
for score in dummyscores:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
newscore = scores["scores"][score["id"]][score["chart"]]
|
|
|
|
|
newmedal = scores["medals"][score["id"]][score["chart"]]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
|
if "expected_score" in score:
|
|
|
|
|
expected_score = score["expected_score"]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
expected_score = score["score"]
|
|
|
|
|
if "expected_medal" in score:
|
|
|
|
|
expected_medal = score["expected_medal"]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
expected_medal = score["medal"]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
if newscore != expected_score:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(
|
|
|
|
|
f'Expected a score of \'{expected_score}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got score \'{newscore}\''
|
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
if newmedal != expected_medal:
|
2022-10-15 20:56:30 +02:00
|
|
|
|
raise Exception(
|
|
|
|
|
f'Expected a medal of \'{expected_medal}\' for song \'{score["id"]}\' chart \'{score["chart"]}\' but got medal \'{newmedal}\''
|
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
# Sleep so we don't end up putting in score history on the same second
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
else:
|
|
|
|
|
print("Skipping score checks for existing card")
|
|
|
|
|
|
|
|
|
|
# Verify paseli handling
|
|
|
|
|
if paseli_enabled:
|
|
|
|
|
print("PASELI enabled for this PCBID, executing PASELI checks")
|
|
|
|
|
else:
|
|
|
|
|
print("PASELI disabled for this PCBID, skipping PASELI checks")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
sessid, balance = self.verify_eacoin_checkin(card)
|
|
|
|
|
if balance == 0:
|
|
|
|
|
print("Skipping PASELI consume check because card has 0 balance")
|
|
|
|
|
else:
|
|
|
|
|
self.verify_eacoin_consume(sessid, balance, random.randint(0, balance))
|
|
|
|
|
self.verify_eacoin_checkout(sessid)
|