Exemple #1
0
def _charge_ship(obj):
    try:
        server = get_game_config(obj.serverid)
        if not server:
            raise Exception("not found server {0}".format(obj.serverid))
        platform = 0
        if obj.tester == 1:
            platform = 1
        elif obj.platform == 'android':
            platform = 3
        elif obj.platform == 'ios':
            platform = 2
        elif obj.platform == 'feiyu':
            platform = 4
        res = requests.get('http://{0}:{1}/charge'.format(
            server['http_host'], game_http_port(obj.serverid)),
                           params={
                               'account': obj.account,
                               'product_id': obj.product_id,
                               'platform': platform,
                               'order': obj.order_id,
                               'pay_way': obj.pay_way,
                           })
        if res and res.content:
            obj.status = 1
            obj.save()
            return True
    except Exception as e:
        logger.error('_charge_ship error: {0}'.format(str(e)))
    return False
Exemple #2
0
def enter_game(request):
    uid = request.GET.get('account', None)
    sid = request.GET.get('serverid', None)
    playerid = request.GET.get('playerid', None)
    name = request.GET.get('name', '')
    data = get_cache_account(uid=uid)
    platform = {}
    if data:
        server = get_game_config(sid)
        if server and ('test' not in server or not server['test']):
            if data['lastserver'] != sid or data['playerid'] != playerid or data['name'] != name:
                obj = WebAccount.objects.get(uid=uid)
                obj.lastserver = sid
                obj.playerid = playerid
                obj.name = name
                obj.save()
        platform = data['platform']
        request_charge(sid, uid)
    return JsonResponse(platform)
Exemple #3
0
def head_status(request):
    playerid = request.GET.get('playerid', None)
    sid = int(request.GET.get('serverid', 0))
    status = request.GET.get('status', None)
    head = request.GET.get('head', None)
    code = 0
    server = get_game_config(sid)
    if not server:
        code = 2
    else:
        res = requests.get('http://{0}:{1}/headstatus'.format(server['http_host'], game_http_port(sid)), params={
            'playerid': playerid,
            'status': status,
            'head': head,
        })
        if res.status_code != requests.codes.ok:
            logger.error("head_status error {0} {1}".format(str(res.status_code), res.content))
        else:
            code = int(res.content)
    return HttpResponse(code)
Exemple #4
0
def _get_account_server(account, loginid, sid, country):
    login = get_login_config(loginid)
    if sid == 0:
        res = requests.get('http://{0}:{1}/last_server'.format(login['http_host'], login_http_port(login['loginid'])), params={
            'account': account,
        })
        if res.status_code == requests.codes.ok:
            sid = int(res.text)
    if sid == 0:
        pool = get_country_weight(country)
        if len(pool) > 0:
            sid = random_weight(pool)
    game = get_game_config(sid)
    return {
        'serverid': game['serverid'],
        'ip': login['network_ip'],
        'port': login['network_port'],
        'status': game['status'],
        'appver': game['appver'],
        'resver': game['resver'],
    }
Exemple #5
0
def charge_player(request):
    playerid = request.GET.get('uid', None)
    serverid = request.GET.get('sid', None)
    server = get_game_config(serverid)
    ret = {
        'ret': 1,
        'error': 'not found user',
    }
    if server:
        res = requests.get('http://{0}:{1}/reqchargeplayer'.format(
            server['http_host'], game_http_port(serverid)),
                           params={
                               'playerid': playerid,
                           })
        if res and res.content:
            data = json.loads(res.content)
            user = get_cache_account(uid=data['account'])
            if user:
                ret = data
                ret['ret'] = 0
                ret['uid'] = playerid
                if 'xindong' in user['platform']:
                    ret['account'] = user['platform']['xindong']
    return JsonResponse(ret)