2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
from typing import Any, Dict, Optional, 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.ess import EventLogHandler
|
|
|
|
from bemani.backend.sdvx.base import SoundVoltexBase
|
2021-08-20 06:43:13 +02:00
|
|
|
from bemani.common import Profile, VersionConstants, ID, intish
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import Score, UserID
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
class SoundVoltexBooth(
|
|
|
|
EventLogHandler,
|
|
|
|
SoundVoltexBase,
|
|
|
|
):
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
name: str = "SOUND VOLTEX BOOTH"
|
2021-09-07 19:56:15 +02:00
|
|
|
version: int = VersionConstants.SDVX_BOOTH
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-07 19:56:15 +02:00
|
|
|
GAME_LIMITED_LOCKED: Final[int] = 1
|
|
|
|
GAME_LIMITED_UNLOCKED: Final[int] = 2
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-07 19:56:15 +02:00
|
|
|
GAME_CURRENCY_PACKETS: Final[int] = 0
|
|
|
|
GAME_CURRENCY_BLOCKS: Final[int] = 1
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-07 19:56:15 +02:00
|
|
|
GAME_CLEAR_TYPE_NO_CLEAR: Final[int] = 1
|
|
|
|
GAME_CLEAR_TYPE_CLEAR: Final[int] = 2
|
|
|
|
GAME_CLEAR_TYPE_ULTIMATE_CHAIN: Final[int] = 3
|
|
|
|
GAME_CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN: Final[int] = 4
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2021-09-07 19:56:15 +02:00
|
|
|
GAME_GRADE_NO_PLAY: Final[int] = 0
|
|
|
|
GAME_GRADE_D: Final[int] = 1
|
|
|
|
GAME_GRADE_C: Final[int] = 2
|
|
|
|
GAME_GRADE_B: Final[int] = 3
|
|
|
|
GAME_GRADE_A: Final[int] = 4
|
|
|
|
GAME_GRADE_AA: Final[int] = 5
|
|
|
|
GAME_GRADE_AAA: Final[int] = 6
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_settings(cls) -> Dict[str, Any]:
|
|
|
|
"""
|
|
|
|
Return all of our front-end modifiably settings.
|
|
|
|
"""
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"bools": [
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"name": "Disable Online Matching",
|
|
|
|
"tip": "Disable online matching between games.",
|
|
|
|
"category": "game_config",
|
|
|
|
"setting": "disable_matching",
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"name": "Force Song Unlock",
|
|
|
|
"tip": "Force unlock all songs.",
|
|
|
|
"category": "game_config",
|
|
|
|
"setting": "force_unlock_songs",
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"name": "Force Appeal Card Unlock",
|
|
|
|
"tip": "Force unlock all appeal cards.",
|
|
|
|
"category": "game_config",
|
|
|
|
"setting": "force_unlock_cards",
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
def previous_version(self) -> Optional[SoundVoltexBase]:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def __game_to_db_clear_type(self, clear_type: int) -> int:
|
|
|
|
return {
|
|
|
|
self.GAME_CLEAR_TYPE_NO_CLEAR: self.CLEAR_TYPE_FAILED,
|
|
|
|
self.GAME_CLEAR_TYPE_CLEAR: self.CLEAR_TYPE_CLEAR,
|
|
|
|
self.GAME_CLEAR_TYPE_ULTIMATE_CHAIN: self.CLEAR_TYPE_ULTIMATE_CHAIN,
|
|
|
|
self.GAME_CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN: self.CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN,
|
|
|
|
}[clear_type]
|
|
|
|
|
|
|
|
def __db_to_game_clear_type(self, clear_type: int) -> int:
|
|
|
|
return {
|
|
|
|
self.CLEAR_TYPE_NO_PLAY: self.GAME_CLEAR_TYPE_NO_CLEAR,
|
|
|
|
self.CLEAR_TYPE_FAILED: self.GAME_CLEAR_TYPE_NO_CLEAR,
|
|
|
|
self.CLEAR_TYPE_CLEAR: self.GAME_CLEAR_TYPE_CLEAR,
|
|
|
|
self.CLEAR_TYPE_HARD_CLEAR: self.GAME_CLEAR_TYPE_CLEAR,
|
|
|
|
self.CLEAR_TYPE_ULTIMATE_CHAIN: self.GAME_CLEAR_TYPE_ULTIMATE_CHAIN,
|
|
|
|
self.CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN: self.GAME_CLEAR_TYPE_PERFECT_ULTIMATE_CHAIN,
|
|
|
|
}[clear_type]
|
|
|
|
|
|
|
|
def __game_to_db_grade(self, grade: int) -> int:
|
|
|
|
return {
|
|
|
|
self.GAME_GRADE_NO_PLAY: self.GRADE_NO_PLAY,
|
|
|
|
self.GAME_GRADE_D: self.GRADE_D,
|
|
|
|
self.GAME_GRADE_C: self.GRADE_C,
|
|
|
|
self.GAME_GRADE_B: self.GRADE_B,
|
|
|
|
self.GAME_GRADE_A: self.GRADE_A,
|
|
|
|
self.GAME_GRADE_AA: self.GRADE_AA,
|
|
|
|
self.GAME_GRADE_AAA: self.GRADE_AAA,
|
|
|
|
}[grade]
|
|
|
|
|
|
|
|
def __db_to_game_grade(self, grade: int) -> int:
|
|
|
|
return {
|
|
|
|
self.GRADE_NO_PLAY: self.GAME_GRADE_NO_PLAY,
|
|
|
|
self.GRADE_D: self.GAME_GRADE_D,
|
|
|
|
self.GRADE_C: self.GAME_GRADE_C,
|
|
|
|
self.GRADE_B: self.GAME_GRADE_B,
|
|
|
|
self.GRADE_A: self.GAME_GRADE_A,
|
|
|
|
self.GRADE_A_PLUS: self.GAME_GRADE_A,
|
|
|
|
self.GRADE_AA: self.GAME_GRADE_AA,
|
|
|
|
self.GRADE_AA_PLUS: self.GAME_GRADE_AA,
|
|
|
|
self.GRADE_AAA: self.GAME_GRADE_AAA,
|
|
|
|
self.GRADE_AAA_PLUS: self.GAME_GRADE_AAA,
|
|
|
|
self.GRADE_S: self.GAME_GRADE_AAA,
|
|
|
|
}[grade]
|
|
|
|
|
|
|
|
def handle_game_exception_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
|
|
|
|
|
|
|
def handle_game_entry_s_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
# This should be created on the fly for a lobby that we're in.
|
2022-10-15 20:56:30 +02:00
|
|
|
game.add_child(Node.u32("entry_id", 1))
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_lounge_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
# Refresh interval in seconds.
|
2022-10-15 20:56:30 +02:00
|
|
|
game.add_child(Node.u32("interval", 10))
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_entry_e_request(self, request: Node) -> Node:
|
|
|
|
# Lobby destroy method, eid attribute (u32) should be used
|
|
|
|
# to destroy any open lobbies.
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_game_frozen_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
game.set_attribute("result", "0")
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_shop_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
self.update_machine_name(request.child_value("shopname"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Respond with number of milliseconds until next request
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
game.add_child(Node.u32("nxt_time", 1000 * 5 * 60))
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_common_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
limited = Node.void("limited")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(limited)
|
|
|
|
|
|
|
|
game_config = self.get_game_config()
|
2022-10-15 20:56:30 +02:00
|
|
|
if game_config.get_bool("force_unlock_songs"):
|
2019-12-08 22:43:49 +01:00
|
|
|
ids = set()
|
|
|
|
songs = self.data.local.music.get_all_songs(self.game, self.version)
|
|
|
|
for song in songs:
|
2022-10-15 20:56:30 +02:00
|
|
|
if song.data.get_int("limited") == self.GAME_LIMITED_LOCKED:
|
2019-12-08 22:43:49 +01:00
|
|
|
ids.add(song.id)
|
|
|
|
|
|
|
|
for songid in ids:
|
2022-10-15 20:56:30 +02:00
|
|
|
music = Node.void("music")
|
2019-12-08 22:43:49 +01:00
|
|
|
limited.add_child(music)
|
2022-10-15 20:56:30 +02:00
|
|
|
music.set_attribute("id", str(songid))
|
|
|
|
music.set_attribute("flag", str(self.GAME_LIMITED_UNLOCKED))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
event = Node.void("event")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(event)
|
|
|
|
|
|
|
|
def enable_event(eid: int) -> None:
|
2022-10-15 20:56:30 +02:00
|
|
|
evt = Node.void("info")
|
2019-12-08 22:43:49 +01:00
|
|
|
event.add_child(evt)
|
2022-10-15 20:56:30 +02:00
|
|
|
evt.set_attribute("id", str(eid))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if not game_config.get_bool("disable_matching"):
|
2019-12-08 22:43:49 +01:00
|
|
|
enable_event(3) # Matching enabled
|
|
|
|
enable_event(9) # Rank Soukuu
|
|
|
|
enable_event(13) # Year-end bonus
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
catalog = Node.void("catalog")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(catalog)
|
|
|
|
songunlocks = self.data.local.game.get_items(self.game, self.version)
|
|
|
|
for unlock in songunlocks:
|
2022-10-15 20:56:30 +02:00
|
|
|
if unlock.type != "song_unlock":
|
2019-12-08 22:43:49 +01:00
|
|
|
continue
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
info = Node.void("info")
|
2019-12-08 22:43:49 +01:00
|
|
|
catalog.add_child(info)
|
2022-10-15 20:56:30 +02:00
|
|
|
info.set_attribute("id", str(unlock.id))
|
|
|
|
info.set_attribute("currency", str(self.GAME_CURRENCY_BLOCKS))
|
|
|
|
info.set_attribute("price", str(unlock.data.get_int("blocks")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
kacinfo = Node.void("kacinfo")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(kacinfo)
|
2022-10-15 20:56:30 +02:00
|
|
|
kacinfo.add_child(Node.u32("note00", 0))
|
|
|
|
kacinfo.add_child(Node.u32("note01", 0))
|
|
|
|
kacinfo.add_child(Node.u32("note02", 0))
|
|
|
|
kacinfo.add_child(Node.u32("note10", 0))
|
|
|
|
kacinfo.add_child(Node.u32("note11", 0))
|
|
|
|
kacinfo.add_child(Node.u32("note12", 0))
|
|
|
|
kacinfo.add_child(Node.u32("rabbeat0", 0))
|
|
|
|
kacinfo.add_child(Node.u32("rabbeat1", 0))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_hiscore_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Ranking system I think?
|
|
|
|
for i in range(1, 21):
|
2022-10-15 20:56:30 +02:00
|
|
|
ranking = Node.void("ranking")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(ranking)
|
2022-10-15 20:56:30 +02:00
|
|
|
ranking.set_attribute("id", str(i))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
hiscore = Node.void("hiscore")
|
2019-12-08 22:43:49 +01:00
|
|
|
game.add_child(hiscore)
|
2022-10-15 20:56:30 +02:00
|
|
|
hiscore.set_attribute("type", "1")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
records = self.data.remote.music.get_all_records(self.game, self.version)
|
|
|
|
|
|
|
|
# Organize by song->chart
|
|
|
|
records_by_id: Dict[int, Dict[int, Tuple[UserID, Score]]] = {}
|
|
|
|
missing_users = []
|
|
|
|
for record in records:
|
|
|
|
userid, score = record
|
|
|
|
if score.id not in records_by_id:
|
|
|
|
records_by_id[score.id] = {}
|
|
|
|
|
|
|
|
records_by_id[score.id][score.chart] = record
|
|
|
|
missing_users.append(userid)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
users = {
|
|
|
|
userid: profile
|
|
|
|
for (userid, profile) in self.get_any_profiles(missing_users)
|
|
|
|
}
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Output records
|
|
|
|
for songid in records_by_id:
|
2022-10-15 20:56:30 +02:00
|
|
|
music = Node.void("music")
|
2019-12-08 22:43:49 +01:00
|
|
|
hiscore.add_child(music)
|
2022-10-15 20:56:30 +02:00
|
|
|
music.set_attribute("id", str(songid))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for chart in records_by_id[songid]:
|
2022-10-15 20:56:30 +02:00
|
|
|
note = Node.void("note")
|
2019-12-08 22:43:49 +01:00
|
|
|
music.add_child(note)
|
2022-10-15 20:56:30 +02:00
|
|
|
note.set_attribute("type", str(chart))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
userid, score = records_by_id[songid][chart]
|
2022-10-15 20:56:30 +02:00
|
|
|
note.set_attribute("score", str(score.points))
|
|
|
|
note.set_attribute("name", users[userid].get_str("name"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_new_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("refid")
|
|
|
|
name = request.attribute("name")
|
|
|
|
loc = ID.parse_machine_id(request.attribute("locid"))
|
2019-12-08 22:43:49 +01:00
|
|
|
self.new_profile_by_refid(refid, name, loc)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
return root
|
|
|
|
|
|
|
|
def handle_game_load_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("dataid")
|
2019-12-08 22:43:49 +01:00
|
|
|
root = self.get_profile_by_refid(refid)
|
|
|
|
if root is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
root = Node.void("game")
|
|
|
|
root.set_attribute("none", "1")
|
2019-12-08 22:43:49 +01:00
|
|
|
return root
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if refid is not None:
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
else:
|
|
|
|
userid = None
|
|
|
|
|
|
|
|
if userid is not None:
|
|
|
|
oldprofile = self.get_profile(userid)
|
|
|
|
newprofile = self.unformat_profile(userid, request, oldprofile)
|
|
|
|
else:
|
|
|
|
newprofile = None
|
|
|
|
|
|
|
|
if userid is not None and newprofile is not None:
|
|
|
|
self.put_profile(userid, newprofile)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_game_load_m_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("dataid")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if refid is not None:
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
else:
|
|
|
|
userid = None
|
|
|
|
|
|
|
|
if userid is not None:
|
|
|
|
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
|
|
|
|
else:
|
|
|
|
scores = []
|
|
|
|
|
|
|
|
# Organize by song->chart
|
|
|
|
scores_by_id: Dict[int, Dict[int, Score]] = {}
|
|
|
|
for score in scores:
|
|
|
|
if score.id not in scores_by_id:
|
|
|
|
scores_by_id[score.id] = {}
|
|
|
|
|
|
|
|
scores_by_id[score.id][score.chart] = score
|
|
|
|
|
|
|
|
# Output to the game
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
for songid in scores_by_id:
|
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("music_id", str(songid))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for chart in scores_by_id[songid]:
|
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("type_id", str(chart))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
score = scores_by_id[songid][chart]
|
2022-10-15 20:56:30 +02:00
|
|
|
typenode.set_attribute("score", str(score.points))
|
|
|
|
typenode.set_attribute("cnt", str(score.plays))
|
|
|
|
typenode.set_attribute(
|
|
|
|
"clear_type",
|
|
|
|
str(self.__db_to_game_clear_type(score.data.get_int("clear_type"))),
|
|
|
|
)
|
|
|
|
typenode.set_attribute(
|
|
|
|
"score_grade",
|
|
|
|
str(self.__db_to_game_grade(score.data.get_int("grade"))),
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
|
|
|
def handle_game_save_m_request(self, request: Node) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
refid = request.attribute("dataid")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if refid is not None:
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
else:
|
|
|
|
userid = None
|
|
|
|
|
|
|
|
if userid is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
musicid = int(request.attribute("music_id"))
|
|
|
|
chart = int(request.attribute("music_type"))
|
|
|
|
score = int(request.attribute("score"))
|
|
|
|
combo = int(request.attribute("max_chain"))
|
|
|
|
grade = self.__game_to_db_grade(int(request.attribute("score_grade")))
|
|
|
|
clear_type = self.__game_to_db_clear_type(int(request.attribute("clear_type")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Save the score
|
|
|
|
self.update_score(
|
|
|
|
userid,
|
|
|
|
musicid,
|
|
|
|
chart,
|
|
|
|
score,
|
|
|
|
clear_type,
|
|
|
|
grade,
|
|
|
|
combo,
|
|
|
|
)
|
|
|
|
|
|
|
|
# No response necessary
|
2022-10-15 20:56:30 +02:00
|
|
|
return Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def handle_game_buy_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
|
|
|
|
|
|
|
if refid is not None:
|
|
|
|
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
|
|
|
|
else:
|
|
|
|
userid = None
|
|
|
|
|
|
|
|
if userid is not None:
|
|
|
|
profile = self.get_profile(userid)
|
|
|
|
else:
|
|
|
|
profile = None
|
|
|
|
|
|
|
|
if userid is not None and profile is not None:
|
|
|
|
# Look up packets and blocks
|
2022-10-15 20:56:30 +02:00
|
|
|
packet = profile.get_int("packet")
|
|
|
|
block = profile.get_int("block")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Add on any additional we earned this round
|
2022-10-15 20:56:30 +02:00
|
|
|
packet = packet + (request.child_value("earned_gamecoin_packet") or 0)
|
|
|
|
block = block + (request.child_value("earned_gamecoin_block") or 0)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Look up the item to get the actual price and currency used
|
2022-10-15 20:56:30 +02:00
|
|
|
item = self.data.local.game.get_item(
|
|
|
|
self.game,
|
|
|
|
self.version,
|
|
|
|
request.child_value("catalog_id"),
|
|
|
|
"song_unlock",
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
if item is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
currency_type = request.child_value("currency_type")
|
2019-12-08 22:43:49 +01:00
|
|
|
if currency_type == self.GAME_CURRENCY_PACKETS:
|
2022-10-15 20:56:30 +02:00
|
|
|
if "packets" in item:
|
2019-12-08 22:43:49 +01:00
|
|
|
# This is a valid purchase
|
2022-10-15 20:56:30 +02:00
|
|
|
newpacket = packet - item.get_int("packets")
|
2019-12-08 22:43:49 +01:00
|
|
|
if newpacket < 0:
|
|
|
|
result = 1
|
|
|
|
else:
|
|
|
|
packet = newpacket
|
|
|
|
result = 0
|
|
|
|
else:
|
|
|
|
# Bad transaction
|
|
|
|
result = 1
|
|
|
|
elif currency_type == self.GAME_CURRENCY_BLOCKS:
|
2022-10-15 20:56:30 +02:00
|
|
|
if "blocks" in item:
|
2019-12-08 22:43:49 +01:00
|
|
|
# This is a valid purchase
|
2022-10-15 20:56:30 +02:00
|
|
|
newblock = block - item.get_int("blocks")
|
2019-12-08 22:43:49 +01:00
|
|
|
if newblock < 0:
|
|
|
|
result = 1
|
|
|
|
else:
|
|
|
|
block = newblock
|
|
|
|
result = 0
|
|
|
|
else:
|
|
|
|
# Bad transaction
|
|
|
|
result = 1
|
|
|
|
else:
|
|
|
|
# Bad currency type
|
|
|
|
result = 1
|
|
|
|
|
|
|
|
if result == 0:
|
|
|
|
# Transaction is valid, update the profile with new packets and blocks
|
2022-10-15 20:56:30 +02:00
|
|
|
profile.replace_int("packet", packet)
|
|
|
|
profile.replace_int("block", block)
|
2019-12-08 22:43:49 +01:00
|
|
|
self.put_profile(userid, profile)
|
|
|
|
else:
|
|
|
|
# Bad catalog ID
|
|
|
|
result = 1
|
|
|
|
else:
|
|
|
|
# Unclear what to do here, return a bad response
|
|
|
|
packet = 0
|
|
|
|
block = 0
|
|
|
|
result = 1
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
|
|
|
game.add_child(Node.u32("gamecoin_packet", packet))
|
|
|
|
game.add_child(Node.u32("gamecoin_block", block))
|
|
|
|
game.add_child(Node.s8("result", result))
|
2019-12-08 22:43:49 +01:00
|
|
|
return game
|
|
|
|
|
2021-08-20 06:43:13 +02:00
|
|
|
def format_profile(self, userid: UserID, profile: Profile) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
game = Node.void("game")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Generic profile stuff
|
2022-10-15 20:56:30 +02:00
|
|
|
game.add_child(Node.string("name", profile.get_str("name")))
|
|
|
|
game.add_child(Node.string("code", ID.format_extid(profile.extid)))
|
|
|
|
game.add_child(Node.u32("gamecoin_packet", profile.get_int("packet")))
|
|
|
|
game.add_child(Node.u32("gamecoin_block", profile.get_int("block")))
|
|
|
|
game.add_child(Node.u32("exp_point", profile.get_int("exp")))
|
|
|
|
game.add_child(Node.u32("m_user_cnt", profile.get_int("m_user_cnt")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
game_config = self.get_game_config()
|
2022-10-15 20:56:30 +02:00
|
|
|
if game_config.get_bool("force_unlock_cards"):
|
|
|
|
game.add_child(Node.bool_array("have_item", [True] * 512))
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
game.add_child(
|
|
|
|
Node.bool_array(
|
|
|
|
"have_item",
|
|
|
|
[x > 0 for x in profile.get_int_array("have_item", 512)],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if game_config.get_bool("force_unlock_songs"):
|
|
|
|
game.add_child(Node.bool_array("have_note", [True] * 512))
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
game.add_child(
|
|
|
|
Node.bool_array(
|
|
|
|
"have_note",
|
|
|
|
[x > 0 for x in profile.get_int_array("have_note", 512)],
|
|
|
|
)
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Last played stuff
|
2022-10-15 20:56:30 +02:00
|
|
|
lastdict = profile.get_dict("last")
|
|
|
|
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("music_id", str(lastdict.get_int("music_id")))
|
|
|
|
last.set_attribute("music_type", str(lastdict.get_int("music_type")))
|
|
|
|
last.set_attribute("sort_type", str(lastdict.get_int("sort_type")))
|
|
|
|
last.set_attribute("headphone", str(lastdict.get_int("headphone")))
|
|
|
|
last.set_attribute("hispeed", str(lastdict.get_int("hispeed")))
|
|
|
|
last.set_attribute("appeal_id", str(lastdict.get_int("appeal_id")))
|
|
|
|
last.set_attribute("frame0", str(lastdict.get_int("frame0")))
|
|
|
|
last.set_attribute("frame1", str(lastdict.get_int("frame1")))
|
|
|
|
last.set_attribute("frame2", str(lastdict.get_int("frame2")))
|
|
|
|
last.set_attribute("frame3", str(lastdict.get_int("frame3")))
|
|
|
|
last.set_attribute("frame4", str(lastdict.get_int("frame4")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return game
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def unformat_profile(
|
|
|
|
self, userid: UserID, request: Node, oldprofile: Profile
|
|
|
|
) -> Profile:
|
2021-09-07 19:56:15 +02:00
|
|
|
newprofile = oldprofile.clone()
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Update experience and in-game currencies
|
2022-10-15 20:56:30 +02:00
|
|
|
earned_gamecoin_packet = request.child_value("earned_gamecoin_packet")
|
2019-12-08 22:43:49 +01:00
|
|
|
if earned_gamecoin_packet is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int(
|
|
|
|
"packet", newprofile.get_int("packet") + earned_gamecoin_packet
|
|
|
|
)
|
|
|
|
earned_gamecoin_block = request.child_value("earned_gamecoin_block")
|
2019-12-08 22:43:49 +01:00
|
|
|
if earned_gamecoin_block is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int(
|
|
|
|
"block", newprofile.get_int("block") + earned_gamecoin_block
|
|
|
|
)
|
|
|
|
gain_exp = request.child_value("gain_exp")
|
2019-12-08 22:43:49 +01:00
|
|
|
if gain_exp is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("exp", newprofile.get_int("exp") + gain_exp)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Miscelaneous stuff
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int("m_user_cnt", request.child_value("m_user_cnt"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Update user's unlock status if we aren't force unlocked
|
|
|
|
game_config = self.get_game_config()
|
2022-10-15 20:56:30 +02:00
|
|
|
if not game_config.get_bool("force_unlock_cards"):
|
|
|
|
have_item = request.child_value("have_item")
|
2019-12-08 22:43:49 +01:00
|
|
|
if have_item is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int_array(
|
|
|
|
"have_item", 512, [1 if x else 0 for x in have_item]
|
|
|
|
)
|
|
|
|
if not game_config.get_bool("force_unlock_songs"):
|
|
|
|
have_note = request.child_value("have_note")
|
2019-12-08 22:43:49 +01:00
|
|
|
if have_note is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_int_array(
|
|
|
|
"have_note", 512, [1 if x else 0 for x in have_note]
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab last information.
|
2022-10-15 20:56:30 +02:00
|
|
|
lastdict = newprofile.get_dict("last")
|
|
|
|
lastdict.replace_int("headphone", request.child_value("headphone"))
|
|
|
|
lastdict.replace_int("hispeed", request.child_value("hispeed"))
|
|
|
|
lastdict.replace_int("appeal_id", request.child_value("appeal_id"))
|
|
|
|
lastdict.replace_int("frame0", request.child_value("frame0"))
|
|
|
|
lastdict.replace_int("frame1", request.child_value("frame1"))
|
|
|
|
lastdict.replace_int("frame2", request.child_value("frame2"))
|
|
|
|
lastdict.replace_int("frame3", request.child_value("frame3"))
|
|
|
|
lastdict.replace_int("frame4", request.child_value("frame4"))
|
|
|
|
last = request.child("last")
|
2019-12-08 22:43:49 +01:00
|
|
|
if last is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
lastdict.replace_int("music_id", intish(last.attribute("music_id")))
|
|
|
|
lastdict.replace_int("music_type", intish(last.attribute("music_type")))
|
|
|
|
lastdict.replace_int("sort_type", intish(last.attribute("sort_type")))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Save back last information gleaned from results
|
2022-10-15 20:56:30 +02:00
|
|
|
newprofile.replace_dict("last", lastdict)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Keep track of play statistics
|
|
|
|
self.update_play_statistics(userid)
|
|
|
|
|
|
|
|
return newprofile
|