示例#1
0
    def process_response(self, request, response):
        if response.status_code != 200:
            return response

        if request.path.startswith('/api/'):
            return response

        char_id = getattr(request, '_char_id', None)
        if char_id:
            other_msgs = message_get(char_id)
        else:
            other_msgs = []

        if not response.content:
            num_of_msgs = len(other_msgs)
            data = '%s%s' % (
                NUM_FIELD.pack(num_of_msgs),
                ''.join(other_msgs)
            )
        else:
            ret_msg_amount = getattr(response, '_msg_amount', 1)
            num_of_msgs = len(other_msgs) + ret_msg_amount
            data = '%s%s%s' % (
                NUM_FIELD.pack(num_of_msgs),
                response.content,
                ''.join(other_msgs)
            )

        # FOR DEBUG
        # print repr(data)
        _unpakced_data = app_test_helper.unpack_data(data)
        _msg_type = [RESPONSE_NOTIFY_TYPE_REV[a] for a, b, c in _unpakced_data]
        print _msg_type
        # DEBUG END
        return HttpResponse(data, content_type='text/plain')
示例#2
0
    def process_response(self, request, response):
        if response.status_code != 200:
            return response

        if request.path.startswith('/api/'):
            return response

        char_id = getattr(request, '_char_id', None)
        if char_id:
            other_msgs = message_get(char_id)
        else:
            other_msgs = []

        if not response.content:
            num_of_msgs = len(other_msgs)
            data = '%s%s' % (NUM_FIELD.pack(num_of_msgs), ''.join(other_msgs))
        else:
            ret_msg_amount = getattr(response, '_msg_amount', 1)
            num_of_msgs = len(other_msgs) + ret_msg_amount
            data = '%s%s%s' % (NUM_FIELD.pack(num_of_msgs), response.content,
                               ''.join(other_msgs))

        # FOR DEBUG
        # print repr(data)
        _unpakced_data = app_test_helper.unpack_data(data)
        _msg_type = [RESPONSE_NOTIFY_TYPE_REV[a] for a, b, c in _unpakced_data]
        print _msg_type
        # DEBUG END
        return HttpResponse(data, content_type='text/plain')
示例#3
0
    def process_request(self, request):
        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        path = request.path

        if path.startswith('/api/'):
            return None

        data = request.body

        num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        data = data[4:]

        for i in range(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                # TODO Check Version
                pass
            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session
                decrypted_session = ""
                if msg_id not in MSG_TYPE_EMPTY_SESSION:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)

                request._proto = p
                request._session = decrypted_session

                splited_session = decrypted_session.split(':')
                len_of_splited_session = len(splited_session)
                if len_of_splited_session == 1:
                    request._account_id = None
                    request._server_id = None
                    request._char_id = None
                elif len_of_splited_session == 2:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = None
                else:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = int(splited_session[2])
                    print "CHAR ID =", request._char_id
示例#4
0
    def process_request(self, request):
        path = request.path

        if path.startswith('/api/') or path.startswith(
                '/system/') or path.startswith('/callback/'):
            return None

        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        data = request.body

        try:
            num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        except:
            print "==== ERROR ===="
            traceback.print_exc()
            return HttpResponse(status=403)

        if num_of_msgs > MAX_NUM_FIELD_AMOUNT:
            print "==== ERROR ===="
            print "NUM_OF_MSGS TOO BIG! {0} > {1}".format(
                num_of_msgs, MAX_NUM_FIELD_AMOUNT)
            return HttpResponse(status=403)

        data = data[4:]

        for i in xrange(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                proto = protomsg.VersionCheckRequest()
                try:
                    proto.ParseFromString(msg)
                except:
                    print "PARSE VERSION_CHECK_REQUEST ERROR"
                    return HttpResponse(status=403)

                if not version.is_valid(proto.version):
                    print "==== VERSION CHECK FAILURE ===="
                    print "==== client: {0} ====".format(proto.version)
                    print "==== server: {0} ====".format(version.version)

                    raise VersionCheckFailure()

            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session

                if msg_id in MSG_TYPE_EMPTY_SESSION:
                    decrypted_session = EmptyGameSession
                else:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)
                    decrypted_session = session_loads(decrypted_session)

                request._proto = p
                request._game_session = decrypted_session

                request._account_id = request._game_session.account_id
                request._server_id = request._game_session.server_id
                request._char_id = request._game_session.char_id

                print "CHAR ID =", request._char_id

        if getattr(request, '_proto', None) is None:
            print "==== ERROR ===="
            print "requests has no proto"
            return HttpResponse(status=403)
