protocolold.cpp

main 78 lines · 2 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1/**
2 * The Forgotten Server - a free and open-source MMORPG server emulator
3 * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include "otpch.h"
21
22#include "protocolold.h"
23#include "outputmessage.h"
24
25#include "game.h"
26
27extern Game g_game;
28
29void ProtocolOld::disconnectClient(const std::string& message)
30{
31 auto output = OutputMessagePool::getOutputMessage();
32 output->addByte(0x0A);
33 output->addString(message);
34 send(output);
35
36 disconnect();
37}
38
39void ProtocolOld::onRecvFirstMessage(NetworkMessage& msg)
40{
41 if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
42 disconnect();
43 return;
44 }
45
46 /*uint16_t clientOS =*/ msg.get<uint16_t>();
47 uint16_t version = msg.get<uint16_t>();
48 msg.skipBytes(12);
49
50 if (version <= 760) {
51 std::ostringstream ss;
52 ss << "Only clients with protocol " << CLIENT_VERSION_STR << " allowed!";
53 disconnectClient(ss.str());
54 return;
55 }
56
57 if (!Protocol::RSA_decrypt(msg)) {
58 disconnect();
59 return;
60 }
61
62 xtea::key key;
63 key[0] = msg.get<uint32_t>();
64 key[1] = msg.get<uint32_t>();
65 key[2] = msg.get<uint32_t>();
66 key[3] = msg.get<uint32_t>();
67 enableXTEAEncryption();
68 setXTEAKey(std::move(key));
69
70 if (version <= 822) {
71 disableChecksum();
72 }
73
74 std::ostringstream ss;
75 ss << "Only clients with protocol " << CLIENT_VERSION_STR << " allowed!";
76 disconnectClient(ss.str());
77}
78
Top