def roll_broadcast(request, template='game/roll_broadcast.html'): '''滚动公告 ''' server_id = int(request.REQUEST.get('server_id', '') or 0) group_servers_dict = get_group_servers_dict(request) select_server_ids = [server_id] try: if server_id: gmp = GMProtocol(server_id) #server_time = gmp.query_server_time()[0] if request.method == 'POST': json_msg = request.REQUEST.get('msg', '') msg = json.loads(json_msg) _r = {"code": -1, "msg": ""} if request.REQUEST.get('req_type', '') == 'roll_broadcast_del': result = gmp.roll_broadcast_del(msg) else: msg[0]["bc"] = msg[0]["bc"].replace("<br />", "") result = gmp.roll_broadcast_set(msg) _r['code'] = result _r['msg'] = gmp.rsp_map.get(result, result) gmp.save_log(request.admin.id, gmp.req_type, _r['code'], remark1='remark', remark2=json_msg) return HttpResponse(json.dumps(_r)) else: roll_broadcasts = gmp.roll_broadcast_query() server_model = Server.objects.get(id=server_id) else: the_user = request.admin server_list = the_user.get_resource("server").all() # 返回所有正在滚动的公告 roll_broadcasts = [] # for g,servers in group_servers_dict.items(): # for s in servers: for s in server_list: gmp = GMProtocol(s.id) result = gmp.roll_broadcast_query() if result: for i in range(len(result)): result[i]['serverId'] = s.id result[i]['serverName'] = s.name roll_broadcasts.extend(result) # gmp = GMProtocol(7) # roll_broadcasts = gmp.roll_broadcast_query() # print roll_broadcasts # if roll_broadcasts: # roll_broadcasts[0]['serverId'] = 7 # roll_broadcasts[0]['serverName'] = 'test' # server_model = Server.objects.get(id=7) except: err_msg = trace_msg() return render_to_response(template, locals())
def server_info(request, server_id=0): server_id = int(request.REQUEST.get('server_id', '') or 0) if server_id: try: gmp = GMProtocol(server_id) gmp.time_out = 10 server_params = gmp.get_server_param() except: err_msg = '%s' % trace_msg() default_params = json.dumps(SERVER_PARAM_MAP, ensure_ascii=True) group_servers_dict = get_group_servers_dict(request) return render_to_response('game/server_info.html', locals())
def role_edit(request, id=0): '''角色编辑 ''' id = int(request.REQUEST.get('id', '0')) is_copy = request.REQUEST.get('copy','') resource = {} if id : role = request.admin.get_resource('role').get(id=id) if is_copy: role.name = '%s-copy' % role.name else: role = Role() role.id = id roles = request.admin.get_resource('role').exclude(id=role.id) menus = MenuTree(request.admin.get_resource('menu').all().order_by('parent_id')).get_list_record() agent_channels_dict = get_agent_channels_dict(request) group_servers_dict = get_group_servers_dict(request) platforms = request.admin.get_resource('platform') return render_to_response('system/role_edit.html',locals())
def gm(request, gm_id=0, template='game/gm_form.html'): '''GM 接口 ''' gm_id = gm_id or int(request.REQUEST.get('gm_id', '') or 0) server_id = int(request.REQUEST.get('server_id', '') or 0) is_ajax = request.REQUEST.get('is_ajax', '') or request.is_ajax() input_params = request.POST err_msg = result = '' now_time_str = get_now_str() def_params = {} def_result = {} try: gm_def = GMDefine.objects.get(id=gm_id) def_result = gm_def.def_result def_params = gm_def.def_params print def_params if gm_def.result_type == 'from': template = 'game/gm_from.html' if request.method == 'POST' or gm_def.result_type == 'msg': template = 'game/gm_post.html' other_templates = [ 'game/%s.html' % t for t in def_result.get('templates', '').split(',') if t ] if server_id: gmp = GMProtocolProxy(server_id, gm_def, def_result, def_params) gmp.input_params_handle(input_params) result = gmp.get_result() except GMDefine.DoesNotExist: err_msg = 'GM协议未定义' except: err_msg = trace_msg() result = {"code": -1, "msg": "%s" % err_msg} if not is_ajax: group_servers_dict = get_group_servers_dict(request) select_server_ids = [server_id] else: return HttpResponse(json.dumps(result)) return render_to_response(template, locals())
def flash_sale_pilot_edit(request, template_path='game/flash_sale_pilot_edit.html'): '''修改限时抢购武将 ''' print request.REQUEST _r = {'code': -1, 'msg': ''} ty = int(request.REQUEST.get('ty', '0')) sid = int(request.GET.get('sid', '0')) server_id = int(request.POST.get('server_id', '0')) msg_json = request.POST.get('msg', '0') context = {} context["group_servers_dict"] = get_group_servers_dict(request) result = '' if sid: try: gmp = GMProtocol(sid) result = gmp.get_flash_sale_pilot() except Exception, e: print e
def send_msg(request, server_id=0): '''发送消息 ''' player_id = int(request.REQUEST.get('player_id', 0)) server_id = int(request.REQUEST.get('server_id', 0)) player_name = request.REQUEST.get('player_name', '') msg_type = int(request.REQUEST.get('msg_type', '') or 0) usm = request.admin server_list = request.admin.get_resource('server') err_msg = '' if request.method == 'POST': msg_content = request.POST.get('content', '').encode('utf-8') remark2 = '' user_server_list = [s.id for s in server_list] if not user_server_list.__contains__(server_id): return HttpResponse(u'没有权限') try: if msg_content: gmp = GMProtocol(server_id) if msg_type == 1: #全服 player_id = 0 remark2 = request.REQUEST.get('cause', '') result = gmp.send_msg(msg_content, player_name) err_msg = gmp.rsp_map.get(result, result) gmp.save_log(request.admin.id, gmp.req_type, result, role_name=player_name, remark1=msg_content, remark2=remark2) else: err_msg = '没有填写消息!' except: err_msg = trace_msg() return render_to_response('feedback.html', locals()) if not player_id: group_servers_dict = get_group_servers_dict(request) return render_to_response('game/send_msg.html', locals())
def group_edit(request, model_id=0): model_id = int(model_id) if model_id == 0: model_id = int(request.GET.get('model_id', '0')) model = None if model_id > 0: model = Group.objects.using('read').get(id=model_id) if model == None: model = Group() model.id = 0 model.other = '' list_notice = Notice.objects.using('read').filter(notice_type=3) parg = {} parg["models"] = model parg["group_servers_dict"] = get_group_servers_dict(request) parg["select_server_ids"] = [s.id for s in model.server.all()] parg["list_notice"] = list_notice ######PID列表##### pid_list = parg["models"].pid_list try: if pid_list and pid_list != 'None': pid_list = eval(pid_list) parg["model"].pid_list = ','.join(pid_list) r = {} o = DictDefine.objects.filter(key='gid_pid') _r = o[0].get_dict() if pid_list: for i in pid_list: if i in _r: r[i] = _r[i] parg["pids_dict"] = r except Exception, e: print e
def shop_daily_save(request): import urllib ''' 每日限购保存 ''' MIN_ITEM_ID = 10000 server_id = int(request.GET.get('server_id', 0)) usm = request.admin server_ids = request.POST.getlist('server_id') server_ids = list(set([int(i) for i in server_ids])) item_id = request.POST.get('item_id', 0) item_name = request.POST.get('item_name', '') item_desc = request.POST.get('item_desc', '') # 处理 % 符号 item_desc = urllib.quote(item_desc.encode('utf-8')) item_type = int(request.POST.get('item_type', 0)) content = int(request.POST.get('content', 0)) currency = int(request.POST.get('currency', -1)) tag = request.POST.get('tag', '') discount = int(request.POST.get('discount', 10)) price = float(request.POST.get('price', 0)) limit_num = int(request.POST.get('limit_num', 0)) limit_vip = int(request.POST.get('limit_vip', 0)) limit_rank = int(request.POST.get('limit_rank', 0)) begin_time = request.POST.get('begin_time', '0') end_time = request.POST.get('end_time', '0') reward_desc = json.loads(request.POST.get('reward_desc', '')) output_path = request.POST.get('output_path', '') level_ratio = json.loads(request.POST.get('level_ratio', '')) res_info = convert_res_info(reward_desc, level_ratio) if begin_time and end_time: begin_time = datetime_to_timestamp(begin_time) end_time = datetime_to_timestamp(end_time) elif not begin_time and not end_time: begin_time = 0 end_time = 0 else: return HttpResponse("日期错误") ishot = False if tag and tag == "ishot": ishot = True discount = 10 elif discount not in range(1, 11): return HttpResponse('折扣数据非法') item = [ None, item_name, item_desc, content, currency, ishot, price, item_type, discount, limit_num, limit_vip, limit_rank, begin_time, end_time, reward_desc, output_path, level_ratio ] allow_create = True # 权限判断 //如果不是管理员账号 if not usm.is_manager: user_server_list = usm.get_resource( 'server').all() # 获取当前登陆的管理员账号有权限管理的服务器列表 user_server_id = [] for user_server in user_server_list: user_server_id.append(user_server.id) if not allow_create: return HttpResponse('没有权限添加') if server_ids: for new_server_id in server_ids: gmp = GMProtocol(new_server_id) if new_server_id == server_id and item_id: item_id = int(item_id) else: # 添加商品ID _s, _p = gmp.get_shop_list(1) shop_list, _p = gmp.get_shop_list(_p) item_ids = [i[0] for i in shop_list] item_id = max(max(item_ids), MIN_ITEM_ID) + 1 item[0] = item_id msg = [ item, ] try: result = gmp.set_shop_list(msg) except: return HttpResponse('{"code":1, "data": "添加出错"}') else: if len(result) > 1 and not result[1]: return HttpResponse('{"code":1, "data": "添加出错"}') server_time = None if server_id != 0: gmp = GMProtocol(server_id) server_time = gmp.query_server_time()[0] template_path = 'game/shop_daily_edit.html' context = {} item[2] = urllib.unquote(item[2]) context["item"] = item context["item_id"] = item_id context["res_info"] = res_info context["server_id"] = server_id context["server_time"] = server_time context["group_servers_dict"] = get_group_servers_dict(request) context["select_server_ids"] = server_ids ajax = request.GET.get('ajax', '') if ajax: return HttpResponse('{"code":0}') return render_to_response(template_path, context)
try: gmp = GMProtocol(server_id) server_time = gmp.query_server_time()[0] shop_list, page_sum = gmp.get_shop_list(page_num) item = [i for i in shop_list if i[0] == item_id][0] res_info = convert_res_info(item[14], item[16]) except Exception, e: err_msg = trace_msg() context = {} context["item_id"] = item_id context["item"] = item context["res_info"] = res_info context["server_id"] = server_id context["server_time"] = server_time context["group_servers_dict"] = get_group_servers_dict(request) context["select_server_ids"] = [server_id] template_path = 'game/shop_daily_edit.html' return render_to_response(template_path, context) @Route() def shop_daily_save(request): import urllib ''' 每日限购保存 ''' MIN_ITEM_ID = 10000 server_id = int(request.GET.get('server_id', 0))
def pay_result_list(request, table_name=''): page_size = 50 page_num = int(request.GET.get('page_num', '1')) key = request.GET.get('key', '') pay_type = int(request.GET.get('pay_type', '0')) server_id = int(request.GET.get('server_id', '') or 0) key_type = int(request.GET.get('key_type', '0')) #**支付通道列表 *** payChannel_record = {} payChannel_list = PayChannel.objects.all() for payChannel in payChannel_list: payChannel_record[payChannel.id] = payChannel.name #***支付通道列表 END list_record = [] pay_status = int(request.GET.get('status', '0')) list_server = request.admin.get_resource('server').all() server_ids = [s.id for s in list_server] query = Q() if server_id > 0 and server_id in server_ids: server_ids = [server_id] query = query & Q(server_id__in=server_ids) if pay_type > 0: query = query & Q(pay_type=pay_type) if pay_status != 0 and pay_status != -4: query = query & Q(pay_status=pay_status) if pay_status == -4: query = query & Q(pay_status__lt=2) if key != '': if key_type == 0: query = query & Q(query_id=key) elif key_type == 1: query = query & Q(pay_user=key) elif key_type == 2: query = query & Q(order_id=key) elif key_type == 3: query = query & Q(card_no=key) elif key_type == 4: query = query & Q(remark__contains=key) if 'old' == table_name: PayAction._meta.db_table = 'pay_action_old' else: PayAction._meta.db_table = 'pay_action' if not request.admin.is_root: channel_ids = request.admin.get_resource('channel').all().values_list( 'id', flat=True) query = query & Q(channel_id__in=channel_ids) group_id = int(request.GET.get('group_id', 0)) total_record = PayAction.objects.filter(query).count() if total_record > 0: list_record = PayAction.objects.filter(query)[(page_num - 1) * page_size:page_num * page_size] itemServerList = {} for item in list_server: itemServerList[item.id] = item.name for item in list_record: item.playerName = '' item.pay_type_name = payChannel_record.get(item.pay_type, '') item.server_name = itemServerList.get(item.server_id, '--') parg = {} group_servers_dict = get_group_servers_dict(request) status = pay_status return render_to_response('pay/pay_list.html', locals())
def dict_list(request): list_record = DictDefine.objects.using('read').all() group_servers_dict = get_group_servers_dict(request) return render_to_response('log/dict_list.html', locals())
offset = (page_num - 1) * page_size if not _sort_condition: _sort_condition = [("olt", -1)] #默认最后登录时间 _list = mongo_conn[db_name].tk.player.find(condition_country).sort( _sort_condition).skip(offset).limit(page_size) player_list = player_list_handle(ths, _list) mongo_conn.close() except Exception, e: traceback.print_exc() err_msg = str(e) #print country_code sort_condition = [] for c in _sort_condition: sort_condition.append(c + (condition_map.get(c[0], ''), )) group_servers_dict = get_group_servers_dict(request) player_info_map = PLAYER_INFO_MAP country_map_list = sorted(PLAYER_INFO_MAP['nat']['dict'].iteritems(), key=lambda x: x[0]) return render_to_response('game/player_list.html', locals()) 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)
def _player_list(request, server_id=0): '''玩家列表 ''' page_size = 30 page_num = int(request.GET.get("page_num", "1")) is_block = int(request.GET.get("block", 0)) group_id = int(request.GET.get("group_id", 0)) post_back = int(request.GET.get('post_back', '0')) list_group = center_cache.get_group_list() if (page_num < 1): page_num = 1 the_user = request.admin list_channel = center_cache.get_channel_list() itemChannelList = {} for item in list_channel: itemChannelList[item.id] = item.name list_group_server = [] if group_id != 0: list_group_server = center_cache.get_group_server_list(group_id) if request.admin.is_root: list_server = center_cache.get_server_list() else: list_server = center_cache.get_user_server_list(the_user) tmp_list_server = [] if 0 != list_group_server.__len__(): for item in list_group_server: if list_server.__contains__(item): tmp_list_server.append(item) list_server = tmp_list_server itemServerList = {} for item in list_server: itemServerList[item.id] = item.name player_key = request.GET.get('key', '') key_type = request.GET.get('key_type', '0') user_type = int(request.GET.get('user_type', '-1')) channel_id = int(request.session.get('channelId', '0')) server_id = int(request.GET.get("server_id", "0")) if server_id <= 0: server_id = int(request.session.get("serverId", "0")) # if server_id<=0 and len(list_server)>0: # server_id=list_server[0].id player_keys = [player_key] if key_type == '0' and player_key: if ',' in player_key: player_keys = [x.strip() for x in player_key.split(',') if x] if server_id <= 0: server_id = int(player_keys[0]) >> 20 #账号状态 status_condition = 0 if is_block == 1: status_condition = -1 total_record = 0 player_list = [] player_list1 = [] if 0 != post_back and server_id > 0: conn = getConn(server_id) cursor = conn.cursor() query = [] query.append("status=%d" % status_condition) if channel_id > 0: query.append('channel_id=%d' % channel_id) if player_key != "": if key_type == '0': query.append('player_id in (%s)' % ','.join(player_keys)) elif key_type == '1': query.append('player_name like \'%s%%\'' % player_key.encode('utf-8')) elif key_type == '2': query.append('link_key=\'%s\'' % player_key) elif key_type == '3': query.append('mobile_key=\'%s\'' % player_key) if user_type > -1: query.append('user_type=%d' % player_key) if not request.admin.is_root: channel_count = request.admin.get_resource('channel').count() if request > 0: channel_list = request.admin.get_resource('channel') channel_id_list_query = ' channel_id in (%s) ' % ','.join( [str(item.id) for item in channel_list]) query.append(channel_id_list_query) if len(query) > 0: sql1 = 'select count(1) from player_%d where %s' % ( server_id, ' and '.join(query)) sql2 = 'select player_id,player_name,channel_id,user_type,link_key,login_num,mobile_key,last_time,create_time,status from player_%d where %s order by id desc limit %d,%d' % ( server_id, ' and '.join(query), (page_num - 1) * page_size, page_size) else: sql1 = 'select count(1) from player_%d' % server_id sql2 = 'select player_id,player_name,channel_id,user_type,link_key,login_num,mobile_key,last_time,create_time,status from player_%d order by id desc limit %d,%d' % ( server_id, (page_num - 1) * page_size, page_size) print(sql1, sql2) cursor.execute(sql1) count_list = cursor.fetchone() total_record = int(count_list[0]) if total_record > 0: cursor.execute(sql2) player_list1 = cursor.fetchall() user_type_name = { 0: '游爱', 1: '当乐', 2: 'UC', 3: '91', 4: '云游', 5: '飞流', 6: '乐逗', 8: '小虎', 9: '4399', 10: 'facebook', 11: 'qq' } for item in player_list1: item = list(item) item[2] = itemChannelList.get(int(item[2]), item[2]) item[3] = user_type_name.get(int(item[3]), item[3]) player_list.append(item) cursor.close() parg = {} parg["server_id"] = server_id parg["list_group"] = list_group parg["list_server"] = list_server parg["player_key"] = player_key parg["player_list"] = player_list parg["is_block"] = is_block parg['key_type'] = key_type parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record group_servers_dict = get_group_servers_dict(request) agent_channels_dict = get_agent_channels_dict(request) return render_to_response('player/player_list.html', locals())
def battle_server_time(request, template='game/battle_server_time.html'): server_id = int(request.REQUEST.get('server_id', '') or 0) server_time = diff_time = 0 if server_id: group_servers_dict = get_group_servers_dict(request) gmp = GM_battleProtocol(server_id) result = gmp.query_battle_server_time() server_time = result[0] diff_time = result[2] if request.method == 'POST': modify_time = request.REQUEST.get('modify_time', '') server_time_str = request.REQUEST.get('server_time_str', '') if server_time_str and modify_time: modify_timestamp = datetime_to_timestamp(modify_time) server_timestamp = datetime_to_timestamp(server_time_str) add_sec = modify_timestamp - server_timestamp add_sec = 0 if add_sec < 0 else add_sec # day = int(request.REQUEST.get('day','') or 0) # hour = int(request.REQUEST.get('hour','') or 0) # minute = int(request.REQUEST.get('minute','') or 0) # sec = int(request.REQUEST.get('sec','') or 0) # add_sec = day * 86400 + hour * 3600 + minute * 60 + sec if add_sec >= 10 * 86400: err_msg = '嘿嘿嘿 增加时间不能大于 10天!' else: result = gmp.add_battle_server_time(add_sec) # server_time = result[0] # diff_time = result[2] info_msg = '成功!' if server_time else '失败!' kid = request.REQUEST.get('kid', '') sids = request.REQUEST.get('sids', '') if sids: sids = json.loads(sids) if kid and len(sids) > 0: _r = {'success': [], 'failed': []} for s in sids: try: gmp = GMProtocol(s) stime_res = gmp.query_server_time() sid_time = stime_res[0] dif_time = server_time - sid_time result = -1 while 1: if dif_time >= 10 * 86400: _dif_time = 10 * 86300 try: result = gmp.add_server_time(_dif_time) except: break dif_time = dif_time - _dif_time else: result = gmp.add_server_time(dif_time) break if result == 0: _r['success'].append(s) else: _r['failed'].append(s) except Exception, e: print trace_msg() _r['failed'].append(s) pass return HttpResponse(json.dumps(_r)) else: server_time = result[0] diff_time = result[2] real_time = server_time - diff_time add_day = diff_time / 86400 add_hour = (diff_time % 86400) / 3600 add_minute = ((diff_time % 86400) % 3600) / 60 add_second = ((diff_time % 86400) % 3600) % 60
def activity_manage(request, template="game/activity_manage.html"): server_ids = request.REQUEST.getlist('server_id') server_ids = list(set(server_ids)) if server_ids else [] server_ids = [int(i) for i in server_ids] activity_type = request.REQUEST.get('activity_type', u'7天乐活动') query_type = request.REQUEST.get('query_type', None) query_type_dict = { u'status': u'按活动状态分类', u'id': u'按活动ID分类', u'type': u'查看当前活动(单服)', u'temp': u'查看当前模版活动' } table_head = [] results = {} server = None for server_id in server_ids: try: server = Server.objects.filter(id=server_id).first() gmp = GMProtocol(server_id) server_time = gmp.query_server_time()[0] results[server] = get_activity_status(activity_type, server, server_time, query_type) except Exception: err_msg = trace_msg() activity_data = {} if query_type == 'status': table_head = ['活动ID', '开始时间', '结束时间', '活动状态', '服务器'] for server, result in results.iteritems(): cur = result.get('cur') nor = result.get('nor') for i in cur: activity_data.setdefault(i, {}).setdefault(u'正在进行', []).append(server) for i in nor: activity_data.setdefault(i, {}).setdefault(u'尚未开启', []).append(server) elif query_type == 'id': table_head = ['活动ID', '开始时间', '结束时间', '服务器'] for server, result in results.iteritems(): results[server] = [] results[server].extend(result['cur']) results[server].extend(result['nor']) for server, ids in sorted(results.iteritems()): for i in ids: activity_data.setdefault(i, []).append(server) elif query_type == 'temp': table_head = ['活动类型', '显示开始', '活动开始', '活动结束', '显示结束'] res = gmp.get_temp_activity() res_obj = {} res_obj[res[0]] = res[1:5] res_obj[res[6]] = res[7:11] res_obj[res[12]] = res[13:17] res_obj[res[18]] = res[19:23] else: table_head = ['活动类型', '活动ID'] if server and results: cur = results[server].get('cur') for i in cur: ac_type = Activity.objects.filter(id=i['aid']).first().type if ac_type not in activity_data: activity_data[ac_type] = [] activity_data[ac_type].append(i) model = get_activity_model(request) select_server_ids = server_ids group_servers_dict = get_group_servers_dict(request) return render_to_response(template, locals())