2019-12-08 22:43:49 +01:00
|
|
|
from typing import Dict, Optional, Tuple
|
|
|
|
|
|
|
|
from bemani.backend.ddr.base import DDRBase
|
2021-08-25 01:18:53 +02:00
|
|
|
from bemani.common import Profile, intish
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import Score, UserID
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameShopHandler(DDRBase):
|
|
|
|
def handle_game_shop_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
self.update_machine_name(request.attribute("name"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
game.set_attribute("stop", "0")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameLogHandler(DDRBase):
|
|
|
|
def handle_game_log_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DDRGameMessageHandler(DDRBase):
|
|
|
|
def handle_game_message_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DDRGameRankingHandler(DDRBase):
|
|
|
|
def handle_game_ranking_request(self, request: Node) -> Node:
|
|
|
|
# Ranking request, unknown what its for
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DDRGameLockHandler(DDRBase):
|
|
|
|
def handle_game_lock_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
game.set_attribute("now_login", "0")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameTaxInfoHandler(DDRBase):
|
|
|
|
def handle_game_tax_info_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
tax_info = Node.void("tax_info")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(tax_info)
|
2022-10-15 20:56:30 +02:00
|
|
|
tax_info.set_attribute("tax_phase", "0")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameRecorderHandler(DDRBase):
|
|
|
|
def handle_game_recorder_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DDRGameHiscoreHandler(DDRBase):
|
|
|
|
def handle_game_hiscore_request(self, request: Node) -> Node:
|
|
|
|
records = self.data.remote.music.get_all_records(self.game, self.music_version)
|
|
|
|
|
|
|
|
sortedrecords: Dict[int, Dict[int, Tuple[UserID, Score]]] = {}
|
|
|
|
missing_profiles = []
|
|
|
|
for (userid, score) in records:
|
|
|
|
if score.id not in sortedrecords:
|
|
|
|
sortedrecords[score.id] = {}
|
|
|
|
sortedrecords[score.id][score.chart] = (userid, score)
|
|
|
|
missing_profiles.append(userid)
|
2022-10-15 20:56:30 +02:00
|
|
|
users = {
|
|
|
|
userid: profile
|
|
|
|
for (userid, profile) in self.get_any_profiles(missing_profiles)
|
|
|
|
}
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
for song in sortedrecords:
|
2022-10-15 20:56:30 +02:00
|
|
|
music = Node.void("music")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(music)
|
2022-10-15 20:56:30 +02:00
|
|
|
music.set_attribute("reclink_num", str(song))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for chart in sortedrecords[song]:
|
|
|
|
userid, score = sortedrecords[song][chart]
|
|
|
|
try:
|
|
|
|
gamechart = self.db_to_game_chart(chart)
|
|
|
|
except KeyError:
|
|
|
|
# Don't support this chart in this game
|
|
|
|
continue
|
2022-10-15 20:56:30 +02:00
|
|
|
gamerank = self.db_to_game_rank(score.data.get_int("rank"))
|
|
|
|
combo_type = self.db_to_game_halo(score.data.get_int("halo"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode = Node.void("type")
|
2019-12-08 22:43:49 +01:00
|
|
|
music.add_child(typenode)
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode.set_attribute("diff", str(gamechart))
|
|
|
|
|
|
|
|
typenode.add_child(Node.string("name", users[userid].get_str("name")))
|
|
|
|
typenode.add_child(Node.u32("score", score.points))
|
|
|
|
typenode.add_child(
|
|
|
|
Node.u16(
|
|
|
|
"area", users[userid].get_int("area", self.get_machine_region())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
typenode.add_child(Node.u8("rank", gamerank))
|
|
|
|
typenode.add_child(Node.u8("combo_type", combo_type))
|
|
|
|
typenode.add_child(Node.u32("code", users[userid].extid))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameAreaHiscoreHandler(DDRBase):
|
|
|
|
def handle_game_area_hiscore_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
shop_area = int(request.attribute("shop_area"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# First, get all users that are in the current shop's area
|
|
|
|
area_users = {
|
2022-10-15 20:56:30 +02:00
|
|
|
uid: prof
|
|
|
|
for (uid, prof) in self.data.local.user.get_all_profiles(
|
|
|
|
self.game, self.version
|
|
|
|
)
|
|
|
|
if prof.get_int("area", self.get_machine_region()) == shop_area
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Second, look up records belonging only to those users
|
2022-10-15 20:56:30 +02:00
|
|
|
records = self.data.local.music.get_all_records(
|
|
|
|
self.game, self.music_version, userlist=list(area_users.keys())
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Now, do the same lazy thing as 'hiscore' because I don't want
|
|
|
|
# to think about how to change this knowing that we only pulled
|
|
|
|
# up area records.
|
|
|
|
area_records: Dict[int, Dict[int, Tuple[UserID, Score]]] = {}
|
|
|
|
for (userid, score) in records:
|
|
|
|
if score.id not in area_records:
|
|
|
|
area_records[score.id] = {}
|
|
|
|
area_records[score.id][score.chart] = (userid, score)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
for song in area_records:
|
2022-10-15 20:56:30 +02:00
|
|
|
music = Node.void("music")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(music)
|
2022-10-15 20:56:30 +02:00
|
|
|
music.set_attribute("reclink_num", str(song))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for chart in area_records[song]:
|
|
|
|
userid, score = area_records[song][chart]
|
2022-10-15 20:56:30 +02:00
|
|
|
if (
|
|
|
|
area_users[userid].get_int("area", self.get_machine_region())
|
|
|
|
!= shop_area
|
|
|
|
):
|
2019-12-08 22:43:49 +01:00
|
|
|
# Don't return this, this user isn't in this area
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
gamechart = self.db_to_game_chart(chart)
|
|
|
|
except KeyError:
|
|
|
|
# Don't support this chart in this game
|
|
|
|
continue
|
2022-10-15 20:56:30 +02:00
|
|
|
gamerank = self.db_to_game_rank(score.data.get_int("rank"))
|
|
|
|
combo_type = self.db_to_game_halo(score.data.get_int("halo"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode = Node.void("type")
|
2019-12-08 22:43:49 +01:00
|
|
|
music.add_child(typenode)
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode.set_attribute("diff", str(gamechart))
|
|
|
|
|
|
|
|
typenode.add_child(
|
|
|
|
Node.string("name", area_users[userid].get_str("name"))
|
|
|
|
)
|
|
|
|
typenode.add_child(Node.u32("score", score.points))
|
|
|
|
typenode.add_child(
|
|
|
|
Node.u16(
|
|
|
|
"area",
|
|
|
|
area_users[userid].get_int("area", self.get_machine_region()),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
typenode.add_child(Node.u8("rank", gamerank))
|
|
|
|
typenode.add_child(Node.u8("combo_type", combo_type))
|
|
|
|
typenode.add_child(Node.u32("code", area_users[userid].extid))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameScoreHandler(DDRBase):
|
|
|
|
def handle_game_score_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
|
|
|
songid = int(request.attribute("mid"))
|
|
|
|
chart = self.game_to_db_chart(int(request.attribute("type")))
|
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:
|
|
|
|
attempts = self.data.local.music.get_all_attempts(
|
|
|
|
self.game,
|
|
|
|
self.music_version,
|
|
|
|
userid,
|
|
|
|
songid=songid,
|
|
|
|
songchart=chart,
|
|
|
|
limit=5,
|
|
|
|
)
|
|
|
|
recentscores = [attempt.points for (_, attempt) in attempts]
|
|
|
|
else:
|
|
|
|
recentscores = []
|
|
|
|
|
|
|
|
# Always pad to five, so we ensure that we return all the scores
|
|
|
|
while len(recentscores) < 5:
|
|
|
|
recentscores.append(0)
|
|
|
|
|
|
|
|
# Return the most recent five scores
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
for i in range(len(recentscores)):
|
2022-10-15 20:56:30 +02:00
|
|
|
game.set_attribute(f"sc{i + 1}", str(recentscores[i]))
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameTraceHandler(DDRBase):
|
|
|
|
def handle_game_trace_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
extid = int(request.attribute("code"))
|
|
|
|
chart = int(request.attribute("type"))
|
|
|
|
cid = intish(request.attribute("cid"))
|
|
|
|
mid = intish(request.attribute("mid"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Base packet is just game, if we find something we add to it
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Rival trace loading
|
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
if userid is None:
|
|
|
|
# Nothing to load
|
|
|
|
return game
|
|
|
|
|
|
|
|
if mid is not None:
|
|
|
|
# Load trace from song score
|
|
|
|
songscore = self.data.remote.music.get_score(
|
|
|
|
self.game,
|
|
|
|
self.music_version,
|
|
|
|
userid,
|
|
|
|
mid,
|
|
|
|
self.game_to_db_chart(chart),
|
|
|
|
)
|
2022-10-15 20:56:30 +02:00
|
|
|
if songscore is not None and "trace" in songscore.data:
|
|
|
|
game.add_child(Node.u32("size", len(songscore.data["trace"])))
|
|
|
|
game.add_child(Node.u8_array("trace", songscore.data["trace"]))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
elif cid is not None:
|
|
|
|
# Load trace from achievement
|
|
|
|
coursescore = self.data.local.user.get_achievement(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
(cid * 4) + chart,
|
2022-10-15 20:56:30 +02:00
|
|
|
"course",
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
2022-10-15 20:56:30 +02:00
|
|
|
if coursescore is not None and "trace" in coursescore:
|
|
|
|
game.add_child(Node.u32("size", len(coursescore["trace"])))
|
|
|
|
game.add_child(Node.u8_array("trace", coursescore["trace"]))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Nothing found, return empty
|
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameLoadHandler(DDRBase):
|
|
|
|
def handle_game_load_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
2019-12-08 22:43:49 +01:00
|
|
|
profile = self.get_profile_by_refid(refid)
|
|
|
|
if profile is not None:
|
|
|
|
return profile
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
game.set_attribute("none", "0")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameLoadDailyHandler(DDRBase):
|
|
|
|
def handle_game_load_daily_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
extid = intish(request.attribute("code"))
|
|
|
|
refid = request.attribute("refid")
|
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
profiledict = None
|
|
|
|
|
|
|
|
if extid is not None:
|
|
|
|
# Rival daily loading
|
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
else:
|
|
|
|
# Self daily loading
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
if userid is not None:
|
|
|
|
profiledict = self.get_profile(userid)
|
|
|
|
|
|
|
|
if profiledict is not None:
|
|
|
|
play_stats = self.get_play_statistics(userid)
|
|
|
|
|
|
|
|
# Day play counts
|
2022-10-15 20:56:30 +02:00
|
|
|
daycount = Node.void("daycount")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(daycount)
|
2022-10-15 20:56:30 +02:00
|
|
|
daycount.set_attribute("playcount", str(play_stats.today_plays))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Daily combo stuff, unclear how this works
|
2022-10-15 20:56:30 +02:00
|
|
|
dailycombo = Node.void("dailycombo")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(dailycombo)
|
2022-10-15 20:56:30 +02:00
|
|
|
dailycombo.set_attribute("daily_combo", str(0))
|
|
|
|
dailycombo.set_attribute("daily_combo_lv", str(0))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameOldHandler(DDRBase):
|
|
|
|
def handle_game_old_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
previous_version: Optional[DDRBase] = None
|
2021-08-20 06:43:13 +02:00
|
|
|
oldprofile: Optional[Profile] = None
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if userid is not None:
|
|
|
|
previous_version = self.previous_version()
|
|
|
|
if previous_version is not None:
|
|
|
|
oldprofile = previous_version.get_profile(userid)
|
|
|
|
if oldprofile is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
game.set_attribute("name", oldprofile.get_str("name"))
|
|
|
|
game.set_attribute(
|
|
|
|
"area", str(oldprofile.get_int("area", self.get_machine_region()))
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameNewHandler(DDRBase):
|
|
|
|
def handle_game_new_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
|
|
|
area = int(request.attribute("area"))
|
|
|
|
name = request.attribute("name").strip()
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Create a new profile for this user!
|
|
|
|
self.new_profile_by_refid(refid, name, area)
|
|
|
|
|
|
|
|
# No response needed
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameSaveHandler(DDRBase):
|
|
|
|
def handle_game_save_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
2019-12-08 22:43:49 +01:00
|
|
|
self.put_profile_by_refid(refid, request)
|
|
|
|
|
|
|
|
# No response needed
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameFriendHandler(DDRBase):
|
|
|
|
def handle_game_friend_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
extid = intish(request.attribute("code"))
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = None
|
|
|
|
friend = None
|
|
|
|
|
|
|
|
if extid is not None:
|
|
|
|
# Rival score loading
|
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
if userid is not None:
|
|
|
|
friend = self.get_profile(userid)
|
|
|
|
play_stats = self.get_play_statistics(userid)
|
|
|
|
|
|
|
|
if friend is None:
|
|
|
|
# Return an empty node to tell the game we don't have a player here
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
game.set_attribute("data", "1")
|
|
|
|
game.add_child(Node.u32("code", friend.extid))
|
|
|
|
game.add_child(Node.string("name", friend.get_str("name")))
|
|
|
|
game.add_child(
|
|
|
|
Node.u8("area", friend.get_int("area", self.get_machine_region()))
|
|
|
|
)
|
|
|
|
game.add_child(Node.u32("exp", play_stats.get_int("exp")))
|
|
|
|
game.add_child(Node.u32("star", friend.get_int("star")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Drill rankings
|
2022-10-15 20:56:30 +02:00
|
|
|
if "title" in friend:
|
|
|
|
title = Node.void("title")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(title)
|
2022-10-15 20:56:30 +02:00
|
|
|
titledict = friend.get_dict("title")
|
|
|
|
if "t" in titledict:
|
|
|
|
title.set_attribute("t", str(titledict.get_int("t")))
|
|
|
|
if "s" in titledict:
|
|
|
|
title.set_attribute("s", str(titledict.get_int("s")))
|
|
|
|
if "d" in titledict:
|
|
|
|
title.set_attribute("d", str(titledict.get_int("d")))
|
|
|
|
|
|
|
|
if "title_gr" in friend:
|
|
|
|
title_gr = Node.void("title_gr")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(title_gr)
|
2022-10-15 20:56:30 +02:00
|
|
|
title_grdict = friend.get_dict("title_gr")
|
|
|
|
if "t" in title_grdict:
|
|
|
|
title_gr.set_attribute("t", str(title_grdict.get_int("t")))
|
|
|
|
if "s" in title_grdict:
|
|
|
|
title_gr.set_attribute("s", str(title_grdict.get_int("s")))
|
|
|
|
if "d" in title_grdict:
|
|
|
|
title_gr.set_attribute("d", str(title_grdict.get_int("d")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Groove gauge level-ups
|
2022-10-15 20:56:30 +02:00
|
|
|
gr_s = Node.void("gr_s")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(gr_s)
|
|
|
|
index = 1
|
2022-10-15 20:56:30 +02:00
|
|
|
for entry in friend.get_int_array("gr_s", 5):
|
|
|
|
gr_s.set_attribute(f"gr{index}", str(entry))
|
2019-12-08 22:43:49 +01:00
|
|
|
index = index + 1
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
gr_d = Node.void("gr_d")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(gr_d)
|
|
|
|
index = 1
|
2022-10-15 20:56:30 +02:00
|
|
|
for entry in friend.get_int_array("gr_d", 5):
|
|
|
|
gr_d.set_attribute(f"gr{index}", str(entry))
|
2019-12-08 22:43:49 +01:00
|
|
|
index = index + 1
|
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameLoadCourseHandler(DDRBase):
|
|
|
|
def handle_game_load_c_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
extid = intish(request.attribute("code"))
|
|
|
|
refid = request.attribute("refid")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if extid is not None:
|
|
|
|
# Rival score loading
|
|
|
|
userid = self.data.remote.user.from_extid(self.game, self.version, extid)
|
|
|
|
else:
|
|
|
|
# Self score loading
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
|
|
|
|
coursedata = [0] * 3200
|
|
|
|
if userid is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
for course in self.data.local.user.get_achievements(
|
|
|
|
self.game, self.version, userid
|
|
|
|
):
|
|
|
|
if course.type != "course":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
# Grab course ID and chart (kinda pointless because we add it right back up
|
|
|
|
# below, but it is more documented/readable this way.
|
|
|
|
courseid = int(course.id / 4)
|
|
|
|
coursechart = course.id % 4
|
|
|
|
|
|
|
|
# Populate course data
|
|
|
|
index = ((courseid * 4) + coursechart) * 8
|
|
|
|
if index >= 0 and index <= (len(coursedata) - 8):
|
2022-10-15 20:56:30 +02:00
|
|
|
coursedata[index + 0] = int(course.data.get_int("score") / 10000)
|
|
|
|
coursedata[index + 1] = course.data.get_int("score") % 10000
|
|
|
|
coursedata[index + 2] = course.data.get_int("combo")
|
|
|
|
coursedata[index + 3] = self.db_to_game_rank(
|
|
|
|
course.data.get_int("rank")
|
|
|
|
)
|
|
|
|
coursedata[index + 5] = course.data.get_int("stage")
|
|
|
|
coursedata[index + 6] = course.data.get_int("combo_type")
|
|
|
|
|
|
|
|
game = Node.void("game")
|
|
|
|
game.add_child(Node.u16_array("course", coursedata))
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
|
|
|
|
class DDRGameSaveCourseHandler(DDRBase):
|
|
|
|
def handle_game_save_c_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
|
|
|
courseid = int(request.attribute("cid"))
|
|
|
|
chart = int(request.attribute("ctype"))
|
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:
|
|
|
|
# Calculate statistics
|
2022-10-15 20:56:30 +02:00
|
|
|
data = request.child("data")
|
|
|
|
points = int(data.attribute("score"))
|
|
|
|
combo = int(data.attribute("combo"))
|
|
|
|
combo_type = int(data.attribute("combo_type"))
|
|
|
|
stage = int(data.attribute("stage"))
|
|
|
|
rank = self.game_to_db_rank(int(data.attribute("rank")))
|
|
|
|
trace = request.child_value("trace")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab the old course score
|
|
|
|
oldcourse = self.data.local.user.get_achievement(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
(courseid * 4) + chart,
|
2022-10-15 20:56:30 +02:00
|
|
|
"course",
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
if oldcourse is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
highscore = points > oldcourse.get_int("score")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
points = max(points, oldcourse.get_int("score"))
|
|
|
|
combo = max(combo, oldcourse.get_int("combo"))
|
|
|
|
stage = max(stage, oldcourse.get_int("stage"))
|
|
|
|
rank = max(rank, oldcourse.get_int("rank"))
|
|
|
|
combo_type = max(combo_type, oldcourse.get_int("combo_type"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if not highscore:
|
|
|
|
# Don't overwrite the ghost for a non-highscore
|
2022-10-15 20:56:30 +02:00
|
|
|
trace = oldcourse.get_int_array("trace", len(trace))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
self.data.local.user.put_achievement(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
userid,
|
|
|
|
(courseid * 4) + chart,
|
2022-10-15 20:56:30 +02:00
|
|
|
"course",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"score": points,
|
|
|
|
"combo": combo,
|
|
|
|
"stage": stage,
|
|
|
|
"rank": rank,
|
|
|
|
"combo_type": combo_type,
|
|
|
|
"trace": trace,
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
# No response needed
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|