def patch(self, message, union_message, data, now): """填充联盟战争信息 Args: message[protobuf UnionBattleInfo]: 需要打包的联盟信息 union_message[protobuf UnionBattleInfo]: 己方联盟返回的战斗信息 data[UserData] now[int]: 时间戳 """ #本方联盟返回的联盟战斗信息 message.CopyFrom(union_message) #补充个人信息 user = data.user.get(True) union = data.union.get(True) message.user.user.user_id = user.id message.user.user.name = user.get_readable_name() message.user.user.headicon_id = user.icon_id message.user.left_attack_count = union.battle_attack_count_left message.user.refresh_attack_num = union.battle_attack_refresh_num message.user.drum_count = union.battle_drum_count if (union_message.stage != union_message.INVALID and union_message.stage != union_message.IDLE): #在战争中,需要查询对手联盟的战斗信息 rival_union_req = internal_union_pb2.InternalQueryUnionBattleReq() defer = GlobalObject().remote['gunion'].callRemote( "query_battle", union_message.rival_union_id, rival_union_req.SerializeToString()) defer.addCallback(self._patch_rival_battle_info, message, data, now) return defer else: return self._patch_ranking_info(message, data, now)
def pushObjectByCharacterId_10(topicID, msg, sendList): '''根据角色的ID推送消息''' _sendList = [ VCharacterManager().getClientIdByCharacterId(cid) for cid in sendList ] root = GlobalObject().root root.callChild('net', "pushData", topicID, msg, _sendList)
def forwarding_game(key, session_id, data): """ 消息转发给游戏节点 :param key: 消息id :param session_id: :param data: json串, 里面必须包含userid :return: """ logger.debug(u"forwarding_game:%s", str([key, session_id, data])) user_id = data.get("user_id", -1) passwd = data.get("passwd", -1) if -1 == user_id and key not in [USER_OFFLINE]: print "forwarding_game user_id =", user_id return if USER_LOGIN == key: logger.debug(u"forwarding_game2:%s", str([key, session_id, data])) return process_login(user_id, passwd, session_id, data) if session_id in ROUTE_CACHE.keys(): room_name = ROUTE_CACHE[session_id]["room"] data.update({"gate_name": GATE_NAME}) return GlobalObject().root.callChildByName(room_name, "forwarding_game", key, session_id, data) route_info = route_ins.get_route(user_id, session_id=session_id) print "route_info:", route_info if 200 == route_info.get('code'): data.update({"gate_name": GATE_NAME}) room_name = route_info['info'].get("room") return GlobalObject().root.callChildByName(room_name, "forwarding_game", key, session_id, data) else: return
def create_master(self): """ 创建Master服务 :return: """ config = Config().config GlobalObject().json_config = config mastercnf = config.get('master') rootport = mastercnf.get('rootport') webport = mastercnf.get('webport') masterlog = mastercnf.get('log') self.root = PBRoot() rootservice = services.Service("rootservice") self.root.addServiceChannel(rootservice) self.web = vhost.NameVirtualHost() self.web.addHost('0.0.0.0', './') GlobalObject().root = self.root GlobalObject().webroot = self.web import webapp import rootapp internet.TCPServer(webport, DelaySite(self.web)).setServiceParent(self.service) internet.TCPServer(rootport, BilateralFactory( self.root)).setServiceParent(self.service) self.process.setServiceParent(self.service)
def _calc_query(self, data, req, timer, force): union = data.union.get(True) if not force and not union.is_belong_to_target_union(req.union_id): #已经不属于对应联盟 res = union_pb2.QueryUnionRes() res.status = 0 res.ret = union_pb2.UNION_NOT_MATCHED res.monarch.user_id = data.id res.monarch.union_id = union.union_id defer = DataBase().commit(data) defer.addCallback(self._query_succeed, req, res, timer) return defer union.update_daily_info(timer.now) union_req = internal_union_pb2.InternalQueryUnionReq() union_req.user_id = data.id #请求 Union 模块,查询联盟情况 if not force: defer = GlobalObject().remote['gunion'].callRemote( "query_union", union.union_id, union_req.SerializeToString()) else: defer = GlobalObject().remote['gunion'].callRemote( "query_union_force", req.union_id, union_req.SerializeToString()) defer.addCallback(self._update_query_info, data, req, timer) return defer
def enterInstance1(dynamicId, characterId, InstanceId): '''进入副本 @param dynamicId: int 角色动态id @param characterId: int 角色id @param InstanceId: int 副本id ''' vplayer = VCharacterManager().getVCharacterByClientId(dynamicId) if not vplayer or vplayer.getLocked():#判断是否存在角色或者角色是否被锁定 return oldnode = 201000 if oldnode < 300000 and oldnode != 0:#如果角色在场景 #创建新的副本返回服务器编号,副本动态id famserTag,famId=FamSerManager().createNewFam(dynamicId) if famserTag <0: return vplayer.lock()#锁定角色对象 newnode = 300000+famserTag #获取角色在原先场景中的实例 d = GlobalObject().root.callChild("scense_1000",610,dynamicId, characterId) #调用失败后的处理 d.addErrback(InFamErrbck,vplayer,newnode,famId) #进入副本 d.addCallback(Transfer1501,newnode,dynamicId,characterId,InstanceId,famId) return d else: dd = defer.Deferred() dd.callback({'result':True,'message':u'nofam'}) return dd
def doConnectionLost(conn): '''当客户端断开连接时,调用该方法''' str2 = '%d is logout\r\n' % conn.transport.sessionno lis = GlobalObject().netfactory.connmanager._connections.keys( ) # 获取所有在线的客户端的session_no lis.remove(conn.transport.sessionno) # 移除当前登录的客户端的session_no GlobalObject().netfactory.pushObject(10001, str2, lis) # 向其他客户端发送下线消息
def _calc_buy_legendcity_goods(self, data, req, timer): """购买史实城商店中的商品 """ shop_id = ShopInfo.generate_id(data.id, ShopInfo.GOODS_TYPE_LEGENDCITY, req.index) shop = data.shop_list.get(shop_id) pay = shop.calc_goods_price(req.goods.id) extra_pay = int(pay * (req.tax / 100.0)) if not shop_business.buy_goods(data, shop, req.goods.id, timer.now, req.tax): raise Exception("Buy Goods failed") compare.check_item(data, req.item) #请求 Unit 模块,缴税 unit_req = unit_pb2.UnitBuyGoodsReq() unit_req.user_id = data.id unit_req.pay = pay unit_req.extra_pay = extra_pay unit_req.tax = req.tax defer = GlobalObject().remote['unit'].callRemote( "buy_goods", req.index, unit_req.SerializeToString()) defer.addCallback(self._pack_buy_legendcity_goods_response, data, req, timer) return defer
def _calc_exchange(self, data, req, timer): comm_req = exchange_pb2.QueryExchangeProportionReq() comm_req.user_id = data.id defer = GlobalObject().remote["common"].callRemote( "query_exchange_info", 1, comm_req.SerializeToString()) defer.addCallback(self._calc_exchange_proportion, data, req, timer) return defer
def _try_forward_season_for_user_not_belong_to_union(self): """让不属于任何联盟的玩家,且参加过上个赛季联盟战争的玩家,进入下一个赛季 """ users = [] flag = True begin = 0 gap = 50 while flag: proxy = DataProxy() proxy.search_by_rank("union", "season_score", begin, begin + gap) defer = proxy.execute() for i, indiv_info in enumerate( proxy.get_rank_result("union", "season_score", begin, begin + gap)): if indiv_info.season_score > 0: if indiv_info.user_id not in users: users.append(indiv_info.user_id) else: flag = False break begin += gap for user_id in users: req = internal_pb2.UnionBattleForwardReq() defer = GlobalObject().root.callChild( "portal", "forward_union_battle_season_forward", user_id, req.SerializeToString()) defer.addCallback( self._check_forward_season_for_user_not_belong_to_union)
def _calc_try_forward_season_result(self, union_response, expect, union_ids, req, res, timer): union_res = union_battle_pb2.TryForwardUnionBattleSeasonRes() union_res.ParseFromString(union_response) if union_res.status != 0: raise Exception("Try forward union battle season res error") if expect is None and not union_res.enable: #无法进入下一个赛季,直接返回 return self._try_forward_season_succeed(req, res, timer) elif expect is not None and union_res.enable != expect: #各个联盟进入下一个赛季,出现不一致的情况 logger.warning("Try forward union battle season unexpected") #各个联盟均已经进入下一个赛季 if len(union_ids) == 0: res.enable = True self._try_forward_season_for_user_not_belong_to_union() return self._try_forward_season_succeed(req, res, timer) union_id = union_ids.pop() union_req = union_battle_pb2.TryForwardUnionBattleSeasonReq() defer = GlobalObject().remote['gunion'].callRemote( "try_forward_season", union_id, union_req.SerializeToString()) defer.addCallback(self._calc_try_forward_season_result, True, union_ids, req, res, timer) return defer
def _kickout(self, data, member, target_user_id, timer): """踢人 """ target_member = member_business.find_member(data, target_user_id) if target_member is None: logger.debug("User is not belong to union") return self._pack_manage_response(union_pb2.UNION_MEMBER_INVALID) if member.user_id == target_user_id: #任何人都不能踢自己 logger.debug("User is not belong to union") return self._pack_manage_response(union_pb2.UNION_NO_AUTH) elif member.is_normal_member(): #成员不能踢人 return self._pack_manage_response(union_pb2.UNION_NO_AUTH) elif member.is_vice_leader() and not target_member.is_normal_member(): #副盟主只可以踢成员 return self._pack_manage_response(union_pb2.UNION_NO_AUTH) union = data.union.get() member_business.leave_union(data, target_member) app_req = internal_union_pb2.InternalUnionOperateReq() app_req.operator_user_id = member.user_id app_req.union_name = union.get_readable_name() app_req.union_id = union.id defer = GlobalObject().remote['app'].callRemote( "been_kickout_from_union", target_user_id, app_req.SerializeToString()) defer.addCallback(self._post_kickout, data, timer) return defer
def _delete_player(self, data, req, timer): if not data.is_valid(): return data force = False if req.HasField("force") and req.force == True: force = True #删除用户数据: # 1. 删除联盟数据 # 2. 删除史实城官职信息 # 3. 删除用户数据 union = data.union.get(True) if union is not None and force: # 退出联盟 union_req = internal_union_pb2.InternalManageUnionReq() union_req.user_id = data.id union_req.op = union_pb2.ManageUnionReq.EXIT union_req.target_user_id = data.id defer = GlobalObject().remote['gunion'].callRemote( "manage_union", union.union_id, union_req.SerializeToString()) defer.addCallback(self._delete_player_union, data) return defer return self._delete_player_union(None, data)
def DropClient(dynamicId): u = UsersManager().getUserByDynamicId(dynamicId) if u: if u.isCharacterLocked(): return if u.isLoginCharacter(): u.lockChar(True) ## GlobalObject().root.callChild("chat", 2, dynamicId, u.characterId) GlobalObject().root.callChild("combat", 2, dynamicId, u.characterId) scene = u.getSceneNode() if scene: GlobalObject().root.callChild(scene, 2, dynamicId, u.characterId) SceneSerManager().dropClient(scene, dynamicId) node = u.getNode() if node: GlobalObject().root.callChild(node, 2, dynamicId, u.characterId) GameSerManager().dropClient(node, dynamicId) ### u.lockChar(False) #释放角色锁定,其实这里没有对数据库直接操作,而是通知各个子服自己处理,所以角色锁定没啥意义 UsersManager().dropUserByDynamicId(dynamicId) return
def _calc_create_result(self, union_response, data, req, timer): union_res = internal_union_pb2.InternalQueryUnionRes() union_res.ParseFromString(union_response) if union_res.status != 0: raise Exception("Create union res error") res = union_pb2.CreateUnionRes() res.status = 0 res.ret = union_res.ret if res.ret != union_pb2.UNION_OK: return self._create_succeed(data, req, res, timer) #创建联盟 union_business.create_union( data, union_res.union.id, req.gold_cost, timer.now) res.union.CopyFrom(union_res.union) #第一次创建联盟返回时要把union member信息不全 user = data.user.get(True) res.union.members[0].user.name = user.get_readable_name() res.union.members[0].user.level = user.level res.union.members[0].user.headicon_id = user.icon_id #查询联盟boss union_req = internal_union_pb2.InternalQueryUnionBossReq() union_req.user_id = data.id union = data.union.get(True) defer = GlobalObject().remote['gunion'].callRemote( "query_unionboss", union.union_id, union_req.SerializeToString()) defer.addCallback(self._calc_create_result_unionboss, data, req, res, timer) return defer
def forwarding(key, dynamicId, data): """ """ if localservice._targets.has_key(key): return localservice.callTarget(key, dynamicId, data) else: user = UsersManager().getUserByDynamicId(dynamicId) if not user: return if not user.isLoginCharacter(): return if user.isCharacterLocked(): return if not user.CheckEffective(): return global scene_protocol if key in scene_protocol: scene = user.getSceneNode() if scene: GlobalObject().root.callChild(scene, 3, key, dynamicId, user.characterId, data) return global chat_protocol if key in chat_protocol: GlobalObject().root.callChild("chat", 3, key, dynamicId, user.characterId, data) return global combat_protocol if key in combat_protocol: GlobalObject().root.callChild("combat", 3, key, dynamicId, user.characterId, data) return node = user.getNode() return GlobalObject().root.callChild(node, 3, key, dynamicId, user.characterId, data)
def masterapp(self): """ """ config = json.load(open(self.configpath, 'r')) GlobalObject().json_config = config mastercnf = config.get('master') rootport = mastercnf.get('rootport') webport = mastercnf.get('webport') masterlog = mastercnf.get('log') self.root = PBRoot() rootservice = services.Service("rootservice") self.root.addServiceChannel(rootservice) self.webroot = vhost.NameVirtualHost() self.webroot.addHost('0.0.0.0', './') GlobalObject().root = self.root GlobalObject().webroot = self.webroot if masterlog: log.addObserver(loogoo(masterlog)) #日志处理 log.startLogging(sys.stdout) import firefly.master.webapp import firefly.master.rootapp reactor.listenTCP(webport, DelaySite(self.webroot), interface='127.0.0.1') reactor.listenTCP(rootport, BilateralFactory(self.root))
def _calc_finish_battle(self, data, req, timer): res = transfer_arena_pb2.FinishTransferArenaBattleRes() res.status = 0 #记录次数 trainer = data.trainer.get() trainer.add_daily_battle_transfer(1) transfer = data.transfer.get() if req.target_id not in transfer.get_match_ids(): res.ret = transfer_arena_pb2.FinishTransferArenaBattleRes.TARGET_ERROR return self._finish_battle_succeed(data, req, res, timer) transfer.finish_battle(timer.now) win = True if req.battle.result == battle_pb2.BattleOutputInfo.WIN else False #请求common模块进行换位 common_req = internal_pb2.InternalExchangeTransferReq() common_req.user_id = data.id common_req.target_user_id = req.target_id common_req.exchange = win common_request = common_req.SerializeToString() defer = GlobalObject().remote["common"].callRemote( "exchange_transfer", 1, common_request) defer.addCallback(self._calc_finish_battle_result, data, req, timer) return defer
def speak_10001(_conn, data): '''用户发言的方法''' date = datetime.now() str1 = date.strftime("%Y-%m-%d %H:%M:%S") + '(' + str( _conn.transport.sessionno) + '):\r\n' + data lis = GlobalObject().netfactory.connmanager._connections.keys() # 获取所有在线用户 lis.remove(_conn.transport.sessionno) # 移除发言者本身 GlobalObject().netfactory.pushObject(10001, str1, lis) # 向用户群发送当前发言者的发言信息
def _get_members_info(members, members_info, i): app_req = internal_pb2.GetUserBasicInfoReq() app_req.user_id = members[i].user_id defer = GlobalObject().remote['app'].callRemote("get_user_basic_info", members[i].user_id, app_req.SerializeToString()) defer.addCallback(_get_members_info_result, members, members_info, i) return defer
def forwarding_0(target_key, _conn, data): if target_key >= 2000: return GlobalObject().remote['gate'].callRemote( "forwarding", target_key, _conn.transport.sessionno, data) else: return GlobalObject().remote['auth'].callRemote( "forwarding", target_key, _conn.transport.sessionno, _conn.transport.client, data)
def _calc_delete_legend_city(self, status, city_id, timer): assert status == 0 unit_req = unit_pb2.UnitDeleteLegendCityReq() defer = GlobalObject().remote['unit'].callRemote( "delete_city", city_id, unit_req.SerializeToString()) defer.addCallback(self._check_delete_legend_city, city_id, timer) return defer
def _forward_award_prosperity(self, union_id, prosperity): union_req = internal_union_pb2.InternalAddUnionProsperityReq() union_req.prosperity = prosperity defer = GlobalObject().remote['gunion'].callRemote( "add_prosperity", union_id, union_req.SerializeToString()) defer.addCallback(self._check_award_prosperity) return defer
def _calc_get_position_rank(self, state, city_id, res, timer): assert state == True unit_req = unit_pb2.UnitGetPositionRankReq() defer = GlobalObject().remote['unit'].callRemote( "get_position_rank", city_id, unit_req.SerializeToString()) defer.addCallback(self._check_position_rank, city_id, res, timer) return defer
def _calc_delete_common(self, status, common_id, timer): assert status == 0 req = internal_pb2.DeleteCommonReq() defer = GlobalObject().remote['common'].callRemote( "delete_common", common_id, req.SerializeToString()) defer.addCallback(self._check_delete_common, common_id, timer) return defer
def _query_notice(self, data, basic_data, request, req, timer): #查询广播信息 defer = GlobalObject().remote["common"].callRemote( "query_broadcast_record", 1, request) defer.addCallback(self._check_query_broadcast_record_result, basic_data, data, req, timer) return defer
def _query_union_info(self, proxy, data, plunder, rival, req, timer): """""" union_req = internal_union_pb2.InternalQueryUnionReq() union_req.user_id = data.id defer = GlobalObject().remote['gunion'].callRemote( "query_union_summary", rival.union_id, union_req.SerializeToString()) defer.addCallback(self._pack_query_player_response, data, plunder, rival, req, timer) return defer
def speak_10001(_conn, data): '''发消息接口,定义客户端访接口,命令码是10001''' date = datetime.now() str1 = date.strftime("%Y-%m-%d %H:%M:%S") + ' (' + str( _conn.transport.sessionno) + '):\r\n' + data # 拼装字符串 lis = GlobalObject().netfactory.connmanager._connections.keys( ) # 获取所有在线的客户端的session_no lis.remove(_conn.transport.sessionno) # 移除当前登录的客户端的session_no GlobalObject().netfactory.pushObject(10001, str1, lis) # 向其他客户端发送发言消息
def _calc_delete_notice(self, data, request, req, timer): """ """ #删除广播信息 defer = GlobalObject().remote["common"].callRemote( "delete_broadcast_record", 1, request) defer.addCallback(self._check_delete_broadcast_record_result, data, req, timer) return defer
def _calc_gain(self, data, req, timer): union = data.union.get() union_req = internal_union_pb2.InternalGainUnionBattleScoreReq() union_req.union_score = req.score defer = GlobalObject().remote['gunion'].callRemote( "gain_battle_score", req.union_id, union_req.SerializeToString()) defer.addCallback(self._calc_gain_post, data, req, timer) return defer
def _calc_union_chat(self, data, req, timer): #assert req.type == req.UNION union_req = internal_union_pb2.InternalStartUnionChatReq() union_req.user_id = data.id defer = GlobalObject().remote['gunion'].callRemote( "start_union_chat", req.union_id, union_req.SerializeToString()) defer.addCallback(self._calc_union_chat_result, req, timer) return defer
def SavePlayerInfoInDB(dynamicId): '''将玩家信息写入数据库''' vcharacter = VCharacterManager().getVCharacterByClientId(dynamicId) # node = vcharacter.getNode() root=GlobalObject().root d = root.callChild("scense_1000",2,dynamicId) # pid = vcharacter.getCharacterId() # if TeamFight.ishaveTeamFight(pid): # root.callChild(9999,4307,dynamicId,pid) return d
def TransferPlayer(deferData,nownode,dynamicId,characterId,placeId,force,vplayer): '''传递角色''' player,oldplaceId = deferData #将角色信息写入新的场景 d=GlobalObject().root.callChild("scense_1000",612,601,dynamicId, characterId, placeId,force,player) # d = root.callChild(nownode,601,dynamicId, characterId, placeId,force,player) #调用失败后的处理 d.addErrback(sceneErorrBack,vplayer) #删除原先场景中的角色 d.addCallback(DropCharacterInScene,vplayer,nownode,dynamicId) return d
def JoinDuiWu(dynamicId, pid, pos, dwId): """加入队伍 """ vplayer = VCharacterManager().getVCharacterByClientId(dynamicId) if not vplayer or vplayer.getLocked(): # 判断是否存在角色或者角色是否被锁定 return # nownode = vplayer.getNode() d = GlobalObject().root.callChild("scense_1000", 610, dynamicId, pid) d.addErrback(ErorrBack) d.addCallback(TransferPlayerJoin, dynamicId, pid, pos, dwId) return d
def render(self,request): username=request.args['username'][0] opera_str=request.args['opera_str'][0] usermodedata=register_admin.getObjData(username) if not usermodedata: return "Account dose not exist!!!" pid=usermodedata.get('id') if not pid: return "Role does not exist!!!" gate_node=GlobalObject().remote.get('gate') gate_node.callRemote("opera_gamer",pid,opera_str) return "Success"
def Transfer1501(resultdata,nownode,dynamicId,characterId,instanceId,famId): '''调用进入副本方法 @param nownode: int 副本服务器动态id+30W ''' vplayer = VCharacterManager().getVCharacterByClientId(dynamicId) player,placeId = resultdata #加入角色的实例到创建的副本中去 d = GlobalObject().root.callChild("scense_1000",1501,player,dynamicId,characterId,instanceId,famId) #写入出错时的错误处理 d.addErrback(InFamErrbck,vplayer,nownode,famId) #写入成功时,清除原先场景中的角色实例 d.addCallback(DropCharacterInSceneForFam,vplayer,nownode,dynamicId,famId) return d
def DropCharacterInScene(deferResult,vcharacter,nownode,dynamicId): '''删除原先场景中角色的实例 ''' if not deferResult.get('result',False):#如果不能进行跳转 vcharacter.release()#释放角色对象锁 d = defer.Deferred() d.callback(deferResult) else: # oldnode = vcharacter.getNode() d=GlobalObject().root.callChild("scense_1000",612,dynamicId, vcharacter.characterId) # d = root.callChild(oldnode,612,dynamicId, vcharacter.characterId) d.addErrback(sceneErorrBack2,nownode,dynamicId,vcharacter) d.addCallback(cleanOldScene,deferResult,vcharacter,dynamicId,nownode) return d
def render(self, request): username = request.args["username"][0] oprea_str = request.args["opera_str"][0] usermodedata = register_admin.getObjData( username ) # register_admin,注册表的mmode管理器,getObjData(username),通过主键获取的对应的数据,dict型 if not usermodedata: return "Account does not exist!!!" pid = usermodedata.get("characterId") # 角色id if not pid: return "Role does not exist!!!" # 角色不存在,创建了账号没有创建人物 gate_node = GlobalObject().remote.get("gate") gate_node.callRemote("opera_player", pid, oprea_str) return "Success"
def performAction(self, request): # get parameters action = request.args['action'][0] message = request.args['message'][0] users = [] if request.args.has_key('username'): users.append(request.args['username'][0]) # perform action based on action parameter if action == 'push': child = GlobalObject().root.childsmanager.getChildByName('gate') if child: msg = { KEY_ERRNO : E_OK, KEY_DATA : { KEY_MESSAGE : message } } child.callbackChild('pushObject', COMMAND_TEST_PUSH, json.dumps(msg), users)
def DropCharacterInSceneForFam(deferResult,vcharacter,nownode,dynamicId,famId): '''删除原先场景角色的实例 ''' if not deferResult.get('result',False):#如果不能进行跳转 vcharacter.release()#释放角色对象锁 d = defer.Deferred() d.callback(deferResult) else: # oldnode = vcharacter.getNode() #通知原先场景服务器删除角色的信息 d = GlobalObject().root.callChild("scense_1000",612,dynamicId, vcharacter.characterId) #消息出错时的处理 d.addErrback(InFamErrbck2,vcharacter,nownode,famId) #消息成功时的处理 d.addCallback(cleanOldSceneForFam,deferResult,vcharacter,nownode,famId) return d
def Transfer1502(data,dynamicId,characterId,force): '''离开副本后将角色实例传递回来 ''' player, placeId = data vplayer = VCharacterManager().getVCharacterByClientId(dynamicId) oldnode = 201000 #vplayer.getNode() famId = vplayer.getFamId() if oldnode < 300000: dp = defer.Deferred() dp.callback({'result':True,'message':u'nofam'}) return dp nownode = SceneSerManager().getBsetScenNodeId(placeId) d = GlobalObject().root.callChild("scense_1000",601,dynamicId, characterId, placeId,force,player) #进入场景错误时的处理 d.addErrback(sceneErorrBack,vplayer) #进入成功时 d.addCallback(DropCharacterInFam,vplayer,nownode,dynamicId,oldnode,famId) return d
def _doChildConnect(name,transport): """当server节点连接到master的处理 """ server_config = GlobalObject().json_config.get('servers',{}).get(name,{}) remoteport = server_config.get('remoteport',[]) child_host = transport.broker.transport.client[0] root_list = [rootport.get('rootname') for rootport in remoteport] GlobalObject().remote_map[name] = {"host":child_host,"root_list":root_list} #通知有需要连的node节点连接到此root节点 for serverName,remote_list in GlobalObject().remote_map.items(): remote_host = remote_list.get("host","") remote_name_host = remote_list.get("root_list","") if name in remote_name_host: GlobalObject().root.callChild(serverName,"remote_connect",name,remote_host) #查看当前是否有可供连接的root节点 master_node_list = GlobalObject().remote_map.keys() for root_name in root_list: if root_name in master_node_list: root_host = GlobalObject().remote_map[root_name]['host'] GlobalObject().root.callChild(name,"remote_connect",root_name,root_host)
def forwarding(key,dynamicId,data): #net传过来的信息 '''分配处理netserver转发的请求 @param key: int 请求的指令号 @param conn: Conn Object Client到netserver的连接 @param data: str Client 发送过来的数据 ''' if localservice._targets.has_key(key): return localservice.callTarget(key,dynamicId,data) else: from app.gate.basicapp.pushObject import pushOtherMessage from app.gate.utils.dbopera.db_language_login import getLanguageStr user = UsersManager().getUserByDynamicId(dynamicId) if not user: msg = getLanguageStr('conn_error') pushOtherMessage(msg,[dynamicId]) return oldvcharacter = VCharacterManager().getVCharacterByClientId(dynamicId) if oldvcharacter.getLocked():#判断角色对象是否被锁定 return node = VCharacterManager().getNodeByClientId(dynamicId) root=GlobalObject().root return root.callChild(node,key,dynamicId,data)
def instanceColonizeBattle_712(key,dynamicId,request_proto): '''副本殖民的加锁处理,避免同时殖民同一个副本 ''' global COLONIZE_POOL argument = ColonizationBattle712_pb2.FightRequest() argument.ParseFromString(request_proto) response = ColonizationBattle712_pb2.FightResponse() dynamicId = dynamicId instanceid = argument.copyId #副本id(难度最小的那个) if instanceid in COLONIZE_POOL: response.result = False response.message = u'该副本正在进行殖民战斗' return response.SerializeToString() COLONIZE_POOL.append(instanceid) try: node = VCharacterManager().getNodeByClientId(dynamicId) d = GlobalObject().root.callChild("scense_1000",key,dynamicId,request_proto) d.addBoth(bothhandle,instanceid) return d except : COLONIZE_POOL.remove(instanceid)
def closeInstance(dynamicId,characterId): '''退出副本''' vplayer = VCharacterManager().getVCharacterByClientId(dynamicId) if not vplayer: dp = defer.Deferred() dp.callback({'result':True,'message':u'nofam'}) return dp oldnode = 201000 #vplayer.getNode() if oldnode > 300000:#如果角色在副本中 #锁定角色对象 vplayer.lock() #获取角色在原先场景中的实例 d = GlobalObject().root.callChild("scense_1000",610,dynamicId, characterId) #获取错误时的处理 d.addErrback(sceneErorrBack,vplayer) #获取成功时的处理 d.addCallback(Transfer1502,dynamicId,characterId,True) return d else: dp = defer.Deferred() dp.callback({'result':True,'message':u'nofam'}) return dp
def pushObjectByCharacterId_10(topicID,msg,sendList): '''根据角色的ID推送消息''' _sendList = [VCharacterManager().getClientIdByCharacterId(cid) for cid in sendList] root=GlobalObject().root root.callChild('net',"pushData",topicID,msg,_sendList)
def pushObjectToAll_11(topicID,msg): '''根据角色的ID推送消息''' _sendList = [cid for cid in VCharacterManager().client_character.keys()] root=GlobalObject().root root.callChild('net',"pushData",topicID,msg,_sendList)
def pushObject(topicID,msg,sendList): '''推送消息 ''' root=GlobalObject().root root.callChild('net',"pushData",topicID,msg,sendList)
def user(self, request, tag): gate = GlobalObject().root.childsmanager.getChildByName('gate') d = gate.callbackChild('getUserNames') d.addCallback(self.onUserNamesCollected, tag) yield d