• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ function does not take 1 arguments namespace

T

Tibia Demon

Guest
i was adding this change to tfs 1.4.2
and i get this error
Code:
(66,21): error C2660: '`anonymous-namespace'::XTEA_encrypt': function does not take 1 arguments
(15,6): message : see declaration of '`anonymous-namespace'::XTEA_encrypt'
idk how to fix namespace it look like this
C++:
// Copyright 2022 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.

#include "otpch.h"

#include "protocol.h"
#include "outputmessage.h"
#include "rsa.h"
#include "xtea.h"

extern RSA g_RSA;

namespace {

void XTEA_encrypt(OutputMessage& msg, const xtea::round_keys& key)
{
    // The message must be a multiple of 8
    size_t paddingBytes = msg.getLength() % 8u;
    if (paddingBytes != 0) {
        msg.addPaddingBytes(8 - paddingBytes);
    }

    uint8_t* buffer = msg.getOutputBuffer();
    xtea::encrypt(buffer, msg.getLength(), key);
}

bool XTEA_decrypt(NetworkMessage& msg, const xtea::round_keys& key)
{
    if (((msg.getLength() - 6) & 7) != 0) {
        return false;
    }

    uint8_t* buffer = msg.getBuffer() + msg.getBufferPosition();
    xtea::decrypt(buffer, msg.getLength() - 6, key);

    uint16_t innerLength = msg.get<uint16_t>();
    if (innerLength + 8 > msg.getLength()) {
        return false;
    }

    msg.setLength(innerLength);
    return true;
}

}

Protocol::~Protocol()
{
    if (compression) {
        deflateEnd(&zstream);
    }
}

void Protocol::onSendMessage(const OutputMessage_ptr& msg) const
{
    if (!rawMessages) {
        bool compressed = false;
        if (compression && msg->getLength() > 64) {
            compress(*msg);
            compressed = true;
        }

        msg->writeMessageLength();

        if (encryptionEnabled) {
            XTEA_encrypt(*msg);
            msg->addCryptoHeader(checksumEnabled, compressed);
        }
    }
}

void Protocol::onRecvMessage(NetworkMessage& msg)
{
    if (encryptionEnabled && !XTEA_decrypt(msg, key)) {
        return;
    }

    parsePacket(msg);
}

OutputMessage_ptr Protocol::getOutputBuffer(int32_t size)
{
    //dispatcher thread
    if (!outputBuffer) {
        outputBuffer = OutputMessagePool::getOutputMessage();
    } else if ((outputBuffer->getLength() + size) > NetworkMessage::MAX_PROTOCOL_BODY_LENGTH) {
        send(outputBuffer);
        outputBuffer = OutputMessagePool::getOutputMessage();
    }
    return outputBuffer;
}

bool Protocol::RSA_decrypt(NetworkMessage& msg)
{
    if ((msg.getLength() - msg.getBufferPosition()) < 128) {
        return false;
    }

    g_RSA.decrypt(reinterpret_cast<char*>(msg.getBuffer()) + msg.getBufferPosition()); //does not break strict aliasing
    return msg.getByte() == 0;
}

uint32_t Protocol::getIP() const
{
    if (auto connection = getConnection()) {
        return connection->getIP();
    }

    return 0;
}

void Protocol::enableCompression()
{
    if (compression)
        return;
    if (deflateInit2(&zstream, 6, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
        std::cerr << "ZLIB initialization error: " << (zstream.msg ? zstream.msg : "unknown") << std::endl;
    }
    compression = true;
}

void Protocol::compress(OutputMessage& msg) const
{
    static thread_local std::vector<uint8_t> buffer(NETWORKMESSAGE_MAXSIZE);
    zstream.next_in = msg.getOutputBuffer();
    zstream.avail_in = msg.getLength();
    zstream.next_out = buffer.data();
    zstream.avail_out = buffer.size();
    if (deflate(&zstream, Z_SYNC_FLUSH) != Z_OK) {
        std::cerr << "ZLIB deflate error: " << (zstream.msg ? zstream.msg : "unknown") << std::endl;
        return;
    }
    int finalSize = buffer.size() - zstream.avail_out - 4;
    if (finalSize < 0) {
        std::cerr << "Packet compression error: " << (zstream.msg ? zstream.msg : "unknown") << std::endl;
        return;
    }

    msg.reset();
    msg.addBytes((const char*)buffer.data(), finalSize);
}
 
i solved it. i changed
C++:
XTEA_encrypt(*msg);
to
C++:
XTEA_encrypt(*msg, key);
it compiled, is this safe solution?
 

Similar threads

Back
Top