def verify(request): req = request._proto res = verify_buy(request._char_id, req.receipt) response = BuyVerityResponse() response.ret = res.ret if response.ret: return pack_msg(response) response.name = res.name response.add_sycee = res.add_sycee return pack_msg(response)
def arena_panel(request): arena = Arena(request._char_id) response = ArenaPanelResponse() response.ret = 0 arena._fill_up_panel_msg(response.panel) return pack_msg(response)
def bind(request): req = request._proto data = { 'name': req.email, 'password': req.password, 'token': req.device_token } try: res = api_account_bind(data) except APIFailure: raise SanguoException( errormsg.SERVER_FAULT, request._char_id, 'Account Bind', 'APIFailure. api_account_bind' ) if res['ret'] != 0: raise SanguoException( res['ret'], request._char_id, 'Account Bind', 'api_account_bind, ret = {0}'.format(res['ret']) ) response = BindAccountResponse() response.ret = 0 response.email = req.email response.password = req.password return pack_msg(response)
def panel(request): s = Store(request._char_id) msg = s.fill_up_notify_msg() response = StorePanelResponse() response.ret = 0 response.panel.MergeFrom(msg) return pack_msg(response)
def process_request(self, request): try: super(RequestFilterWrapperForVersionCheck, self).process_request(request) except VersionCheckFailure: version_msg = VersionCheckResponse() version_msg.ret = 0 version_msg.version = version.version return HttpResponse(pack_msg(version_msg), content_type='text/plain')
def prisoner_get(request): req = request._proto p = Prison(request._char_id) got = p.prisoner_get(req.id, [i for i in req.treasure_ids]) msg = PrisonerGetResponse() msg.ret = 0 msg.success = got return pack_msg(msg)
def merge(request): req = request._proto item = Item(request._char_id) new_id = item.gem_merge(req.id) response = MergeGemResponse() response.ret = 0 response.new_id = new_id return pack_msg(response)
def resume(request): sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = arrow.utcnow().timestamp login_signal.send( sender=None, char_id=request._char_id, ) new_session = GameSession(request._account_id, request._server_id, request._char_id) encrypted_session = crypto.encrypt(session_dumps(new_session)) Player(request._char_id).set_login_id(new_session.login_id) response = ResumeResponse() response.ret = 0 return [pack_msg(response, encrypted_session), pack_msg(sync)]
def hang_get_reward(request): affairs = Affairs(request._char_id) drop = affairs.get_hang_reward() msg = HangGetRewardResponse() msg.ret = 0 msg.drop.MergeFrom(drop) return pack_msg(msg)
def resume(request): req = request._proto sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = timezone.utc_timestamp() login_signal.send( sender=None, account_id=request._account_id, server_id=request._server_id, char_id=request._char_id, ) new_session = '%d:%d:%d' % (request._account_id, req.server_id, request._char_id) new_session = crypto.encrypt(new_session) response = ResumeResponse() response.ret = 0 return [pack_msg(response, new_session), pack_msg(sync)]
def purchase_ios_verify(request): req = request._proto p = PurchaseActionIOS(request._char_id) goods_id = p.check_verify(req.receipt) response = PurchaseIOSVerifyResponse() response.ret = 0 response.goods_id = goods_id return pack_msg(response)
def purchase_allsdk_verify(request): req = request._proto p = PurchaseActionAllSDk(request._char_id) goods_id = p.check_verify(req.sn, req.goods_id, req.platform) response = PurchaseAllSDKVerifyResponse() response.ret = 0 response.goods_id = goods_id return pack_msg(response)
def open(request): req = request._proto p = HeroPanel(request._char_id) hero_oid = p.open(req.id) response = GetHeroResponse() response.ret = 0 response.id = req.id response.hero_oid = hero_oid return pack_msg(response)
def prisoner_kill(request): req = request._proto p = Prison(request._char_id) attachment_msg = p.kill(req.id) response = PrisonerKillResponse() response.ret = 0 response.reward.MergeFrom(attachment_msg) return pack_msg(response)
def stuff_use(request): req = request._proto item = Item(request._char_id) res = item.stuff_use(req.id, req.amount) response = StuffUseResponse() response.ret = 0 if res: response.attachment.MergeFrom(res) return pack_msg(response)
def arena_battle(request): char_id = request._char_id arena = Arena(char_id) msg = arena.battle() response = ArenaResponse() response.ret = 0 response.battle.MergeFrom(msg) return pack_msg(response)
def arena_battle(request): char_id = request._char_id arena = Arena(char_id) msg, drop = arena.battle() response = ArenaResponse() response.ret = 0 response.battle.MergeFrom(msg) response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def strengthen_equip(request): req = request._proto item = Item(request._char_id) equip_msgs = item.equip_level_up(req.id, req.quick) response = StrengthEquipResponse() response.ret = 0 for m in equip_msgs: equip_msg = response.equips.add() equip_msg.MergeFrom(m) return pack_msg(response)
def hang_start(request): req = request._proto affairs = Affairs(request._char_id) drop = affairs.start_hang(req.city_id) msg = HangStartResponse() msg.ret = 0 if drop: msg.drop.MergeFrom(drop) return pack_msg(msg)
def plunder(request): char_id = request._char_id p = Plunder(char_id) msg, drop = p.plunder() response = PlunderResponse() response.ret = 0 response.battle.MergeFrom(msg) response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def products(request): response = GetProductsResponse() response.ret = 0 data = get_purchase_products() for k, v in data.iteritems(): p = response.products.add() p.id = k p.name = v['name'] p.des = v['des'] return pack_msg(response)
def plunder(request): req = request._proto char_id = request._char_id p = Plunder(char_id) msg = p.plunder(req.id) response = PlunderResponse() response.ret = 0 response.battle.MergeFrom(msg) return pack_msg(response)
def prize_get(request): req = request._proto char_id = request._char_id attachment = Attachment(char_id) att_msg = attachment.get_attachment(req.prize.id, req.prize.param) response = PrizeResponse() response.ret = 0 response.prize.MergeFrom(req.prize) response.drop.MergeFrom(att_msg) return pack_msg(response)
def get_reward(request): req = request._proto char_id = request._char_id p = Plunder(char_id) attachment_msg = p.get_reward(req.tp) response = PlunderGetRewardResponse() response.ret = 0 response.tp = req.tp response.reward.MergeFrom(attachment_msg) return pack_msg(response)
def candidate_list(request): char_id = request._char_id f = Friend(char_id) res = f.candidate_list() response = protomsg.PlayerListResponse() response.ret = 0 for r in res: msg = response.players.add() f._msg_friend(msg, r, FRIEND_NOT) return pack_msg(response)
def plunder_refresh(request): req = request._proto char_id = request._char_id p = Plunder(char_id) target = p.get_plunder_target(req.city_id) response = PlunderRefreshResponse() if not target: response.ret = errormsg.PLUNDER_NO_RIVAL else: response.ret = 0 response.plunder.MergeFrom(target.make_plunder_msg(Char(char_id).mc.level)) return pack_msg(response)
def arena_battle(request): char_id = request._char_id arena = Arena(char_id) msg, adding_score = arena.battle() response = ArenaResponse() response.ret = 0 response.battle.MergeFrom(msg) drop = make_standard_drop_from_template() drop["stuffs"] = [(1001, adding_score)] response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def plunder_list(request): char_id = request._char_id p = Plunder(char_id) res = p.get_plunder_list() response = PlunderListResponse() response.ret = 0 for _id, name, power, formation, is_robot, gold in res: plunder = response.plunders.add() plunder.id = _id plunder.name = name plunder.gold = gold plunder.power = power plunder.hero_original_ids.extend(formation) return pack_msg(response)
def create_character(request): req = request._proto data = { 'account_id': request._account_id, 'server_id': server.id, 'name': req.name } res = api_character_create(data) if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Character Create', 'api_character_create, ret = {0}'.format(res['ret']) ) char_id = res['data']['char_id'] try: char_initialize(request._account_id, server.id, char_id, req.name) except Exception as e: data = { 'char_id': char_id, } api_character_failure(data) raise e login_signal.send( sender=None, char_id=char_id, real_login=True, ) request._char_id = char_id game_session = request._game_session game_session.char_id = char_id new_session = crypto.encrypt(session_dumps(game_session)) Player(char_id).set_login_id(game_session.login_id) response = CreateCharacterResponse() response.ret = 0 return pack_msg(response, new_session)
def create_character(request): req = request._proto data = { 'account_id': request._account_id, 'server_id': server.id, 'name': req.name } try: res = api_character_create(data) except APIFailure: raise SanguoException( errormsg.SERVER_FAULT, 0, 'Character Create', 'APIFailure, api_character_create' ) if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Character Create', 'api_character_create, ret = {0}'.format(res['ret']) ) char_id = res['data']['char_id'] login_signal.send( sender=None, char_id=char_id ) request._char_id = char_id game_session = request._game_session game_session.char_id = char_id new_session = crypto.encrypt(session_dumps(game_session)) Player(char_id).set_login_id(game_session.login_id) response = CreateCharacterResponse() response.ret = 0 return pack_msg(response, new_session)
def login(request): req = request._proto data = {} data['server_id'] = req.server_id if req.regular.email: data['method'] = 'regular' data['name'] = req.regular.email data['password'] = req.regular.password else: data['method'] = 'anonymous' data['token'] = req.anonymous.device_token try: res = api_account_login(data) except APIFailure: raise SanguoException(errormsg.SERVER_FAULT, 0, 'Login', 'APIFailure. api_account_login') if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Login', 'login, api_account_login, ret = {0}'.format(res['ret'])) account_id = res['data']['account_id'] char_id = res['data']['char_id'] new_token = res['data']['new_token'] request._account_id = account_id request._server_id = req.server_id login_signal.send(sender=None, account_id=request._account_id, server_id=request._server_id, char_id=char_id) if char_id: request._char_id = char_id session_str = '{0}:{1}:{2}'.format(request._account_id, request._server_id, request._char_id) else: request._char_id = None session_str = '{0}:{1}'.format(request._account_id, request._server_id) session = crypto.encrypt(session_str) response = StartGameResponse() response.ret = 0 if req.regular.email: response.regular.MergeFrom(req.regular) else: response.anonymous.device_token = str(new_token) response.need_create_new_char = char_id == 0 sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = timezone.utc_timestamp() return [pack_msg(response, session), pack_msg(sync)]
def sync(request): msg = SyncResponse() msg.ret = 0 msg.utc_timestamp = arrow.utcnow().timestamp return pack_msg(msg)
def purchase_91_confirm(request): p = PurchaseAction(request._char_id) response = p.check_confirm() return pack_msg(response)
def sync(request): msg = SyncResponse() msg.ret = 0 msg.utc_timestamp = timezone.utc_timestamp() return pack_msg(msg)
def get_leaderboard(request): msg = PlunderLeaderboardWeekly.make_get_response() return pack_msg(msg)
def checkin(request): c = CheckIn(request._char_id) msg = c.checkin() return pack_msg(msg)
def arena_panel(request): response = Arena(request._char_id).make_panel_response() return pack_msg(response)