1
0
forked from Hay1tsme/artemis

wacca: add request validation, fix HousingStartRequestV2

This commit is contained in:
Hay1tsme 2023-11-17 11:37:11 -05:00
parent 9a017f75e9
commit 05be10dabc
2 changed files with 19 additions and 7 deletions

View File

@ -32,6 +32,8 @@ class HousingStartRequestV1(BaseRequest):
class HousingStartRequestV2(HousingStartRequestV1): class HousingStartRequestV2(HousingStartRequestV1):
def __init__(self, data: Dict) -> None: def __init__(self, data: Dict) -> None:
super(HousingStartRequestV1, self).__init__(data) super(HousingStartRequestV1, self).__init__(data)
self.unknown0: str = self.params[0]
self.errorLog: str = self.params[1]
self.creditLog: str = self.params[2] self.creditLog: str = self.params[2]
self.info: List[HousingInfo] = [] self.info: List[HousingInfo] = []

View File

@ -18,7 +18,7 @@ from .lilyr import WaccaLilyR
from .lily import WaccaLily from .lily import WaccaLily
from .s import WaccaS from .s import WaccaS
from .base import WaccaBase from .base import WaccaBase
from .handlers.base import BaseResponse from .handlers.base import BaseResponse, BaseRequest
from .handlers.helpers import Version from .handlers.helpers import Version
@ -115,10 +115,20 @@ class WaccaServlet:
try: try:
req_json = json.loads(request.content.getvalue()) req_json = json.loads(request.content.getvalue())
version_full = Version(req_json["appVersion"]) version_full = Version(req_json["appVersion"])
req = BaseRequest(req_json)
except Exception: except KeyError as e:
self.logger.error( self.logger.error(
f"Failed to parse request to {url_path} -> {request.content.getvalue()}" f"Failed to parse request to {request.content.getvalue()} -> Missing required value {e}"
)
resp = BaseResponse()
resp.status = 1
resp.message = "不正なリクエスト エラーです"
return end(resp.make())
except Exception as e:
self.logger.error(
f"Failed to parse request to {url_path} -> {request.content.getvalue()} -> {e}"
) )
resp = BaseResponse() resp = BaseResponse()
resp.status = 1 resp.status = 1
@ -144,7 +154,7 @@ class WaccaServlet:
else: else:
self.logger.warning( self.logger.warning(
f"Unsupported version ({req_json['appVersion']}) request {url_path} - {req_json}" f"Unsupported version ({req.appVersion}) request {url_path} - {req_json}"
) )
resp = BaseResponse() resp = BaseResponse()
resp.status = 1 resp.status = 1
@ -152,7 +162,7 @@ class WaccaServlet:
return end(resp.make()) return end(resp.make())
self.logger.info( self.logger.info(
f"v{req_json['appVersion']} {url_path} request from {client_ip} with chipId {req_json['chipId']}" f"v{req.appVersion} {url_path} request from {client_ip} with chipId {req.chipId}"
) )
self.logger.debug(req_json) self.logger.debug(req_json)
@ -167,12 +177,12 @@ class WaccaServlet:
handler = getattr(self.versions[internal_ver], func_to_find) handler = getattr(self.versions[internal_ver], func_to_find)
resp = handler(req_json) resp = handler(req_json)
self.logger.debug(f"{req_json['appVersion']} response {resp}") self.logger.debug(f"{req.appVersion} response {resp}")
return end(resp) return end(resp)
except Exception as e: except Exception as e:
self.logger.error( self.logger.error(
f"{req_json['appVersion']} Error handling method {url_path} -> {e}" f"{req.appVersion} Error handling method {url_path} -> {e}"
) )
if self.logger.level == logging.DEBUG: if self.logger.level == logging.DEBUG:
traceback.print_exception(e, limit=1) traceback.print_exception(e, limit=1)