1
0
mirror of synced 2024-11-12 01:00:46 +01:00

Fix user name check for MGA in frontend

Use "for key, value in" when reading usaneko phases
Lint fixes
This commit is contained in:
cracrayol 2021-09-06 02:16:06 +02:00
parent f541acb206
commit d3d1fe6ca0
10 changed files with 25 additions and 126 deletions

View File

@ -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

View File

@ -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)

View File

@ -71,4 +71,4 @@ class PopnMusicPeace(PopnMusicUsaNeko):
23: 1,
# Unknown event (0-1)
24: 1,
}
}

View File

@ -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([

View File

@ -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', ''))

View File

@ -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])

View File

@ -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:

View File

@ -66,93 +66,22 @@ var settings_view = React.createClass({
<input
type="text"
className="inline"
maxlength="6"
size="6"
maxlength="8"
size="8"
autofocus="true"
ref={c => (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)}

View File

@ -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

View File

@ -40,6 +40,7 @@ declare -a arr=(
"reflec-4"
"reflec-5"
"reflec-6"
"mga"
)
for project in "${arr[@]}"