From d162d57024e59d61ada55d4db3398d5f4c225132 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sat, 19 Aug 2023 19:04:12 +0000 Subject: [PATCH] Move logic for handling mdata_ver into central place for Jubeat, fix saucer and fulfill over-sending rival data. --- bemani/backend/jubeat/base.py | 22 +++++++++++++++------- bemani/backend/jubeat/clan.py | 16 ++-------------- bemani/backend/jubeat/festo.py | 16 ++-------------- bemani/backend/jubeat/prop.py | 16 ++-------------- bemani/backend/jubeat/qubell.py | 16 ++-------------- bemani/backend/jubeat/saucer.py | 20 ++++---------------- bemani/backend/jubeat/saucerfulfill.py | 20 ++++---------------- 7 files changed, 31 insertions(+), 95 deletions(-) diff --git a/bemani/backend/jubeat/base.py b/bemani/backend/jubeat/base.py index e4977ca..e1371a9 100644 --- a/bemani/backend/jubeat/base.py +++ b/bemani/backend/jubeat/base.py @@ -159,23 +159,31 @@ class JubeatBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): return self.format_profile(userid, profile) - def get_scores_by_extid(self, extid: Optional[int]) -> Optional[Node]: + def get_scores_by_extid( + self, extid: Optional[int], partition: int, total_partitions: int + ) -> Optional[Node]: """ Given an ExtID, return a formatted score node. Similar rationale to - get_profile_by_refid. + get_profile_by_refid. Note that this takes into account the game's + desire to partition scores into separate fetches to ensure that we + don't make any one request too long. We handle the logic for that here. """ if extid is None: return None userid = self.data.remote.user.from_extid(self.game, self.version, extid) - scores = self.data.remote.music.get_scores( - self.game, self.music_version, userid - ) - if scores is None: - return None profile = self.get_profile(userid) if profile is None: return None + + if partition != 1: + scores = [] + else: + scores = self.data.remote.music.get_scores( + self.game, self.music_version, userid + ) + if scores is None: + return None return self.format_scores(userid, profile, scores) def update_score( diff --git a/bemani/backend/jubeat/clan.py b/bemani/backend/jubeat/clan.py index 2377da2..4163d41 100644 --- a/bemani/backend/jubeat/clan.py +++ b/bemani/backend/jubeat/clan.py @@ -1377,20 +1377,8 @@ class JubeatClan( data = request.child("data") player = data.child("player") extid = player.child_value("jid") - mdata_ver = player.child_value( - "mdata_ver" - ) # Game requests mdata 3 times per profile for some reason - if mdata_ver != 1: - root = Node.void("gametop") - datanode = Node.void("data") - root.add_child(datanode) - player = Node.void("player") - datanode.add_child(player) - player.add_child(Node.s32("jid", extid)) - playdata = Node.void("mdata_list") - player.add_child(playdata) - return root - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE)) diff --git a/bemani/backend/jubeat/festo.py b/bemani/backend/jubeat/festo.py index 19d59c0..5753171 100644 --- a/bemani/backend/jubeat/festo.py +++ b/bemani/backend/jubeat/festo.py @@ -2178,20 +2178,8 @@ class JubeatFesto( data = request.child("data") player = data.child("player") extid = player.child_value("jid") - mdata_ver = player.child_value( - "mdata_ver" - ) # Game requests mdata 3 times per profile for some reason - if mdata_ver != 1: - root = Node.void("gametop") - datanode = Node.void("data") - root.add_child(datanode) - player = Node.void("player") - datanode.add_child(player) - player.add_child(Node.s32("jid", extid)) - playdata = Node.void("mdata_list") - player.add_child(playdata) - return root - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE)) diff --git a/bemani/backend/jubeat/prop.py b/bemani/backend/jubeat/prop.py index 45e2b67..ffe9ec4 100644 --- a/bemani/backend/jubeat/prop.py +++ b/bemani/backend/jubeat/prop.py @@ -632,20 +632,8 @@ class JubeatProp( data = request.child("data") player = data.child("player") extid = player.child_value("jid") - mdata_ver = player.child_value( - "mdata_ver" - ) # Game requests mdata 3 times per profile for some reason - if mdata_ver != 1: - root = Node.void("gametop") - datanode = Node.void("data") - root.add_child(datanode) - player = Node.void("player") - datanode.add_child(player) - player.add_child(Node.s32("jid", extid)) - playdata = Node.void("mdata_list") - player.add_child(playdata) - return root - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE)) diff --git a/bemani/backend/jubeat/qubell.py b/bemani/backend/jubeat/qubell.py index 3be1981..84943ca 100644 --- a/bemani/backend/jubeat/qubell.py +++ b/bemani/backend/jubeat/qubell.py @@ -639,20 +639,8 @@ class JubeatQubell( data = request.child("data") player = data.child("player") extid = player.child_value("jid") - mdata_ver = player.child_value( - "mdata_ver" - ) # Game requests mdata 3 times per profile for some reason - if mdata_ver != 1: - root = Node.void("gametop") - datanode = Node.void("data") - root.add_child(datanode) - player = Node.void("player") - datanode.add_child(player) - player.add_child(Node.s32("jid", extid)) - playdata = Node.void("mdata_list") - player.add_child(playdata) - return root - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE)) diff --git a/bemani/backend/jubeat/saucer.py b/bemani/backend/jubeat/saucer.py index d2c1387..a960715 100644 --- a/bemani/backend/jubeat/saucer.py +++ b/bemani/backend/jubeat/saucer.py @@ -185,21 +185,8 @@ class JubeatSaucer( data = request.child("data") player = data.child("player") extid = player.child_value("jid") - mdata_ver = player.child_value( - "mdata_ver" - ) # Game requests mdata 3 times per profile for some reason - if mdata_ver != 1: - root = Node.void("gametop") - datanode = Node.void("data") - root.add_child(datanode) - player = Node.void("player") - datanode.add_child(player) - player.add_child(Node.s32("jid", extid)) - playdata = Node.void("playdata") - player.add_child(playdata) - playdata.set_attribute("count", "0") - return root - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE)) @@ -209,7 +196,8 @@ class JubeatSaucer( data = request.child("data") player = data.child("player") extid = player.child_value("rival") - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE)) diff --git a/bemani/backend/jubeat/saucerfulfill.py b/bemani/backend/jubeat/saucerfulfill.py index 58f4388..34b60f3 100644 --- a/bemani/backend/jubeat/saucerfulfill.py +++ b/bemani/backend/jubeat/saucerfulfill.py @@ -320,21 +320,8 @@ class JubeatSaucerFulfill( data = request.child("data") player = data.child("player") extid = player.child_value("jid") - mdata_ver = player.child_value( - "mdata_ver" - ) # Game requests mdata 3 times per profile for some reason - if mdata_ver != 1: - root = Node.void("gametop") - datanode = Node.void("data") - root.add_child(datanode) - player = Node.void("player") - datanode.add_child(player) - player.add_child(Node.s32("jid", extid)) - playdata = Node.void("playdata") - player.add_child(playdata) - playdata.set_attribute("count", "0") - return root - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE)) @@ -344,7 +331,8 @@ class JubeatSaucerFulfill( data = request.child("data") player = data.child("player") extid = player.child_value("rival") - root = self.get_scores_by_extid(extid) + mdata_ver = player.child_value("mdata_ver") + root = self.get_scores_by_extid(extid, mdata_ver, 3) if root is None: root = Node.void("gametop") root.set_attribute("status", str(Status.NO_PROFILE))