Example #1
0
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
Example #2
0
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  
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
        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)

    usm = None
    try:
        usm = UserStateManager(request)

        write_gm_log(
            request,
            [req_type, server_id, player_id, result['code'], request_param
             ])  #写日志,保存到数据库

    except Exception, ex:
        operate_id = -1
        operate_id = usm.get_the_user().id

        print '<<views game battle_heart.py>> write_log error, operate admin id :%s , player_id:%s ' % (
            operate_id.player_id)
        print ex
        pass

    if result['code'] == 0:
        return HttpResponse('成功')
    else:
        return HttpResponse('失败')
Example #7
0
    try:
        result_json_str = result_json_str.decode('utf-8')
    except:
        print '<views.game.gm> warring: result decode utf-8 fail'
        result_json_str = source_result_json_str

    #print u'result_json::::', result_json_str
    #print '*****************************************'

    try:
        #写日志
        log_req_params = req_params
        log_data_result = result_json_str
        write_gm_log(request, [
            req_type, 0, 0, 0,
            u'协议:%s 返回代码:%s  URL:%s  参数:%s' %
            (req_type, log_data_result, gm_def.url, log_req_params)
        ])
    except Exception, ex:
        print 'write gm log error'
        print ex

    result = ''
    if '' == err_msg and '' != result_json_str:
        #    if True:
        try:
            result_json = json.loads(result_json_str)
            result_code = result_json

            try:
                for path_item in code_path:
Example #8
0
def server_modify(request, server_id=0):
    server_id = int(server_id)
    if server_id == 0:
        server_id = int(request.GET.get('server_id', '0'))
    err_msg = ''
    #*****定时任务设置参数 ****************

    task_setting = int(request.GET.get('task_setting', 0))
    trigger_time = request.GET.get('trigger_time', '')
    recover_time = request.GET.get('recover_time', '')

    if 1 == task_setting:
        try:
            trigger_time = datetime.datetime.strptime(trigger_time,
                                                      '%Y-%m-%d %H:%M:%S')
            recover_time = datetime.datetime.strptime(recover_time,
                                                      '%Y-%m-%d %H:%M:%S')
        except:
            err_msg = '请输入正确的时间格式'

    #*****定时任务设置参数 END ***********

    is_ajax = request.GET.get('ajax', False)
    req_type = 606
    result_msgs = {-1: u'未知错误', 0: u'成功'}
    result_code = -1
    config_json = request.POST
    #    modify_science_info = json.dumps(modify_science_info)
    net_id = request.GET.get('net_id', '-1')
    config_type = request.GET.get('config_type', '0')

    source_server_info = get_server_info(server_id, net_id, config_type)

    log_param = {}
    request_param = do_filter_server_param(config_json, source_server_info,
                                           log_param)

    #需要设置定时任务
    if task_setting == 1:
        server = Server.objects.get(id=server_id)
        recover_data = {}
        for modify_param_key in request_param:
            recover_data[modify_param_key] = source_server_info.get(
                modify_param_key)
        setting_task(server, net_id, trigger_time, recover_time, recover_data,
                     request_param)
        if is_ajax:
            return HttpResponse('{code:0,msg:"设置成功"}')

        return render_to_response('game/feedback.html',
                                  {"result_msg": u"设置成功"})

    request_param = json.dumps(request_param, ensure_ascii=False)  #转化字符串
    log_param = json.dumps(log_param, ensure_ascii=False)

    req_params = 'req_type=%d&server_id=%d&net_id=%s&config_type=%s&config_json=%s' % (
        req_type, server_id, net_id, config_type, request_param)

    try:
        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, net_id, result_code, log_param])
    except Exception, e:
        err_msg = u'发生错误%s' % e
Example #9
0
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())
Example #10
0
        log_param = json.dumps(log_param, ensure_ascii=False)
        request_param = json.dumps(request_param, ensure_ascii=False)  #转化字符串

        req_params = 'req_type=%d&player_id=%s&server_id=%d&edited_player_info=%s' % (
            req_type, player_id, server_id, request_param)
        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:
                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

        result_msg = result_msgs.get(result_code, '')
    else:
        result_msg = err_msg
    parg = {}
    parg["result_msg"] = result_msg
    parg["err_msg"] = err_msg

    return render_to_response('game/feedback.html', parg)


#根据请求提交回来的参数,区别是覆盖玩家信息或者是追加值