forked from Hay1tsme/artemis
diva: add game_init and attend handlers
This commit is contained in:
parent
3076bdf575
commit
21c9b23617
@ -28,21 +28,30 @@ class DivaBase:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def handle_game_init_request(self, data: bytes) -> str:
|
def handle_game_init_request(self, data: bytes) -> str:
|
||||||
pass
|
req = GameInitRequest(data)
|
||||||
|
return None
|
||||||
|
|
||||||
def handle_attend_request(self, data: bytes) -> str:
|
def handle_attend_request(self, data: bytes) -> str:
|
||||||
encoded = "&"
|
req = AttendRequest(data)
|
||||||
params = {
|
resp = AttendResponse(req.cmd, req.req_id)
|
||||||
"atnd_prm1": "0,1,1,0,0,0,1,0,100,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,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,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,1,1,1,1,1,1,1,1,1,1,1,1",
|
|
||||||
"atnd_prm2": "30,10,100,4,1,50,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,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,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,1,1,1,1,1,1,1,1,1,1,1,1,1",
|
|
||||||
"atnd_prm3": "100,0,1,1,1,1,1,1,1,1,2,3,4,1,1,1,3,4,5,1,1,1,4,5,6,1,1,1,5,6,7,4,4,4,9,10,14,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,10,30,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
|
|
||||||
"atnd_lut": f"{self.time_lut}",
|
|
||||||
}
|
|
||||||
|
|
||||||
encoded += parse.urlencode(params)
|
for i in [0, 3, 4, 5, 7, 9, 10, 11, 12, 13]:
|
||||||
encoded = encoded.replace("%2C", ",")
|
resp.atnd_prm1[i] = 0
|
||||||
|
resp.atnd_prm1[8] = 100
|
||||||
|
|
||||||
return encoded
|
resp.atnd_prm2[:5] = [30, 10, 100, 4, 1, 50]
|
||||||
|
|
||||||
|
resp.atnd_prm3[0] = 100
|
||||||
|
resp.atnd_prm3[1] = 0
|
||||||
|
resp.atnd_prm3[10:13] = [2, 3, 4]
|
||||||
|
resp.atnd_prm3[16: 19] = [3, 4, 5]
|
||||||
|
resp.atnd_prm3[22: 25] = [4, 5, 6]
|
||||||
|
resp.atnd_prm3[80:] = [0] * 20
|
||||||
|
resp.atnd_prm3[28:78] = [5,6,7,4,4,4,9,10,14,5,10,10,25,20,50,30,90,5,
|
||||||
|
10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,
|
||||||
|
5,10,10,25,20,50,30,90,10,30]
|
||||||
|
|
||||||
|
return resp.make()
|
||||||
|
|
||||||
def handle_ping_request(self, data: bytes) -> str:
|
def handle_ping_request(self, data: bytes) -> str:
|
||||||
encoded = "&"
|
encoded = "&"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from urllib import parse
|
from urllib import parse
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Union
|
from typing import Union, Dict
|
||||||
|
|
||||||
|
|
||||||
class DivaRequestParseException(Exception):
|
class DivaRequestParseException(Exception):
|
||||||
@ -45,53 +45,53 @@ class BaseRequest:
|
|||||||
|
|
||||||
def __init__(self, raw: Union[str, bytes]) -> None:
|
def __init__(self, raw: Union[str, bytes]) -> None:
|
||||||
self.raw = raw
|
self.raw = raw
|
||||||
self.raw_dict = dict(parse.parse_qsl(raw))
|
self.raw_dict: Dict[bytes, bytes] = dict(parse.parse_qsl(raw))
|
||||||
|
|
||||||
if "cmd" not in self.raw_dict:
|
if b"cmd" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(f"cmd not in request data {self.raw_dict}")
|
raise DivaRequestParseException(f"cmd not in request data {self.raw_dict}")
|
||||||
|
|
||||||
if "req_id" not in self.raw_dict:
|
if b"req_id" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"req_id not in request data {self.raw_dict}"
|
f"req_id not in request data {self.raw_dict}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "place_id" not in self.raw_dict:
|
if b"place_id" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"place_id not in request data {self.raw_dict}"
|
f"place_id not in request data {self.raw_dict}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "start_up_mode" not in self.raw_dict:
|
if b"start_up_mode" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"start_up_mode not in request data {self.raw_dict}"
|
f"start_up_mode not in request data {self.raw_dict}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "cmm_dly_mod" not in self.raw_dict:
|
if b"cmm_dly_mod" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"cmm_dly_mod not in request data {self.raw_dict}"
|
f"cmm_dly_mod not in request data {self.raw_dict}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "cmm_dly_sec" not in self.raw_dict:
|
if b"cmm_dly_sec" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"cmm_dly_sec not in request data {self.raw_dict}"
|
f"cmm_dly_sec not in request data {self.raw_dict}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "cmm_err_mod" not in self.raw_dict:
|
if b"cmm_err_mod" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"cmm_err_mod not in request data {self.raw_dict}"
|
f"cmm_err_mod not in request data {self.raw_dict}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "region_code" not in self.raw_dict:
|
if b"region_code" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"region_code not in request data {self.raw_dict}"
|
f"region_code not in request data {self.raw_dict}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "time_stamp" not in self.raw_dict:
|
if b"time_stamp" not in self.raw_dict:
|
||||||
raise DivaRequestParseException(
|
raise DivaRequestParseException(
|
||||||
f"time_stamp not in request data {self.raw_dict}"
|
f"time_stamp 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)
|
setattr(self, k.decode(), v.decode())
|
||||||
|
|
||||||
self.place_id = int(self.place_id)
|
self.place_id = int(self.place_id)
|
||||||
self.start_up_mode = int(self.start_up_mode)
|
self.start_up_mode = int(self.start_up_mode)
|
||||||
@ -110,17 +110,34 @@ class BaseResponse:
|
|||||||
self.stat = "ok"
|
self.stat = "ok"
|
||||||
|
|
||||||
def make(self) -> str:
|
def make(self) -> str:
|
||||||
all_vars = vars(self)
|
return f"cmd={self.cmd}&req_id={self.req_id}&stat={self.stat}"
|
||||||
all_vars.pop("cmd")
|
|
||||||
all_vars.pop("req_id")
|
|
||||||
all_vars.pop("stat")
|
|
||||||
|
|
||||||
ret = f"cmd={self.cmd}&req_id={self.req_id}&stat={self.stat}"
|
class GameInitRequest(BaseRequest):
|
||||||
additional_params = parse.urlencode(
|
def __init__(self, raw: Union[str, bytes]) -> None:
|
||||||
all_vars, doseq=True, quote_via=parse.quote, safe=","
|
super().__init__(raw)
|
||||||
)
|
|
||||||
|
|
||||||
if additional_params != "":
|
class AttendRequest(BaseRequest):
|
||||||
ret += f"&{additional_params}"
|
def __init__(self, raw: Union[str, bytes]) -> None:
|
||||||
|
super().__init__(raw)
|
||||||
|
self.power_on = int(self.power_on)
|
||||||
|
self.is_bb = bool(int(self.power_on))
|
||||||
|
|
||||||
|
class AttendResponse(BaseResponse):
|
||||||
|
def __init__(self, cmd_id: str, req_id: int) -> None:
|
||||||
|
super().__init__(cmd_id, req_id)
|
||||||
|
self.atnd_prm1 = [1] * 100
|
||||||
|
self.atnd_prm2 = [1] * 100
|
||||||
|
self.atnd_prm3 = [1] * 100
|
||||||
|
self.atnd_lut = datetime.now()
|
||||||
|
|
||||||
|
def make(self) -> str:
|
||||||
|
ret = super().make()
|
||||||
|
ret_dict = {
|
||||||
|
"atnd_prm1": ','.join([str(i) for i in self.atnd_prm1]),
|
||||||
|
"atnd_prm2": ','.join([str(i) for i in self.atnd_prm2]),
|
||||||
|
"atnd_prm3": ','.join([str(i) for i in self.atnd_prm3]),
|
||||||
|
"atnd_lut": parse.quote(self.atnd_lut.strftime('%Y-%m-%d %H:%M:%S:16.0'))
|
||||||
|
}
|
||||||
|
ret += "&" + parse.urlencode(ret_dict, safe=",")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -103,9 +103,9 @@ class DivaServlet:
|
|||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
return b"stat=0"
|
return b"stat=0"
|
||||||
|
|
||||||
self.logger.debug(f"Request: {req_raw}\nHeaders: {url_header}")
|
self.logger.debug(f"Request: {url_data}\nHeaders: {url_header}")
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
f"{req_cls.cmd} request from {req_cls.b_serial} at {req.getClientAddress().host}"
|
f"{req_cls.cmd} request from {req_cls.kc_serial}/{req_cls.b_serial} at {req.getClientAddress().host}"
|
||||||
)
|
)
|
||||||
|
|
||||||
handler_str = f"handle_{req_cls.cmd}_request"
|
handler_str = f"handle_{req_cls.cmd}_request"
|
||||||
|
Loading…
Reference in New Issue
Block a user