protocolgame.cpp

main 89 lines · 2.9 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
22#include <framework/core/application.h>
23
24#include "protocolgame.h"
25#include "game.h"
26#include "player.h"
27#include "item.h"
28#include "localplayer.h"
29
30void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName, const std::string& authenticatorToken, const std::string& sessionKey, const std::string& worldName)
31{
32 m_accountName = accountName;
33 m_accountPassword = accountPassword;
34 m_authenticatorToken = authenticatorToken;
35 m_sessionKey = sessionKey;
36 m_characterName = characterName;
37 m_worldName = worldName;
38
39 connect(host, port);
40}
41
42void ProtocolGame::onConnect()
43{
44 m_firstRecv = true;
45 Protocol::onConnect();
46
47 m_localPlayer = g_game.getLocalPlayer();
48
49 if (g_game.getFeature(Otc::GameSendWorldName))
50 sendWorldName();
51
52 if (g_game.getFeature(Otc::GamePacketSizeU32))
53 enableBigPackets();
54
55 if(g_game.getFeature(Otc::GameProtocolChecksum))
56 enableChecksum();
57
58 if(!g_game.getFeature(Otc::GameChallengeOnLogin))
59 sendLoginPacket(0, 0);
60
61 recv();
62}
63
64void ProtocolGame::onRecv(const InputMessagePtr& inputMessage)
65{
66 m_recivedPackeds += 1;
67 m_recivedPackedsSize += inputMessage->getMessageSize();
68 if(m_firstRecv) {
69 m_firstRecv = false;
70
71 if(g_game.getFeature(Otc::GameMessageSizeCheck)) {
72 int size = g_game.getFeature(Otc::GamePacketSizeU32) ? inputMessage->getU32() : inputMessage->getU16();
73 if(size != inputMessage->getUnreadSize()) {
74 g_logger.traceError("invalid message size");
75 return;
76 }
77 }
78 }
79
80 parseMessage(inputMessage);
81 recv();
82}
83
84void ProtocolGame::onError(const boost::system::error_code& error)
85{
86 g_game.processConnectionError(error);
87 disconnect();
88}
89
Top