Exemple #1
0
def login(request):
    req = request._proto

    try:
        account_data = make_account_dict_from_message(req.login)
    except Exception as e:
        raise SanguoException(errormsg.BAD_MESSAGE, 0, 'Login', e.args[0])

    account_data['server_id'] = server.id

    try:
        res = api_account_login(data=account_data)
    except APIFailure:
        raise SanguoException(errormsg.SERVER_FAULT, 0, 'Login',
                              'APIFailure. api_account_login')

    if res['ret'] != 0:
        raise SanguoException(
            res['ret'], 0, 'Login',
            'login, api_account_login, ret = {0}'.format(res['ret']))

    account_id = res['data']['account_id']
    char_id = res['data']['char_id']
    new_token = res['data']['new_token']

    request._account_id = account_id
    request._server_id = server.id

    login_signal.send(
        sender=None,
        char_id=char_id,
        real_login=True,
    )

    if char_id:
        request._char_id = char_id
    else:
        request._char_id = None

    session = GameSession(request._account_id, request._server_id,
                          request._char_id)

    if char_id:
        Player(char_id).set_login_id(session.login_id)

    request._game_session = session
    session = crypto.encrypt(session_dumps(session))

    response = StartGameResponse()
    response.ret = 0

    response.login.MergeFrom(make_login_response_msg(req.login, new_token))
    response.need_create_new_char = char_id == 0

    sync = SyncResponse()
    sync.ret = 0
    sync.utc_timestamp = arrow.utcnow().timestamp

    return [pack_msg(response, session), pack_msg(sync)]
Exemple #2
0
def resume(request):
    sync = SyncResponse()
    sync.ret = 0
    sync.utc_timestamp = arrow.utcnow().timestamp

    login_signal.send(
        sender=None,
        char_id=request._char_id,
    )

    new_session = GameSession(request._account_id, request._server_id, request._char_id)
    encrypted_session = crypto.encrypt(session_dumps(new_session))

    Player(request._char_id).set_login_id(new_session.login_id)

    response = ResumeResponse()
    response.ret = 0
    return [pack_msg(response, encrypted_session), pack_msg(sync)]
Exemple #3
0
def resume(request):
    req = request._proto
    sync = SyncResponse()
    sync.ret = 0
    sync.utc_timestamp = timezone.utc_timestamp()

    login_signal.send(
        sender=None,
        account_id=request._account_id,
        server_id=request._server_id,
        char_id=request._char_id,
    )

    new_session = '%d:%d:%d' % (request._account_id, req.server_id, request._char_id)
    new_session = crypto.encrypt(new_session)

    response = ResumeResponse()
    response.ret = 0
    return [pack_msg(response, new_session), pack_msg(sync)]
Exemple #4
0
def resume(request):
    req = request._proto
    sync = SyncResponse()
    sync.ret = 0
    sync.utc_timestamp = timezone.utc_timestamp()

    login_signal.send(
        sender=None,
        account_id=request._account_id,
        server_id=request._server_id,
        char_id=request._char_id,
    )

    new_session = '%d:%d:%d' % (request._account_id, req.server_id,
                                request._char_id)
    new_session = crypto.encrypt(new_session)

    response = ResumeResponse()
    response.ret = 0
    return [pack_msg(response, new_session), pack_msg(sync)]
Exemple #5
0
def login(request):
    req = request._proto

    try:
        account_data = make_account_dict_from_message(req.login)
    except Exception as e:
        raise SanguoException(
            errormsg.BAD_MESSAGE,
            0,
            'Login',
            e.args[0]
        )

    account_data['server_id'] = server.id

    try:
        res = api_account_login(data=account_data)
    except APIFailure:
        raise SanguoException(
            errormsg.SERVER_FAULT,
            0,
            'Login',
            'APIFailure. api_account_login'
        )

    if res['ret'] != 0:
        raise SanguoException(
            res['ret'],
            0,
            'Login',
            'login, api_account_login, ret = {0}'.format(res['ret'])
        )

    account_id = res['data']['account_id']
    char_id = res['data']['char_id']
    new_token = res['data']['new_token']

    request._account_id = account_id
    request._server_id = server.id

    login_signal.send(
        sender=None,
        char_id=char_id
    )

    if char_id:
        request._char_id = char_id
    else:
        request._char_id = None

    session = GameSession(request._account_id, request._server_id, request._char_id)

    if char_id:
        Player(char_id).set_login_id(session.login_id)

    request._game_session = session
    session = crypto.encrypt(session_dumps(session))

    response = StartGameResponse()
    response.ret = 0

    response.login.MergeFrom(make_login_response_msg(req.login, new_token))
    response.need_create_new_char = char_id == 0

    sync = SyncResponse()
    sync.ret = 0
    sync.utc_timestamp = arrow.utcnow().timestamp

    return [pack_msg(response, session), pack_msg(sync)]
