From 11bd6ba26dfdf70d54e685ed1fd1a5898a322c76 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Fri, 19 Sep 2025 23:49:21 -0300 Subject: support 7.72 with non-default `-DTIBIA772=1` switch --- src/communication.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/communication.cc b/src/communication.cc index ab92092..b373900 100644 --- a/src/communication.cc +++ b/src/communication.cc @@ -23,7 +23,12 @@ #define MAX_COMMUNICATION_THREADS 1100 #define COMMUNICATION_THREAD_STACK_SIZE ((int)KB(64)) +#if TIBIA772 +static const int TERMINALVERSION[] = {772, 772, 772}; +#else static const int TERMINALVERSION[] = {770, 770, 770}; +#endif + static int TCPSocket; static ThreadHandle AcceptorThread; static pid_t AcceptorThreadID; @@ -918,10 +923,23 @@ bool HandleLogin(TConnection *Connection){ char PlayerName[30]; char PlayerPassword[30]; try{ +#if TIBIA772 + // IMPORTANT(fusion): With 7.72, the terminal type and version are brought + // outside the asymmetric data. This is probably to maintain some level of + // backwards compatibility, given that 7.7 was the first encrypted protocol. + TerminalType = (int)InputBuffer.readWord(); + TerminalVersion = (int)InputBuffer.readWord(); +#endif + + // IMPORTANT(fusion): Without a checksum, there is no way of validating the + // asymmetric data. The best we can do is to verify that the first plaintext + // byte is ZERO, but that alone isn't enough. + // TODO(fusion): Using `SendLoginMessage` before initializing the symmetric + // key will result in gibberish being sent back to the client. uint8 AsymmetricData[128]; InputBuffer.readBytes(AsymmetricData, 128); RSAMutex.down(); - if(!PrivateKey.decrypt(AsymmetricData)){ + if(!PrivateKey.decrypt(AsymmetricData) || AsymmetricData[0] != 0){ RSAMutex.up(); error("HandleLogin: Fehler beim Entschlüsseln.\n"); SendLoginMessage(Connection, LOGIN_MESSAGE_ERROR, @@ -933,8 +951,10 @@ bool HandleLogin(TConnection *Connection){ TReadBuffer ReadBuffer(AsymmetricData, 128); ReadBuffer.readByte(); // always zero Connection->SymmetricKey.init(&ReadBuffer); +#if !TIBIA772 TerminalType = (int)ReadBuffer.readWord(); TerminalVersion = (int)ReadBuffer.readWord(); +#endif GamemasterClient = ReadBuffer.readByte() != 0; AccountID = ReadBuffer.readQuad(); ReadBuffer.readString(PlayerName, sizeof(PlayerName)); -- cgit v1.2.3