forked from Hay1tsme/artemis
pokken: backport changes from Diana
This commit is contained in:
parent
e06e316b7d
commit
3fd65da7fd
@ -1,9 +1,7 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
import json, logging
|
import json, logging
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
import random
|
|
||||||
|
|
||||||
from core.data import Data
|
|
||||||
from core import CoreConfig
|
from core import CoreConfig
|
||||||
from .config import PokkenConfig
|
from .config import PokkenConfig
|
||||||
from .proto import jackal_pb2
|
from .proto import jackal_pb2
|
||||||
@ -18,7 +16,6 @@ class PokkenBase:
|
|||||||
self.version = 0
|
self.version = 0
|
||||||
self.logger = logging.getLogger("pokken")
|
self.logger = logging.getLogger("pokken")
|
||||||
self.data = PokkenData(core_cfg)
|
self.data = PokkenData(core_cfg)
|
||||||
self.SUPPORT_SET_NONE = 4294967295
|
|
||||||
|
|
||||||
async def handle_noop(self, request: Any) -> bytes:
|
async def handle_noop(self, request: Any) -> bytes:
|
||||||
res = jackal_pb2.Response()
|
res = jackal_pb2.Response()
|
||||||
@ -38,7 +35,30 @@ class PokkenBase:
|
|||||||
res = jackal_pb2.Response()
|
res = jackal_pb2.Response()
|
||||||
res.result = 1
|
res.result = 1
|
||||||
res.type = jackal_pb2.MessageType.REGISTER_PCB
|
res.type = jackal_pb2.MessageType.REGISTER_PCB
|
||||||
self.logger.info(f"Register PCB {request.register_pcb.pcb_id}")
|
pcbid = request.register_pcb.pcb_id
|
||||||
|
if not pcbid.isdigit() or len(pcbid) != 12 or \
|
||||||
|
not pcbid.startswith(f"{PokkenConstants.SERIAL_IDENT[0]}{PokkenConstants.SERIAL_REGIONS[0]}{PokkenConstants.SERIAL_ROLES[0]}{PokkenConstants.SERIAL_CAB_IDENTS[0]}"):
|
||||||
|
self.logger.warn(f"Bad PCBID {pcbid}")
|
||||||
|
res.result = 0
|
||||||
|
return res
|
||||||
|
|
||||||
|
netid = PokkenConstants.NETID_PREFIX[0] + pcbid[5:]
|
||||||
|
|
||||||
|
self.logger.info(f"Register PCB {pcbid} (netID {netid})")
|
||||||
|
|
||||||
|
minfo = await self.data.arcade.get_machine(netid)
|
||||||
|
|
||||||
|
if not minfo and not self.core_cfg.server.allow_unregistered_serials:
|
||||||
|
self.logger.warn(f"netID {netid} does not belong to any shop!")
|
||||||
|
res.result = 0
|
||||||
|
return res
|
||||||
|
|
||||||
|
elif not minfo:
|
||||||
|
self.logger.warn(f"Orphaned netID {netid} allowed to connect")
|
||||||
|
locid = 0
|
||||||
|
|
||||||
|
else:
|
||||||
|
locid = minfo['arcade']
|
||||||
|
|
||||||
regist_pcb = jackal_pb2.RegisterPcbResponseData()
|
regist_pcb = jackal_pb2.RegisterPcbResponseData()
|
||||||
regist_pcb.server_time = int(datetime.now().timestamp())
|
regist_pcb.server_time = int(datetime.now().timestamp())
|
||||||
@ -46,7 +66,7 @@ class PokkenBase:
|
|||||||
"MatchingServer": {
|
"MatchingServer": {
|
||||||
"host": f"https://{self.game_cfg.server.hostname}",
|
"host": f"https://{self.game_cfg.server.hostname}",
|
||||||
"port": self.game_cfg.ports.game,
|
"port": self.game_cfg.ports.game,
|
||||||
"url": "/SDAK/100/matching",
|
"url": "/pokken/matching",
|
||||||
},
|
},
|
||||||
"StunServer": {
|
"StunServer": {
|
||||||
"addr": self.game_cfg.server.stun_server_host,
|
"addr": self.game_cfg.server.stun_server_host,
|
||||||
@ -56,12 +76,12 @@ class PokkenBase:
|
|||||||
"addr": self.game_cfg.server.stun_server_host,
|
"addr": self.game_cfg.server.stun_server_host,
|
||||||
"port": self.game_cfg.server.stun_server_port,
|
"port": self.game_cfg.server.stun_server_port,
|
||||||
},
|
},
|
||||||
"AdmissionUrl": f"ws://{self.game_cfg.server.hostname}:{self.game_cfg.ports.admission}",
|
"AdmissionUrl": f"ws://{self.game_cfg.server.hostname}:{self.game_cfg.ports.admission}/pokken/admission",
|
||||||
"locationId": 123, # FIXME: Get arcade's ID from the database
|
"locationId": locid,
|
||||||
"logfilename": "JackalMatchingLibrary.log",
|
"logfilename": "J:\\JackalMatchingLibrary.log",
|
||||||
"biwalogfilename": "./biwa.log",
|
"biwalogfilename": "J:\\biwa_log.log",
|
||||||
}
|
}
|
||||||
regist_pcb.bnp_baseuri = f"{self.core_cfg.server.hostname}/bna"
|
regist_pcb.bnp_baseuri = f"{self.core_cfg.mucha.hostname}/bna"
|
||||||
regist_pcb.biwa_setting = json.dumps(biwa_setting)
|
regist_pcb.biwa_setting = json.dumps(biwa_setting)
|
||||||
|
|
||||||
res.register_pcb.CopyFrom(regist_pcb)
|
res.register_pcb.CopyFrom(regist_pcb)
|
||||||
@ -95,12 +115,11 @@ class PokkenBase:
|
|||||||
res.type = jackal_pb2.MessageType.LOAD_CLIENT_SETTINGS
|
res.type = jackal_pb2.MessageType.LOAD_CLIENT_SETTINGS
|
||||||
settings = jackal_pb2.LoadClientSettingsResponseData()
|
settings = jackal_pb2.LoadClientSettingsResponseData()
|
||||||
|
|
||||||
# TODO: Make configurable
|
|
||||||
settings.money_magnification = 1
|
settings.money_magnification = 1
|
||||||
settings.continue_bonus_exp = 100
|
settings.continue_bonus_exp = 100
|
||||||
settings.continue_fight_money = 100
|
settings.continue_fight_money = 100
|
||||||
settings.event_bonus_exp = 100
|
settings.event_bonus_exp = 100
|
||||||
settings.level_cap = 999
|
settings.level_cap = 100
|
||||||
settings.op_movie_flag = 0xFFFFFFFF
|
settings.op_movie_flag = 0xFFFFFFFF
|
||||||
settings.lucky_bonus_rate = 1
|
settings.lucky_bonus_rate = 1
|
||||||
settings.fail_support_num = 10
|
settings.fail_support_num = 10
|
||||||
@ -132,9 +151,13 @@ class PokkenBase:
|
|||||||
res.type = jackal_pb2.MessageType.LOAD_USER
|
res.type = jackal_pb2.MessageType.LOAD_USER
|
||||||
access_code = request.load_user.access_code
|
access_code = request.load_user.access_code
|
||||||
load_usr = jackal_pb2.LoadUserResponseData()
|
load_usr = jackal_pb2.LoadUserResponseData()
|
||||||
user_id = await self.data.card.get_user_id_from_card(access_code)
|
load_usr.load_hash = 1
|
||||||
|
load_usr.access_code = access_code
|
||||||
|
load_usr.precedent_release_flag = 0xFFFFFFFF
|
||||||
|
load_usr.cardlock_status = False
|
||||||
|
card = await self.data.card.get_card_by_access_code(access_code)
|
||||||
|
|
||||||
if user_id is None and self.game_cfg.server.auto_register:
|
if card is None and self.game_cfg.server.auto_register:
|
||||||
user_id = await self.data.user.create_user()
|
user_id = await self.data.user.create_user()
|
||||||
card_id = await self.data.card.create_card(user_id, access_code)
|
card_id = await self.data.card.create_card(user_id, access_code)
|
||||||
|
|
||||||
@ -142,41 +165,27 @@ class PokkenBase:
|
|||||||
f"Register new card {access_code} (UserId {user_id}, CardId {card_id})"
|
f"Register new card {access_code} (UserId {user_id}, CardId {card_id})"
|
||||||
)
|
)
|
||||||
|
|
||||||
elif user_id is None:
|
elif card is None:
|
||||||
self.logger.info(f"Registration of card {access_code} blocked!")
|
self.logger.info(f"Registration of card {access_code} blocked!")
|
||||||
res.load_user.CopyFrom(load_usr)
|
res.load_user.CopyFrom(load_usr)
|
||||||
return res.SerializeToString()
|
return res.SerializeToString()
|
||||||
|
|
||||||
|
else:
|
||||||
|
user_id = card['user']
|
||||||
|
card_id = card['id']
|
||||||
|
|
||||||
"""
|
"""
|
||||||
TODO: Add repeated values
|
TODO: Unlock all supports? Probably
|
||||||
tutorial_progress_flag
|
|
||||||
rankmatch_progress
|
|
||||||
support_pokemon_list
|
support_pokemon_list
|
||||||
support_set_1
|
|
||||||
support_set_2
|
|
||||||
support_set_3
|
|
||||||
aid_skill_list
|
|
||||||
achievement_flag
|
|
||||||
event_achievement_flag
|
|
||||||
event_achievement_param
|
|
||||||
"""
|
"""
|
||||||
profile = await self.data.profile.get_profile(user_id)
|
profile = await self.data.profile.get_profile(user_id)
|
||||||
load_usr.commidserv_result = 1
|
load_usr.commidserv_result = 1
|
||||||
load_usr.load_hash = 1
|
|
||||||
load_usr.cardlock_status = False
|
|
||||||
load_usr.banapass_id = user_id
|
load_usr.banapass_id = user_id
|
||||||
load_usr.access_code = access_code
|
|
||||||
load_usr.precedent_release_flag = 0xFFFFFFFF
|
|
||||||
|
|
||||||
if profile is None:
|
if profile is None or profile['trainer_name'] is None:
|
||||||
profile_id = await self.data.profile.create_profile(user_id)
|
profile_id = await self.data.profile.create_profile(user_id)
|
||||||
profile_dict = {"id": profile_id, "user": user_id}
|
profile_dict = {"id": profile_id, "user": user_id}
|
||||||
pokemon_data = []
|
pokemon_data = []
|
||||||
tutorial_progress = []
|
|
||||||
rankmatch_progress = []
|
|
||||||
achievement_flag = []
|
|
||||||
event_achievement_flag = []
|
|
||||||
event_achievement_param = []
|
|
||||||
load_usr.new_card_flag = True
|
load_usr.new_card_flag = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -185,11 +194,6 @@ class PokkenBase:
|
|||||||
f"Card-in user {user_id} (Trainer name {profile_dict.get('trainer_name', '')})"
|
f"Card-in user {user_id} (Trainer name {profile_dict.get('trainer_name', '')})"
|
||||||
)
|
)
|
||||||
pokemon_data = await self.data.profile.get_all_pokemon_data(user_id)
|
pokemon_data = await self.data.profile.get_all_pokemon_data(user_id)
|
||||||
tutorial_progress = []
|
|
||||||
rankmatch_progress = []
|
|
||||||
achievement_flag = []
|
|
||||||
event_achievement_flag = []
|
|
||||||
event_achievement_param = []
|
|
||||||
load_usr.new_card_flag = False
|
load_usr.new_card_flag = False
|
||||||
|
|
||||||
load_usr.navi_newbie_flag = profile_dict.get("navi_newbie_flag", True)
|
load_usr.navi_newbie_flag = profile_dict.get("navi_newbie_flag", True)
|
||||||
@ -201,9 +205,9 @@ class PokkenBase:
|
|||||||
load_usr.trainer_name = profile_dict.get(
|
load_usr.trainer_name = profile_dict.get(
|
||||||
"trainer_name", f"Newb{str(user_id).zfill(4)}"
|
"trainer_name", f"Newb{str(user_id).zfill(4)}"
|
||||||
)
|
)
|
||||||
load_usr.trainer_rank_point = profile_dict.get("trainer_rank_point", 0)
|
load_usr.trainer_rank_point = profile_dict.get("trainer_rank_point", 0) # determines rank
|
||||||
load_usr.wallet = profile_dict.get("wallet", 0)
|
load_usr.wallet = profile_dict.get("wallet", 0) # pg count
|
||||||
load_usr.fight_money = profile_dict.get("fight_money", 0)
|
load_usr.fight_money = profile_dict.get("fight_money", 0) # ?
|
||||||
load_usr.score_point = profile_dict.get("score_point", 0)
|
load_usr.score_point = profile_dict.get("score_point", 0)
|
||||||
load_usr.grade_max_num = profile_dict.get("grade_max_num", 0)
|
load_usr.grade_max_num = profile_dict.get("grade_max_num", 0)
|
||||||
load_usr.extra_counter = profile_dict.get("extra_counter", 0)
|
load_usr.extra_counter = profile_dict.get("extra_counter", 0)
|
||||||
@ -218,18 +222,18 @@ class PokkenBase:
|
|||||||
load_usr.rank_event = profile_dict.get("rank_event", 0)
|
load_usr.rank_event = profile_dict.get("rank_event", 0)
|
||||||
load_usr.awake_num = profile_dict.get("awake_num", 0)
|
load_usr.awake_num = profile_dict.get("awake_num", 0)
|
||||||
load_usr.use_support_num = profile_dict.get("use_support_num", 0)
|
load_usr.use_support_num = profile_dict.get("use_support_num", 0)
|
||||||
load_usr.rankmatch_flag = profile_dict.get("rankmatch_flag", 0)
|
load_usr.rankmatch_flag = profile_dict.get("rankmatch_flag", 0) # flags that next rank match will be rank up
|
||||||
load_usr.rankmatch_max = profile_dict.get("rankmatch_max", 0)
|
load_usr.rankmatch_max = profile_dict.get("rankmatch_max", 0)
|
||||||
load_usr.rankmatch_success = profile_dict.get("rankmatch_success", 0)
|
load_usr.rankmatch_success = profile_dict.get("rankmatch_success", 0)
|
||||||
load_usr.beat_num = profile_dict.get("beat_num", 0)
|
load_usr.beat_num = profile_dict.get("beat_num", 0)
|
||||||
load_usr.title_text_id = profile_dict.get("title_text_id", 0)
|
load_usr.title_text_id = profile_dict.get("title_text_id", 2)
|
||||||
load_usr.title_plate_id = profile_dict.get("title_plate_id", 0)
|
load_usr.title_plate_id = profile_dict.get("title_plate_id", 1)
|
||||||
load_usr.title_decoration_id = profile_dict.get("title_decoration_id", 0)
|
load_usr.title_decoration_id = profile_dict.get("title_decoration_id", 1)
|
||||||
load_usr.navi_trainer = profile_dict.get("navi_trainer", 0)
|
load_usr.navi_trainer = profile_dict.get("navi_trainer", 0)
|
||||||
load_usr.navi_version_id = profile_dict.get("navi_version_id", 0)
|
load_usr.navi_version_id = profile_dict.get("navi_version_id", 0)
|
||||||
load_usr.aid_skill = profile_dict.get("aid_skill", 0)
|
load_usr.aid_skill = profile_dict.get("aid_skill", 0)
|
||||||
load_usr.comment_text_id = profile_dict.get("comment_text_id", 0)
|
load_usr.comment_text_id = profile_dict.get("comment_text_id", 1)
|
||||||
load_usr.comment_word_id = profile_dict.get("comment_word_id", 0)
|
load_usr.comment_word_id = profile_dict.get("comment_word_id", 1)
|
||||||
load_usr.latest_use_pokemon = profile_dict.get("latest_use_pokemon", 0)
|
load_usr.latest_use_pokemon = profile_dict.get("latest_use_pokemon", 0)
|
||||||
load_usr.ex_ko_num = profile_dict.get("ex_ko_num", 0)
|
load_usr.ex_ko_num = profile_dict.get("ex_ko_num", 0)
|
||||||
load_usr.wko_num = profile_dict.get("wko_num", 0)
|
load_usr.wko_num = profile_dict.get("wko_num", 0)
|
||||||
@ -237,11 +241,11 @@ class PokkenBase:
|
|||||||
load_usr.cool_ko_num = profile_dict.get("cool_ko_num", 0)
|
load_usr.cool_ko_num = profile_dict.get("cool_ko_num", 0)
|
||||||
load_usr.perfect_ko_num = profile_dict.get("perfect_ko_num", 0)
|
load_usr.perfect_ko_num = profile_dict.get("perfect_ko_num", 0)
|
||||||
load_usr.record_flag = profile_dict.get("record_flag", 0)
|
load_usr.record_flag = profile_dict.get("record_flag", 0)
|
||||||
load_usr.site_register_status = profile_dict.get("site_register_status", 0)
|
load_usr.site_register_status = profile_dict.get("site_register_status", 1)
|
||||||
load_usr.continue_num = profile_dict.get("continue_num", 0)
|
load_usr.continue_num = profile_dict.get("continue_num", 0)
|
||||||
|
|
||||||
load_usr.avatar_body = profile_dict.get("avatar_body", 0)
|
load_usr.avatar_body = profile_dict.get("avatar_body", 0)
|
||||||
load_usr.avatar_gender = profile_dict.get("avatar_gender", 0)
|
load_usr.avatar_gender = profile_dict.get("avatar_gender", 1)
|
||||||
load_usr.avatar_background = profile_dict.get("avatar_background", 0)
|
load_usr.avatar_background = profile_dict.get("avatar_background", 0)
|
||||||
load_usr.avatar_head = profile_dict.get("avatar_head", 0)
|
load_usr.avatar_head = profile_dict.get("avatar_head", 0)
|
||||||
load_usr.avatar_battleglass = profile_dict.get("avatar_battleglass", 0)
|
load_usr.avatar_battleglass = profile_dict.get("avatar_battleglass", 0)
|
||||||
@ -284,6 +288,31 @@ class PokkenBase:
|
|||||||
|
|
||||||
load_usr.pokemon_data.append(pkm)
|
load_usr.pokemon_data.append(pkm)
|
||||||
|
|
||||||
|
for x in profile_dict.get("tutorial_progress_flag", []):
|
||||||
|
load_usr.tutorial_progress_flag.append(x)
|
||||||
|
|
||||||
|
for x in profile_dict.get("achievement_flag", []):
|
||||||
|
load_usr.achievement_flag.append(x)
|
||||||
|
|
||||||
|
for x in profile_dict.get("aid_skill_list", []):
|
||||||
|
load_usr.aid_skill_list.append(x)
|
||||||
|
|
||||||
|
for x in profile_dict.get("rankmatch_progress", []):
|
||||||
|
load_usr.rankmatch_progress.append(x)
|
||||||
|
|
||||||
|
for x in profile_dict.get("event_achievement_flag", []):
|
||||||
|
load_usr.event_achievement_flag.append(x)
|
||||||
|
|
||||||
|
for x in profile_dict.get("event_achievement_param", []):
|
||||||
|
load_usr.event_achievement_param.append(x)
|
||||||
|
|
||||||
|
load_usr.support_set_1.append(profile_dict.get("support_set_1_1", 4294967295))
|
||||||
|
load_usr.support_set_1.append(profile_dict.get("support_set_1_2", 4294967295))
|
||||||
|
load_usr.support_set_2.append(profile_dict.get("support_set_2_1", 4294967295))
|
||||||
|
load_usr.support_set_2.append(profile_dict.get("support_set_2_2", 4294967295))
|
||||||
|
load_usr.support_set_3.append(profile_dict.get("support_set_3_1", 4294967295))
|
||||||
|
load_usr.support_set_3.append(profile_dict.get("support_set_3_2", 4294967295))
|
||||||
|
|
||||||
res.load_user.CopyFrom(load_usr)
|
res.load_user.CopyFrom(load_usr)
|
||||||
return res.SerializeToString()
|
return res.SerializeToString()
|
||||||
|
|
||||||
@ -301,6 +330,8 @@ class PokkenBase:
|
|||||||
req = request.save_user
|
req = request.save_user
|
||||||
user_id = req.banapass_id
|
user_id = req.banapass_id
|
||||||
|
|
||||||
|
self.logger.info(f"Save user data for {user_id}")
|
||||||
|
|
||||||
tut_flgs: List[int] = []
|
tut_flgs: List[int] = []
|
||||||
ach_flgs: List[int] = []
|
ach_flgs: List[int] = []
|
||||||
evt_flgs: List[int] = []
|
evt_flgs: List[int] = []
|
||||||
@ -339,7 +370,7 @@ class PokkenBase:
|
|||||||
for ach_flg in req.achievement_flag:
|
for ach_flg in req.achievement_flag:
|
||||||
ach_flgs.append(ach_flg)
|
ach_flgs.append(ach_flg)
|
||||||
|
|
||||||
await self.data.profile.update_profile_achievement_flags(user_id, ach_flg)
|
await self.data.profile.update_profile_achievement_flags(user_id, ach_flgs)
|
||||||
|
|
||||||
for evt_flg in req.event_achievement_flag:
|
for evt_flg in req.event_achievement_flag:
|
||||||
evt_flgs.append(evt_flg)
|
evt_flgs.append(evt_flg)
|
||||||
@ -354,17 +385,22 @@ class PokkenBase:
|
|||||||
|
|
||||||
await self.data.profile.add_profile_points(user_id, get_rank_pts, get_money, get_score_pts, grade_max)
|
await self.data.profile.add_profile_points(user_id, get_rank_pts, get_money, get_score_pts, grade_max)
|
||||||
|
|
||||||
|
# Inconsistant underscore use AND a typo??
|
||||||
|
await self.data.profile.update_rankmatch_data(user_id, req.rankmatch_flag, req.rank_match_max, req.rank_match_success, req.rank_match_process)
|
||||||
|
|
||||||
await self.data.profile.update_support_team(user_id, 1, req.support_set_1[0], req.support_set_1[1])
|
await self.data.profile.update_support_team(user_id, 1, req.support_set_1[0], req.support_set_1[1])
|
||||||
await self.data.profile.update_support_team(user_id, 2, req.support_set_2[0], req.support_set_2[1])
|
await self.data.profile.update_support_team(user_id, 2, req.support_set_2[0], req.support_set_2[1])
|
||||||
await self.data.profile.update_support_team(user_id, 3, req.support_set_3[0], req.support_set_3[1])
|
await self.data.profile.update_support_team(user_id, 3, req.support_set_3[0], req.support_set_3[1])
|
||||||
|
|
||||||
await self.data.profile.put_pokemon(user_id, mon.char_id, mon.illustration_book_no, mon.bp_point_atk, mon.bp_point_res, mon.bp_point_def, mon.bp_point_sp)
|
await self.data.profile.put_pokemon(user_id, mon.char_id, mon.illustration_book_no, mon.bp_point_atk, mon.bp_point_res, mon.bp_point_def, mon.bp_point_sp)
|
||||||
await self.data.profile.add_pokemon_xp(user_id, mon.char_id, mon.get_pokemon_exp)
|
await self.data.profile.add_pokemon_xp(user_id, mon.illustration_book_no, mon.get_pokemon_exp)
|
||||||
|
await self.data.profile.set_latest_mon(user_id, mon.illustration_book_no)
|
||||||
|
|
||||||
for x in range(len(battle.play_mode)):
|
for x in range(len(battle.play_mode)):
|
||||||
|
self.logger.info(f"Save {PokkenConstants.BATTLE_TYPE(battle.play_mode[x]).name} battle {PokkenConstants.BATTLE_RESULT(battle.result[x]).name} for {user_id} with mon {mon.illustration_book_no}")
|
||||||
await self.data.profile.put_pokemon_battle_result(
|
await self.data.profile.put_pokemon_battle_result(
|
||||||
user_id,
|
user_id,
|
||||||
mon.char_id,
|
mon.illustration_book_no,
|
||||||
PokkenConstants.BATTLE_TYPE(battle.play_mode[x]),
|
PokkenConstants.BATTLE_TYPE(battle.play_mode[x]),
|
||||||
PokkenConstants.BATTLE_RESULT(battle.result[x])
|
PokkenConstants.BATTLE_RESULT(battle.result[x])
|
||||||
)
|
)
|
||||||
@ -391,7 +427,6 @@ class PokkenBase:
|
|||||||
last_evt
|
last_evt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
return res.SerializeToString()
|
return res.SerializeToString()
|
||||||
|
|
||||||
async def handle_save_ingame_log(self, data: jackal_pb2.Request) -> bytes:
|
async def handle_save_ingame_log(self, data: jackal_pb2.Request) -> bytes:
|
||||||
@ -419,6 +454,13 @@ class PokkenBase:
|
|||||||
async def handle_matching_is_matching(
|
async def handle_matching_is_matching(
|
||||||
self, data: Dict = {}, client_ip: str = "127.0.0.1"
|
self, data: Dict = {}, client_ip: str = "127.0.0.1"
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
|
"""
|
||||||
|
"sessionId":"12345678",
|
||||||
|
"A":{
|
||||||
|
"pcb_id": data["data"]["must"]["pcb_id"],
|
||||||
|
"gip": client_ip
|
||||||
|
},
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
"data": {
|
"data": {
|
||||||
"sessionId":"12345678",
|
"sessionId":"12345678",
|
||||||
@ -435,6 +477,11 @@ class PokkenBase:
|
|||||||
) -> Dict:
|
) -> Dict:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
async def handle_matching_obtain_matching(
|
||||||
|
self, data: Dict = {}, client_ip: str = "127.0.0.1"
|
||||||
|
) -> Dict:
|
||||||
|
return {}
|
||||||
|
|
||||||
async def handle_admission_noop(self, data: Dict, req_ip: str = "127.0.0.1") -> Dict:
|
async def handle_admission_noop(self, data: Dict, req_ip: str = "127.0.0.1") -> Dict:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
from typing import Optional, Dict, List, Union
|
from typing import Optional, Dict, List, Union
|
||||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_, case
|
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_, case
|
||||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON
|
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, INTEGER
|
||||||
from sqlalchemy.schema import ForeignKey
|
from sqlalchemy.schema import ForeignKey
|
||||||
from sqlalchemy.sql import func, select, update, delete
|
from sqlalchemy.sql import func, select, update, delete
|
||||||
from sqlalchemy.sql.functions import coalesce
|
from sqlalchemy.sql.functions import coalesce
|
||||||
from sqlalchemy.engine import Row
|
from sqlalchemy.engine import Row
|
||||||
from sqlalchemy.dialects.mysql import insert
|
from sqlalchemy.dialects.postgresql import insert
|
||||||
|
|
||||||
from core.data.schema import BaseData, metadata
|
from core.data.schema import BaseData, metadata
|
||||||
from ..const import PokkenConstants
|
from ..const import PokkenConstants
|
||||||
@ -16,13 +16,8 @@ profile = Table(
|
|||||||
"pokken_profile",
|
"pokken_profile",
|
||||||
metadata,
|
metadata,
|
||||||
Column("id", Integer, primary_key=True, nullable=False),
|
Column("id", Integer, primary_key=True, nullable=False),
|
||||||
Column(
|
Column("user", Integer, ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False, unique=True),
|
||||||
"user",
|
Column("trainer_name", String(14)), # optional
|
||||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
|
||||||
nullable=False,
|
|
||||||
unique=True,
|
|
||||||
),
|
|
||||||
Column("trainer_name", String(16)), # optional
|
|
||||||
Column("home_region_code", Integer),
|
Column("home_region_code", Integer),
|
||||||
Column("home_loc_name", String(255)),
|
Column("home_loc_name", String(255)),
|
||||||
Column("pref_code", Integer),
|
Column("pref_code", Integer),
|
||||||
@ -105,20 +100,15 @@ profile = Table(
|
|||||||
Column("battle_num_vs_cpu", Integer), # 2
|
Column("battle_num_vs_cpu", Integer), # 2
|
||||||
Column("win_cpu", Integer),
|
Column("win_cpu", Integer),
|
||||||
Column("battle_num_tutorial", Integer), # 1?
|
Column("battle_num_tutorial", Integer), # 1?
|
||||||
mysql_charset="utf8mb4",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pokemon_data = Table(
|
pokemon_data = Table(
|
||||||
"pokken_pokemon_data",
|
"pokken_pokemon",
|
||||||
metadata,
|
metadata,
|
||||||
Column("id", Integer, primary_key=True, nullable=False),
|
Column("id", Integer, primary_key=True, nullable=False),
|
||||||
Column(
|
Column("user", Integer, ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||||
"user",
|
Column("char_id", Integer),
|
||||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
Column("illustration_book_no", Integer, nullable=False), # This is the fucking pokedex number????
|
||||||
nullable=False,
|
|
||||||
),
|
|
||||||
Column("char_id", Integer, nullable=False),
|
|
||||||
Column("illustration_book_no", Integer),
|
|
||||||
Column("pokemon_exp", Integer),
|
Column("pokemon_exp", Integer),
|
||||||
Column("battle_num_vs_wan", Integer), # 4?
|
Column("battle_num_vs_wan", Integer), # 4?
|
||||||
Column("win_vs_wan", Integer),
|
Column("win_vs_wan", Integer),
|
||||||
@ -132,8 +122,7 @@ pokemon_data = Table(
|
|||||||
Column("bp_point_res", Integer),
|
Column("bp_point_res", Integer),
|
||||||
Column("bp_point_def", Integer),
|
Column("bp_point_def", Integer),
|
||||||
Column("bp_point_sp", Integer),
|
Column("bp_point_sp", Integer),
|
||||||
UniqueConstraint("user", "char_id", name="pokken_pokemon_data_uk"),
|
UniqueConstraint("user", "illustration_book_no", name="pokken_pokemon_uk"),
|
||||||
mysql_charset="utf8mb4",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -157,8 +146,8 @@ class PokkenProfileData(BaseData):
|
|||||||
return result.lastrowid
|
return result.lastrowid
|
||||||
|
|
||||||
async def set_profile_name(self, user_id: int, new_name: str, gender: Union[int, None] = None) -> None:
|
async def set_profile_name(self, user_id: int, new_name: str, gender: Union[int, None] = None) -> None:
|
||||||
sql = update(profile).where(profile.c.user == user_id).values(
|
sql = profile.update(profile.c.user == user_id).values(
|
||||||
trainer_name=new_name,
|
trainer_name=new_name if new_name else profile.c.trainer_name,
|
||||||
avatar_gender=gender if gender is not None else profile.c.avatar_gender
|
avatar_gender=gender if gender is not None else profile.c.avatar_gender
|
||||||
)
|
)
|
||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
@ -179,12 +168,12 @@ class PokkenProfileData(BaseData):
|
|||||||
aid_skill: int,
|
aid_skill: int,
|
||||||
last_evt: int
|
last_evt: int
|
||||||
) -> None:
|
) -> None:
|
||||||
sql = update(profile).where(profile.c.user == user_id).values(
|
sql = profile.update(profile.c.user == user_id).values(
|
||||||
extra_counter=extra_counter,
|
extra_counter=extra_counter,
|
||||||
event_reward_get_flag=evt_reward_get_flg,
|
event_reward_get_flag=evt_reward_get_flg,
|
||||||
total_play_days=total_play_days,
|
total_play_days=coalesce(profile.c.total_play_days, 0) + total_play_days,
|
||||||
awake_num=awake_num,
|
awake_num=coalesce(profile.c.awake_num, 0) + awake_num,
|
||||||
use_support_num=use_support_ct,
|
use_support_num=coalesce(profile.c.use_support_num, 0) + use_support_ct,
|
||||||
beat_num=beat_num,
|
beat_num=beat_num,
|
||||||
aid_skill=aid_skill,
|
aid_skill=aid_skill,
|
||||||
last_play_event_id=last_evt
|
last_play_event_id=last_evt
|
||||||
@ -195,7 +184,7 @@ class PokkenProfileData(BaseData):
|
|||||||
self.logger.error(f"Failed to put extra data for user {user_id}")
|
self.logger.error(f"Failed to put extra data for user {user_id}")
|
||||||
|
|
||||||
async def update_profile_tutorial_flags(self, user_id: int, tutorial_flags: List) -> None:
|
async def update_profile_tutorial_flags(self, user_id: int, tutorial_flags: List) -> None:
|
||||||
sql = update(profile).where(profile.c.user == user_id).values(
|
sql = profile.update(profile.c.user == user_id).values(
|
||||||
tutorial_progress_flag=tutorial_flags,
|
tutorial_progress_flag=tutorial_flags,
|
||||||
)
|
)
|
||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
@ -205,7 +194,7 @@ class PokkenProfileData(BaseData):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def update_profile_achievement_flags(self, user_id: int, achievement_flags: List) -> None:
|
async def update_profile_achievement_flags(self, user_id: int, achievement_flags: List) -> None:
|
||||||
sql = update(profile).where(profile.c.user == user_id).values(
|
sql = profile.update(profile.c.user == user_id).values(
|
||||||
achievement_flag=achievement_flags,
|
achievement_flag=achievement_flags,
|
||||||
)
|
)
|
||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
@ -215,7 +204,7 @@ class PokkenProfileData(BaseData):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def update_profile_event(self, user_id: int, event_state: List, event_flags: List[int], event_param: List[int], last_evt: int = None) -> None:
|
async def update_profile_event(self, user_id: int, event_state: List, event_flags: List[int], event_param: List[int], last_evt: int = None) -> None:
|
||||||
sql = update(profile).where(profile.c.user == user_id).values(
|
sql = profile.update(profile.c.user == user_id).values(
|
||||||
event_state=event_state,
|
event_state=event_state,
|
||||||
event_achievement_flag=event_flags,
|
event_achievement_flag=event_flags,
|
||||||
event_achievement_param=event_param,
|
event_achievement_param=event_param,
|
||||||
@ -230,13 +219,17 @@ class PokkenProfileData(BaseData):
|
|||||||
async def add_profile_points(
|
async def add_profile_points(
|
||||||
self, user_id: int, rank_pts: int, money: int, score_pts: int, grade_max: int
|
self, user_id: int, rank_pts: int, money: int, score_pts: int, grade_max: int
|
||||||
) -> None:
|
) -> None:
|
||||||
sql = update(profile).where(profile.c.user == user_id).values(
|
sql = profile.update(profile.c.user == user_id).values(
|
||||||
trainer_rank_point = profile.c.trainer_rank_point + rank_pts,
|
trainer_rank_point = coalesce(profile.c.trainer_rank_point, 0) + rank_pts,
|
||||||
fight_money = profile.c.fight_money + money,
|
wallet = coalesce(profile.c.wallet, 0) + money,
|
||||||
score_point = profile.c.score_point + score_pts,
|
score_point = coalesce(profile.c.score_point, 0) + score_pts,
|
||||||
grade_max_num = grade_max
|
grade_max_num = grade_max
|
||||||
)
|
)
|
||||||
|
|
||||||
|
result = await self.execute(sql)
|
||||||
|
if result is None:
|
||||||
|
return None
|
||||||
|
|
||||||
async def get_profile(self, user_id: int) -> Optional[Row]:
|
async def get_profile(self, user_id: int) -> Optional[Row]:
|
||||||
sql = profile.select(profile.c.user == user_id)
|
sql = profile.select(profile.c.user == user_id)
|
||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
@ -248,7 +241,7 @@ class PokkenProfileData(BaseData):
|
|||||||
self,
|
self,
|
||||||
user_id: int,
|
user_id: int,
|
||||||
pokemon_id: int,
|
pokemon_id: int,
|
||||||
illust_no: int,
|
pokedex_number: int,
|
||||||
atk: int,
|
atk: int,
|
||||||
res: int,
|
res: int,
|
||||||
defe: int,
|
defe: int,
|
||||||
@ -257,7 +250,7 @@ class PokkenProfileData(BaseData):
|
|||||||
sql = insert(pokemon_data).values(
|
sql = insert(pokemon_data).values(
|
||||||
user=user_id,
|
user=user_id,
|
||||||
char_id=pokemon_id,
|
char_id=pokemon_id,
|
||||||
illustration_book_no=illust_no,
|
illustration_book_no=pokedex_number,
|
||||||
pokemon_exp=0,
|
pokemon_exp=0,
|
||||||
battle_num_vs_wan=0,
|
battle_num_vs_wan=0,
|
||||||
win_vs_wan=0,
|
win_vs_wan=0,
|
||||||
@ -274,7 +267,7 @@ class PokkenProfileData(BaseData):
|
|||||||
)
|
)
|
||||||
|
|
||||||
conflict = sql.on_duplicate_key_update(
|
conflict = sql.on_duplicate_key_update(
|
||||||
illustration_book_no=illust_no,
|
illustration_book_no=pokedex_number,
|
||||||
bp_point_atk=pokemon_data.c.bp_point_atk + atk,
|
bp_point_atk=pokemon_data.c.bp_point_atk + atk,
|
||||||
bp_point_res=pokemon_data.c.bp_point_res + res,
|
bp_point_res=pokemon_data.c.bp_point_res + res,
|
||||||
bp_point_def=pokemon_data.c.bp_point_def + defe,
|
bp_point_def=pokemon_data.c.bp_point_def + defe,
|
||||||
@ -293,7 +286,7 @@ class PokkenProfileData(BaseData):
|
|||||||
pokemon_id: int,
|
pokemon_id: int,
|
||||||
xp: int
|
xp: int
|
||||||
) -> None:
|
) -> None:
|
||||||
sql = update(pokemon_data).where(and_(pokemon_data.c.user==user_id, pokemon_data.c.char_id==pokemon_id)).values(
|
sql = pokemon_data.update(and_(pokemon_data.c.user==user_id, pokemon_data.c.illustration_book_no==pokemon_id)).values(
|
||||||
pokemon_exp=coalesce(pokemon_data.c.pokemon_exp, 0) + xp
|
pokemon_exp=coalesce(pokemon_data.c.pokemon_exp, 0) + xp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -315,6 +308,14 @@ class PokkenProfileData(BaseData):
|
|||||||
return None
|
return None
|
||||||
return result.fetchall()
|
return result.fetchall()
|
||||||
|
|
||||||
|
async def set_latest_mon(self, user_id: int, pokedex_no: int) -> None:
|
||||||
|
sql = profile.update(profile.c.user == user_id).values(
|
||||||
|
latest_use_pokemon=pokedex_no
|
||||||
|
)
|
||||||
|
result = await self.execute(sql)
|
||||||
|
if result is None:
|
||||||
|
self.logger.warning(f"Failed to update user {user_id}'s last used pokemon {pokedex_no}")
|
||||||
|
|
||||||
async def put_pokemon_battle_result(
|
async def put_pokemon_battle_result(
|
||||||
self, user_id: int, pokemon_id: int, match_type: PokkenConstants.BATTLE_TYPE, match_result: PokkenConstants.BATTLE_RESULT
|
self, user_id: int, pokemon_id: int, match_type: PokkenConstants.BATTLE_TYPE, match_result: PokkenConstants.BATTLE_RESULT
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -322,7 +323,7 @@ class PokkenProfileData(BaseData):
|
|||||||
Records the match stats (type and win/loss) for the pokemon and profile
|
Records the match stats (type and win/loss) for the pokemon and profile
|
||||||
coalesce(pokemon_data.c.win_vs_wan, 0)
|
coalesce(pokemon_data.c.win_vs_wan, 0)
|
||||||
"""
|
"""
|
||||||
sql = update(pokemon_data).where(and_(pokemon_data.c.user==user_id, pokemon_data.c.char_id==pokemon_id)).values(
|
sql = pokemon_data.update(and_(pokemon_data.c.user==user_id, pokemon_data.c.char_id==pokemon_id)).values(
|
||||||
battle_num_tutorial=coalesce(pokemon_data.c.battle_num_tutorial, 0) + 1 if match_type==PokkenConstants.BATTLE_TYPE.TUTORIAL else coalesce(pokemon_data.c.battle_num_tutorial, 0),
|
battle_num_tutorial=coalesce(pokemon_data.c.battle_num_tutorial, 0) + 1 if match_type==PokkenConstants.BATTLE_TYPE.TUTORIAL else coalesce(pokemon_data.c.battle_num_tutorial, 0),
|
||||||
battle_all_num_tutorial=coalesce(pokemon_data.c.battle_all_num_tutorial, 0) + 1 if match_type==PokkenConstants.BATTLE_TYPE.TUTORIAL else coalesce(pokemon_data.c.battle_all_num_tutorial, 0),
|
battle_all_num_tutorial=coalesce(pokemon_data.c.battle_all_num_tutorial, 0) + 1 if match_type==PokkenConstants.BATTLE_TYPE.TUTORIAL else coalesce(pokemon_data.c.battle_all_num_tutorial, 0),
|
||||||
|
|
||||||
@ -353,7 +354,7 @@ class PokkenProfileData(BaseData):
|
|||||||
"""
|
"""
|
||||||
Records profile stats
|
Records profile stats
|
||||||
"""
|
"""
|
||||||
sql = update(profile).where(profile.c.user==user_id).values(
|
sql = profile.update(profile.c.user==user_id).values(
|
||||||
ex_ko_num=coalesce(profile.c.ex_ko_num, 0) + exkos,
|
ex_ko_num=coalesce(profile.c.ex_ko_num, 0) + exkos,
|
||||||
wko_num=coalesce(profile.c.wko_num, 0) + wkos,
|
wko_num=coalesce(profile.c.wko_num, 0) + wkos,
|
||||||
timeup_win_num=coalesce(profile.c.timeup_win_num, 0) + timeout_wins,
|
timeup_win_num=coalesce(profile.c.timeup_win_num, 0) + timeout_wins,
|
||||||
@ -367,7 +368,12 @@ class PokkenProfileData(BaseData):
|
|||||||
self.logger.warning(f"Failed to update stats for user {user_id}")
|
self.logger.warning(f"Failed to update stats for user {user_id}")
|
||||||
|
|
||||||
async def update_support_team(self, user_id: int, support_id: int, support1: int = None, support2: int = None) -> None:
|
async def update_support_team(self, user_id: int, support_id: int, support1: int = None, support2: int = None) -> None:
|
||||||
sql = update(profile).where(profile.c.user==user_id).values(
|
if support1 == 4294967295:
|
||||||
|
support1 = None
|
||||||
|
|
||||||
|
if support2 == 4294967295:
|
||||||
|
support2 = None
|
||||||
|
sql = profile.update(profile.c.user==user_id).values(
|
||||||
support_set_1_1=support1 if support_id == 1 else profile.c.support_set_1_1,
|
support_set_1_1=support1 if support_id == 1 else profile.c.support_set_1_1,
|
||||||
support_set_1_2=support2 if support_id == 1 else profile.c.support_set_1_2,
|
support_set_1_2=support2 if support_id == 1 else profile.c.support_set_1_2,
|
||||||
support_set_2_1=support1 if support_id == 2 else profile.c.support_set_2_1,
|
support_set_2_1=support1 if support_id == 2 else profile.c.support_set_2_1,
|
||||||
@ -379,3 +385,15 @@ class PokkenProfileData(BaseData):
|
|||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
if result is None:
|
if result is None:
|
||||||
self.logger.warning(f"Failed to update support team {support_id} for user {user_id}")
|
self.logger.warning(f"Failed to update support team {support_id} for user {user_id}")
|
||||||
|
|
||||||
|
async def update_rankmatch_data(self, user_id: int, flag: int, rm_max: Optional[int], success: Optional[int], progress: List[int]) -> None:
|
||||||
|
sql = profile.update(profile.c.user==user_id).values(
|
||||||
|
rankmatch_flag=flag,
|
||||||
|
rankmatch_max=rm_max,
|
||||||
|
rankmatch_progress=progress,
|
||||||
|
rankmatch_success=success,
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await self.execute(sql)
|
||||||
|
if result is None:
|
||||||
|
self.logger.warning(f"Failed to update rankmatch data for user {user_id}")
|
||||||
|
Loading…
Reference in New Issue
Block a user