diff --git a/data/masterdata/live.db b/data/masterdata/live.db new file mode 100644 index 0000000..723ddd3 Binary files /dev/null and b/data/masterdata/live.db differ diff --git a/sif/__init__.py b/sif/__init__.py index b3f8bbd..bff6a08 100644 --- a/sif/__init__.py +++ b/sif/__init__.py @@ -1,15 +1,19 @@ from sanic import Blueprint +from .api import bp_sif_api from .login import bp_sif_login from .user import bp_sif_user from .misc import bp_sif_misc from .download import bp_sif_download -from .api import bp_sif_api +from .live import bp_sif_live +from .unit import bp_sif_unit bp_sif = Blueprint.group(bp_sif_login, bp_sif_user, bp_sif_misc, bp_sif_download, bp_sif_api, + bp_sif_live, + bp_sif_unit, url_prefix="main.php") diff --git a/sif/common.py b/sif/common.py index 9f471ed..e9f4237 100644 --- a/sif/common.py +++ b/sif/common.py @@ -53,5 +53,6 @@ async def pack_resp(f, *args, **kw): }) + def common_api(f): return check_token(parse_data(pack_resp(f))) \ No newline at end of file diff --git a/sif/download.py b/sif/download.py index 5203657..16f1cf6 100644 --- a/sif/download.py +++ b/sif/download.py @@ -36,7 +36,7 @@ async def batch(request: Request): request_data = request.ctx.request_data static_root = Sanic.get_app().config["STATIC_ROOT"] - download_resp = [] + resp = [] if request_data.get("client_version", "") == Sanic.get_app().config["PACKAGE_VERSION"]: # 97.4.6 package_type = request_data.get("package_type", 0) excluded_package_ids = request_data.get("excluded_package_ids", []) @@ -46,11 +46,11 @@ async def batch(request: Request): if package_id in excluded_package_ids: continue package_order_list.sort(key=lambda x: x[0]) for package_order, package_size in package_order_list: - download_resp.append({ + resp.append({ "size": package_size, "url": f"{static_root}/{os}/{package_type}_{package_id}_{package_order}.zip" }) - return download_resp + return resp @@ -62,19 +62,19 @@ async def update(request: Request): version = Sanic.get_app().config["PACKAGE_VERSION"] target_os = request_data.get("target_os", "") - download_resp = [] + resp = [] if request_data.get("external_version", "") != version: # 97.4.6 package_type = 99 package_dict = Sanic.get_app().ctx.assets_list[target_os][package_type] for package_id, package_order_list in package_dict.items(): package_order_list.sort(key=lambda x: x[0]) for package_order, package_size in package_order_list: - download_resp.append({ + resp.append({ "size": package_size, "url": f"{static_root}/{target_os}/{package_type}_{package_id}_{package_order}.zip", "version": version }) - return download_resp + return resp diff --git a/sif/live.py b/sif/live.py new file mode 100644 index 0000000..c3a6248 --- /dev/null +++ b/sif/live.py @@ -0,0 +1,74 @@ +from sanic import Blueprint, Request + +import time + +from .common import common_api +from utils.masterdata import get_masterdata + + +bp_sif_live = Blueprint("sif_live", url_prefix="live") + + + +@bp_sif_live.route("liveStatus", methods=["POST"]) +@common_api +async def liveStatus(request: Request): + normal_live_status_list = [] + live_difficulty_id = get_masterdata("live.db", "normal_live_m", ["live_difficulty_id"]) + for t in live_difficulty_id: + normal_live_status_list.append({ + "live_difficulty_id": t[0], + "status": 1, + "hi_score": 0, + "hi_combo_count": 0, + "clear_cnt": 0, + "achieved_goal_id_list": [] + }) + + special_live_status_list = [] + live_difficulty_id = get_masterdata("live.db", "special_live_m", ["live_difficulty_id"]) + for t in live_difficulty_id: + special_live_status_list.append({ + "live_difficulty_id": t[0], + "status": 1, + "hi_score": 0, + "hi_combo_count": 0, + "clear_cnt": 0, + "achieved_goal_id_list": [] + }) + + resp = { + "normal_live_status_list": normal_live_status_list, + "special_live_status_list": special_live_status_list, + "training_live_status_list": [], + "marathon_live_status_list": [], + "free_live_status_list": [], + "can_resume_live": True + } + return resp + + + +@bp_sif_live.route("schedule", methods=["POST"]) +@common_api +async def schedule(request: Request): + live_list = [] + live_difficulty_id = get_masterdata("live.db", "special_live_m", ["live_difficulty_id"]) + for t in live_difficulty_id: + live_list.append({ + "live_difficulty_id": 46, + "start_date": "2000-01-01 00:00:00", + "end_date": "2099-01-01 00:00:00", + "is_random": False + }) + resp = { + "event_list": [], + "live_list": live_list, + "limited_bonus_list": [], + "limited_bonus_common_list": [], + "random_live_list": [], + "free_live_list": [], + "training_live_list": [] + } + return resp + diff --git a/sif/login.py b/sif/login.py index 0ed5cd2..938c9b3 100644 --- a/sif/login.py +++ b/sif/login.py @@ -40,11 +40,11 @@ async def authkey(request: Request): # f"version=1.1&nonce={nonce}&" # f"requestTimeStamp={int(time.time())}") - auth_resp = { + resp = { "authorize_token": authorize_token, "dummy_token": server_token } - return auth_resp + return resp @@ -76,7 +76,7 @@ async def login(request: Request): ctx = Sanic.get_app().ctx if not hasattr(ctx, "auth_token"): ctx.auth_token = {} ctx.auth_token[user.user_id] = new_authorize_token - login_resp = { + resp = { "authorize_token": new_authorize_token, "user_id": user.user_id, "review_version": "", @@ -85,5 +85,5 @@ async def login(request: Request): "skip_login_news": False, "adult_flag": 2 } - return login_resp + return resp diff --git a/sif/misc.py b/sif/misc.py index d6ee155..8f5c49b 100644 --- a/sif/misc.py +++ b/sif/misc.py @@ -13,12 +13,12 @@ bp_sif_misc = Blueprint("sif_misc") @bp_sif_misc.route("/gdpr/get", methods=["POST"]) @common_api async def gdpr_get(request: Request): - gdpr_resp = { + resp = { "enable_gdpr": True, "is_eea": False, "server_timestamp": int(time.time()) } - return gdpr_resp + return resp @@ -39,7 +39,7 @@ async def lbonus_execute(request: Request): } } - lbonus_resp = { + resp = { "sheets": [], "calendar_info": { "current_date": "2006-01-02 03:04:05", @@ -87,14 +87,14 @@ async def lbonus_execute(request: Request): "server_timestamp": int(time.time()), "present_cnt": 0, } - return lbonus_resp + return resp @bp_sif_misc.route("/personalnotice/get", methods=["POST"]) @common_api async def personalnotice_get(request: Request): - notice_resp = { + resp = { "has_notice": False, "notice_id": 0, "type": 0, @@ -102,7 +102,7 @@ async def personalnotice_get(request: Request): "contents": "", "server_timestamp": int(time.time()), } - return notice_resp + return resp @bp_sif_misc.route("/personalnotice/agree", methods=["POST"]) @common_api @@ -113,16 +113,16 @@ async def personalnotice_agree(request: Request): @bp_sif_misc.route("/tos/tosCheck", methods=["POST"]) @common_api -async def tos_toscheck(request: Request): - notice_resp = { +async def tos_tosCheck(request: Request): + resp = { "tos_id": 1, "tos_type": 1, "is_agreed": True, "server_timestamp": int(time.time()), } - return notice_resp + return resp @bp_sif_misc.route("/tos/tosAgree", methods=["POST"]) @common_api -async def tos_tosagree(request: Request): +async def tos_tosAgree(request: Request): return {} \ No newline at end of file diff --git a/sif/module_template.py b/sif/module_template.py new file mode 100644 index 0000000..481318a --- /dev/null +++ b/sif/module_template.py @@ -0,0 +1,17 @@ +from sanic import Blueprint, Request + +import time + +from .common import common_api + + + +bp_sif_name = Blueprint("sif_name", url_prefix="name") + + + +@bp_sif_name.route("", methods=["POST"]) +@common_api +async def _(request: Request): + resp = {} + return resp \ No newline at end of file diff --git a/sif/unit.py b/sif/unit.py new file mode 100644 index 0000000..b3cc37f --- /dev/null +++ b/sif/unit.py @@ -0,0 +1,52 @@ +from sanic import Blueprint, Request + +import time + +from .common import common_api + + + +bp_sif_unit = Blueprint("sif_unit", url_prefix="unit") + + + +@bp_sif_unit.route("unitAll", methods=["POST"]) +@common_api +async def unitAll(request: Request): + + ### TODO - PLACEHOLDER ### + + active = [] + for i in range(9): + active.append({ + "unit_owning_user_id": 38383+i, + "unit_id": i+1, + "exp": 8000, + "next_exp": 0, + "level": 40, + "max_level": 40, + "level_limit_id": 0, + "rank": 1, + "max_rank": 2, + "love": 50, + "max_love": 50, + "unit_skill_exp": 0, + "unit_skill_level": 0, + "max_hp": 3, + "unit_removable_skill_capacity": 0, + "favorite_flag": False, + "display_rank": 2, + "is_rank_max": False, + "is_love_max": False, + "is_level_max": False, + "is_signed": False, + "is_skill_level_max": False, + "is_removable_skill_capacity_max": False, + "insert_date": "2023-03-13 11:47:24" + }) + + resp = { + "active": active, + "waiting": [] + } + return resp \ No newline at end of file diff --git a/sif/user.py b/sif/user.py index 9c4b404..6dc5c42 100644 --- a/sif/user.py +++ b/sif/user.py @@ -13,7 +13,7 @@ bp_sif_user = Blueprint("sif_user", url_prefix="user") @bp_sif_user.route("userInfo", methods=["POST"]) @common_api async def userinfo(request: Request): - userinfo_resp = { + resp = { "user": { "user_id": request.ctx.user_id, "name": "wlt233", @@ -50,4 +50,4 @@ async def userinfo(request: Request): }, "server_timestamp": int(time.time()) } - return userinfo_resp \ No newline at end of file + return resp \ No newline at end of file diff --git a/utils/masterdata.py b/utils/masterdata.py new file mode 100644 index 0000000..cf7adc3 --- /dev/null +++ b/utils/masterdata.py @@ -0,0 +1,9 @@ +import sqlite3 + +def get_masterdata(db: str, table: str, columns: list[str]) -> list[tuple]: + con = sqlite3.connect(f"./data/masterdata/{db}") + cur = con.cursor() + query = f"select {','.join(columns)} from {table}" + res = cur.execute(query).fetchall() + con.close() + return res \ No newline at end of file