Merge branch 'develop'

This commit is contained in:
Hay1tsme 2023-03-01 23:41:42 -05:00
commit e2129b45b7
82 changed files with 2423 additions and 806 deletions

View File

@ -4,3 +4,4 @@ from core.aimedb import AimedbFactory
from core.title import TitleServlet
from core.utils import Utils
from core.mucha import MuchaServlet
from core.frontend import FrontendServlet

View File

@ -95,14 +95,19 @@ class AllnetServlet:
def handle_poweron(self, request: Request, _: Dict):
request_ip = request.getClientAddress().host
try:
req = AllnetPowerOnRequest(self.allnet_req_to_dict(request.content.getvalue())[0])
req_dict = self.allnet_req_to_dict(request.content.getvalue())
if req_dict is None:
raise AllnetRequestException()
req = AllnetPowerOnRequest(req_dict[0])
# Validate the request. Currently we only validate the fields we plan on using
if not req.game_id or not req.ver or not req.token or not req.serial or not req.ip:
raise AllnetRequestException(f"Bad auth request params from {request_ip} - {vars(req)}")
except AllnetRequestException as e:
self.logger.error(e)
if e.message != "":
self.logger.error(e)
return b""
if req.format_ver == 3:
@ -155,14 +160,19 @@ class AllnetServlet:
def handle_dlorder(self, request: Request, _: Dict):
request_ip = request.getClientAddress().host
try:
req = AllnetDownloadOrderRequest(self.allnet_req_to_dict(request.content.getvalue())[0])
req_dict = self.allnet_req_to_dict(request.content.getvalue())
if req_dict is None:
raise AllnetRequestException()
req = AllnetDownloadOrderRequest(req_dict[0])
# Validate the request. Currently we only validate the fields we plan on using
if not req.game_id or not req.ver or not req.serial:
raise AllnetRequestException(f"Bad download request params from {request_ip} - {vars(req)}")
except AllnetRequestException as e:
self.logger.error(e)
if e.message != "":
self.logger.error(e)
return b""
resp = AllnetDownloadOrderResponse()
@ -234,6 +244,10 @@ class AllnetServlet:
self.logger.debug(f"response {vars(resp)}")
return resp_str.encode("utf-8")
def handle_naomitest(self, request: Request, _: Dict) -> bytes:
self.logger.info(f"Ping from {request.getClientAddress().host}")
return b"naomi ok"
def kvp_to_dict(self, kvp: List[str]) -> List[Dict[str, Any]]:
ret: List[Dict[str, Any]] = []
for x in kvp:
@ -261,7 +275,7 @@ class AllnetServlet:
return self.kvp_to_dict(sections)
except Exception as e:
self.logger.error(e)
self.logger.error(f"billing_req_to_dict: {e} while parsing {data}")
return None
def allnet_req_to_dict(self, data: str) -> Optional[List[Dict[str, Any]]]:
@ -276,7 +290,7 @@ class AllnetServlet:
return self.kvp_to_dict(sections)
except Exception as e:
self.logger.error(e)
self.logger.error(f"allnet_req_to_dict: {e} while parsing {data}")
return None
def dict_to_http_form_string(self, data:List[Dict[str, Any]], crlf: bool = False, trailing_newline: bool = True) -> Optional[str]:
@ -303,7 +317,7 @@ class AllnetServlet:
return urlencode
except Exception as e:
self.logger.error(e)
self.logger.error(f"dict_to_http_form_string: {e} while parsing {data}")
return None
class AllnetPowerOnRequest():
@ -403,6 +417,6 @@ class BillingResponse():
# YYYY -> 4 digit year, MM -> 2 digit month, C -> Playcount during that period
class AllnetRequestException(Exception):
def __init__(self, message="Allnet Request Error") -> None:
def __init__(self, message="") -> None:
self.message = message
super().__init__(self.message)

View File

@ -194,6 +194,7 @@ class CoreConfig(dict):
self.allnet = AllnetConfig(self)
self.billing = BillingConfig(self)
self.aimedb = AimedbConfig(self)
self.mucha = MuchaConfig(self)
@classmethod
def str_to_loglevel(cls, level_str: str):

View File

@ -31,6 +31,61 @@ class KeychipPlatformsCodes():
NU = ("A60E", "A60E", "A60E")
NUSX = ("A61X", "A69X")
ALLS = "A63E"
class RegionIDs(Enum):
pass
class AllnetCountryCode(Enum):
JAPAN = "JPN"
UNITED_STATES = "USA"
HONG_KONG = "HKG"
SINGAPORE = "SGP"
SOUTH_KOREA = "KOR"
CHINA = "CHN"
class AllnetJapanRegionId(Enum):
NONE = 0
AICHI = 1
AOMORI = 2
AKITA = 3
ISHIKAWA = 4
IBARAKI = 5
IWATE = 6
EHIME = 7
OITA = 8
OSAKA = 9
OKAYAMA = 10
OKINAWA = 11
KAGAWA = 12
KAGOSHIMA = 13
KANAGAWA = 14
GIFU = 15
KYOTO = 16
KUMAMOTO = 17
GUNMA = 18
KOCHI = 19
SAITAMA = 20
SAGA = 21
SHIGA = 22
SHIZUOKA = 23
SHIMANE = 24
CHIBA = 25
TOKYO = 26
TOKUSHIMA = 27
TOCHIGI = 28
TOTTORI = 29
TOYAMA = 30
NAGASAKI = 31
NAGANO = 32
NARA = 33
NIIGATA = 34
HYOGO = 35
HIROSHIMA = 36
FUKUI = 37
FUKUOKA = 38
FUKUSHIMA = 39
HOKKAIDO = 40
MIE = 41
MIYAGI = 42
MIYAZAKI = 43
YAMAGATA = 44
YAMAGUCHI = 45
YAMANASHI = 46
WAKAYAMA = 47

View File

@ -31,7 +31,7 @@ class Data:
self.arcade = ArcadeData(self.config, self.session)
self.card = CardData(self.config, self.session)
self.base = BaseData(self.config, self.session)
self.schema_ver_latest = 1
self.schema_ver_latest = 2
log_fmt_str = "[%(asctime)s] %(levelname)s | Database | %(message)s"
log_fmt = logging.Formatter(log_fmt_str)

View File

@ -1,9 +1,14 @@
from enum import Enum
from typing import Dict, Optional
from sqlalchemy import Table, Column
from sqlalchemy import Table, Column, and_
from sqlalchemy.types import Integer, String, TIMESTAMP
from sqlalchemy.sql.schema import ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.dialects.mysql import insert
from sqlalchemy.sql import func, select, Delete
from uuid import uuid4
from datetime import datetime, timedelta
from sqlalchemy.engine import Row
from core.data.schema.base import BaseData, metadata
@ -26,6 +31,7 @@ frontend_session = Table(
metadata,
Column("id", Integer, primary_key=True, unique=True),
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
Column("ip", String(15)),
Column('session_cookie', String(32), nullable=False, unique=True),
Column("expires", TIMESTAMP, nullable=False),
mysql_charset='utf8mb4'
@ -37,21 +43,83 @@ class PermissionBits(Enum):
PermSysAdmin = 4
class UserData(BaseData):
def create_user(self, username: str = None, email: str = None, password: str = None) -> Optional[int]:
def create_user(self, id: int = None, username: str = None, email: str = None, password: str = None, permission: int = 1) -> Optional[int]:
if email is None:
permission = None
else:
permission = 0
permission = 1
sql = aime_user.insert().values(username=username, email=email, password=password, permissions=permission)
if id is None:
sql = insert(aime_user).values(
username=username,
email=email,
password=password,
permissions=permission
)
else:
sql = insert(aime_user).values(
id=id,
username=username,
email=email,
password=password,
permissions=permission
)
conflict = sql.on_duplicate_key_update(
username=username,
email=email,
password=password,
permissions=permission
)
result = self.execute(sql)
result = self.execute(conflict)
if result is None: return None
return result.lastrowid
def login(self, user_id: int, passwd: bytes = None, ip: str = "0.0.0.0") -> Optional[str]:
sql = select(aime_user).where(and_(aime_user.c.id == user_id, aime_user.c.password == passwd))
result = self.execute(sql)
if result is None: return None
usr = result.fetchone()
if usr is None: return None
return self.create_session(user_id, ip)
def check_session(self, cookie: str, ip: str = "0.0.0.0") -> Optional[Row]:
sql = select(frontend_session).where(
and_(
frontend_session.c.session_cookie == cookie,
frontend_session.c.ip == ip
)
)
result = self.execute(sql)
if result is None: return None
return result.fetchone()
def delete_session(self, session_id: int) -> bool:
sql = Delete(frontend_session).where(frontend_session.c.id == session_id)
result = self.execute(sql)
if result is None: return False
return True
def create_session(self, user_id: int, ip: str = "0.0.0.0", expires: datetime = datetime.now() + timedelta(days=1)) -> Optional[str]:
cookie = uuid4().hex
sql = insert(frontend_session).values(
user = user_id,
ip = ip,
session_cookie = cookie,
expires = expires
)
result = self.execute(sql)
if result is None:
return None
return cookie
def reset_autoincrement(self, ai_value: int) -> None:
# Didn't feel like learning how to do this the right way
# if somebody wants a free PR go nuts I guess
# ALTER TABLE isn't in sqlalchemy so we do this the ugly way
sql = f"ALTER TABLE aime_user AUTO_INCREMENT={ai_value}"
self.execute(sql)

View File

@ -0,0 +1,2 @@
ALTER TABLE `frontend_session`
DROP COLUMN `ip`;

View File

@ -0,0 +1,2 @@
ALTER TABLE `frontend_session`
ADD `ip` CHAR(15);

View File

@ -0,0 +1,9 @@
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE diva_score DROP COLUMN edition;
ALTER TABLE diva_playlog DROP COLUMN edition;
ALTER TABLE diva_score DROP FOREIGN KEY diva_score_ibfk_1;
ALTER TABLE diva_score DROP CONSTRAINT diva_score_uk;
ALTER TABLE diva_score ADD CONSTRAINT diva_score_uk UNIQUE (user, pv_id, difficulty);
ALTER TABLE diva_score ADD CONSTRAINT diva_score_ibfk_1 FOREIGN KEY (user) REFERENCES aime_user(id) ON DELETE CASCADE;
SET FOREIGN_KEY_CHECKS=1;

View File

@ -0,0 +1,17 @@
ALTER TABLE diva_profile_shop DROP COLUMN c_itm_eqp_ary;
ALTER TABLE diva_profile_shop DROP COLUMN ms_itm_flg_ary;
ALTER TABLE diva_profile DROP COLUMN use_pv_mdl_eqp;
ALTER TABLE diva_profile DROP COLUMN use_mdl_pri;
ALTER TABLE diva_profile DROP COLUMN use_pv_skn_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_btn_se_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_sld_se_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_chn_sld_se_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_sldr_tch_se_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_mdl_eqp VARCHAR(8) NOT NULL DEFAULT "true" AFTER sort_kind;
ALTER TABLE diva_profile ADD COLUMN use_pv_btn_se_eqp VARCHAR(8) NOT NULL DEFAULT "true" AFTER use_pv_mdl_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_sld_se_eqp VARCHAR(8) NOT NULL DEFAULT "false" AFTER use_pv_btn_se_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_chn_sld_se_eqp VARCHAR(8) NOT NULL DEFAULT "false" AFTER use_pv_sld_se_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_sldr_tch_se_eqp VARCHAR(8) NOT NULL DEFAULT "false" AFTER use_pv_chn_sld_se_eqp;
DROP TABLE IF EXISTS `diva_profile_pv_customize`;

View File

@ -0,0 +1,9 @@
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE diva_score ADD COLUMN edition int(11) DEFAULT 0 AFTER difficulty;
ALTER TABLE diva_playlog ADD COLUMN edition int(11) DEFAULT 0 AFTER difficulty;
ALTER TABLE diva_score DROP FOREIGN KEY diva_score_ibfk_1;
ALTER TABLE diva_score DROP CONSTRAINT diva_score_uk;
ALTER TABLE diva_score ADD CONSTRAINT diva_score_uk UNIQUE (user, pv_id, difficulty, edition);
ALTER TABLE diva_score ADD CONSTRAINT diva_score_ibfk_1 FOREIGN KEY (user) REFERENCES aime_user(id) ON DELETE CASCADE;
SET FOREIGN_KEY_CHECKS=1;

View File

@ -0,0 +1,3 @@
ALTER TABLE diva_profile DROP COLUMN passwd_stat;
ALTER TABLE diva_profile DROP COLUMN passwd;
ALTER TABLE diva_profile MODIFY player_name VARCHAR(8);

View File

@ -0,0 +1,33 @@
ALTER TABLE diva_profile_shop ADD COLUMN c_itm_eqp_ary varchar(59) DEFAULT "-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999";
ALTER TABLE diva_profile_shop ADD COLUMN ms_itm_flg_ary varchar(59) DEFAULT "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1";
ALTER TABLE diva_profile DROP COLUMN use_pv_mdl_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_btn_se_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_sld_se_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_chn_sld_se_eqp;
ALTER TABLE diva_profile DROP COLUMN use_pv_sldr_tch_se_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_mdl_eqp BOOLEAN NOT NULL DEFAULT true AFTER sort_kind;
ALTER TABLE diva_profile ADD COLUMN use_mdl_pri BOOLEAN NOT NULL DEFAULT false AFTER use_pv_mdl_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_skn_eqp BOOLEAN NOT NULL DEFAULT false AFTER use_mdl_pri;
ALTER TABLE diva_profile ADD COLUMN use_pv_btn_se_eqp BOOLEAN NOT NULL DEFAULT true AFTER use_pv_skn_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_sld_se_eqp BOOLEAN NOT NULL DEFAULT false AFTER use_pv_btn_se_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_chn_sld_se_eqp BOOLEAN NOT NULL DEFAULT false AFTER use_pv_sld_se_eqp;
ALTER TABLE diva_profile ADD COLUMN use_pv_sldr_tch_se_eqp BOOLEAN NOT NULL DEFAULT false AFTER use_pv_chn_sld_se_eqp;
CREATE TABLE diva_profile_pv_customize (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
user INT NOT NULL,
version INT NOT NULL,
pv_id INT NOT NULL,
mdl_eqp_ary VARCHAR(14) DEFAULT '-999,-999,-999',
c_itm_eqp_ary VARCHAR(59) DEFAULT '-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999',
ms_itm_flg_ary VARCHAR(59) DEFAULT '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1',
skin INT DEFAULT '-1',
btn_se INT DEFAULT '-1',
sld_se INT DEFAULT '-1',
chsld_se INT DEFAULT '-1',
sldtch_se INT DEFAULT '-1',
UNIQUE KEY diva_profile_pv_customize_uk (user, version, pv_id),
CONSTRAINT diva_profile_pv_customize_ibfk_1 FOREIGN KEY (user) REFERENCES aime_user (id) ON DELETE CASCADE ON UPDATE CASCADE
);

View File

@ -0,0 +1,3 @@
ALTER TABLE diva_profile ADD COLUMN passwd_stat INTEGER NOT NULL DEFAULT 0;
ALTER TABLE diva_profile ADD COLUMN passwd VARCHAR(12) NOT NULL DEFAULT "**********";
ALTER TABLE diva_profile MODIFY player_name VARCHAR(10);

View File

@ -0,0 +1 @@
ALTER TABLE chuni_static_music CHANGE COLUMN worldsEndTag worldsEndTag VARCHAR(20) NULL DEFAULT NULL ;

View File

@ -0,0 +1 @@
ALTER TABLE chuni_score_course DROP COLUMN theoryCount, DROP COLUMN orderId, DROP COLUMN playerRating;

View File

@ -0,0 +1 @@
ALTER TABLE chuni_static_music CHANGE COLUMN worldsEndTag worldsEndTag VARCHAR(7) NULL DEFAULT NULL ;

View File

@ -0,0 +1 @@
ALTER TABLE chuni_score_course ADD theoryCount int(11), ADD orderId int(11), ADD playerRating int(11);

View File

@ -0,0 +1,3 @@
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE mai2_playlog DROP COLUMN trialPlayAchievement;
SET FOREIGN_KEY_CHECKS=1;

View File

@ -0,0 +1,3 @@
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE mai2_playlog ADD trialPlayAchievement INT NULL;
SET FOREIGN_KEY_CHECKS=1;

181
core/frontend.py Normal file
View File

@ -0,0 +1,181 @@
import logging, coloredlogs
from typing import Any, Dict, List
from twisted.web import resource
from twisted.web.util import redirectTo
from twisted.web.http import Request
from logging.handlers import TimedRotatingFileHandler
import jinja2
import bcrypt
from core.config import CoreConfig
from core.data import Data
from core.utils import Utils
class FrontendServlet(resource.Resource):
def getChild(self, name: bytes, request: Request):
self.logger.debug(f"{request.getClientIP()} -> {name.decode()}")
if name == b'':
return self
return resource.Resource.getChild(self, name, request)
def __init__(self, cfg: CoreConfig, config_dir: str) -> None:
self.config = cfg
log_fmt_str = "[%(asctime)s] Frontend | %(levelname)s | %(message)s"
log_fmt = logging.Formatter(log_fmt_str)
self.logger = logging.getLogger("frontend")
self.environment = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
self.game_list: List[Dict[str, str]] = []
self.children: Dict[str, Any] = {}
fileHandler = TimedRotatingFileHandler("{0}/{1}.log".format(self.config.server.log_dir, "frontend"), when="d", backupCount=10)
fileHandler.setFormatter(log_fmt)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(log_fmt)
self.logger.addHandler(fileHandler)
self.logger.addHandler(consoleHandler)
self.logger.setLevel(cfg.frontend.loglevel)
coloredlogs.install(level=cfg.frontend.loglevel, logger=self.logger, fmt=log_fmt_str)
fe_game = FE_Game(cfg, self.environment)
games = Utils.get_all_titles()
for game_dir, game_mod in games.items():
if hasattr(game_mod, "frontend"):
try:
game_fe = game_mod.frontend(cfg, self.environment, config_dir)
self.game_list.append({"url": game_dir, "name": game_fe.nav_name})
fe_game.putChild(game_dir.encode(), game_fe)
except:
raise
self.environment.globals["game_list"] = self.game_list
self.putChild(b"gate", FE_Gate(cfg, self.environment))
self.putChild(b"user", FE_User(cfg, self.environment))
self.putChild(b"game", fe_game)
self.logger.info(f"Ready on port {self.config.frontend.port} serving {len(fe_game.children)} games")
def render_GET(self, request):
self.logger.debug(f"{request.getClientIP()} -> {request.uri.decode()}")
template = self.environment.get_template("core/frontend/index.jinja")
return template.render(server_name=self.config.server.name, title=self.config.server.name, game_list=self.game_list).encode("utf-16")
class FE_Base(resource.Resource):
"""
A Generic skeleton class that all frontend handlers should inherit from
Initializes the environment, data, logger, config, and sets isLeaf to true
It is expected that game implementations of this class overwrite many of these
"""
isLeaf = True
def __init__(self, cfg: CoreConfig, environment: jinja2.Environment) -> None:
self.core_config = cfg
self.data = Data(cfg)
self.logger = logging.getLogger('frontend')
self.environment = environment
self.nav_name = "nav_name"
class FE_Gate(FE_Base):
def render_GET(self, request: Request):
self.logger.debug(f"{request.getClientIP()} -> {request.uri.decode()}")
uri: str = request.uri.decode()
if uri.startswith("/gate/create"):
return self.create_user(request)
if b'e' in request.args:
try:
err = int(request.args[b'e'][0].decode())
except:
err = 0
else: err = 0
template = self.environment.get_template("core/frontend/gate/gate.jinja")
return template.render(title=f"{self.core_config.server.name} | Login Gate", error=err).encode("utf-16")
def render_POST(self, request: Request):
uri = request.uri.decode()
ip = request.getClientAddress().host
if uri == "/gate/gate.login":
access_code: str = request.args[b"access_code"][0].decode()
passwd: str = request.args[b"passwd"][0]
if passwd == b"":
passwd = None
uid = self.data.card.get_user_id_from_card(access_code)
if uid is None:
return redirectTo(b"/gate?e=1", request)
if passwd is None:
sesh = self.data.user.login(uid, ip=ip)
if sesh is not None:
return redirectTo(f"/gate/create?ac={access_code}".encode(), request)
return redirectTo(b"/gate?e=1", request)
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(passwd, salt)
sesh = self.data.user.login(uid, hashed, ip)
if sesh is None:
return redirectTo(b"/gate?e=1", request)
request.addCookie('session', sesh)
return redirectTo(b"/user", request)
elif uri == "/gate/gate.create":
access_code: str = request.args[b"access_code"][0].decode()
username: str = request.args[b"username"][0]
email: str = request.args[b"email"][0].decode()
passwd: str = request.args[b"passwd"][0]
uid = self.data.card.get_user_id_from_card(access_code)
if uid is None:
return redirectTo(b"/gate?e=1", request)
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(passwd, salt)
result = self.data.user.create_user(uid, username, email, hashed.decode(), 1)
if result is None:
return redirectTo(b"/gate?e=3", request)
sesh = self.data.user.login(uid, hashed, ip)
if sesh is None:
return redirectTo(b"/gate", request)
request.addCookie('session', sesh)
return redirectTo(b"/user", request)
else:
return b""
def create_user(self, request: Request):
if b'ac' not in request.args or len(request.args[b'ac'][0].decode()) != 20:
return redirectTo(b"/gate?e=2", request)
ac = request.args[b'ac'][0].decode()
template = self.environment.get_template("core/frontend/gate/create.jinja")
return template.render(title=f"{self.core_config.server.name} | Create User", code=ac).encode("utf-16")
class FE_User(FE_Base):
def render_GET(self, request: Request):
template = self.environment.get_template("core/frontend/user/index.jinja")
return template.render().encode("utf-16")
if b'session' not in request.cookies:
return redirectTo(b"/gate", request)
class FE_Game(FE_Base):
isLeaf = False
children: Dict[str, Any] = {}
def getChild(self, name: bytes, request: Request):
if name == b'':
return self
return resource.Resource.getChild(self, name, request)
def render_GET(self, request: Request) -> bytes:
return redirectTo(b"/user", request)

View File

@ -0,0 +1,24 @@
{% extends "core/frontend/index.jinja" %}
{% block content %}
<h1>Create User</h1>
<form id="create" style="max-width: 240px; min-width: 10%;" action="/gate/gate.create" method="post">
<div class="form-group row">
<label for="access_code">Card Access Code</label><br>
<input class="form-control" name="access_code" id="access_code" type="text" placeholder="00000000000000000000" value={{ code }} maxlength="20" readonly>
</div>
<div class="form-group row">
<label for="username">Username</label><br>
<input id="username" class="form-control" name="username" type="text" placeholder="username">
</div>
<div class="form-group row">
<label for="email">Email</label><br>
<input id="email" class="form-control" name="email" type="email" placeholder="example@example.com">
</div>
<div class="form-group row">
<label for="passwd">Password</label><br>
<input id="passwd" class="form-control" name="passwd" type="password" placeholder="password">
</div>
<p></p>
<input id="submit" class="btn btn-primary" style="display: block; margin: 0 auto;" type="submit" value="Create">
</form>
{% endblock content %}

View File

@ -0,0 +1,17 @@
{% extends "core/frontend/index.jinja" %}
{% block content %}
<h1>Gate</h1>
{% include "core/frontend/widgets/err_banner.jinja" %}
<form id="login" style="max-width: 240px; min-width: 10%;" action="/gate/gate.login" method="post">
<div class="form-group row">
<label for="access_code">Card Access Code</label><br>
<input form="login" class="form-control" name="access_code" id="access_code" type="text" placeholder="00000000000000000000" maxlength="20" required>
</div>
<div class="form-group row">
<label for="passwd">Password</label><br>
<input id="passwd" class="form-control" name="passwd" type="password" placeholder="password">
</div>
<p></p>
<input id="submit" class="btn btn-primary" style="display: block; margin: 0 auto;" form="login" type="submit" value="Login">
</form>
{% endblock content %}

88
core/frontend/index.jinja Normal file
View File

@ -0,0 +1,88 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
<style>
html {
background-color: #181a1b !important;
margin: 10px;
}
html {
color-scheme: dark !important;
}
html, body, input, textarea, select, button, dialog {
background-color: #181a1b;
}
html, body, input, textarea, select, button {
border-color: #736b5e;
color: #e8e6e3;
}
a {
color: #3391ff;
}
table {
border-color: #545b5e;
}
::placeholder {
color: #b2aba1;
}
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
background-color: #404400 !important;
color: #e8e6e3 !important;
}
::-webkit-scrollbar {
background-color: #202324;
color: #aba499;
}
::-webkit-scrollbar-thumb {
background-color: #454a4d;
}
::-webkit-scrollbar-thumb:hover {
background-color: #575e62;
}
::-webkit-scrollbar-thumb:active {
background-color: #484e51;
}
::-webkit-scrollbar-corner {
background-color: #181a1b;
}
* {
scrollbar-color: #454a4d #202324;
}
::selection {
background-color: #004daa !important;
color: #e8e6e3 !important;
}
::-moz-selection {
background-color: #004daa !important;
color: #e8e6e3 !important;
}
input[type="text"], input[type="text"]:focus, input[type="password"], input[type="password"]:focus, input[type="email"], input[type="email"]:focus {
background-color: #202324 !important;
color: #e8e6e3;
}
form {
outline: 1px solid grey;
padding: 20px;
padding-top: 10px;
padding-bottom: 10px;
}
.err-banner {
background-color: #AA0000;
padding: 20px;
margin-bottom: 10px;
width: 15%;
}
</style>
</head>
<body>
{% include "core/frontend/widgets/topbar.jinja" %}
{% block content %}
<h1>{{ server_name }}</h1>
{% endblock content %}
</body>
</html>

