mirror of
https://gitea.tendokyu.moe/Hay1tsme/artemis.git
synced 2026-02-14 19:57:27 +08:00
diva: add register, fixes, start still busted
This commit is contained in:
@@ -2,6 +2,16 @@ from urllib import parse
|
||||
from datetime import datetime
|
||||
from typing import Union, Dict
|
||||
|
||||
def lazy_http_form_parse(src: Union[str, bytes]) -> Dict[bytes, bytes]:
|
||||
out = {}
|
||||
if type(src) == str:
|
||||
src = src.encode()
|
||||
for param in src.split(b"&"):
|
||||
kvp = param.split(b"=")
|
||||
out[parse.unquote(kvp[0])] = parse.unquote(kvp[1])
|
||||
|
||||
return out
|
||||
|
||||
|
||||
class DivaRequestParseException(Exception):
|
||||
"""
|
||||
@@ -30,7 +40,7 @@ class BaseBinaryRequest:
|
||||
f"req_id not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
for k, v in self.raw_dict:
|
||||
for k, v in self.raw_dict.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
|
||||
@@ -45,53 +55,56 @@ class BaseRequest:
|
||||
|
||||
def __init__(self, raw: Union[str, bytes]) -> None:
|
||||
self.raw = raw
|
||||
self.raw_dict: Dict[bytes, bytes] = dict(parse.parse_qsl(raw))
|
||||
try:
|
||||
self.raw_dict: Dict[str, str] = lazy_http_form_parse(raw)
|
||||
except UnicodeDecodeError as e:
|
||||
raise DivaRequestParseException(f"Could not decode data {raw} - {e}")
|
||||
|
||||
if b"cmd" not in self.raw_dict:
|
||||
if "cmd" not in self.raw_dict:
|
||||
raise DivaRequestParseException(f"cmd not in request data {self.raw_dict}")
|
||||
|
||||
if b"req_id" not in self.raw_dict:
|
||||
if "req_id" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"req_id not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
if b"place_id" not in self.raw_dict:
|
||||
if "place_id" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"place_id not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
if b"start_up_mode" not in self.raw_dict:
|
||||
if "start_up_mode" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"start_up_mode not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
if b"cmm_dly_mod" not in self.raw_dict:
|
||||
if "cmm_dly_mod" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"cmm_dly_mod not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
if b"cmm_dly_sec" not in self.raw_dict:
|
||||
if "cmm_dly_sec" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"cmm_dly_sec not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
if b"cmm_err_mod" not in self.raw_dict:
|
||||
if "cmm_err_mod" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"cmm_err_mod not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
if b"region_code" not in self.raw_dict:
|
||||
if "region_code" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"region_code not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
if b"time_stamp" not in self.raw_dict:
|
||||
if "time_stamp" not in self.raw_dict:
|
||||
raise DivaRequestParseException(
|
||||
f"time_stamp not in request data {self.raw_dict}"
|
||||
)
|
||||
|
||||
for k, v in self.raw_dict.items():
|
||||
setattr(self, k.decode(), v.decode())
|
||||
setattr(self, k, v)
|
||||
|
||||
self.place_id = int(self.place_id)
|
||||
self.start_up_mode = int(self.start_up_mode)
|
||||
@@ -110,7 +123,13 @@ class BaseResponse:
|
||||
self.stat = "ok"
|
||||
|
||||
def make(self) -> str:
|
||||
return f"cmd={self.cmd}&req_id={self.req_id}&stat={self.stat}"
|
||||
ret = ""
|
||||
for k, v in vars(self).items():
|
||||
ret += f"{k}={v}&"
|
||||
|
||||
if ret[-1] == "&":
|
||||
ret = ret[:-1]
|
||||
return ret
|
||||
|
||||
class GameInitRequest(BaseRequest):
|
||||
def __init__(self, raw: Union[str, bytes]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user