def members_train(context): """获取社团成员数据 """ ki_user = context.user uid = context.get_parameter("uid") group_id = ki_user.group.group_id if not judge_open_train(ki_user.sid, group_id): context.result['mc'] = MsgCode['UserModuleNotOpen'] return member_data = GroupService.get_member_info_by_uid(ki_user.sid, group_id, uid) # 检测目标是否在公会 if not member_data: context.result['mc'] = MsgCode['GroupMemberNotExist'] return user = User.get(uid) if not isinstance(user, User): context.result['mc'] = MsgCode['UserNotExist'] return else: data = {} data["state"] = user.group.train_list ids = [i for i in user.group.train_list if i not in [0,-1]] heros = {} group_data = GroupService.find(ki_user.sid, group_id) for hid in ids: heros[hid] = count_group_train_hero(hid, user, group_data["level"]) data["heros"] = heros context.result["data"] = data
def members_train(context): """获取社团成员数据 """ ki_user = context.user uid = context.get_parameter("uid") group_id = ki_user.group.group_id if not judge_open_train(ki_user.sid, group_id): context.result['mc'] = MsgCode['UserModuleNotOpen'] return member_data = GroupService.get_member_info_by_uid(ki_user.sid, group_id, uid) # 检测目标是否在公会 if not member_data: context.result['mc'] = MsgCode['GroupMemberNotExist'] return user = User.get(uid) if not isinstance(user, User): context.result['mc'] = MsgCode['UserNotExist'] return else: data = {} data["state"] = user.group.train_list ids = [i for i in user.group.train_list if i not in [0, -1]] heros = {} group_data = GroupService.find(ki_user.sid, group_id) for hid in ids: heros[hid] = count_group_train_hero(hid, user, group_data["level"]) data["heros"] = heros context.result["data"] = data
def judge_open_train(sid, group_id): """判断训练所是否开启 """ group_data = GroupService.find(sid, group_id) if group_data: gcfg = game_config.group_cfg.get(group_data["level"], {}) # return gcfg["open_train"] == 1 return True else: return False
def rank(cls, rtype, sid, start, end): """读取排行榜数据 rtype: 1 - 今日排名 2 - 总排名 3 - 英雄圣殿 4 - 昨日榜单 """ if rtype == WORLD_BOSS_RANK_YES: cache_rank_name = rediskey_config.WORLD_BOSS_DMG_YES_RANK_KEY % sid return redis_client.lrange(cache_rank_name, start - 1, end - 1) if rtype == WORLD_BOSS_RANK_TODAY: key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid elif rtype == WORLD_BOSS_RANK_TOTAL: key = rediskey_config.WORLD_BOSS_MAIN_KEY % sid version = redis_client.hget(key, "version") key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid, version) else: key = rediskey_config.WORLD_BOSS_HEROS_KEY % sid ranking_list = redis_client.zrevrange(key, start - 1, end - 1, withscores=True) ranks = [] for index, i in enumerate(ranking_list): rank_data = {} rank_data['rank'] = start + index + 1 rank_data['data'] = int(i[1]) user = User.get(i[0]) if isinstance(user, User): rank_data['name'] = user.name rank_data['level'] = user.game_info.role_level rank_data['group_name'] = GroupService.find( user.sid, user.group.group_id) ranks.append(rank_data) return ranks
def info(context): """训练所信息 """ ki_user = context.user group_id = ki_user.group.group_id if not judge_open_train(ki_user.sid, group_id): context.result['mc'] = MsgCode['UserModuleNotOpen'] return group_data = GroupService.find(ki_user.sid, group_id) gcfg = game_config.group_cfg.get(group_data["level"]) ids = [i for i in ki_user.group.train_list if i not in [0,-1]] data = {} data["hero_add_exps"] = sys_logic.handle_group_train_heros(ids, ki_user, gcfg["train_exp"]) data["state"] = ki_user.group.train_list data["info"] = ki_user.group.train_dict context.result["data"] = data
def info(context): """训练所信息 """ ki_user = context.user group_id = ki_user.group.group_id if not judge_open_train(ki_user.sid, group_id): context.result['mc'] = MsgCode['UserModuleNotOpen'] return group_data = GroupService.find(ki_user.sid, group_id) gcfg = game_config.group_cfg.get(group_data["level"]) ids = [i for i in ki_user.group.train_list if i not in [0, -1]] data = {} data["hero_add_exps"] = sys_logic.handle_group_train_heros( ids, ki_user, gcfg["train_exp"]) data["state"] = ki_user.group.train_list data["info"] = ki_user.group.train_dict context.result["data"] = data
def get(context): """获取排行榜数据 Args: rtype 排行榜类型 start 排行榜起始位置 end 排行榜结束位置 Returns: my_rank 我的名次 rank_datas 对应条件的排行榜数据 """ rtype = context.get_parameter("rtype") start = context.get_parameter("start") stop = context.get_parameter("stop") if rtype not in rank_service.RANK_KEY_MAPPING: context.result['mc'] = MsgCode['ParamIllegal'] return ki_user = context.user if rtype == 3: my_rank = rank_service.rank(ki_user.sid, rtype, "%s_%s" % (ki_user.uid, ki_user.hero.get_max_fight_hero())) elif rtype == 2: my_rank = rank_service.rank(ki_user.sid, rtype, ki_user.group.group_id) if not my_rank and ki_user.group.group_id: group_data = GroupService.find(ki_user.sid, ki_user.group.group_id) my_rank = _build_group_data_s2c(group_data, ki_user.sid) else: my_rank = rank_service.rank(ki_user.sid, rtype, ki_user.uid) rank_datas = rank_service.top(ki_user.sid, rtype, start, stop) data = {} data["my_rank"] = my_rank data["rank_datas"] = rank_datas context.result["data"] = data
def rank(cls, rtype, sid, start, end): """读取排行榜数据 rtype: 1 - 今日排名 2 - 总排名 3 - 英雄圣殿 4 - 昨日榜单 """ if rtype == WORLD_BOSS_RANK_YES: cache_rank_name = rediskey_config.WORLD_BOSS_DMG_YES_RANK_KEY % sid return redis_client.lrange(cache_rank_name, start-1, end-1) if rtype == WORLD_BOSS_RANK_TODAY: key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid elif rtype == WORLD_BOSS_RANK_TOTAL: key = rediskey_config.WORLD_BOSS_MAIN_KEY % sid version = redis_client.hget(key, "version") key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid, version) else: key = rediskey_config.WORLD_BOSS_HEROS_KEY % sid ranking_list = redis_client.zrevrange(key, start-1, end-1, withscores=True) ranks = [] for index,i in enumerate(ranking_list): rank_data = {} rank_data['rank'] = start + index + 1 rank_data['data'] = int(i[1]) user = User.get(i[0]) if isinstance(user, User): rank_data['name'] = user.name rank_data['level'] = user.game_info.role_level rank_data['group_name'] = GroupService.find(user.sid, user.group.group_id) ranks.append(rank_data) return ranks
def admin_query_player_info(cls, params): sid = params.get("sid") uid = params.get("uid", "") uname = params.get("uname", "") dtype = params.get("type", "user") from apps.models.user import User # uid为空 则根据uname查询玩家数据 if uid: target_user = User.get(uid) elif uname: target_uid = name_service.get_uid_by_name(uname) target_user = User.get(target_uid) else: target_user = None if not target_user: return {"mc": 900007} data = {} if str(dtype) == "user": user_attrs = ["uid","name","update_name_times","avatar", "user_sign","account_id","platform","sid", "state","type","create_time","last_request", "last_sign_time","total_login_days","login_history_dates", "used_cdkey_tags", "game_info", "ext_info"] elif str(dtype) == "hero": user_attrs = ["hero", "equip", "skill", "spirit"] elif str(dtype) == "group": attr_obj = eval("target_user.group") data["group"] = {} for attr1 in attr_obj.all_def_attrs: if attr1 not in ["uid"]: data["group"][attr1] = getattr(attr_obj, attr1) if not target_user.group.group_id: group = {} else: group = GroupService.find(target_user.sid, target_user.group.group_id) data["group_data"] = {} data["group_data"]["base"] = group data["uid"] = target_user.uid data["name"] = target_user.name data["mc"] = 900002 data["info"] = pickle.dumps(data) return data else: user_attrs = [dtype] for attr in user_attrs: if type(eval("target_user.%s" % attr)) in [unicode, str, int, dict, list, set, tuple]: data[attr] = eval("target_user.%s" % attr) else: attr_obj = eval("target_user.%s" % attr) data[attr] = {} for attr1 in attr_obj.all_def_attrs: if attr1 not in ["uid"]: data[attr][attr1] = getattr(attr_obj, attr1) data["uid"] = target_user.uid data["name"] = target_user.name data["mc"] = 900002 data["info"] = pickle.dumps(data) return data
def _fetch_group_name_by_id(sid, group_id): """ """ group_data = GroupService.find(sid, group_id) return group_data["name"] if group_data else ''
def _run_update_cached_group_rank(sid, tag): """更新公会排行榜 抓取所有公会数据 - 按等级排 - 按总战力排 - 存放进cache里 """ ranking_name = rediskey_config.RANK_KEY_PREFIX % (sid, tag) ranking_list = redis_client.zrevrange(ranking_name, 0, -1, withscores=True) group_rank = [] if ranking_list: for key, value in enumerate(ranking_list): rank_data = {} rank_data['rank'] = 0 rank_data['group_id'] = int(value[0]) rank_data['exp'] = int(value[1]) group_data = GroupService.find(sid, value[0]) if group_data: rank_data['name'] = group_data["name"] rank_data['icon'] = group_data["icon"] rank_data['level'] = group_data["level"] master = User.get(group_data["master"]) rank_data['master'] = master.name if isinstance(master, User) else "会长" rank_data['member_number'] = group_data["member_number"] rank_data['join_level_limit'] = group_data["join_level_limit"] rank_data['join_state'] = group_data["join_state"] rank_data['notice'] = group_data["notice"] fight = 0 for uid in [ member["uid"] for member in GroupService.members(sid, int(value[0])) if isinstance(member, dict) ]: try: user = User.get(uid) fight += user.game_info.fight except: fight += 0 rank_data['fight'] = fight group_rank.append(rank_data) def gsorted(x, y): if x["level"] == y["level"]: return y["fight"] - x["fight"] else: return y["level"] - x["level"] group_rank = sorted(group_rank, cmp=gsorted) a = 1 for x in group_rank: x['rank'] = a a += 1 # 放入排行缓存列表中 group_rank.reverse() cache_rank_name = rediskey_config.RANK_CACHE_KEY_PREFIX % (sid, tag) while redis_client.llen(cache_rank_name) != 0: redis_client.delete(cache_rank_name) time.sleep(1) # 放入排行缓存列表中 for rank in group_rank: redis_client.lpush(cache_rank_name, rank) print 'ranking_name:', cache_rank_name print 'ranking_list:', group_rank print '=' * 60
def _run_update_cached_group_rank(sid, tag): """更新公会排行榜 抓取所有公会数据 - 按等级排 - 按总战力排 - 存放进cache里 """ ranking_name = rediskey_config.RANK_KEY_PREFIX % (sid, tag) ranking_list = redis_client.zrevrange(ranking_name, 0, -1, withscores=True) group_rank = [] if ranking_list: for key, value in enumerate(ranking_list): rank_data = {} rank_data['rank'] = 0 rank_data['group_id'] = int(value[0]) rank_data['exp'] = int(value[1]) group_data = GroupService.find(sid, value[0]) if group_data: rank_data['name'] = group_data["name"] rank_data['icon'] = group_data["icon"] rank_data['level'] = group_data["level"] master = User.get(group_data["master"]) rank_data['master'] = master.name if isinstance(master, User) else "会长" rank_data['member_number'] = group_data["member_number"] rank_data['join_level_limit'] = group_data["join_level_limit"] rank_data['join_state'] = group_data["join_state"] rank_data['notice'] = group_data["notice"] fight = 0 for uid in [member["uid"] for member in GroupService.members(sid, int(value[0])) if isinstance(member, dict)]: try: user = User.get(uid) fight += user.game_info.fight except: fight += 0 rank_data['fight'] = fight group_rank.append(rank_data) def gsorted(x,y): if x["level"] == y["level"]: return y["fight"] - x["fight"] else: return y["level"] - x["level"] group_rank = sorted(group_rank, cmp=gsorted) a = 1 for x in group_rank: x['rank'] = a a += 1 # 放入排行缓存列表中 group_rank.reverse() cache_rank_name = rediskey_config.RANK_CACHE_KEY_PREFIX % (sid, tag) while redis_client.llen(cache_rank_name) != 0: redis_client.delete(cache_rank_name) time.sleep(1) # 放入排行缓存列表中 for rank in group_rank: redis_client.lpush(cache_rank_name, rank) print 'ranking_name:', cache_rank_name print 'ranking_list:', group_rank print '=' * 60