forked from Hay1tsme/artemis
wacca: add region IDs and version helper classes
This commit is contained in:
parent
447743da4c
commit
88f6eba30b
@ -110,7 +110,6 @@ class WaccaBase():
|
||||
def handle_user_status_get_request(self, data: Dict)-> Dict:
|
||||
req = UserStatusGetRequest(data)
|
||||
resp = UserStatusGetV1Response()
|
||||
ver_split = req.appVersion.split(".")
|
||||
|
||||
profile = self.data.profile.get_profile(aime_id=req.aimeId)
|
||||
if profile is None:
|
||||
@ -118,14 +117,11 @@ class WaccaBase():
|
||||
resp.profileStatus = ProfileStatus.ProfileRegister
|
||||
return resp.make()
|
||||
|
||||
|
||||
self.logger.info(f"User preview for {req.aimeId} from {req.chipId}")
|
||||
if profile["last_game_ver"] is None:
|
||||
profile_ver_split = ver_split
|
||||
resp.lastGameVersion = req.appVersion
|
||||
resp.lastGameVersion = ShortVersion(str(req.appVersion))
|
||||
else:
|
||||
profile_ver_split = profile["last_game_ver"].split(".")
|
||||
resp.lastGameVersion = profile["last_game_ver"]
|
||||
resp.lastGameVersion = ShortVersion(profile["last_game_ver"])
|
||||
|
||||
resp.userStatus.userId = profile["id"]
|
||||
resp.userStatus.username = profile["username"]
|
||||
@ -145,28 +141,12 @@ class WaccaBase():
|
||||
set_icon_id = self.OPTIONS_DEFAULTS["set_icon_id"]
|
||||
resp.setIconId = set_icon_id
|
||||
|
||||
|
||||
if int(ver_split[0]) > int(profile_ver_split[0]):
|
||||
if req.appVersion > resp.lastGameVersion:
|
||||
resp.versionStatus = PlayVersionStatus.VersionUpgrade
|
||||
|
||||
elif int(ver_split[0]) < int(profile_ver_split[0]):
|
||||
elif req.appVersion < resp.lastGameVersion:
|
||||
resp.versionStatus = PlayVersionStatus.VersionTooNew
|
||||
|
||||
else:
|
||||
if int(ver_split[1]) > int(profile_ver_split[1]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionUpgrade
|
||||
|
||||
elif int(ver_split[1]) < int(profile_ver_split[1]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionTooNew
|
||||
|
||||
else:
|
||||
if int(ver_split[2]) > int(profile_ver_split[2]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionUpgrade
|
||||
|
||||
|
||||
elif int(ver_split[2]) < int(profile_ver_split[2]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionTooNew
|
||||
|
||||
return resp.make()
|
||||
|
||||
def handle_user_status_login_request(self, data: Dict)-> Dict:
|
||||
|
@ -95,19 +95,69 @@ class WaccaConstants():
|
||||
"set_plate_id": 1005, # ID
|
||||
}
|
||||
|
||||
DIFFICULTIES = {
|
||||
"Normal": 1,
|
||||
"Hard": 2,
|
||||
"Expert": 3,
|
||||
"Inferno": 4,
|
||||
}
|
||||
|
||||
class Difficulty(Enum):
|
||||
NORMAL = 1
|
||||
HARD = 2
|
||||
EXPERT = 3
|
||||
INFERNO = 4
|
||||
|
||||
class Region(Enum):
|
||||
NONE = 0
|
||||
HOKKAIDO = 1
|
||||
AOMORI = 2
|
||||
IWATE = 3
|
||||
MIYAGI = 4
|
||||
AKITA = 5
|
||||
YAMAGATA = 6
|
||||
FUKUSHIMA = 7
|
||||
IBARAKI = 8
|
||||
TOCHIGI = 9
|
||||
GUNMA = 10
|
||||
SAITAMA = 11
|
||||
CHIBA = 12
|
||||
TOKYO = 13
|
||||
KANAGAWA = 14
|
||||
NIIGATA = 15
|
||||
TOYAMA = 16
|
||||
ISHIKAWA = 17
|
||||
FUKUI = 18
|
||||
YAMANASHI = 19
|
||||
NAGANO = 20
|
||||
GIFU = 21
|
||||
SHIZUOKA = 22
|
||||
AICHI = 23
|
||||
MIE = 24
|
||||
SHIGA = 25
|
||||
KYOTO = 26
|
||||
OSAKA = 27
|
||||
HYOGO = 28
|
||||
NARA = 29
|
||||
WAKAYAMA = 30
|
||||
TOTTORI = 31
|
||||
SHIMANE = 32
|
||||
OKAYAMA = 33
|
||||
HIROSHIMA = 34
|
||||
YAMAGUCHI = 35
|
||||
TOKUSHIMA = 36
|
||||
KAGAWA = 37
|
||||
EHIME = 38
|
||||
KOCHI = 39
|
||||
FUKUOKA = 40
|
||||
SAGA = 41
|
||||
NAGASAKI = 42
|
||||
KUMAMOTO = 43
|
||||
OITA = 44
|
||||
MIYAZAKI = 45
|
||||
KAGOSHIMA = 46
|
||||
OKINAWA = 47
|
||||
UNITED_STATES = 48
|
||||
TAIWAN = 49
|
||||
HONG_KONG = 50
|
||||
SINGAPORE = 51
|
||||
KOREA = 52
|
||||
|
||||
VALID_COUNTRIES = set(["JPN", "USA", "KOR", "HKG", "SGP"])
|
||||
|
||||
@classmethod
|
||||
def game_ver_to_string(cls, ver: int):
|
||||
return cls.VERSION_NAMES[ver]
|
@ -1,10 +1,11 @@
|
||||
from typing import Dict, List
|
||||
from titles.wacca.handlers.helpers import Version
|
||||
from datetime import datetime
|
||||
|
||||
class BaseRequest():
|
||||
def __init__(self, data: Dict) -> None:
|
||||
self.requestNo: int = data["requestNo"]
|
||||
self.appVersion: str = data["appVersion"]
|
||||
self.appVersion: Version = Version(data["appVersion"])
|
||||
self.boardId: str = data["boardId"]
|
||||
self.chipId: str = data["chipId"]
|
||||
self.params: List = data["params"]
|
||||
|
@ -3,6 +3,94 @@ from enum import Enum
|
||||
|
||||
from titles.wacca.const import WaccaConstants
|
||||
|
||||
class ShortVersion:
|
||||
def __init__(self, version: str = "", major = 1, minor = 0, patch = 0) -> None:
|
||||
split = version.split(".")
|
||||
if len(split) >= 3:
|
||||
self.major = int(split[0])
|
||||
self.minor = int(split[1])
|
||||
self.patch = int(split[2])
|
||||
|
||||
else:
|
||||
self.major = major
|
||||
self.minor = minor
|
||||
self.patch = patch
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.major}.{self.minor}.{self.patch}"
|
||||
|
||||
def __int__(self) -> int:
|
||||
return (self.major * 10000) + (self.minor * 100) + self.patch
|
||||
|
||||
def __eq__(self, other: "ShortVersion"):
|
||||
return self.major == other.major and self.minor == other.minor and self.patch == other.patch
|
||||
|
||||
def __gt__(self, other: "ShortVersion"):
|
||||
if self.major > other.major:
|
||||
return True
|
||||
elif self.major == other.major:
|
||||
if self.minor > other.minor:
|
||||
return True
|
||||
elif self.minor == other.minor:
|
||||
if self.patch > other.patch:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def __ge__(self, other: "ShortVersion"):
|
||||
if self.major > other.major:
|
||||
return True
|
||||
elif self.major == other.major:
|
||||
if self.minor > other.minor:
|
||||
return True
|
||||
elif self.minor == other.minor:
|
||||
if self.patch > other.patch or self.patch == other.patch:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def __lt__(self, other: "ShortVersion"):
|
||||
if self.major < other.major:
|
||||
return True
|
||||
elif self.major == other.major:
|
||||
if self.minor < other.minor:
|
||||
return True
|
||||
elif self.minor == other.minor:
|
||||
if self.patch < other.patch:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def __le__(self, other: "ShortVersion"):
|
||||
if self.major < other.major:
|
||||
return True
|
||||
elif self.major == other.major:
|
||||
if self.minor < other.minor:
|
||||
return True
|
||||
elif self.minor == other.minor:
|
||||
if self.patch < other.patch or self.patch == other.patch:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
class Version(ShortVersion):
|
||||
def __init__(self, version = "", major = 1, minor = 0, patch = 0, country = "JPN", build = 0, role = "C") -> None:
|
||||
super().__init__(version, major, minor, patch)
|
||||
split = version.split(".")
|
||||
if len(split) >= 6:
|
||||
self.country = split[3]
|
||||
self.build = int(split[4])
|
||||
self.role = split[5]
|
||||
|
||||
else:
|
||||
self.country = country
|
||||
self.build = build
|
||||
self.role = role
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.major}.{self.minor}.{self.patch}.{self.country}.{self.role}.{self.build}"
|
||||
|
||||
|
||||
class HousingInfo():
|
||||
"""
|
||||
1 is lan install role, 2 is country
|
||||
|
@ -19,7 +19,7 @@ class UserStatusGetV1Response(BaseResponse):
|
||||
self.setIconId: int = 0
|
||||
self.profileStatus: ProfileStatus = ProfileStatus.ProfileGood
|
||||
self.versionStatus: PlayVersionStatus = PlayVersionStatus.VersionGood
|
||||
self.lastGameVersion: str = ""
|
||||
self.lastGameVersion: ShortVersion = ShortVersion()
|
||||
|
||||
def make(self) -> Dict:
|
||||
self.params = [
|
||||
@ -29,7 +29,7 @@ class UserStatusGetV1Response(BaseResponse):
|
||||
self.profileStatus.value,
|
||||
[
|
||||
self.versionStatus.value,
|
||||
self.lastGameVersion
|
||||
str(self.lastGameVersion)
|
||||
]
|
||||
]
|
||||
|
||||
|
@ -18,6 +18,7 @@ from titles.wacca.lily import WaccaLily
|
||||
from titles.wacca.s import WaccaS
|
||||
from titles.wacca.base import WaccaBase
|
||||
from titles.wacca.handlers.base import BaseResponse
|
||||
from titles.wacca.handlers.helpers import Version
|
||||
|
||||
class WaccaServlet():
|
||||
def __init__(self, core_cfg: CoreConfig, cfg_dir: str) -> None:
|
||||
@ -56,11 +57,9 @@ class WaccaServlet():
|
||||
request.responseHeaders.addRawHeader(b"X-Wacca-Hash", hash.hex().encode())
|
||||
return json.dumps(resp).encode()
|
||||
|
||||
version_full = []
|
||||
|
||||
try:
|
||||
req_json = json.loads(request.content.getvalue())
|
||||
version_full = req_json["appVersion"].split(".")
|
||||
version_full = Version(req_json["appVersion"])
|
||||
except:
|
||||
self.logger.error(f"Failed to parse request toi {request.uri} -> {request.content.getvalue()}")
|
||||
resp = BaseResponse()
|
||||
@ -76,7 +75,7 @@ class WaccaServlet():
|
||||
func_to_find += f"{url_split[x + start_req_idx]}_"
|
||||
func_to_find += "request"
|
||||
|
||||
ver_search = (int(version_full[0]) * 10000) + (int(version_full[1]) * 100) + int(version_full[2])
|
||||
ver_search = int(version_full)
|
||||
|
||||
if ver_search < 15000:
|
||||
internal_ver = WaccaConstants.VER_WACCA
|
||||
|
@ -59,7 +59,6 @@ class WaccaLily(WaccaS):
|
||||
def handle_user_status_get_request(self, data: Dict)-> Dict:
|
||||
req = UserStatusGetRequest(data)
|
||||
resp = UserStatusGetV2Response()
|
||||
ver_split = req.appVersion.split(".")
|
||||
|
||||
profile = self.data.profile.get_profile(aime_id=req.aimeId)
|
||||
if profile is None:
|
||||
@ -69,11 +68,9 @@ class WaccaLily(WaccaS):
|
||||
|
||||
self.logger.info(f"User preview for {req.aimeId} from {req.chipId}")
|
||||
if profile["last_game_ver"] is None:
|
||||
profile_ver_split = ver_split
|
||||
resp.lastGameVersion = req.appVersion
|
||||
resp.lastGameVersion = ShortVersion(str(req.appVersion))
|
||||
else:
|
||||
profile_ver_split = profile["last_game_ver"].split(".")
|
||||
resp.lastGameVersion = profile["last_game_ver"]
|
||||
resp.lastGameVersion = ShortVersion(profile["last_game_ver"])
|
||||
|
||||
resp.userStatus.userId = profile["id"]
|
||||
resp.userStatus.username = profile["username"]
|
||||
@ -103,27 +100,12 @@ class WaccaLily(WaccaS):
|
||||
if profile["last_login_date"].timestamp() < int((datetime.now().replace(hour=0,minute=0,second=0,microsecond=0) - timedelta(days=1)).timestamp()):
|
||||
resp.userStatus.loginConsecutiveDays = 0
|
||||
|
||||
if int(ver_split[0]) > int(profile_ver_split[0]):
|
||||
if req.appVersion > resp.lastGameVersion:
|
||||
resp.versionStatus = PlayVersionStatus.VersionUpgrade
|
||||
|
||||
elif int(ver_split[0]) < int(profile_ver_split[0]):
|
||||
elif req.appVersion < resp.lastGameVersion:
|
||||
resp.versionStatus = PlayVersionStatus.VersionTooNew
|
||||
|
||||
else:
|
||||
if int(ver_split[1]) > int(profile_ver_split[1]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionUpgrade
|
||||
|
||||
elif int(ver_split[1]) < int(profile_ver_split[1]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionTooNew
|
||||
|
||||
else:
|
||||
if int(ver_split[2]) > int(profile_ver_split[2]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionUpgrade
|
||||
|
||||
|
||||
elif int(ver_split[2]) < int(profile_ver_split[2]):
|
||||
resp.versionStatus = PlayVersionStatus.VersionTooNew
|
||||
|
||||
if profile["vip_expire_time"] is not None:
|
||||
resp.userStatus.vipExpireTime = int(profile["vip_expire_time"].timestamp())
|
||||
|
||||
@ -178,8 +160,7 @@ class WaccaLily(WaccaS):
|
||||
|
||||
def handle_user_status_getDetail_request(self, data: Dict)-> Dict:
|
||||
req = UserStatusGetDetailRequest(data)
|
||||
ver_split = req.appVersion.split(".")
|
||||
if int(ver_split[1]) >= 53:
|
||||
if req.appVersion.minor >= 53:
|
||||
resp = UserStatusGetDetailResponseV3()
|
||||
else:
|
||||
resp = UserStatusGetDetailResponseV2()
|
||||
@ -252,7 +233,7 @@ class WaccaLily(WaccaS):
|
||||
|
||||
for user_gate in profile_gates:
|
||||
if user_gate["gate_id"] == gate:
|
||||
if int(ver_split[1]) >= 53:
|
||||
if req.appVersion.minor >= 53:
|
||||
resp.gateInfo.append(GateDetailV2(user_gate["gate_id"],user_gate["page"],user_gate["progress"],
|
||||
user_gate["loops"],int(user_gate["last_used"].timestamp()),user_gate["mission_flag"]))
|
||||
|
||||
@ -266,7 +247,7 @@ class WaccaLily(WaccaS):
|
||||
break
|
||||
|
||||
if not added_gate:
|
||||
if int(ver_split[1]) >= 53:
|
||||
if req.appVersion.minor >= 53:
|
||||
resp.gateInfo.append(GateDetailV2(gate))
|
||||
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user