示例#5
0
    def process_request(self, request):
        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        path = request.path

        if path.startswith('/api/'):
            return None

        data = request.body

        num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        data = data[4:]

        for i in range(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                # TODO Check Version
                pass
            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session
                decrypted_session = ""
                if msg_id not in MSG_TYPE_EMPTY_SESSION:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)

                request._proto = p
                request._session = decrypted_session

                splited_session = decrypted_session.split(':')
                len_of_splited_session = len(splited_session)
                if len_of_splited_session == 1:
                    request._account_id = None
                    request._server_id = None
                    request._char_id = None
                elif len_of_splited_session == 2:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = None
                else:
                    request._account_id = int(splited_session[0])
                    request._server_id = int(splited_session[1])
                    request._char_id = int(splited_session[2])
                    print "CHAR ID =", request._char_id
示例#6
0
    def process_request(self, request):
        path = request.path

        if path.startswith('/api/') or path.startswith('/system/') or path.startswith('/callback/'):
            return None

        if request.method != METHOD_POST:
            return HttpResponse(status=403)

        data = request.body

        try:
            num_of_msgs = NUM_FIELD.unpack(data[:4])[0]
        except:
            print "==== ERROR ===="
            traceback.print_exc()
            return HttpResponse(status=403)

        if num_of_msgs > MAX_NUM_FIELD_AMOUNT:
            print "==== ERROR ===="
            print "NUM_OF_MSGS TOO BIG! {0} > {1}".format(num_of_msgs, MAX_NUM_FIELD_AMOUNT)
            return HttpResponse(status=403)

        data = data[4:]

        for i in xrange(num_of_msgs):
            msg_id, msg, data = unpack_msg(data)
            if msg_id == 51:
                proto = protomsg.VersionCheckRequest()
                try:
                    proto.ParseFromString(msg)
                except:
                    print "PARSE VERSION_CHECK_REQUEST ERROR"
                    return HttpResponse(status=403)

                if not version.is_valid(proto.version):
                    print "==== VERSION CHECK FAILURE ===="
                    print "==== client: {0} ====".format(proto.version)
                    print "==== server: {0} ====".format(version.version)

                    raise VersionCheckFailure()

            else:
                if getattr(request, '_proto', None) is not None:
                    continue

                if COMMAND_TYPE[path] != msg_id:
                    print "COMMAND TYPE NOT MATCH", path, msg_id
                    return HttpResponse(status=403)

                msg_name = COMMAND_REQUEST[path]
                proto = getattr(protomsg, msg_name)
                p = proto()
                try:
                    p.ParseFromString(msg)
                except:
                    print "PARSE PROTO ERROR"
                    return HttpResponse(status=403)

                print p

                game_session = p.session

                if msg_id in MSG_TYPE_EMPTY_SESSION:
                    decrypted_session = EmptyGameSession
                else:
                    try:
                        decrypted_session = crypto.decrypt(game_session)
                    except crypto.BadEncryptedText:
                        print "BAD SESSION"
                        return HttpResponse(status=403)
                    decrypted_session = session_loads(decrypted_session)

                request._proto = p
                request._game_session = decrypted_session

                request._account_id = request._game_session.account_id
                request._server_id = request._game_session.server_id
                request._char_id = request._game_session.char_id

                print "CHAR ID =", request._char_id

        if getattr(request, '_proto', None) is None:
            print "==== ERROR ===="
            print "requests has no proto"
            return HttpResponse(status=403)