def connectionLost(self, reason): """连接断开处理 """ logger.info('Client %d login out(%s).' % (self.transport.sessionno, reason)) self.factory.doConnectionLost(self) self.factory.connmanager.dropConnectionByID(self.transport.sessionno)
def assemble_monster(stage_id, stage_config, stage_type_name): """组装怪物战斗单位 """ stage_config = stage_config.get(stage_type_name).get(stage_id) monsters = [] for i in range(3): logger.debug("stage_id %s" % stage_id) logger.debug( "stage_group_id %s" % getattr( stage_config, 'round%s' % (i + 1))) monster_group_id = getattr(stage_config, 'round%s' % (i+1)) if not monster_group_id: continue monster_group_config = game_configs.monster_group_config.get(monster_group_id) round_monsters = {} boss_position = monster_group_config.bossPosition for j in range(6): pos = j + 1 monster_id = getattr(monster_group_config, 'pos%s' % pos) if not monster_id: continue is_boss = False if j + 1 == boss_position: is_boss = True monster_config = game_configs.monster_config.get(monster_id) logger.info('怪物ID:%s' % monster_id) battle_unit = do_assemble( 0, monster_config.id, monster_config.quality, [], monster_config.hp, monster_config.atk, monster_config.physicalDef, monster_config.magicDef, monster_config.hit, monster_config.dodge, monster_config.cri, monster_config.criCoeff, monster_config.criDedCoeff, monster_config.block, monster_config.ductility, pos, monster_config.monsterLv, 0, is_boss, is_hero=False) round_monsters[pos] = battle_unit monsters.append(round_monsters) # 保存关卡怪物信息, 掉落信息 logger.info('关卡怪物信息: %s ' % monsters) return monsters
def dataReceived(self, data): """数据到达处理 @param data: str 客户端传送过来的数据 """ length = self.factory.dataprotocl.getHeadlength() # 获取协议头的长度 self.buff += data while self.buff.__len__() >= length: unpackdata = self.factory.dataprotocl.unpack(self.buff[:length]) if not unpackdata.get('result'): logger.info('illegal data package --') self.connectionLost('illegal data package') break command = unpackdata.get('command') rlength = unpackdata.get('length') request = self.buff[length:length + rlength] if request.__len__() < rlength: logger.info('some data lose') break self.buff = self.buff[length + rlength:] response = self.factory.doDataReceived(self, command, request) # if not response: # continue self.safeToWriteData(response, command)
def set_pay_arg(self, value): self._platform = value.get("platform") self._openid = str(value.get("openid")) self._openkey = str(value.get("openkey")) self._pay_token = str(value.get("pay_token")) self._appid = str(value.get("appid")) #self._appkey = str(value.get("appkey")) self._pf = str(value.get("pf")) self._pfkey = str(value.get("pfkey")) login_channel = str(value.get("login_channel")) logger.debug("login_channel %s" % login_channel) if login_channel != "tencent": self.REMOTE_DEPLOYED = False # self._zoneid = str(value.get("zoneid")) if self.REMOTE_DEPLOYED: previous_gold = self._owner.finance.gold self.get_balance() # 登录时从tx拉取gold add_gold = self._owner.finance.gold - previous_gold if add_gold == 0: return logger.info('tencent add gold:%s', add_gold) recharge_config = game_configs.recharge_config.get('android') for k, item in recharge_config.items(): if item.get('activity') == add_gold: response = GetGoldResponse() self._owner.recharge.recharge_gain(item, response, 5, True) break else: logger.error('tencent add gold-num:%d', add_gold)
def pushAllObject(self, topicID, msg): """服务端向所有连接客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 """ logger.info("pushAllObject:topic_id: %s" % topicID) self.connmanager.pushAllObject(topicID, msg)
def callTarget(self, targetKey, *args, **kw): target = self.getTarget(targetKey) logger.info("call method begin %s on service[%s]", target.__name__, self._name) if not target: print 'targetKey', targetKey logger.error('command %s not Found on service' % str(targetKey)) return None # if targetKey not in self.unDisplay: # logger.info("call method %s on service[%s]" % # (target.__name__, self._name)) t = time.time() dynamic_id = args[0] try: #logger.debug('key and dynamic_id,%s,%s', dynamic_id, targetKey) if targetKey != 'enter_scene_remote': _player = PlayersManager().get_player_by_dynamic_id(dynamic_id) # print 'find player:', _player if not _player: logger.error('cantfind player dynamic id:%s', dynamic_id) return {'result': False, 'result_no': 1, 'message': u''} args = args[1:] kw['player'] = _player response = target(*args, **kw) else: response = target(*args, **kw) except AuthError, e: logger.exception(e) remote_gate.disconnect_remote(dynamic_id) return None
def user_register(): user_name = request.args.get('name') user_pwd = request.args.get('pwd') device_id = request.args.get('deviceid', '') is_tourist = 'tourist' in request.args logger.info('register name:%s pwd:%s %s', user_name, user_pwd, is_tourist) if not user_name.isalnum(): return json.dumps(dict(result=False, result_no=-2, message='error name')) if len(user_name) > 32: return json.dumps(dict(result=False, result_no=-3, message='error name len')) if len(user_pwd) > 32: return json.dumps(dict(result=False, result_no=-4, message='error pwd len')) return __user_register(account_name=user_name, account_password=user_pwd, device_id=device_id, is_tourist=is_tourist)
def check_equ(self, condition_param): for slot in self.line_up_slots.values(): if slot.equipment_nos: logger.info('slot equipment nos:%s', slot.equipment_nos) if condition_param in slot.equipment_nos: return True return False
def check_suit(self, condition_param): for slot in self.line_up_slots.values(): if slot.equ_suit: logger.info('slot equ suit:%s', slot.equ_suit.keys()) if condition_param in slot.equ_suit: return True return False
def _assemble_monster(self): """组装怪物战斗单位 """ stage_config = self._get_stage_config() # 关卡配置 monsters = [] for i in range(3): logger.debug("stage_id %s" % self._stage_id) logger.debug("stage_group_id %s" % getattr(stage_config, 'round%s' % (i + 1))) monster_group_id = getattr(stage_config, 'round%s' % (i + 1)) if not monster_group_id: continue monster_group_config = self.__get_monster_group_config( monster_group_id) round_monsters = {} boss_position = monster_group_config.bossPosition print("boss_position %s" % boss_position) for j in range(6): pos = j + 1 monster_id = getattr(monster_group_config, 'pos%s' % pos) if not monster_id: continue is_boss = False if j + 1 == boss_position: is_boss = True monster_config = self.__get_monster_config(monster_id) logger.info('怪物ID:%s' % monster_id) battle_unit = do_assemble(0, monster_config.id, monster_config.quality, [], monster_config.hp, monster_config.atk, monster_config.physicalDef, monster_config.magicDef, monster_config.hit, monster_config.dodge, monster_config.cri, monster_config.criCoeff, monster_config.criDedCoeff, monster_config.block, monster_config.ductility, pos, monster_config.monsterLv, 0, is_boss, is_hero=False) round_monsters[pos] = battle_unit monsters.append(round_monsters) # 保存关卡怪物信息, 掉落信息 self._blue_unit = monsters self._common_drop = stage_config.commonDrop self._elite_drop = stage_config.eliteDrop # logger.info('关卡怪物信息: %s ' % monsters) return monsters
def check_hero(self, condition_param): hero_nos = self.owner.line_up_component.hero_nos logger.info('hero nos:%s', hero_nos) if condition_param in hero_nos: self._not_replace.append(condition_param) return True return False
def serverStop(): """停止服务进程""" logger.info('stop') if GlobalObject().stophandler: GlobalObject().stophandler() reactor.callLater(0.5, reactor.stop) return True
def __character_login(dynamic_id): user = UsersManager().get_by_dynamic_id(dynamic_id) logger.info("user_id:%d", dynamic_id) if not user: return {'result': False} v_character = VCharacterManager().get_by_id(user.user_id) if v_character: v_character.dynamic_id = dynamic_id else: v_character = VirtualCharacter(user.user_id, dynamic_id) VCharacterManager().add_character(v_character) now_node = SceneSerManager().get_best_sceneid() # game服登录 child_node = GlobalObject().child(now_node) player_data = child_node.enter_scene_remote(dynamic_id, user.user_id) if not player_data: return {'result': False} v_character.node = now_node # pull message from transit GlobalObject().remote['transit'].pull_message_remote(user.user_id) SceneSerManager().add_client(now_node, dynamic_id) return {'result': True, 'player_data': player_data}
def user_verify(): user_passport = request.args.get('passport') logger.info(account_login_cache) if user_passport not in account_login_cache: return str({'result': False}) account_login_cache.remove(user_passport) return str({'result': True})
def user_bind(): user_name = request.args.get('name') user_pwd = request.args.get('pwd') tourist_id = request.args.get('tid') logger.info('bind name:%s pwd:%s %s', user_name, user_pwd, tourist_id) if not user_name.isalnum(): return json.dumps( dict(result=False, result_no=-2, message='error name')) if len(user_name) > 32: return json.dumps( dict(result=False, result_no=-3, message='error name len')) if len(user_pwd) > 32: return json.dumps( dict(result=False, result_no=-4, message='error pwd len')) get_result = util.GetOneRecordInfo( USER_TABLE_NAME, dict(account_name=tourist_id, account_password=TOURIST_PWD)) if get_result is None: return json.dumps( dict(result=False, message='account name or password error!')) result = util.UpdateWithDict( USER_TABLE_NAME, dict(account_name=user_name, account_password=user_pwd, device_id=''), dict(id=get_result['id'])) logger.info('bind result:%s', result) return json.dumps(dict(result=result))
def _doChildLostConnect(childId): """ """ try: del GlobalObject().remote_map[childId] except Exception, e: logger.info(str(e))
def get_warriors_906(pro_data, player): """请求无双 """ response = stage_response_pb2.UnparalleledResponse() warriors = player.line_up_component.warriors for warrior in warriors: unpar_add = response.unpar.add() unpar_add.id = warrior warriors_cof = game_configs.warriors_config.get(warrior) # 无双配置 for i in range(1, 4): triggle = getattr(warriors_cof, 'triggle%s' % i) # 技能编号 if triggle: skill_cof = game_configs.skill_config.get(triggle) # 技能配置 group = skill_cof.group skill = unpar_add.unpar.add() skill.id = triggle buffs = skill.buffs for buff_id in group: buffs.append(buff_id) logger.info('warriors: %s' % response) return response.SerializePartialToString()
def gm(): print("gm================") response = {} res = {} admin_command = ['reset_star_gift', 'update_excel', 'get_user_info', 'send_mail', 'get_user_hero_chips', 'get_user_eq_chips', 'get_user_finances', 'get_user_items', 'get_user_guild_info', 'get_user_heros', 'get_user_eqs', 'copy_user', 'update_server_list', 'add_push_message'] print request.args, type(request.args) if request.args: t_dict = request.args else: t_dict = request.form logger.info('gm2admin,command:%s', t_dict['command']) if t_dict['command'] in admin_command: com = t_dict['command'] + "(t_dict)" res = eval(com) else: res = remote_gate.from_admin_rpc_remote(cPickle.dumps(t_dict)) if res['success'] == 2: com = t_dict['command'] + "(t_dict)" logger.debug("gm=======%s" % com) res = eval(com) logger.info('######################################,server2gm:%s', res) return json.dumps(res)
def sreload(): """供master调用的接口:热更新模块 """ logger.info('reload') if GlobalObject().reloadmodule: reload(GlobalObject().reloadmodule) return True
def reload(): logger.info('test reload') print game_configs.base_config print '----------------------' xreload(game_configs) print '----------------------'
def new_guide_step_1802(data, player): request = NewbeeGuideStepRequest() request.ParseFromString(data) response = NewbeeGuideStepResponse() new_guide_item = game_configs.newbee_guide_config.get(request.step_id) if not new_guide_item: logger.error('error newbee id:%s', request.step_id) response.res.result = False return response.SerializePartialToString() new_guide_type = new_guide_item.get('SequenceType') logger.info('newbee:%s step:%s=>%s', player.base_info.id, player.base_info.newbee_guide, request.step_id) my_newbee_sequence = 0 if player.base_info.newbee_guide.get(new_guide_type): my_newbee_sequence = game_configs.newbee_guide_config.get( player.base_info.newbee_guide[new_guide_type]).get('Sequence') if my_newbee_sequence < new_guide_item.get('Sequence'): gain_data = new_guide_item.get('rewards') return_data = gain(player, gain_data, const.NEW_GUIDE_STEP) get_return(player, return_data, response.gain) logger.debug('new bee id:%s step:%s reward:%s response:%s', player.base_info.id, request.step_id, gain_data, response.gain) else: response.res.result_no = 111 logger.debug("new bee reward repeated, id:%s step:%s %s %s", player.base_info.id, request.step_id, my_newbee_sequence, new_guide_item.get('Sequence')) consume_config = new_guide_item.get('consume') result = is_afford(player, consume_config) # 校验 if not result.get('result'): logger.error('newbee guide comsume:%s', consume_config) response.res.result = False response.res.result_no = 1802 return response.SerializePartialToString() need_gold = get_consume_gold_num(consume_config) def func(): consume_data = consume(player, consume_config, const.NEW_GUIDE_STEP) get_return(player, consume_data, response.consume) # logger.debug("gain_data %s %s" % (gain_data, request.step_id)) # logger.debug(player.finance.coin) tlog_action.log('NewGuide', player, new_guide_item.get('Sequence'), request.step_id) if my_newbee_sequence < new_guide_item.get('Sequence'): player.base_info.newbee_guide[new_guide_type] = request.step_id player.base_info.current_newbee_guide = request.step_id player.base_info.save_data() player.pay.pay(need_gold, const.NEW_GUIDE_STEP, func) response.res.result = True response.step_id = request.step_id return response.SerializePartialToString()
def dataReceived(self, data): '''数据到达处理 @param data: str 客户端传送过来的数据 ''' length = self.factory.dataprotocl.getHeadlength() # 获取协议头的长度 self.buff += data while self.buff.__len__() >= length: unpackdata = self.factory.dataprotocl.unpack(self.buff[:length]) if not unpackdata.get('result'): logger.info('illegal data package --') self.transport.connectionLost() break command = unpackdata.get('command') rlength = unpackdata.get('length') request = self.buff[length:length + rlength] if request.__len__() < rlength: logger.info('some data lose') break self.buff = self.buff[length + rlength:] response = self.factory.doDataReceived(self, command, request) # if not response: # continue self.safeToWriteData(response, command)
def gm(): print("gm================") response = {} res = {} admin_command = [ 'reset_star_gift', 'update_excel', 'get_user_info', 'send_mail', 'get_user_hero_chips', 'get_user_eq_chips', 'get_user_finances', 'get_user_items', 'get_user_guild_info', 'get_user_heros', 'get_user_eqs', 'copy_user', 'update_server_list', 'add_push_message', 'kick_player' ] print request.args, type(request.args) if request.args: t_dict = request.args else: t_dict = request.form logger.info('gm2admin,command:%s', t_dict['command']) if t_dict['command'] in admin_command: com = t_dict['command'] + "(t_dict)" res = eval(com) else: res = remote_gate.from_admin_rpc_remote(cPickle.dumps(t_dict)) if res['success'] == 2: com = t_dict['command'] + "(t_dict)" logger.debug("gm=======%s" % com) res = eval(com) logger.info('######################################,server2gm:%s', res) return json.dumps(res)
def user_bind(): user_name = request.args.get('name') user_pwd = request.args.get('pwd') tourist_id = request.args.get('tid') logger.info('bind name:%s pwd:%s %s', user_name, user_pwd, tourist_id) if not user_name.isalnum(): return json.dumps(dict(result=False, result_no=-2, message='error name')) if len(user_name) > 32: return json.dumps(dict(result=False, result_no=-3, message='error name len')) if len(user_pwd) > 32: return json.dumps(dict(result=False, result_no=-4, message='error pwd len')) get_result = util.GetOneRecordInfo(USER_TABLE_NAME, dict(account_name=tourist_id, account_password=TOURIST_PWD)) if get_result is None: return json.dumps(dict(result=False, message='account name or password error!')) result = util.UpdateWithDict(USER_TABLE_NAME, dict(account_name=user_name, account_password=user_pwd, device_id=''), dict(id=get_result['id'])) logger.info('bind result:%s', result) return json.dumps(dict(result=result))
def pushObject(self, topicID, msg, sendList): """服务端向客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 @param sendList: 推向的目标列表(客户端id 列表) """ logger.info("pushObject: %s to %s" % (topicID, sendList)) self.connmanager.pushObject(topicID, msg, sendList)
def connectionMade(self): '''连接建立处理 ''' address = self.transport.getAddress() logger.info('Client %d login in.[%s,%d]' % (self.transport.sessionno, \ address[0], address[1])) self.factory.connmanager.addConnection(self) self.factory.doConnectionMade(self)
def pushObject(self, topicID, msg, sendList): '''服务端向客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 @param sendList: 推向的目标列表(客户端id 列表) ''' logger.info("pushObject: %s to %s" % (topicID, sendList)) self.connmanager.pushObject(topicID, msg, sendList)
def dropChildByID(self, childId): """删除一个child 节点\n @param childId: Child ID """ try: del self._childs[childId] except Exception, e: logger.info(str(e))
def send_all(self, mtype, message): count = 0 for user in self.register.values(): logger.info('user.device_token:%s', user.device_token) if user.can_push(mtype): push_by_token(user.device_token, message.message) count += 1 logger.debug('count:%s', count)
def connectionMade(self): """连接建立处理 """ address = self.transport.getAddress() logger.info('Client %d login in.[%s,%d]' % (self.transport.sessionno, address[0], address[1])) self.factory.connmanager.addConnection(self) self.factory.doConnectionMade(self)
def serverStop(): """供master调用的接口:关闭服务器 """ logger.info('stop') if GlobalObject().stophandler: GlobalObject().stophandler() reactor.callLater(0.5, reactor.stop) return True
def pvp_player_rank_refresh(self): rank = tb_pvp_rank.zscore(self.owner.base_info.id) rank_max = int(tb_pvp_rank.ztotal()) if not rank or rank_max == rank: rank = rank_max self._pvp_arena_players = range(rank-9, rank + 1) return else: rank = int(rank) if len(self._pvp_arena_players) != 0 and \ self._pvp_current_rank == rank: return self._pvp_current_rank = rank if rank < 9: self._pvp_arena_players = range(1, 11) return # self._pvp_arena_players = range(max(1, rank-8), # min(rank+1, rank_max)) self._pvp_arena_players = [] stage_info = get_player_pvp_stage_up(rank) if stage_info: _choose = eval(stage_info.get('choose')) if _choose: a, b, _ = _choose[0] _id = random.randint(a, b) self._pvp_upstage_challenge_rank = _id for v in game_configs.arena_fight_config.values(): if v.get('type') != 1: continue play_rank = v.get('play_rank') if rank in range(play_rank[0], play_rank[1] + 1): para = dict(k=rank) choose_fields = eval(v.get('choose'), para) logger.info('cur:%s choose:%s', rank, choose_fields) for x, y, c in choose_fields: _min = int(x) _max = min(int(y), rank_max) range_nums = range(_min, _max+1) if not range_nums: logger.error('pvp rank range error:min:%s max:%s, rank_max:%s', _min, _max, rank_max) continue if len(range_nums) < c: logger.error('pvp rank not enough:min:%s max:%s, rank_max:%s', _min, _max, rank_max) continue for _ in range(c): r = random.choice(range_nums) range_nums.remove(r) self._pvp_arena_players.append(r) break else: logger.error('not found rank:%s in config', rank) logger.info('pvp rank refresh:%s', self._pvp_arena_players)
def regist(self, uid, device_token): logger.info('device_token:%s', device_token) if not device_token: return user = Character() user.uid = uid user.device_token = device_token self.register[user.uid] = user push_reg.hset(uid, user)
def tick(): result = GlobalObject().remote['login'].server_sync_remote( name, front_ip, front_port, '1', server_no) if result is False: reactor.callLater(1, tick) else: reactor.callLater(60, tick) logger.info('server online num:%s', UsersManager().get_online_num()) tlog_action.log('OnlineNum', UsersManager().get_online_num())
def connectionMade(self): """连接建立处理 """ address = self.transport.getAddress() logger.info('Client %d login in.[%s,%d]' % (self.transport.sessionno, address[0], address[1])) self.factory.connmanager.addConnection(self) self.factory.doConnectionMade(self) self.sem = BoundedSemaphore(1)
def send_msg(self, msg): if msg: try: if tlog: self.sock.sendto(msg, (host, port)) # logger.debug('t logclient,send_msg:%s', msg) except socket.error, arg: (_, err_msg) = arg logger.info(str(err_msg))
def dropChild(self, child): """删除一个child 节点\n @param child: Child Object """ key = child._id try: del self._childs[key] except Exception, e: logger.info(str(e))
def assemble_monster(stage_id, stage_config, stage_type_name): """组装怪物战斗单位 """ stage_config = stage_config.get(stage_type_name).get(stage_id) monsters = [] for i in range(3): logger.debug("stage_id %s" % stage_id) logger.debug("stage_group_id %s" % getattr(stage_config, 'round%s' % (i + 1))) monster_group_id = getattr(stage_config, 'round%s' % (i + 1)) if not monster_group_id: continue monster_group_config = game_configs.monster_group_config.get( monster_group_id) round_monsters = {} boss_position = monster_group_config.bossPosition for j in range(6): pos = j + 1 monster_id = getattr(monster_group_config, 'pos%s' % pos) if not monster_id: continue is_boss = False if j + 1 == boss_position: is_boss = True monster_config = game_configs.monster_config.get(monster_id) logger.info('怪物ID:%s' % monster_id) battle_unit = do_assemble(0, monster_config.id, monster_config.quality, [], monster_config.hp, monster_config.atk, monster_config.physicalDef, monster_config.magicDef, monster_config.hit, monster_config.dodge, monster_config.cri, monster_config.criCoeff, monster_config.criDedCoeff, monster_config.block, monster_config.ductility, pos, monster_config.monsterLv, 0, is_boss, is_hero=False) round_monsters[pos] = battle_unit monsters.append(round_monsters) # 保存关卡怪物信息, 掉落信息 logger.info('关卡怪物信息: %s ' % monsters) return monsters
def do_auto_refresh_items(type_shop, shop_data): if type_shop not in shop_data: logger.error('err type shop:%s', type_shop) return False ids = get_shop_item_ids(type_shop, shop_data[type_shop]['luck_num']) shop_data[type_shop]['item_ids'] = ids shop_data[type_shop]['last_auto_refresh_time'] = time.time() shop_data[type_shop]['items'] = {} logger.info('refresh_item_ids:%s', ids)
def account_verify_remote(key): response = {'result': False} logger.info('account verify:%s', key) if key in manager.account_cache: response['result'] = True response['uuid'] = manager.account_cache[key] else: logger.debug(manager.account_cache) logger.info('acount verify result:%s', response) return str(response)
def tick(): result = GlobalObject().remote['login'].server_sync_remote(name, front_ip, front_port, '1', server_no) if result is False: reactor.callLater(1, tick) else: reactor.callLater(60, tick) logger.info('server online num:%s', UsersManager().get_online_num()) tlog_action.log('OnlineNum', UsersManager().get_online_num())
def remote_takeProxy(self, name, transport): """设置代理通道 @param name: 根节点的名称 """ logger.info('>1 node [%s] takeProxy ready' % name) child = Child(self._index, name) self._index += 1 self.childsmanager.addChild(child) child.setTransport(transport) self.doChildConnect(name, transport) logger.info('>2 node [%s] takeProxy ready' % name)
def first_recharge(self, recharge_item, response): if recharge_item.get('id') in self._first_recharge_ids: logger.error('first recharge is repeated:%s:%s', self.id, recharge_item.get('fristGift')) return False self._first_recharge_ids.append(recharge_item.get('id')) self.save_data() logger.info('first recharge :%s:%s:%s', self.id, recharge_item.get('fristGift'), self._first_recharge_ids) return True
def __user_login(account_name='', account_password=''): get_result = util.GetOneRecordInfo(USER_TABLE_NAME, dict(account_name=account_name, account_password=account_password)) logger.info(get_result) if get_result is None: return json.dumps(dict(result=False, id=11, result_no=3300010007, message='account name or password error!')) if get_result['id'] not in account_login_cache: account_login_cache.append(get_result['id']) return json.dumps(dict(result=True, passport=get_result['id']))