Exemple #6
0
def sync(request):
    msg = SyncResponse()
    msg.ret = 0
    msg.utc_timestamp = timezone.utc_timestamp()
    return pack_msg(msg)
Exemple #7
0
def sync(request):
    msg = SyncResponse()
    msg.ret = 0
    msg.utc_timestamp = arrow.utcnow().timestamp
    return pack_msg(msg)
Exemple #8
0
def sync(request):
    msg = SyncResponse()
    msg.ret = 0
    msg.utc_timestamp = timezone.utc_timestamp()
    return pack_msg(msg)
Exemple #9
0
def login(request):
    req = request._proto
    data = {}
    data['server_id'] = req.server_id

    if req.regular.email:
        data['method'] = 'regular'
        data['name'] = req.regular.email
        data['password'] = req.regular.password
    else:
        data['method'] = 'anonymous'
        data['token'] = req.anonymous.device_token

    try:
        res = api_account_login(data)
    except APIFailure:
        raise SanguoException(errormsg.SERVER_FAULT, 0, 'Login',
                              'APIFailure. api_account_login')

    if res['ret'] != 0:
        raise SanguoException(
            res['ret'], 0, 'Login',
            'login, api_account_login, ret = {0}'.format(res['ret']))

    account_id = res['data']['account_id']
    char_id = res['data']['char_id']
    new_token = res['data']['new_token']

    request._account_id = account_id
    request._server_id = req.server_id

    login_signal.send(sender=None,
                      account_id=request._account_id,
                      server_id=request._server_id,
                      char_id=char_id)

    if char_id:
        request._char_id = char_id
        session_str = '{0}:{1}:{2}'.format(request._account_id,
                                           request._server_id,
                                           request._char_id)
    else:
        request._char_id = None
        session_str = '{0}:{1}'.format(request._account_id, request._server_id)

    session = crypto.encrypt(session_str)

    response = StartGameResponse()
    response.ret = 0
    if req.regular.email:
        response.regular.MergeFrom(req.regular)
    else:
        response.anonymous.device_token = str(new_token)

    response.need_create_new_char = char_id == 0

    sync = SyncResponse()
    sync.ret = 0
    sync.utc_timestamp = timezone.utc_timestamp()

    return [pack_msg(response, session), pack_msg(sync)]
Exemple #10
0
def login(request):
    req = request._proto
    data = {}
    data['server_id'] = req.server_id

    if req.regular.email:
        data['method'] = 'regular'
        data['name'] = req.regular.email
        data['password'] = req.regular.password
    else:
        data['method'] = 'anonymous'
        data['token'] = req.anonymous.device_token

    try:
        res = api_account_login(data)
    except APIFailure:
        raise SanguoException(
            errormsg.SERVER_FAULT,
            0,
            'Login',
            'APIFailure. api_account_login'
        )

    if res['ret'] != 0:
        raise SanguoException(
            res['ret'],
            0,
            'Login',
            'login, api_account_login, ret = {0}'.format(res['ret'])
        )

    account_id = res['data']['account_id']
    char_id = res['data']['char_id']
    new_token = res['data']['new_token']

    request._account_id = account_id
    request._server_id = req.server_id

    login_signal.send(
        sender=None,
        account_id=request._account_id,
        server_id=request._server_id,
        char_id=char_id
    )

    if char_id:
        request._char_id = char_id
        session_str = '{0}:{1}:{2}'.format(
            request._account_id,
            request._server_id,
            request._char_id
        )
    else:
        request._char_id = None
        session_str = '{0}:{1}'.format(request._account_id, request._server_id)

    session = crypto.encrypt(session_str)

    response = StartGameResponse()
    response.ret = 0
    if req.regular.email:
        response.regular.MergeFrom(req.regular)
    else:
        response.anonymous.device_token = str(new_token)

    response.need_create_new_char = char_id == 0

    sync = SyncResponse()
    sync.ret = 0
    sync.utc_timestamp = timezone.utc_timestamp()

    return [pack_msg(response, session), pack_msg(sync)]