• 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!

TFS 1.X+ [C++] Need help with resolving client crashes in version 12

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,694
Location
Poland
Hey.

I'm trying to make tfs run with client 12.71, but I'm facing some connection problems.

I got login through webService working:
https://github.com/Zbizu/forgottenserver/commit/7e4022bd3800616338a3864c401cace794843557

but the problem is that the client crashes the moment it receives first packet from the server. Because the server version is still 10.98, this should be sent:
https://github.com/Zbizu/forgottens...64c401cace794843557/src/protocolgame.cpp#L431
(I know it's commented but crash happens when I uncomment it)

The problem is that the client crashes instead of receiving this message (reproduction rate varies between 5th try and 100%).
The code is constructed the way it still supports legacy login method, which works fine, but for some reason client 12 just crashes.

The problem isn't in disconnectClient function itself because it's identical in canary and optimized-forgottenserver. I suspect something changed in encryption, but I couldn't really figure out what I'm supposed to change.

Don't ask me to just use canary, the goal here is to update the base tfs.
 
Solution
One thing I saw by quickly looking at the second link is that your code still sends the adler checksum, it was removed in favour of a sequence number

Also, @fabian766 did a very good job documenting the changes between different protocols, take a look at his code at my forked repo optimized_forgottenserver/features.h at master · Erza/optimized_forgottenserver (https://github.com/Erza/optimized_forgottenserver/blob/master/src/features.h)

Find all references to those definitions and then look at what changes in the code where they're used
One thing I saw by quickly looking at the second link is that your code still sends the adler checksum, it was removed in favour of a sequence number

Also, @fabian766 did a very good job documenting the changes between different protocols, take a look at his code at my forked repo optimized_forgottenserver/features.h at master · Erza/optimized_forgottenserver (https://github.com/Erza/optimized_forgottenserver/blob/master/src/features.h)

Find all references to those definitions and then look at what changes in the code where they're used
 
Last edited:
Solution
Thank you. Solution:

protocol.h (class Protocol -> private):
C++:
uint32_t sequenceNumber = 0;

protocol.cpp:
C++:
void Protocol::onSendMessage(const OutputMessage_ptr& msg) /* const <-- remove const here + in header file */
{
    if (!rawMessages) {
        msg->writeMessageLength();

        if (encryptionEnabled) {
            XTEA_encrypt(*msg, key);
            if (true) { //11.11+, haven't figured the condition yet
                msg->addCryptoHeader(2, sequenceNumber);
            } else { //older
                msg->addCryptoHeader((checksumEnabled ? 1 : 0), sequenceNumber);
            }
        }
    }
}

outputmessage.h
C++:
        void addCryptoHeader(uint8_t addChecksum, uint32_t& sequence) {
            if (addChecksum == 1) {
                add_header(adlerChecksum(buffer + outputBufferStart, info.length));
            } else if (addChecksum == 2) {
                add_header(sequence++);
            }

            writeMessageLength();
        }

full change list:
https://github.com/otland/forgottenserver/pull/3671/files
 
Last edited:
Back
Top