2022-08-26 12:39:11 +02:00
|
|
|
from fastapi import APIRouter, Request, Response
|
|
|
|
from tinydb import Query, where
|
|
|
|
|
|
|
|
from core_common import core_process_request, core_prepare_response, E
|
|
|
|
from core_database import get_db
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/core", tags=["cardmng"])
|
|
|
|
|
|
|
|
|
|
|
|
def get_target_table(game_id):
|
|
|
|
target_table = {
|
|
|
|
"LDJ": "iidx_profile",
|
|
|
|
"MDX": "ddr_profile",
|
|
|
|
"KFC": "sdvx_profile",
|
2022-10-11 03:30:53 +02:00
|
|
|
"JDZ": "iidx_profile",
|
|
|
|
"KDZ": "iidx_profile",
|
2022-08-26 12:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return target_table[game_id]
|
|
|
|
|
|
|
|
|
|
|
|
def get_profile(game_id, cid):
|
|
|
|
target_table = get_target_table(game_id)
|
2022-11-15 15:03:37 +01:00
|
|
|
profile = get_db().table(target_table).get(where("card") == cid)
|
2022-08-26 12:39:11 +02:00
|
|
|
|
|
|
|
if profile is None:
|
|
|
|
profile = {
|
2022-11-15 15:03:37 +01:00
|
|
|
"card": cid,
|
|
|
|
"version": {},
|
2022-08-26 12:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return profile
|
|
|
|
|
|
|
|
|
|
|
|
def get_game_profile(game_id, game_version, cid):
|
|
|
|
profile = get_profile(game_id, cid)
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
if str(game_version) not in profile["version"]:
|
|
|
|
profile["version"][str(game_version)] = {}
|
2022-08-26 12:39:11 +02:00
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
return profile["version"][str(game_version)]
|
2022-08-26 12:39:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
def create_profile(game_id, game_version, cid, pin):
|
|
|
|
target_table = get_target_table(game_id)
|
|
|
|
profile = get_profile(game_id, cid)
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
profile["pin"] = pin
|
2022-08-26 12:39:11 +02:00
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
get_db().table(target_table).upsert(profile, where("card") == cid)
|
2022-08-26 12:39:11 +02:00
|
|
|
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
@router.post("/{gameinfo}/cardmng/authpass")
|
2022-08-26 12:39:11 +02:00
|
|
|
async def cardmng_authpass(request: Request):
|
|
|
|
request_info = await core_process_request(request)
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
cid = request_info["root"][0].attrib["refid"]
|
|
|
|
passwd = request_info["root"][0].attrib["pass"]
|
2022-08-26 12:39:11 +02:00
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
profile = get_profile(request_info["model"], cid)
|
|
|
|
if profile is None or passwd != profile.get("pin", None):
|
2022-08-26 12:39:11 +02:00
|
|
|
status = 116
|
|
|
|
else:
|
|
|
|
status = 0
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
response = E.response(E.authpass(status=status))
|
2022-08-26 12:39:11 +02:00
|
|
|
|
|
|
|
response_body, response_headers = await core_prepare_response(request, response)
|
|
|
|
return Response(content=response_body, headers=response_headers)
|
|
|
|
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
@router.post("/{gameinfo}/cardmng/bindmodel")
|
2022-08-26 12:39:11 +02:00
|
|
|
async def cardmng_bindmodel(request: Request):
|
|
|
|
request_info = await core_process_request(request)
|
|
|
|
|
|
|
|
response = E.response(
|
|
|
|
E.bindmodel(
|
|
|
|
dataid=1,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
response_body, response_headers = await core_prepare_response(request, response)
|
|
|
|
return Response(content=response_body, headers=response_headers)
|
|
|
|
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
@router.post("/{gameinfo}/cardmng/getrefid")
|
2022-08-26 12:39:11 +02:00
|
|
|
async def cardmng_getrefid(request: Request):
|
|
|
|
request_info = await core_process_request(request)
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
cid = request_info["root"][0].attrib["cardid"]
|
|
|
|
passwd = request_info["root"][0].attrib["passwd"]
|
2022-08-26 12:39:11 +02:00
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
create_profile(request_info["model"], request_info["game_version"], cid, passwd)
|
2022-08-26 12:39:11 +02:00
|
|
|
|
|
|
|
response = E.response(
|
|
|
|
E.getrefid(
|
|
|
|
dataid=cid,
|
|
|
|
refid=cid,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
response_body, response_headers = await core_prepare_response(request, response)
|
|
|
|
return Response(content=response_body, headers=response_headers)
|
|
|
|
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
@router.post("/{gameinfo}/cardmng/inquire")
|
2022-08-26 12:39:11 +02:00
|
|
|
async def cardmng_inquire(request: Request):
|
|
|
|
request_info = await core_process_request(request)
|
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
cid = request_info["root"][0].attrib["cardid"]
|
2022-08-26 12:39:11 +02:00
|
|
|
|
2022-11-15 15:03:37 +01:00
|
|
|
profile = get_game_profile(request_info["model"], request_info["game_version"], cid)
|
2022-08-26 12:39:11 +02:00
|
|
|
if profile:
|
|
|
|
binded = 1
|
|
|
|
newflag = 0
|
|
|
|
status = 0
|
|
|
|
else:
|
|
|
|
binded = 0
|
|
|
|
newflag = 1
|
|
|
|
status = 112
|
|
|
|
|
|
|
|
response = E.response(
|
|
|
|
E.inquire(
|
|
|
|
dataid=cid,
|
|
|
|
ecflag=1,
|
|
|
|
expired=0,
|
|
|
|
binded=binded,
|
|
|
|
newflag=newflag,
|
|
|
|
refid=cid,
|
|
|
|
status=status,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
response_body, response_headers = await core_prepare_response(request, response)
|
|
|
|
return Response(content=response_body, headers=response_headers)
|