View File

@ -0,0 +1,4 @@
{% extends "core/frontend/index.jinja" %}
{% block content %}
<h1>testing</h1>
{% endblock content %}

View File

@ -0,0 +1,14 @@
{% if error > 0 %}
<div class="err-banner">
<h3>Error</h3>
{% if error == 1 %}
Card not registered, or wrong password
{% elif error == 2 %}
Missing or malformed access code
{% elif error == 3 %}
Failed to create user
{% else %}
An unknown error occoured
{% endif %}
</div>
{% endif %}

View File

@ -0,0 +1,13 @@
<div style="background: #333; color: #f9f9f9; width: 10%; height: 50px; line-height: 50px; text-align: center; float: left;">
Navigation
</div>
<div style="background: #333; color: #f9f9f9; width: 80%; height: 50px; line-height: 50px; padding-left: 10px; float: left;">
<a href=/><button class="btn btn-primary">Home</button></a>&nbsp;
{% for game in game_list %}
<a href=game/{{ game.url }}><button class="btn btn-success">{{ game.name }}</button></a>&nbsp;
{% endfor %}
</div>
</div>
<div style="background: #333; color: #f9f9f9; width: 10%; height: 50px; line-height: 50px; text-align: center; float: left;">
<a href="/gate"><button class="btn btn-primary">Gate</button></a>
</div>

View File

@ -35,9 +35,14 @@ class MuchaServlet:
return b""
req = MuchaAuthRequest(req_dict)
self.logger.info(f"Mucha request {vars(req)}")
resp = MuchaAuthResponse(mucha_url=f"{self.config.mucha.hostname}:{self.config.mucha.port}")
self.logger.info(f"Mucha response {vars(resp)}")
self.logger.debug(f"Mucha request {vars(req)}")
if self.config.server.is_develop:
resp = MuchaAuthResponse(mucha_url=f"{self.config.mucha.hostname}:{self.config.mucha.port}")
else:
resp = MuchaAuthResponse(mucha_url=f"{self.config.mucha.hostname}")
self.logger.debug(f"Mucha response {vars(resp)}")
return self.mucha_postprocess(vars(resp))
@ -48,9 +53,14 @@ class MuchaServlet:
return b""
req = MuchaUpdateRequest(req_dict)
self.logger.info(f"Mucha request {vars(req)}")
resp = MuchaUpdateResponse(mucha_url=f"{self.config.mucha.hostname}:{self.config.mucha.port}")
self.logger.info(f"Mucha response {vars(resp)}")
self.logger.debug(f"Mucha request {vars(req)}")
if self.config.server.is_develop:
resp = MuchaUpdateResponse(mucha_url=f"{self.config.mucha.hostname}:{self.config.mucha.port}")
else:
resp = MuchaUpdateResponse(mucha_url=f"{self.config.mucha.hostname}")
self.logger.debug(f"Mucha response {vars(resp)}")
return self.mucha_postprocess(vars(resp))

View File

@ -71,4 +71,4 @@ class TitleServlet():
self.logger.warn(f"{code} does not dispatch POST")
return b""
return index.render_POST(request, endpoints["version"], endpoints["endpoint"])
return index.render_POST(request, int(endpoints["version"]), endpoints["endpoint"])

View File

@ -1,6 +1,6 @@
from typing import Dict, List, Any, Optional
from typing import Dict, Any
from types import ModuleType
import zlib, base64
import logging
import importlib
from os import walk
@ -17,6 +17,6 @@ class Utils:
ret[dir] = mod
except ImportError as e:
print(f"{dir} - {e}")
logging.getLogger("core").error(f"get_all_titles: {dir} - {e}")
raise
return ret

View File

@ -23,22 +23,22 @@ if __name__=='__main__':
elif args.action == "upgrade" or args.action == "rollback":
if args.version is None:
print("Must set game and version to migrate to")
data.logger.error("Must set game and version to migrate to")
exit(0)
if args.game is None:
print("No game set, upgrading core schema")
data.logger.info("No game set, upgrading core schema")
data.migrate_database("CORE", int(args.version))
else:
data.migrate_database(args.game, int(args.version), args.action)
elif args.action == "migrate":
print("Migrating from old schema to new schema")
data.logger.info("Migrating from old schema to new schema")
data.restore_from_old_schema()
elif args.action == "dump":
print("Dumping old schema to migrate to new schema")
data.logger.info("Dumping old schema to migrate to new schema")
data.dump_db()
elif args.action == "generate":

129
docs/INSTALL_UBUNTU.md Normal file
View File

@ -0,0 +1,129 @@
# ARTEMiS - Ubuntu 20.04 LTS Guide
This step-by-step guide assumes that you are using a fresh install of Ubuntu 20.04 LTS, some of the steps can be skipped if you already have an installation with MySQL 5.7 or even some of the modules already present on your environment
# Setup
## Install memcached module
1. sudo apt-get install memcached
2. Under the file /etc/memcached.conf, please make sure the following parameters are set:
```
# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-I 128m
-m 1024
```
** This is mandatory to avoid memcached overload caused by Crossbeats or by massive profiles
3. Restart memcached using: sudo systemctl restart memcached
## Install MySQL 5.7
```
sudo apt update
sudo apt install wget -y
wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
```
1. During the first prompt, select Ubuntu Bionic
2. Select the default option
3. Select MySQL 5.7
4. Select the last option
```
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
sudo apt-get update
sudo apt-cache policy mysql-server
sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
```
## Default Configuration for MySQL Server
1. sudo mysql_secure_installation
> Make sure to follow the steps that will be prompted such as changing the mysql root password and such
2. Test your MySQL Server login by doing the following command :
> mysql -u root -p
## Create the default ARTEMiS database and user
1. mysql -u root -p
2. Please change the password indicated in the next line for a custom secure one and continue with the next commands
```
CREATE USER 'aime'@'localhost' IDENTIFIED BY 'MyStrongPass.';
CREATE DATABASE aime;
GRANT Alter,Create,Delete,Drop,Index,Insert,References,Select,Update ON aime.* TO 'aime'@'localhost';
FLUSH PRIVILEGES;
exit;
```
3. sudo systemctl restart mysql
## Install Python modules
```
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential mysql-client libmysqlclient-dev libmemcached-dev
sudo apt install libpython3.8-dev
sudo apt-get install python3-software-properties
sudo apt install python3-pip
sudo pip3 install --upgrade pip testresources
sudo pip3 install --upgrade pip setuptools
sudo apt-get install python3-tk
```
7. Change your work path to the ARTEMiS root folder using 'cd' and install the requirements:
> sudo python3 -m pip install -r requirements.txt
## Copy/Rename the folder example_config to config
## Adjust /config/core.yaml
1. Make sure to change the server listen_address to be set to your local machine IP (ex.: 192.168.1.xxx)
2. Adjust the proper MySQL information you created earlier
3. Add the AimeDB key at the bottom of the file
## Create the database tables for ARTEMiS
1. sudo python3 dbutils.py create
2. If you get "No module named Crypto", run the following command:
```
sudo pip uninstall crypto
sudo pip uninstall pycrypto
sudo pip install pycrypto
```
## Firewall Adjustements
```
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 8443
sudo ufw allow 22345
sudo ufw allow 8090
sudo ufw allow 8444
sudo ufw allow 9000
```
## Running the ARTEMiS instance
1. sudo python3 index.py
# Troubleshooting
## Game does not connect to ARTEMiS Allnet server
1. Double-check your core.yaml, the listen_address is most likely either not binded to the proper IP or the port is not opened
## Game does not connect to Title Server
1. Verify that your core.yaml is setup properly for both the server listen_address and title hostname
2. Boot your game and verify that an AllNet response does show and if it does, attempt to open the URI that is shown under a browser such as Edge, Chrome & Firefox.
3. If a page is shown, the server is working properly and if it doesn't, double check your port forwarding and also that you have entered the proper local IP under the Title hostname in core.yaml.
## Unhandled command under AimeDB
1. Double check your AimeDB key under core.yaml, it is incorrect.
## Memcache failed, error 3
1. Make sure memcached is properly installed and running. You can check the status of the service using the following command:
> sudo systemctl status memcached
2. If it is failing, double check the /etc/memcached.conf file, it may have duplicated arguments like the -I and -m
3. If it is still not working afterward, you can proceed with a workaround by manually editing the /core/data/cache.py file.
```
# Make memcache optional
try:
has_mc = False
except ModuleNotFoundError:
has_mc = False
```

83
docs/INSTALL_WINDOWS.md Normal file
View File

@ -0,0 +1,83 @@
# ARTEMiS - Windows 10/11 Guide
This step-by-step guide assumes that you are using a fresh install of Windows 10/11 without MySQL installed, some of the steps can be skipped if you already have an installation with MySQL 8.0 or even some of the modules already present on your environment
# Setup
## Install Python Python 3.9 (recommended) or 3.10
1. Download Python 3.9 : [Link](https://www.python.org/ftp/python/3.9.13/python-3.9.13-amd64.exe)
2. Install python-3.9.13-amd64.exe
1. Select Customize installation
2. Make sure that pip, tcl/tk, and the for all users are checked and hit Next
3. Make sure that you enable "Create shortcuts for installed applications" and "Add Python to environment variables" and hit Install
## Install MySQL 8.0
1. Download MySQL 8.0 Server : [Link](https://cdn.mysql.com//Downloads/MySQLInstaller/mysql-installer-web-community-8.0.31.0.msi)
2. Install mysql-installer-web-community-8.0.31.0.msi
1. Click on "Add ..." on the side
2. Click on the "+" next to MySQL Servers
3. Make sure MySQL Server 8.0.29 - X64 is under the products to be installed.
4. Hit Next and Next once installed
5. Select the configuration type "Development Computer"
6. Hit Next
7. Select "Use Legacy Authentication Method (Retain MySQL 5.x compatibility)" and hit Next
8. Enter a root password and then hit Next >
9. Leave everything under Windows Service as default and hit Next >
10. Click on Execute and for it to finish and hit Next> and then Finish
3. Open MySQL 8.0 Command Line Client and login as your root user
4. Type those commands to create your user and the database
```
CREATE USER 'aime'@'localhost' IDENTIFIED BY 'MyStrongPass.';
CREATE DATABASE aime;
GRANT Alter,Create,Delete,Drop,Index,Insert,References,Select,Update ON aime.* TO 'aime'@'localhost';
FLUSH PRIVILEGES;
exit;
```
## Install Python modules
1. Change your work path to the artemis-master folder using 'cd' and install the requirements:
> pip install -r requirements.txt
## Copy/Rename the folder example_config to config
## Adjust /config/core.yaml
1. Make sure to change the server listen_address to be set to your local machine IP (ex.: 192.168.1.xxx)
- In case you want to run this only locally, set the following values:
```
server:
listen_address: 0.0.0.0
title:
hostname: localhost
```
2. Adjust the proper MySQL information you created earlier
3. Add the AimeDB key at the bottom of the file
4. If the webui is needed, change the flag from False to True
## Create the database tables for ARTEMiS
> python dbutils.py create
## Firewall Adjustements
Make sure the following ports are open both on your router and local Windows firewall in case you want to use this for public use (NOT recommended):
> Port 80 (TCP), 443 (TCP), 8443 (TCP), 22345 (TCP), 8090 (TCP) **webui, 8444 (TCP) **mucha, 9000 (TCP)
## Running the ARTEMiS instance
> python index.py
# Troubleshooting
## Game does not connect to ARTEMiS Allnet server
1. Double-check your core.yaml, the listen_address is most likely either not binded to the proper IP or the port is not opened
## Game does not connect to Title Server
1. Verify that your core.yaml is setup properly for both the server listen_address and title hostname
2. Boot your game and verify that an AllNet response does show and if it does, attempt to open the URI that is shown under a browser such as Edge, Chrome & Firefox.
3. If a page is shown, the server is working properly and if it doesn't, double check your port forwarding and also that you have entered the proper local IP under the Title hostname in core.yaml.
## Unhandled command under AimeDB
1. Double check your AimeDB key under core.yaml, it is incorrect.
## AttributeError: module 'collections' has no attribute 'Hashable'
1. This means the pyYAML module is obsolete, simply rerun pip with the -U (force update) flag, as shown below.
- Change your work path to the artemis-master (or artemis-develop) folder using 'cd' and run the following commands:
```
pip install -r requirements.txt -U
```

View File

@ -2,3 +2,6 @@ server:
enable: True
loglevel: "info"
mods:
unlock_all_modules: True
unlock_all_items: True

View File

@ -18,7 +18,7 @@ server {
}
}
# SSL titles
# SSL titles, comment out if you don't plan on accepting SSL titles
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
@ -57,4 +57,99 @@ server {
location / {
proxy_pass http://localhost:8444/;
}
}
# Pokken, comment this out if you don't plan on serving pokken.
server {
listen 443 ssl;
server_name pokken.hostname.here;
ssl_certificate /path/to/cert/pokken.pem;
ssl_certificate_key /path/to/cert/pokken.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers "ALL:@SECLEVEL=1";
ssl_prefer_server_ciphers off;
location / {
proxy_pass http://localhost:8080/;
}
}
# CXB, comment this out if you don't plan on serving crossbeats.
server {
listen 443 ssl;
server_name cxb.hostname.here;
ssl_certificate /path/to/cert/cxb.pem;
ssl_certificate_key /path/to/cert/cxb.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers "ALL:@SECLEVEL=1";
ssl_prefer_server_ciphers off;
location / {
proxy_pass http://localhost:8080/SDBT/104/;
}
}
# CXB, comment this out if you don't plan on serving crossbeats.
server {
listen 443 ssl;
server_name cxb.hostname.here;
ssl_certificate /path/to/cert/cxb.pem;
ssl_certificate_key /path/to/cert/cxb.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers "ALL:@SECLEVEL=1";
ssl_prefer_server_ciphers off;
location / {
proxy_pass http://localhost:8080/SDBT/104/;
}
}
# Frontend, set to redirect to HTTPS. Comment out if you don't intend to use the frontend
server {
listen 80;
server_name frontend.hostname.here
location / {
return 301 https://$host$request_uri;
# If you don't want https redirection, comment the line above and uncomment the line below
# proxy_pass http://localhost:8090/;
}
}
# Frontend HTTPS. Comment out if you on't intend to use the frontend
server {
listen 443 ssl;
ssl_certificate /path/to/cert/frontend.pem;
ssl_certificate_key /path/to/cert/frontend.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m; # about 40000 sessions
ssl_session_tickets off;
# intermediate configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# HSTS (ngx_http_headers_module is required) (63072000 seconds)
add_header Strict-Transport-Security "max-age=63072000" always;
location / {
proxy_pass http://localhost:8090/;
}
}

View File

@ -1,8 +1,6 @@
server:
enable: True
loglevel: "info"
hostname: "localhost"
ssl_enable: False
port: 9000
port_matching: 9001
ssl_cert: cert/pokken.crt

View File

@ -1,6 +1,7 @@
server:
enable: True
loglevel: "info"
prefecture_name: "Hokkaido"
mods:
always_vip: True

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python3
import argparse
import logging, coloredlogs
from logging.handlers import TimedRotatingFileHandler
from typing import Dict
import yaml
from os import path, mkdir, access, W_OK
@ -17,11 +19,13 @@ class HttpDispatcher(resource.Resource):
self.isLeaf = True
self.map_get = Mapper()
self.map_post = Mapper()
self.logger = logging.getLogger("core")
self.allnet = AllnetServlet(cfg, config_dir)
self.title = TitleServlet(cfg, config_dir)
self.mucha = MuchaServlet(cfg)
self.map_post.connect('allnet_ping', '/naomitest.html', controller="allnet", action='handle_naomitest', conditions=dict(method=['GET']))
self.map_post.connect('allnet_poweron', '/sys/servlet/PowerOn', controller="allnet", action='handle_poweron', conditions=dict(method=['POST']))
self.map_post.connect('allnet_downloadorder', '/sys/servlet/DownloadOrder', controller="allnet", action='handle_dlorder', conditions=dict(method=['POST']))
self.map_post.connect('allnet_billing', '/request', controller="allnet", action='handle_billing_request', conditions=dict(method=['POST']))
@ -29,31 +33,39 @@ class HttpDispatcher(resource.Resource):
self.map_post.connect('mucha_boardauth', '/mucha/boardauth.do', controller="mucha", action='handle_boardauth', conditions=dict(method=['POST']))
self.map_post.connect('mucha_updatacheck', '/mucha/updatacheck.do', controller="mucha", action='handle_updatacheck', conditions=dict(method=['POST']))
self.map_get.connect("title_get", "/{game}/{version}/{endpoint:.*?}", controller="title", action="render_GET", requirements=dict(game=R"S..."))
self.map_post.connect("title_post", "/{game}/{version}/{endpoint:.*?}", controller="title", action="render_POST", requirements=dict(game=R"S..."))
self.map_get.connect("title_get", "/{game}/{version}/{endpoint:.*?}", controller="title", action="render_GET", conditions=dict(method=['GET']), requirements=dict(game=R"S..."))
self.map_post.connect("title_post", "/{game}/{version}/{endpoint:.*?}", controller="title", action="render_POST", conditions=dict(method=['POST']), requirements=dict(game=R"S..."))
def render_POST(self, request: Request) -> bytes:
def render_GET(self, request: Request) -> bytes:
test = self.map_get.match(request.uri.decode())
if test is None:
return b""
self.logger.debug(f"Unknown GET endpoint {request.uri.decode()} from {request.getClientAddress().host} to port {request.getHost().port}")
request.setResponseCode(404)
return b"Endpoint not found."
return self.dispatch(test, request)
def render_POST(self, request: Request) -> bytes:
test = self.map_post.match(request.uri.decode())
if test is None:
return b""
self.logger.debug(f"Unknown POST endpoint {request.uri.decode()} from {request.getClientAddress().host} to port {request.getHost().port}")
request.setResponseCode(404)
return b"Endpoint not found."
return self.dispatch(test, request)
def dispatch(self, matcher: Dict, request: Request) -> bytes:
controller = getattr(self, matcher["controller"], None)
if controller is None:
return b""
self.logger.error(f"Controller {matcher['controller']} not found via endpoint {request.uri.decode()}")
request.setResponseCode(404)
return b"Endpoint not found."
handler = getattr(controller, matcher["action"], None)
if handler is None:
return b""
self.logger.error(f"Action {matcher['action']} not found in controller {matcher['controller']} via endpoint {request.uri.decode()}")
request.setResponseCode(404)
return b"Endpoint not found."
url_vars = matcher
url_vars.pop("controller")
@ -79,22 +91,40 @@ if __name__ == "__main__":
cfg: CoreConfig = CoreConfig()
cfg.update(yaml.safe_load(open(f"{args.config}/core.yaml")))
logger = logging.getLogger("core")
log_fmt_str = "[%(asctime)s] Core | %(levelname)s | %(message)s"
log_fmt = logging.Formatter(log_fmt_str)
fileHandler = TimedRotatingFileHandler("{0}/{1}.log".format(cfg.server.log_dir, "core"), when="d", backupCount=10)
fileHandler.setFormatter(log_fmt)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(log_fmt)
logger.addHandler(fileHandler)
logger.addHandler(consoleHandler)
log_lv = logging.DEBUG if cfg.server.is_develop else logging.INFO
logger.setLevel(log_lv)
coloredlogs.install(level=log_lv, logger=logger, fmt=log_fmt_str)
if not path.exists(cfg.server.log_dir):
mkdir(cfg.server.log_dir)
if not access(cfg.server.log_dir, W_OK):
print(f"Log directory {cfg.server.log_dir} NOT writable, please check permissions")
logger.error(f"Log directory {cfg.server.log_dir} NOT writable, please check permissions")
exit(1)
if not cfg.aimedb.key:
print("!!AIMEDB KEY BLANK, SET KEY IN CORE.YAML!!")
logger.error("!!AIMEDB KEY BLANK, SET KEY IN CORE.YAML!!")
exit(1)
print(f"ARTEMiS starting in {'develop' if cfg.server.is_develop else 'production'} mode")
logger.info(f"ARTEMiS starting in {'develop' if cfg.server.is_develop else 'production'} mode")
allnet_server_str = f"tcp:{cfg.allnet.port}:interface={cfg.server.listen_address}"
title_server_str = f"tcp:{cfg.title.port}:interface={cfg.server.listen_address}"
adb_server_str = f"tcp:{cfg.aimedb.port}:interface={cfg.server.listen_address}"
frontend_server_str = f"tcp:{cfg.frontend.port}:interface={cfg.server.listen_address}"
billing_server_str = f"tcp:{cfg.billing.port}:interface={cfg.server.listen_address}"
if cfg.server.is_develop:
@ -106,6 +136,9 @@ if __name__ == "__main__":
endpoints.serverFromString(reactor, allnet_server_str).listen(server.Site(dispatcher))
endpoints.serverFromString(reactor, adb_server_str).listen(AimedbFactory(cfg))
if cfg.frontend.enable:
endpoints.serverFromString(reactor, frontend_server_str).listen(server.Site(FrontendServlet(cfg, args.config)))
if cfg.billing.port > 0:
endpoints.serverFromString(reactor, billing_server_str).listen(server.Site(dispatcher))

View File

@ -85,7 +85,7 @@ if __name__ == "__main__":
log_fmt = logging.Formatter(log_fmt_str)
logger = logging.getLogger("reader")
fileHandler = TimedRotatingFileHandler("{0}/{1}.log".format(config.server.logs, "reader"), when="d", backupCount=10)
fileHandler = TimedRotatingFileHandler("{0}/{1}.log".format(config.server.log_dir, "reader"), when="d", backupCount=10)
fileHandler.setFormatter(log_fmt)
consoleHandler = logging.StreamHandler()
@ -94,8 +94,9 @@ if __name__ == "__main__":
logger.addHandler(fileHandler)
logger.addHandler(consoleHandler)
logger.setLevel(logging.INFO)
coloredlogs.install(level=logging.INFO, logger=logger, fmt=log_fmt_str)
log_lv = logging.DEBUG if config.server.is_develop else logging.INFO
logger.setLevel(log_lv)
coloredlogs.install(level=log_lv, logger=logger, fmt=log_fmt_str)
if args.series is None or args.version is None:
logger.error("Game or version not specified")

View File

@ -13,4 +13,6 @@ coloredlogs
pylibmc; platform_system != "Windows"
wacky
Routes
bcrypt
jinja2
protobuf

View File

@ -47,10 +47,10 @@ class ChuniNew(ChuniBase):
"matchErrorLimit": 9999,
"romVersion": "2.00.00",
"dataVersion": "2.00.00",
"matchingUri": f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
"matchingUriX": f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
"udpHolePunchUri": f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
"reflectorUri": f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
"matchingUri": f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
"matchingUriX": f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
"udpHolePunchUri": f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
"reflectorUri": f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/200/ChuniServlet/",
},
"isDumpUpload": "false",
"isAou": "false",

