def start_battle_replay(account: PlayerAccount, battle_type, stage_id): battle_type = BattleModel.BattleType.get_value_or_default(battle_type) api = BATTLE_START_URL.format(battle_type=battle_type) data = BATTLE_START_REPLAY_DATA.copy() mybattle = BattleModel.Battle(account, battle_type, stage_id) if not mybattle.has_battle_data(): logger.error("[{}] battle reply data for stage id={} not found".format( account.uid, stage_id)) return if account.current_battle.get(stage_id) is not None: logger.warning("[{}] already start battle for stage id={}".format( account.uid, stage_id)) return logger.info("[{}] starting battle stage_id={}".format( account.uid, stage_id)) data["stageId"] = stage_id # simulate system delay data["startTs"] = mybattle.start_time - 1 ret_data = http_client.post_with_seqnum(account, api, data=json.dumps(data)) if ret_data.get("battleId") is None: logger.warning("[{}] fail to start battle replay, reason: {}".format( account.uid, ret_data)) return ret_data mybattle.battle_id = ret_data.get("battleId") account.current_battle[stage_id] = mybattle return ret_data
def get_with_seqnum(self, account: PlayerAccount, url, headers=None, **kwargs): secure_header = { 'uid': int(account.uid), 'secret': account.secret, 'seqnum': account.seqnum } headers = secure_header if headers is None else update_header( headers, secure_header) ret = self._get(url, headers=headers, **kwargs) if ret is None: account.seqnum = account.seqnum + 1 return None else: account.seqnum = int(ret.headers.get("Seqnum")) return ret.json()
def get_token(account: PlayerAccount, login_para: LoginPara): logger.info("get token") data = U8_GETTOKEN_DATA.copy() data["appId"] = login_para.APP_ID data["channelId"] = login_para.CHANNEL_ID data["deviceId"] = account.device_id data["deviceId2"] = account.device_id2 data["extension"] = json.dumps({ "uid": account.channel_uid, "access_token": account.access_token }).replace(" ", "") data["platform"] = PlatformKey.ANDROID.value data["subChannel"] = login_para.SUB_CHANNEL data["worldId"] = login_para.WORLD_ID data["sign"] = encryption.get_u8_gettoken_sign( login_para.APP_ID, login_para.CHANNEL_ID, account.device_id, account.device_id2, account.device_id3, { "uid": account.channel_uid, "access_token": account.access_token }, PlatformKey.ANDROID.value, login_para.SUB_CHANNEL, login_para.WORLD_ID) print(data) ret_data = http_client.post(account, U8_GETTOKEN_URL, data=json.dumps(data)) if ret_data is None: logger.error("http get/post fail") return if ret_data.get("result") is None or ret_data["result"] != 0: logger.warning("fail,reason: {}".format(json.dumps(ret_data))) return account.uid = ret_data["uid"] account.token = ret_data["token"] account.channel_uid = ret_data["channelUid"] logger.info("get token success with uid={},token={}".format( ret_data["uid"], ret_data["token"])) return ret_data
def auth(account: PlayerAccount): logger.info("login by access_token={}".format(account.access_token)) data = U8_AUTH_DATA.copy() data["token"] = account.access_token data["sign"] = encryption.get_u8_auth_sign(account.access_token) ret_data = http_client.post(account, U8_AUTH_URL, data=json.dumps(data)) if ret_data is None: logger.error("http get/post fail") return if ret_data.get("uid") is None: logger.warning("fail,reason: {}".format(json.dumps(ret_data))) return account.channel_uid = ret_data["uid"] logger.info("auth success with channel_uid={}".format(ret_data["uid"])) return ret_data
def login(account: PlayerAccount): logger.info("login by username={} and password={}".format( account.username, account.password)) data = U8_LOGIN_DATA.copy() data["account"] = account.username data["deviceId"] = account.device_id data["password"] = account.password data["platform"] = PlatformKey.ANDROID.value data["sign"] = encryption.get_u8_login_sign(account.username, account.password, account.device_id, PlatformKey.ANDROID.value) ret_data = http_client.post(account, U8_LOGIN_URL, data=json.dumps(data)) if ret_data is None: logger.error("http get/post fail") return if ret_data["result"] != 0: logger.warning("fail,reason: {}".format(json.dumps(ret_data))) return account.channel_uid = ret_data["uid"] account.access_token = ret_data["token"] logger.info("login success with channel_uid={},access_token={}".format( ret_data["uid"], ret_data["token"])) return ret_data
from client.data_model import MissionModel from client.data_model.akaccount import PlayerAccount from client.api import auth_server, game_server, config_server, data_server import time from client.data_model.mission import get_mission_by_type, MissionType data_server.update_mission_table() data_server.update_character_table() data_server.update_skin_table() data_server.update_item_table() data_server.update_gacha_table() print(config_server.get_version()) print(config_server.get_network(ConfigServerName.OFFICIAL.value)) acc = PlayerAccount.init_random_device() acc.username = "******" acc.password = "******" # # acc = load_from_file("tempuser.json") # # auth_server.auth(acc) auth_server.login(acc) time.sleep(1) auth_server.ping(acc) time.sleep(1) auth_server.get_token(acc) time.sleep(1) game_server.login(acc) time.sleep(1) game_server.sync_data(acc) time.sleep(1)