def rc_sellAll(self, equip=None, item=None, fate=None, gem=None): """ 批量卖出 """ resp_f = 'sellAll' rs, data = self.player.bag.sell_all(equip, item, fate, gem) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_enterHitFate(self): """ 进入猎命获取初始数据 """ resp_f = 'enterHitFate' rs, data = self.player._game.hfate_mgr.enter_hit_fate(self.player) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0)
def rc_mergeItem(self, desId, count, srcId): """ 物品合成 """ res_f = 'mergeItem' rs, data = self.player.merge_item(desId, count, srcId) if rs: return pack_msg(res_f, 1, data=data) return pack_msg(res_f, 0, err=data)
def rc_mergeAllFt(self): """ 命格一键合成""" resp_f = 'mergeAllFt' rs, data = self.player.roles.merge_all_fate() if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_carExchange(self, cid): """ 坐骑兑换 """ resp_f = 'carExchange' rs, data = self.player.car_exchange(cid) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_carDo(self, cid): """ 坐骑的操作 """ resp_f = 'carDo' rs, data = self.player.car_do(cid) if rs: return pack_msg(resp_f, 1) return pack_msg(resp_f, 0, err=data)
def rc_bfTaskGet(self, index): """ 接兵符任务 """ resp_f = 'bfTaskGet' rs, data = self.player._game.bftask_mgr.bf_task_get(self.player, index) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_bfTaskFinish(self): """ 立即完成的兵符任务 """ resp_f = 'bfTaskFinish' rs, data = self.player._game.bftask_mgr.bf_finish(self.player) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_bfTaskRe(self, type): """ 兵符任务刷新 """ resp_f = 'bfTaskRe' rs, data = self.player._game.bftask_mgr.bf_task_re(self.player, type) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_bfTaskBox(self): """ 打开兵符宝箱 """ resp_f = 'bfTaskBox' rs, data = self.player._game.bftask_mgr.bf_task_box(self.player) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_bfTaskEnter(self): """ 进入兵符任务 """ resp_f = 'bfTaskEnter' rs, data = self.player._game.bftask_mgr.bf_task_enter(self.player) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_chapterComplete(self): """ 完成章节 """ resp_f = 'chapterComplete' if self.player.task.chapter_complete(): return pack_msg(resp_f, 1) else: return pack_msg(resp_f, 0)
def rc_pAttrSet(self, key, value): """ 设置属性 """ resp_f = 'pAttrSet' if not key: return pack_msg(resp_f, 0) self.player.play_attr.set(key, value) return pack_msg(resp_f, 1)
def rc_stopSit(self): """ 停止打坐 """ resp_f = 'stopSit' rs, data = self.player.sit.stop_sit() if rs: return pack_msg(resp_f, 1) return pack_msg(resp_f, 0, err=data)
def rc_onlineSitExp(self): """ 上线获取打坐信息 """ resp_f = 'onlineSitExp' rs, data = self.player.sit.online_sit() if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def player_login(self, pid): resp_f = 'enter' player_data = PlayerData.load(pid) player = Player() player.data.update(player_data) if player.data.id is None: log.error('player(%d)player_login load error:%s', pid, player_data) return pack_msg(resp_f, 0, err=errcode.EC_VALUE) if player.is_forbid_login: return pack_msg(resp_f, 0, err=errcode.EC_FORBID_LOGON) if not self.mgr.add_player(player): return pack_msg(resp_f, 0, err=errcode.EC_TIME_UNDUE) self.player = player try: player.set_rpc(self._rpc) player.login(self) map_id = player.data.mapId if player.data.mapId else 1 player.scene_enter(map_id, login=True) self.mgr.logon_player(player) log.debug(u'(%s)玩家(%s)登陆成功', player.data.id, player.data.name) player.send_msg(player.get_init_msg()) spawn(self.mgr.logoned_player, player) return pack_msg(resp_f, 1) except: log.log_except(u'玩家(%s)登陆初始化失败', player.data.id) self.player_logout() return pack_msg(resp_f, 0, err=errcode.EC_VALUE)
def rc_allyEnter(self): """ 玩家进入游戏的发送 """ resp_f = "allyEnter" rs, data = self.player._game.rpc_ally_mgr.enter(self.player) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_new(self, name, rid): """ 新建player """ resp_f = 'new' #log.debug(u'rc_new:%s', name) #判断该账号是否超过创建角色的数目 name = name.strip() tPlayerNum = len( Game.rpc_store.query_loads(TN_PLAYER, dict(uid=self.data.id))) if tPlayerNum > Game.instance.setting_mgr.setdefault( USE_PLAYS_MAX, USE_PLAYS_MAX_V): return pack_msg(resp_f, 0, err=errcode.EC_USER_MAX) if not name or rid not in Game.res_mgr.roles: return pack_msg(resp_f, 0, err=errcode.EC_VALUE) #敏感词 if Game.rpc_ban_word_mgr.check_ban_word(name): #if Game.setting_mgr.check_ban_word(name): return pack_msg(resp_f, 0, err=errcode.EC_NAME_REPEAT) #名字长度截取 player_dict = Game.rpc_player_mgr.new_player(self.data.id, name[:50], rid) if not player_dict: return pack_msg(resp_f, 0, err=errcode.EC_NAME_REPEAT) player = Player.new_player(player_dict) log.info(u'用户(%s)新建玩家(%s):%s', self.data.name, name, player.data.id) data = player.to_dict() self.player_datas.append(data) self.players[player.data.id] = len(self.player_datas) - 1 return pack_msg(resp_f, 1, data=data)
def rc_speedUp(self, mul): """vip战斗加速mul战斗的倍数""" resp_f = 'speedUp' rs, data = self.player.vip_attr.speed_up(mul) if rs: return pack_msg(resp_f, 1, data=data) return pack_msg(resp_f, 0, err=data)
def rc_rewardCode(self, code): """ 兑换码领取 """ resp_f = 'rewardCode' rs, data = self.player._game.reward_mgr2.reward_code(self.player, code) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_useItem(self, id): """ 使用物品,获取东西 """ resp_f = 'useItem' rs, data = self.player.use_item(id) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_fightReport(self, id): """ 获取战报 """ resp_f = 'fightReport' rs, data = self.player._game.rpc_report_mgr.get_url(id) if rs: return pack_msg(resp_f, 1, data=dict(url=data)) return pack_msg(resp_f, 0, err=data)
def rc_gemShop(self): """珠宝商店""" resp_f = 'gemShop' rs, data = self.player._game.shop_mgr.gem_enter(self.player) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_resetShop(self): """ 重置神秘商店 """ resp_f = "resetShop" rs, data = self.player._game.shop_mgr.resetShop(self.player) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_shopBuy(self, t=2, sid=0): """ 神秘商店购买物品 """ resp_f = 'shopBuy' rs, data = self.player._game.shop_mgr.buy(self.player, t, sid) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_dshopBuy(self, id=0, c=0): """可购买物品""" resp_f = 'dshopBuy' rs, data = self.player._game.shop_mgr.dshopBuy(self.player, id, c) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_shop(self, t=2): """ 神秘商店 """ resp_f = 'shop' rs, data = self.player._game.shop_mgr.enter(self.player, t) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_deepEnter(self, type): """ 进入深渊 """ resp_f = 'deepEnter' rs, data = self.player._game.deep_mgr.enter(self.player, type) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def rc_foodEat(self, id, t): """ 进食 """ resp_f = 'foodEat' rs, err = self.player.buffs.eat(id, t) if not rs: return pack_msg(resp_f, 0, err=err) return pack_msg(resp_f, 1, data=err)
def rc_fishEnter(self): """ 进入钓鱼操作获取所有的鱼饵 """ resp_f = 'fishEnter' rs, data = self.player._game.fish_mgr.fish_enter(self.player) if not rs: return pack_msg(resp_f, 0, err=data) return pack_msg(resp_f, 1, data=data)
def _notice_data(self, l_sec): """ 广播数据 包括世界boss剩余血量和排名 """ #log.debug('(%s)WorldBoss_notice_data %s', self.data.blid, l_sec) hp_resp_f = 'bossHp' rank_resp_f = 'bossRank' hp_time = self.fetch_hp_time c = self.fetch_rank_time / hp_time sleep(l_sec) tmp = 0 self.is_start = is_win =True while not self.gm_stoped: sleep(hp_time) msg = pack_msg(hp_resp_f, 1, data={'hp':self.boss_hp, 'mhp':self.max_hp}) Game.rpc_player_mgr.player_send_msg(self.enter_pids, msg) #log.debug('world hp enter_pids %s %s', self.boss_hp, self.enter_pids) if self.boss_hp <= 0: break if self.boss_start + self.fetch_world_boss_times < time.time(): is_win = False break tmp += 1 if tmp != c: continue tmp = 0 rs, data = self._get_rank() #log.debug('world_rank %s', data) if not rs: continue msg = pack_msg(rank_resp_f, 1, data=data) Game.rpc_player_mgr.player_send_msg(self.enter_pids, msg) self.boss_mgr.w_start_boss = None log.debug('is_win------- %s, gm %s, join-player %s', is_win, self.gm_stoped, len(self.pid_hurts)) if self.gm_stoped: is_win = False #if is_win: #更改为不管怪物是否死都发奖励 try: #发放奖励 self._reward() #vip不参加也发奖励 self._reward_vip() except: log.log_except() #写入log 记录伤害 self._log_info() #清楚数据 self._clear_data() #记录数据 self.save_data(is_win) if self.boss_mgr.gm_wboss: self.boss_mgr.gm_wboss = False self.boss_mgr.gm_start = False self.gm_stoped = False
def recv_mails(self, mids): """ 接收发送到玩家的新邮件 """ if not self.player: return if isinstance(mids, int): mids = [mids] news = [] waits = [] for mid in mids: m = self.player._game.rpc_store.load(TN_P_MAIL, mid) if not m: continue if not self.player: return mail = Mail(adict=m) news.append(mail) #log.debug('(%s)recv_mails.mail:%s', self.player.data.id, mid) self.mails[mid] = mail if mail.data.wid: wait = self.player.wait_bag.load_item(mail.data.wid) if wait: waits.append(wait) if news and self.player and self.player.logined: #主动推送消息 resp_f = 'mailPush' self.player.send_msg(pack_msg(resp_f, 1, data=self.player.pack_msg_data(mails=news, waits=waits)))
def get_enter_msg(self): resp_f = 'enterFete' vip = self.player.data.vip num1 = self.player._game.fete_mgr.free_num(vip) - self.feteData.n1 num2 = self.player._game.fete_mgr.coin2_num(vip) - self.feteData.n2 #返回可以使用的次数 return pack_msg(resp_f, 1, data={'num1':num1, 'num2':num2})
def send_accept_tasks(self, tasks): """ 主动推送 """ if self.player is None or not self.player.logined: return #log.debug('send_accept_tasks:%s', str([(t.data.tid, t.data.id) for t in tasks])) resp_f = 'taskPush' self.player.send_msg(pack_msg(resp_f, 1, data=[t.to_dict() for t in tasks]))
def wear_equip(self, player, equip, res_equip, pack_msgd=1): """ 穿装备 """ uid = self.get_equip(res_equip.part) if uid == equip.data.id: return False, errcode.EC_VALUE if equip.data.used: return False, errcode.EC_EQUIP_NOUSE if uid: rs, off_equip = self.take_off_equip(player, res_equip.part, forced=1) if not rs: off_equip = None else: off_equip = None self.set_equip(res_equip.part, equip.data.id) equip.data.used = USED_DO if off_equip: player.bag.update_equip(equip) else: player.bag.update_equip(equip, used_count=-1) self.modified = True if self.is_main: if self.is_body_place(res_equip.part): #主将换装 player.update_scene_info({IF_IDX_EID:res_equip.id}) #监听主将传装备 player.safe_pub(MSG_MAIN_WEAR_EQUIP, self, equip, res_equip) if pack_msgd: resp_f = 'wearEq' data = dict(id=equip.data.id, rid=self.data.id) if off_equip: data['uid'] = uid return True, (off_equip, pack_msg(resp_f, 1, data=data)) return True, off_equip
def _notice_data(self, l_sec, stop=False): """ 同盟广播数据 包括boss剩余血量和排名 """ #log.debug('_a_data %s', l_sec) hp_resp_f = 'allyBossHp' rank_resp_f = 'allyBossRank' hp_time = self.fetch_hp_time c = self.fetch_rank_time / hp_time sleep(l_sec) tmp = 0 self.is_start = is_win = True while not stop and not self.gm_stoped: sleep(hp_time) msg = pack_msg(hp_resp_f, 1, data={'hp':self.boss_hp}) Game.rpc_player_mgr.player_send_msg(self.enter_pids, msg) if self.boss_hp <= 0: break if self.boss_start + self.fetch_ally_boss_times < time.time(): is_win = False break tmp += 1 if tmp != c: continue tmp = 0 rs, data = self._get_rank() if not rs: continue msg = pack_msg(rank_resp_f, 1, data=data) Game.rpc_player_mgr.player_send_msg(self.enter_pids, msg) #log.debug('ally_isWin %s', is_win) if self.data.aid in self.boss_mgr.notices: self.boss_mgr.notices.remove(self.data.aid) if self.gm_stoped: is_win = False if is_win: try: #发放奖励 self._reward() except: log.log_except() #清楚数据 self._clear_data() #记录数据 self.save_data(is_win) if self.boss_mgr.gm_aboss: self.boss_mgr.gm_aboss = 0 self.gm_stoped = False
def _send_msgs(self, all_msgs, id2msgs): #log.debug('_send_msgs(%s, %s)', all_msgs, id2msgs) resp_f = 'chatMsg' if all_msgs: pids = Game.instance.player_mgr.players.iterkeys() all_msgs = prepare_send(pack_msg(resp_f, 1, data=all_msgs)) elif id2msgs: pids = id2msgs.iterkeys() else: return for pid in pids: p = Game.instance.player_mgr.get_player(pid) if not p: continue if all_msgs: p.send_msg(all_msgs) if pid in id2msgs: p.send_msg(pack_msg(resp_f, 1, data=id2msgs[pid]))
def _notice(self, l_sec, pids=None): """ 活动开启提前广播 """ notice_resp_f = 'awarNotice' if pids is None: pids = self._game.rpc_ally_mgr.get_allypids_by_level(self.warstart_config.unlock) if not pids: return data = dict(type=self.warstart_config.type, ltime=l_sec) msg = pack_msg(notice_resp_f, 1, data=data) self._game.rpc_player_mgr.player_send_msg(pids, msg)
def add_sit_exp(self): """ 添加经验并发给客户端 """ resp_f = 'addSitExp' vip = self.player.data.vip res_rate = self.vip_addexp(vip) tResLevelExp = self._get_res_exp(self.player.data.level) add_sit_exp = tResLevelExp.siteExp + tResLevelExp.siteExp * res_rate / 100 self.player.add_exp(add_sit_exp) #主动发送给客户端 self.sit_data[SIT_EXP] += add_sit_exp self.player.send_msg(pack_msg(resp_f, 1, data={'exp':self.sit_data[SIT_EXP]}))
def notice(self, times, pids=None): """ boss广播开启时间 """ if self.aid: resp_f = 'allyBossNotice' if not pids: pids = Game.rpc_ally_mgr.member_pids_by_aid(self.data.aid) else: resp_f = 'bossNotice' pids = Game.rpc_player_mgr.get_pids_by_level(self.fetch_boss_uplevel, start_chapter=True) #log.debug('login _------notice ---- %s', resp_f) msg = pack_msg(resp_f, 1, data={'times': times}) Game.rpc_player_mgr.player_send_msg(pids, msg)
def send_msg(self, resp_f, data, remove_pid=0, send_pids=None): """ 主动发给客户端的数据 """ msg = pack_msg(resp_f, 1, data=data) if not send_pids: if self.war_data: send_pids = self.war_data.war_pids[:] else: send_pids = self.room.pids[:] if remove_pid and remove_pid in send_pids: send_pids.remove(remove_pid) if send_pids: log.debug('broad-- pids-%s, resp_f-%s, data- %s', send_pids, resp_f, msg) Game.rpc_player_mgr.player_send_msg(send_pids, msg)
def _handle_type_data(self, type): """ 处理特殊类型凌晨刷新的数据(主动发给客户端) """ #猎命 if type == WAITBAG_TYPE_HITFATE: hfate = getattr(self.player.runtimes, PLAYER_ATTR_HITFATE) if hfate.handle_pass_day(fetch=True): resp_f = 'enterHitFate' rs, data = hfate.enter() if rs: self.player.send_msg(resp_f, 1, data=data) #时光盒 elif type == WAITBAG_TYPE_TIMEBOX: ptbox = getattr(self.player.runtimes, TN_P_TBOX) ch = ptbox.handle_pass_day(fetch=True) if ch: resp_f = 'tBoxEnter' rs, data = ptbox.enter(ch) if rs: pack = pack_msg(resp_f, 1, data={'tbox':data.to_dict()}) else: pack = pack_msg(resp_f, 0, data=data) self.player.send_msg(pack)
def scenes_changes(self, changes, _no_result=True): """ 场景变更,发送消息 """ #log.debug('scenes_changes(%s)', changes) resp_f = 'mapChange' #log.debug('scenes_changes:%s', changes) for scene_id, (plist, change) in changes.iteritems(): #pack_msg出来的数据只能发送一次,里面的_tag会消失,如果需要发送多次用prepare_send data = prepare_send(pack_msg(resp_f, 1, data=change)) for pid in plist: player = self._game.player_mgr.players.get(pid) if not player: continue player.send_msg(data)
def pay_back(self, bag_items): """ 支付回调,获取奖励 """ #_last = self.player.data.vipCoin #调整vip self.player.data.vipCoin += bag_items.coin2 #log.info("pay_back_vipCoin last:%s, now:%s", _last, self.player.data.vipCoin) self._init_vip_level() #支付奖励,马上保存 self.player.save(full=1) #通知前端 resp_f = 'goodsGive' data = dict(player=self.player.to_dict(), data=bag_items.pack_msg(), vipData=self.player.vip_attr.to_dict()) self.player.send_msg(pack_msg(resp_f, 1, data=data))
def rc_login(self, user, pwd, UDID, DT, MAC='', DEV='', VER='', **kw): """ 用户登录请求 """ log.debug(u'收到用户登录请求:%s, %s, %s, %s, %s, %s, %s, %s', user, pwd, UDID, DT, MAC, DEV, VER, kw) resp_f = 'login' if self.count >= self.max_players: return pack_msg(resp_f, 0, err=language.STR_PLAYER_3) if not user:#游客登录 u = Game.rpc_store.query_loads(TN_USER, dict(UDID=UDID, name='')) else: #检查user,pwd是否正确,返回uid u = Game.rpc_store.query_loads(TN_USER, dict(name=user)) if not u: #不存在自动增加 u = self._new_user(SNS_NONE, user, pwd, UDID, DT, MAC, DEV, VER) else: u = u[0] u = User(adict=u) if u.data.pwd != pwd: return pack_msg(resp_f, 0, err=language.LOGIN_PWD_ERROR) params = self._get_login_params(user, u.data.id) return pack_msg(resp_f, 1, data=params)
def call(self, name, kw): _no_result = kw.pop('_no_result', False) msg = pack_msg(name, 1, data=kw) self.rpc.send(msg) if _no_result: return None, None, None assert name not in self.waits, 'waits error' rs = AsyncResult() self.waits[name] = rs try: result = rs.get(timeout=300) if rs.exception: raise rs.exception return result finally: self.waits.pop(name)
def rc_loginSNS(self, t, sid, session, UDID, DT, MAC='', DEV='', VER='', **kw): """ 平台登录接口 """ resp_f = 'loginSNS' if not self.area_legal(): return pack_msg(resp_f, 0, err=errcode.EC_LOGIN_AREA_ERR) if not self.is_debug_time(): return pack_msg(resp_f, 0, err=errcode.EC_LOGIN_DEBUG_TIME) log.debug(u'平台(%s)用户登录请求:%s, %s, %s, %s, %s, %s, %s, %s', t, sid, session, UDID, DT, MAC, DEV, VER, kw) if self.count >= self.max_players: return pack_msg(resp_f, 0, err=errcode.EC_TEAM_ROLE_FULL) if not sid and t not in SNS_LOGINS:#游客登录 return pack_msg(resp_f, 0, err=errcode.EC_VALUE) #u = Game.rpc_store.query_loads(TN_USER, dict(UDID=UDID, name='')) else: rs, data = self.sns_client.login(t, sid, session) if not rs: return pack_msg(resp_f, 0, err=data) if data:#login返回sid sid = data u = UserData.user_by_sns(t, sid) if not u: #不存在自动增加 u = self._new_user(t, sid, '', UDID, DT, MAC, DEV, VER) else: u = u[0] u = User(adict=u) #如果mac地址不同,记录 if u.data.UDID != UDID or u.data.DT != DT or \ u.data.DEV != DEV or \ u.data.MAC != MAC or u.data.VER != VER: def _log_mac(): if 1: #强制保存更新信息, not u.data.MAC: u.data.UDID = UDID u.data.DT = DT u.data.MAC = MAC u.data.DEV = DEV u.data.VER = VER u.save(Game.rpc_store) else: self.glog(PM_MAC, u=u.data.id, UDID=UDID, MAC=MAC, DEV=DEV, VER=VER) spawn(_log_mac) params = self._get_login_params(sid, u.data.id, t) log.debug(u'loginSNS finish:%s', params) return pack_msg(resp_f, 1, data=params)
def attach_ally(self, aid, n, dic): resp_f = "allyUpdate" self.set_ally(dict(aid=aid, n=n)) self.send_msg(pack_msg(resp_f, 1, data=dic))
def detach_ally(self, dic): """ 被踢 自己退出 解散同盟 """ self.detach_ally1() resp_f = "allyUpdate" self.send_msg(pack_msg(resp_f, 1, data=dic))
def send(self, msg_name, status=1, data=None, err=None): msg = pack_msg(msg_name, status, data=data, err=err) self.rpc.send(msg)