View File

@ -16,8 +16,8 @@ class ChuniNewPlus(ChuniNew):
ret = super().handle_get_game_setting_api_request(data)
ret["gameSetting"]["romVersion"] = "2.05.00"
ret["gameSetting"]["dataVersion"] = "2.05.00"
ret["gameSetting"]["matchingUri"] = f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
ret["gameSetting"]["matchingUriX"] = f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
ret["gameSetting"]["udpHolePunchUri"] = f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
ret["gameSetting"]["reflectorUri"] = f"http://{self.core_cfg.server.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
ret["gameSetting"]["matchingUri"] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
ret["gameSetting"]["matchingUriX"] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
ret["gameSetting"]["udpHolePunchUri"] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
ret["gameSetting"]["reflectorUri"] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/"
return ret

View File

@ -82,7 +82,7 @@ class ChuniReader(BaseReader):
for MusicFumenData in fumens.findall('MusicFumenData'):
fumen_path = MusicFumenData.find('file').find("path")
if fumen_path.text is not None:
if fumen_path is not None:
chart_id = MusicFumenData.find('type').find('id').text
if chart_id == "4":
level = float(xml_root.find("starDifType").text)

View File

@ -29,6 +29,9 @@ course = Table(
Column("param3", Integer),
Column("param4", Integer),
Column("isClear", Boolean),
Column("theoryCount", Integer),
Column("orderId", Integer),
Column("playerRating", Integer),
UniqueConstraint("user", "courseId", name="chuni_score_course_uk"),
mysql_charset='utf8mb4'
)

View File

@ -34,7 +34,7 @@ music = Table(
Column("level", Float),
Column("genre", String(255)),
Column("jacketPath", String(255)),
Column("worldsEndTag", String(20)),
Column("worldsEndTag", String(7)),
UniqueConstraint("version", "songId", "chartId", name="chuni_static_music_uk"),
mysql_charset='utf8mb4'
)

View File

