2019-12-08 22:43:49 +01:00
|
|
|
from typing import Dict, List, Tuple
|
2021-09-07 19:56:15 +02:00
|
|
|
from typing_extensions import Final
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.backend.reflec.base import ReflecBeatBase
|
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import ID, Time, Profile
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import Attempt, UserID
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
class ReflecBeatVolzzaBase(ReflecBeatBase):
|
|
|
|
# Clear types according to the game
|
2021-09-07 19:56:15 +02:00
|
|
|
GAME_CLEAR_TYPE_NO_PLAY: Final[int] = 0
|
|
|
|
GAME_CLEAR_TYPE_EARLY_FAILED: Final[int] = 1
|
|
|
|
GAME_CLEAR_TYPE_FAILED: Final[int] = 2
|
|
|
|
GAME_CLEAR_TYPE_CLEARED: Final[int] = 9
|
|
|
|
GAME_CLEAR_TYPE_HARD_CLEARED: Final[int] = 10
|
|
|
|
GAME_CLEAR_TYPE_S_HARD_CLEARED: Final[int] = 11
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Combo types according to the game (actually a bitmask, where bit 0 is
|
|
|
|
# full combo status, and bit 2 is just reflec status). But we don't support
|
|
|
|
# saving just reflec without full combo, so we downgrade it.
|
2021-09-07 19:56:15 +02:00
|
|
|
GAME_COMBO_TYPE_NONE: Final[int] = 0
|
|
|
|
GAME_COMBO_TYPE_ALL_JUST: Final[int] = 2
|
|
|
|
GAME_COMBO_TYPE_FULL_COMBO: Final[int] = 1
|
|
|
|
GAME_COMBO_TYPE_FULL_COMBO_ALL_JUST: Final[int] = 3
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def _db_to_game_clear_type(self, db_status: int) -> int:
|
|
|
|
return {
|
|
|
|
self.CLEAR_TYPE_NO_PLAY: self.GAME_CLEAR_TYPE_NO_PLAY,
|
|
|
|
self.CLEAR_TYPE_FAILED: self.GAME_CLEAR_TYPE_FAILED,
|
|
|
|
self.CLEAR_TYPE_CLEARED: self.GAME_CLEAR_TYPE_CLEARED,
|
|
|
|
self.CLEAR_TYPE_HARD_CLEARED: self.GAME_CLEAR_TYPE_HARD_CLEARED,
|
|
|
|
self.CLEAR_TYPE_S_HARD_CLEARED: self.GAME_CLEAR_TYPE_S_HARD_CLEARED,
|
|
|
|
}[db_status]
|
|
|
|
|
|
|
|
def _game_to_db_clear_type(self, status: int) -> int:
|
|
|
|
return {
|
|
|
|
self.GAME_CLEAR_TYPE_NO_PLAY: self.CLEAR_TYPE_NO_PLAY,
|
|
|
|
self.GAME_CLEAR_TYPE_EARLY_FAILED: self.CLEAR_TYPE_FAILED,
|
|
|
|
self.GAME_CLEAR_TYPE_FAILED: self.CLEAR_TYPE_FAILED,
|
|
|
|
self.GAME_CLEAR_TYPE_CLEARED: self.CLEAR_TYPE_CLEARED,
|
|
|
|
self.GAME_CLEAR_TYPE_HARD_CLEARED: self.CLEAR_TYPE_HARD_CLEARED,
|
|
|
|
self.GAME_CLEAR_TYPE_S_HARD_CLEARED: self.CLEAR_TYPE_S_HARD_CLEARED,
|
|
|
|
}[status]
|
|
|
|
|
|
|
|
def _db_to_game_combo_type(self, db_combo: int) -> int:
|
|
|
|
return {
|
|
|
|
self.COMBO_TYPE_NONE: self.GAME_COMBO_TYPE_NONE,
|
|
|
|
self.COMBO_TYPE_ALMOST_COMBO: self.GAME_COMBO_TYPE_NONE,
|
|
|
|
self.COMBO_TYPE_FULL_COMBO: self.GAME_COMBO_TYPE_FULL_COMBO,
|
|
|
|
self.COMBO_TYPE_FULL_COMBO_ALL_JUST: self.GAME_COMBO_TYPE_FULL_COMBO_ALL_JUST,
|
|
|
|
}[db_combo]
|
|
|
|
|
|
|
|
def _game_to_db_combo_type(self, game_combo: int, miss_count: int) -> int:
|
|
|
|
if game_combo in [
|
|
|
|
self.GAME_COMBO_TYPE_NONE,
|
|
|
|
self.GAME_COMBO_TYPE_ALL_JUST,
|
|
|
|
]:
|
|
|
|
if miss_count >= 0 and miss_count <= 2:
|
|
|
|
return self.COMBO_TYPE_ALMOST_COMBO
|
|
|
|
else:
|
|
|
|
return self.COMBO_TYPE_NONE
|
|
|
|
if game_combo == self.GAME_COMBO_TYPE_FULL_COMBO:
|
|
|
|
return self.COMBO_TYPE_FULL_COMBO
|
|
|
|
if game_combo == self.GAME_COMBO_TYPE_FULL_COMBO_ALL_JUST:
|
|
|
|
return self.COMBO_TYPE_FULL_COMBO_ALL_JUST
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Invalid game_combo value {game_combo}")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def _add_event_info(self, root: Node) -> None:
|
|
|
|
# Overridden in subclasses
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _add_shop_score(self, root: Node) -> None:
|
2022-10-15 20:56:30 +02:00
|
|
|
shop_score = Node.void("shop_score")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(shop_score)
|
2022-10-15 20:56:30 +02:00
|
|
|
today = Node.void("today")
|
2019-12-08 22:43:49 +01:00
|
|
|
shop_score.add_child(today)
|
2022-10-15 20:56:30 +02:00
|
|
|
yesterday = Node.void("yesterday")
|
2019-12-08 22:43:49 +01:00
|
|
|
shop_score.add_child(yesterday)
|
|
|
|
|
|
|
|
all_profiles = self.data.local.user.get_all_profiles(self.game, self.version)
|
2022-10-15 20:56:30 +02:00
|
|
|
all_attempts = self.data.local.music.get_all_attempts(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
timelimit=(Time.beginning_of_today() - Time.SECONDS_IN_DAY),
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
machine = self.data.local.machine.get_machine(self.config.machine.pcbid)
|
2019-12-08 22:43:49 +01:00
|
|
|
if machine.arcade is not None:
|
|
|
|
lids = [
|
2022-10-15 20:56:30 +02:00
|
|
|
machine.id
|
|
|
|
for machine in self.data.local.machine.get_all_machines(machine.arcade)
|
2019-12-08 22:43:49 +01:00
|
|
|
]
|
|
|
|
else:
|
|
|
|
lids = [machine.id]
|
|
|
|
|
|
|
|
relevant_profiles = [
|
2022-10-15 20:56:30 +02:00
|
|
|
profile for profile in all_profiles if profile[1].get_int("lid", -1) in lids
|
2019-12-08 22:43:49 +01:00
|
|
|
]
|
|
|
|
|
2023-02-17 04:02:41 +01:00
|
|
|
for rootnode, timeoffset in [
|
2019-12-08 22:43:49 +01:00
|
|
|
(today, 0),
|
|
|
|
(yesterday, Time.SECONDS_IN_DAY),
|
|
|
|
]:
|
|
|
|
# Grab all attempts made in the relevant day
|
|
|
|
relevant_attempts = [
|
2022-10-15 20:56:30 +02:00
|
|
|
attempt
|
|
|
|
for attempt in all_attempts
|
2019-12-08 22:43:49 +01:00
|
|
|
if (
|
2022-10-15 20:56:30 +02:00
|
|
|
attempt[1].timestamp >= (Time.beginning_of_today() - timeoffset)
|
|
|
|
and attempt[1].timestamp <= (Time.end_of_today() - timeoffset)
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
# Calculate scores based on attempt
|
|
|
|
scores_by_user: Dict[UserID, Dict[int, Dict[int, Attempt]]] = {}
|
2023-02-17 04:02:41 +01:00
|
|
|
for userid, attempt in relevant_attempts:
|
2019-12-08 22:43:49 +01:00
|
|
|
if userid not in scores_by_user:
|
|
|
|
scores_by_user[userid] = {}
|
|
|
|
if attempt.id not in scores_by_user[userid]:
|
|
|
|
scores_by_user[userid][attempt.id] = {}
|
|
|
|
if attempt.chart not in scores_by_user[userid][attempt.id]:
|
|
|
|
# No high score for this yet, just use this attempt
|
|
|
|
scores_by_user[userid][attempt.id][attempt.chart] = attempt
|
|
|
|
else:
|
|
|
|
# If this attempt is better than the stored one, replace it
|
2022-10-15 20:56:30 +02:00
|
|
|
if (
|
|
|
|
scores_by_user[userid][attempt.id][attempt.chart].points
|
|
|
|
< attempt.points
|
|
|
|
):
|
2019-12-08 22:43:49 +01:00
|
|
|
scores_by_user[userid][attempt.id][attempt.chart] = attempt
|
|
|
|
|
|
|
|
# Calculate points earned by user in the day
|
|
|
|
points_by_user: Dict[UserID, int] = {}
|
|
|
|
for userid in scores_by_user:
|
|
|
|
points_by_user[userid] = 0
|
|
|
|
for mid in scores_by_user[userid]:
|
|
|
|
for chart in scores_by_user[userid][mid]:
|
2022-10-15 20:56:30 +02:00
|
|
|
points_by_user[userid] = (
|
|
|
|
points_by_user[userid]
|
|
|
|
+ scores_by_user[userid][mid][chart].points
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Output that day's earned points
|
2023-02-17 04:02:41 +01:00
|
|
|
for userid, profile in relevant_profiles:
|
2022-10-15 20:56:30 +02:00
|
|
|
data = Node.void("data")
|
2019-12-08 22:43:49 +01:00
|
|
|
rootnode.add_child(data)
|
2022-10-15 20:56:30 +02:00
|
|
|
data.add_child(
|
|
|
|
Node.s16(
|
|
|
|
"day_id", int((Time.now() - timeoffset) / Time.SECONDS_IN_DAY)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
data.add_child(Node.s32("user_id", profile.extid))
|
|
|
|
data.add_child(
|
|
|
|
Node.s16("icon_id", profile.get_dict("config").get_int("icon_id"))
|
|
|
|
)
|
|
|
|
data.add_child(
|
|
|
|
Node.s16("point", min(points_by_user.get(userid, 0), 32767))
|
|
|
|
)
|
|
|
|
data.add_child(Node.s32("update_time", Time.now()))
|
|
|
|
data.add_child(Node.string("name", profile.get_str("name")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
rootnode.add_child(Node.s32("time", Time.beginning_of_today() - timeoffset))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_info_rb5_info_read_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("info")
|
2019-12-08 22:43:49 +01:00
|
|
|
self._add_event_info(root)
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_info_rb5_info_read_hit_chart_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
version = request.child_value("ver")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("info")
|
|
|
|
root.add_child(Node.s32("ver", version))
|
|
|
|
ranking = Node.void("ranking")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(ranking)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def add_hitchart(
|
|
|
|
name: str, start: int, end: int, hitchart: List[Tuple[int, int]]
|
|
|
|
) -> None:
|
2019-12-08 22:43:49 +01:00
|
|
|
base = Node.void(name)
|
|
|
|
ranking.add_child(base)
|
2022-10-15 20:56:30 +02:00
|
|
|
base.add_child(Node.s32("bt", start))
|
|
|
|
base.add_child(Node.s32("et", end))
|
|
|
|
new = Node.void("new")
|
2019-12-08 22:43:49 +01:00
|
|
|
base.add_child(new)
|
|
|
|
|
2023-02-17 04:02:41 +01:00
|
|
|
for mid, plays in hitchart:
|
2022-10-15 20:56:30 +02:00
|
|
|
d = Node.void("d")
|
2019-12-08 22:43:49 +01:00
|
|
|
new.add_child(d)
|
2022-10-15 20:56:30 +02:00
|
|
|
d.add_child(Node.s16("mid", mid))
|
|
|
|
d.add_child(Node.s32("cnt", plays))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Weekly hit chart
|
|
|
|
add_hitchart(
|
2022-10-15 20:56:30 +02:00
|
|
|
"weekly",
|
2019-12-08 22:43:49 +01:00
|
|
|
Time.now() - Time.SECONDS_IN_WEEK,
|
|
|
|
Time.now(),
|
|
|
|
self.data.local.music.get_hit_chart(self.game, self.version, 1024, 7),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Monthly hit chart
|
|
|
|
add_hitchart(
|
2022-10-15 20:56:30 +02:00
|
|
|
"monthly",
|
2019-12-08 22:43:49 +01:00
|
|
|
Time.now() - Time.SECONDS_IN_DAY * 30,
|
|
|
|
Time.now(),
|
|
|
|
self.data.local.music.get_hit_chart(self.game, self.version, 1024, 30),
|
|
|
|
)
|
|
|
|
|
|
|
|
# All time hit chart
|
|
|
|
add_hitchart(
|
2022-10-15 20:56:30 +02:00
|
|
|
"total",
|
2019-12-08 22:43:49 +01:00
|
|
|
Time.now() - Time.SECONDS_IN_DAY * 365,
|
|
|
|
Time.now(),
|
|
|
|
self.data.local.music.get_hit_chart(self.game, self.version, 1024, 365),
|
|
|
|
)
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_info_rb5_info_read_shop_ranking_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
start_music_id = request.child_value("min")
|
|
|
|
end_music_id = request.child_value("max")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("info")
|
|
|
|
shop_score = Node.void("shop_score")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(shop_score)
|
2022-10-15 20:56:30 +02:00
|
|
|
shop_score.add_child(Node.s32("time", Time.now()))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
profiles: Dict[UserID, Profile] = {}
|
2019-12-08 22:43:49 +01:00
|
|
|
for songid in range(start_music_id, end_music_id + 1):
|
|
|
|
allscores = self.data.local.music.get_all_scores(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
songid=songid,
|
|
|
|
)
|
|
|
|
|
|
|
|
for ng in [
|
|
|
|
self.CHART_TYPE_BASIC,
|
|
|
|
self.CHART_TYPE_MEDIUM,
|
|
|
|
self.CHART_TYPE_HARD,
|
|
|
|
self.CHART_TYPE_SPECIAL,
|
|
|
|
]:
|
|
|
|
scores = sorted(
|
|
|
|
[score for score in allscores if score[1].chart == ng],
|
|
|
|
key=lambda score: score[1].points,
|
|
|
|
reverse=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
for i in range(len(scores)):
|
|
|
|
userid, score = scores[i]
|
|
|
|
if userid not in profiles:
|
|
|
|
profiles[userid] = self.get_any_profile(userid)
|
|
|
|
profile = profiles[userid]
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
data = Node.void("data")
|
2019-12-08 22:43:49 +01:00
|
|
|
shop_score.add_child(data)
|
2022-10-15 20:56:30 +02:00
|
|
|
data.add_child(Node.s32("rank", i + 1))
|
|
|
|
data.add_child(Node.s16("music_id", songid))
|
|
|
|
data.add_child(Node.s8("note_grade", score.chart))
|
|
|
|
data.add_child(
|
|
|
|
Node.s8(
|
|
|
|
"clear_type",
|
|
|
|
self._db_to_game_clear_type(
|
|
|
|
score.data.get_int("clear_type")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
data.add_child(Node.s32("user_id", profile.extid))
|
|
|
|
data.add_child(
|
|
|
|
Node.s16(
|
|
|
|
"icon_id", profile.get_dict("config").get_int("icon_id")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
data.add_child(Node.s32("score", score.points))
|
|
|
|
data.add_child(Node.s32("time", score.timestamp))
|
|
|
|
data.add_child(Node.string("name", profile.get_str("name")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_lobby_rb5_lobby_entry_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("lobby")
|
|
|
|
root.add_child(Node.s32("interval", 120))
|
|
|
|
root.add_child(Node.s32("interval_p", 120))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Create a lobby entry for this user
|
2022-10-15 20:56:30 +02:00
|
|
|
extid = request.child_value("e/uid")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
if userid is not None:
|
|
|
|
profile = self.get_profile(userid)
|
2022-10-15 20:56:30 +02:00
|
|
|
info = self.data.local.lobby.get_play_session_info(
|
|
|
|
self.game, self.version, userid
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
if profile is None or info is None:
|
|
|
|
return root
|
|
|
|
|
|
|
|
self.data.local.lobby.put_lobby(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"mid": request.child_value("e/mid"),
|
|
|
|
"ng": request.child_value("e/ng"),
|
|
|
|
"mopt": request.child_value("e/mopt"),
|
|
|
|
"lid": request.child_value("e/lid"),
|
|
|
|
"sn": request.child_value("e/sn"),
|
|
|
|
"pref": request.child_value("e/pref"),
|
|
|
|
"stg": request.child_value("e/stg"),
|
|
|
|
"pside": request.child_value("e/pside"),
|
|
|
|
"eatime": request.child_value("e/eatime"),
|
|
|
|
"ga": request.child_value("e/ga"),
|
|
|
|
"gp": request.child_value("e/gp"),
|
|
|
|
"la": request.child_value("e/la"),
|
|
|
|
"ver": request.child_value("e/ver"),
|
|
|
|
},
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
lobby = self.data.local.lobby.get_lobby(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
)
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.s32("eid", lobby.get_int("id")))
|
|
|
|
e = Node.void("e")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(e)
|
2022-10-15 20:56:30 +02:00
|
|
|
e.add_child(Node.s32("eid", lobby.get_int("id")))
|
|
|
|
e.add_child(Node.u16("mid", lobby.get_int("mid")))
|
|
|
|
e.add_child(Node.u8("ng", lobby.get_int("ng")))
|
|
|
|
e.add_child(Node.s32("uid", profile.extid))
|
|
|
|
e.add_child(Node.s32("uattr", profile.get_int("uattr")))
|
|
|
|
e.add_child(Node.string("pn", profile.get_str("name")))
|
|
|
|
e.add_child(Node.s32("plyid", info.get_int("id")))
|
|
|
|
e.add_child(Node.s16("mg", profile.get_int("mg")))
|
|
|
|
e.add_child(Node.s32("mopt", lobby.get_int("mopt")))
|
|
|
|
e.add_child(Node.string("lid", lobby.get_str("lid")))
|
|
|
|
e.add_child(Node.string("sn", lobby.get_str("sn")))
|
|
|
|
e.add_child(Node.u8("pref", lobby.get_int("pref")))
|
|
|
|
e.add_child(Node.s8("stg", lobby.get_int("stg")))
|
|
|
|
e.add_child(Node.s8("pside", lobby.get_int("pside")))
|
|
|
|
e.add_child(Node.s16("eatime", lobby.get_int("eatime")))
|
|
|
|
e.add_child(Node.u8_array("ga", lobby.get_int_array("ga", 4)))
|
|
|
|
e.add_child(Node.u16("gp", lobby.get_int("gp")))
|
|
|
|
e.add_child(Node.u8_array("la", lobby.get_int_array("la", 4)))
|
|
|
|
e.add_child(Node.u8("ver", lobby.get_int("ver")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_lobby_rb5_lobby_read_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("lobby")
|
|
|
|
root.add_child(Node.s32("interval", 120))
|
|
|
|
root.add_child(Node.s32("interval_p", 120))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Look up all lobbies matching the criteria specified
|
2022-10-15 20:56:30 +02:00
|
|
|
ver = request.child_value("var")
|
|
|
|
mg = request.child_value("m_grade") # noqa: F841
|
|
|
|
extid = request.child_value("uid")
|
|
|
|
limit = request.child_value("max")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
if userid is not None:
|
|
|
|
lobbies = self.data.local.lobby.get_all_lobbies(self.game, self.version)
|
2023-02-17 04:02:41 +01:00
|
|
|
for user, lobby in lobbies:
|
2019-12-08 22:43:49 +01:00
|
|
|
if limit <= 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
if user == userid:
|
|
|
|
# If we have our own lobby, don't return it
|
|
|
|
continue
|
2022-10-15 20:56:30 +02:00
|
|
|
if ver != lobby.get_int("ver"):
|
2019-12-08 22:43:49 +01:00
|
|
|
# Don't return lobby data for different versions
|
|
|
|
continue
|
|
|
|
|
|
|
|
profile = self.get_profile(user)
|
2022-10-15 20:56:30 +02:00
|
|
|
info = self.data.local.lobby.get_play_session_info(
|
|
|
|
self.game, self.version, userid
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
if profile is None or info is None:
|
|
|
|
# No profile info, don't return this lobby
|
|
|
|
return root
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
e = Node.void("e")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(e)
|
2022-10-15 20:56:30 +02:00
|
|
|
e.add_child(Node.s32("eid", lobby.get_int("id")))
|
|
|
|
e.add_child(Node.u16("mid", lobby.get_int("mid")))
|
|
|
|
e.add_child(Node.u8("ng", lobby.get_int("ng")))
|
|
|
|
e.add_child(Node.s32("uid", profile.extid))
|
|
|
|
e.add_child(Node.s32("uattr", profile.get_int("uattr")))
|
|
|
|
e.add_child(Node.string("pn", profile.get_str("name")))
|
|
|
|
e.add_child(Node.s32("plyid", info.get_int("id")))
|
|
|
|
e.add_child(Node.s16("mg", profile.get_int("mg")))
|
|
|
|
e.add_child(Node.s32("mopt", lobby.get_int("mopt")))
|
|
|
|
e.add_child(Node.string("lid", lobby.get_str("lid")))
|
|
|
|
e.add_child(Node.string("sn", lobby.get_str("sn")))
|
|
|
|
e.add_child(Node.u8("pref", lobby.get_int("pref")))
|
|
|
|
e.add_child(Node.s8("stg", lobby.get_int("stg")))
|
|
|
|
e.add_child(Node.s8("pside", lobby.get_int("pside")))
|
|
|
|
e.add_child(Node.s16("eatime", lobby.get_int("eatime")))
|
|
|
|
e.add_child(Node.u8_array("ga", lobby.get_int_array("ga", 4)))
|
|
|
|
e.add_child(Node.u16("gp", lobby.get_int("gp")))
|
|
|
|
e.add_child(Node.u8_array("la", lobby.get_int_array("la", 4)))
|
|
|
|
e.add_child(Node.u8("ver", lobby.get_int("ver")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
limit = limit - 1
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_lobby_rb5_lobby_delete_entry_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
eid = request.child_value("eid")
|
2019-12-08 22:43:49 +01:00
|
|
|
self.data.local.lobby.destroy_lobby(eid)
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("lobby")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_pcb_rb5_pcb_boot_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
shop_id = ID.parse_machine_id(request.child_value("lid"))
|
2019-12-08 22:43:49 +01:00
|
|
|
machine = self.get_machine_by_id(shop_id)
|
|
|
|
if machine is not None:
|
|
|
|
machine_name = machine.name
|
2022-10-15 20:56:30 +02:00
|
|
|
close = machine.data.get_bool("close")
|
|
|
|
hour = machine.data.get_int("hour")
|
|
|
|
minute = machine.data.get_int("minute")
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
machine_name = ""
|
2019-12-08 22:43:49 +01:00
|
|
|
close = False
|
|
|
|
hour = 0
|
|
|
|
minute = 0
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("pcb")
|
|
|
|
sinfo = Node.void("sinfo")
|
2019-12-08 22:43:49 +01:00
|
|
|
root.add_child(sinfo)
|
2022-10-15 20:56:30 +02:00
|
|
|
sinfo.add_child(Node.string("nm", machine_name))
|
|
|
|
sinfo.add_child(Node.bool("cl_enbl", close))
|
|
|
|
sinfo.add_child(Node.u8("cl_h", hour))
|
|
|
|
sinfo.add_child(Node.u8("cl_m", minute))
|
|
|
|
sinfo.add_child(Node.bool("shop_flag", True))
|
2019-12-08 22:43:49 +01:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_pcb_rb5_pcb_error_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("pcb")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_pcb_rb5_pcb_update_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("pcb")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_shop_rb5_shop_write_setting_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("shop")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_shop_rb5_shop_write_info_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
self.update_machine_name(request.child_value("sinfo/nm"))
|
|
|
|
self.update_machine_data(
|
|
|
|
{
|
|
|
|
"close": request.child_value("sinfo/cl_enbl"),
|
|
|
|
"hour": request.child_value("sinfo/cl_h"),
|
|
|
|
"minute": request.child_value("sinfo/cl_m"),
|
|
|
|
"pref": request.child_value("sinfo/prf"),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return Node.void("shop")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_player_rb5_player_start_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Create a new play session based on info from the request
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
if userid is not None:
|
|
|
|
self.data.local.lobby.put_play_session_info(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"ga": request.child_value("ga"),
|
|
|
|
"gp": request.child_value("gp"),
|
|
|
|
"la": request.child_value("la"),
|
|
|
|
"pnid": request.child_value("pnid"),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
info = self.data.local.lobby.get_play_session_info(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
)
|
|
|
|
if info is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
play_id = info.get_int("id")
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
|
|
|
play_id = 0
|
|
|
|
else:
|
|
|
|
play_id = 0
|
|
|
|
|
|
|
|
# Session stuff, and resend global defaults
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.s32("plyid", play_id))
|
|
|
|
root.add_child(Node.u64("start_time", Time.now() * 1000))
|
2019-12-08 22:43:49 +01:00
|
|
|
self._add_event_info(root)
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_player_rb5_player_end_request(self, request: Node) -> Node:
|
|
|
|
# Destroy play session based on info from the request
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
if userid is not None:
|
|
|
|
# Kill any lingering lobbies by this user
|
|
|
|
lobby = self.data.local.lobby.get_lobby(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
)
|
|
|
|
if lobby is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
self.data.local.lobby.destroy_lobby(lobby.get_int("id"))
|
|
|
|
self.data.local.lobby.destroy_play_session_info(
|
|
|
|
self.game, self.version, userid
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_player_rb5_player_delete_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_player_rb5_player_succeed_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
if userid is not None:
|
|
|
|
previous_version = self.previous_version()
|
|
|
|
profile = previous_version.get_profile(userid)
|
|
|
|
else:
|
|
|
|
profile = None
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("player")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if profile is None:
|
|
|
|
# Return empty succeed to say this is new
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.string("name", ""))
|
|
|
|
root.add_child(Node.s32("grd", -1))
|
|
|
|
root.add_child(Node.s32("ap", -1))
|
|
|
|
root.add_child(Node.s32("uattr", 0))
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
|
|
|
# Return previous profile formatted to say this is data succession
|
2022-10-15 20:56:30 +02:00
|
|
|
root.add_child(Node.string("name", profile.get_str("name")))
|
|
|
|
root.add_child(Node.s32("grd", profile.get_int("mg"))) # This is a guess
|
|
|
|
root.add_child(Node.s32("ap", profile.get_int("ap")))
|
|
|
|
root.add_child(Node.s32("uattr", profile.get_int("uattr")))
|
2019-12-08 22:43:49 +01:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_player_rb5_player_read_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.child_value("rid")
|
2019-12-08 22:43:49 +01:00
|
|
|
profile = self.get_profile_by_refid(refid)
|
|
|
|
if profile:
|
|
|
|
return profile
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("player")
|