def data_updater(datafile): logger.info("updating {}".format(datafile)) data = http_client.get(None, GAME_DATA_URL.format(datafile)) if data is None: logger.error("updating {} fail".format(datafile)) return with open(get_resource_path(datafile), "w", encoding="utf-8") as f: f.write(json.dumps(data, indent=2, ensure_ascii=False)) logger.info("success") return data
def update_stage_table(): logger.info("updating stage table") data = http_client.get(None, STAGE_TABLE_URL) if data is None: logger.error("updating stage table fail") return with open(get_resource_path("stage_table.json"), "w", encoding="utf-8") as f: f.write(json.dumps(data, indent=2, ensure_ascii=False)) logger.info("success") return data
def ping(account: PlayerAccount): logger.info("ping auth server") data = U8_PING_DATA.copy() data["token"] = account.access_token data["sign"] = encryption.get_u8_auth_sign(account.access_token) ret_data = http_client.post(account, U8_PING_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 logger.info("success") 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 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 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