@ -127,32 +127,57 @@ class DivaBase():
def handle_shop_catalog_request(self, data: Dict) -> Dict:
catalog = ""
shopList = self.data.static.get_enabled_shop(self.version)
shopList = self.data.static.get_enabled_shops(self.version)
if not shopList:
with open(r"titles/diva/data/ShopCatalog.dat", encoding="utf-8") as shop:
lines = shop.readlines()
for line in lines:
line = urllib.parse.quote(line) + ","
catalog += f"{urllib.parse.quote(line)}"
catalog = catalog.replace("+", "%20")
response = ""
response += f"&shp_ctlg_lut={self.time_lut}"
response += f"&shp_ctlg={catalog[:-3]}"
else:
for shop in shopList:
line = str(shop["shopId"]) + "," + str(shop['unknown_0']) + "," + shop['name'] + "," + str(shop['points']) + "," + shop['start_date'] + "," + shop['end_date'] + "," + str(shop["type"])
line = urllib.parse.quote(line) + ","
catalog += f"{urllib.parse.quote(line)}"
catalog = catalog.replace("+", "%20")
response = ""
response += f"&shp_ctlg_lut={self.time_lut}"
response += f"&shp_ctlg={catalog[:-3]}"
catalog = catalog.replace("+", "%20")
response = f"&shp_ctlg_lut={self.time_lut}"
response += f"&shp_ctlg={catalog[:-3]}"
return ( response )
def handle_buy_module_request(self, data: Dict) -> Dict:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
module = self.data.static.get_enabled_shop(self.version, int(data["mdl_id"]))
# make sure module is available to purchase
if not module:
return f"&shp_rslt=0&vcld_pts={profile['vcld_pts']}"
# make sure player has enough vocaloid points to buy module
if profile["vcld_pts"] < int(data["mdl_price"]):
return f"&shp_rslt=0&vcld_pts={profile['vcld_pts']}"
new_vcld_pts = profile["vcld_pts"] - int(data["mdl_price"])
self.data.profile.update_profile(
profile["user"],
vcld_pts=new_vcld_pts
)
self.data.module.put_module(data["pd_id"], self.version, data["mdl_id"])
# generate the mdl_have string
mdl_have = self.data.module.get_modules_have_string(data["pd_id"], self.version)
response = "&shp_rslt=1"
response += f"&mdl_id={data['mdl_id']}"
response += f"&mdl_have={mdl_have}"
response += f"&vcld_pts={new_vcld_pts}"
return response
def handle_cstmz_itm_ctlg_request(self, data: Dict) -> Dict:
catalog = ""
@ -163,25 +188,52 @@ class DivaBase():
for line in lines:
line = urllib.parse.quote(line) + ","
catalog += f"{urllib.parse.quote(line)}"
catalog = catalog.replace("+", "%20")
response = ""
response += f"&cstmz_itm_ctlg_lut={self.time_lut}"
response += f"&cstmz_itm_ctlg={catalog[:-3]}"
else:
for item in itemList:
line = str(item["itemId"]) + "," + str(item['unknown_0']) + "," + item['name'] + "," + str(item['points']) + "," + item['start_date'] + "," + item['end_date'] + "," + str(item["type"])
line = urllib.parse.quote(line) + ","
catalog += f"{urllib.parse.quote(line)}"
catalog = catalog.replace("+", "%20")
catalog = catalog.replace("+", "%20")
response = ""
response += f"&cstmz_itm_ctlg_lut={self.time_lut}"
response += f"&cstmz_itm_ctlg={catalog[:-3]}"
response = f"&cstmz_itm_ctlg_lut={self.time_lut}"
response += f"&cstmz_itm_ctlg={catalog[:-3]}"
return ( response )
def handle_buy_cstmz_itm_request(self, data: Dict) -> Dict:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
item = self.data.static.get_enabled_item(self.version, int(data["cstmz_itm_id"]))
# make sure module is available to purchase
if not item:
return f"&shp_rslt=0&vcld_pts={profile['vcld_pts']}"
# make sure player has enough vocaloid points to buy the customize item
if profile["vcld_pts"] < int(data["cstmz_itm_price"]):
return f"&shp_rslt=0&vcld_pts={profile['vcld_pts']}"
new_vcld_pts = profile["vcld_pts"] - int(data["cstmz_itm_price"])
# save new Vocaloid Points balance
self.data.profile.update_profile(
profile["user"],
vcld_pts=new_vcld_pts
)
self.data.customize.put_customize_item(data["pd_id"], self.version, data["cstmz_itm_id"])
# generate the cstmz_itm_have string
cstmz_itm_have = self.data.customize.get_customize_items_have_string(data["pd_id"], self.version)
response = "&shp_rslt=1"
response += f"&cstmz_itm_id={data['cstmz_itm_id']}"
response += f"&cstmz_itm_have={cstmz_itm_have}"
response += f"&vcld_pts={new_vcld_pts}"
return response
def handle_festa_info_request(self, data: Dict) -> Dict:
encoded = "&"
params = {
@ -191,7 +243,7 @@ class DivaBase():
'fi_difficulty': '-1,-1',
'fi_pv_id_lst': 'ALL,ALL',
'fi_attr': '7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
'fi_add_vp': '10,0',
'fi_add_vp': '20,0',
'fi_mul_vp': '1,1',
'fi_st': '2022-06-17 17:00:00.0,2014-07-08 18:10:11.0',
'fi_et': '2029-01-01 10:00:00.0,2014-07-08 18:10:11.0',
@ -278,48 +330,68 @@ class DivaBase():
def handle_pstd_item_ng_lst_request(self, data: Dict) -> Dict:
return ( f'' )
def handle_pre_start_request(self, data: Dict) -> Dict:
def handle_pre_start_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["aime_id"], self.version)
profile_shop = self.data.item.get_shop(data["aime_id"], self.version)
if profile is None:
return ( f"&ps_result=-3")
return f"&ps_result=-3"
else:
response = ""
response += "&ps_result=1"
response += f"&pd_id={data['aime_id']}"
response = "&ps_result=1"
response += "&accept_idx=100"
response += "&nblss_ltt_stts=-1"
response += "&nblss_ltt_tckt=-1"
response += "&nblss_ltt_is_opn=-1"
response += f"&vcld_pts={profile['vcld_pts']}"
response += f"&pd_id={data['aime_id']}"
response += f"&player_name={profile['player_name']}"
response += f"&sort_kind={profile['player_name']}"
response += f"&lv_efct_id={profile['lv_efct_id']}"
response += f"&lv_plt_id={profile['lv_plt_id']}"
response += f"&lv_str={profile['lv_str']}"
response += f"&lv_num={profile['lv_num']}"
response += f"&lv_pnt={profile['lv_pnt']}"
response += f"&vcld_pts={profile['vcld_pts']}"
response += f"&skn_eqp={profile['use_pv_skn_eqp']}"
response += f"&btn_se_eqp={profile['use_pv_btn_se_eqp']}"
response += f"&sld_se_eqp={profile['use_pv_sld_se_eqp']}"
response += f"&chn_sld_se_eqp={profile['use_pv_chn_sld_se_eqp']}"
response += f"&sldr_tch_se_eqp={profile['use_pv_sldr_tch_se_eqp']}"
response += f"&passwd_stat={profile['passwd_stat']}"
#Store stuff to add to rework
# Store stuff to add to rework
response += f"&mdl_eqp_tm={self.time_lut}"
mdl_eqp_ary = "-999,-999,-999"
# get the common_modules from the profile shop
if profile_shop:
response += f"&mdl_eqp_ary={profile_shop['mdl_eqp_ary']}"
mdl_eqp_ary = profile_shop["mdl_eqp_ary"]
response += f"&c_itm_eqp_ary=-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999"
response += f"&ms_itm_flg_ary=1,1,1,1,1,1,1,1,1,1,1,1"
response += f"&mdl_eqp_ary={mdl_eqp_ary}"
return ( response )
def handle_registration_request(self, data: Dict) -> Dict: #DONE
return response
def handle_registration_request(self, data: Dict) -> Dict:
self.data.profile.create_profile(self.version, data["aime_id"], data["player_name"])
return ( f"&cd_adm_result=1&pd_id={data['aime_id']}")
return (f"&cd_adm_result=1&pd_id={data['aime_id']}")
def handle_start_request(self, data: Dict) -> Dict:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
profile_shop = self.data.item.get_shop(data["pd_id"], self.version)
if profile is None: return
response = ""
response += f"&pd_id={data['pd_id']}"
if profile is None:
return
mdl_have = "F" * 250
# generate the mdl_have string if "unlock_all_modules" is disabled
if not self.game_config.mods.unlock_all_modules:
mdl_have = self.data.module.get_modules_have_string(data["pd_id"], self.version)
cstmz_itm_have = "F" * 250
# generate the cstmz_itm_have string if "unlock_all_items" is disabled
if not self.game_config.mods.unlock_all_items:
cstmz_itm_have = self.data.customize.get_customize_items_have_string(data["pd_id"], self.version)
response = f"&pd_id={data['pd_id']}"
response += "&start_result=1"
response += "&accept_idx=100"
@ -333,13 +405,15 @@ class DivaBase():
response += f"&lv_pnt={profile['lv_pnt']}"
response += f"&lv_efct_id={profile['lv_efct_id']}"
response += f"&lv_plt_id={profile['lv_plt_id']}"
response += "&mdl_have=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
response += "&cstmz_itm_have=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
response += f"&use_pv_mdl_eqp={profile['use_pv_mdl_eqp']}"
response += f"&use_pv_btn_se_eqp={profile['use_pv_btn_se_eqp']}"
response += f"&use_pv_sld_se_eqp={profile['use_pv_sld_se_eqp']}"
response += f"&use_pv_chn_sld_se_eqp={profile['use_pv_chn_sld_se_eqp']}"
response += f"&use_pv_sldr_tch_se_eqp={profile['use_pv_sldr_tch_se_eqp']}"
response += f"&mdl_have={mdl_have}"
response += f"&cstmz_itm_have={cstmz_itm_have}"
response += f"&use_pv_mdl_eqp={int(profile['use_pv_mdl_eqp'])}"
response += f"&use_mdl_pri={int(profile['use_mdl_pri'])}"
response += f"&use_pv_skn_eqp={int(profile['use_pv_skn_eqp'])}"
response += f"&use_pv_btn_se_eqp={int(profile['use_pv_btn_se_eqp'])}"
response += f"&use_pv_sld_se_eqp={int(profile['use_pv_sld_se_eqp'])}"
response += f"&use_pv_chn_sld_se_eqp={int(profile['use_pv_chn_sld_se_eqp'])}"
response += f"&use_pv_sldr_tch_se_eqp={int(profile['use_pv_sldr_tch_se_eqp'])}"
response += f"&vcld_pts={profile['lv_efct_id']}"
response += f"&nxt_pv_id={profile['nxt_pv_id']}"
response += f"&nxt_dffclty={profile['nxt_dffclty']}"
@ -349,7 +423,7 @@ class DivaBase():
response += f"&dsp_clr_sts={profile['dsp_clr_sts']}"
response += f"&rgo_sts={profile['rgo_sts']}"
#To be fully fixed
# To be fully fixed
if "my_qst_id" not in profile:
response += f"&my_qst_id=-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"
response += f"&my_qst_sts=0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"
@ -361,14 +435,23 @@ class DivaBase():
response += f"&my_qst_et=2022-06-19%2010%3A28%3A52.0,2022-06-19%2010%3A28%3A52.0,2022-06-19%2010%3A28%3A52.0,2100-01-01%2008%3A59%3A59.0,2100-01-01%2008%3A59%3A59.0,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx,xxx"
response += f"&clr_sts=0,0,0,0,0,0,0,0,56,52,35,6,6,3,1,0,0,0,0,0"
#Store stuff to add to rework
# Store stuff to add to rework
response += f"&mdl_eqp_tm={self.time_lut}"
if profile_shop:
response += f"&mdl_eqp_ary={profile_shop['mdl_eqp_ary']}"
mdl_eqp_ary = "-999,-999,-999"
c_itm_eqp_ary = "-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999"
ms_itm_flg_ary = "1,1,1,1,1,1,1,1,1,1,1,1"
response += f"&c_itm_eqp_ary=-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999"
response += f"&ms_itm_flg_ary=1,1,1,1,1,1,1,1,1,1,1,1"
# get the common_modules, customize_items and customize_item_flags
# from the profile shop
if profile_shop:
mdl_eqp_ary = profile_shop["mdl_eqp_ary"]
c_itm_eqp_ary = profile_shop["c_itm_eqp_ary"]
ms_itm_flg_ary = profile_shop["ms_itm_flg_ary"]
response += f"&mdl_eqp_ary={mdl_eqp_ary}"
response += f"&c_itm_eqp_ary={c_itm_eqp_ary}"
response += f"&ms_itm_flg_ary={ms_itm_flg_ary}"
return ( response )
@ -390,22 +473,89 @@ class DivaBase():
return ( response )
def _get_pv_pd_result(self, song: int, pd_db_song: Dict, pd_db_ranking: Dict,
pd_db_customize: Dict, edition: int) -> str:
"""
Helper function to generate the pv_result string for every song, ranking and edition
"""
global_ranking = -1
if pd_db_ranking:
# make sure there are enough max scores to calculate a ranking
if pd_db_ranking["ranking"] != 0:
global_ranking = pd_db_ranking["ranking"]
# pv_no
pv_result = f"{song},"
# edition
pv_result += f"{edition},"
# rslt
pv_result += f"{pd_db_song['clr_kind']}," if pd_db_song else "-1,"
# max_score
pv_result += f"{pd_db_song['score']}," if pd_db_song else "-1,"
# max_atn_pnt
pv_result += f"{pd_db_song['atn_pnt']}," if pd_db_song else "-1,"
# challenge_kind
pv_result += f"{pd_db_song['sort_kind']}," if pd_db_song else "0,"
module_eqp = "-999,-999,-999"
customize_eqp = "-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999"
customize_flag = "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"
# skin, btn_se, sld_se, chsld_se, sldtch_se
pv_settings = "-1,-1,-1,-1,-1"
if pd_db_customize:
module_eqp = pd_db_customize["mdl_eqp_ary"]
customize_eqp = pd_db_customize["c_itm_eqp_ary"]
customize_flag = pd_db_customize["ms_itm_flg_ary"]
pv_settings = (
f"{pd_db_customize['skin']},"
f"{pd_db_customize['btn_se']},"
f"{pd_db_customize['sld_se']},"
f"{pd_db_customize['chsld_se']},"
f"{pd_db_customize['sldtch_se']}"
)
pv_result += f"{module_eqp},"
pv_result += f"{customize_eqp},"
pv_result += f"{customize_flag},"
pv_result += f"{pv_settings},"
# rvl_pd_id, rvl_score, rvl_attn_pnt, -1, -1
pv_result += "-1,-1,-1,-1,-1,"
# countrywide_ranking
pv_result += f"{global_ranking},"
# rgo_purchased
pv_result += "1,1,1,"
# rgo_played
pv_result += "0,0,0"
return pv_result
def handle_get_pv_pd_request(self, data: Dict) -> Dict:
song_id = data["pd_pv_id_lst"].split(",")
pv = ""
for song in song_id:
if int(song) > 0:
pd_db_song = self.data.score.get_best_score(data["pd_id"], int(song), data["difficulty"])
if pd_db_song is not None:
pv += urllib.parse.quote(f"{song},0,{pd_db_song['clr_kind']},{pd_db_song['score']},{pd_db_song['atn_pnt']},{pd_db_song['sort_kind']},-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1337,1,1,1,0,0,0")
else:
#self.logger.debug(f"No score saved for ID: {song}!")
pv += urllib.parse.quote(f"{song},0,-1,-1,-1,0,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,0,0,0")
# the request do not send a edition so just perform a query best score and ranking for each edition.
# 0=ORIGINAL, 1=EXTRA
pd_db_song_0 = self.data.score.get_best_user_score(data["pd_id"], int(song), data["difficulty"], edition=0)
pd_db_song_1 = self.data.score.get_best_user_score(data["pd_id"], int(song), data["difficulty"], edition=1)
#pv_no, edition, rslt, max_score, max_atn_pnt, challenge_kind, module_eqp[-999,-999,-999], customize_eqp[-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999], customize_flag[1,1,1,1,1,1,1,1,1,1,1,1], skin, btn_se, sld_se, chsld_se, sldtch_se, rvl_pd_id, rvl_score, rvl_attn_pnt, countrywide_ranking, rgo_hispeed, rgo_hidden, rgo_sudden, rgo_hispeed_cleared, rgo_hidden_cleared, rgo_sudden_cleared, chain_challenge_num, chain_challenge_max, chain_challenge_open, version
pd_db_ranking_0, pd_db_ranking_1 = None, None
if pd_db_song_0:
pd_db_ranking_0 = self.data.score.get_global_ranking(data["pd_id"], int(song), data["difficulty"], edition=0)
if pd_db_song_1:
pd_db_ranking_1 = self.data.score.get_global_ranking(data["pd_id"], int(song), data["difficulty"], edition=1)
pd_db_customize = self.data.pv_customize.get_pv_customize(data["pd_id"], int(song))
# generate the pv_result string with the ORIGINAL edition and the EXTRA edition appended
pv_result = self._get_pv_pd_result(int(song), pd_db_song_0, pd_db_ranking_0, pd_db_customize, edition=0)
pv_result += "," + self._get_pv_pd_result(int(song), pd_db_song_1, pd_db_ranking_1, pd_db_customize, edition=1)
self.logger.debug(f"pv_result = {pv_result}")
pv += urllib.parse.quote(pv_result)
else:
pv += urllib.parse.quote(f"{song}***")
pv += ","
@ -426,6 +576,7 @@ class DivaBase():
pd_song_list = data["stg_ply_pv_id"].split(",")
pd_song_difficulty = data["stg_difficulty"].split(",")
pd_song_edition = data["stg_edtn"].split(",")
pd_song_max_score = data["stg_score"].split(",")
pd_song_max_atn_pnt = data["stg_atn_pnt"].split(",")
pd_song_ranking = data["stg_clr_kind"].split(",")
@ -439,31 +590,52 @@ class DivaBase():
for index, value in enumerate(pd_song_list):
if "-1" not in pd_song_list[index]:
profile_pd_db_song = self.data.score.get_best_score(data["pd_id"], pd_song_list[index], pd_song_difficulty[index])
profile_pd_db_song = self.data.score.get_best_user_score(data["pd_id"], pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index])
if profile_pd_db_song is None:
self.data.score.put_best_score(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
self.data.score.put_best_score(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
elif int(pd_song_max_score[index]) >= int(profile_pd_db_song["score"]):
self.data.score.put_best_score(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
self.data.score.put_best_score(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
elif int(pd_song_max_score[index]) != int(profile_pd_db_song["score"]):
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
# Profile saving based on registration list
old_level = int(profile['lv_num'])
new_level = (int(data["ttl_vp_add"]) + int(profile["lv_pnt"])) / 12
# Calculate new level
best_scores = self.data.score.get_best_scores(data["pd_id"])
self.data.profile.update_profile(data["pd_id"], int(new_level), int(profile["lv_pnt"]) + int(data["ttl_vp_add"]), int(data["vcld_pts"]), int(data["hp_vol"]), int(data["btn_se_vol"]), int(data["btn_se_vol2"]), int(data["sldr_se_vol2"]), int(data["sort_kind"]), int(data["use_pv_mdl_eqp"]), profile["use_pv_btn_se_eqp"], profile["use_pv_sld_se_eqp"], profile["use_pv_chn_sld_se_eqp"], profile["use_pv_sldr_tch_se_eqp"], int(data["ply_pv_id"]), int(data["nxt_dffclty"]), int(data["nxt_edtn"]), profile["dsp_clr_brdr"], profile["dsp_intrm_rnk"], profile["dsp_clr_sts"], profile["rgo_sts"], profile["lv_efct_id"], profile["lv_plt_id"], data["my_qst_id"], data["my_qst_sts"])
total_atn_pnt = 0
for best_score in best_scores:
total_atn_pnt += best_score["atn_pnt"]
new_level = (total_atn_pnt // 13979) + 1
new_level_pnt = round((total_atn_pnt % 13979) / 13979 * 100)
response = ""
response += "&chllng_kind=-1"
response += f"&lv_num_old={int(old_level)}"
response = "&chllng_kind=-1"
response += f"&lv_num_old={int(profile['lv_num'])}"
response += f"&lv_pnt_old={int(profile['lv_pnt'])}"
response += f"&lv_num={int(profile['lv_num'])}"
# update the profile and commit changes to the db
self.data.profile.update_profile(
profile["user"],
lv_num=new_level,
lv_pnt=new_level_pnt,
vcld_pts=int(data["vcld_pts"]),
hp_vol=int(data["hp_vol"]),
btn_se_vol=int(data["btn_se_vol"]),
sldr_se_vol2=int(data["sldr_se_vol2"]),
sort_kind=int(data["sort_kind"]),
nxt_pv_id=int(data["ply_pv_id"]),
nxt_dffclty=int(data["nxt_dffclty"]),
nxt_edtn=int(data["nxt_edtn"]),
my_qst_id=data["my_qst_id"],
my_qst_sts=data["my_qst_sts"]
)
response += f"&lv_num={new_level}"
response += f"&lv_str={profile['lv_str']}"
response += f"&lv_pnt={int(profile['lv_pnt']) + int(data['ttl_vp_add'])}"
response += f"&lv_pnt={new_level_pnt}"
response += f"&lv_efct_id={int(profile['lv_efct_id'])}"
response += f"&lv_plt_id={int(profile['lv_plt_id'])}"
response += f"&vcld_pts={int(data['vcld_pts'])}"
@ -495,12 +667,84 @@ class DivaBase():
def handle_end_request(self, data: Dict) -> Dict:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
self.data.profile.update_profile(data["pd_id"], profile["lv_num"], profile["lv_pnt"], profile["vcld_pts"], profile["hp_vol"], profile["btn_se_vol"], profile["btn_se_vol2"], profile["sldr_se_vol2"], profile["sort_kind"], profile["use_pv_mdl_eqp"], profile["use_pv_btn_se_eqp"], profile["use_pv_sld_se_eqp"], profile["use_pv_chn_sld_se_eqp"], profile["use_pv_sldr_tch_se_eqp"], profile["nxt_pv_id"], profile["nxt_dffclty"], profile["nxt_edtn"], profile["dsp_clr_brdr"], profile["dsp_intrm_rnk"], profile["dsp_clr_sts"], profile["rgo_sts"], profile["lv_efct_id"], profile["lv_plt_id"], data["my_qst_id"], data["my_qst_sts"])
return ( f'' )
self.data.profile.update_profile(
profile["user"],
my_qst_id=data["my_qst_id"],
my_qst_sts=data["my_qst_sts"]
)
return (f'')
def handle_shop_exit_request(self, data: Dict) -> Dict:
self.data.item.put_shop(data["pd_id"], self.version, data["mdl_eqp_cmn_ary"])
self.data.item.put_shop(data["pd_id"], self.version, data["mdl_eqp_cmn_ary"], data["c_itm_eqp_cmn_ary"], data["ms_itm_flg_cmn_ary"])
if int(data["use_pv_mdl_eqp"]) == 1:
self.data.pv_customize.put_pv_customize(data["pd_id"], self.version, data["ply_pv_id"],
data["mdl_eqp_pv_ary"], data["c_itm_eqp_pv_ary"], data["ms_itm_flg_pv_ary"])
else:
self.data.pv_customize.put_pv_customize(data["pd_id"], self.version, data["ply_pv_id"],
"-1,-1,-1", "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1", "1,1,1,1,1,1,1,1,1,1,1,1")
response = ""
response += "&shp_rslt=1"
response = "&shp_rslt=1"
return ( response )
def handle_card_procedure_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["aime_id"], self.version)
if profile is None:
return "&cd_adm_result=0"
response = "&cd_adm_result=1"
response += "&chg_name_price=100"
response += "&accept_idx=100"
response += f"&pd_id={profile['user']}"
response += f"&player_name={profile['player_name']}"
response += f"&lv_num={profile['lv_num']}"
response += f"&lv_pnt={profile['lv_pnt']}"
response += f"&lv_str={profile['lv_str']}"
response += f"&lv_efct_id={profile['lv_efct_id']}"
response += f"&lv_plt_id={profile['lv_plt_id']}"
response += f"&vcld_pts={profile['vcld_pts']}"
response += f"&passwd_stat={profile['passwd_stat']}"
return response
def handle_change_name_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
# make sure user has enough Vocaloid Points
if profile["vcld_pts"] < int(data["chg_name_price"]):
return "&cd_adm_result=0"
# update the vocaloid points and player name
new_vcld_pts = profile["vcld_pts"] - int(data["chg_name_price"])
self.data.profile.update_profile(
profile["user"],
player_name=data["player_name"],
vcld_pts=new_vcld_pts
)
response = "&cd_adm_result=1"
response += "&accept_idx=100"
response += f"&pd_id={profile['user']}"
response += f"&player_name={data['player_name']}"
return response
def handle_change_passwd_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
# TODO: return correct error number instead of 0
if (data["passwd"] != profile["passwd"]):
return "&cd_adm_result=0"
# set password to true and update the saved password
self.data.profile.update_profile(
profile["user"],
passwd_stat=1,
passwd=data["new_passwd"]
)
response = "&cd_adm_result=1"
response += "&accept_idx=100"
response += f"&pd_id={profile['user']}"
return response

View File

@ -1,17 +1,33 @@
from core.config import CoreConfig
class DivaServerConfig():
def __init__(self, parent_config: "DivaConfig") -> None:
self.__config = parent_config
@property
def enable(self) -> bool:
return CoreConfig.get_config_field(self.__config, 'diva', 'server', 'enable', default=True)
@property
def loglevel(self) -> int:
return CoreConfig.str_to_loglevel(CoreConfig.get_config_field(self.__config, 'diva', 'server', 'loglevel', default="info"))
class DivaModsConfig():
def __init__(self, parent_config: "DivaConfig") -> None:
self.__config = parent_config
@property
def unlock_all_modules(self) -> bool:
return CoreConfig.get_config_field(self.__config, 'diva', 'mods', 'unlock_all_modules', default=True)
@property
def unlock_all_items(self) -> bool:
return CoreConfig.get_config_field(self.__config, 'diva', 'mods', 'unlock_all_items', default=True)
class DivaConfig(dict):
def __init__(self) -> None:
self.server = DivaServerConfig(self)
self.server = DivaServerConfig(self)
self.mods = DivaModsConfig(self)

View File

@ -1,6 +1,7 @@
from core.data import Data
from core.config import CoreConfig
from titles.diva.schema import DivaProfileData, DivaScoreData, DivaItemData, DivaStaticData
from titles.diva.schema import DivaProfileData, DivaScoreData, DivaModuleData, DivaCustomizeItemData, DivaPvCustomizeData, DivaItemData, DivaStaticData
class DivaData(Data):
def __init__(self, cfg: CoreConfig) -> None:
@ -8,5 +9,8 @@ class DivaData(Data):
self.profile = DivaProfileData(self.config, self.session)
self.score = DivaScoreData(self.config, self.session)
self.module = DivaModuleData(self.config, self.session)
self.customize = DivaCustomizeItemData(self.config, self.session)
self.pv_customize = DivaPvCustomizeData(self.config, self.session)
self.item = DivaItemData(self.config, self.session)
self.static = DivaStaticData(self.config, self.session)

View File

@ -1,6 +1,11 @@
from titles.diva.schema.profile import DivaProfileData
from titles.diva.schema.score import DivaScoreData
from titles.diva.schema.module import DivaModuleData
from titles.diva.schema.customize import DivaCustomizeItemData
from titles.diva.schema.pv_customize import DivaPvCustomizeData
from titles.diva.schema.item import DivaItemData
from titles.diva.schema.static import DivaStaticData
__all__ = [DivaProfileData, DivaScoreData, DivaItemData, DivaStaticData]
__all__ = [DivaProfileData, DivaScoreData, DivaModuleData,
DivaCustomizeItemData, DivaPvCustomizeData, DivaItemData,
DivaStaticData]

View File

@ -0,0 +1,63 @@
from typing import Optional, Dict, List
from sqlalchemy import Table, Column, UniqueConstraint, and_
from sqlalchemy.types import Integer
from sqlalchemy.schema import ForeignKey
from sqlalchemy.dialects.mysql import insert
from core.data.schema import BaseData, metadata
customize = Table(
"diva_profile_customize_item",
metadata,
Column("id", Integer, primary_key=True, nullable=False),
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
Column("version", Integer, nullable=False),
Column("item_id", Integer, nullable=False),
UniqueConstraint("user", "version", "item_id", name="diva_profile_customize_item_uk"),
mysql_charset='utf8mb4'
)
class DivaCustomizeItemData(BaseData):
def put_customize_item(self, aime_id: int, version: int, item_id: int) -> None:
sql = insert(customize).values(
version=version,
user=aime_id,
item_id=item_id
)
result = self.execute(sql)
if result is None:
self.logger.error(f"{__name__} Failed to insert diva profile customize item! aime id: {aime_id} item: {item_id}")
return None
return result.lastrowid
def get_customize_items(self, aime_id: int, version: int) -> Optional[List[Dict]]:
"""
Given a game version and an aime id, return all the customize items, not used directly
"""
sql = customize.select(and_(
customize.c.version == version,
customize.c.user == aime_id
))
result = self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_customize_items_have_string(self, aime_id: int, version: int) -> str:
"""
Given a game version and an aime id, return the cstmz_itm_have hex string
required for diva directly
"""
items_list = self.get_customize_items(aime_id, version)
if items_list is None:
items_list = []
item_have = 0
for item in items_list:
item_have |= 1 << item["item_id"]
# convert the int to a 250 digit long hex string
return "{0:0>250}".format(hex(item_have).upper()[2:])

View File

@ -14,20 +14,29 @@ shop = Table(
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
Column("version", Integer, nullable=False),
Column("mdl_eqp_ary", String(32)),
Column("c_itm_eqp_ary", String(59)),
Column("ms_itm_flg_ary", String(59)),
UniqueConstraint("user", "version", name="diva_profile_shop_uk"),
mysql_charset='utf8mb4'
)
class DivaItemData(BaseData):
def put_shop(self, aime_id: int, version: int, mdl_eqp_ary: str) -> None:
class DivaItemData(BaseData):
def put_shop(self, aime_id: int, version: int, mdl_eqp_ary: str,
c_itm_eqp_ary: str, ms_itm_flg_ary: str) -> None:
sql = insert(shop).values(
version=version,
user=aime_id,
mdl_eqp_ary=mdl_eqp_ary
mdl_eqp_ary=mdl_eqp_ary,
c_itm_eqp_ary=c_itm_eqp_ary,
ms_itm_flg_ary=ms_itm_flg_ary
)
conflict = sql.on_duplicate_key_update(
mdl_eqp_ary = sql.inserted.mdl_eqp_ary
mdl_eqp_ary=mdl_eqp_ary,
c_itm_eqp_ary=c_itm_eqp_ary,
ms_itm_flg_ary=ms_itm_flg_ary
)
result = self.execute(conflict)
@ -44,7 +53,8 @@ class DivaItemData(BaseData):
shop.c.version == version,
shop.c.user == aime_id
))
result = self.execute(sql)
if result is None: return None
return result.fetchone()
if result is None:
return None
return result.fetchone()

View File

@ -0,0 +1,63 @@
from typing import Optional, Dict, List
from sqlalchemy import Table, Column, UniqueConstraint, and_
from sqlalchemy.types import Integer
from sqlalchemy.schema import ForeignKey
from sqlalchemy.dialects.mysql import insert
from core.data.schema import BaseData, metadata
module = Table(
"diva_profile_module",
metadata,
Column("id", Integer, primary_key=True, nullable=False),
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
Column("version", Integer, nullable=False),
Column("module_id", Integer, nullable=False),
UniqueConstraint("user", "version", "module_id", name="diva_profile_module_uk"),
mysql_charset='utf8mb4'
)
class DivaModuleData(BaseData):
def put_module(self, aime_id: int, version: int, module_id: int) -> None:
sql = insert(module).values(
version=version,
user=aime_id,
module_id=module_id
)
result = self.execute(sql)
if result is None:
self.logger.error(f"{__name__} Failed to insert diva profile module! aime id: {aime_id} module: {module_id}")
return None
return result.lastrowid
def get_modules(self, aime_id: int, version: int) -> Optional[List[Dict]]:
"""
Given a game version and an aime id, return all the modules, not used directly
"""
sql = module.select(and_(
module.c.version == version,
module.c.user == aime_id
))
result = self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_modules_have_string(self, aime_id: int, version: int) -> str:
"""
Given a game version and an aime id, return the mdl_have hex string
required for diva directly
"""
module_list = self.get_modules(aime_id, version)
if module_list is None:
module_list = []
module_have = 0
for module in module_list:
module_have |= 1 << module["module_id"]
# convert the int to a 250 digit long hex string
return "{0:0>250}".format(hex(module_have).upper()[2:])

View File

@ -11,9 +11,10 @@ profile = Table(
"diva_profile",
metadata,
Column("id", Integer, primary_key=True, nullable=False),
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
Column("user", ForeignKey("aime_user.id", ondelete="cascade",
onupdate="cascade"), nullable=False),
Column("version", Integer, nullable=False),
Column("player_name", String(8), nullable=False),
Column("player_name", String(10), nullable=False),
Column("lv_str", String(24), nullable=False, server_default="Dab on 'em"),
Column("lv_num", Integer, nullable=False, server_default="0"),
Column("lv_pnt", Integer, nullable=False, server_default="0"),
@ -23,11 +24,15 @@ profile = Table(
Column("btn_se_vol2", Integer, nullable=False, server_default="100"),
Column("sldr_se_vol2", Integer, nullable=False, server_default="100"),
Column("sort_kind", Integer, nullable=False, server_default="2"),
Column("use_pv_mdl_eqp", String(8), nullable=False, server_default="true"),
Column("use_pv_btn_se_eqp", String(8), nullable=False, server_default="true"),
Column("use_pv_sld_se_eqp", String(8), nullable=False, server_default="false"),
Column("use_pv_chn_sld_se_eqp", String(8), nullable=False, server_default="false"),
Column("use_pv_sldr_tch_se_eqp", String(8), nullable=False, server_default="false"),
Column("use_pv_mdl_eqp", Boolean, nullable=False, server_default="1"),
Column("use_mdl_pri", Boolean, nullable=False, server_default="0"),
Column("use_pv_skn_eqp", Boolean, nullable=False, server_default="0"),
Column("use_pv_btn_se_eqp", Boolean, nullable=False, server_default="1"),
Column("use_pv_sld_se_eqp", Boolean, nullable=False, server_default="0"),
Column("use_pv_chn_sld_se_eqp", Boolean,
nullable=False, server_default="0"),
Column("use_pv_sldr_tch_se_eqp", Boolean,
nullable=False, server_default="0"),
Column("nxt_pv_id", Integer, nullable=False, server_default="708"),
Column("nxt_dffclty", Integer, nullable=False, server_default="2"),
Column("nxt_edtn", Integer, nullable=False, server_default="0"),
@ -37,14 +42,20 @@ profile = Table(
Column("rgo_sts", Integer, nullable=False, server_default="1"),
Column("lv_efct_id", Integer, nullable=False, server_default="0"),
Column("lv_plt_id", Integer, nullable=False, server_default="1"),
Column("my_qst_id", String(128), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
Column("my_qst_sts", String(128), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
Column("passwd_stat", Integer, nullable=False, server_default="0"),
Column("passwd", String(12), nullable=False, server_default="**********"),
Column("my_qst_id", String(
128), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
Column("my_qst_sts", String(
128), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
UniqueConstraint("user", "version", name="diva_profile_uk"),
mysql_charset='utf8mb4'
)
class DivaProfileData(BaseData):
def create_profile(self, version: int, aime_id: int, player_name: str) -> Optional[int]:
def create_profile(self, version: int, aime_id: int,
player_name: str) -> Optional[int]:
"""
Given a game version, aime id, and player_name, create a profile and return it's ID
"""
@ -55,48 +66,27 @@ class DivaProfileData(BaseData):
)
conflict = sql.on_duplicate_key_update(
player_name = sql.inserted.player_name
player_name=sql.inserted.player_name
)
result = self.execute(conflict)
if result is None:
self.logger.error(f"{__name__} Failed to insert diva profile! aime id: {aime_id} username: {player_name}")
self.logger.error(
f"{__name__} Failed to insert diva profile! aime id: {aime_id} username: {player_name}")
return None
return result.lastrowid
def update_profile(self, profile_id: int, lv_num: int, lv_pnt: int, vcld_pts: int, hp_vol: int, btn_se_vol: int, btn_se_vol2: int, sldr_se_vol2: int, sort_kind: int, use_pv_mdl_eqp: str, use_pv_btn_se_eqp: str, use_pv_sld_se_eqp: str, use_pv_chn_sld_se_eqp: str, use_pv_sldr_tch_se_eqp: str, nxt_pv_id: int, nxt_dffclty: int, nxt_edtn: int, dsp_clr_brdr: int, dsp_intrm_rnk: int, dsp_clr_sts: int, rgo_sts: int, lv_efct_id: int, lv_plt_id: int, my_qst_id: str, my_qst_sts: str) -> None:
sql = profile.update(profile.c.user == profile_id).values(
lv_num = lv_num,
lv_pnt = lv_pnt,
vcld_pts = vcld_pts,
hp_vol = hp_vol,
btn_se_vol = btn_se_vol,
btn_se_vol2 = btn_se_vol2,
sldr_se_vol2 = sldr_se_vol2,
sort_kind = sort_kind,
use_pv_mdl_eqp = use_pv_mdl_eqp,
use_pv_btn_se_eqp = use_pv_btn_se_eqp,
use_pv_sld_se_eqp = use_pv_sld_se_eqp,
use_pv_chn_sld_se_eqp = use_pv_chn_sld_se_eqp,
use_pv_sldr_tch_se_eqp = use_pv_sldr_tch_se_eqp,
nxt_pv_id = nxt_pv_id,
nxt_dffclty = nxt_dffclty,
nxt_edtn = nxt_edtn,
dsp_clr_brdr = dsp_clr_brdr,
dsp_intrm_rnk = dsp_intrm_rnk,
dsp_clr_sts = dsp_clr_sts,
rgo_sts = rgo_sts,
lv_efct_id = lv_efct_id,
lv_plt_id = lv_plt_id,
my_qst_id = my_qst_id,
my_qst_sts = my_qst_sts
)
def update_profile(self, aime_id: int, **profile_args) -> None:
"""
Given an aime_id update the profile corresponding to the arguments
which are the diva_profile Columns
"""
sql = profile.update(profile.c.user == aime_id).values(**profile_args)
result = self.execute(sql)
if result is None:
self.logger.error(f"update_profile: failed to update profile! profile: {profile_id}")
if result is None:
self.logger.error(
f"update_profile: failed to update profile! profile: {aime_id}")
return None
def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]:
@ -104,10 +94,11 @@ class DivaProfileData(BaseData):
Given a game version and either a profile or aime id, return the profile
"""
sql = profile.select(and_(
profile.c.version == version,
profile.c.user == aime_id
))
profile.c.version == version,
profile.c.user == aime_id
))
result = self.execute(sql)
if result is None: return None
if result is None:
return None
return result.fetchone()

View File

@ -0,0 +1,69 @@
from typing import Optional, Dict, List
from sqlalchemy import Table, Column, UniqueConstraint, and_
from sqlalchemy.types import Integer, String
from sqlalchemy.schema import ForeignKey
from sqlalchemy.dialects.mysql import insert
from core.data.schema import BaseData, metadata
pv_customize = Table(
"diva_profile_pv_customize",
metadata,
Column("id", Integer, primary_key=True, nullable=False),
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
Column("version", Integer, nullable=False),
Column("pv_id", Integer, nullable=False),
Column("mdl_eqp_ary", String(14), server_default="-999,-999,-999"),
Column("c_itm_eqp_ary", String(59), server_default="-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999"),
Column("ms_itm_flg_ary", String(59), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
Column("skin", Integer, server_default="-1"),
Column("btn_se", Integer, server_default="-1"),
Column("sld_se", Integer, server_default="-1"),
Column("chsld_se", Integer, server_default="-1"),
Column("sldtch_se", Integer, server_default="-1"),
UniqueConstraint("user", "version", "pv_id", name="diva_profile_pv_customize_uk"),
mysql_charset='utf8mb4'
)
class DivaPvCustomizeData(BaseData):
def put_pv_customize(self, aime_id: int, version: int, pv_id: int,
mdl_eqp_ary: str, c_itm_eqp_ary: str,
ms_itm_flg_ary: str) -> Optional[int]:
sql = insert(pv_customize).values(
version=version,
user=aime_id,
pv_id=pv_id,
mdl_eqp_ary=mdl_eqp_ary,
c_itm_eqp_ary=c_itm_eqp_ary,
ms_itm_flg_ary=ms_itm_flg_ary,
)
conflict = sql.on_duplicate_key_update(
pv_id=pv_id,
mdl_eqp_ary=mdl_eqp_ary,
c_itm_eqp_ary=c_itm_eqp_ary,
ms_itm_flg_ary=ms_itm_flg_ary,
)
result = self.execute(conflict)
if result is None:
self.logger.error(f"{__name__} Failed to insert diva pv customize! aime id: {aime_id}")
return None
return result.lastrowid
def get_pv_customize(self, aime_id: int,
pv_id: int) -> Optional[List[Dict]]:
"""
Given either a profile or aime id, return a Pv Customize row
"""
sql = pv_customize.select(and_(
pv_customize.c.user == aime_id,
pv_customize.c.pv_id == pv_id
))
result = self.execute(sql)
if result is None:
return None
return result.fetchone()

View File

@ -1,7 +1,7 @@
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
from sqlalchemy.types import Integer, String, TIMESTAMP, JSON, Boolean
from sqlalchemy.schema import ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.sql import func, select
from sqlalchemy.dialects.mysql import insert
from typing import Optional, List, Dict, Any
@ -16,6 +16,7 @@ score = Table(
Column("version", Integer),
Column("pv_id", Integer),
Column("difficulty", Integer),
Column("edition", Integer),
Column("score", Integer),
Column("atn_pnt", Integer),
Column("clr_kind", Integer),
@ -26,7 +27,7 @@ score = Table(
Column("sad", Integer),
Column("worst", Integer),
Column("max_combo", Integer),
UniqueConstraint("user", "pv_id", "difficulty", name="diva_score_uk"),
UniqueConstraint("user", "pv_id", "difficulty", "edition", name="diva_score_uk"),
mysql_charset='utf8mb4'
)
@ -38,6 +39,7 @@ playlog = Table(
Column("version", Integer),
Column("pv_id", Integer),
Column("difficulty", Integer),
Column("edition", Integer),
Column("score", Integer),
Column("atn_pnt", Integer),
Column("clr_kind", Integer),
@ -52,90 +54,144 @@ playlog = Table(
mysql_charset='utf8mb4'
)
class DivaScoreData(BaseData):
def put_best_score(self, user_id: int, game_version: int, song_id: int, difficulty: int, song_score: int, atn_pnt: int,
clr_kind: int, sort_kind:int, cool: int, fine: int, safe: int, sad: int, worst: int, max_combo: int) -> Optional[int]:
def put_best_score(self, user_id: int, game_version: int, song_id: int,
difficulty: int, edition: int, song_score: int,
atn_pnt: int, clr_kind: int, sort_kind: int,
cool: int, fine: int, safe: int, sad: int,
worst: int, max_combo: int) -> Optional[int]:
"""
Update the user's best score for a chart
"""
sql = insert(score).values(
user=user_id,
version=game_version,
pv_id = song_id,
pv_id=song_id,
difficulty=difficulty,
edition=edition,
score=song_score,
atn_pnt = atn_pnt,
clr_kind = clr_kind,
sort_kind = sort_kind,
cool = cool,
fine = fine,
safe = safe,
sad = sad,
worst = worst,
max_combo = max_combo,
atn_pnt=atn_pnt,
clr_kind=clr_kind,
sort_kind=sort_kind,
cool=cool,
fine=fine,
safe=safe,
sad=sad,
worst=worst,
max_combo=max_combo,
)
conflict = sql.on_duplicate_key_update(
score=song_score,
atn_pnt = atn_pnt,
clr_kind = clr_kind,
sort_kind = sort_kind,
cool = cool,
fine = fine,
safe = safe,
sad = sad,
worst = worst,
max_combo = max_combo,
atn_pnt=atn_pnt,
clr_kind=clr_kind,
sort_kind=sort_kind,
cool=cool,
fine=fine,
safe=safe,
sad=sad,
worst=worst,
max_combo=max_combo,
)
result = self.execute(conflict)
if result is None:
self.logger.error(f"{__name__} failed to insert best score! profile: {user_id}, song: {song_id}")
self.logger.error(
f"{__name__} failed to insert best score! profile: {user_id}, song: {song_id}")
return None
return result.lastrowid
def put_playlog(self, user_id: int, game_version: int, song_id: int, difficulty: int, song_score: int, atn_pnt: int,
clr_kind: int, sort_kind:int, cool: int, fine: int, safe: int, sad: int, worst: int, max_combo: int) -> Optional[int]:
def put_playlog(self, user_id: int, game_version: int, song_id: int,
difficulty: int, edition: int, song_score: int,
atn_pnt: int, clr_kind: int, sort_kind: int,
cool: int, fine: int, safe: int, sad: int,
worst: int, max_combo: int) -> Optional[int]:
"""
Add an entry to the user's play log
"""
sql = playlog.insert().values(
user=user_id,
version=game_version,
pv_id = song_id,
pv_id=song_id,
difficulty=difficulty,
edition=edition,
score=song_score,
atn_pnt = atn_pnt,
clr_kind = clr_kind,
sort_kind = sort_kind,
cool = cool,
fine = fine,
safe = safe,
sad = sad,
worst = worst,
max_combo = max_combo
atn_pnt=atn_pnt,
clr_kind=clr_kind,
sort_kind=sort_kind,
cool=cool,
fine=fine,
safe=safe,
sad=sad,
worst=worst,
max_combo=max_combo
)
result = self.execute(sql)
if result is None:
self.logger.error(f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_id}, chart: {difficulty}")
self.logger.error(
f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_id}, chart: {difficulty}")
return None
return result.lastrowid
def get_best_score(self, user_id: int, pv_id: int, chart_id: int) -> Optional[Dict]:
def get_best_user_score(self, user_id: int, pv_id: int, difficulty: int,
edition: int) -> Optional[Dict]:
sql = score.select(
and_(score.c.user == user_id, score.c.pv_id == pv_id, score.c.difficulty == chart_id)
and_(score.c.user == user_id,
score.c.pv_id == pv_id,
score.c.difficulty == difficulty,
score.c.edition == edition)
)
result = self.execute(sql)
if result is None: return None
if result is None:
return None
return result.fetchone()
def get_best_scores(self, user_id: int) -> Optional[Dict]:
def get_top3_scores(self, pv_id: int, difficulty: int,
edition: int) -> Optional[List[Dict]]:
sql = score.select(
and_(score.c.pv_id == pv_id,
score.c.difficulty == difficulty,
score.c.edition == edition)
).order_by(score.c.score.desc()).limit(3)
result = self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_global_ranking(self, user_id: int, pv_id: int, difficulty: int,
edition: int) -> Optional[List]:
# get the subquery max score of a user with pv_id, difficulty and
# edition
sql_sub = select([score.c.score]).filter(
score.c.user == user_id,
score.c.pv_id == pv_id,
score.c.difficulty == difficulty,
score.c.edition == edition
).scalar_subquery()
# Perform the main query, also rename the resulting column to ranking
sql = select(func.count(score.c.id).label("ranking")).filter(
score.c.score >= sql_sub,
score.c.pv_id == pv_id,
score.c.difficulty == difficulty,
score.c.edition == edition
)
result = self.execute(sql)
if result is None:
return None
return result.fetchone()
def get_best_scores(self, user_id: int) -> Optional[List]:
sql = score.select(score.c.user == user_id)
result = self.execute(sql)
if result is None: return None
if result is None:
return None
return result.fetchall()

View File

@ -132,11 +132,25 @@ class DivaStaticData(BaseData):
if result is None: return None
return result.lastrowid
def get_enabled_shop(self, version: int) -> Optional[List[Row]]:
sql = select(shop).where(and_(shop.c.version == version, shop.c.enabled == True))
def get_enabled_shop(self, version: int, shopId: int) -> Optional[Row]:
sql = select(shop).where(and_(
shop.c.version == version,
shop.c.shopId == shopId,
shop.c.enabled == True))
result = self.execute(sql)
if result is None: return None
if result is None:
return None
return result.fetchone()
def get_enabled_shops(self, version: int) -> Optional[List[Row]]:
sql = select(shop).where(and_(
shop.c.version == version,
shop.c.enabled == True))
result = self.execute(sql)
if result is None:
return None
return result.fetchall()
def put_items(self, version: int, itemId: int, name: str, type: int, points: int, unknown_0: int, start_date: str, end_date: str) -> Optional[int]:
@ -158,12 +172,26 @@ class DivaStaticData(BaseData):
result = self.execute(conflict)
if result is None: return None
return result.lastrowid
def get_enabled_items(self, version: int) -> Optional[List[Row]]:
sql = select(items).where(and_(items.c.version == version, items.c.enabled == True))
def get_enabled_item(self, version: int, itemId: int) -> Optional[Row]:
sql = select(items).where(and_(
items.c.version == version,
items.c.itemId == itemId,
items.c.enabled == True))
result = self.execute(sql)
if result is None: return None
if result is None:
return None
return result.fetchone()
def get_enabled_items(self, version: int) -> Optional[List[Row]]:
sql = select(items).where(and_(
items.c.version == version,
items.c.enabled == True))
result = self.execute(sql)
if result is None:
return None
return result.fetchall()
def put_music(self, version: int, song: int, chart: int, title: str, arranger: str, illustrator: str,

View File

@ -15,4 +15,4 @@ trailing_slash = True
use_default_host = False
host = ""
current_schema_version = 1
current_schema_version = 2

View File

@ -135,6 +135,7 @@ playlog = Table(
Column("isNewFree", Boolean),
Column("extNum1", Integer),
Column("extNum2", Integer),
Column("trialPlayAchievement", Integer),
mysql_charset='utf8mb4'
)
@ -161,6 +162,7 @@ course = Table(
class Mai2ScoreData(BaseData):
def put_best_score(self, user_id: int, score_data: Dict) -> Optional[int]:
score_data["user"] = user_id
sql = insert(best_score).values(**score_data)
conflict = sql.on_duplicate_key_update(**score_data)
@ -197,6 +199,7 @@ class Mai2ScoreData(BaseData):
return result.fetchone()
def put_playlog(self, user_id: int, playlog_data: Dict) -> Optional[int]:
playlog_data["user"] = user_id
sql = insert(playlog).values(**playlog_data)
conflict = sql.on_duplicate_key_update(**playlog_data)
@ -208,6 +211,7 @@ class Mai2ScoreData(BaseData):
return result.lastrowid
def put_course(self, user_id: int, course_data: Dict) -> Optional[int]:
course_data["user"] = user_id
sql = insert(course).values(**course_data)
conflict = sql.on_duplicate_key_update(**course_data)

View File

@ -1,7 +1,9 @@
from titles.pokken.index import PokkenServlet
from titles.pokken.const import PokkenConstants
from titles.pokken.database import PokkenData
index = PokkenServlet
database = PokkenData
use_default_title = True
include_protocol = True

View File

@ -12,10 +12,6 @@ class PokkenServerConfig():
def loglevel(self) -> int:
return CoreConfig.str_to_loglevel(CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'loglevel', default="info"))
@property
def hostname(self) -> str:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'hostname', default="localhost")
@property
def port(self) -> int:
return CoreConfig.get_config_field(self.__config, 'pokken', 'server', 'port', default=9000)

View File

@ -0,0 +1,6 @@
from core.data import Data
from core.config import CoreConfig
class PokkenData(Data):
def __init__(self, cfg: CoreConfig) -> None:
super().__init__(cfg)

View File

@ -5,7 +5,8 @@ import yaml
import logging, coloredlogs
from logging.handlers import TimedRotatingFileHandler
from titles.pokken.proto import jackal_pb2
from google.protobuf import text_format
from os import path
from google.protobuf.message import DecodeError
from core.config import CoreConfig
from titles.pokken.config import PokkenConfig
@ -41,27 +42,46 @@ class PokkenServlet(resource.Resource):
self.base = PokkenBase(core_cfg, self.game_cfg)
def setup(self):
if self.game_cfg.server.enable:
if self.core_cfg.server.is_develop:
"""
There's currently no point in having this server on because Twisted
won't play ball with both the fact that it's TLSv1.1, and because the
types of certs that pokken will accept are too flimsy for Twisted
so it will throw a fit. Currently leaving this here in case a bypass
is discovered in the future, but it's unlikly. For now, just use NGINX.
"""
if self.game_cfg.server.enable and self.core_cfg.server.is_develop:
key_exists = path.exists(self.game_cfg.server.ssl_key)
cert_exists = path.exists(self.game_cfg.server.ssl_cert)
if key_exists and cert_exists:
endpoints.serverFromString(reactor, f"ssl:{self.game_cfg.server.port}"\
f":interface={self.game_cfg.server.hostname}:privateKey={self.game_cfg.server.ssl_key}:"\
f":interface={self.core_cfg.server.listen_address}:privateKey={self.game_cfg.server.ssl_key}:"\
f"certKey={self.game_cfg.server.ssl_cert}")\
.listen(server.Site(PokkenServlet(self.core_cfg, self.config_dir)))
.listen(server.Site(self))
self.logger.info(f"Pokken title server ready on port {self.game_cfg.server.port}")
else:
endpoints.serverFromString(reactor, f"tcp:{self.game_cfg.server.port}"\
f":interface={self.game_cfg.server.hostname}")\
.listen(server.Site(PokkenServlet(self.core_cfg, self.config_dir)))
self.logger.error(f"Could not find cert at {self.game_cfg.server.ssl_key} or key at {self.game_cfg.server.ssl_cert}, Pokken not running.")
self.logger.info(f"Pokken title server ready on port {self.game_cfg.server.port}")
def render_POST(self, request: Request, version: int, endpoints: str) -> bytes:
req_url = request.uri.decode()
if req_url == "/matching":
def render_POST(self, request: Request, version: int = 0, endpoints: str = "") -> bytes:
if endpoints == "":
endpoints = request.uri.decode()
if endpoints.startswith("/matching"):
self.logger.info("Matching request")
content = request.content.getvalue()
if content == b"":
self.logger.info("Empty request")
return b""
pokken_request = jackal_pb2.Request()
pokken_request.ParseFromString(request.content.getvalue())
try:
pokken_request.ParseFromString(content)
except DecodeError as e:
self.logger.warn(f"{e} {content}")
return b""
endpoint = jackal_pb2.MessageType(pokken_request.type).name.lower()
self.logger.info(f"{endpoint} request")

View File

@ -2,10 +2,12 @@ from titles.wacca.const import WaccaConstants
from titles.wacca.index import WaccaServlet
from titles.wacca.read import WaccaReader
from titles.wacca.database import WaccaData
from titles.wacca.frontend import WaccaFrontend
index = WaccaServlet
database = WaccaData
reader = WaccaReader
frontend = WaccaFrontend
use_default_title = True
include_protocol = True

View File

@ -1,9 +1,8 @@
from typing import Any, List, Dict
import logging
import inflection
from math import floor
from datetime import datetime, timedelta
from core.config import CoreConfig
from titles.wacca.config import WaccaConfig
from titles.wacca.const import WaccaConstants
@ -23,53 +22,60 @@ class WaccaBase():
self.season = 1
self.OPTIONS_DEFAULTS: Dict[str, Any] = {
"note_speed": 5,
"field_mask": 0,
"note_sound": 105001,
"note_color": 203001,
"bgm_volume": 10,
"bg_video": 0,
"mirror": 0,
"judge_display_pos": 0,
"judge_detail_display": 0,
"measure_guidelines": 1,
"guideline_mask": 1,
"judge_line_timing_adjust": 10,
"note_design": 3,
"bonus_effect": 1,
"chara_voice": 1,
"score_display_method": 0,
"give_up": 0,
"guideline_spacing": 1,
"center_display": 1,
"ranking_display": 1,
"stage_up_icon_display": 1,
"rating_display": 1,
"player_level_display": 1,
"touch_effect": 1,
"guide_sound_vol": 3,
"touch_note_vol": 8,
"hold_note_vol": 8,
"slide_note_vol": 8,
"snap_note_vol": 8,
"chain_note_vol": 8,
"bonus_note_vol": 8,
"gate_skip": 0,
"key_beam_display": 1,
"note_speed": 5,
"field_mask": 0,
"note_sound": 105001,
"note_color": 203001,
"bgm_volume": 10,
"bg_video": 0,
"left_slide_note_color": 4,
"right_slide_note_color": 3,
"forward_slide_note_color": 1,
"back_slide_note_color": 2,
"master_vol": 3,
"set_title_id": 104001,
"set_icon_id": 102001,
"set_nav_id": 210001,
"set_plate_id": 211001
}
"mirror": 0,
"judge_display_pos": 0,
"judge_detail_display": 0,
"measure_guidelines": 1,
"guideline_mask": 1,
"judge_line_timing_adjust": 10,
"note_design": 3,
"bonus_effect": 1,
"chara_voice": 1,
"score_display_method": 0,
"give_up": 0,
"guideline_spacing": 1,
"center_display": 1,
"ranking_display": 1,
"stage_up_icon_display": 1,
"rating_display": 1,
"player_level_display": 1,
"touch_effect": 1,
"guide_sound_vol": 3,
"touch_note_vol": 8,
"hold_note_vol": 8,
"slide_note_vol": 8,
"snap_note_vol": 8,
"chain_note_vol": 8,
"bonus_note_vol": 8,
"gate_skip": 0,
"key_beam_display": 1,
"left_slide_note_color": 4,
"right_slide_note_color": 3,
"forward_slide_note_color": 1,
"back_slide_note_color": 2,
"master_vol": 3,
"set_title_id": 104001,
"set_icon_id": 102001,
"set_nav_id": 210001,
"set_plate_id": 211001
}
self.allowed_stages = []
prefecture_name = inflection.underscore(game_cfg.server.prefecture_name).replace(' ', '_').upper()
if prefecture_name not in [region.name for region in WaccaConstants.Region]:
self.logger.warning(f"Invalid prefecture name {game_cfg.server.prefecture_name} in config file")
self.region_id = WaccaConstants.Region.HOKKAIDO
else:
self.region_id = WaccaConstants.Region[prefecture_name]
def handle_housing_get_request(self, data: Dict) -> Dict:
req = BaseRequest(data)
@ -77,21 +83,20 @@ class WaccaBase():
self.logger.info(f"{req.chipId} -> {housing_id}")
resp = HousingGetResponse(housing_id)
return resp.make()
def handle_advertise_GetRanking_request(self, data: Dict) -> Dict:
req = AdvertiseGetRankingRequest(data)
return AdvertiseGetRankingResponse().make()
def handle_housing_start_request(self, data: Dict) -> Dict:
req = HousingStartRequest(data)
req = HousingStartRequestV1(data)
resp = HousingStartResponseV1(
1,
[ # Recomended songs
1269,1007,1270,1002,1020,1003,1008,1211,1018,1092,1056,32,
1260,1230,1258,1251,2212,1264,1125,1037,2001,1272,1126,1119,
1104,1070,1047,1044,1027,1004,1001,24,2068,2062,2021,1275,
1249,1207,1203,1107,1021,1009,9,4,3,23,22,2014,13,1276,1247,
1240,1237,1128,1114,1110,1109,1102,1045,1043,1036,1035,1030,
1023,1015
]
)
if req.appVersion.country != "JPN" and req.appVersion.country in [region.name for region in WaccaConstants.Region]:
region_id = WaccaConstants.Region[req.appVersion.country]
else:
region_id = self.region_id
resp = HousingStartResponseV1(region_id)
return resp.make()
def handle_advertise_GetNews_request(self, data: Dict) -> Dict:
@ -103,7 +108,49 @@ class WaccaBase():
self.logger.info(f"Log out user {req.userId} from {req.chipId}")
return BaseResponse().make()
def handle_user_status_login_request(self, data: Dict) -> List[Any]:
def handle_user_status_get_request(self, data: Dict)-> Dict:
req = UserStatusGetRequest(data)
resp = UserStatusGetV1Response()
profile = self.data.profile.get_profile(aime_id=req.aimeId)
if profile is None:
self.logger.info(f"No user exists for aime id {req.aimeId}")
resp.profileStatus = ProfileStatus.ProfileRegister
return resp.make()
self.logger.info(f"User preview for {req.aimeId} from {req.chipId}")
if profile["last_game_ver"] is None:
resp.lastGameVersion = ShortVersion(str(req.appVersion))
else:
resp.lastGameVersion = ShortVersion(profile["last_game_ver"])
resp.userStatus.userId = profile["id"]
resp.userStatus.username = profile["username"]
resp.userStatus.xp = profile["xp"]
resp.userStatus.danLevel = profile["dan_level"]
resp.userStatus.danType = profile["dan_type"]
resp.userStatus.wp = profile["wp"]
resp.userStatus.useCount = profile["login_count"]
set_title_id = self.data.profile.get_options(WaccaConstants.OPTIONS["set_title_id"], profile["user"])
if set_title_id is None:
set_title_id = self.OPTIONS_DEFAULTS["set_title_id"]
resp.setTitleId = set_title_id
set_icon_id = self.data.profile.get_options(WaccaConstants.OPTIONS["set_title_id"], profile["user"])
if set_icon_id is None:
set_icon_id = self.OPTIONS_DEFAULTS["set_icon_id"]
resp.setIconId = set_icon_id
if req.appVersion > resp.lastGameVersion:
resp.versionStatus = PlayVersionStatus.VersionUpgrade
elif req.appVersion < resp.lastGameVersion:
resp.versionStatus = PlayVersionStatus.VersionTooNew
return resp.make()
def handle_user_status_login_request(self, data: Dict)-> Dict:
req = UserStatusLoginRequest(data)
resp = UserStatusLoginResponseV1()
is_new_day = False
@ -139,120 +186,8 @@ class WaccaBase():
resp.firstLoginDaily = int(is_new_day)
return resp.make()
def handle_user_status_get_request(self, data: Dict) -> List[Any]:
req = UserStatusGetRequest(data)
resp = UserStatusGetV1Response()
ver_split = req.appVersion.split(".")
profile = self.data.profile.get_profile(aime_id=req.aimeId)
if profile is None:
self.logger.info(f"No user exists for aime id {req.aimeId}")
return resp.make()
self.logger.info(f"User preview for {req.aimeId} from {req.chipId}")
if profile["last_game_ver"] is None:
profile_ver_split = ver_split
resp.lastGameVersion = req.appVersion
else:
profile_ver_split = profile["last_game_ver"].split(".")
resp.lastGameVersion = profile["last_game_ver"]
resp.userStatus.userId = profile["id"]
resp.userStatus.username = profile["username"]
resp.userStatus.xp = profile["xp"]
resp.userStatus.danLevel = profile["dan_level"]
resp.userStatus.danType = profile["dan_type"]
resp.userStatus.wp = profile["wp"]
resp.userStatus.useCount = profile["login_count"]
resp.userStatus.loginDays = profile["login_count_days"]
resp.userStatus.loginConsecutiveDays = profile["login_count_days_consec"]
set_title_id = self.data.profile.get_options(WaccaConstants.OPTIONS["set_title_id"], profile["user"])
if set_title_id is None:
set_title_id = self.OPTIONS_DEFAULTS["set_title_id"]
resp.setTitleId = set_title_id
set_icon_id = self.data.profile.get_options(WaccaConstants.OPTIONS["set_title_id"], profile["user"])
if set_icon_id is None:
set_icon_id = self.OPTIONS_DEFAULTS["set_icon_id"]
resp.setIconId = set_icon_id
if profile["last_login_date"].timestamp() < int((datetime.now().replace(hour=0,minute=0,second=0,microsecond=0) - timedelta(days=1)).timestamp()):
resp.userStatus.loginConsecutiveDays = 0
if int(ver_split[0]) > int(profile_ver_split[0]):
resp.versionStatus = PlayVersionStatus.VersionUpgrade
elif int(ver_split[0]) < int(profile_ver_split[0]):
resp.versionStatus = PlayVersionStatus.VersionTooNew
else:
if int(ver_split[1]) > int(profile_ver_split[1]):
resp.versionStatus = PlayVersionStatus.VersionUpgrade
elif int(ver_split[1]) < int(profile_ver_split[1]):
resp.versionStatus = PlayVersionStatus.VersionTooNew
else:
if int(ver_split[2]) > int(profile_ver_split[2]):
resp.versionStatus = PlayVersionStatus.VersionUpgrade
elif int(ver_split[2]) < int(profile_ver_split[2]):
resp.versionStatus = PlayVersionStatus.VersionTooNew
if profile["always_vip"]:
resp.userStatus.vipExpireTime = int((datetime.now() + timedelta(days=30)).timestamp())
elif profile["vip_expire_time"] is not None:
resp.userStatus.vipExpireTime = int(profile["vip_expire_time"].timestamp())
return resp.make()
def handle_user_status_login_request(self, data: Dict) -> List[Any]:
req = UserStatusLoginRequest(data)
resp = UserStatusLoginResponseV2()
is_new_day = False
is_consec_day = False
is_consec_day = True
if req.userId == 0:
self.logger.info(f"Guest login on {req.chipId}")
resp.lastLoginDate = 0
else:
profile = self.data.profile.get_profile(req.userId)
if profile is None:
self.logger.warn(f"Unknown user id {req.userId} attempted login from {req.chipId}")
return resp.make()
self.logger.info(f"User {req.userId} login on {req.chipId}")
last_login_time = int(profile["last_login_date"].timestamp())
resp.lastLoginDate = last_login_time
# If somebodies login timestamp < midnight of current day, then they are logging in for the first time today
if last_login_time < int(datetime.now().replace(hour=0,minute=0,second=0,microsecond=0).timestamp()):
is_new_day = True
is_consec_day = True
# If somebodies login timestamp > midnight of current day + 1 day, then they broke their daily login streak
elif last_login_time > int((datetime.now().replace(hour=0,minute=0,second=0,microsecond=0) + timedelta(days=1)).timestamp()):
is_consec_day = False
# else, they are simply logging in again on the same day, and we don't need to do anything for that
self.data.profile.session_login(req.userId, is_new_day, is_consec_day)
resp.vipInfo.pageYear = datetime.now().year
resp.vipInfo.pageMonth = datetime.now().month
resp.vipInfo.pageDay = datetime.now().day
resp.vipInfo.numItem = 1
resp.firstLoginDaily = int(is_new_day)
return resp.make()
def handle_user_status_create_request(self, data: Dict) -> List[Any]:
def handle_user_status_create_request(self, data: Dict)-> Dict:
req = UserStatusCreateRequest(data)
profileId = self.data.profile.create_profile(req.aimeId, req.username, self.version)
@ -284,7 +219,7 @@ class WaccaBase():
return UserStatusCreateResponseV2(profileId, req.username).make()
def handle_user_status_getDetail_request(self, data: Dict) -> List[Any]:
def handle_user_status_getDetail_request(self, data: Dict)-> Dict:
req = UserStatusGetDetailRequest(data)
resp = UserStatusGetDetailResponseV1()
@ -301,16 +236,7 @@ class WaccaBase():
profile_song_unlocks = self.data.item.get_song_unlocks(user_id)
profile_options = self.data.profile.get_options(user_id)
profile_trophies = self.data.item.get_trophies(user_id)
profile_tickets = self.data.item.get_tickets(user_id)
if profile["vip_expire_time"] is None:
resp.userStatus.vipExpireTime = 0
else:
resp.userStatus.vipExpireTime = int(profile["vip_expire_time"].timestamp())
if profile["always_vip"] or self.game_config.mods.always_vip:
resp.userStatus.vipExpireTime = int((self.srvtime + timedelta(days=31)).timestamp())
profile_tickets = self.data.item.get_tickets(user_id)
resp.songUpdateTime = int(profile["last_login_date"].timestamp())
resp.songPlayStatus = [profile["last_song_id"], 1]
@ -322,8 +248,6 @@ class WaccaBase():
resp.userStatus.danType = profile["dan_type"]
resp.userStatus.wp = profile["wp"]
resp.userStatus.useCount = profile["login_count"]
resp.userStatus.loginDays = profile["login_count_days"]
resp.userStatus.loginConsecutiveDays = profile["login_count_days_consec"]
if self.game_config.mods.infinite_wp:
resp.userStatus.wp = 999999
@ -346,13 +270,9 @@ class WaccaBase():
for unlock in profile_song_unlocks:
for x in range(1, unlock["highest_difficulty"] + 1):
resp.userItems.songUnlocks.append(SongUnlock(unlock["song_id"], x, 0, int(unlock["acquire_date"].timestamp())))
if x > 2:
resp.scores.append(BestScoreDetailV1(unlock["song_id"], x))
empty_scores = len(resp.scores)
for song in profile_scores:
resp.seasonInfo.cumulativeScore += song["score"]
empty_score_idx = resp.find_score_idx(song["song_id"], song["chart_id"], 0, empty_scores)
clear_cts = SongDetailClearCounts(
song["play_ct"],
@ -368,24 +288,16 @@ class WaccaBase():
song["grade_master_ct"]
)
if empty_score_idx is not None:
resp.scores[empty_score_idx].clearCounts = clear_cts
resp.scores[empty_score_idx].clearCountsSeason = clear_cts
resp.scores[empty_score_idx].gradeCounts = grade_cts
resp.scores[empty_score_idx].score = song["score"]
resp.scores[empty_score_idx].bestCombo = song["best_combo"]
resp.scores[empty_score_idx].lowestMissCtMaybe = song["lowest_miss_ct"]
resp.scores[empty_score_idx].rating = song["rating"]
else:
deets = BestScoreDetailV1(song["song_id"], song["chart_id"])
deets.clearCounts = clear_cts
deets.clearCountsSeason = clear_cts
deets.gradeCounts = grade_cts
deets.score = song["score"]
deets.bestCombo = song["best_combo"]
deets.lowestMissCtMaybe = song["lowest_miss_ct"]
deets.rating = song["rating"]
deets = BestScoreDetailV1(song["song_id"], song["chart_id"])
deets.clearCounts = clear_cts
deets.clearCountsSeason = clear_cts
deets.gradeCounts = grade_cts
deets.score = song["score"]
deets.bestCombo = song["best_combo"]
deets.lowestMissCtMaybe = song["lowest_miss_ct"]
deets.rating = song["rating"]
resp.scores.append(deets)
for trophy in profile_trophies:
resp.userItems.trophies.append(TrophyItem(trophy["trophy_id"], trophy["season"], trophy["progress"], trophy["badge_type"]))
@ -434,7 +346,7 @@ class WaccaBase():
return resp.make()
def handle_user_trial_get_request(self, data: Dict) -> List[Any]:
def handle_user_trial_get_request(self, data: Dict)-> Dict:
req = UserTrialGetRequest(data)
resp = UserTrialGetResponse()
@ -444,16 +356,12 @@ class WaccaBase():
return resp.make()
self.logger.info(f"Get trial info for user {req.profileId}")
for d in self.allowed_stages:
if d[1] > 0 and d[1] < 10:
resp.stageList.append(StageInfo(d[0], d[1]))
stages = self.data.score.get_stageup(user_id, self.version)
if stages is None:
stages = []
add_next = True
tmp: List[StageInfo] = []
for d in self.allowed_stages:
stage_info = StageInfo(d[0], d[1])
@ -466,15 +374,17 @@ class WaccaBase():
stage_info.song3BestScore = score["song3_score"]
break
if add_next or stage_info.danLevel < 9:
resp.stageList.append(stage_info)
tmp.append(stage_info)
if stage_info.danLevel >= 9 and stage_info.clearStatus < 1:
add_next = False
for x in range(len(tmp)):
if tmp[x].danLevel >= 10 and (tmp[x + 1].clearStatus >= 1 or tmp[x].clearStatus >= 1):
resp.stageList.append(tmp[x])
elif tmp[x].danLevel < 10:
resp.stageList.append(tmp[x])
return resp.make()
def handle_user_trial_update_request(self, data: Dict) -> List[Any]:
def handle_user_trial_update_request(self, data: Dict)-> Dict:
req = UserTrialUpdateRequest(data)
total_score = 0
@ -496,8 +406,8 @@ class WaccaBase():
# We only care about total score for best of, even if one score happens to be lower (I think)
if total_score > (old_stage["song1_score"] + old_stage["song2_score"] + old_stage["song3_score"]):
best_score1 = req.songScores[0]
best_score2 = req.songScores[2]
best_score3 = req.songScores[3]
best_score2 = req.songScores[1]
best_score3 = req.songScores[2]
else:
best_score1 = old_stage["song1_score"]
best_score2 = old_stage["song2_score"]
@ -528,9 +438,9 @@ class WaccaBase():
self.data.item.put_item(user_id, WaccaConstants.ITEM_TYPES["icon"], current_icon)
self.data.item.put_item(user_id, WaccaConstants.ITEM_TYPES["navigator"], current_nav)
self.data.profile.update_profile_playtype(req.profileId, 4, data["appVersion"][:7])
return BaseResponse.make()
return BaseResponse().make()
def handle_user_sugoroku_update_request(self, data: Dict) -> List[Any]:
def handle_user_sugoroku_update_request(self, data: Dict)-> Dict:
ver_split = data["appVersion"].split(".")
resp = BaseResponse()
@ -552,10 +462,10 @@ class WaccaBase():
self.data.profile.update_gate(user_id, req.gateId, req.page, req.progress, req.loops, mission_flg, req.totalPts)
return resp.make()
def handle_user_info_getMyroom_request(self, data: Dict) -> List[Any]:
return UserInfogetMyroomResponse().make()
def handle_user_info_getMyroom_request(self, data: Dict)-> Dict:
return UserInfogetMyroomResponseV1().make()
def handle_user_music_unlock_request(self, data: Dict) -> List[Any]:
def handle_user_music_unlock_request(self, data: Dict)-> Dict:
req = UserMusicUnlockRequest(data)
profile = self.data.profile.get_profile(req.profileId)
@ -605,29 +515,35 @@ class WaccaBase():
return UserMusicUnlockResponse(current_wp, new_tickets).make()
def handle_user_info_getRanking_request(self, data: Dict) -> List[Any]:
def handle_user_info_getRanking_request(self, data: Dict)-> Dict:
# total score, high score by song, cumulative socre, stage up score, other score, WP ranking
# This likely requies calculating standings at regular intervals and caching the results
return UserInfogetRankingResponse().make()
def handle_user_music_update_request(self, data: Dict) -> List[Any]:
req = UserMusicUpdateRequest(data)
ver_split = req.appVersion.split(".")
def handle_user_music_update_request(self, data: Dict)-> Dict:
ver_split = data["appVersion"].split(".")
if int(ver_split[0]) >= 3:
resp = UserMusicUpdateResponseV3()
req = UserMusicUpdateRequestV2(data)
elif int(ver_split[0]) >= 2:
resp = UserMusicUpdateResponseV2()
req = UserMusicUpdateRequestV2(data)
else:
resp = UserMusicUpdateResponseV1()
req = UserMusicUpdateRequestV1(data)
resp.songDetail.songId = req.songDetail.songId
resp.songDetail.difficulty = req.songDetail.difficulty
if req.profileId == 0:
self.logger.info(f"Guest score for song {req.songDetail.songId} difficulty {req.songDetail.difficulty}")
return resp.make()
profile = self.data.profile.get_profile(req.profileId)
if profile is None:
self.logger.warn(f"handle_user_music_update_request: No profile for game_id {req.profileId}")
return BaseResponse().make()
return resp.make()
user_id = profile["user"]
self.util_put_items(req.profileId, user_id, req.itemsObtained)
@ -715,18 +631,18 @@ class WaccaBase():
return resp.make()
#TODO: Coop and vs data
def handle_user_music_updateCoop_request(self, data: Dict) -> List[Any]:
def handle_user_music_updateCoop_request(self, data: Dict)-> Dict:
coop_info = data["params"][4]
return self.handle_user_music_update_request(data)
def handle_user_music_updateVersus_request(self, data: Dict) -> List[Any]:
def handle_user_music_updateVersus_request(self, data: Dict)-> Dict:
vs_info = data["params"][4]
return self.handle_user_music_update_request(data)
def handle_user_music_updateTrial_request(self, data: Dict) -> List[Any]:
def handle_user_music_updateTrial_request(self, data: Dict)-> Dict:
return self.handle_user_music_update_request(data)
def handle_user_mission_update_request(self, data: Dict) -> List[Any]:
def handle_user_mission_update_request(self, data: Dict)-> Dict:
req = UserMissionUpdateRequest(data)
page_status = req.params[1][1]
@ -742,7 +658,7 @@ class WaccaBase():
return BaseResponse().make()
def handle_user_goods_purchase_request(self, data: Dict) -> List[Any]:
def handle_user_goods_purchase_request(self, data: Dict)-> Dict:
req = UserGoodsPurchaseRequest(data)
resp = UserGoodsPurchaseResponse()
@ -775,13 +691,13 @@ class WaccaBase():
return resp.make()
def handle_competition_status_login_request(self, data: Dict) -> List[Any]:
def handle_competition_status_login_request(self, data: Dict)-> Dict:
return BaseResponse().make()
def handle_competition_status_update_request(self, data: Dict) -> List[Any]:
def handle_competition_status_update_request(self, data: Dict)-> Dict:
return BaseResponse().make()
def handle_user_rating_update_request(self, data: Dict) -> List[Any]:
def handle_user_rating_update_request(self, data: Dict)-> Dict:
req = UserRatingUpdateRequest(data)
user_id = self.data.profile.profile_to_aime_user(req.profileId)
@ -797,8 +713,8 @@ class WaccaBase():
return BaseResponse().make()
def handle_user_status_update_request(self, data: Dict) -> List[Any]:
req = UserStatusUpdateRequestV2(data)
def handle_user_status_update_request(self, data: Dict)-> Dict:
req = UserStatusUpdateRequestV1(data)
user_id = self.data.profile.profile_to_aime_user(req.profileId)
if user_id is None:
@ -807,8 +723,6 @@ class WaccaBase():
self.util_put_items(req.profileId, user_id, req.itemsRecieved)
self.data.profile.update_profile_playtype(req.profileId, req.playType.value, data["appVersion"][:7])
self.data.profile.update_profile_lastplayed(req.profileId, req.lastSongInfo.lastSongId, req.lastSongInfo.lastSongDiff,
req.lastSongInfo.lastFolderOrd, req.lastSongInfo.lastFolderId, req.lastSongInfo.lastSongOrd)
current_icon = self.data.profile.get_options(user_id, WaccaConstants.OPTIONS["set_icon_id"])
current_nav = self.data.profile.get_options(user_id, WaccaConstants.OPTIONS["set_nav_id"])
@ -826,7 +740,7 @@ class WaccaBase():
self.data.item.put_item(user_id, WaccaConstants.ITEM_TYPES["navigator"], current_nav)
return BaseResponse().make()
def handle_user_info_update_request(self, data: Dict) -> List[Any]:
def handle_user_info_update_request(self, data: Dict)-> Dict:
req = UserInfoUpdateRequest(data)
user_id = self.data.profile.profile_to_aime_user(req.profileId)
@ -845,7 +759,7 @@ class WaccaBase():
return BaseResponse().make()
def handle_user_vip_get_request(self, data: Dict) -> List[Any]:
def handle_user_vip_get_request(self, data: Dict)-> Dict:
req = UserVipGetRequest(data)
resp = UserVipGetResponse()
@ -868,7 +782,7 @@ class WaccaBase():
return resp.make()
def handle_user_vip_start_request(self, data: Dict) -> List[Any]:
def handle_user_vip_start_request(self, data: Dict)-> Dict:
req = UserVipStartRequest(data)
profile = self.data.profile.get_profile(req.profileId)
@ -879,9 +793,9 @@ class WaccaBase():
if "always_vip" in profile and profile["always_vip"] or self.game_config.mods.always_vip:
return UserVipStartResponse(int((self.srvtime + timedelta(days=req.days)).timestamp())).make()
profile["vip_expire_time"] = int((self.srvtime + timedelta(days=req.days)).timestamp())
self.data.profile.update_vip_time(req.profileId, self.srvtime + timedelta(days=req.days))
return UserVipStartResponse(profile["vip_expire_time"]).make()
vip_exp_time = (self.srvtime + timedelta(days=req.days))
self.data.profile.update_vip_time(req.profileId, vip_exp_time)
return UserVipStartResponse(int(vip_exp_time.timestamp())).make()
def util_put_items(self, profile_id: int, user_id: int, items_obtained: List[GenericItemRecv]) -> None:
if user_id is None or profile_id <= 0:

View File

@ -13,6 +13,10 @@ class WaccaServerConfig():
def loglevel(self) -> int:
return CoreConfig.str_to_loglevel(CoreConfig.get_config_field(self.__config, 'wacca', 'server', 'loglevel', default="info"))
@property
def prefecture_name(self) -> str:
return CoreConfig.get_config_field(self.__config, 'wacca', 'server', 'prefecture_name', default="Hokkaido")
class WaccaModsConfig():
def __init__(self, parent_config: "WaccaConfig") -> None:
self.__config = parent_config

View File

@ -95,18 +95,73 @@ class WaccaConstants():
"set_plate_id": 1005, # ID
}
DIFFICULTIES = {
"Normal": 1,
"Hard": 2,
"Expert": 3,
"Inferno": 4,
}
class Difficulty(Enum):
NORMAL = 1
HARD = 2
EXPERT = 3
INFERNO = 4
class Region(Enum):
NONE = 0
HOKKAIDO = 1
AOMORI = 2
IWATE = 3
MIYAGI = 4
AKITA = 5
YAMAGATA = 6
FUKUSHIMA = 7
IBARAKI = 8
TOCHIGI = 9
GUNMA = 10
SAITAMA = 11
CHIBA = 12
TOKYO = 13
KANAGAWA = 14
NIIGATA = 15
TOYAMA = 16
ISHIKAWA = 17
FUKUI = 18
YAMANASHI = 19
NAGANO = 20
GIFU = 21
SHIZUOKA = 22
AICHI = 23
MIE = 24
SHIGA = 25
KYOTO = 26
OSAKA = 27
HYOGO = 28
NARA = 29
WAKAYAMA = 30
TOTTORI = 31
SHIMANE = 32
OKAYAMA = 33
HIROSHIMA = 34
YAMAGUCHI = 35
TOKUSHIMA = 36
KAGAWA = 37
EHIME = 38
KOCHI = 39
FUKUOKA = 40
SAGA = 41
NAGASAKI = 42
KUMAMOTO = 43
OITA = 44
MIYAZAKI = 45
KAGOSHIMA = 46
OKINAWA = 47
UNITED_STATES = 48
USA = 48
TAIWAN = 49
TWN = 49
HONG_KONG = 50
HKG = 50
SINGAPORE = 51
SGP = 51
KOREA = 52
KOR = 52
VALID_COUNTRIES = set(["JPN", "USA", "KOR", "HKG", "SGP"])
@classmethod
def game_ver_to_string(cls, ver: int):

24
titles/wacca/frontend.py Normal file
View File

@ -0,0 +1,24 @@
import yaml
import jinja2
from twisted.web.http import Request
from core.frontend import FE_Base
from core.config import CoreConfig
from titles.wacca.database import WaccaData
from titles.wacca.config import WaccaConfig
from titles.wacca.const import WaccaConstants
class WaccaFrontend(FE_Base):
def __init__(self, cfg: CoreConfig, environment: jinja2.Environment, cfg_dir: str) -> None:
super().__init__(cfg, environment)
self.data = WaccaData(cfg)
self.game_cfg = WaccaConfig()
self.game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/wacca.yaml")))
self.nav_name = "Wacca"
def render_GET(self, request: Request) -> bytes:
template = self.environment.get_template("titles/wacca/frontend/wacca_index.jinja")
return template.render(
title=f"{self.core_config.server.name} | {self.nav_name}",
game_list=self.environment.globals["game_list"]
).encode("utf-16")

View File

@ -0,0 +1,4 @@
{% extends "core/frontend/index.jinja" %}
{% block content %}
<h1>Wacca</h1>
{% endblock content %}

View File

@ -1,6 +1,6 @@
from typing import List, Dict
from titles.wacca.handlers.base import BaseResponse
from titles.wacca.handlers.base import BaseResponse, BaseRequest
from titles.wacca.handlers.helpers import Notice
# ---advertise/GetNews---
@ -33,13 +33,33 @@ class GetNewsResponseV1(BaseResponse):
class GetNewsResponseV2(GetNewsResponseV1):
stoppedProducts: list[int] = []
def make(self) -> Dict:
super().make()
self.params.append(self.stoppedProducts)
return super(GetNewsResponseV1, self).make()
class GetNewsResponseV3(GetNewsResponseV2):
stoppedNavs: list[int] = []
stoppedNavVoices: list[int] = []
def make(self) -> Dict:
super().make()
self.params.append(self.stoppedProducts)
self.params.append(self.stoppedNavs)
self.params.append(self.stoppedNavVoices)
return super(GetNewsResponseV1, self).make()
# ---advertise/GetRanking---
class AdvertiseGetRankingRequest(BaseRequest):
def __init__(self, data: Dict) -> None:
super().__init__(data)
self.resourceVer: int = self.params[0]
class AdvertiseGetRankingResponse(BaseResponse):
def __init__(self) -> None:
super().__init__()
def make(self) -> Dict:
return super().make()

View File

@ -1,10 +1,11 @@
from typing import Dict, List
from titles.wacca.handlers.helpers import Version
from datetime import datetime
class BaseRequest():
def __init__(self, data: Dict) -> None:
self.requestNo: int = data["requestNo"]
self.appVersion: str = data["appVersion"]
self.appVersion: Version = Version(data["appVersion"])
self.boardId: str = data["boardId"]
self.chipId: str = data["chipId"]
self.params: List = data["params"]

View File

@ -1,9 +1,96 @@
from typing import List, Dict, Any
from typing import List, Optional, Any
from enum import Enum
from titles.wacca.const import WaccaConstants
class HousingInfo():
class ShortVersion:
def __init__(self, version: str = "", major = 1, minor = 0, patch = 0) -> None:
split = version.split(".")
if len(split) >= 3:
self.major = int(split[0])
self.minor = int(split[1])
self.patch = int(split[2])
else:
self.major = major
self.minor = minor
self.patch = patch
def __str__(self) -> str:
return f"{self.major}.{self.minor}.{self.patch}"
def __int__(self) -> int:
return (self.major * 10000) + (self.minor * 100) + self.patch
def __eq__(self, other: "ShortVersion"):
return self.major == other.major and self.minor == other.minor and self.patch == other.patch
def __gt__(self, other: "ShortVersion"):
if self.major > other.major:
return True
elif self.major == other.major:
if self.minor > other.minor:
return True
elif self.minor == other.minor:
if self.patch > other.patch:
return True
return False
def __ge__(self, other: "ShortVersion"):
if self.major > other.major:
return True
elif self.major == other.major:
if self.minor > other.minor:
return True
elif self.minor == other.minor:
if self.patch > other.patch or self.patch == other.patch:
return True
return False
def __lt__(self, other: "ShortVersion"):
if self.major < other.major:
return True
elif self.major == other.major:
if self.minor < other.minor:
return True
elif self.minor == other.minor:
if self.patch < other.patch:
return True
return False
def __le__(self, other: "ShortVersion"):
if self.major < other.major:
return True
elif self.major == other.major:
if self.minor < other.minor:
return True
elif self.minor == other.minor:
if self.patch < other.patch or self.patch == other.patch:
return True
return False
class Version(ShortVersion):
def __init__(self, version = "", major = 1, minor = 0, patch = 0, country = "JPN", build = 0, role = "C") -> None:
super().__init__(version, major, minor, patch)
split = version.split(".")
if len(split) >= 6:
self.country = split[3]
self.build = int(split[4])
self.role = split[5]
else:
self.country = country
self.build = build
self.role = role
def __str__(self) -> str:
return f"{self.major}.{self.minor}.{self.patch}.{self.country}.{self.role}.{self.build}"
class HousingInfo:
"""
1 is lan install role, 2 is country
"""
@ -17,7 +104,7 @@ class HousingInfo():
def make(self) -> List:
return [ self.id, self.val ]
class Notice():
class Notice:
name: str = ""
title: str = ""
message: str = ""
@ -40,10 +127,7 @@ class Notice():
return [ self.name, self.title, self.message, self.unknown3, self.unknown4, int(self.showTitleScreen),
int(self.showWelcomeScreen), self.startTime, self.endTime, self.voiceline]
class UserOption():
opt_id: int
opt_val: Any
class UserOption:
def __init__(self, opt_id: int = 0, opt_val: Any = 0) -> None:
self.opt_id = opt_id
self.opt_val = opt_val
@ -51,9 +135,9 @@ class UserOption():
def make(self) -> List:
return [self.opt_id, self.opt_val]
class UserStatusV1():
class UserStatusV1:
def __init__(self) -> None:
self.userId: int = -1
self.userId: int = 0
self.username: str = ""
self.userType: int = 1
self.xp: int = 0
@ -62,10 +146,6 @@ class UserStatusV1():
self.wp: int = 0
self.titlePartIds: List[int] = [0, 0, 0]
self.useCount: int = 0
self.loginDays: int = 0
self.loginConsecutive: int = 0
self.loginConsecutiveDays: int = 0
self.vipExpireTime: int = 0
def make(self) -> List:
return [
@ -78,21 +158,25 @@ class UserStatusV1():
self.wp,
self.titlePartIds,
self.useCount,
self.loginDays,
self.loginConsecutive,
self.loginConsecutiveDays,
self.vipExpireTime
]
class UserStatusV2(UserStatusV1):
def __init__(self) -> None:
super().__init__()
super().__init__()
self.loginDays: int = 0
self.loginConsecutive: int = 0
self.loginConsecutiveDays: int = 0
self.loginsToday: int = 0
self.rating: int = 0
self.rating: int = 0
self.vipExpireTime: int = 0
def make(self) -> List:
ret = super().make()
ret.append(self.loginDays)
ret.append(self.loginConsecutive)
ret.append(self.loginConsecutiveDays)
ret.append(self.vipExpireTime)
ret.append(self.loginsToday)
ret.append(self.rating)
@ -109,7 +193,7 @@ class PlayVersionStatus(Enum):
VersionTooNew = 1
VersionUpgrade = 2
class PlayModeCounts():
class PlayModeCounts:
seasonId: int = 0
modeId: int = 0
playNum: int = 0
@ -126,7 +210,7 @@ class PlayModeCounts():
self.playNum
]
class SongUnlock():
class SongUnlock:
songId: int = 0
difficulty: int = 0
whenAppeared: int = 0
@ -146,7 +230,7 @@ class SongUnlock():
self.whenUnlocked
]
class GenericItemRecv():
class GenericItemRecv:
def __init__(self, item_type: int = 1, item_id: int = 1, quantity: int = 1) -> None:
self.itemId = item_id
self.itemType = item_type
@ -155,7 +239,7 @@ class GenericItemRecv():
def make(self) -> List:
return [ self.itemType, self.itemId, self.quantity ]
class GenericItemSend():
class GenericItemSend:
def __init__(self, itemId: int, itemType: int, whenAcquired: int) -> None:
self.itemId = itemId
self.itemType = itemType
@ -183,7 +267,7 @@ class IconItem(GenericItemSend):
self.whenAcquired
]
class TrophyItem():
class TrophyItem:
trophyId: int = 0
season: int = 1
progress: int = 0
@ -203,7 +287,7 @@ class TrophyItem():
self.badgeType
]
class TicketItem():
class TicketItem:
userTicketId: int = 0
ticketId: int = 0
whenExpires: int = 0
@ -236,7 +320,7 @@ class NavigatorItem(IconItem):
self.usesToday
]
class SkillItem():
class SkillItem:
skill_type: int
level: int
flag: int
@ -250,7 +334,7 @@ class SkillItem():
self.badge
]
class UserItemInfoV1():
class UserItemInfoV1:
def __init__(self) -> None:
self.songUnlocks: List[SongUnlock] = []
self.titles: List[GenericItemSend] = []
@ -334,9 +418,9 @@ class UserItemInfoV3(UserItemInfoV2):
ret.append(effect)
return ret
class SongDetailClearCounts():
class SongDetailClearCounts:
def __init__(self, play_ct: int = 0, clear_ct: int = 0, ml_ct: int = 0, fc_ct: int = 0,
am_ct: int = 0, counts: List[int] = None) -> None:
am_ct: int = 0, counts: Optional[List[int]] = None) -> None:
if counts is None:
self.playCt = play_ct
self.clearCt = clear_ct
@ -354,7 +438,7 @@ class SongDetailClearCounts():
def make(self) -> List:
return [self.playCt, self.clearCt, self.misslessCt, self.fullComboCt, self.allMarvelousCt]
class SongDetailGradeCountsV1():
class SongDetailGradeCountsV1:
dCt: int
cCt: int
bCt: int
@ -367,7 +451,7 @@ class SongDetailGradeCountsV1():
masterCt: int
def __init__(self, d: int = 0, c: int = 0, b: int = 0, a: int = 0, aa: int = 0, aaa: int = 0, s: int = 0,
ss: int = 0, sss: int = 0, master: int = 0, counts: List[int] = None) -> None:
ss: int = 0, sss: int = 0, master: int = 0, counts: Optional[List[int]] = None) -> None:
if counts is None:
self.dCt = d
self.cCt = c
@ -401,7 +485,7 @@ class SongDetailGradeCountsV2(SongDetailGradeCountsV1):
ssspCt: int
def __init__(self, d: int = 0, c: int = 0, b: int = 0, a: int = 0, aa: int = 0, aaa: int = 0, s: int = 0,
ss: int = 0, sss: int = 0, master: int = 0, sp: int = 0, ssp: int = 0, sssp: int = 0, counts: List[int] = None, ) -> None:
ss: int = 0, sss: int = 0, master: int = 0, sp: int = 0, ssp: int = 0, sssp: int = 0, counts: Optional[List[int]] = None) -> None:
super().__init__(d, c, b, a, aa, aaa, s, ss, sss, master, counts)
if counts is None:
self.spCt = sp
@ -416,7 +500,7 @@ class SongDetailGradeCountsV2(SongDetailGradeCountsV1):
def make(self) -> List:
return super().make() + [self.spCt, self.sspCt, self.ssspCt]
class BestScoreDetailV1():
class BestScoreDetailV1:
songId: int = 0
difficulty: int = 1
clearCounts: SongDetailClearCounts = SongDetailClearCounts()
@ -449,7 +533,7 @@ class BestScoreDetailV1():
class BestScoreDetailV2(BestScoreDetailV1):
gradeCounts: SongDetailGradeCountsV2 = SongDetailGradeCountsV2()
class SongUpdateJudgementCounts():
class SongUpdateJudgementCounts:
marvCt: int
greatCt: int
goodCt: int
@ -464,25 +548,8 @@ class SongUpdateJudgementCounts():
def make(self) -> List:
return [self.marvCt, self.greatCt, self.goodCt, self.missCt]
class SongUpdateDetail():
songId: int
difficulty: int
level: float
score: int
judgements: SongUpdateJudgementCounts
maxCombo: int
grade: WaccaConstants.GRADES
flagCleared: bool
flagMissless: bool
flagFullcombo: bool
flagAllMarvelous: bool
flagGiveUp: bool
skillPt: int
fastCt: int
slowCt: int
flagNewRecord: bool
def __init__(self, data: List = None) -> None:
class SongUpdateDetailV1:
def __init__(self, data: List) -> None:
if data is not None:
self.songId = data[0]
self.difficulty = data[1]
@ -498,13 +565,20 @@ class SongUpdateDetail():
self.flagFullcombo = False if data[9] == 0 else True
self.flagAllMarvelous = False if data[10] == 0 else True
self.flagGiveUp = False if data[11] == 0 else True
self.skillPt = data[12]
self.fastCt = 0
self.slowCt = 0
self.flagNewRecord = False
self.skillPt = data[12]
class SongUpdateDetailV2(SongUpdateDetailV1):
def __init__(self, data: List) -> None:
super().__init__(data)
if data is not None:
self.fastCt = data[13]
self.slowCt = data[14]
self.flagNewRecord = False if data[15] == 0 else True
class SeasonalInfoV1():
class SeasonalInfoV1:
def __init__(self) -> None:
self.level: int = 0
self.wpObtained: int = 0
@ -538,7 +612,7 @@ class SeasonalInfoV2(SeasonalInfoV1):
def make(self) -> List:
return super().make() + [self.platesObtained, self.cumulativeGatePts]
class BingoPageStatus():
class BingoPageStatus:
id = 0
location = 1
progress = 0
@ -551,7 +625,7 @@ class BingoPageStatus():
def make(self) -> List:
return [self.id, self.location, self.progress]
class BingoDetail():
class BingoDetail:
def __init__(self, pageNumber: int) -> None:
self.pageNumber = pageNumber
self.pageStatus: List[BingoPageStatus] = []
@ -566,7 +640,7 @@ class BingoDetail():
status
]
class GateDetailV1():
class GateDetailV1:
def __init__(self, gate_id: int = 1, page: int = 1, progress: int = 0, loops: int = 0, last_used: int = 0, mission_flg = 0) -> None:
self.id = gate_id
self.page = page
@ -582,11 +656,11 @@ class GateDetailV2(GateDetailV1):
def make(self) -> List:
return super().make() + [self.missionFlg]
class GachaInfo():
def make() -> List:
class GachaInfo:
def make(self) -> List:
return []
class LastSongDetail():
class LastSongDetail:
lastSongId = 90
lastSongDiff = 1
lastFolderOrd = 1
@ -605,22 +679,11 @@ class LastSongDetail():
return [self.lastSongId, self.lastSongDiff, self.lastFolderOrd, self.lastFolderId,
self.lastSongOrd]
class FriendDetail():
class FriendDetail:
def make(self) -> List:
return []
class UserOption():
id = 1
val = 1
def __init__(self, id: int = 1, val: int = val) -> None:
self.id = id
self.val = val
def make(self) -> List:
return [self.id, self.val]
class LoginBonusInfo():
class LoginBonusInfo:
def __init__(self) -> None:
self.tickets: List[TicketItem] = []
self.items: List[GenericItemRecv] = []
@ -638,7 +701,7 @@ class LoginBonusInfo():
return [ tks, itms, self.message ]
class VipLoginBonus():
class VipLoginBonus:
id = 1
unknown = 0
item: GenericItemRecv
@ -651,7 +714,7 @@ class VipLoginBonus():
def make(self) -> List:
return [ self.id, self.unknown, self.item.make() ]
class VipInfo():
class VipInfo:
def __init__(self, year: int = 2019, month: int = 1, day: int = 1, num_item: int = 1) -> None:
self.pageYear = year
self.pageMonth = month
@ -682,20 +745,7 @@ class PlayType(Enum):
PlayTypeCoop = 3
PlayTypeStageup = 4
class SongRatingUpdate():
song_id = 0
difficulty = 0
rating = 0
def __init__(self, song: int = 0, difficulty: int = 0, rating: int = 0) -> None:
self.song_id = song
self.difficulty = difficulty
self.rating = rating
def make(self) -> List:
return [self.song_id, self.difficulty, self.rating]
class StageInfo():
class StageInfo:
danId: int = 0
danLevel: int = 0
clearStatus: int = 0
@ -729,7 +779,7 @@ class StageupClearType(Enum):
CLEAR_SILVER = 2
CLEAR_GOLD = 3
class MusicUpdateDetailV1():
class MusicUpdateDetailV1:
def __init__(self) -> None:
self.songId = 0
self.difficulty = 1
@ -740,7 +790,6 @@ class MusicUpdateDetailV1():
self.lowestMissCount = 0
self.maxSkillPts = 0
self.locked = 0
self.rating = 0
def make(self) -> List:
return [
@ -753,15 +802,22 @@ class MusicUpdateDetailV1():
self.lowestMissCount,
self.maxSkillPts,
self.locked,
self.rating
]
class MusicUpdateDetailV2(MusicUpdateDetailV1):
def __init__(self) -> None:
super().__init__()
self.rating = 0
def make(self) -> List:
return super().make() + [self.rating]
class MusicUpdateDetailV3(MusicUpdateDetailV2):
def __init__(self) -> None:
super().__init__()
self.grades = SongDetailGradeCountsV2()
class SongRatingUpdate():
class SongRatingUpdate:
def __init__(self, song_id: int = 0, difficulty: int = 1, new_rating: int = 0) -> None:
self.songId = song_id
self.difficulty = difficulty
@ -774,7 +830,7 @@ class SongRatingUpdate():
self.rating,
]
class GateTutorialFlag():
class GateTutorialFlag:
def __init__(self, tutorial_id: int = 1, flg_watched: bool = False) -> None:
self.tutorialId = tutorial_id
self.flagWatched = flg_watched

View File

@ -2,6 +2,7 @@ from typing import List, Dict
from titles.wacca.handlers.base import BaseRequest, BaseResponse
from titles.wacca.handlers.helpers import HousingInfo
from titles.wacca.const import WaccaConstants
# ---housing/get----
class HousingGetResponse(BaseResponse):
@ -15,24 +16,44 @@ class HousingGetResponse(BaseResponse):
return super().make()
# ---housing/start----
class HousingStartRequest(BaseRequest):
class HousingStartRequestV1(BaseRequest):
def __init__(self, data: Dict) -> None:
super().__init__(data)
self.unknown0: str = self.params[0]
self.errorLog: str = self.params[1]
self.unknown2: str = self.params[2]
self.info: List[HousingInfo] = []
for info in self.params[2]:
self.info.append(HousingInfo(info[0], info[1]))
class HousingStartRequestV2(HousingStartRequestV1):
def __init__(self, data: Dict) -> None:
super(HousingStartRequestV1, self).__init__(data)
self.unknown0: str = self.params[0]
self.errorLog: str = self.params[1]
self.creditLog: str = self.params[2]
self.info: List[HousingInfo] = []
for info in self.params[3]:
self.info.append(HousingInfo(info[0], info[1]))
class HousingStartResponseV1(BaseResponse):
def __init__(self, regionId: int, songList: List[int]) -> None:
def __init__(self, regionId: WaccaConstants.Region = WaccaConstants.Region.HOKKAIDO, songList: List[int] = []) -> None:
super().__init__()
self.regionId = regionId
self.songList = songList
self.songList = songList # Recomended songs
if not self.songList:
self.songList = [
1269,1007,1270,1002,1020,1003,1008,1211,1018,1092,1056,32,
1260,1230,1258,1251,2212,1264,1125,1037,2001,1272,1126,1119,
1104,1070,1047,1044,1027,1004,1001,24,2068,2062,2021,1275,
1249,1207,1203,1107,1021,1009,9,4,3,23,22,2014,13,1276,1247,
1240,1237,1128,1114,1110,1109,1102,1045,1043,1036,1035,1030,
1023,1015
]
def make(self) -> Dict:
self.params = [self.regionId, self.songList]
self.params = [self.regionId.value, self.songList]
return super().make()

View File

@ -23,14 +23,37 @@ class UserInfogetMyroomRequest(BaseRequest):
super().__init__(data)
self.game_id = int(self.params[0])
class UserInfogetMyroomResponse(BaseResponse):
class UserInfogetMyroomResponseV1(BaseResponse):
def __init__(self) -> None:
super().__init__()
self.titleViewBadge = 0
self.iconViewBadge = 0
self.trophyViewBadge = 0
self.noteColorViewBadge = 0
self.noteSoundViewBadge = 0
self.userViewingInfo = []
def make(self) -> Dict:
self.params = [
0,0,0,0,0,[],0,0,0
self.titleViewBadge,
self.iconViewBadge,
self.trophyViewBadge,
self.noteColorViewBadge,
self.noteSoundViewBadge,
self.userViewingInfo,
]
return super().make()
class UserInfogetMyroomResponseV2(UserInfogetMyroomResponseV1):
def __init__(self) -> None:
super().__init__()
def make(self) -> Dict:
super().make()
self.params += [0, 0, 0]
return super(UserInfogetMyroomResponseV1, self).make()
# ---user/info/getRanking---
class UserInfogetRankingRequest(BaseRequest):
game_id = 0

View File

@ -25,7 +25,7 @@ class UserGoodsPurchaseResponse(BaseResponse):
for ticket in tickets:
self.tickets.append(TicketItem(ticket[0], ticket[1], ticket[2]))
def make(self) -> List:
def make(self) -> Dict:
tix = []
for ticket in self.tickets:
tix.append(ticket.make())

View File

@ -1,22 +1,28 @@
from typing import List, Dict
from titles.wacca.handlers.base import BaseRequest, BaseResponse
from titles.wacca.handlers.helpers import GenericItemRecv, SongUpdateDetail, TicketItem
from titles.wacca.handlers.helpers import MusicUpdateDetailV1, MusicUpdateDetailV2
from titles.wacca.handlers.helpers import SeasonalInfoV2, SeasonalInfoV1
from titles.wacca.handlers.helpers import GenericItemRecv, SongUpdateDetailV2, TicketItem
from titles.wacca.handlers.helpers import MusicUpdateDetailV2, MusicUpdateDetailV3
from titles.wacca.handlers.helpers import SeasonalInfoV2, SeasonalInfoV1, SongUpdateDetailV1
from titles.wacca.handlers.helpers import MusicUpdateDetailV1
# ---user/music/update---
class UserMusicUpdateRequest(BaseRequest):
class UserMusicUpdateRequestV1(BaseRequest):
def __init__(self, data: Dict) -> None:
super().__init__(data)
self.profileId: int = self.params[0]
self.songNumber: int = self.params[1]
self.songDetail = SongUpdateDetail(self.params[2])
self.songDetail = SongUpdateDetailV1(self.params[2])
self.itemsObtained: List[GenericItemRecv] = []
for itm in data["params"][3]:
self.itemsObtained.append(GenericItemRecv(itm[0], itm[1], itm[2]))
class UserMusicUpdateRequestV2(UserMusicUpdateRequestV1):
def __init__(self, data: Dict) -> None:
super().__init__(data)
self.songDetail = SongUpdateDetailV2(self.params[2])
class UserMusicUpdateResponseV1(BaseResponse):
def __init__(self) -> None:
super().__init__()
@ -37,21 +43,22 @@ class UserMusicUpdateResponseV1(BaseResponse):
class UserMusicUpdateResponseV2(UserMusicUpdateResponseV1):
def __init__(self) -> None:
super().__init__()
self.songDetail = MusicUpdateDetailV2()
self.seasonInfo = SeasonalInfoV2()
class UserMusicUpdateResponseV3(UserMusicUpdateResponseV2):
def __init__(self) -> None:
super().__init__()
self.songDetail = MusicUpdateDetailV2()
self.songDetail = MusicUpdateDetailV3()
# ---user/music/updateCoop---
class UserMusicUpdateCoopRequest(UserMusicUpdateRequest):
class UserMusicUpdateCoopRequest(UserMusicUpdateRequestV2):
def __init__(self, data: Dict) -> None:
super().__init__(data)
self.coopData = self.params[4]
# ---user/music/updateVs---
class UserMusicUpdateVsRequest(UserMusicUpdateRequest):
class UserMusicUpdateVsRequest(UserMusicUpdateRequestV2):
def __init__(self, data: Dict) -> None:
super().__init__(data)
self.vsData = self.params[4]
@ -77,7 +84,7 @@ class UserMusicUnlockResponse(BaseResponse):
for ticket in tickets_remaining:
self.tickets.append(TicketItem(ticket[0], ticket[1], ticket[2]))
def make(self) -> List:
def make(self)-> Dict:
tickets = []
for ticket in self.tickets:

View File

@ -19,7 +19,7 @@ class UserStatusGetV1Response(BaseResponse):
self.setIconId: int = 0
self.profileStatus: ProfileStatus = ProfileStatus.ProfileGood
self.versionStatus: PlayVersionStatus = PlayVersionStatus.VersionGood
self.lastGameVersion: str = ""
self.lastGameVersion: ShortVersion = ShortVersion()
def make(self) -> Dict:
self.params = [
@ -29,7 +29,7 @@ class UserStatusGetV1Response(BaseResponse):
self.profileStatus.value,
[
self.versionStatus.value,
self.lastGameVersion
str(self.lastGameVersion)
]
]
@ -65,11 +65,11 @@ class UserStatusGetDetailResponseV1(BaseResponse):
self.userItems: UserItemInfoV1 = UserItemInfoV1()
self.scores: List[BestScoreDetailV1] = []
self.songPlayStatus: List[int] = [0,0]
self.seasonInfo: SeasonalInfoV1 = []
self.seasonInfo: SeasonalInfoV1 = SeasonalInfoV1()
self.playAreaList: List = [ [0],[0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0],[0,0,0,0],[0,0,0,0,0,0,0],[0] ]
self.songUpdateTime: int = 0
def make(self) -> List:
def make(self)-> Dict:
opts = []
play_modes = []
scores = []
@ -97,7 +97,7 @@ class UserStatusGetDetailResponseV1(BaseResponse):
return super().make()
def find_score_idx(self, song_id: int, difficulty: int = 1, start_idx: int = 0, stop_idx: int = None) -> Optional[int]:
def find_score_idx(self, song_id: int, difficulty: int = 1, start_idx: int = 0, stop_idx: Optional[int] = None) -> Optional[int]:
if stop_idx is None or stop_idx > len(self.scores):
stop_idx = len(self.scores)
@ -122,7 +122,7 @@ class UserStatusGetDetailResponseV2(UserStatusGetDetailResponseV1):
self.gatchaInfo: List[GachaInfo] = []
self.friendList: List[FriendDetail] = []
def make(self) -> List:
def make(self)-> Dict:
super().make()
gates = []
friends = []
@ -164,7 +164,7 @@ class UserStatusGetDetailResponseV4(UserStatusGetDetailResponseV3):
self.bingoStatus: BingoDetail = BingoDetail(0)
self.scores: List[BestScoreDetailV2] = []
def make(self) -> List:
def make(self)-> Dict:
super().make()
self.params.append(self.bingoStatus.make())
@ -187,7 +187,8 @@ class UserStatusLoginResponseV1(BaseResponse):
self.firstLoginDaily = is_first_login_daily
self.lastLoginDate = last_login_date
def make(self) -> List:
def make(self)-> Dict:
super().make()
daily = []
consec = []
other = []
@ -205,25 +206,24 @@ class UserStatusLoginResponseV1(BaseResponse):
return super().make()
class UserStatusLoginResponseV2(UserStatusLoginResponseV1):
vipInfo: VipInfo
lastLoginDate: int = 0
def __init__(self, is_first_login_daily: bool = False, last_login_date: int = 0) -> None:
super().__init__(is_first_login_daily)
self.lastLoginDate = last_login_date
self.vipInfo = VipInfo()
def make(self) -> List:
def make(self)-> Dict:
super().make()
self.params.append(self.vipInfo.make())
self.params.append(self.lastLoginDate)
return super(UserStatusLoginResponseV1, self).make()
class UserStatusLoginResponseV3(UserStatusLoginResponseV2):
unk: List = []
def __init__(self, is_first_login_daily: bool = False, last_login_date: int = 0) -> None:
super().__init__(is_first_login_daily, last_login_date)
self.unk: List = []
def make(self) -> List:
def make(self)-> Dict:
super().make()
self.params.append(self.unk)
return super(UserStatusLoginResponseV1, self).make()
@ -242,7 +242,7 @@ class UserStatusCreateResponseV1(BaseResponse):
self.userStatus.userId = userId
self.userStatus.username = username
def make(self) -> List:
def make(self)-> Dict:
self.params = [
self.userStatus.make()
]

View File

@ -1,6 +1,6 @@
from typing import Dict, List
from titles.wacca.handlers.base import BaseRequest, BaseResponse
from titles.wacca.handlers.helpers import StageInfo, StageupClearType
from titles.wacca.handlers.helpers import StageInfo, StageupClearType, GenericItemRecv
# --user/trial/get--
class UserTrialGetRequest(BaseRequest):
@ -28,15 +28,18 @@ class UserTrialGetResponse(BaseResponse):
class UserTrialUpdateRequest(BaseRequest):
def __init__(self, data: Dict) -> None:
super().__init__(data)
self.profileId = self.params[0]
self.stageId = self.params[1]
self.stageLevel = self.params[2]
self.profileId: int = self.params[0]
self.stageId: int = self.params[1]
self.stageLevel: int = self.params[2]
self.clearType = StageupClearType(self.params[3])
self.songScores = self.params[4]
self.numSongsCleared = self.params[5]
self.itemsObtained = self.params[6]
self.songScores: List[int] = self.params[4]
self.numSongsCleared: int = self.params[5]
self.itemsObtained: List[GenericItemRecv] = []
self.unk7: List = []
for x in self.params[6]:
self.itemsObtained.append(GenericItemRecv(x[0], x[1], x[2]))
if len(self.params) == 8:
self.unk7 = self.params[7]

View File

@ -18,6 +18,7 @@ from titles.wacca.lily import WaccaLily
from titles.wacca.s import WaccaS
from titles.wacca.base import WaccaBase
from titles.wacca.handlers.base import BaseResponse
from titles.wacca.handlers.helpers import Version
class WaccaServlet():
def __init__(self, core_cfg: CoreConfig, cfg_dir: str) -> None:
@ -55,12 +56,10 @@ class WaccaServlet():
hash = md5(json.dumps(resp, ensure_ascii=False).encode()).digest()
request.responseHeaders.addRawHeader(b"X-Wacca-Hash", hash.hex().encode())
return json.dumps(resp).encode()
version_full = []
try:
req_json = json.loads(request.content.getvalue())
version_full = req_json["appVersion"].split(".")
version_full = Version(req_json["appVersion"])
except:
self.logger.error(f"Failed to parse request toi {request.uri} -> {request.content.getvalue()}")
resp = BaseResponse()
@ -76,7 +75,7 @@ class WaccaServlet():
func_to_find += f"{url_split[x + start_req_idx]}_"
func_to_find += "request"
ver_search = (int(version_full[0]) * 10000) + (int(version_full[1]) * 100) + int(version_full[2])
ver_search = int(version_full)
if ver_search < 15000:
internal_ver = WaccaConstants.VER_WACCA

View File

@ -17,29 +17,43 @@ class WaccaLily(WaccaS):
self.OPTIONS_DEFAULTS["set_nav_id"] = 210002
self.allowed_stages = [
(2001, 1),
(2002, 2),
(2003, 3),
(2004, 4),
(2005, 5),
(2006, 6),
(2007, 7),
(2008, 8),
(2009, 9),
(2010, 10),
(2011, 11),
(2012, 12),
(2013, 13),
(2014, 14),
(2013, 13),
(2012, 12),
(2011, 11),
(2010, 10),
(2009, 9),
(2008, 8),
(2007, 7),
(2006, 6),
(2005, 5),
(2004, 4),
(2003, 3),
(2002, 2),
(2001, 1),
(210001, 0),
(210002, 0),
(210003, 0),
]
def handle_advertise_GetNews_request(self, data: Dict)-> Dict:
resp = GetNewsResponseV3()
return resp.make()
def handle_user_status_get_request(self, data: Dict) -> List[Any]:
def handle_housing_start_request(self, data: Dict) -> Dict:
req = HousingStartRequestV2(data)
if req.appVersion.country != "JPN" and req.appVersion.country in [region.name for region in WaccaConstants.Region]:
region_id = WaccaConstants.Region[req.appVersion.country]
else:
region_id = self.region_id
resp = HousingStartResponseV1(region_id)
return resp.make()
def handle_user_status_get_request(self, data: Dict)-> Dict:
req = UserStatusGetRequest(data)
resp = UserStatusGetV2Response()
ver_split = req.appVersion.split(".")
profile = self.data.profile.get_profile(aime_id=req.aimeId)
if profile is None:
@ -49,11 +63,9 @@ class WaccaLily(WaccaS):
self.logger.info(f"User preview for {req.aimeId} from {req.chipId}")
if profile["last_game_ver"] is None:
profile_ver_split = ver_split
resp.lastGameVersion = req.appVersion
resp.lastGameVersion = ShortVersion(str(req.appVersion))
else:
profile_ver_split = profile["last_game_ver"].split(".")
resp.lastGameVersion = profile["last_game_ver"]
resp.lastGameVersion = ShortVersion(profile["last_game_ver"])
resp.userStatus.userId = profile["id"]
resp.userStatus.username = profile["username"]
@ -83,26 +95,11 @@ class WaccaLily(WaccaS):
if profile["last_login_date"].timestamp() < int((datetime.now().replace(hour=0,minute=0,second=0,microsecond=0) - timedelta(days=1)).timestamp()):
resp.userStatus.loginConsecutiveDays = 0
if int(ver_split[0]) > int(profile_ver_split[0]):
if req.appVersion > resp.lastGameVersion:
resp.versionStatus = PlayVersionStatus.VersionUpgrade
elif int(ver_split[0]) < int(profile_ver_split[0]):
resp.versionStatus = PlayVersionStatus.VersionTooNew
else:
if int(ver_split[1]) > int(profile_ver_split[1]):
resp.versionStatus = PlayVersionStatus.VersionUpgrade
elif int(ver_split[1]) < int(profile_ver_split[1]):
resp.versionStatus = PlayVersionStatus.VersionTooNew
else:
if int(ver_split[2]) > int(profile_ver_split[2]):
resp.versionStatus = PlayVersionStatus.VersionUpgrade
elif int(ver_split[2]) < int(profile_ver_split[2]):
resp.versionStatus = PlayVersionStatus.VersionTooNew
elif req.appVersion < resp.lastGameVersion:
resp.versionStatus = PlayVersionStatus.VersionTooNew
if profile["vip_expire_time"] is not None:
resp.userStatus.vipExpireTime = int(profile["vip_expire_time"].timestamp())
@ -115,7 +112,7 @@ class WaccaLily(WaccaS):
return resp.make()
def handle_user_status_login_request(self, data: Dict) -> List[Any]:
def handle_user_status_login_request(self, data: Dict)-> Dict:
req = UserStatusLoginRequest(data)
resp = UserStatusLoginResponseV2()
is_new_day = False
@ -156,10 +153,9 @@ class WaccaLily(WaccaS):
return resp.make()
def handle_user_status_getDetail_request(self, data: Dict) -> List[Any]:
def handle_user_status_getDetail_request(self, data: Dict)-> Dict:
req = UserStatusGetDetailRequest(data)
ver_split = req.appVersion.split(".")
if int(ver_split[1]) >= 53:
if req.appVersion.minor >= 53:
resp = UserStatusGetDetailResponseV3()
else:
resp = UserStatusGetDetailResponseV2()
@ -232,7 +228,7 @@ class WaccaLily(WaccaS):
for user_gate in profile_gates:
if user_gate["gate_id"] == gate:
if int(ver_split[1]) >= 53:
if req.appVersion.minor >= 53:
resp.gateInfo.append(GateDetailV2(user_gate["gate_id"],user_gate["page"],user_gate["progress"],
user_gate["loops"],int(user_gate["last_used"].timestamp()),user_gate["mission_flag"]))
@ -246,7 +242,7 @@ class WaccaLily(WaccaS):
break
if not added_gate:
if int(ver_split[1]) >= 53:
if req.appVersion.minor >= 53:
resp.gateInfo.append(GateDetailV2(gate))
else:
@ -255,13 +251,9 @@ class WaccaLily(WaccaS):
for unlock in profile_song_unlocks:
for x in range(1, unlock["highest_difficulty"] + 1):
resp.userItems.songUnlocks.append(SongUnlock(unlock["song_id"], x, 0, int(unlock["acquire_date"].timestamp())))
if x > 2:
resp.scores.append(BestScoreDetailV1(unlock["song_id"], x))
empty_scores = len(resp.scores)
for song in profile_scores:
resp.seasonInfo.cumulativeScore += song["score"]
empty_score_idx = resp.find_score_idx(song["song_id"], song["chart_id"], 0, empty_scores)
clear_cts = SongDetailClearCounts(
song["play_ct"],
@ -277,24 +269,16 @@ class WaccaLily(WaccaS):
song["grade_master_ct"]
)
if empty_score_idx is not None:
resp.scores[empty_score_idx].clearCounts = clear_cts
resp.scores[empty_score_idx].clearCountsSeason = clear_cts
resp.scores[empty_score_idx].gradeCounts = grade_cts
resp.scores[empty_score_idx].score = song["score"]
resp.scores[empty_score_idx].bestCombo = song["best_combo"]
resp.scores[empty_score_idx].lowestMissCtMaybe = song["lowest_miss_ct"]
resp.scores[empty_score_idx].rating = song["rating"]
else:
deets = BestScoreDetailV1(song["song_id"], song["chart_id"])
deets.clearCounts = clear_cts
deets.clearCountsSeason = clear_cts
deets.gradeCounts = grade_cts
deets.score = song["score"]
deets.bestCombo = song["best_combo"]
deets.lowestMissCtMaybe = song["lowest_miss_ct"]
deets.rating = song["rating"]
deets = BestScoreDetailV1(song["song_id"], song["chart_id"])
deets.clearCounts = clear_cts
deets.clearCountsSeason = clear_cts
deets.gradeCounts = grade_cts
deets.score = song["score"]
deets.bestCombo = song["best_combo"]
deets.lowestMissCtMaybe = song["lowest_miss_ct"]
deets.rating = song["rating"]
resp.scores.append(deets)
for trophy in profile_trophies:
resp.userItems.trophies.append(TrophyItem(trophy["trophy_id"], trophy["season"], trophy["progress"], trophy["badge_type"]))
@ -348,4 +332,14 @@ class WaccaLily(WaccaS):
resp.seasonInfo.noteSoundsObtained = len(resp.userItems.noteSounds)
resp.seasonInfo.platesObtained = len(resp.userItems.plates)
return resp.make()
return resp.make()
def handle_user_info_getMyroom_request(self, data: Dict)-> Dict:
return UserInfogetMyroomResponseV2().make()
def handle_user_status_update_request(self, data: Dict)-> Dict:
super().handle_user_status_update_request(data)
req = UserStatusUpdateRequestV2(data)
self.data.profile.update_profile_lastplayed(req.profileId, req.lastSongInfo.lastSongId, req.lastSongInfo.lastSongDiff,
req.lastSongInfo.lastFolderOrd, req.lastSongInfo.lastFolderId, req.lastSongInfo.lastSongOrd)
return BaseResponse().make()

View File

@ -16,26 +16,26 @@ class WaccaLilyR(WaccaLily):
self.OPTIONS_DEFAULTS["set_nav_id"] = 210002
self.allowed_stages = [
(2501, 1),
(2502, 2),
(2503, 3),
(2504, 4),
(2505, 5),
(2506, 6),
(2507, 7),
(2508, 8),
(2509, 9),
(2510, 10),
(2511, 11),
(2512, 12),
(2513, 13),
(2514, 14),
(2513, 13),
(2512, 12),
(2511, 11),
(2510, 10),
(2509, 9),
(2508, 8),
(2507, 7),
(2506, 6),
(2505, 5),
(2504, 4),
(2503, 3),
(2501, 2),
(2501, 1),
(210001, 0),
(210002, 0),
(210003, 0),
]
def handle_user_status_create_request(self, data: Dict) -> List[Any]:
def handle_user_status_create_request(self, data: Dict)-> Dict:
req = UserStatusCreateRequest(data)
resp = super().handle_user_status_create_request(data)
@ -50,5 +50,5 @@ class WaccaLilyR(WaccaLily):
return resp
def handle_user_status_logout_request(self, data: Dict) -> List[Any]:
def handle_user_status_logout_request(self, data: Dict)-> Dict:
return BaseResponse().make()

View File

@ -18,20 +18,20 @@ class WaccaReverse(WaccaLilyR):
self.OPTIONS_DEFAULTS["set_nav_id"] = 310001
self.allowed_stages = [
(3001, 1),
(3002, 2),
(3003, 3),
(3004, 4),
(3005, 5),
(3006, 6),
(3007, 7),
(3008, 8),
(3009, 9),
(3010, 10),
(3011, 11),
(3012, 12),
(3013, 13),
(3014, 14),
(3013, 13),
(3012, 12),
(3011, 11),
(3010, 10),
(3009, 9),
(3008, 8),
(3007, 7),
(3006, 6),
(3005, 5),
(3004, 4),
(3003, 3),
(3002, 2),
(3001, 1),
# Touhou
(210001, 0),
(210002, 0),
@ -46,12 +46,12 @@ class WaccaReverse(WaccaLilyR):
(310006, 0),
]
def handle_user_status_login_request(self, data: Dict) -> List[Any]:
def handle_user_status_login_request(self, data: Dict)-> Dict:
resp = super().handle_user_status_login_request(data)
resp["params"].append([])
return resp
def handle_user_status_getDetail_request(self, data: Dict) -> List[Any]:
def handle_user_status_getDetail_request(self, data: Dict)-> Dict:
req = UserStatusGetDetailRequest(data)
resp = UserStatusGetDetailResponseV4()
@ -148,13 +148,9 @@ class WaccaReverse(WaccaLilyR):
for unlock in profile_song_unlocks:
for x in range(1, unlock["highest_difficulty"] + 1):
resp.userItems.songUnlocks.append(SongUnlock(unlock["song_id"], x, 0, int(unlock["acquire_date"].timestamp())))
if x > 2:
resp.scores.append(BestScoreDetailV2(unlock["song_id"], x))
empty_scores = len(resp.scores)
for song in profile_scores:
resp.seasonInfo.cumulativeScore += song["score"]
empty_score_idx = resp.find_score_idx(song["song_id"], song["chart_id"], 0, empty_scores)
clear_cts = SongDetailClearCounts(
song["play_ct"],
@ -167,28 +163,19 @@ class WaccaReverse(WaccaLilyR):
grade_cts = SongDetailGradeCountsV2(
song["grade_d_ct"], song["grade_c_ct"], song["grade_b_ct"], song["grade_a_ct"], song["grade_aa_ct"],
song["grade_aaa_ct"], song["grade_s_ct"], song["grade_ss_ct"], song["grade_sss_ct"],
song["grade_master_ct"], song["grade_sp_ct"], song["grade_ssp_ct"], song["grade_sssp_ct"]
song["grade_master_ct"], song["grade_sp_ct"], song["grade_ssp_ct"], song["grade_sssp_ct"]
)
if empty_score_idx is not None:
resp.scores[empty_score_idx].clearCounts = clear_cts
resp.scores[empty_score_idx].clearCountsSeason = clear_cts
resp.scores[empty_score_idx].gradeCounts = grade_cts
resp.scores[empty_score_idx].score = song["score"]
resp.scores[empty_score_idx].bestCombo = song["best_combo"]
resp.scores[empty_score_idx].lowestMissCtMaybe = song["lowest_miss_ct"]
resp.scores[empty_score_idx].rating = song["rating"]
else:
deets = BestScoreDetailV2(song["song_id"], song["chart_id"])
deets.clearCounts = clear_cts
deets.clearCountsSeason = clear_cts
deets.gradeCounts = grade_cts
deets.score = song["score"]
deets.bestCombo = song["best_combo"]
deets.lowestMissCtMaybe = song["lowest_miss_ct"]
deets.rating = song["rating"]
resp.scores.append(deets)
deets = BestScoreDetailV2(song["song_id"], song["chart_id"])
deets.clearCounts = clear_cts
deets.clearCountsSeason = clear_cts
deets.gradeCounts = grade_cts
deets.score = song["score"]
deets.bestCombo = song["best_combo"]
deets.lowestMissCtMaybe = song["lowest_miss_ct"]
deets.rating = song["rating"]
resp.scores.append(deets)
for trophy in profile_trophies:
resp.userItems.trophies.append(TrophyItem(trophy["trophy_id"], trophy["season"], trophy["progress"], trophy["badge_type"]))
@ -247,7 +234,7 @@ class WaccaReverse(WaccaLilyR):
return resp.make()
def handle_user_status_create_request(self, data: Dict) -> List[Any]:
def handle_user_status_create_request(self, data: Dict)-> Dict:
req = UserStatusCreateRequest(data)
resp = super().handle_user_status_create_request(data)

View File

@ -11,25 +11,25 @@ from titles.wacca.handlers import *
class WaccaS(WaccaBase):
allowed_stages = [
(1501, 1),
(1502, 2),
(1503, 3),
(1504, 4),
(1505, 5),
(1506, 6),
(1507, 7),
(1508, 8),
(1509, 9),
(1510, 10),
(1511, 11),
(1512, 12),
(1513, 13),
(1512, 12),
(1511, 11),
(1510, 10),
(1509, 9),
(1508, 8),
(1507, 7),
(1506, 6),
(1505, 5),
(1514, 4),
(1513, 3),
(1512, 2),
(1511, 1),
]
def __init__(self, cfg: CoreConfig, game_cfg: WaccaConfig) -> None:
super().__init__(cfg, game_cfg)
self.version = WaccaConstants.VER_WACCA_S
def handle_advertise_GetNews_request(self, data: Dict) -> List[Any]:
def handle_advertise_GetNews_request(self, data: Dict) -> Dict:
resp = GetNewsResponseV2()
return resp.make()