def player_list_handle(ths, player_list): '''玩家列表处理 ''' _player_list = [] for p in player_list: if p.get('pc', ''): p['pc'] = timestamp_to_datetime_str(p['pc'] + time.timezone) if p.get('olt', ''): p['olt'] = timestamp_to_datetime_str(p['olt'] + time.timezone) p['of'] = OFFICAL.get(str(p['of']), p['of']) # if p.get('rg',''): # vip_level = filter(lambda x:p['rg']>x,VIP_PRICE).__len__() # p['rg'] = '%s (VIP:%s)' % (p['rg'],vip_level) p['nat'] = '%s(%s)' % (PLAYER_INFO_MAP['nat']['dict'].get( p.get('nat', -1), '没有'), p.get('nat')) _player_list.append(p) return _player_list
def player_list(request): '''玩家列表 ''' server_id = int(request.REQUEST.get('server_id', '') or 0) player_id = int(request.REQUEST.get('player_id', '') or 0) single = request.REQUEST.get("type", "") query_name = '玩家角色管理' charge_map = DictDefine.get_dict_for_key("recharge_type") request.POST.setlist("charge_map", charge_map.values()) print '玩家角色管理', request.POST.getlist('server_id', '') request.has_shutup = True if server_id: shutup_player_list = {} gmp = GMProtocol(server_id) result = gmp.player_shutup_list(0) resutl = json.dumps(result) for l in result[0]: try: timestamp_to_datetime_str(l[2]) except Exception as e: l[2] = l[1] + max_time shutup_player_list[l[0]] = [ timestamp_to_datetime_str(l[1]), timestamp_to_datetime_str(l[2]) ] player_ids = shutup_player_list.keys() if server_id and player_id and single == 'single': conn = Server.get_conn(server_id) cur = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor) sql = """select '',p.player_id,%s,p.player_name,CONVERT(IFNULL(pp.log_level,'1'),SIGNED) level,p.channel_id,p.other,p.user_type,p.link_key,p.login_num,p.mobile_key,p.last_time,p.last_ip,p.create_time,p.status , '' as action from player_%s p LEFT JOIN ( select log_user,MAX(log_level) as log_level from log_player_level group by log_user ) pp ON p.player_id=pp.log_user where player_id = %s""" % ( server_id, server_id, player_id) cur.execute(sql) player = cur.fetchone()[0] conn.close() if player: last_time = player["last_time"].strftime('%Y-%m-%d %H:%M:%S') create_time = player["create_time"].strftime('%Y-%m-%d %H:%M:%S') for t in Player.TYPE_CHOICES: if player["user_type"] == t[0]: user_type = t[1] for s in Player.STATUS_CHOICES: if player["status"] == s[0]: status = s[1] request.playerData = [[ "", player["player_id"], server_id, player["player_name"], player["level"], player["channel_id"], player["other"], user_type, player["link_key"], player["login_num"], player["mobile_key"], last_time, player["last_ip"], create_time, status, "" ]] def list_data_handle(list_data): new_list_data = [] for p in request.playerData: if p[1] in player_ids: new_list_data.append( list(p) + shutup_player_list.get(player_id, [0, 0])) if new_list_data: return new_list_data return request.playerData return query_view(request, query_name=query_name, list_data_handle=list_data_handle) if request.REQUEST.get('is_shutup', ''): try: player_ids = player_ids or [1] request.POST.setlist('player_id', player_ids) print shutup_player_list def list_data_handle(list_data): new_list_data = [] for row in list_data: player_id = row[1] new_list_data.append( list(row) + shutup_player_list.get(player_id, [0, 0])) return new_list_data return query_view(request, query_name=query_name, list_data_handle=list_data_handle) except: err_msg = trace_msg() return HttpResponse('{"code":-1,"msg":"%s"}' % err_msg) else: try: def list_data_handle(list_data): new_list_data = [] for row in list_data: player_id = row[1] if player_id in player_ids: new_list_data.append( list(row) + shutup_player_list.get(player_id)) else: new_list_data.append(list(row)) return new_list_data return query_view(request, query_name=query_name, list_data_handle=list_data_handle) except: err_msg = trace_msg() return HttpResponse('{"code":-1,"msg":"%s"}' % err_msg) return query_view(request, query_name)
def timestamp_to_datetime(value, _f='datetime'): try: _r = timestamp_to_datetime_str(int(value), _f) if value else '' except: _r = '' return _r
def server_active_cfg_list(request): _now = int(time.time()) g = lambda x, y: request.GET.get(x, request.POST.get(x, y)) status = int(g('status', '1')) sdate = g('sdate', '') edate = g('edate', '') page_num = int(g('page_num', '1')) _result_list = load_active_task_data() if sdate and edate: _sd = datetime_to_timestamp(sdate) _ed = datetime_to_timestamp(edate) else: sdate = edate = timestamp_to_datetime_str(_now) _sd = _ed = 0 result_list = [] for item in _result_list: _ststamp = datetime_to_timestamp(item['sdate']) _etstamp = datetime_to_timestamp(item['edate']) if _sd and _ed: #时间搜索 _is_append = (_ed > _ststamp > _sd) else: if status == 1: #活动中 _is_append = _now < _etstamp elif status == 2: #过期 _is_append = _now > _etstamp else: _is_append = True if _is_append: result_list.append(item) page_size = int(g('page_size', '20')) total_record = len(result_list) sp = (page_num - 1) * page_size result_list = result_list[sp:sp + page_size] list_len = result_list.__len__() param_dict = {} for p in get_server_param(): param_dict[p[0]] = p[1] i = 0 while list_len > i: k = 1 + i item1 = result_list[i] while list_len > (k): item2 = result_list[k] sdate1 = datetime.datetime.strptime(item1['sdate'], '%Y-%m-%d %H:%M:%S') info1 = item1['server_info'] edate1 = datetime.datetime.strptime(item1['edate'], '%Y-%m-%d %H:%M:%S') rev_info1 = item1['recover_server_info'] sdate2 = datetime.datetime.strptime(item2['sdate'], '%Y-%m-%d %H:%M:%S') info2 = item2['server_info'] edate2 = datetime.datetime.strptime(item2['edate'], '%Y-%m-%d %H:%M:%S') rev_info2 = item2['recover_server_info'] error_dict = {} def set_msg(p1, p2): for key1 in p1: value1 = p1.get(key1) value2 = p2.get(key1, None) if None != p2.get(key1, None) and value1 != value2: d = error_dict.get(i, {}) if None == d.get(key1, None): msg_list = item1.get('msg_list', []) msg = '%s(%s)' % (item2['title'].encode('utf-8'), param_dict.get(key1, '')) msg_list.append(msg) item1['msg_list'] = msg_list d[key1] = 1 error_dict[i] = d s1 = set([int(server_id) for server_id in item1["server_list"]]) s2 = set([int(server_id) for server_id in item2["server_list"]]) if (datetime.datetime.now() - edate1).days < 2 and (s1 & s2).__len__() != 0: if abs((sdate1 - sdate2).days) <= 1: set_msg(info1, info2) if abs((sdate1 - edate2).days) <= 1: set_msg(info1, rev_info2) if abs((edate1 - edate2).days) <= 1: set_msg(rev_info1, rev_info2) if abs((edate1 - sdate2).days) <= 1: set_msg(rev_info1, info2) k += 1 i += 1 return render_to_response('game/cfg_server_active_list.html', locals())