def del_zombie_user(self, cid): ''' 清除僵尸玩家,无效client连接 ''' _user = self.user_dic.get(cid, None) if _user: if hasattr(_user, 'p'): if hasattr(_user.p, 'transport'): if _user.p.transport: defer.returnValue(NO_ERROR) else: log.error( 'Unknown user. cid:{0}, transport:{1}.'.format( cid, _user.p.transport)) else: log.warn( 'Unknown user. cid:{0}, the p has no transport attribute..' .format(cid)) else: log.warn('__broadcast. cid:{0}, the user has no p attribute..'. format(_user.cid)) self.delUserByCid(cid) gs_call('gs_logout', cid) ms_call('ms_logout', [cid]) yield alli_call('alli_logout', [cid]) log.warn('Del zombie user success. cid: {0}.'.format(cid)) defer.returnValue(NO_ERROR)
def gm_bag_info(cmd, ts, args, sign): ''' 查询玩家的背包物品 ''' res_err = {'result': 1, 'bag_info': []} if len(args) != 2: res_err['result'] = GM_INVALID_ARGS defer.returnValue( res_err ) _cid = int(args['character_id']) _bag_type = int(args['bag_type']) try: errorno = yield gs_call("gs_gm_login", (_cid, True)) if errorno: res_err['result'] = errorno defer.returnValue(res_err) _bag_info = yield gs_call('gs_gm_get_bag_info', [_cid, _bag_type]) res_err['bag_info'] = _bag_info except Exception as e: log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(res_err) defer.returnValue(res_err)
def gm_camp_info(cmd, ts, args, sign): ''' 查询玩家的阵容信息 ''' res_err = {'result': 1, 'camp_info': []} if len(args) != 1: res_err['result'] = GM_INVALID_ARGS defer.returnValue(res_err) _cid = int(args['character_id']) try: errorno = yield gs_call("gs_gm_login", (_cid, True)) if errorno: res_err['result'] = errorno defer.returnValue(res_err) _camp_info = yield gs_call('gs_gm_get_camp_info', [_cid]) res_err['camp_info'] = _camp_info except Exception as e: log.error(' ERROR e:', e) log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(res_err) defer.returnValue(res_err)
def gm_bag_info(cmd, ts, args, sign): ''' 查询玩家的背包物品 ''' res_err = {'result': 1, 'bag_info': []} if len(args) != 2: res_err['result'] = GM_INVALID_ARGS defer.returnValue(res_err) _cid = int(args['character_id']) _bag_type = int(args['bag_type']) try: errorno = yield gs_call("gs_gm_login", (_cid, True)) if errorno: res_err['result'] = errorno defer.returnValue(res_err) _bag_info = yield gs_call('gs_gm_get_bag_info', [_cid, _bag_type]) res_err['bag_info'] = _bag_info except Exception as e: log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(res_err) defer.returnValue(res_err)
def gm_camp_info(cmd, ts, args, sign): ''' 查询玩家的阵容信息 ''' res_err = {'result': 1, 'camp_info': []} if len(args) != 1: res_err['result'] = GM_INVALID_ARGS defer.returnValue( res_err ) _cid = int(args['character_id']) try: errorno = yield gs_call("gs_gm_login", (_cid, True)) if errorno: res_err['result'] = errorno defer.returnValue(res_err) _camp_info = yield gs_call('gs_gm_get_camp_info', [_cid]) res_err['camp_info'] = _camp_info except Exception as e: log.error(' ERROR e:', e) log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(res_err) defer.returnValue(res_err)
def gm_modify_character_level(cmd, ts, args, sign): res_err = {'result': 1, 'level': 0} if len(args) != 2: defer.returnValue(GM_INVALID_ARGS) _cid = int(args['character_id']) _level = int(args['character_level']) try: errorno = yield gs_call("gs_gm_login", (_cid, False)) if errorno: res_err['result'] = errorno defer.returnValue(res_err) errorno, _final_level = yield gs_call('gs_gm_modify_character_level', [_cid, _level]) if errorno: res_err['result'] = GM_INVALID_ERROR else: res_err['level'] = _final_level except Exception as e: log.error(' ERROR e:', e) log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(res_err) server_logout_user(_cid) defer.returnValue(res_err)
def gm_modify_character_level(cmd, ts, args, sign): res_err = {'result': 1, 'level': 0} if len(args) != 2: defer.returnValue(GM_INVALID_ARGS) _cid = int(args['character_id']) _level = int(args['character_level']) try: errorno = yield gs_call("gs_gm_login", (_cid, False)) if errorno: res_err['result'] = errorno defer.returnValue(res_err) errorno, _final_level = yield gs_call('gs_gm_modify_character_level', [_cid, _level]) if errorno: res_err['result'] = GM_INVALID_ERROR else: res_err['level'] = _final_level except Exception as e: log.error(' ERROR e:', e) log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(res_err) server_logout_user(_cid) defer.returnValue( res_err )
def logoutUser(self, cid): user = self.user_dic.get(cid, None) if user: user.p = None user.temp_lost = True # update logout_timestamp now_timestamp = int(time()) user.logout_timestamp = now_timestamp gs_call('sync_user_to_cs', cid) reactor.callLater(SESSION_LOGOUT_REAL, self.logoutUserReal, cid, now_timestamp) log.debug('user will logout later. cid: {0}.'.format( cid )) else: log.warn('Unknown user. cid: {0}.'.format( cid ))
def gm_add_credits(cmd, ts, args, sign): if len(args) != 2: log.error('add credits error. args:{0}.'.format( args )) defer.returnValue(GM_INVALID_ARGS) account = args[0] add_credits = int( args[1] ) try: res_login = yield server_login_user( account ) except Exception as e: log.exception() defer.returnValue(GM_EXECUTE_FAIL) log.debug('Res of server_login_user:'******'Exp39287692 login user fail! account {0}, err_login {1}'.format( account, err_login )) defer.returnValue(GM_LOGIN_USER_FAIL) res = GM_EXECUTE_FAIL try: res = yield gs_call('gs_gm_add_credits', [ cid, add_credits ]) except Exception as e: log.debug('Exp39380828 e:', e) log.exception() server_logout_user(cid) defer.returnValue( res )
def alliance_create(p, req): cid, [ name, create_type ] = req _m = g_UserMgr.getUser( cid ) if not _m: returnValue( CONNECTION_LOSE ) # 判断玩家是否有仙盟 if _m.alliance: returnValue( ALLIANCE_SELF_HAD_IN ) name = name.strip() _all = server.alliances for _alliance in _all: # 仙盟名重复 if _alliance.name == name: returnValue( ALLIANCE_NAME_DUPLICATED ) res_gs, golds, credits = yield gs_call( 'gs_create_alliance', [ cid, create_type ] ) if res_gs: returnValue( res_gs ) _alliance = yield server.create_alliance( name, _m ) _rank = server.rank( _alliance ) syslogger(LOG_ALLIANCE_CREATE, cid, _m.level, _m.vip_level, _alliance.aid) returnValue( (golds, credits, _alliance.info+[_rank, _alliance.notice]) )
def alliance_create(p, req): cid, [name, create_type] = req _m = g_UserMgr.getUser(cid) if not _m: returnValue(CONNECTION_LOSE) # 判断玩家是否有仙盟 if _m.alliance: returnValue(ALLIANCE_SELF_HAD_IN) name = name.strip() _all = server.alliances for _alliance in _all: # 仙盟名重复 if _alliance.name == name: returnValue(ALLIANCE_NAME_DUPLICATED) res_gs, golds, credits = yield gs_call('gs_create_alliance', [cid, create_type]) if res_gs: returnValue(res_gs) _alliance = yield server.create_alliance(name, _m) _rank = server.rank(_alliance) syslogger(LOG_ALLIANCE_CREATE, cid, _m.level, _m.vip_level, _alliance.aid) returnValue((golds, credits, _alliance.info + [_rank, _alliance.notice]))
def logoutUser(self, cid): user = self.user_dic.get(cid, None) if user: user.p = None user.temp_lost = True # update logout_timestamp now_timestamp = int(time()) user.logout_timestamp = now_timestamp gs_call('sync_user_to_cs', cid) reactor.callLater(SESSION_LOGOUT_REAL, self.logoutUserReal, cid, now_timestamp) log.debug('user will logout later. cid: {0}.'.format(cid)) else: log.warn('Unknown user. cid: {0}.'.format(cid))
def gm_add_credits(cmd, ts, args, sign): if len(args) != 2: log.error('add credits error. args:{0}.'.format(args)) defer.returnValue(GM_INVALID_ARGS) account = args[0] add_credits = int(args[1]) try: res_login = yield server_login_user(account) except Exception as e: log.exception() defer.returnValue(GM_EXECUTE_FAIL) log.debug('Res of server_login_user:'******'Exp39287692 login user fail! account {0}, err_login {1}'.format( account, err_login)) defer.returnValue(GM_LOGIN_USER_FAIL) res = GM_EXECUTE_FAIL try: res = yield gs_call('gs_gm_add_credits', [cid, add_credits]) except Exception as e: log.debug('Exp39380828 e:', e) log.exception() server_logout_user(cid) defer.returnValue(res)
def logoutUserReal(self, cid, now_timestamp): ''' 同时满足两个条件才能真正的删除玩家 1: temp_lost == True, offline 2: logout_timestamp == now_timestamp, 借用时间戳作为标识, 匹配后标识是同一个事件 ''' user = self.user_dic.get(cid, None) if user: log.debug('logout cid: {0}, temp_lost: {1}, logout_timestamp: {2}, now_timestamp: {3}.'.format(\ cid, user.temp_lost, user.logout_timestamp, now_timestamp) ) if user.temp_lost and user.logout_timestamp == now_timestamp: self.delUserByCid( cid ) gs_call('gs_logout', cid) ms_call('ms_logout', [cid]) yield alli_call('alli_logout', [cid]) log.debug('User logout real. cid: {0}.'.format( cid )) else: log.error('User had logout. cid: {0}.'.format( cid ))
def logoutUserReal(self, cid, now_timestamp): ''' 同时满足两个条件才能真正的删除玩家 1: temp_lost == True, offline 2: logout_timestamp == now_timestamp, 借用时间戳作为标识, 匹配后标识是同一个事件 ''' user = self.user_dic.get(cid, None) if user: log.debug('logout cid: {0}, temp_lost: {1}, logout_timestamp: {2}, now_timestamp: {3}.'.format(\ cid, user.temp_lost, user.logout_timestamp, now_timestamp) ) if user.temp_lost and user.logout_timestamp == now_timestamp: self.delUserByCid(cid) gs_call('gs_logout', cid) ms_call('ms_logout', [cid]) yield alli_call('alli_logout', [cid]) log.debug('User logout real. cid: {0}.'.format(cid)) else: log.error('User had logout. cid: {0}.'.format(cid))
def kickoutUser(self, cid): _user = self.user_dic.get(cid, None) if _user: self.delUserByCid(cid) yield gs_call('gs_kickout_user', [cid]) ms_call('ms_logout', [cid]) yield alli_call('alli_logout', [cid]) defer.returnValue(NO_ERROR)
def kickoutUser(self, cid): _user = self.user_dic.get(cid, None) if _user: self.delUserByCid( cid ) yield gs_call('gs_kickout_user', [cid]) ms_call('ms_logout', [cid]) yield alli_call('alli_logout', [cid]) defer.returnValue( NO_ERROR )
def use_gift_code(p, req): ''' 使用兑换码 @param: platform_id-合作商ID。1:tipcat, 其它... @param: giftcode-兑换码序列号 @param: game_server_id-OSS中服务器管理对应的游戏服务器ID ''' errorno = GIFT_CODE_FAILURE response, url, cid, return_code, errorno = '', '', 0, 0, 0 platform_id, giftcode, game_server_id = int(req[0]), req[1], int(req[2]) if platform_id is None: log.error('OSS PARAM ERROR. request: {0}.'.format(req)) defer.returnValue((errorno, '')) # 除了tipcat外 就是heitao if platform_id == TIPCAT_CID: base_url = TIPCAT_LOCAL_OSS_URLBASE else: base_url = TIPCAT_ONLINE_OSS_URLBASE try: cid = p.cid url = oss_gift_code_url(base_url, platform_id, giftcode, game_server_id, cid) #log.info('For Test. url: {0}.'.format( url )) gift_id = 0 response = yield httphelper.request(url, 'POST') response = loads(response) #log.info('For Test. response: {0}.'.format( response )) return_code = int(response['return_code']) if return_code <= 0: log.error( 'OSS GIFTCODE ERROR. cid: {0}, request: {1}, response: {2}, url: {3}.' .format(cid, req, response, url)) errorno = OSS_RETURN_CODE.get(return_code, GIFT_CODE_FAILURE) else: gift_id = int(response['gift_id']) errorno = yield gs_call('new_award_to_center', (cid, gift_id)) if errorno: log.error( 'Unknown gift_id ERROR. cid: {0}, request: {1}, response: {2}, url: {3}.' .format(cid, req, response, url)) user = g_UserMgr.getUserByCid(cid) if user and user.info: syslogger(LOG_GIFT_CODE_USE, cid, user.info['level'], user.info['vip_level'], 0, giftcode, gift_id, return_code, errorno) else: syslogger(LOG_GIFT_CODE_USE, cid, 0, 0, 0, giftcode, gift_id, return_code, errorno) defer.returnValue((errorno, '')) except Exception as e: log.error('OSS GIFTCODE ERROR. cid: {0}, request: {1}, response: {2}.'. format(cid, req, response)) log.exception() defer.returnValue((errorno, ''))
def gm_character_info(cmd, ts, args, sign): res_err = {'result': 1, 'character_info': {}} if len(args) != 1: res_err['result'] = GM_INVALID_ARGS defer.returnValue(res_err) _cid = int(args['character_id']) _dict_data = {} user = g_UserMgr.getUserByCid(_cid) if user: _dict_data = copy.deepcopy(user.info) if user.temp_lost: _dict_data['online'] = 0 else: _dict_data['online'] = 1 else: try: errorno = yield gs_call("gs_gm_login", (_cid, True)) if errorno: res_err['result'] = GM_INVALID_CID defer.returnValue(res_err) _dict_data = yield gs_call('gs_gm_get_character_info', [_cid]) _dict_data['online'] = 0 except Exception as e: log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(res_err) _dict_data['register_time'] = timestamp2string(_dict_data['register_time']) _dict_data['last_login_time'] = timestamp2string( _dict_data['last_login_time']) _dict_data['forbidden_seconds'] = yield check_character_status( _cid, TYPE_FORBIDDEN) _dict_data['mute_seconds'] = yield check_character_status(_cid, TYPE_MUTE) res_err['character_info'] = _dict_data defer.returnValue(res_err)
def del_zombie_user(self, cid): ''' 清除僵尸玩家,无效client连接 ''' _user = self.user_dic.get(cid, None) if _user: if hasattr(_user, 'p'): if hasattr(_user.p, 'transport'): if _user.p.transport: defer.returnValue( NO_ERROR ) else: log.error('Unknown user. cid:{0}, transport:{1}.'.format(cid, _user.p.transport)) else: log.warn('Unknown user. cid:{0}, the p has no transport attribute..'.format(cid)) else: log.warn('__broadcast. cid:{0}, the user has no p attribute..'.format(_user.cid)) self.delUserByCid( cid ) gs_call('gs_logout', cid) ms_call('ms_logout', [cid]) yield alli_call('alli_logout', [cid]) log.warn('Del zombie user success. cid: {0}.'.format( cid )) defer.returnValue( NO_ERROR )
def gm_character_info(cmd, ts, args, sign): res_err = {'result': 1, 'character_info': {}} if len(args) != 1: res_err['result'] = GM_INVALID_ARGS defer.returnValue( res_err ) _cid = int(args['character_id']) _dict_data = {} user = g_UserMgr.getUserByCid( _cid ) if user: _dict_data = copy.deepcopy(user.info) if user.temp_lost: _dict_data['online'] = 0 else: _dict_data['online'] = 1 else: try: errorno = yield gs_call("gs_gm_login", (_cid, True)) if errorno: res_err['result'] = GM_INVALID_CID defer.returnValue( res_err ) _dict_data = yield gs_call('gs_gm_get_character_info', [_cid]) _dict_data['online'] = 0 except Exception as e: log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue( res_err ) _dict_data['register_time'] = timestamp2string( _dict_data['register_time'] ) _dict_data['last_login_time'] = timestamp2string( _dict_data['last_login_time'] ) _dict_data['forbidden_seconds'] = yield check_character_status(_cid, TYPE_FORBIDDEN) _dict_data['mute_seconds'] = yield check_character_status(_cid, TYPE_MUTE) res_err['character_info'] = _dict_data defer.returnValue( res_err )
def use_gift_code(p, req): ''' 使用兑换码 @param: platform_id-合作商ID。1:tipcat, 其它... @param: giftcode-兑换码序列号 @param: game_server_id-OSS中服务器管理对应的游戏服务器ID ''' errorno = GIFT_CODE_FAILURE response, url, cid, return_code, errorno = '', '', 0, 0, 0 platform_id, giftcode, game_server_id = int(req[0]), req[1], int(req[2]) if platform_id is None: log.error('OSS PARAM ERROR. request: {0}.'.format( req )) defer.returnValue( (errorno, '') ) # 除了tipcat外 就是heitao if platform_id == TIPCAT_CID: base_url = TIPCAT_LOCAL_OSS_URLBASE else: base_url = TIPCAT_ONLINE_OSS_URLBASE try: cid = p.cid url = oss_gift_code_url(base_url, platform_id, giftcode, game_server_id, cid) #log.info('For Test. url: {0}.'.format( url )) gift_id = 0 response = yield httphelper.request(url, 'POST') response = loads(response) #log.info('For Test. response: {0}.'.format( response )) return_code = int(response['return_code']) if return_code <= 0: log.error('OSS GIFTCODE ERROR. cid: {0}, request: {1}, response: {2}, url: {3}.'.format( cid, req, response, url )) errorno = OSS_RETURN_CODE.get(return_code, GIFT_CODE_FAILURE) else: gift_id = int(response['gift_id']) errorno = yield gs_call('new_award_to_center', (cid, gift_id)) if errorno: log.error('Unknown gift_id ERROR. cid: {0}, request: {1}, response: {2}, url: {3}.'.format( cid, req, response, url )) user = g_UserMgr.getUserByCid( cid ) if user and user.info: syslogger(LOG_GIFT_CODE_USE, cid, user.info['level'], user.info['vip_level'], 0, giftcode, gift_id, return_code, errorno) else: syslogger(LOG_GIFT_CODE_USE, cid, 0, 0, 0, giftcode, gift_id, return_code, errorno) defer.returnValue( (errorno, '') ) except Exception as e: log.error('OSS GIFTCODE ERROR. cid: {0}, request: {1}, response: {2}.'.format( cid, req, response )) log.exception() defer.returnValue( (errorno, '') )
def limit_item_exchange(self, member, index): ''' 仙盟商店中兑换珍宝 ''' _data = yield redis.hget(HASH_ALLIANCE_LIMIT_ITEM, self.__id) if not _data: defer.returnValue( REFRESH_ITEM_ERROR ) _data = loads( _data ) # 判断是否是12点需要更新 _reset_timestamp = get_reset_timestamp(12) if _data[0] <= _reset_timestamp or len(_data[2]) <= index: defer.returnValue( REFRESH_ITEM_ERROR ) detail = _data[2][index] limit_conf = get_shop_limit_conf( _data[1] ) item_conf = limit_conf.get( detail[0], None ) if not item_conf: defer.returnValue( NOT_FOUND_CONF ) # 检查是否重复兑换 if member.cid in detail[1]: defer.returnValue( EXCHANGE_ITEM_REPEAT_ERROR ) # 检查可兑换次数 _left_count = item_conf['BuyMax'] - len(detail[1]) if _left_count <= 0: defer.returnValue( EXCHANGE_ITEM_COUNT_NOT_ENOUGH ) # 检查个人贡献是否满足 if member.contribution < item_conf['Cost']: defer.returnValue( MEMBER_CONTRIBUTE_NOT_ENOUGH ) # 兑换道具 items_list = [[item_conf['ItemType'], item_conf['ItemID'], item_conf['ItemNum']]] errorno, add_items = yield gs_call('gs_exchange_item', (member.cid, WAY_ALLIANCE_LIMIT_ITEM, items_list)) if errorno: defer.returnValue( errorno ) # 更新兑换记录 detail[1].append( member.cid ) _data[2][index] = detail yield redis.hset(HASH_ALLIANCE_LIMIT_ITEM, self.__id, dumps(_data)) # 扣个人贡献度 member.delta_contribution( -item_conf['Cost'] ) # add syslog syslogger(LOG_CONTRIBUTE_LOSE, member.cid, member.level, member.vip_level, self.__id, \ item_conf['Cost'], member.contribution, member.contribution_total, WAY_ALLIANCE_LIMIT_ITEM, '(%s,)'%(detail[0])) defer.returnValue( (index, _left_count-1, member.contribution, add_items) )
def gm_add_items(cmd, ts, args, sign): if len(args) != 5: log.error('add items error. args:{0}.'.format(args)) defer.returnValue(GM_INVALID_ARGS) account = args[0] item_type = int(args[1]) item_id = int(args[2]) add_count = int(args[3]) server_id = int(args[4]) try: res_login = yield server_login_user('%s%s' % (account, server_id)) except Exception as e: log.exception() defer.returnValue(GM_EXECUTE_FAIL) log.debug('Res of server_login_user:'******'user login fail! account {0}, err_login {1}'.format( account, err_login)) defer.returnValue(GM_LOGIN_USER_FAIL) res = GM_EXECUTE_FAIL try: res = yield gs_call('gs_gm_add_items', [cid, item_type, item_id, add_count]) if not res[0]: quantity = 0 for _, _, _, _num in res[1]: quantity += _num res[1] = quantity except Exception as e: log.error('exception. cid: {0}, e: {1}.'.format(cid, e)) log.exception() server_logout_user(cid) defer.returnValue(res)
def item_exchange(self, member, shop_item_id): ''' 仙盟商店-兑换道具 ''' item_conf = get_shop_item_conf( shop_item_id ) if not item_conf: defer.returnValue( NOT_FOUND_CONF ) # 道具的公会等级限制 if self.__level < item_conf['GuildLevel']: defer.returnValue( ALLIANCE_LEVEL_LIMIT ) # 检查个人贡献是否满足 if member.contribution < item_conf['Cost']: defer.returnValue( MEMBER_CONTRIBUTE_NOT_ENOUGH ) # 检查今日兑换次数是否充足 exchange_count = 0 exchange_info = yield self.item_info(member) for _idx, _detail in enumerate(exchange_info[1]): if _detail[0] == shop_item_id: if _detail[1] >= item_conf['BuyMax']: defer.returnValue( EXCHANGE_ITEM_COUNT_NOT_ENOUGH ) _detail[1] += 1 exchange_count = _detail[1] exchange_info[1][_idx] = _detail break else: exchange_count = 1 exchange_info[1].append( [shop_item_id, 1] ) # 兑换道具 items_list = [[item_conf['ItemType'], item_conf['ItemID'], item_conf['ItemNum']]] errorno, add_items = yield gs_call('gs_exchange_item', (member.cid, WAY_ALLIANCE_ITEM, items_list)) if errorno: defer.returnValue( errorno ) # 更新兑换记录 yield redis.hset(HASH_ALLIANCE_ITEM, member.cid, dumps(exchange_info)) # 扣个人贡献度 member.delta_contribution( -item_conf['Cost'] ) # add syslog syslogger(LOG_CONTRIBUTE_LOSE, member.cid, member.level, member.vip_level, self.__id, \ item_conf['Cost'], member.contribution, member.contribution_total, WAY_ALLIANCE_ITEM, '(%s,)'%(shop_item_id)) defer.returnValue( (shop_item_id, exchange_count, member.contribution, add_items) )
def server_login_user(account, character_id=None): if character_id: cid = character_id else: cid = yield redis.hget(DICT_ACCOUNT_REGISTERED, account) if not cid: defer.returnValue( (GM_INVALID_CID, 0) ) else: cid = int( cid ) user = g_UserMgr.getUserByCid( cid ) if user: defer.returnValue( (0, cid) ) try: errorno = yield gs_call("gs_gm_login", (cid, False)) if errorno: defer.returnValue( (GM_INVALID_ERROR, 0) ) except Exception as e: log.warn('Some exp raise when calling gs_offline_login(). e: {0}'.format(e)) defer.returnValue( (GM_INVALID_ERROR, 0) ) defer.returnValue( (0, cid) )
def gm_add_items(cmd, ts, args, sign): if len(args) != 5: log.error('add items error. args:{0}.'.format( args )) defer.returnValue(GM_INVALID_ARGS) account = args[0] item_type = int( args[1] ) item_id = int( args[2] ) add_count = int( args[3] ) server_id = int( args[4] ) try: res_login = yield server_login_user( '%s%s'%(account,server_id) ) except Exception as e: log.exception() defer.returnValue(GM_EXECUTE_FAIL) log.debug('Res of server_login_user:'******'user login fail! account {0}, err_login {1}'.format( account, err_login )) defer.returnValue(GM_LOGIN_USER_FAIL) res = GM_EXECUTE_FAIL try: res = yield gs_call('gs_gm_add_items', [ cid, item_type, item_id, add_count ]) if not res[0]: quantity = 0 for _, _, _, _num in res[1]: quantity += _num res[1] = quantity except Exception as e: log.error('exception. cid: {0}, e: {1}.'.format(cid, e) ) log.exception() server_logout_user( cid ) defer.returnValue( res )
def server_login_user(account, character_id=None): if character_id: cid = character_id else: cid = yield redis.hget(DICT_ACCOUNT_REGISTERED, account) if not cid: defer.returnValue((GM_INVALID_CID, 0)) else: cid = int(cid) user = g_UserMgr.getUserByCid(cid) if user: defer.returnValue((0, cid)) try: errorno = yield gs_call("gs_gm_login", (cid, False)) if errorno: defer.returnValue((GM_INVALID_ERROR, 0)) except Exception as e: log.warn( 'Some exp raise when calling gs_offline_login(). e: {0}'.format(e)) defer.returnValue((GM_INVALID_ERROR, 0)) defer.returnValue((0, cid))
def htpayment(request): ''' @param: charge_id-充值交易ID ''' request.setHeader('Content-Type', 'application/json;charset=UTF-8') log.info('[ payment ] request.args: {0}.'.format( request.args )) res_err = {'result': 1, 'extend': ''} if len(request.args) != 6: log.error("[ payment ] unknown args: {0}.".format( request.args )) res_err['result'] = -PAYMENT_ARGS_ERROR defer.returnValue( json.dumps( res_err ) ) charge_id = int(request.args['order'][0]) orderno = request.args['transaction'][0] account = request.args['user'][0] server_id = request.args['server'][0] amount = request.args['amount'][0] sign = request.args['salt'][0] repeat_flag, new_flag = yield load_data(orderno) log.info('repeat_flag: {0}, new_flag: {1}.'.format( repeat_flag, new_flag )) if repeat_flag: log.error("[ payment ] repeat orderno. args: {0}.".format( request.args )) res_err['result'] = -PAYMENT_ORDERNO_REPEAT defer.returnValue( json.dumps( res_err ) ) if new_flag: yield new_data( [orderno, account, 0, server_id, amount, charge_id, datetime.now(), 0, 0] ) log.info('[ payment ] charge_id:{0}, orderno:{1}, account:{2}, server_id:{3}, amount:{4}.'.format(charge_id, orderno, account, server_id, amount)) #Check sign sign_local = check_sign(charge_id, orderno, account, server_id, amount, '2481ba98a91fca6') sign_local = sign_local[3:28] log.info("[ payment ] sign:{0}, sign_local:{1}.".format(sign, sign_local)) if sign != sign_local: log.error("[ payment ] unknown sign:{0}, sign_local:{1}.".format(sign, sign_local)) res_err['result'] = -PAYMENT_SIGN_ERROR defer.returnValue( json.dumps( res_err ) ) try: err_login, cid = yield server_login_user( '%s%s'%(account, server_id) ) except Exception as e: log.error("[ htpayment ] unknown error, account: {0}, e: {1}, args: {2}.".format( account, e, request.args )) res_err['result'] = -PAYMENT_USER_ERROR defer.returnValue( json.dumps(res_err) ) if err_login or (not cid): log.error('[ payment ] unknown account: {0}, cid: {1}, args: {2}.'.format( account, cid, request.args )) res_err['result'] = -PAYMENT_USER_ERROR defer.returnValue( json.dumps(res_err) ) # 预留的参数 platform_id, parent_id, currency_type, currency = 1, 1, 1, 0 try: res_data, credits_data = yield gs_call("payment_from_platfrom", (cid, orderno, charge_id, platform_id, parent_id, currency_type, currency)) if not res_data: send2client(cid, 'sync_credits_added', credits_data[1:]) # update sql data yield update_data( [cid, datetime.now(), credits_data[0], orderno] ) else: log.error('[ payment ]result from gameserver. res_data:{0}, args: {1}.'.format(res_data, request.args)) res_err['result'] = -PAYMENT_FAIL defer.returnValue( json.dumps(res_err) ) except Exception, e: log.exception("[ payment ]gs_call error. account:{0}, charge_id:{1}, platform_id:{2}, parent_id:{3}, currency_type:{4}, currency:{5}, args:{6}.".format( account, charge_id, platform_id, parent_id, currency_type, currency, request.args)) res_err['result'] = -PAYMENT_FAIL defer.returnValue( json.dumps(res_err) )
def daily_sacrifice(self, sacrifice_type, member): ''' 公会成员拜祭女蜗宫 ''' _detail_count = yield self.sacrifice_info(member) if isinstance(_detail_count, int): defer.returnValue( _detail_count ) _data = _detail_count[5] if sacrifice_type == ALLIANCE_SACRIFICE_NORMAL: # 次数不足 if _detail_count[1] <= 0: defer.returnValue( SACRIFICE_NORMAL_COUNT_ERROR ) if _detail_count[0] <= 0: defer.returnValue( SACRIFICE_ALLIANCE_COUNT_ERROR ) # 个人可用贡献度不足 if member.contribution < SACRIFICE_NEED_CONTRIBUTION: defer.returnValue( MEMBER_CONTRIBUTE_NOT_ENOUGH ) # 给奖励 _award_conf = get_sacrifice_award_conf( self.__building_levels[0] ) if not _award_conf: defer.returnValue( NOT_FOUND_CONF ) errorno, left_credits, add_items = yield gs_call('gs_alliance_sacrifice', (member.cid, 0, _award_conf)) if errorno: defer.returnValue( errorno ) # 扣个人贡献度 member.delta_contribution( -SACRIFICE_NEED_CONTRIBUTION ) # 扣拜祭次数 _data[1] += 1 for _idx, _value in enumerate(_data[2]): if _value[0] == member.cid: _value[1] += 1 _data[2][_idx] = _value break else: _data[2].append( [member.cid, 1, 0] ) yield redis.hset(HASH_ALLIANCE_SACRIFICE, self.__id, dumps(_data)) # 公会动态 self.new_action( (ALLIANCE_ACTION_8, int(time()), member.cid, member.lead_id, \ member.nick_name, member.level, [self.__building_levels[0]]) ) # add syslog syslogger(LOG_CONTRIBUTE_LOSE, member.cid, member.level, member.vip_level, self.__id, \ SACRIFICE_NEED_CONTRIBUTION, member.contribution, member.contribution_total, WAY_ALLIANCE_SACRIFICE_NORMAL, '') defer.returnValue( (_detail_count[0]-1, _detail_count[1]-1, _detail_count[2], member.contribution, left_credits, add_items) ) elif sacrifice_type == ALLIANCE_SACRIFICE_CREDITS: # 次数不足 if _detail_count[2] <= 0: defer.returnValue( SACRIFICE_CREDITS_COUNT_ERROR ) # 给奖励 _award_conf = get_sacrifice_award_conf( self.__building_levels[0] ) if not _award_conf: defer.returnValue( NOT_FOUND_CONF ) errorno, left_credits, add_items = yield gs_call('gs_alliance_sacrifice', (member.cid, SACRIFICE_NEED_CREDITS, _award_conf)) if errorno: defer.returnValue( errorno ) # 扣拜祭次数 for _idx, _value in enumerate(_data[2]): if _value[0] == member.cid: _value[2] += 1 _data[2][_idx] = _value break else: _data[2].append( [member.cid, 0, 1] ) yield redis.hset(HASH_ALLIANCE_SACRIFICE, self.__id, dumps(_data)) # 公会动态 self.new_action( (ALLIANCE_ACTION_8, int(time()), member.cid, member.lead_id, \ member.nick_name, member.level, [self.__building_levels[0]]) ) # add syslog syslogger(LOG_CONTRIBUTE_LOSE, member.cid, member.level, member.vip_level, self.__id, \ 0, member.contribution, member.contribution_total, WAY_ALLIANCE_SACRIFICE_CREDITS, '') defer.returnValue( (_detail_count[0], _detail_count[1], _detail_count[2]-1, member.contribution, left_credits, add_items) ) else: defer.returnValue( REQUEST_LIMIT_ERROR )
#Check gm_sign sign_local = heitao_gm_sign(cmd, ts, args) if sign != sign_local: sign_local = base_gm_sign(cmd, ts, args) if sign != sign_local: log.error('Sign does not match! req {0}, local {1}'.format( sign, sign_local )) res_err['result'] = GM_INVALID_SIGN defer.returnValue( json.dumps(res_err) ) try: args = json.loads(args) if gm_cmd_route.has_key(cmd): func = gm_cmd_route[cmd] res_data = yield func(cmd, ts, args, sign) #log.info('For Test. request cmd: {0}, res of data: {1}.'.format( cmd, res_data )) elif gs_gm_cmd_route.has_key(cmd): res_data = yield gs_call('gs_gm_%s'%cmd, (args, )) else: log.error('Invalid cmd : {0}.'.format( cmd )) res_err['result'] = GM_INVALID_CMD defer.returnValue( json.dumps(res_err) ) defer.returnValue( json.dumps(res_data, cls=DecimalEncoder) ) except Exception as e: log.error('Unknown error. e:{0}, req_args:{1}.'.format(e, req_args)) log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue( json.dumps(res_err) )
def gm_grant_items_to(cmd, ts, args, sign): """ 系统道具发放, 在玩家登陆时到领奖中心获取奖励 """ res_err = {'result': 1, \ 'errors': {'character_ids':'', 'items_list':[]}, \ 'success': {'character_ids':''}} if len(args) != 2: res_err['result'] = GM_INVALID_ARGS log.error('Args length error. args: {0}.'.format(args)) defer.returnValue(res_err) _character_cids = args['character_ids'] _all_items = args['item_lists'] if not _character_cids: res_err['result'] = GM_INVALID_ARGS log.error( 'Unknown cids. _character_cids: {0}.'.format(_character_cids)) defer.returnValue(res_err) try: # 检查道具的类型和ID是否匹配 _items_list = [[ int(_item['item_type']), int(_item['item_id']), int(_item['item_cnt']) ] for _item in _all_items] errorno, error_items = yield gs_call("gs_gm_check_grant_items", (_items_list, )) if errorno: res_err['result'] = GM_INVALID_ITEM res_err['errors']['items_list'] = error_items defer.returnValue(res_err) _grant_key = int(time()) # 处理玩家cid 列表 _grant_cids = [] # 需要在线发放item的玩家ID列表 _connect_cids = g_UserMgr.connect_cids() if _character_cids == '-1': _character_cids = [] _grant_cids = _connect_cids else: _character_cids = map(int, _character_cids.split(',')) if not _character_cids or not isinstance(_character_cids, list): res_err['result'] = GM_INVALID_ARGS log.error('Unknown cids. _character_cids: {0}.'.format( _character_cids)) defer.returnValue(res_err) # 检查cid的合法性 未知cid将被忽略 _invalid_cids = [] for _cid in _character_cids: _valid_cid = yield redis.sismember(SET_CID_REGISTERED, _cid) if not _valid_cid: _invalid_cids.append(_cid) continue if _cid in _connect_cids: _grant_cids.append(_cid) if _invalid_cids: res_err['result'] = GM_INVALID_CID res_err['errors']['character_ids'] = _invalid_cids defer.returnValue(res_err) # 在线玩家直接发送到领奖中心 if _grant_cids: yield gs_call('gs_gm_grant_to_center', (_grant_cids, _grant_key, _items_list)) # 保存发放记录 _grant_info = marshal.dumps((_character_cids, _items_list, 0)) yield redis.hset(HASH_GM_GRANT_ITEMS, _grant_key, _grant_info) # 更新返回值的信息 if _character_cids != '-1': res_err['success']['character_ids'] = args['character_ids'] defer.returnValue(res_err) except Exception as e: log.exception() res_err['result'] = GM_INVALID_ARGS defer.returnValue(res_err) defer.returnValue(res_err)
def gm_grant_items_to(cmd, ts, args, sign): """ 系统道具发放, 在玩家登陆时到领奖中心获取奖励 """ res_err = {'result': 1, \ 'errors': {'character_ids':'', 'items_list':[]}, \ 'success': {'character_ids':''}} if len(args) != 2: res_err['result'] = GM_INVALID_ARGS log.error('Args length error. args: {0}.'.format( args )) defer.returnValue( res_err ) _character_cids = args['character_ids'] _all_items = args['item_lists'] if not _character_cids: res_err['result'] = GM_INVALID_ARGS log.error('Unknown cids. _character_cids: {0}.'.format( _character_cids )) defer.returnValue( res_err ) try: # 检查道具的类型和ID是否匹配 _items_list = [[int(_item['item_type']), int(_item['item_id']), int(_item['item_cnt'])] for _item in _all_items] errorno, error_items = yield gs_call("gs_gm_check_grant_items", (_items_list, )) if errorno: res_err['result'] = GM_INVALID_ITEM res_err['errors']['items_list'] = error_items defer.returnValue( res_err ) _grant_key = int(time()) # 处理玩家cid 列表 _grant_cids = [] # 需要在线发放item的玩家ID列表 _connect_cids = g_UserMgr.connect_cids() if _character_cids == '-1': _character_cids = [] _grant_cids = _connect_cids else: _character_cids = map(int, _character_cids.split(',')) if not _character_cids or not isinstance(_character_cids, list): res_err['result'] = GM_INVALID_ARGS log.error('Unknown cids. _character_cids: {0}.'.format( _character_cids )) defer.returnValue(res_err) # 检查cid的合法性 未知cid将被忽略 _invalid_cids = [] for _cid in _character_cids: _valid_cid = yield redis.sismember(SET_CID_REGISTERED, _cid) if not _valid_cid: _invalid_cids.append( _cid ) continue if _cid in _connect_cids: _grant_cids.append( _cid ) if _invalid_cids: res_err['result'] = GM_INVALID_CID res_err['errors']['character_ids'] = _invalid_cids defer.returnValue( res_err ) # 在线玩家直接发送到领奖中心 if _grant_cids: yield gs_call('gs_gm_grant_to_center', (_grant_cids, _grant_key, _items_list)) # 保存发放记录 _grant_info = marshal.dumps((_character_cids, _items_list, 0)) yield redis.hset(HASH_GM_GRANT_ITEMS, _grant_key, _grant_info) # 更新返回值的信息 if _character_cids != '-1': res_err['success']['character_ids'] = args['character_ids'] defer.returnValue( res_err ) except Exception as e: log.exception() res_err['result'] = GM_INVALID_ARGS defer.returnValue(res_err) defer.returnValue( res_err )
def hall_contribute(self, contribute_id, member): ''' 公会成员建设大殿 ''' _data = yield redis.hget(HASH_ALLIANCE_HALL, self.__id) if _data: _data = loads( _data ) # 判断是否需要更新0点更新 _reset_timestamp = get_reset_timestamp() if _data[0] <= _reset_timestamp: _data = [int(time()), [], []] else: _data = [int(time()), [], []] # 当日已建设 if member.cid in _data[2]: defer.returnValue( ALLIANCE_HAD_HALL_CONTRIBUTE ) # 缺少配置 _contribute_conf = get_alliance_contribution_conf(contribute_id) if not _contribute_conf: defer.returnValue( NOT_FOUND_CONF ) # vip level限制 if member.vip_level < _contribute_conf['VipLevel']: defer.returnValue( CHAR_VIP_LEVEL_LIMIT ) # 所需道具是否充足 if _contribute_conf['CostItemType'] != ITEM_TYPE_MONEY: defer.returnValue( UNKNOWN_ITEM_ERROR ) # 扣道具 errorno, left_golds, left_credits = yield gs_call('gs_alliance_hall_contribute', (member.cid, _contribute_conf['CostItemID'], _contribute_conf['CostItemNum']) ) if errorno: defer.returnValue( errorno ) # 更新基本信息 _data[1].append( (member.nick_name, contribute_id) ) _data[2].append( member.cid ) yield redis.hset(HASH_ALLIANCE_HALL, self.__id, dumps(_data)) # 给奖励 需要特殊处理 _guild_num = 0 for _type, _id, _guild_num in _contribute_conf['GuildAward']: if _type != ITEM_TYPE_MONEY or _id != ITEM_GUILD_CONTRIBUTE: log.error('Unknown award type. guild award conf: {0}.'.format( _contribute_conf['GuildAward'] )) continue self.__exp += _guild_num self.dirty() # 推送消息给公会当前在线的会长/副会长, 除了自己 _broadcast_cids = self.online_lead_cids( [member.cid] ) if _broadcast_cids: gw_broadcast( 'sync_multicast', [SYNC_MULTICATE_TYPE_6, [self.__id, self.__level, self.__exp]], _broadcast_cids ) _persion_num = 0 for _type, _id, _persion_num in _contribute_conf['PersonAward']: if _type != ITEM_TYPE_MONEY or _id != ITEM_MEMBER_CONTRIBUTE: log.error('Unknown award type. person award conf: {0}.'.format( _contribute_conf['PersonAward'] )) continue member.hall_get_contribution( _persion_num ) # 公会动态 if _guild_num > 0 or _persion_num > 0: if _contribute_conf['CostItemID'] == ITEM_MONEY_GOLDS: _action_type = ALLIANCE_ACTION_6 else: _action_type = ALLIANCE_ACTION_7 self.new_action( (_action_type, int(time()), member.cid, member.lead_id, member.nick_name, \ member.level, [_contribute_conf['CostItemNum'], _guild_num, _persion_num]) ) #成就 yield gs_send('gs_update_achievement', [member.cid, ACHIEVEMENT_QUEST_ID_24, self.level]) # add syslog if _guild_num > 0: syslogger(LOG_ALLIANCE_EXP_GET, member.cid, member.level, member.vip_level, \ self.__id, _guild_num, self.__exp, WAY_ALLIANCE_HALL_CONTRIBUTE_IDS[contribute_id], '') if _persion_num > 0: syslogger(LOG_CONTRIBUTE_GET, member.cid, member.level, member.vip_level, self.__id, \ _persion_num, member.contribution, member.contribution_total, WAY_ALLIANCE_HALL_CONTRIBUTE_IDS[contribute_id], '') defer.returnValue( (self.__exp, member.contribution, member.contribution_total, left_golds, left_credits) )
def payment(request): ''' @param: charge_id-充值交易ID ''' request.setHeader('Content-Type', 'application/json;charset=UTF-8') args_data_raw = request.args['args'] #log.info("[ payment ]args raw:{0}.".format(args_data_raw)) if 0 == len(args_data_raw): log.error("[ payment ]unknown args raw:{0}.".format(args_data_raw)) defer.returnValue(json.dumps(GM_INVALID_CMD)) cmd_info = json.loads(args_data_raw[0]) if len(cmd_info) != 9: log.err("[ payment ]unknown cmd_info:{0}.".format(args_data_raw[0])) defer.returnValue(json.dumps(GM_INVALID_CMD)) account, charge_id, server_id, platform_id, parent_id, currency_type, currency, t, sign = cmd_info log.info( '[ payment ]account:{0}, charge_id:{1}, platform_id:{2}, parent_id:{3}, currency_type:{4}, currency:{5}, t:{6}, sign:{7}, server_id:{8}' .format(account, charge_id, platform_id, parent_id, currency_type, currency, t, sign, server_id)) #Check base_gm_sign later sign_local = base_gm_sign(*cmd_info[:-1]) if sign != sign_local: log.error("[ payment ]unknown sign:{0}, correct sign:{1}.".format( sign, sign_local)) defer.returnValue(json.dumps(GM_INVALID_SIGN)) try: res_login = yield server_login_user('%s%s' % (account, server_id)) except Exception as e: log.error("[ payment ]unknown error, e: {0}.".format(e)) defer.returnValue(json.dumps(GM_EXECUTE_FAIL)) err_login, cid = res_login if 0 != err_login: log.error( "[ payment ]unknown error. account:{0}, cid:{1}, error no:{2}.". format(account, cid, err_login)) defer.returnValue(json.dumps(GM_LOGIN_USER_FAIL)) try: res_data, credits_data = yield gs_call( "payment_from_platfrom", (cid, '', charge_id, platform_id, parent_id, currency_type, currency)) if not res_data: _user = g_UserMgr.getUserByCid(cid) if _user: send2client(cid, 'sync_credits_added', credits_data[1:]) log.info('[ payment ] credits_data: {0}.'.format(credits_data)) else: log.error( '[ payment ]result from gameserver. res_data:{0}.'.format( res_data)) defer.returnValue(json.dumps(res_data)) except Exception, e: log.exception( "[ payment ]gs_call error. account:{0}, charge_id:{1}, platform_id:{2}, parent_id:{3}, currency_type:{4}, currency:{5}" .format(account, charge_id, platform_id, parent_id, currency_type, currency)) defer.returnValue(json.dumps(GM_EXECUTE_FAIL))
def login(p, req): cid, = req p.cid = cid r = yield gs_call('gs_login', cid) raise Return(r)
#Check gm_sign sign_local = heitao_gm_sign(cmd, ts, args) if sign != sign_local: sign_local = base_gm_sign(cmd, ts, args) if sign != sign_local: log.error('Sign does not match! req {0}, local {1}'.format( sign, sign_local)) res_err['result'] = GM_INVALID_SIGN defer.returnValue(json.dumps(res_err)) try: args = json.loads(args) if gm_cmd_route.has_key(cmd): func = gm_cmd_route[cmd] res_data = yield func(cmd, ts, args, sign) #log.info('For Test. request cmd: {0}, res of data: {1}.'.format( cmd, res_data )) elif gs_gm_cmd_route.has_key(cmd): res_data = yield gs_call('gs_gm_%s' % cmd, (args, )) else: log.error('Invalid cmd : {0}.'.format(cmd)) res_err['result'] = GM_INVALID_CMD defer.returnValue(json.dumps(res_err)) defer.returnValue(json.dumps(res_data, cls=DecimalEncoder)) except Exception as e: log.error('Unknown error. e:{0}, req_args:{1}.'.format(e, req_args)) log.exception() res_err['result'] = GM_INVALID_ERROR defer.returnValue(json.dumps(res_err))
def htpayment(request): ''' @param: charge_id-充值交易ID ''' request.setHeader('Content-Type', 'application/json;charset=UTF-8') log.info('[ payment ] request.args: {0}.'.format(request.args)) res_err = {'result': 1, 'extend': ''} if len(request.args) != 6: log.error("[ payment ] unknown args: {0}.".format(request.args)) res_err['result'] = -PAYMENT_ARGS_ERROR defer.returnValue(json.dumps(res_err)) charge_id = int(request.args['order'][0]) orderno = request.args['transaction'][0] account = request.args['user'][0] server_id = request.args['server'][0] amount = request.args['amount'][0] sign = request.args['salt'][0] repeat_flag, new_flag = yield load_data(orderno) log.info('repeat_flag: {0}, new_flag: {1}.'.format(repeat_flag, new_flag)) if repeat_flag: log.error("[ payment ] repeat orderno. args: {0}.".format( request.args)) res_err['result'] = -PAYMENT_ORDERNO_REPEAT defer.returnValue(json.dumps(res_err)) if new_flag: yield new_data([ orderno, account, 0, server_id, amount, charge_id, datetime.now(), 0, 0 ]) log.info( '[ payment ] charge_id:{0}, orderno:{1}, account:{2}, server_id:{3}, amount:{4}.' .format(charge_id, orderno, account, server_id, amount)) #Check sign sign_local = check_sign(charge_id, orderno, account, server_id, amount, '2481ba98a91fca6') sign_local = sign_local[3:28] log.info("[ payment ] sign:{0}, sign_local:{1}.".format(sign, sign_local)) if sign != sign_local: log.error("[ payment ] unknown sign:{0}, sign_local:{1}.".format( sign, sign_local)) res_err['result'] = -PAYMENT_SIGN_ERROR defer.returnValue(json.dumps(res_err)) try: err_login, cid = yield server_login_user('%s%s' % (account, server_id)) except Exception as e: log.error( "[ htpayment ] unknown error, account: {0}, e: {1}, args: {2}.". format(account, e, request.args)) res_err['result'] = -PAYMENT_USER_ERROR defer.returnValue(json.dumps(res_err)) if err_login or (not cid): log.error( '[ payment ] unknown account: {0}, cid: {1}, args: {2}.'.format( account, cid, request.args)) res_err['result'] = -PAYMENT_USER_ERROR defer.returnValue(json.dumps(res_err)) # 预留的参数 platform_id, parent_id, currency_type, currency = 1, 1, 1, 0 try: res_data, credits_data = yield gs_call( "payment_from_platfrom", (cid, orderno, charge_id, platform_id, parent_id, currency_type, currency)) if not res_data: send2client(cid, 'sync_credits_added', credits_data[1:]) # update sql data yield update_data([cid, datetime.now(), credits_data[0], orderno]) else: log.error( '[ payment ]result from gameserver. res_data:{0}, args: {1}.'. format(res_data, request.args)) res_err['result'] = -PAYMENT_FAIL defer.returnValue(json.dumps(res_err)) except Exception, e: log.exception( "[ payment ]gs_call error. account:{0}, charge_id:{1}, platform_id:{2}, parent_id:{3}, currency_type:{4}, currency:{5}, args:{6}." .format(account, charge_id, platform_id, parent_id, currency_type, currency, request.args)) res_err['result'] = -PAYMENT_FAIL defer.returnValue(json.dumps(res_err))