def viewevents() -> Response: iidx = IIDXFrontend(g.data, g.config, g.cache) jubeat = JubeatFrontend(g.data, g.config, g.cache) pnm = PopnMusicFrontend(g.data, g.config, g.cache) return render_react( 'Events', 'admin/events.react.js', { 'events': [format_event(event) for event in g.data.local.network.get_events(limit=100)], 'users': {user.id: user.username for user in g.data.local.user.get_all_users()}, 'arcades': {arcade.id: arcade.name for arcade in g.data.local.machine.get_all_arcades()}, 'iidxsongs': iidx.get_all_songs(), 'jubeatsongs': jubeat.get_all_songs(), 'pnmsongs': pnm.get_all_songs(), 'iidxversions': {version: name for (game, version, name) in iidx.all_games()}, 'jubeatversions': {version: name for (game, version, name) in jubeat.all_games()}, 'pnmversions': {version: name for (game, version, name) in pnm.all_games()}, }, { 'refresh': url_for('admin_pages.listevents', since=-1), 'backfill': url_for('admin_pages.backfillevents', until=-1), 'viewuser': url_for('admin_pages.viewuser', userid=-1), 'jubeatsong': url_for('jubeat_pages.viewtopscores', musicid=-1) if g.config.get('support', {}).get(GameConstants.JUBEAT, False) else None, 'iidxsong': url_for('iidx_pages.viewtopscores', musicid=-1) if g.config.get('support', {}).get(GameConstants.IIDX, False) else None, 'pnmsong': url_for('popn_pages.viewtopscores', musicid=-1) if g.config.get('support', {}).get(GameConstants.POPN_MUSIC, False) else None, }, )
def preload(cls, data: Data, config: Dict[str, Any]) -> None: cache = Cache(app, config={ 'CACHE_TYPE': 'filesystem', 'CACHE_DIR': config['cache_dir'], }) frontend = IIDXFrontend(data, config, cache) frontend.get_all_songs(force_db_load=True)
def updateqpro() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) qpros = request.get_json()['qpro'] version = int(request.get_json()['version']) user = g.data.local.user.get_user(g.userID) if user is None: raise Exception('Unable to find user to update!') # Grab profile and qpro dict that needs updating profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id) if profile is None: raise Exception('Unable to find profile to update!') qpro_dict = profile.get_dict('qpro') for qpro in qpros: qpro_dict.replace_int(qpro, qpros[qpro]) # Update the qpro dict profile.replace_dict('qpro', qpro_dict) g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile) # Return updated qpro return { 'qpro': frontend.format_qpro(qpro_dict), 'version': version, }
def viewsettings() -> Response: frontend = IIDXFrontend(g.data, g.config, g.cache) userid = g.userID djinfo = frontend.get_all_player_info([userid])[userid] if not djinfo: abort(404) return render_react( 'IIDX Game Settings', 'iidx/settings.react.js', { 'player': djinfo, 'versions': {version: name for (game, version, name) in frontend.all_games()}, }, { 'updateqpro': url_for('iidx_pages.updateqpro'), 'updateflags': url_for('iidx_pages.updateflags'), 'updatesettings': url_for('iidx_pages.updatesettings'), 'updatename': url_for('iidx_pages.updatename'), 'updateprefecture': url_for('iidx_pages.updateprefecture'), 'leavearcade': url_for('iidx_pages.leavearcade'), }, )
def addrival() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) rivaltype = request.get_json()['type'] other_userid = UserID(int(request.get_json()['userid'])) userid = g.userID # Add this rival link if rivaltype != 'sp_rival' and rivaltype != 'dp_rival': raise Exception(f'Invalid rival type {rivaltype}!') profile = g.data.remote.user.get_profile(GameConstants.IIDX, version, other_userid) if profile is None: raise Exception('Unable to find profile for rival!') g.data.local.user.put_link( GameConstants.IIDX, version, userid, rivaltype, other_userid, {}, ) # Now return updated rival info rivals, djinfo = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': djinfo, }
def updatesettings() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) settings = request.get_json()['settings'] version = int(request.get_json()['version']) user = g.data.local.user.get_user(g.userID) if user is None: raise Exception('Unable to find user to update!') # Grab profile and settings dict that needs updating profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id) if profile is None: raise Exception('Unable to find profile to update!') settings_dict = profile.get_dict('settings') for setting in settings: settings_dict.replace_int(setting, settings[setting]) # Update the settings dict profile.replace_dict('settings', settings_dict) g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile) # Return updated settings return { 'settings': frontend.format_settings(settings_dict), 'version': version, }
def viewnetworkrecords() -> Response: frontend = IIDXFrontend(g.data, g.config, g.cache) network_records = frontend.get_network_records() return render_react( 'Global IIDX Records', 'iidx/records.react.js', { 'records': network_records['records'], 'songs': frontend.get_all_songs(), 'players': network_records['players'], 'versions': {version: name for (game, version, name) in frontend.all_games()}, 'showdjnames': True, 'showpersonalsort': False, 'filterempty': False, }, { 'refresh': url_for('iidx_pages.listnetworkrecords'), 'player': url_for('iidx_pages.viewplayer', userid=-1), 'individual_score': url_for('iidx_pages.viewtopscores', musicid=-1), }, )
def removerival() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) rivaltype = request.get_json()['type'] other_userid = UserID(int(request.get_json()['userid'])) userid = g.userID # Remove this rival link if rivaltype != 'sp_rival' and rivaltype != 'dp_rival': raise Exception(f'Invalid rival type {rivaltype}!') g.data.local.user.destroy_link( GameConstants.IIDX, version, userid, rivaltype, other_userid, ) # Now return updated rival info rivals, djinfo = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': djinfo, }
def viewplayer(userid: UserID) -> Response: frontend = IIDXFrontend(g.data, g.config, g.cache) djinfo = frontend.get_all_player_info([userid])[userid] if not djinfo: abort(404) latest_version = sorted(djinfo.keys(), reverse=True)[0] for version in djinfo: sp_rival = g.data.local.user.get_link(GameConstants.IIDX, version, g.userID, 'sp_rival', userid) dp_rival = g.data.local.user.get_link(GameConstants.IIDX, version, g.userID, 'dp_rival', userid) djinfo[version]['sp_rival'] = sp_rival is not None djinfo[version]['dp_rival'] = dp_rival is not None return render_react( f'dj {djinfo[latest_version]["name"]}\'s IIDX Profile', 'iidx/player.react.js', { 'playerid': userid, 'own_profile': userid == g.userID, 'player': djinfo, 'versions': {version: name for (game, version, name) in frontend.all_games()}, }, { 'refresh': url_for('iidx_pages.listplayer', userid=userid), 'records': url_for('iidx_pages.viewrecords', userid=userid), 'scores': url_for('iidx_pages.viewscores', userid=userid), 'addrival': url_for('iidx_pages.addrival'), 'removerival': url_for('iidx_pages.removerival'), }, )
def listrivals() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) rivals, djinfo = frontend.get_rivals(g.userID) return { 'rivals': rivals, 'players': djinfo, }
def viewplayers() -> Response: frontend = IIDXFrontend(g.data, g.config, g.cache) return render_react( 'All IIDX Players', 'iidx/allplayers.react.js', {'players': frontend.get_all_players()}, { 'refresh': url_for('iidx_pages.listplayers'), 'player': url_for('iidx_pages.viewplayer', userid=-1), }, )
def listplayer(userid: UserID) -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) djinfo = frontend.get_all_player_info([userid])[userid] for version in djinfo: sp_rival = g.data.local.user.get_link(GameConstants.IIDX, version, g.userID, 'sp_rival', userid) dp_rival = g.data.local.user.get_link(GameConstants.IIDX, version, g.userID, 'dp_rival', userid) djinfo[version]['sp_rival'] = sp_rival is not None djinfo[version]['dp_rival'] = dp_rival is not None return { 'player': djinfo, }
def viewtopscores(musicid: int) -> Response: # We just want to find the latest mix that this song exists in frontend = IIDXFrontend(g.data, g.config, g.cache) versions = sorted( [version for (game, version, name) in frontend.all_games()], reverse=True, ) name = None artist = None genre = None difficulties = [0, 0, 0, 0, 0, 0] notecounts = [0, 0, 0, 0, 0, 0] for version in versions: for omniadd in [0, 10000]: for chart in [0, 1, 2, 3, 4, 5]: details = g.data.local.music.get_song(GameConstants.IIDX, version + omniadd, musicid, chart) if details is not None: name = details.name artist = details.artist genre = details.genre difficulties[chart] = details.data.get_int( 'difficulty', 13) notecounts[chart] = details.data.get_int('notecount', 5730) if name is None: # Not a real song! abort(404) top_scores = frontend.get_top_scores(musicid) return render_react( f'Top IIDX Scores for {artist} - {name}', 'iidx/topscores.react.js', { 'name': name, 'artist': artist, 'genre': genre, 'difficulties': difficulties, 'notecounts': notecounts, 'players': top_scores['players'], 'topscores': top_scores['topscores'], }, { 'refresh': url_for('iidx_pages.listtopscores', musicid=musicid), 'player': url_for('iidx_pages.viewplayer', userid=-1), }, )
def updateflags() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) flags = request.get_json()['flags'] version = int(request.get_json()['version']) user = g.data.local.user.get_user(g.userID) if user is None: raise Exception('Unable to find user to update!') # Grab profile and settings dict that needs updating profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id) if profile is None: raise Exception('Unable to find profile to update!') settings_dict = profile.get_dict('settings') # Set bits for flags based on frontend flagint = 0 flagint += 0x001 if flags['grade'] else 0 flagint += 0x002 if flags['status'] else 0 flagint += 0x004 if flags['difficulty'] else 0 flagint += 0x008 if flags['alphabet'] else 0 flagint += 0x010 if flags['rival_played'] else 0 flagint += 0x040 if flags['rival_win_lose'] else 0 flagint += 0x080 if flags['rival_info'] else 0 flagint += 0x100 if flags['hide_play_count'] else 0 flagint += 0x200 if flags['disable_graph_cutin'] else 0 flagint += 0x400 if flags['classic_hispeed'] else 0 flagint += 0x1000 if flags['hide_iidx_id'] else 0 settings_dict.replace_int('flags', flagint) # Update special case flags settings_dict.replace_int('disable_song_preview', 1 if flags['disable_song_preview'] else 0) settings_dict.replace_int('effector_lock', 1 if flags['effector_lock'] else 0) settings_dict.replace_int('disable_hcn_color', 1 if flags['disable_hcn_color'] else 0) # Update the settings dict profile.replace_dict('settings', settings_dict) g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile) # Return updated flags return { 'flags': frontend.format_flags(settings_dict), 'version': version, }
def viewscores(userid: UserID) -> Response: frontend = IIDXFrontend(g.data, g.config, g.cache) djinfo = frontend.get_latest_player_info([userid]).get(userid) if djinfo is None: abort(404) scores = frontend.get_scores(userid, limit=100) if len(scores) > 10: scores = frontend.round_to_ten(scores) return render_react( f'dj {djinfo["name"]}\'s IIDX Scores', 'iidx/scores.react.js', { 'attempts': scores, 'songs': frontend.get_all_songs(), 'players': {}, 'versions': {version: name for (game, version, name) in frontend.all_games()}, 'showdjnames': False, 'shownewrecords': True, }, { 'refresh': url_for('iidx_pages.listscores', userid=userid), 'player': url_for('iidx_pages.viewplayer', userid=-1), 'individual_score': url_for('iidx_pages.viewtopscores', musicid=-1), }, )
def searchrivals() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) djname = request.get_json()['term'] # Try to treat the term as an extid extid = ID.parse_extid(djname) matches = set() profiles = g.data.remote.user.get_all_profiles(GameConstants.IIDX, version) for (userid, profile) in profiles: if profile.get_int('extid') == extid or profile.get_str('name').lower() == djname.lower(): matches.add(userid) djinfo = frontend.get_all_player_info(list(matches), allow_remote=True) return { 'results': djinfo, }
def viewrivals() -> Response: frontend = IIDXFrontend(g.data, g.config, g.cache) rivals, djinfo = frontend.get_rivals(g.userID) return render_react( 'IIDX Rivals', 'iidx/rivals.react.js', { 'userid': str(g.userID), 'rivals': rivals, 'players': djinfo, 'versions': {version: name for (game, version, name) in frontend.all_games()}, }, { 'refresh': url_for('iidx_pages.listrivals'), 'search': url_for('iidx_pages.searchrivals'), 'player': url_for('iidx_pages.viewplayer', userid=-1), 'addrival': url_for('iidx_pages.addrival'), 'removerival': url_for('iidx_pages.removerival'), }, )
def viewrecords(userid: UserID) -> Response: frontend = IIDXFrontend(g.data, g.config, g.cache) djinfo = frontend.get_latest_player_info([userid]).get(userid) if djinfo is None: abort(404) return render_react( f'dj {djinfo["name"]}\'s IIDX Records', 'iidx/records.react.js', { 'records': frontend.get_records(userid), 'songs': frontend.get_all_songs(), 'players': {}, 'versions': {version: name for (game, version, name) in frontend.all_games()}, 'showdjnames': False, 'showpersonalsort': True, 'filterempty': True, }, { 'refresh': url_for('iidx_pages.listrecords', userid=userid), 'player': url_for('iidx_pages.viewplayer', userid=-1), 'individual_score': url_for('iidx_pages.viewtopscores', musicid=-1), }, )
def viewnetworkscores() -> Response: # Only load the last 100 results for the initial fetch, so we can render faster frontend = IIDXFrontend(g.data, g.config, g.cache) network_scores = frontend.get_network_scores(limit=100) if len(network_scores['attempts']) > 10: network_scores['attempts'] = frontend.round_to_ten( network_scores['attempts']) return render_react( 'Global IIDX Scores', 'iidx/scores.react.js', { 'attempts': network_scores['attempts'], 'songs': frontend.get_all_songs(), 'players': network_scores['players'], 'versions': {version: name for (game, version, name) in frontend.all_games()}, 'showdjnames': True, 'shownewrecords': False, }, { 'refresh': url_for('iidx_pages.listnetworkscores'), 'player': url_for('iidx_pages.viewplayer', userid=-1), 'individual_score': url_for('iidx_pages.viewtopscores', musicid=-1), }, )
def listplayers() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) return { 'players': frontend.get_all_players(), }
def listscores(userid: UserID) -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) return { 'attempts': frontend.get_scores(userid), 'players': {}, }
def listrecords(userid: UserID) -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) return { 'records': frontend.get_records(userid), 'players': {}, }
def listnetworkscores() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) return frontend.get_network_scores()
def listtopscores(musicid: int) -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) return frontend.get_top_scores(musicid)