2019-12-08 22:43:49 +01:00
import random
import time
from typing import Any , Dict , List , Optional
from bemani . client . base import BaseClient
from bemani . protocol import Node
class DDRX2Client ( BaseClient ) :
2022-10-15 20:56:30 +02:00
NAME = " TEST "
2019-12-08 22:43:49 +01:00
def verify_cardmng_getkeepspan ( self ) - > None :
call = self . call_node ( )
# Calculate model node
2022-10-15 20:56:30 +02:00
model = " : " . join ( self . config [ " model " ] . split ( " : " ) [ : 4 ] )
2019-12-08 22:43:49 +01:00
# Construct node
2022-10-15 20:56:30 +02:00
cardmng = Node . void ( " cardmng " )
cardmng . set_attribute ( " method " , " getkeepspan " )
cardmng . set_attribute ( " model " , model )
2019-12-08 22:43:49 +01:00
call . add_child ( cardmng )
# 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/cardmng/@keepspan " )
def verify_game_shop ( self , loc : str ) - > None :
call = self . call_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 " , " shop " )
game . set_attribute ( " diff " , " 3 " )
game . set_attribute ( " time " , " 60 " )
game . set_attribute ( " close " , " 0 " )
game . set_attribute ( " during " , " 1 " )
game . set_attribute ( " stage " , " 1 " )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " machine " , " 2 " )
game . set_attribute ( " area " , " 0 " )
game . set_attribute ( " soft " , self . config [ " model " ] )
game . set_attribute ( " close_t " , " 0 " )
game . set_attribute ( " region " , " . " )
game . set_attribute ( " is_paseli " , " 1 " )
game . set_attribute ( " ip " , " 1.5.7.3 " )
game . set_attribute ( " pay " , " 0 " )
game . set_attribute ( " softid " , self . pcbid )
game . set_attribute ( " first " , " 1 " )
game . set_attribute ( " boot " , " 34 " )
game . set_attribute ( " type " , " 0 " )
game . set_attribute ( " coin " , " 02.01.--.--.01.G " )
game . set_attribute ( " name " , " T E S T " )
game . set_attribute ( " mac " , " 00:11:22:33:44:55 " )
game . set_attribute ( " loc " , loc )
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/game/@stop " )
def verify_game_common ( self ) - > None :
call = self . call_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 " , " common " )
game . set_attribute ( " ver " , " 1 " )
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/game/flag/@id " )
self . assert_path ( resp , " response/game/flag/@s1 " )
self . assert_path ( resp , " response/game/flag/@s2 " )
self . assert_path ( resp , " response/game/flag/@t " )
self . assert_path ( resp , " response/game/cnt_music " )
def verify_game_hiscore ( self ) - > None :
call = self . call_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 " , " hiscore " )
game . set_attribute ( " ver " , " 1 " )
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/game " )
2022-10-15 20:56:30 +02:00
for child in resp . child ( " game " ) . children :
self . assert_path ( child , " music/@reclink_num " )
self . assert_path ( child , " music/type/@diff " )
self . assert_path ( child , " music/type/name " )
self . assert_path ( child , " music/type/score " )
self . assert_path ( child , " music/type/area " )
self . assert_path ( child , " music/type/rank " )
self . assert_path ( child , " music/type/combo_type " )
2019-12-08 22:43:49 +01:00
def verify_game_message ( self ) - > None :
call = self . call_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 " , " message " )
game . set_attribute ( " ver " , " 1 " )
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/game " )
def verify_game_ranking ( self ) - > None :
call = self . call_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 " , " ranking " )
game . set_attribute ( " ver " , " 1 " )
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/game " )
def verify_game_log ( self ) - > None :
call = self . call_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 " , " log " )
game . set_attribute ( " type " , " 0 " )
game . set_attribute ( " soft " , self . config [ " model " ] )
game . set_attribute ( " softid " , self . pcbid )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " boot " , " 34 " )
game . set_attribute ( " mac " , " 00:11:22:33:44:55 " )
clear = Node . void ( " clear " )
2019-12-08 22:43:49 +01:00
game . add_child ( clear )
2022-10-15 20:56:30 +02:00
clear . set_attribute ( " book " , " 0 " )
clear . set_attribute ( " edit " , " 0 " )
clear . set_attribute ( " rank " , " 0 " )
clear . set_attribute ( " set " , " 0 " )
auto = Node . void ( " auto " )
2019-12-08 22:43:49 +01:00
game . add_child ( auto )
2022-10-15 20:56:30 +02:00
auto . set_attribute ( " book " , " 1 " )
auto . set_attribute ( " edit " , " 1 " )
auto . set_attribute ( " rank " , " 1 " )
auto . set_attribute ( " set " , " 1 " )
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/game " )
def verify_game_lock ( self , ref_id : str , play : int ) - > None :
call = self . call_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 ( " refid " , ref_id )
game . set_attribute ( " method " , " lock " )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " play " , str ( play ) )
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/game/@now_login " )
def verify_game_new ( self , ref_id : str ) - > None :
# Pad the name to 8 characters
name = self . NAME [ : 8 ]
while len ( name ) < 8 :
2022-10-15 20:56:30 +02:00
name = name + " "
2019-12-08 22:43:49 +01:00
call = self . call_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 " , " new " )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " name " , name )
game . set_attribute ( " area " , " 51 " )
game . set_attribute ( " old " , " 0 " )
game . set_attribute ( " refid " , ref_id )
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/game " )
def verify_game_load ( self , ref_id : str , msg_type : str ) - > Dict [ str , Any ] :
call = self . call_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 " , " load " )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " refid " , ref_id )
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
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/game/@none " )
return { }
2022-10-15 20:56:30 +02:00
if msg_type == " existing " :
2019-12-08 22:43:49 +01:00
# Verify existing profile and return info
self . assert_path ( resp , " response/game/seq " )
self . assert_path ( resp , " response/game/code " )
self . assert_path ( resp , " response/game/name " )
self . assert_path ( resp , " response/game/area " )
self . assert_path ( resp , " response/game/cnt_s " )
self . assert_path ( resp , " response/game/cnt_d " )
self . assert_path ( resp , " response/game/cnt_b " )
self . assert_path ( resp , " response/game/cnt_m0 " )
self . assert_path ( resp , " response/game/cnt_m1 " )
self . assert_path ( resp , " response/game/cnt_m2 " )
self . assert_path ( resp , " response/game/cnt_m3 " )
self . assert_path ( resp , " response/game/exp " )
self . assert_path ( resp , " response/game/exp_o " )
self . assert_path ( resp , " response/game/star " )
self . assert_path ( resp , " response/game/star_c " )
self . assert_path ( resp , " response/game/combo " )
self . assert_path ( resp , " response/game/timing_diff " )
self . assert_path ( resp , " response/game/chara " )
self . assert_path ( resp , " response/game/chara_opt " )
self . assert_path ( resp , " response/game/last/@cate " )
self . assert_path ( resp , " response/game/last/@cid " )
self . assert_path ( resp , " response/game/last/@ctype " )
self . assert_path ( resp , " response/game/last/@fri " )
self . assert_path ( resp , " response/game/last/@mid " )
self . assert_path ( resp , " response/game/last/@mode " )
self . assert_path ( resp , " response/game/last/@mtype " )
self . assert_path ( resp , " response/game/last/@sid " )
self . assert_path ( resp , " response/game/last/@sort " )
self . assert_path ( resp , " response/game/last/@style " )
self . assert_path ( resp , " response/game/gr_s/@gr1 " )
self . assert_path ( resp , " response/game/gr_s/@gr2 " )
self . assert_path ( resp , " response/game/gr_s/@gr3 " )
self . assert_path ( resp , " response/game/gr_s/@gr4 " )
self . assert_path ( resp , " response/game/gr_s/@gr5 " )
self . assert_path ( resp , " response/game/gr_d/@gr1 " )
self . assert_path ( resp , " response/game/gr_d/@gr2 " )
self . assert_path ( resp , " response/game/gr_d/@gr3 " )
self . assert_path ( resp , " response/game/gr_d/@gr4 " )
self . assert_path ( resp , " response/game/gr_d/@gr5 " )
self . assert_path ( resp , " response/game/opt " )
self . assert_path ( resp , " response/game/opt_ex " )
self . assert_path ( resp , " response/game/flag " )
self . assert_path ( resp , " response/game/rank " )
2022-10-15 20:56:30 +02:00
gr_s = resp . child ( " game/gr_s " )
gr_d = resp . child ( " game/gr_d " )
2019-12-08 22:43:49 +01:00
return {
2022-10-15 20:56:30 +02:00
" name " : resp . child_value ( " game/name " ) ,
" single_plays " : resp . child_value ( " game/cnt_s " ) ,
" double_plays " : resp . child_value ( " game/cnt_d " ) ,
" groove_single " : [
int ( gr_s . attribute ( " gr1 " ) ) ,
int ( gr_s . attribute ( " gr2 " ) ) ,
int ( gr_s . attribute ( " gr3 " ) ) ,
int ( gr_s . attribute ( " gr4 " ) ) ,
int ( gr_s . attribute ( " gr5 " ) ) ,
2019-12-08 22:43:49 +01:00
] ,
2022-10-15 20:56:30 +02:00
" groove_double " : [
int ( gr_d . attribute ( " gr1 " ) ) ,
int ( gr_d . attribute ( " gr2 " ) ) ,
int ( gr_d . attribute ( " gr3 " ) ) ,
int ( gr_d . attribute ( " gr4 " ) ) ,
int ( gr_d . attribute ( " gr5 " ) ) ,
2019-12-08 22:43:49 +01:00
] ,
}
2022-10-15 20:56:30 +02:00
raise Exception ( " Unknown load type! " )
2019-12-08 22:43:49 +01:00
def verify_game_load_m ( self , ref_id : str ) - > Dict [ int , Dict [ int , Dict [ str , Any ] ] ] :
call = self . call_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 ( " ver " , " 1 " )
game . set_attribute ( " all " , " 1 " )
game . set_attribute ( " refid " , ref_id )
game . set_attribute ( " method " , " load_m " )
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
scores : Dict [ int , Dict [ int , Dict [ str , Any ] ] ] = { }
self . assert_path ( resp , " response/game " )
2022-10-15 20:56:30 +02:00
for child in resp . child ( " game " ) . children :
self . assert_path ( child , " music/@reclink " )
reclink = int ( child . attribute ( " reclink " ) )
2019-12-08 22:43:49 +01:00
for typenode in child . children :
2022-10-15 20:56:30 +02:00
self . assert_path ( typenode , " type/@diff " )
self . assert_path ( typenode , " type/score " )
self . assert_path ( typenode , " type/count " )
self . assert_path ( typenode , " type/rank " )
self . assert_path ( typenode , " type/combo_type " )
chart = int ( typenode . attribute ( " diff " ) )
2019-12-08 22:43:49 +01:00
vals = {
2022-10-15 20:56:30 +02:00
" score " : typenode . child_value ( " score " ) ,
" count " : typenode . child_value ( " count " ) ,
" rank " : typenode . child_value ( " rank " ) ,
" halo " : typenode . child_value ( " combo_type " ) ,
2019-12-08 22:43:49 +01:00
}
if reclink not in scores :
scores [ reclink ] = { }
scores [ reclink ] [ chart ] = vals
return scores
def verify_game_load_c ( self , ref_id : str ) - > Dict [ int , Dict [ int , Dict [ str , Any ] ] ] :
call = self . call_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 " , " load_c " )
game . set_attribute ( " refid " , ref_id )
game . set_attribute ( " ver " , " 1 " )
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
courses : Dict [ int , Dict [ int , Dict [ str , Any ] ] ] = { }
self . assert_path ( resp , " response/game/course " )
2022-10-15 20:56:30 +02:00
courseblob = resp . child_value ( " game/course " )
2019-12-08 22:43:49 +01:00
index = 0
2022-10-15 20:56:30 +02:00
for chunk in [ courseblob [ i : ( i + 8 ) ] for i in range ( 0 , len ( courseblob ) , 8 ) ] :
2019-12-08 22:43:49 +01:00
if any ( [ v != 0 for v in chunk ] ) :
course = int ( index / 4 )
chart = index % 4
vals = {
2022-10-15 20:56:30 +02:00
" score " : chunk [ 0 ] * 10000 + chunk [ 1 ] ,
" combo " : chunk [ 2 ] ,
" rank " : chunk [ 3 ] ,
" stage " : chunk [ 5 ] ,
" combo_type " : chunk [ 6 ] ,
2019-12-08 22:43:49 +01:00
}
if course not in courses :
courses [ course ] = { }
courses [ course ] [ chart ] = vals
index = index + 1
return courses
2024-01-02 03:46:24 +01:00
def verify_game_save ( self , ref_id : str , style : int , gauge : Optional [ List [ int ] ] = None ) - > None :
2019-12-08 22:43:49 +01:00
gauge = gauge or [ 0 , 0 , 0 , 0 , 0 ]
call = self . call_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 " , " save " )
game . set_attribute ( " refid " , ref_id )
game . set_attribute ( " ver " , " 1 " )
last = Node . void ( " last " )
2019-12-08 22:43:49 +01:00
game . add_child ( last )
2022-10-15 20:56:30 +02:00
last . set_attribute ( " mode " , " 1 " )
last . set_attribute ( " style " , str ( style ) )
gr = Node . void ( " gr " )
2019-12-08 22:43:49 +01:00
game . add_child ( gr )
2022-10-15 20:56:30 +02:00
gr . set_attribute ( " gr1 " , str ( gauge [ 0 ] ) )
gr . set_attribute ( " gr2 " , str ( gauge [ 1 ] ) )
gr . set_attribute ( " gr3 " , str ( gauge [ 2 ] ) )
gr . set_attribute ( " gr4 " , str ( gauge [ 3 ] ) )
gr . set_attribute ( " gr5 " , str ( gauge [ 4 ] ) )
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/game " )
def verify_game_score ( self , ref_id : str , songid : int , chart : int ) - > List [ int ] :
call = self . call_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 " , " score " )
game . set_attribute ( " mid " , str ( songid ) )
game . set_attribute ( " refid " , ref_id )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " type " , str ( chart ) )
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/game/@sc1 " )
self . assert_path ( resp , " response/game/@sc2 " )
self . assert_path ( resp , " response/game/@sc3 " )
self . assert_path ( resp , " response/game/@sc4 " )
self . assert_path ( resp , " response/game/@sc5 " )
return [
2022-10-15 20:56:30 +02:00
int ( resp . child ( " game " ) . attribute ( " sc1 " ) ) ,
int ( resp . child ( " game " ) . attribute ( " sc2 " ) ) ,
int ( resp . child ( " game " ) . attribute ( " sc3 " ) ) ,
int ( resp . child ( " game " ) . attribute ( " sc4 " ) ) ,
int ( resp . child ( " game " ) . attribute ( " sc5 " ) ) ,
2019-12-08 22:43:49 +01:00
]
def verify_game_save_m ( self , ref_id : str , score : Dict [ str , Any ] ) - > None :
call = self . call_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 ( " refid " , ref_id )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " mtype " , str ( score [ " chart " ] ) )
game . set_attribute ( " mid " , str ( score [ " id " ] ) )
game . set_attribute ( " method " , " save_m " )
data = Node . void ( " data " )
2019-12-08 22:43:49 +01:00
game . add_child ( data )
2022-10-15 20:56:30 +02:00
data . set_attribute ( " perf " , " 1 " if score [ " halo " ] > = 2 else " 0 " )
data . set_attribute ( " score " , str ( score [ " score " ] ) )
data . set_attribute ( " rank " , str ( score [ " rank " ] ) )
data . set_attribute ( " phase " , " 1 " )
data . set_attribute ( " full " , " 1 " if score [ " halo " ] > = 1 else " 0 " )
data . set_attribute ( " combo " , str ( score [ " combo " ] ) )
option = Node . void ( " option " )
2019-12-08 22:43:49 +01:00
game . add_child ( option )
2022-10-15 20:56:30 +02:00
option . set_attribute ( " opt0 " , " 6 " )
option . set_attribute ( " opt6 " , " 1 " )
game . add_child ( Node . u8_array ( " trace " , [ 0 ] * 512 ) )
game . add_child ( Node . u32 ( " size " , 512 ) )
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/game " )
def verify_game_save_c ( self , ref_id : str , course : Dict [ str , Any ] ) - > None :
call = self . call_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 ( " ctype " , str ( course [ " chart " ] ) )
game . set_attribute ( " cid " , str ( course [ " id " ] ) )
game . set_attribute ( " method " , " save_c " )
game . set_attribute ( " ver " , " 1 " )
game . set_attribute ( " refid " , ref_id )
data = Node . void ( " data " )
2019-12-08 22:43:49 +01:00
game . add_child ( data )
2022-10-15 20:56:30 +02:00
data . set_attribute ( " combo_type " , str ( course [ " combo_type " ] ) )
data . set_attribute ( " clear " , " 1 " )
data . set_attribute ( " combo " , str ( course [ " combo " ] ) )
data . set_attribute ( " opt " , " 32774 " )
data . set_attribute ( " per " , " 995 " )
data . set_attribute ( " score " , str ( course [ " score " ] ) )
data . set_attribute ( " stage " , str ( course [ " stage " ] ) )
data . set_attribute ( " rank " , str ( course [ " rank " ] ) )
game . add_child ( Node . u8_array ( " trace " , [ 0 ] * 4096 ) )
game . add_child ( Node . u32 ( " size " , 4096 ) )
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/game " )
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_cardmng_getkeepspan ( )
self . verify_game_shop ( location )
self . verify_game_common ( )
self . verify_game_hiscore ( )
self . verify_game_message ( )
self . verify_game_ranking ( )
self . verify_game_log ( )
# 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_game_load ( ref_id , msg_type = " new " )
2019-12-08 22:43:49 +01:00
self . verify_game_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
# Verify locking and unlocking profile ability
self . verify_game_lock ( ref_id , 1 )
self . verify_game_lock ( ref_id , 0 )
if cardid is None :
# Verify empty profile
2022-10-15 20:56:30 +02:00
profile = self . verify_game_load ( ref_id , msg_type = " existing " )
if profile [ " name " ] != self . NAME :
raise Exception ( " Profile has invalid name associated with it! " )
if profile [ " single_plays " ] != 0 :
raise Exception ( " Profile has plays on single already! " )
if profile [ " double_plays " ] != 0 :
raise Exception ( " Profile has plays on double already! " )
if any ( [ g != 0 for g in profile [ " groove_single " ] ] ) :
raise Exception ( " Profile has single groove gauge values already! " )
if any ( [ g != 0 for g in profile [ " groove_double " ] ] ) :
raise Exception ( " Profile has double groove gauge values already! " )
2019-12-08 22:43:49 +01:00
# Verify empty scores
scores = self . verify_game_load_m ( ref_id )
if len ( scores ) > 0 :
2022-10-15 20:56:30 +02:00
raise Exception ( " Scores exist on new profile! " )
2019-12-08 22:43:49 +01:00
# Verify empty courses
courses = self . verify_game_load_c ( ref_id )
if len ( courses ) > 0 :
2022-10-15 20:56:30 +02:00
raise Exception ( " Courses exist on new profile! " )
2019-12-08 22:43:49 +01:00
# Verify profile saving
self . verify_game_save ( ref_id , 0 , [ 1 , 2 , 3 , 4 , 5 ] )
2022-10-15 20:56:30 +02:00
profile = self . verify_game_load ( ref_id , msg_type = " existing " )
if profile [ " name " ] != self . NAME :
raise Exception ( " Profile has invalid name associated with it! " )
if profile [ " single_plays " ] != 1 :
raise Exception ( " Profile has invalid plays on single! " )
if profile [ " double_plays " ] != 0 :
raise Exception ( " Profile has invalid plays on double! " )
if profile [ " groove_single " ] != [ 1 , 2 , 3 , 4 , 5 ] :
raise Exception ( " Profile has invalid single groove gauge values! " )
if any ( [ g != 0 for g in profile [ " groove_double " ] ] ) :
raise Exception ( " Profile has invalid double groove gauge values! " )
2019-12-08 22:43:49 +01:00
self . verify_game_save ( ref_id , 1 , [ 5 , 4 , 3 , 2 , 1 ] )
2022-10-15 20:56:30 +02:00
profile = self . verify_game_load ( ref_id , msg_type = " existing " )
if profile [ " name " ] != self . NAME :
raise Exception ( " Profile has invalid name associated with it! " )
if profile [ " single_plays " ] != 1 :
raise Exception ( " Profile has invalid plays on single! " )
if profile [ " double_plays " ] != 1 :
raise Exception ( " Profile has invalid plays on double! " )
if profile [ " groove_single " ] != [ 1 , 2 , 3 , 4 , 5 ] :
raise Exception ( " Profile has invalid single groove gauge values! " )
if profile [ " groove_double " ] != [ 5 , 4 , 3 , 2 , 1 ] :
raise Exception ( " Profile has invalid double groove gauge values! " )
2019-12-08 22:43:49 +01:00
# Now, write some scores and verify saving
for phase in [ 1 , 2 ] :
if phase == 1 :
dummyscores = [
# An okay score on a chart
{
2022-10-15 20:56:30 +02:00
" id " : 524 ,
" chart " : 3 ,
" score " : 800000 ,
" combo " : 123 ,
" rank " : 4 ,
" halo " : 1 ,
2019-12-08 22:43:49 +01:00
} ,
# A good score on an easier chart same song
{
2022-10-15 20:56:30 +02:00
" id " : 524 ,
" chart " : 2 ,
" score " : 990000 ,
" combo " : 321 ,
" rank " : 2 ,
" halo " : 2 ,
2019-12-08 22:43:49 +01:00
} ,
# A perfect score
{
2022-10-15 20:56:30 +02:00
" id " : 483 ,
" chart " : 3 ,
" score " : 1000000 ,
" combo " : 400 ,
" rank " : 1 ,
" halo " : 3 ,
2019-12-08 22:43:49 +01:00
} ,
# A bad score
{
2022-10-15 20:56:30 +02:00
" id " : 483 ,
" chart " : 2 ,
" score " : 100000 ,
" combo " : 5 ,
" rank " : 7 ,
" halo " : 0 ,
2019-12-08 22:43:49 +01:00
} ,
]
if phase == 2 :
dummyscores = [
# A better score on a chart
{
2022-10-15 20:56:30 +02:00
" id " : 524 ,
" chart " : 3 ,
" score " : 850000 ,
" combo " : 234 ,
" rank " : 3 ,
" halo " : 2 ,
2019-12-08 22:43:49 +01:00
} ,
# A worse score on another chart
{
2022-10-15 20:56:30 +02:00
" id " : 524 ,
" chart " : 2 ,
" score " : 980000 ,
" combo " : 300 ,
" rank " : 3 ,
" halo " : 0 ,
" expected_score " : 990000 ,
" expected_rank " : 2 ,
" expected_halo " : 2 ,
2019-12-08 22:43:49 +01:00
} ,
]
# Verify empty scores for starters
if phase == 1 :
for score in dummyscores :
2024-01-02 03:46:24 +01:00
last_five = self . verify_game_score ( ref_id , score [ " id " ] , score [ " chart " ] )
2019-12-08 22:43:49 +01:00
if any ( [ s != 0 for s in last_five ] ) :
2024-01-02 03:46:24 +01:00
raise Exception ( " Score already found on song not played yet! " )
2019-12-08 22:43:49 +01:00
for score in dummyscores :
self . verify_game_save_m ( ref_id , score )
scores = self . verify_game_load_m ( ref_id )
for score in dummyscores :
2022-10-15 20:56:30 +02:00
data = scores . get ( score [ " id " ] , { } ) . get ( score [ " chart " ] , None )
2019-12-08 22:43:49 +01:00
if data is None :
2024-01-02 03:46:24 +01:00
raise Exception ( f ' Expected to get score back for song { score [ " id " ] } chart { score [ " chart " ] } ! ' )
2019-12-08 22:43:49 +01:00
# Verify the attributes of the score
2022-10-15 20:56:30 +02:00
expected_score = score . get ( " expected_score " , score [ " score " ] )
expected_rank = score . get ( " expected_rank " , score [ " rank " ] )
expected_halo = score . get ( " expected_halo " , score [ " halo " ] )
if data [ " score " ] != expected_score :
raise Exception (
f ' Expected a score of \' { expected_score } \' for song \' { score [ " id " ] } \' chart \' { score [ " chart " ] } \' but got score \' { data [ " score " ] } \' '
)
if data [ " rank " ] != expected_rank :
raise Exception (
f ' Expected a rank of \' { expected_rank } \' for song \' { score [ " id " ] } \' chart \' { score [ " chart " ] } \' but got rank \' { data [ " rank " ] } \' '
)
if data [ " halo " ] != expected_halo :
raise Exception (
f ' Expected a halo of \' { expected_halo } \' for song \' { score [ " id " ] } \' chart \' { score [ " chart " ] } \' but got halo \' { data [ " halo " ] } \' '
)
2019-12-08 22:43:49 +01:00
# Verify that the last score is our score
2024-01-02 03:46:24 +01:00
last_five = self . verify_game_score ( ref_id , score [ " id " ] , score [ " chart " ] )
2022-10-15 20:56:30 +02:00
if last_five [ 0 ] != score [ " score " ] :
raise Exception (
f ' Invalid score returned for last five scores on song { score [ " id " ] } chart { score [ " chart " ] } ! '
)
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 )
# Now, write some courses and verify saving
for phase in [ 1 , 2 ] :
if phase == 1 :
dummycourses = [
# An okay score on a course
{
2022-10-15 20:56:30 +02:00
" id " : 5 ,
" chart " : 3 ,
" score " : 800000 ,
" combo " : 123 ,
" rank " : 4 ,
" stage " : 5 ,
" combo_type " : 1 ,
2019-12-08 22:43:49 +01:00
} ,
# A good score on a different coruse
{
2022-10-15 20:56:30 +02:00
" id " : 7 ,
" chart " : 2 ,
" score " : 600000 ,
" combo " : 23 ,
" rank " : 5 ,
" stage " : 5 ,
" combo_type " : 0 ,
2019-12-08 22:43:49 +01:00
} ,
]
if phase == 2 :
dummycourses = [
# A better score on the same course
{
2022-10-15 20:56:30 +02:00
" id " : 5 ,
" chart " : 3 ,
" score " : 900000 ,
" combo " : 234 ,
" rank " : 3 ,
" stage " : 5 ,
" combo_type " : 1 ,
2019-12-08 22:43:49 +01:00
} ,
# A worse score on a different same course
{
2022-10-15 20:56:30 +02:00
" id " : 7 ,
" chart " : 2 ,
" score " : 500000 ,
" combo " : 12 ,
" rank " : 7 ,
" stage " : 4 ,
" combo_type " : 0 ,
" expected_score " : 600000 ,
" expected_combo " : 23 ,
" expected_rank " : 5 ,
" expected_stage " : 5 ,
2019-12-08 22:43:49 +01:00
} ,
]
for course in dummycourses :
self . verify_game_save_c ( ref_id , course )
courses = self . verify_game_load_c ( ref_id )
for course in dummycourses :
2022-10-15 20:56:30 +02:00
data = courses . get ( course [ " id " ] , { } ) . get ( course [ " chart " ] , None )
2019-12-08 22:43:49 +01:00
if data is None :
2022-10-15 20:56:30 +02:00
raise Exception (
f ' Expected to get course back for course { course [ " id " ] } chart { course [ " chart " ] } ! '
)
expected_score = course . get ( " expected_score " , course [ " score " ] )
expected_combo = course . get ( " expected_combo " , course [ " combo " ] )
expected_rank = course . get ( " expected_rank " , course [ " rank " ] )
expected_stage = course . get ( " expected_stage " , course [ " stage " ] )
2024-01-02 03:46:24 +01:00
expected_combo_type = course . get ( " expected_combo_type " , course [ " combo_type " ] )
2022-10-15 20:56:30 +02:00
if data [ " score " ] != expected_score :
raise Exception (
f ' Expected a score of \' { expected_score } \' for course \' { course [ " id " ] } \' chart \' { course [ " chart " ] } \' but got score \' { data [ " score " ] } \' '
)
if data [ " combo " ] != expected_combo :
raise Exception (
f ' Expected a combo of \' { expected_combo } \' for course \' { course [ " id " ] } \' chart \' { course [ " chart " ] } \' but got combo \' { data [ " combo " ] } \' '
)
if data [ " rank " ] != expected_rank :
raise Exception (
f ' Expected a rank of \' { expected_rank } \' for course \' { course [ " id " ] } \' chart \' { course [ " chart " ] } \' but got rank \' { data [ " rank " ] } \' '
)
if data [ " stage " ] != expected_stage :
raise Exception (
f ' Expected a stage of \' { expected_stage } \' for course \' { course [ " id " ] } \' chart \' { course [ " chart " ] } \' but got stage \' { data [ " stage " ] } \' '
)
if data [ " combo_type " ] != expected_combo_type :
raise Exception (
f ' Expected a combo_type of \' { expected_combo_type } \' for course \' { course [ " id " ] } \' chart \' { course [ " chart " ] } \' but got combo_type \' { data [ " combo_type " ] } \' '
)
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 )