def channel_player_shutup(request, player_id=0): channel_id = int(request.session.get('channel_id', '0')) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) if channel_id != 0: #判断 是否在渠道后台中调用此函数 (是否有权限删除) server = Server.objects.using('read').get(id=server_id) the_db_config = json.loads(server.log_db_config) conn = MySQLdb.connect(host=the_db_config['host'], user=the_db_config['user'], passwd=the_db_config['password'], db=the_db_config['db'], charset="utf8") conn.autocommit(1) cursor = conn.cursor() #获得当前选择的服务器连接 sql = 'SELECT COUNT(0) FROM player_%d WHERE channel_id=%d ' % ( server_id, channel_id) cursor.execute(sql) total_record = int(cursor.fetchone()[0]) if 0 >= total_record: return HttpResponse('没有权限操作') if channel_id == 0: return HttpResponse("请登录渠道后台!") return player_shutup(request, player_id)
def player_shutup(request, player_id=0): req_type = 102 result_msgs = {-1: '未知错误', 0: '成功'} result_code = -1 if player_id == 0: player_id = int(request.GET.get('player_id', '0')) if player_id == 0: player_id = int(request.POST.get('player_id', '0')) is_ajax = request.GET.get('ajax', False) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) time_len = int(request.GET.get('time', '1800')) req_params = 'req_type=%d&player_id=%s&server_id=%d&time=%d' % ( req_type, player_id, server_id, time_len) err_msg = '' try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) if result['code'] == 0: result_code = result['content'][0] write_gm_log(request, [req_type, server_id, player_id, result_code, time_len]) except Exception, e: err_msg = '发生错误:%s!' % e
def seience_modify(request, player_id=0): if player_id == 0: player_id = int(request.GET.get('player_id', '0')) req_type = 131 result_msgs = {-1:'未知错误', 0:'成功', 1:'更新信息中存在不允许更新的布阵科技ID'} result_code = -1 #modify_science_info = json.dumps(request.POST) # modify_science_info = json.dumps(modify_science_info) log_param = {} request_param = do_filter_seience_param(request.POST, get_seience_info(player_id), log_param) request_param = json.dumps(request_param, ensure_ascii=False) log_param = json.dumps(log_param, ensure_ascii=False) err_msg = '' server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d&modify_science_info=%s' % (req_type, player_id, server_id, request_param) try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_PLAYER_URL, req_params, result) if result['code'] == 0: result_code = result['content'][0] write_gm_log(request, [req_type, server_id, player_id, result_code, log_param]) except Exception, e: err_msg = '发生错误:%s!' % e
def player_modify(request, player_id=0): if player_id == 0: player_id = int(request.GET.get('player_id', '0')) result_msgs = {-1: '未知错误', 0: '成功'} result_code = -1 server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) player_info = request.POST req_type = get_player_modify_PostType(player_info) #获取请求类别 source_player_info = get_player_info(player_id) #原有player数据 #player_info = {"nn":'hello', "uid":1, "pi":3} #source_player_info = {"nn":'hello2', "uid":2, "pi":3} err_msg = '' result_msg = '' append_gl = request.POST.get('append_gl', '') if append_gl != '': try: append_gl = float(append_gl) if append_gl >= 50000: err_msg = '金币修改最大5W' except Exception, ex: err_msg = '追加金不能超过50000' print 'player_modify error' print ex
def equip_del(request, player_id=0): req_type = 112 result_msgs = {-1: '未知错误', 0: '成功'} result_code = -1 if player_id == 0: player_id = int(request.GET.get('player_id', '0')) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) equip_id = int(request.GET.get('equip_id', '0')) err_msg = '' req_params = 'req_type=%d&player_id=%s&server_id=%d&equip_id=%s' % ( req_type, player_id, server_id, equip_id) try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) if result['code'] == 0: result_code = result['content'][0] write_gm_log(request, [req_type, server_id, player_id, result_code, equip_id]) except Exception, e: err_msg = '发生错误:%s!' % e
def equip_add(request, player_id=0): if player_id == 0: player_id = int(request.GET.get('player_id', '0')) req_type = 111 result_msgs = {-1: '未知错误', 0: '成功', 1: '增加列表存在不存在的装备ID'} result_code = -1 err_msg = '' server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) equip_id = int(request.POST.get('equip_id', '1')) equip_level = int(request.POST.get('equip_level', '0')) equip_num = int(request.POST.get('equip_num', '1')) req_params = 'req_type=%d&player_id=%s&server_id=%d&equip_list=[[%d,%d,%d]]' % ( req_type, player_id, server_id, equip_id, equip_level, equip_num) try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) if result['code'] == 0: result_code = result['content'][0] write_gm_log(request, [ req_type, server_id, player_id, result_code, '[%d,%d,%d]' % (equip_id, equip_level, equip_num) ]) except Exception, e: err_msg = '发生错误:%s!' % e
def get_seience_info(player_id): req_type = 3 server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d' % (req_type, player_id, server_id) result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) seience_info = {} if result['code'] == 0: seience_info = result['content'][0]['scl'] return seience_info
def get_data(player_id, req_type): server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d' % ( req_type, player_id, server_id) result = None try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=20) result = json.loads(result) if result['code'] == 0: result = result['content'][0] except: pass return result
def army_info(request, player_id=0, is_read=0): req_type = 2 def_params = { "rid": u"武将RAWID", "ia": u"是否在野", "glv": u"武将等级 ", "rnl": u"转生需求等级", "exp": u"武将当前经验 ", "slv": u"士兵星级 ", "scn": u"当前士兵数", "smn": u"默认最大士兵数", "aa": u"武将培养增加值", "ee": u"武将身上的装备", "ha": u"武将体力加成" } if player_id == 0: player_id = int(request.GET.get('player_id', '0')) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d' % ( req_type, player_id, server_id) list_infos = [] err_msg = '' try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_PLAYER_URL, req_params, result) if result['code'] == 0: player_info = result['content'][0]['rgl'] for item in player_info: item_info = [] for param in def_params: if item.get(param, None) != None: item_info.append(item.get(param)) list_infos.append(item_info) print(list_infos) except Exception, e: err_msg = '发生错误:%s!' % e
def equip_info(request, player_id=0, is_read=0): req_type = 5 def_params = { "id": u"装备ID", "rawId": u"装备原型ID", "generalName": u"装配武将", "level": u"装备等级", "attribute": u"属性", "mountlvl": u"战魂等级", "pieceNum": u"临时装备删除时间" } if player_id == 0: player_id = int(request.GET.get('player_id', '0')) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d' % ( req_type, player_id, server_id) list_infos = [] err_msg = '' try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_PLAYER_URL, req_params, result) if result['code'] == 0: player_info = result['content'][0]['equipList'] for item in player_info: item_info = [] for param in def_params: if item.get(param, None) != None: item_info.append(item.get(param)) else: item_info.append('') list_infos.append(item_info) print(list_infos) except Exception, e: err_msg = '发生错误:%s!' % e
def team_info(request, player_id=0): req_type = 7 def_params = [["createTime", u"创办时间", 0], ["creator", u"创办者ID", 0], ["creatorName", u"创办者姓名", 0], ["declaration", u"留言", 0], ["emblemLv", u"军徵等级", 0], ["kingdom", u"所属国家", 0], ["leader", u"当前领袖ID", 0], ["leaderName", u"当前领袖名字", 0], ["legionLv", u"军团等级", 0], ["name", u"军团名称", 0], ["legionId", u"军团ID", 0]] if player_id == 0: player_id = int(request.GET.get('player_id', 0)) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) legion_name = request.GET.get('legion_name', '') req_params = 'req_type=%d&player_id=%s&server_id=%d&legion_name=%s' % ( req_type, player_id, server_id, legion_name) list_infos = [] try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_PLAYER_URL, req_params, result) if result['code'] == 0: player_info = result['content'][0] for item in def_params: if player_info.get(item[0], None) != None: list_infos.append({ 'name': item[1], 'key': item[0], 'value': player_info.get(item[0]), 'is_modify': item[2] }) except Exception, e: err_msg = '发生错误:%s!' % e
def post(request): player_id = get_value(request, 'player_id', 0, int) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_type = 141 data = [] append_hunshi = get_value(request, 'append_hunshi', None, int) if None != append_hunshi: data.append(append_hunshi) else: data.append(0) for index in range(1, 21): #1 到 20 append_value = get_value(request, 'append_zhanhun_%s' % index, None, int) if None != append_value: data.append(append_value) else: data.append(0) try: request_param = json.dumps({"data": data}) req_params = 'req_type=%d&player_id=%s&server_id=%d&modify_battle_heart_info=%s' % ( req_type, player_id, server_id, request_param) print req_params result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) print result except Exception, ex: print ex return HttpResponse(ex)
def player_unshutup(request, player_id=0): if player_id == 0: player_id = int(request.GET.get('player_id', '0')) req_type = 103 result_msgs = {-1: '未知错误', 0: '成功'} result_code = -1 server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d' % ( req_type, player_id, server_id) err_msg = '' try: result = http_post(game_server_url.GM_PLAYER_URL, req_params) result = json.loads(result) print(game_server_url.GM_PLAYER_URL, req_params, result) if result['code'] == 0: result_code = result['content'][0] except Exception, e: err_msg = '发生错误:%s!' % e
def train_info(request, player_id=0, is_read=0): req_type = 4 def_params = { "gi": u"武将ID", "ft": u"训练结束时间", "tt": u"训练类型", "lu": u"最后更新时间" } #"pn":"训练位置","tl":"训练列表","hft":"突飞CD完成时间","hil":"突飞CD完成时间", if player_id == 0: player_id = int(request.GET.get('player_id', 0)) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d' % ( req_type, player_id, server_id) list_infos = [] err_msg = '' try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_PLAYER_URL, req_params, result) if result['code'] == 0: train_info = result['content'][0]['tl'] for item in train_info: item_info = [] for param in def_params: if item.get(param, None) != None: item_info.append(item.get(param)) list_infos.append(item_info) except Exception, e: err_msg = '发生错误:%s!' % e
def hero_add(request, player_id=0): req_type = 121 result_msgs = { -1: '未知错误', 0: '成功', 2: '玩家不存在', 3: '该英雄已可招募', 4: '不存在该ID的英雄' } result_code = -1 err_msg = '' hero_id = int(request.POST.get('hero_id', '0')) if player_id == 0: player_id = int(request.GET.get('player_id', '0')) if player_id == 0: player_id = int(request.POST.get('player_id', '0')) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d&hero_id=%s' % ( req_type, player_id, server_id, hero_id) try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) if result['code'] == 0: result_code = result['content'][0] write_gm_log(request, [req_type, server_id, player_id, result_code, hero_id]) except Exception, e: err_msg = '发生错误:%s!' % e
def build_info(request, player_id=0, is_read=0): req_type = 6 def_params = { 0: u"主城", 1: u"银库", 2: u"民居一", 3: u"民居二", 4: u"民居三", 5: u"民居四", 6: u"商店", 7: u"校场", 8: u"军机处", 9: u"粮仓", 10: u"市场", 11: u"兵营", 12: u"民居五", 13: u"民居六", 14: u"民居七", 15: u"账房", 16: u"民居八", 17: u"铸币厂", 18: u"民居九", 19: u"驿站", 20: u"钱庄", 21: u"民居十", 22: u"第二校场", 23: u"纺织局", 24: u"铁匠铺" } if player_id == 0: player_id = int(request.GET.get('player_id', '0')) server_id = int(player_id) >> 20 server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) req_params = 'req_type=%d&player_id=%s&server_id=%d' % ( req_type, player_id, server_id) list_infos = [] err_msg = '' try: result = http_post(game_server_url.GM_PLAYER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_PLAYER_URL, req_params, result) if result['code'] == 0: build_list = result['content'][0]['buildingList'] for item in build_list: if def_params.get(item['rawId'], None) != None: list_infos.append({ 'name': def_params.get(item['rawId'], '未知'), 'key': item['rawId'], 'value': item['level'], 'is_modify': 0 }) except Exception, e: err_msg = '发生错误:%s!' % e
def send_msg(request, server_id=0): server_id = int(server_id) player_id = int(request.GET.get('player_id', '0')) if player_id == 0: player_id = int(request.POST.get('player_id', '0')) if server_id == 0: server_id = int(request.GET.get('server_id', '0')) if server_id == 0: server_id = int(request.POST.get('server_id', '0')) usm = UserStateManager(request) server_list = [] if server_id == 0: if usm.current_userRole_is_root(): server_list = get_server_list() else: server_list = usm.get_the_user().server.all() err_msg = '' if request.method == 'POST': result_msgs = {-1: '未知错误', 0: '成功'} result_code = -1 if not usm.current_userRole_is_root(): the_user = usm.get_the_user() user_server_list = [] for server in the_user.server.all(): user_server_list.append(server.id) if not user_server_list.__contains__(server_id): return HttpResponse(u'没有权限') server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) msg_content = request.POST.get('content', '').encode('utf-8') try: if player_id > 0: if request.POST.get('msg_type', '0') == '0': req_type = 612 else: req_type = 616 req_params = 'req_type=%d&server_id=%d&reciver_id=%s&msg_content=%s' % ( req_type, server_id, player_id, msg_content) else: req_type = 611 net_id = request.GET.get('net_id', '-1') req_params = 'req_type=%d&server_id=%d&net_id=%s&msg_content=%s' % ( req_type, server_id, net_id, msg_content) result = http_post(game_server_url.GM_SERVER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_SERVER_URL, req_params, result) if result['code'] == 0: result_code = result['content'][0] write_gm_log( request, [req_type, server_id, player_id, result_code, msg_content]) except Exception, e: err_msg = '发生错误%s' % e #print(u'发生错误:%s' % e) result_msg = result_msgs.get(result_code, '') parg = {} parg["err_msg"] = err_msg parg["result_msg"] = result_msg return render_to_response('game/feedback.html', locals())