2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
import re
|
|
|
|
from typing import Any, Dict
|
2021-05-20 00:38:00 +02:00
|
|
|
from flask import Blueprint, request, Response, url_for, abort
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-25 15:58:52 +02:00
|
|
|
from bemani.common import ID, GameConstants, RegionConstants, DBConstants
|
2019-12-08 22:43:49 +01:00
|
|
|
from bemani.data import UserID
|
|
|
|
from bemani.frontend.app import loginrequired, jsonify, render_react
|
|
|
|
from bemani.frontend.iidx.iidx import IIDXFrontend
|
|
|
|
from bemani.frontend.templates import templates_location
|
|
|
|
from bemani.frontend.static import static_location
|
2021-05-20 00:38:00 +02:00
|
|
|
from bemani.frontend.types import g
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
iidx_pages = Blueprint(
|
2022-10-15 20:56:30 +02:00
|
|
|
"iidx_pages",
|
2019-12-08 22:43:49 +01:00
|
|
|
__name__,
|
2022-10-15 20:56:30 +02:00
|
|
|
url_prefix=f"/{GameConstants.IIDX.value}",
|
2019-12-08 22:43:49 +01:00
|
|
|
template_folder=templates_location,
|
|
|
|
static_folder=static_location,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/scores")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
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)
|
2022-10-15 20:56:30 +02:00
|
|
|
if len(network_scores["attempts"]) > 10:
|
|
|
|
network_scores["attempts"] = frontend.round_to_ten(network_scores["attempts"])
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return render_react(
|
2022-10-15 20:56:30 +02:00
|
|
|
"Global IIDX Scores",
|
|
|
|
"iidx/scores.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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,
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"refresh": url_for("iidx_pages.listnetworkscores"),
|
|
|
|
"player": url_for("iidx_pages.viewplayer", userid=-1),
|
|
|
|
"individual_score": url_for("iidx_pages.viewtopscores", musicid=-1),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/scores/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def listnetworkscores() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
return frontend.get_network_scores()
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/scores/<int:userid>")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
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(
|
2020-01-07 22:29:07 +01:00
|
|
|
f'dj {djinfo["name"]}\'s IIDX Scores',
|
2022-10-15 20:56:30 +02:00
|
|
|
"iidx/scores.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"attempts": scores,
|
|
|
|
"songs": frontend.get_all_songs(),
|
|
|
|
"players": {},
|
|
|
|
"versions": {
|
|
|
|
version: name for (game, version, name) in frontend.all_games()
|
|
|
|
},
|
|
|
|
"showdjnames": False,
|
|
|
|
"shownewrecords": True,
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/scores/<int:userid>/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def listscores(userid: UserID) -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"attempts": frontend.get_scores(userid),
|
|
|
|
"players": {},
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/records")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
def viewnetworkrecords() -> Response:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
network_records = frontend.get_network_records()
|
|
|
|
|
|
|
|
return render_react(
|
2022-10-15 20:56:30 +02:00
|
|
|
"Global IIDX Records",
|
|
|
|
"iidx/records.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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,
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"refresh": url_for("iidx_pages.listnetworkrecords"),
|
|
|
|
"player": url_for("iidx_pages.viewplayer", userid=-1),
|
|
|
|
"individual_score": url_for("iidx_pages.viewtopscores", musicid=-1),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/records/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def listnetworkrecords() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
return frontend.get_network_records()
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/records/<int:userid>")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
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(
|
2020-01-07 22:29:07 +01:00
|
|
|
f'dj {djinfo["name"]}\'s IIDX Records',
|
2022-10-15 20:56:30 +02:00
|
|
|
"iidx/records.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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,
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/records/<int:userid>/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def listrecords(userid: UserID) -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"records": frontend.get_records(userid),
|
|
|
|
"players": {},
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/topscores/<int:musicid>")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
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:
|
2022-10-25 15:58:52 +02:00
|
|
|
for omniadd in [0, DBConstants.OMNIMIX_VERSION_BUMP]:
|
2019-12-08 22:43:49 +01:00
|
|
|
for chart in [0, 1, 2, 3, 4, 5]:
|
2022-10-15 20:56:30 +02:00
|
|
|
details = g.data.local.music.get_song(
|
|
|
|
GameConstants.IIDX, version + omniadd, musicid, chart
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
if details is not None:
|
|
|
|
name = details.name
|
|
|
|
artist = details.artist
|
|
|
|
genre = details.genre
|
2022-10-15 20:56:30 +02:00
|
|
|
difficulties[chart] = details.data.get_int("difficulty", 13)
|
|
|
|
notecounts[chart] = details.data.get_int("notecount", 5730)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if name is None:
|
|
|
|
# Not a real song!
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
top_scores = frontend.get_top_scores(musicid)
|
|
|
|
|
|
|
|
return render_react(
|
2022-10-15 20:56:30 +02:00
|
|
|
f"Top IIDX Scores for {artist} - {name}",
|
|
|
|
"iidx/topscores.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"name": name,
|
|
|
|
"artist": artist,
|
|
|
|
"genre": genre,
|
|
|
|
"difficulties": difficulties,
|
|
|
|
"notecounts": notecounts,
|
|
|
|
"players": top_scores["players"],
|
|
|
|
"topscores": top_scores["topscores"],
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"refresh": url_for("iidx_pages.listtopscores", musicid=musicid),
|
|
|
|
"player": url_for("iidx_pages.viewplayer", userid=-1),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/topscores/<int:musicid>/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def listtopscores(musicid: int) -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
return frontend.get_top_scores(musicid)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/players")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
def viewplayers() -> Response:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
return render_react(
|
2022-10-15 20:56:30 +02:00
|
|
|
"All IIDX Players",
|
|
|
|
"iidx/allplayers.react.js",
|
|
|
|
{"players": frontend.get_all_players()},
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"refresh": url_for("iidx_pages.listplayers"),
|
|
|
|
"player": url_for("iidx_pages.viewplayer", userid=-1),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/players/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def listplayers() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"players": frontend.get_all_players(),
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/players/<int:userid>")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
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:
|
2022-10-15 20:56:30 +02:00
|
|
|
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
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return render_react(
|
2020-01-07 22:29:07 +01:00
|
|
|
f'dj {djinfo[latest_version]["name"]}\'s IIDX Profile',
|
2022-10-15 20:56:30 +02:00
|
|
|
"iidx/player.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"playerid": userid,
|
|
|
|
"own_profile": userid == g.userID,
|
|
|
|
"player": djinfo,
|
|
|
|
"versions": {
|
|
|
|
version: name for (game, version, name) in frontend.all_games()
|
|
|
|
},
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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"),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/players/<int:userid>/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
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:
|
2022-10-15 20:56:30 +02:00
|
|
|
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
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"player": djinfo,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/options")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
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)
|
2021-05-17 23:52:19 +02:00
|
|
|
versions = sorted(
|
|
|
|
[version for (game, version, name) in frontend.all_games()],
|
|
|
|
reverse=True,
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
return render_react(
|
2022-10-15 20:56:30 +02:00
|
|
|
"IIDX Game Settings",
|
|
|
|
"iidx/settings.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"player": djinfo,
|
|
|
|
"regions": RegionConstants.LUT,
|
|
|
|
"versions": {
|
|
|
|
version: name for (game, version, name) in frontend.all_games()
|
|
|
|
},
|
|
|
|
"qpros": frontend.get_all_items(versions),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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"),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/options/flags/update", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def updateflags() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
2022-10-15 20:56:30 +02:00
|
|
|
flags = request.get_json()["flags"]
|
|
|
|
version = int(request.get_json()["version"])
|
2019-12-08 22:43:49 +01:00
|
|
|
user = g.data.local.user.get_user(g.userID)
|
|
|
|
if user is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find user to update!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab profile and settings dict that needs updating
|
|
|
|
profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id)
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find profile to update!")
|
|
|
|
settings_dict = profile.get_dict("settings")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Set bits for flags based on frontend
|
|
|
|
flagint = 0
|
2022-10-15 20:56:30 +02:00
|
|
|
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)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Update special case flags
|
2022-10-15 20:56:30 +02:00
|
|
|
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
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Update the settings dict
|
2022-10-15 20:56:30 +02:00
|
|
|
profile.replace_dict("settings", settings_dict)
|
2019-12-08 22:43:49 +01:00
|
|
|
g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile)
|
|
|
|
|
|
|
|
# Return updated flags
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"flags": frontend.format_flags(settings_dict),
|
|
|
|
"version": version,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
2021-05-17 23:52:19 +02:00
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/options/qpro/update", methods=["POST"])
|
2021-05-17 23:52:19 +02:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def updateqpro() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
2022-10-15 20:56:30 +02:00
|
|
|
qpros = request.get_json()["qpro"]
|
|
|
|
version = int(request.get_json()["version"])
|
2021-05-17 23:52:19 +02:00
|
|
|
user = g.data.local.user.get_user(g.userID)
|
|
|
|
if user is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find user to update!")
|
2021-05-17 23:52:19 +02:00
|
|
|
|
|
|
|
# Grab profile and qpro dict that needs updating
|
|
|
|
profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id)
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find profile to update!")
|
|
|
|
qpro_dict = profile.get_dict("qpro")
|
2021-05-17 23:52:19 +02:00
|
|
|
|
|
|
|
for qpro in qpros:
|
|
|
|
qpro_dict.replace_int(qpro, qpros[qpro])
|
|
|
|
|
|
|
|
# Update the qpro dict
|
2022-10-15 20:56:30 +02:00
|
|
|
profile.replace_dict("qpro", qpro_dict)
|
2021-05-17 23:52:19 +02:00
|
|
|
g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile)
|
|
|
|
|
|
|
|
# Return updated qpro
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"qpro": frontend.format_qpro(qpro_dict),
|
|
|
|
"version": version,
|
2021-05-17 23:52:19 +02:00
|
|
|
}
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/options/settings/update", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def updatesettings() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
2022-10-15 20:56:30 +02:00
|
|
|
settings = request.get_json()["settings"]
|
|
|
|
version = int(request.get_json()["version"])
|
2019-12-08 22:43:49 +01:00
|
|
|
user = g.data.local.user.get_user(g.userID)
|
|
|
|
if user is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find user to update!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab profile and settings dict that needs updating
|
|
|
|
profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id)
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find profile to update!")
|
|
|
|
settings_dict = profile.get_dict("settings")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for setting in settings:
|
|
|
|
settings_dict.replace_int(setting, settings[setting])
|
|
|
|
|
|
|
|
# Update the settings dict
|
2022-10-15 20:56:30 +02:00
|
|
|
profile.replace_dict("settings", settings_dict)
|
2019-12-08 22:43:49 +01:00
|
|
|
g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile)
|
|
|
|
|
|
|
|
# Return updated settings
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"settings": frontend.format_settings(settings_dict),
|
|
|
|
"version": version,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/options/arcade/leave", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def leavearcade() -> Dict[str, Any]:
|
2022-10-15 20:56:30 +02:00
|
|
|
version = int(request.get_json()["version"])
|
2019-12-08 22:43:49 +01:00
|
|
|
user = g.data.local.user.get_user(g.userID)
|
|
|
|
if user is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find user to update!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab profile and nuke the shop location
|
|
|
|
profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id)
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find profile to update!")
|
|
|
|
if "shop_location" in profile:
|
|
|
|
del profile["shop_location"]
|
2019-12-08 22:43:49 +01:00
|
|
|
g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile)
|
|
|
|
|
|
|
|
# Return that we updated
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"version": version,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/options/name/update", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def updatename() -> Dict[str, Any]:
|
2022-10-15 20:56:30 +02:00
|
|
|
version = int(request.get_json()["version"])
|
|
|
|
name = request.get_json()["name"]
|
2019-12-08 22:43:49 +01:00
|
|
|
user = g.data.local.user.get_user(g.userID)
|
|
|
|
if user is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find user to update!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab profile and update dj name
|
|
|
|
profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id)
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find profile to update!")
|
2019-12-08 22:43:49 +01:00
|
|
|
if len(name) == 0 or len(name) > 6:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Invalid profile name!")
|
|
|
|
if re.match(r"^[-&$#\.\?\*!A-Z0-9]*$", name) is None:
|
|
|
|
raise Exception("Invalid profile name!")
|
|
|
|
profile.replace_str("name", name)
|
2019-12-08 22:43:49 +01:00
|
|
|
g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile)
|
|
|
|
|
|
|
|
# Return that we updated
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"version": version,
|
|
|
|
"name": name,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/options/prefecture/update", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def updateprefecture() -> Dict[str, Any]:
|
2022-10-15 20:56:30 +02:00
|
|
|
version = int(request.get_json()["version"])
|
|
|
|
prefecture = int(request.get_json()["prefecture"])
|
2019-12-08 22:43:49 +01:00
|
|
|
user = g.data.local.user.get_user(g.userID)
|
|
|
|
if user is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find user to update!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Grab profile and update prefecture
|
|
|
|
profile = g.data.local.user.get_profile(GameConstants.IIDX, version, user.id)
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find profile to update!")
|
|
|
|
profile.replace_int(
|
|
|
|
"pid", RegionConstants.db_to_game_region(version >= 25, prefecture)
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
g.data.local.user.put_profile(GameConstants.IIDX, version, user.id, profile)
|
|
|
|
|
|
|
|
# Return that we updated
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"version": version,
|
|
|
|
"prefecture": prefecture,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/rivals")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
def viewrivals() -> Response:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
rivals, djinfo = frontend.get_rivals(g.userID)
|
|
|
|
|
|
|
|
return render_react(
|
2022-10-15 20:56:30 +02:00
|
|
|
"IIDX Rivals",
|
|
|
|
"iidx/rivals.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"userid": str(g.userID),
|
|
|
|
"rivals": rivals,
|
|
|
|
"players": djinfo,
|
|
|
|
"versions": {
|
|
|
|
version: name for (game, version, name) in frontend.all_games()
|
|
|
|
},
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"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"),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/rivals/list")
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def listrivals() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
|
|
|
rivals, djinfo = frontend.get_rivals(g.userID)
|
|
|
|
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"rivals": rivals,
|
|
|
|
"players": djinfo,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/rivals/search", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def searchrivals() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
2022-10-15 20:56:30 +02:00
|
|
|
version = int(request.get_json()["version"])
|
|
|
|
djname = request.get_json()["term"]
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# 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:
|
2022-10-15 20:56:30 +02:00
|
|
|
if profile.extid == extid or profile.get_str("name").lower() == djname.lower():
|
2019-12-08 22:43:49 +01:00
|
|
|
matches.add(userid)
|
|
|
|
|
|
|
|
djinfo = frontend.get_all_player_info(list(matches), allow_remote=True)
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"results": djinfo,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/rivals/add", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def addrival() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
2022-10-15 20:56:30 +02:00
|
|
|
version = int(request.get_json()["version"])
|
|
|
|
rivaltype = request.get_json()["type"]
|
|
|
|
other_userid = UserID(int(request.get_json()["userid"]))
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = g.userID
|
|
|
|
|
|
|
|
# Add this rival link
|
2022-10-15 20:56:30 +02:00
|
|
|
if rivaltype != "sp_rival" and rivaltype != "dp_rival":
|
|
|
|
raise Exception(f"Invalid rival type {rivaltype}!")
|
2019-12-08 22:43:49 +01:00
|
|
|
profile = g.data.remote.user.get_profile(GameConstants.IIDX, version, other_userid)
|
|
|
|
if profile is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Unable to find profile for rival!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
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 {
|
2022-10-15 20:56:30 +02:00
|
|
|
"rivals": rivals,
|
|
|
|
"players": djinfo,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@iidx_pages.route("/rivals/remove", methods=["POST"])
|
2019-12-08 22:43:49 +01:00
|
|
|
@jsonify
|
|
|
|
@loginrequired
|
|
|
|
def removerival() -> Dict[str, Any]:
|
|
|
|
frontend = IIDXFrontend(g.data, g.config, g.cache)
|
2022-10-15 20:56:30 +02:00
|
|
|
version = int(request.get_json()["version"])
|
|
|
|
rivaltype = request.get_json()["type"]
|
|
|
|
other_userid = UserID(int(request.get_json()["userid"]))
|
2019-12-08 22:43:49 +01:00
|
|
|
userid = g.userID
|
|
|
|
|
|
|
|
# Remove this rival link
|
2022-10-15 20:56:30 +02:00
|
|
|
if rivaltype != "sp_rival" and rivaltype != "dp_rival":
|
|
|
|
raise Exception(f"Invalid rival type {rivaltype}!")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
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 {
|
2022-10-15 20:56:30 +02:00
|
|
|
"rivals": rivals,
|
|
|
|
"players": djinfo,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|