diff --git a/core/__init__.py b/core/__init__.py
index c72ba0a..717de33 100644
--- a/core/__init__.py
+++ b/core/__init__.py
@@ -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
\ No newline at end of file
diff --git a/core/allnet.py b/core/allnet.py
index bd2ecce..c938a88 100644
--- a/core/allnet.py
+++ b/core/allnet.py
@@ -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)
diff --git a/core/config.py b/core/config.py
index f8f57e4..04ad280 100644
--- a/core/config.py
+++ b/core/config.py
@@ -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):
diff --git a/core/const.py b/core/const.py
index f5979e8..3a2c116 100644
--- a/core/const.py
+++ b/core/const.py
@@ -31,6 +31,61 @@ class KeychipPlatformsCodes():
NU = ("A60E", "A60E", "A60E")
NUSX = ("A61X", "A69X")
ALLS = "A63E"
-
-class RegionIDs(Enum):
- pass
\ No newline at end of file
+
+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
diff --git a/core/data/database.py b/core/data/database.py
index 963d016..70fc3e0 100644
--- a/core/data/database.py
+++ b/core/data/database.py
@@ -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)
diff --git a/core/data/schema/user.py b/core/data/schema/user.py
index 7d76bbe..9e79891 100644
--- a/core/data/schema/user.py
+++ b/core/data/schema/user.py
@@ -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)
\ No newline at end of file
diff --git a/core/data/schema/versions/CORE_1_rollback.sql b/core/data/schema/versions/CORE_1_rollback.sql
new file mode 100644
index 0000000..8a1144b
--- /dev/null
+++ b/core/data/schema/versions/CORE_1_rollback.sql
@@ -0,0 +1,2 @@
+ALTER TABLE `frontend_session`
+DROP COLUMN `ip`;
\ No newline at end of file
diff --git a/core/data/schema/versions/CORE_2_upgrade.sql b/core/data/schema/versions/CORE_2_upgrade.sql
new file mode 100644
index 0000000..44deb6d
--- /dev/null
+++ b/core/data/schema/versions/CORE_2_upgrade.sql
@@ -0,0 +1,2 @@
+ALTER TABLE `frontend_session`
+ADD `ip` CHAR(15);
\ No newline at end of file
diff --git a/core/data/schema/versions/SBZV_1_rollback.sql b/core/data/schema/versions/SBZV_1_rollback.sql
new file mode 100644
index 0000000..a7bccce
--- /dev/null
+++ b/core/data/schema/versions/SBZV_1_rollback.sql
@@ -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;
\ No newline at end of file
diff --git a/core/data/schema/versions/SBZV_2_rollback.sql b/core/data/schema/versions/SBZV_2_rollback.sql
new file mode 100644
index 0000000..5bd46c0
--- /dev/null
+++ b/core/data/schema/versions/SBZV_2_rollback.sql
@@ -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`;
\ No newline at end of file
diff --git a/core/data/schema/versions/SBZV_2_upgrade.sql b/core/data/schema/versions/SBZV_2_upgrade.sql
new file mode 100644
index 0000000..26cb2ed
--- /dev/null
+++ b/core/data/schema/versions/SBZV_2_upgrade.sql
@@ -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;
\ No newline at end of file
diff --git a/core/data/schema/versions/SBZV_3_rollback.sql b/core/data/schema/versions/SBZV_3_rollback.sql
new file mode 100644
index 0000000..18c2448
--- /dev/null
+++ b/core/data/schema/versions/SBZV_3_rollback.sql
@@ -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);
diff --git a/core/data/schema/versions/SBZV_3_upgrade.sql b/core/data/schema/versions/SBZV_3_upgrade.sql
new file mode 100644
index 0000000..a06d7f4
--- /dev/null
+++ b/core/data/schema/versions/SBZV_3_upgrade.sql
@@ -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
+);
diff --git a/core/data/schema/versions/SBZV_4_upgrade.sql b/core/data/schema/versions/SBZV_4_upgrade.sql
new file mode 100644
index 0000000..c3a802c
--- /dev/null
+++ b/core/data/schema/versions/SBZV_4_upgrade.sql
@@ -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);
diff --git a/core/data/schema/versions/SDBT_1_rollback.sql b/core/data/schema/versions/SDBT_1_rollback.sql
new file mode 100644
index 0000000..e8bca83
--- /dev/null
+++ b/core/data/schema/versions/SDBT_1_rollback.sql
@@ -0,0 +1 @@
+ALTER TABLE chuni_static_music CHANGE COLUMN worldsEndTag worldsEndTag VARCHAR(20) NULL DEFAULT NULL ;
diff --git a/core/data/schema/versions/SDBT_2_rollback.sql b/core/data/schema/versions/SDBT_2_rollback.sql
new file mode 100644
index 0000000..de11416
--- /dev/null
+++ b/core/data/schema/versions/SDBT_2_rollback.sql
@@ -0,0 +1 @@
+ALTER TABLE chuni_score_course DROP COLUMN theoryCount, DROP COLUMN orderId, DROP COLUMN playerRating;
diff --git a/core/data/schema/versions/SDBT_2_upgrade.sql b/core/data/schema/versions/SDBT_2_upgrade.sql
new file mode 100644
index 0000000..30f0fc4
--- /dev/null
+++ b/core/data/schema/versions/SDBT_2_upgrade.sql
@@ -0,0 +1 @@
+ALTER TABLE chuni_static_music CHANGE COLUMN worldsEndTag worldsEndTag VARCHAR(7) NULL DEFAULT NULL ;
diff --git a/core/data/schema/versions/SDBT_3_upgrade.sql b/core/data/schema/versions/SDBT_3_upgrade.sql
new file mode 100644
index 0000000..57498cc
--- /dev/null
+++ b/core/data/schema/versions/SDBT_3_upgrade.sql
@@ -0,0 +1 @@
+ALTER TABLE chuni_score_course ADD theoryCount int(11), ADD orderId int(11), ADD playerRating int(11);
diff --git a/core/data/schema/versions/SDEZ_1_rollback.sql b/core/data/schema/versions/SDEZ_1_rollback.sql
new file mode 100644
index 0000000..6ebbab4
--- /dev/null
+++ b/core/data/schema/versions/SDEZ_1_rollback.sql
@@ -0,0 +1,3 @@
+SET FOREIGN_KEY_CHECKS=0;
+ALTER TABLE mai2_playlog DROP COLUMN trialPlayAchievement;
+SET FOREIGN_KEY_CHECKS=1;
\ No newline at end of file
diff --git a/core/data/schema/versions/SDEZ_2_upgrade.sql b/core/data/schema/versions/SDEZ_2_upgrade.sql
new file mode 100644
index 0000000..626cc60
--- /dev/null
+++ b/core/data/schema/versions/SDEZ_2_upgrade.sql
@@ -0,0 +1,3 @@
+SET FOREIGN_KEY_CHECKS=0;
+ALTER TABLE mai2_playlog ADD trialPlayAchievement INT NULL;
+SET FOREIGN_KEY_CHECKS=1;
\ No newline at end of file
diff --git a/core/frontend.py b/core/frontend.py
new file mode 100644
index 0000000..780698e
--- /dev/null
+++ b/core/frontend.py
@@ -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)
\ No newline at end of file
diff --git a/core/frontend/gate/create.jinja b/core/frontend/gate/create.jinja
new file mode 100644
index 0000000..f8b5e51
--- /dev/null
+++ b/core/frontend/gate/create.jinja
@@ -0,0 +1,24 @@
+{% extends "core/frontend/index.jinja" %}
+{% block content %}
+
Create User
+
+{% endblock content %}
\ No newline at end of file
diff --git a/core/frontend/gate/gate.jinja b/core/frontend/gate/gate.jinja
new file mode 100644
index 0000000..760fbab
--- /dev/null
+++ b/core/frontend/gate/gate.jinja
@@ -0,0 +1,17 @@
+{% extends "core/frontend/index.jinja" %}
+{% block content %}
+
Gate
+{% include "core/frontend/widgets/err_banner.jinja" %}
+
+{% endblock content %}
\ No newline at end of file
diff --git a/core/frontend/index.jinja b/core/frontend/index.jinja
new file mode 100644
index 0000000..7e4a1ca
--- /dev/null
+++ b/core/frontend/index.jinja
@@ -0,0 +1,88 @@
+
+
+
+ {{ title }}
+
+
+
+
+
+ {% include "core/frontend/widgets/topbar.jinja" %}
+ {% block content %}
+
{{ server_name }}
+ {% endblock content %}
+
+
\ No newline at end of file
diff --git a/core/frontend/user/index.jinja b/core/frontend/user/index.jinja
new file mode 100644
index 0000000..eabdd18
--- /dev/null
+++ b/core/frontend/user/index.jinja
@@ -0,0 +1,4 @@
+{% extends "core/frontend/index.jinja" %}
+{% block content %}
+
testing
+{% endblock content %}
\ No newline at end of file
diff --git a/core/frontend/widgets/err_banner.jinja b/core/frontend/widgets/err_banner.jinja
new file mode 100644
index 0000000..23af92d
--- /dev/null
+++ b/core/frontend/widgets/err_banner.jinja
@@ -0,0 +1,14 @@
+{% if error > 0 %}
+
+
Error
+{% 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 %}
+
+{% endif %}
\ No newline at end of file
diff --git a/core/frontend/widgets/topbar.jinja b/core/frontend/widgets/topbar.jinja
new file mode 100644
index 0000000..6bef3e3
--- /dev/null
+++ b/core/frontend/widgets/topbar.jinja
@@ -0,0 +1,13 @@
+
+ Navigation
+
+
+
+ {% for game in game_list %}
+
+ {% endfor %}
+
+
+
+
+
\ No newline at end of file
diff --git a/core/mucha.py b/core/mucha.py
index 312d83f..0848c70 100644
--- a/core/mucha.py
+++ b/core/mucha.py
@@ -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))
diff --git a/core/title.py b/core/title.py
index dd47ec8..6c54450 100644
--- a/core/title.py
+++ b/core/title.py
@@ -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"])
diff --git a/core/utils.py b/core/utils.py
index a14f9ff..d4b7f16 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -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
diff --git a/dbutils.py b/dbutils.py
index 8e6024b..d52128e 100644
--- a/dbutils.py
+++ b/dbutils.py
@@ -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":
diff --git a/docs/INSTALL_UBUNTU.md b/docs/INSTALL_UBUNTU.md
new file mode 100644
index 0000000..eaabb0c
--- /dev/null
+++ b/docs/INSTALL_UBUNTU.md
@@ -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
+```
diff --git a/docs/INSTALL_WINDOWS.md b/docs/INSTALL_WINDOWS.md
new file mode 100644
index 0000000..abd1e43
--- /dev/null
+++ b/docs/INSTALL_WINDOWS.md
@@ -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
+```
diff --git a/example_config/diva.yaml b/example_config/diva.yaml
index 1354910..ad1842a 100644
--- a/example_config/diva.yaml
+++ b/example_config/diva.yaml
@@ -2,3 +2,6 @@ server:
enable: True
loglevel: "info"
+mods:
+ unlock_all_modules: True
+ unlock_all_items: True
diff --git a/example_config/nginx_example.conf b/example_config/nginx_example.conf
index 3b8bf3c..096a072 100644
--- a/example_config/nginx_example.conf
+++ b/example_config/nginx_example.conf
@@ -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/;
+ }
}
\ No newline at end of file
diff --git a/example_config/pokken.yaml b/example_config/pokken.yaml
index 967cca6..5523996 100644
--- a/example_config/pokken.yaml
+++ b/example_config/pokken.yaml
@@ -1,8 +1,6 @@
server:
enable: True
loglevel: "info"
- hostname: "localhost"
- ssl_enable: False
port: 9000
port_matching: 9001
ssl_cert: cert/pokken.crt
diff --git a/example_config/wacca.yaml b/example_config/wacca.yaml
index 4c898a4..aea4f16 100644
--- a/example_config/wacca.yaml
+++ b/example_config/wacca.yaml
@@ -1,6 +1,7 @@
server:
enable: True
loglevel: "info"
+ prefecture_name: "Hokkaido"
mods:
always_vip: True
diff --git a/index.py b/index.py
index 0049427..e514b10 100644
--- a/index.py
+++ b/index.py
@@ -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))
diff --git a/read.py b/read.py
index ffc4812..869ad97 100644
--- a/read.py
+++ b/read.py
@@ -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")
diff --git a/requirements.txt b/requirements.txt
index 0536370..ebb17c9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,4 +13,6 @@ coloredlogs
pylibmc; platform_system != "Windows"
wacky
Routes
+bcrypt
+jinja2
protobuf
diff --git a/titles/chuni/new.py b/titles/chuni/new.py
index 909284e..4b5ba2d 100644
--- a/titles/chuni/new.py
+++ b/titles/chuni/new.py
@@ -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",
diff --git a/titles/chuni/newplus.py b/titles/chuni/newplus.py
index c048f8a..7ebdc96 100644
--- a/titles/chuni/newplus.py
+++ b/titles/chuni/newplus.py
@@ -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
diff --git a/titles/chuni/read.py b/titles/chuni/read.py
index dd67c03..1a666e6 100644
--- a/titles/chuni/read.py
+++ b/titles/chuni/read.py
@@ -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)
diff --git a/titles/chuni/schema/score.py b/titles/chuni/schema/score.py
index 353401f..81f3212 100644
--- a/titles/chuni/schema/score.py
+++ b/titles/chuni/schema/score.py
@@ -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'
)
diff --git a/titles/chuni/schema/static.py b/titles/chuni/schema/static.py
index 99dd3e8..fbfae11 100644
--- a/titles/chuni/schema/static.py
+++ b/titles/chuni/schema/static.py
@@ -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'
)
diff --git a/titles/diva/base.py b/titles/diva/base.py
index aef5841..2e788af 100644
--- a/titles/diva/base.py
+++ b/titles/diva/base.py
@@ -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
diff --git a/titles/diva/config.py b/titles/diva/config.py
index aba99f2..af4d626 100644
--- a/titles/diva/config.py
+++ b/titles/diva/config.py
@@ -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)
\ No newline at end of file
+ self.server = DivaServerConfig(self)
+ self.mods = DivaModsConfig(self)
diff --git a/titles/diva/database.py b/titles/diva/database.py
index f43c42e..a7e4193 100644
--- a/titles/diva/database.py
+++ b/titles/diva/database.py
@@ -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)
diff --git a/titles/diva/schema/__init__.py b/titles/diva/schema/__init__.py
index 57431ef..72cd97f 100644
--- a/titles/diva/schema/__init__.py
+++ b/titles/diva/schema/__init__.py
@@ -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]
diff --git a/titles/diva/schema/customize.py b/titles/diva/schema/customize.py
new file mode 100644
index 0000000..f372349
--- /dev/null
+++ b/titles/diva/schema/customize.py
@@ -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:])
diff --git a/titles/diva/schema/item.py b/titles/diva/schema/item.py
index 96d8ca5..ce7d910 100644
--- a/titles/diva/schema/item.py
+++ b/titles/diva/schema/item.py
@@ -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()
\ No newline at end of file
+ if result is None:
+ return None
+ return result.fetchone()
diff --git a/titles/diva/schema/module.py b/titles/diva/schema/module.py
new file mode 100644
index 0000000..f9c930c
--- /dev/null
+++ b/titles/diva/schema/module.py
@@ -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:])
diff --git a/titles/diva/schema/profile.py b/titles/diva/schema/profile.py
index 72d68ed..993b03c 100644
--- a/titles/diva/schema/profile.py
+++ b/titles/diva/schema/profile.py
@@ -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()
diff --git a/titles/diva/schema/pv_customize.py b/titles/diva/schema/pv_customize.py
new file mode 100644
index 0000000..e456e06
--- /dev/null
+++ b/titles/diva/schema/pv_customize.py
@@ -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()
diff --git a/titles/diva/schema/score.py b/titles/diva/schema/score.py
index 6cd0346..638c25a 100644
--- a/titles/diva/schema/score.py
+++ b/titles/diva/schema/score.py
@@ -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()
diff --git a/titles/diva/schema/static.py b/titles/diva/schema/static.py
index 6544420..c8d83bd 100644
--- a/titles/diva/schema/static.py
+++ b/titles/diva/schema/static.py
@@ -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,
diff --git a/titles/mai2/__init__.py b/titles/mai2/__init__.py
index 1c51244..3cc5f97 100644
--- a/titles/mai2/__init__.py
+++ b/titles/mai2/__init__.py
@@ -15,4 +15,4 @@ trailing_slash = True
use_default_host = False
host = ""
-current_schema_version = 1
\ No newline at end of file
+current_schema_version = 2
\ No newline at end of file
diff --git a/titles/mai2/schema/score.py b/titles/mai2/schema/score.py
index 0ef6da4..59a600c 100644
--- a/titles/mai2/schema/score.py
+++ b/titles/mai2/schema/score.py
@@ -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)
diff --git a/titles/pokken/__init__.py b/titles/pokken/__init__.py
index 5be8ac6..3b574fd 100644
--- a/titles/pokken/__init__.py
+++ b/titles/pokken/__init__.py
@@ -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
diff --git a/titles/pokken/config.py b/titles/pokken/config.py
index 1221c08..b6596f2 100644
--- a/titles/pokken/config.py
+++ b/titles/pokken/config.py
@@ -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)
diff --git a/titles/pokken/database.py b/titles/pokken/database.py
new file mode 100644
index 0000000..eff928b
--- /dev/null
+++ b/titles/pokken/database.py
@@ -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)
\ No newline at end of file
diff --git a/titles/pokken/index.py b/titles/pokken/index.py
index d0b3efd..a47cac7 100644
--- a/titles/pokken/index.py
+++ b/titles/pokken/index.py
@@ -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")
diff --git a/titles/wacca/__init__.py b/titles/wacca/__init__.py
index c0351da..41d8dc2 100644
--- a/titles/wacca/__init__.py
+++ b/titles/wacca/__init__.py
@@ -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
diff --git a/titles/wacca/base.py b/titles/wacca/base.py
index 598f1fc..9df231e 100644
--- a/titles/wacca/base.py
+++ b/titles/wacca/base.py
@@ -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:
diff --git a/titles/wacca/config.py b/titles/wacca/config.py
index f5bc235..fc03dd8 100644
--- a/titles/wacca/config.py
+++ b/titles/wacca/config.py
@@ -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
diff --git a/titles/wacca/const.py b/titles/wacca/const.py
index 910f313..a984682 100644
--- a/titles/wacca/const.py
+++ b/titles/wacca/const.py
@@ -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):
diff --git a/titles/wacca/frontend.py b/titles/wacca/frontend.py
new file mode 100644
index 0000000..b7232b8
--- /dev/null
+++ b/titles/wacca/frontend.py
@@ -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")
diff --git a/titles/wacca/frontend/wacca_index.jinja b/titles/wacca/frontend/wacca_index.jinja
new file mode 100644
index 0000000..6a5f046
--- /dev/null
+++ b/titles/wacca/frontend/wacca_index.jinja
@@ -0,0 +1,4 @@
+{% extends "core/frontend/index.jinja" %}
+{% block content %}
+