From d3d1fe6ca0f357c2cd00ec004e3cbdb2c4ac649a Mon Sep 17 00:00:00 2001 From: cracrayol Date: Mon, 6 Sep 2021 02:16:06 +0200 Subject: [PATCH] Fix user name check for MGA in frontend Use "for key, value in" when reading usaneko phases Lint fixes --- bemani/backend/mga/mga.py | 2 +- bemani/backend/popn/base.py | 2 +- bemani/backend/popn/peace.py | 2 +- bemani/backend/popn/usaneko.py | 4 +- bemani/client/mga/mga.py | 8 +- bemani/data/triggers.py | 2 +- bemani/frontend/mga/endpoints.py | 41 ++------- .../static/controllers/mga/settings.react.js | 87 ++----------------- bemani/utils/read.py | 2 +- verifytraffic | 1 + 10 files changed, 25 insertions(+), 126 deletions(-) diff --git a/bemani/backend/mga/mga.py b/bemani/backend/mga/mga.py index b004711..c87704e 100644 --- a/bemani/backend/mga/mga.py +++ b/bemani/backend/mga/mga.py @@ -1,7 +1,7 @@ # vim: set fileencoding=utf-8 import copy import base64 -from typing import Any, Dict, List +from typing import List from bemani.backend.mga.base import MetalGearArcadeBase from bemani.backend.ess import EventLogHandler diff --git a/bemani/backend/popn/base.py b/bemani/backend/popn/base.py index f7d66ba..128d3dd 100644 --- a/bemani/backend/popn/base.py +++ b/bemani/backend/popn/base.py @@ -290,7 +290,7 @@ class PopnMusicBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): # We saved successfully break - def broadcast_score(self, userid: int, songid: int, chart: int, medal: int, points: int, combo: int, stats: Dict[str,int]) -> None: + def broadcast_score(self, userid: int, songid: int, chart: int, medal: int, points: int, combo: int, stats: Dict[str, int]) -> None: # Generate scorecard profile = self.get_profile(userid) song = self.data.local.music.get_song(self.game, self.version, songid, chart) diff --git a/bemani/backend/popn/peace.py b/bemani/backend/popn/peace.py index ae66e6c..bad1682 100644 --- a/bemani/backend/popn/peace.py +++ b/bemani/backend/popn/peace.py @@ -71,4 +71,4 @@ class PopnMusicPeace(PopnMusicUsaNeko): 23: 1, # Unknown event (0-1) 24: 1, - } \ No newline at end of file + } diff --git a/bemani/backend/popn/usaneko.py b/bemani/backend/popn/usaneko.py index 3d94f97..a5e79a9 100644 --- a/bemani/backend/popn/usaneko.py +++ b/bemani/backend/popn/usaneko.py @@ -161,11 +161,11 @@ class PopnMusicUsaNeko(PopnMusicBase): } def __construct_common_info(self, root: Node) -> None: - for phaseid in self.get_phases(): + for phaseid, phase_value in self.get_phases().items(): phase = Node.void('phase') root.add_child(phase) phase.add_child(Node.s16('event_id', phaseid)) - phase.add_child(Node.s16('phase', self.get_phases()[phaseid])) + phase.add_child(Node.s16('phase', phase_value)) # Gather course informatino and course ranking for users. course_infos, achievements, profiles = Parallel.execute([ diff --git a/bemani/client/mga/mga.py b/bemani/client/mga/mga.py index 84dc459..b709e75 100644 --- a/bemani/client/mga/mga.py +++ b/bemani/client/mga/mga.py @@ -210,7 +210,7 @@ class MetalGearArcadeClient(BaseClient): b'', b'', b'', - b'', + b'', ] if msg_type == 'new': @@ -235,13 +235,13 @@ class MetalGearArcadeClient(BaseClient): data.add_child(record) d = Node.string('d', base64.b64encode(b','.join(profiledata)).decode('ascii')) record.add_child(d) - d.add_child(Node.string('bin1', '')) + d.add_child(Node.string('bin1', '')) d = Node.string('d', base64.b64encode(b','.join(outfitdata)).decode('ascii')) record.add_child(d) - d.add_child(Node.string('bin1', '')) + d.add_child(Node.string('bin1', '')) d = Node.string('d', base64.b64encode(b','.join(weapondata)).decode('ascii')) record.add_child(d) - d.add_child(Node.string('bin1', '')) + d.add_child(Node.string('bin1', '')) d = Node.string('d', base64.b64encode(b','.join(mainruledata)).decode('ascii')) record.add_child(d) d.add_child(Node.string('bin1', '')) diff --git a/bemani/data/triggers.py b/bemani/data/triggers.py index 7343f9b..686d19a 100644 --- a/bemani/data/triggers.py +++ b/bemani/data/triggers.py @@ -33,7 +33,7 @@ class Triggers: self.broadcast_score_discord(data, game, song) def broadcast_score_discord(self, data: Dict[BroadcastConstants, str], game: GameConstants, song: Song) -> None: - if game in [GameConstants.IIDX, GameConstants.POPN_MUSIC] : + if game in {GameConstants.IIDX, GameConstants.POPN_MUSIC}: now = datetime.now() webhook = DiscordWebhook(url=self.config.webhooks.discord[game]) diff --git a/bemani/frontend/mga/endpoints.py b/bemani/frontend/mga/endpoints.py index c326d92..e9a8f1b 100644 --- a/bemani/frontend/mga/endpoints.py +++ b/bemani/frontend/mga/endpoints.py @@ -121,46 +121,15 @@ def updatename() -> Dict[str, Any]: profile = g.data.local.user.get_profile(GameConstants.MGA, version, user.id) if profile is None: raise Exception('Unable to find profile to update!') - if len(name) == 0 or len(name) > 6: + if len(name) == 0 or len(name) > 8: raise Exception('Invalid profile name!') - # Convert lowercase to uppercase. We allow lowercase widetext in - # the JS frontend to allow for Windows IME input of hiragana/katakana. - def conv(char: str) -> str: - i = ord(char) - if i >= 0xFF41 and i <= 0xFF5A: - return chr(i - (0xFF41 - 0xFF21)) - else: - return char - name = ''.join([conv(a) for a in name]) - if re.match( "^[" + - "\uFF20-\uFF3A" + # widetext A-Z, @ - "\uFF10-\uFF19" + # widetext 0-9 - "\u3041-\u308D\u308F\u3092\u3093" + # hiragana - "\u30A1-\u30ED\u30EF\u30F2\u30F3\u30FC" + # katakana - "\u3000" + # widetext blank space - "\u301C" + # widetext ~ - "\u30FB" + # widetext middot - "\u30FC" + # widetext long dash - "\u2212" + # widetext short dash - "\u2605" + # widetext heavy star - "\uFF01" + # widetext ! - "\uFF03" + # widetext # - "\uFF04" + # widetext $ - "\uFF05" + # widetext % - "\uFF06" + # widetext & - "\uFF08" + # widetext ( - "\uFF09" + # widetext ) - "\uFF0A" + # widetext * - "\uFF0B" + # widetext + - "\uFF0F" + # widetext / - "\uFF1C" + # widetext < - "\uFF1D" + # widetext = - "\uFF1E" + # widetext > - "\uFF1F" + # widetext ? - "\uFFE5" + # widetext Yen symbol + "a-z" + + "A-Z" + + "0-9" + + "@!?/=():*^[\]#;\-_{}$.+" + "]*$", name, ) is None: diff --git a/bemani/frontend/static/controllers/mga/settings.react.js b/bemani/frontend/static/controllers/mga/settings.react.js index d21fc3c..d50d936 100644 --- a/bemani/frontend/static/controllers/mga/settings.react.js +++ b/bemani/frontend/static/controllers/mga/settings.react.js @@ -66,93 +66,22 @@ var settings_view = React.createClass({ (this.focus_element = c)} value={this.state.new_name} onChange={function(event) { - var rawvalue = event.target.value; - var value = ""; - // Nasty conversion to change typing into wide text - for (var i = 0; i < rawvalue.length; i++) { - var c = rawvalue.charCodeAt(i); - if (c >= '0'.charCodeAt(0) && c <= '9'.charCodeAt(0)) { - c = 0xFF10 + (c - '0'.charCodeAt(0)); - } else if(c >= 'A'.charCodeAt(0) && c <= 'Z'.charCodeAt(0)) { - c = 0xFF21 + (c - 'A'.charCodeAt(0)); - } else if(c >= 'a'.charCodeAt(0) && c <= 'z'.charCodeAt(0)) { - c = 0xFF41 + (c - 'a'.charCodeAt(0)); - } else if(c == '@'.charCodeAt(0)) { - c = 0xFF20; - } else if(c == ' '.charCodeAt(0)) { - c = 0x3000; - } else if(c == '~'.charCodeAt(0)) { - c = 0x301C; - } else if(c == '-'.charCodeAt(0)) { - c = 0x2212; - } else if(c == '!'.charCodeAt(0)) { - c = 0xFF01; - } else if(c == '#'.charCodeAt(0)) { - c = 0xFF03; - } else if(c == '$'.charCodeAt(0)) { - c = 0xFF04; - } else if(c == '%'.charCodeAt(0)) { - c = 0xFF04; - } else if(c == '&'.charCodeAt(0)) { - c = 0xFF06; - } else if(c == '('.charCodeAt(0)) { - c = 0xFF08; - } else if(c == ')'.charCodeAt(0)) { - c = 0xFF09; - } else if(c == '*'.charCodeAt(0)) { - c = 0xFF0A; - } else if(c == '+'.charCodeAt(0)) { - c = 0xFF0B; - } else if(c == '/'.charCodeAt(0)) { - c = 0xFF0F; - } else if(c == '<'.charCodeAt(0)) { - c = 0xFF1C; - } else if(c == '='.charCodeAt(0)) { - c = 0xFF1D; - } else if(c == '>'.charCodeAt(0)) { - c = 0xFF1E; - } else if(c == '?'.charCodeAt(0)) { - c = 0xFF1F; - } - value = value + String.fromCharCode(c); - } + var value = event.target.value; var nameRegex = new RegExp( "^[" + - "\uFF20-\uFF3A" + // widetext A-Z, @ - "\uFF41-\uFF5A" + // widetext a-z (will be uppercased in backend) - "\uFF10-\uFF19" + // widetext 0-9 - "\u3041-\u308D\u308F\u3092\u3093" + // hiragana - "\u30A1-\u30ED\u30EF\u30F2\u30F3\u30FC" + // katakana - "\u3000" + // widetext blank space - "\u301C" + // widetext ~ - "\u30FB" + // widetext middot - "\u30FC" + // widetext long dash - "\u2212" + // widetext short dash - "\u2605" + // widetext heavy star - "\uFF01" + // widetext ! - "\uFF03" + // widetext # - "\uFF04" + // widetext $ - "\uFF05" + // widetext % - "\uFF06" + // widetext & - "\uFF08" + // widetext ( - "\uFF09" + // widetext ) - "\uFF0A" + // widetext * - "\uFF0B" + // widetext + - "\uFF0F" + // widetext / - "\uFF1C" + // widetext < - "\uFF1D" + // widetext = - "\uFF1E" + // widetext > - "\uFF1F" + // widetext ? - "\uFFE5" + // widetext Yen symbol + "a-z" + + "A-Z" + + "0-9" + + "@!?/=():*^[\\]#;\\-_{}$.+" + "]*$" ); - if (value.length <= 6 && nameRegex.test(value)) { + if (value.length <= 8 && nameRegex.test(value)) { this.setState({new_name: value}); } }.bind(this)} diff --git a/bemani/utils/read.py b/bemani/utils/read.py index 416c966..a49d180 100644 --- a/bemani/utils/read.py +++ b/bemani/utils/read.py @@ -968,7 +968,7 @@ class ImportPopn(ImportBase): True, # Always a battle normal chart mask & 0x4000000 > 0, # Battle hyper chart bit ) - + elif self.version == VersionConstants.POPN_MUSIC_PEACE: # Based on M39:J:A:A:2020092800 diff --git a/verifytraffic b/verifytraffic index 9637946..b6c135f 100755 --- a/verifytraffic +++ b/verifytraffic @@ -40,6 +40,7 @@ declare -a arr=( "reflec-4" "reflec-5" "reflec-6" + "mga" ) for project in "${arr[@]}"