From c7affef159c268f0f4b5c9f7e500cf88147f87cb Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Tue, 7 Sep 2021 02:48:57 +0000 Subject: [PATCH] Use arcade/network region for default prefecture/region wherever possible, including in facility.get. Allows changing game region. --- bemani/backend/base.py | 23 ++++++++++-- bemani/backend/core/core.py | 54 +++++++++++++++++++++++++--- bemani/backend/ddr/common.py | 12 +++---- bemani/backend/ddr/ddr2013.py | 6 ++-- bemani/backend/ddr/ddr2014.py | 6 ++-- bemani/backend/ddr/ddrx2.py | 6 ++-- bemani/backend/ddr/ddrx3.py | 4 +-- bemani/backend/iidx/base.py | 2 +- bemani/backend/iidx/bistrover.py | 3 ++ bemani/backend/iidx/cannonballers.py | 5 ++- bemani/backend/iidx/copula.py | 2 +- bemani/backend/iidx/heroicverse.py | 3 ++ bemani/backend/iidx/pendual.py | 2 +- bemani/backend/iidx/rootage.py | 5 ++- bemani/backend/iidx/sinobuz.py | 2 +- bemani/backend/iidx/spada.py | 2 +- bemani/backend/iidx/tricoro.py | 2 +- bemani/backend/popn/fantasia.py | 2 +- bemani/backend/popn/lapistoria.py | 2 +- bemani/backend/popn/sunnypark.py | 2 +- bemani/backend/reflec/limelight.py | 4 +-- bemani/backend/reflec/reflecbeat.py | 6 ++-- bemani/common/constants.py | 4 +++ bemani/common/id.py | 8 +++-- 24 files changed, 124 insertions(+), 43 deletions(-) diff --git a/bemani/backend/base.py b/bemani/backend/base.py index 9c1169d..53428e9 100644 --- a/bemani/backend/base.py +++ b/bemani/backend/base.py @@ -3,8 +3,8 @@ import traceback from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Type from typing_extensions import Final -from bemani.common import Model, ValidatedDict, Profile, PlayStatistics, GameConstants, Time -from bemani.data import Config, Data, Machine, UserID, RemoteUser +from bemani.common import Model, ValidatedDict, Profile, PlayStatistics, GameConstants, RegionConstants, Time +from bemani.data import Config, Data, Arcade, Machine, UserID, RemoteUser class ProfileCreationException(Exception): @@ -238,6 +238,12 @@ class Base(ABC): """ return True + def requires_extended_regions(self) -> bool: + """ + Override this in your subclass if your game requires an updated region list. + """ + return False + def bind_profile(self, userid: UserID) -> None: """ Handling binding the user's profile to this version on this server. @@ -422,6 +428,19 @@ class Base(ABC): machine.data = newmachine.data self.data.local.machine.put_machine(machine) + def get_arcade(self) -> Optional[Arcade]: + machine = self.get_machine() + if machine.arcade is None: + return None + return self.data.local.machine.get_arcade(machine.arcade) + + def get_machine_region(self) -> int: + arcade = self.get_arcade() + if arcade is None: + return RegionConstants.db_to_game_region(self.requires_extended_regions(), self.config.server.region) + else: + return RegionConstants.db_to_game_region(self.requires_extended_regions(), arcade.region) + def get_game_config(self) -> ValidatedDict: machine = self.data.local.machine.get_machine(self.config.machine.pcbid) if machine.arcade is not None: diff --git a/bemani/backend/core/core.py b/bemani/backend/core/core.py index 69b27be..603a043 100644 --- a/bemani/backend/core/core.py +++ b/bemani/backend/core/core.py @@ -2,7 +2,7 @@ import socket from bemani.backend.base import Base from bemani.protocol import Node -from bemani.common import ID +from bemani.common import ID, RegionConstants class CoreHandler(Base): @@ -120,14 +120,58 @@ class CoreHandler(Base): which expects to return a bunch of information about the arcade this cabinet is in, as well as some settings for URLs and the name of the cab. """ - machine = self.data.local.machine.get_machine(self.config.machine.pcbid) + machine = self.get_machine() + if machine.arcade is None: + region = self.config.server.region + else: + arcade = self.data.local.machine.get_arcade(machine.arcade) + region = arcade.region + + if region == RegionConstants.HONG_KONG: + country = "HK" + regionstr = "" + elif region == RegionConstants.TAIWAN: + country = "TW" + regionstr = "" + elif region == RegionConstants.KOREA: + country = "KR" + regionstr = "" + elif region == RegionConstants.USA: + country = "US" + regionstr = "" + elif region == RegionConstants.THAILAND: + country = "TH" + regionstr = "" + elif region == RegionConstants.INDONESIA: + country = "ID" + regionstr = "" + elif region == RegionConstants.SINGAPORE: + country = "SG" + regionstr = "" + elif region == RegionConstants.PHILLIPINES: + country = "PH" + regionstr = "" + elif region == RegionConstants.MACAO: + country = "MO" + regionstr = "" + elif region >= RegionConstants.MIN_PREF and region <= RegionConstants.MAX_PREF: + country = "JP" + regionstr = f"JP-{region}" + elif region == RegionConstants.EUROPE: + # Pick a random country in the "Europe" category. + country = "GB" + regionstr = "" + else: + # Pick a random nonsensical code. + country = "XX" + regionstr = "" root = Node.void('facility') root.set_attribute('expire', '600') location = Node.void('location') - location.add_child(Node.string('id', ID.format_machine_id(machine.id))) - location.add_child(Node.string('country', 'US')) - location.add_child(Node.string('region', '.')) + location.add_child(Node.string('id', ID.format_machine_id(machine.id, region=country))) + location.add_child(Node.string('country', country)) + location.add_child(Node.string('region', regionstr)) location.add_child(Node.string('name', machine.name)) location.add_child(Node.u8('type', 0)) diff --git a/bemani/backend/ddr/common.py b/bemani/backend/ddr/common.py index db97ff2..58f4f02 100644 --- a/bemani/backend/ddr/common.py +++ b/bemani/backend/ddr/common.py @@ -95,7 +95,7 @@ class DDRGameHiscoreHandler(DDRBase): 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', 51))) + 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)) @@ -111,7 +111,7 @@ class DDRGameAreaHiscoreHandler(DDRBase): # First, get all users that are in the current shop's area area_users = { uid: prof for (uid, prof) in self.data.local.user.get_all_profiles(self.game, self.version) - if prof.get_int('area', 51) == shop_area + if prof.get_int('area', self.get_machine_region()) == shop_area } # Second, look up records belonging only to those users @@ -134,7 +134,7 @@ class DDRGameAreaHiscoreHandler(DDRBase): for chart in area_records[song]: userid, score = area_records[song][chart] - if area_users[userid].get_int('area', 51) != shop_area: + if area_users[userid].get_int('area', self.get_machine_region()) != shop_area: # Don't return this, this user isn't in this area continue try: @@ -151,7 +151,7 @@ class DDRGameAreaHiscoreHandler(DDRBase): 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', 51))) + 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)) @@ -301,7 +301,7 @@ class DDRGameOldHandler(DDRBase): oldprofile = previous_version.get_profile(userid) if oldprofile is not None: game.set_attribute('name', oldprofile.get_str('name')) - game.set_attribute('area', str(oldprofile.get_int('area', 51))) + game.set_attribute('area', str(oldprofile.get_int('area', self.get_machine_region()))) return game @@ -354,7 +354,7 @@ class DDRGameFriendHandler(DDRBase): 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', 51))) + 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'))) diff --git a/bemani/backend/ddr/ddr2013.py b/bemani/backend/ddr/ddr2013.py index aa3c77c..2dc3360 100644 --- a/bemani/backend/ddr/ddr2013.py +++ b/bemani/backend/ddr/ddr2013.py @@ -169,7 +169,7 @@ class DDR2013( flag.set_attribute('t', '0') flag.set_attribute('s1', '0') flag.set_attribute('s2', '0') - flag.set_attribute('area', '51') + flag.set_attribute('area', str(self.get_machine_region())) flag.set_attribute('is_final', '1') hit_chart = self.data.local.music.get_hit_chart(self.game, self.music_version, self.GAME_MAX_SONGS) @@ -281,7 +281,7 @@ class DDR2013( root.add_child(Node.string('seq', '')) root.add_child(Node.u32('code', profile.extid)) root.add_child(Node.string('name', profile.get_str('name'))) - root.add_child(Node.u8('area', profile.get_int('area', 51))) + root.add_child(Node.u8('area', profile.get_int('area', self.get_machine_region()))) root.add_child(Node.u32('cnt_s', play_stats.get_int('single_plays'))) root.add_child(Node.u32('cnt_d', play_stats.get_int('double_plays'))) root.add_child(Node.u32('cnt_b', play_stats.get_int('battle_plays'))) # This could be wrong, its a guess @@ -416,7 +416,7 @@ class DDR2013( friendnode.set_attribute('up', '0') friendnode.add_child(Node.u32('code', friend.extid)) friendnode.add_child(Node.string('name', friend.get_str('name'))) - friendnode.add_child(Node.u8('area', friend.get_int('area', 51))) + friendnode.add_child(Node.u8('area', friend.get_int('area', self.get_machine_region()))) friendnode.add_child(Node.u32('exp', play_stats.get_int('exp'))) friendnode.add_child(Node.u32('star', friend.get_int('star'))) diff --git a/bemani/backend/ddr/ddr2014.py b/bemani/backend/ddr/ddr2014.py index 03e5d75..524f28d 100644 --- a/bemani/backend/ddr/ddr2014.py +++ b/bemani/backend/ddr/ddr2014.py @@ -163,7 +163,7 @@ class DDR2014( flag.set_attribute('t', '0') flag.set_attribute('s1', '0') flag.set_attribute('s2', '0') - flag.set_attribute('area', '51') + flag.set_attribute('area', str(self.get_machine_region())) flag.set_attribute('is_final', '0') # Last month's hit chart @@ -331,7 +331,7 @@ class DDR2014( root.add_child(Node.string('seq', '')) root.add_child(Node.u32('code', profile.extid)) root.add_child(Node.string('name', profile.get_str('name'))) - root.add_child(Node.u8('area', profile.get_int('area', 51))) + root.add_child(Node.u8('area', profile.get_int('area', self.get_machine_region()))) root.add_child(Node.u32('cnt_s', play_stats.get_int('single_plays'))) root.add_child(Node.u32('cnt_d', play_stats.get_int('double_plays'))) root.add_child(Node.u32('cnt_b', play_stats.get_int('battle_plays'))) # This could be wrong, its a guess @@ -471,7 +471,7 @@ class DDR2014( friendnode.set_attribute('up', '0') friendnode.add_child(Node.u32('code', friend.extid)) friendnode.add_child(Node.string('name', friend.get_str('name'))) - friendnode.add_child(Node.u8('area', friend.get_int('area', 51))) + friendnode.add_child(Node.u8('area', friend.get_int('area', self.get_machine_region()))) friendnode.add_child(Node.u32('exp', play_stats.get_int('exp'))) friendnode.add_child(Node.u32('star', friend.get_int('star'))) diff --git a/bemani/backend/ddr/ddrx2.py b/bemani/backend/ddr/ddrx2.py index 53dc801..8bfc620 100644 --- a/bemani/backend/ddr/ddrx2.py +++ b/bemani/backend/ddr/ddrx2.py @@ -203,7 +203,7 @@ class DDRX2( 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', 51))) + 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)) @@ -307,7 +307,7 @@ class DDRX2( root.add_child(Node.string('seq', '')) root.add_child(Node.u32('code', profile.extid)) root.add_child(Node.string('name', profile.get_str('name'))) - root.add_child(Node.u8('area', profile.get_int('area', 51))) + root.add_child(Node.u8('area', profile.get_int('area', self.get_machine_region()))) root.add_child(Node.u32('cnt_s', play_stats.get_int('single_plays'))) root.add_child(Node.u32('cnt_d', play_stats.get_int('double_plays'))) root.add_child(Node.u32('cnt_b', play_stats.get_int('battle_plays'))) # This could be wrong, its a guess @@ -472,7 +472,7 @@ class DDRX2( friendnode.set_attribute('up', '0') friendnode.add_child(Node.u32('code', friend.extid)) friendnode.add_child(Node.string('name', friend.get_str('name'))) - friendnode.add_child(Node.u8('area', friend.get_int('area', 51))) + friendnode.add_child(Node.u8('area', friend.get_int('area', self.get_machine_region()))) friendnode.add_child(Node.u32('exp', play_stats.get_int('exp'))) friendnode.add_child(Node.u32('star', friend.get_int('star'))) diff --git a/bemani/backend/ddr/ddrx3.py b/bemani/backend/ddr/ddrx3.py index 3180a90..b944fc8 100644 --- a/bemani/backend/ddr/ddrx3.py +++ b/bemani/backend/ddr/ddrx3.py @@ -356,7 +356,7 @@ class DDRX3( root.add_child(Node.string('seq', '')) root.add_child(Node.u32('code', profile.extid)) root.add_child(Node.string('name', profile.get_str('name'))) - root.add_child(Node.u8('area', profile.get_int('area', 51))) + root.add_child(Node.u8('area', profile.get_int('area', self.get_machine_region()))) root.add_child(Node.u32('cnt_s', play_stats.get_int('single_plays'))) root.add_child(Node.u32('cnt_d', play_stats.get_int('double_plays'))) root.add_child(Node.u32('cnt_b', play_stats.get_int('battle_plays'))) # This could be wrong, its a guess @@ -491,7 +491,7 @@ class DDRX3( friendnode.set_attribute('up', '0') friendnode.add_child(Node.u32('code', friend.extid)) friendnode.add_child(Node.string('name', friend.get_str('name'))) - friendnode.add_child(Node.u8('area', friend.get_int('area', 51))) + friendnode.add_child(Node.u8('area', friend.get_int('area', self.get_machine_region()))) friendnode.add_child(Node.u32('exp', play_stats.get_int('exp'))) friendnode.add_child(Node.u32('star', friend.get_int('star'))) diff --git a/bemani/backend/iidx/base.py b/bemani/backend/iidx/base.py index ebc83a5..f836fa5 100644 --- a/bemani/backend/iidx/base.py +++ b/bemani/backend/iidx/base.py @@ -149,7 +149,7 @@ class IIDXBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): if name is None: name = 'なし' if pid is None: - pid = 51 + pid = self.get_machine_region() userid = self.data.remote.user.from_refid(self.game, self.version, refid) profile = Profile( diff --git a/bemani/backend/iidx/bistrover.py b/bemani/backend/iidx/bistrover.py index 2c7a1bd..9b202ad 100644 --- a/bemani/backend/iidx/bistrover.py +++ b/bemani/backend/iidx/bistrover.py @@ -13,3 +13,6 @@ class IIDXBistrover(IIDXBase): def previous_version(self) -> Optional[IIDXBase]: return IIDXHeroicVerse(self.data, self.config, self.model) + + def requires_extended_regions(self) -> bool: + return True diff --git a/bemani/backend/iidx/cannonballers.py b/bemani/backend/iidx/cannonballers.py index 38d240c..e327c84 100644 --- a/bemani/backend/iidx/cannonballers.py +++ b/bemani/backend/iidx/cannonballers.py @@ -160,6 +160,9 @@ class IIDXCannonBallers(IIDXCourse, IIDXBase): ], } + def requires_extended_regions(self) -> bool: + return True + def db_to_game_status(self, db_status: int) -> int: return { self.CLEAR_STATUS_NO_PLAY: self.GAME_CLEAR_STATUS_NO_PLAY, @@ -303,7 +306,7 @@ class IIDXCannonBallers(IIDXCourse, IIDXBase): root = Node.void('IIDX25shop') root.set_attribute('opname', machine_name) - root.set_attribute('pid', '51') + root.set_attribute('pid', str(self.get_machine_region())) root.set_attribute('cls_opt', '1' if close else '0') root.set_attribute('hr', str(hour)) root.set_attribute('mi', str(minute)) diff --git a/bemani/backend/iidx/copula.py b/bemani/backend/iidx/copula.py index d9118a5..342103a 100644 --- a/bemani/backend/iidx/copula.py +++ b/bemani/backend/iidx/copula.py @@ -296,7 +296,7 @@ class IIDXCopula(IIDXCourse, IIDXBase): root.set_attribute('cls_opt', '0') machine = self.data.local.machine.get_machine(self.config.machine.pcbid) root.set_attribute('opname', machine.name) - root.set_attribute('pid', '51') + root.set_attribute('pid', str(self.get_machine_region())) return root if method == 'savename': diff --git a/bemani/backend/iidx/heroicverse.py b/bemani/backend/iidx/heroicverse.py index ba3bb8b..3572cec 100644 --- a/bemani/backend/iidx/heroicverse.py +++ b/bemani/backend/iidx/heroicverse.py @@ -13,3 +13,6 @@ class IIDXHeroicVerse(IIDXBase): def previous_version(self) -> Optional[IIDXBase]: return IIDXRootage(self.data, self.config, self.model) + + def requires_extended_regions(self) -> bool: + return True diff --git a/bemani/backend/iidx/pendual.py b/bemani/backend/iidx/pendual.py index 75eef93..86f8d80 100644 --- a/bemani/backend/iidx/pendual.py +++ b/bemani/backend/iidx/pendual.py @@ -164,7 +164,7 @@ class IIDXPendual(IIDXCourse, IIDXBase): root.set_attribute('cls_opt', '0') machine = self.data.local.machine.get_machine(self.config.machine.pcbid) root.set_attribute('opname', machine.name) - root.set_attribute('pid', '51') + root.set_attribute('pid', str(self.get_machine_region())) return root if method == 'savename': diff --git a/bemani/backend/iidx/rootage.py b/bemani/backend/iidx/rootage.py index 0cdc24c..3cf7817 100644 --- a/bemani/backend/iidx/rootage.py +++ b/bemani/backend/iidx/rootage.py @@ -161,6 +161,9 @@ class IIDXRootage(IIDXCourse, IIDXBase): ], } + def requires_extended_regions(self) -> bool: + return True + def db_to_game_status(self, db_status: int) -> int: return { self.CLEAR_STATUS_NO_PLAY: self.GAME_CLEAR_STATUS_NO_PLAY, @@ -304,7 +307,7 @@ class IIDXRootage(IIDXCourse, IIDXBase): root = Node.void('IIDX26shop') root.set_attribute('opname', machine_name) - root.set_attribute('pid', '51') + root.set_attribute('pid', str(self.get_machine_region())) root.set_attribute('cls_opt', '1' if close else '0') root.set_attribute('hr', str(hour)) root.set_attribute('mi', str(minute)) diff --git a/bemani/backend/iidx/sinobuz.py b/bemani/backend/iidx/sinobuz.py index 2650d26..c3932dd 100644 --- a/bemani/backend/iidx/sinobuz.py +++ b/bemani/backend/iidx/sinobuz.py @@ -303,7 +303,7 @@ class IIDXSinobuz(IIDXCourse, IIDXBase): root = Node.void('IIDX24shop') root.set_attribute('opname', machine_name) - root.set_attribute('pid', '51') + root.set_attribute('pid', str(self.get_machine_region())) root.set_attribute('cls_opt', '1' if close else '0') root.set_attribute('hr', str(hour)) root.set_attribute('mi', str(minute)) diff --git a/bemani/backend/iidx/spada.py b/bemani/backend/iidx/spada.py index 149b0af..0df4ba0 100644 --- a/bemani/backend/iidx/spada.py +++ b/bemani/backend/iidx/spada.py @@ -269,7 +269,7 @@ class IIDXSpada(IIDXBase): root.set_attribute('cls_opt', '0') machine = self.data.local.machine.get_machine(self.config.machine.pcbid) root.set_attribute('opname', machine.name) - root.set_attribute('pid', '51') + root.set_attribute('pid', str(self.get_machine_region())) return root if method == 'savename': diff --git a/bemani/backend/iidx/tricoro.py b/bemani/backend/iidx/tricoro.py index d48453f..3f9f9a8 100644 --- a/bemani/backend/iidx/tricoro.py +++ b/bemani/backend/iidx/tricoro.py @@ -268,7 +268,7 @@ class IIDXTricoro(IIDXBase): root.set_attribute('cls_opt', '0') machine = self.data.local.machine.get_machine(self.config.machine.pcbid) root.set_attribute('opname', machine.name) - root.set_attribute('pid', '51') + root.set_attribute('pid', str(self.get_machine_region())) return root if method == 'savename': diff --git a/bemani/backend/popn/fantasia.py b/bemani/backend/popn/fantasia.py index aa61834..91140dd 100644 --- a/bemani/backend/popn/fantasia.py +++ b/bemani/backend/popn/fantasia.py @@ -459,7 +459,7 @@ class PopnMusicFantasia(PopnMusicBase): machine = self.get_machine() root = Node.void('playerdata') - root.add_child(Node.s8('pref', machine.data.get_int('pref', -1))) + root.add_child(Node.s8('pref', machine.data.get_int('pref', self.get_machine_region()))) if refid is None: root.add_child(Node.string('name', '')) diff --git a/bemani/backend/popn/lapistoria.py b/bemani/backend/popn/lapistoria.py index 3ba3f65..9d3e907 100644 --- a/bemani/backend/popn/lapistoria.py +++ b/bemani/backend/popn/lapistoria.py @@ -396,7 +396,7 @@ class PopnMusicLapistoria(PopnMusicBase): course_id = request.child_value('course_id') if course_id is not None: machine = self.data.local.machine.get_machine(self.config.machine.pcbid) - pref = request.child_value('pref') or 51 + pref = request.child_value('pref') or self.get_machine_region() profile = self.get_profile(userid) or Profile(self.game, self.version, refid, 0) course = self.data.local.user.get_achievement( diff --git a/bemani/backend/popn/sunnypark.py b/bemani/backend/popn/sunnypark.py index 0007b89..c6a2bba 100644 --- a/bemani/backend/popn/sunnypark.py +++ b/bemani/backend/popn/sunnypark.py @@ -543,7 +543,7 @@ class PopnMusicSunnyPark(PopnMusicBase): machine = self.get_machine() root = Node.void('playerdata') - root.add_child(Node.s8('pref', machine.data.get_int('pref', -1))) + root.add_child(Node.s8('pref', machine.data.get_int('pref', self.get_machine_region()))) if refid is None: root.add_child(Node.string('name', '')) root.add_child(Node.s8('get_coupon_cnt', -1)) diff --git a/bemani/backend/reflec/limelight.py b/bemani/backend/reflec/limelight.py index 50bfd97..7f34612 100644 --- a/bemani/backend/reflec/limelight.py +++ b/bemani/backend/reflec/limelight.py @@ -96,13 +96,13 @@ class ReflecBeatLimelight(ReflecBeatBase): close = machine.data.get_bool('close') hour = machine.data.get_int('hour') minute = machine.data.get_int('minute') - pref = machine.data.get_int('pref', 51) + pref = machine.data.get_int('pref', self.get_machine_region()) else: machine_name = '' close = False hour = 0 minute = 0 - pref = 51 + pref = self.get_machine_region() root = Node.void('pcbinfo') info = Node.void('info') diff --git a/bemani/backend/reflec/reflecbeat.py b/bemani/backend/reflec/reflecbeat.py index 026eca5..dffcc39 100644 --- a/bemani/backend/reflec/reflecbeat.py +++ b/bemani/backend/reflec/reflecbeat.py @@ -89,13 +89,13 @@ class ReflecBeat(ReflecBeatBase): close = machine.data.get_bool('close') hour = machine.data.get_int('hour') minute = machine.data.get_int('minute') - pref = machine.data.get_int('pref', 51) + pref = machine.data.get_int('pref', self.get_machine_region()) else: machine_name = '' close = False hour = 0 minute = 0 - pref = 51 + pref = self.get_machine_region() root = Node.void('pcbinfo') info = Node.void('info') @@ -140,7 +140,7 @@ class ReflecBeat(ReflecBeatBase): def handle_sysinfo_fan_request(self, request: Node) -> Node: sysinfo = Node.void('sysinfo') - sysinfo.add_child(Node.u8('pref', 51)) + sysinfo.add_child(Node.u8('pref', self.get_machine_region())) sysinfo.add_child(Node.string('lid', request.child_value('lid'))) return sysinfo diff --git a/bemani/common/constants.py b/bemani/common/constants.py index 9cfa1f7..61a5011 100644 --- a/bemani/common/constants.py +++ b/bemani/common/constants.py @@ -405,6 +405,10 @@ class _RegionConstants: MIN: Final[int] = 1 MAX: Final[int] = 56 + # Min/max valid values for JP prefectures + MIN_PREF: Final[int] = 1 + MAX_PREF: Final[int] = 47 + # This is a really nasty LUT to attempt to make the frontend display # the same regardless of the game in question. This is mostly because # the prefecture/region stored in the profile is editable by IIDX and diff --git a/bemani/common/id.py b/bemani/common/id.py index 67070c1..3cc7c61 100644 --- a/bemani/common/id.py +++ b/bemani/common/id.py @@ -42,11 +42,13 @@ class ID: return None @staticmethod - def format_machine_id(machine_id: int) -> str: + def format_machine_id(machine_id: int, region: str = 'US') -> str: """ Take a machine ID as an integer, format it as a string. """ - return f'US-{machine_id}' + if region not in {'JP', 'KR', 'TW', 'HK', 'US', 'GB', 'IT', 'ES', 'FR', 'PT'}: + raise Exception(f'Invalid region {region}!') + return f'{region}-{machine_id}' @staticmethod def parse_machine_id(machine_id: str) -> Optional[int]: @@ -54,7 +56,7 @@ class ID: Take a formatted machine ID as a string, returning an int. """ try: - if machine_id[:3] == 'US-': + if machine_id[:2] in {'JP', 'KR', 'TW', 'HK', 'US', 'GB', 'IT', 'ES', 'FR', 'PT'} and machine_id[2] == '-': return int(machine_id[3:]) except ValueError: pass