Otclient
14/8/2020
protocolgame.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010-2020 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
* furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
* THE SOFTWARE.
21
*/
22
23
#include "
protocolgame.h
"
24
#include "
game.h
"
25
#include "
player.h
"
26
#include "
item.h
"
27
#include "
localplayer.h
"
28
29
void
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)
30
{
31
m_accountName = accountName;
32
m_accountPassword = accountPassword;
33
m_authenticatorToken = authenticatorToken;
34
m_sessionKey = sessionKey;
35
m_characterName = characterName;
36
37
connect
(host, port);
38
}
39
40
void
ProtocolGame::onConnect
()
41
{
42
m_firstRecv =
true
;
43
Protocol::onConnect
();
44
45
m_localPlayer =
g_game
.
getLocalPlayer
();
46
47
if
(
g_game
.
getFeature
(
Otc::GameProtocolChecksum
))
48
enableChecksum
();
49
50
if
(!
g_game
.
getFeature
(
Otc::GameChallengeOnLogin
))
51
sendLoginPacket
(0, 0);
52
53
recv
();
54
}
55
56
void
ProtocolGame::onRecv
(
const
InputMessagePtr
& inputMessage)
57
{
58
if
(m_firstRecv) {
59
m_firstRecv =
false
;
60
61
if
(
g_game
.
getFeature
(
Otc::GameMessageSizeCheck
)) {
62
int
size = inputMessage->
getU16
();
63
if
(size != inputMessage->
getUnreadSize
()) {
64
g_logger
.traceError(
"invalid message size"
);
65
return
;
66
}
67
}
68
}
69
70
parseMessage(inputMessage);
71
recv
();
72
}
73
74
void
ProtocolGame::onError
(
const
boost::system::error_code& error)
75
{
76
g_game
.
processConnectionError
(error);
77
disconnect
();
78
}
Protocol::disconnect
void disconnect()
Definition:
protocol.cpp:50
InputMessage::getU16
uint16 getU16()
Definition:
inputmessage.cpp:56
Protocol::onConnect
virtual void onConnect()
Definition:
protocol.cpp:237
Protocol::connect
void connect(const std::string &host, uint16 port)
Definition:
protocol.cpp:43
ProtocolGame::sendLoginPacket
void sendLoginPacket(uint challengeTimestamp, uint8 challengeRandom)
Definition:
protocolgamesend.cpp:51
ProtocolGame::onConnect
void onConnect()
Definition:
protocolgame.cpp:40
g_game
Game g_game
Definition:
game.cpp:37
Otc::GameProtocolChecksum
@ GameProtocolChecksum
Definition:
const.h:346
Otc::GameChallengeOnLogin
@ GameChallengeOnLogin
Definition:
const.h:348
Otc::GameMessageSizeCheck
@ GameMessageSizeCheck
Definition:
const.h:404
InputMessage::getUnreadSize
int getUnreadSize()
Definition:
inputmessage.h:61
uint16
uint16_t uint16
Definition:
types.h:36
ProtocolGame::onRecv
void onRecv(const InputMessagePtr &inputMessage)
Definition:
protocolgame.cpp:56
localplayer.h
g_logger
Logger g_logger
Definition:
logger.cpp:35
Protocol::enableChecksum
void enableChecksum()
Definition:
protocol.h:55
Game::getFeature
bool getFeature(Otc::GameFeature feature)
Definition:
game.h:310
Protocol::recv
virtual void recv()
Definition:
protocol.cpp:93
Game::processConnectionError
void processConnectionError(const boost::system::error_code &ec)
Definition:
game.cpp:116
ProtocolGame::onError
void onError(const boost::system::error_code &error)
Definition:
protocolgame.cpp:74
player.h
stdext::shared_object_ptr< InputMessage >
Game::getLocalPlayer
LocalPlayerPtr getLocalPlayer()
Definition:
game.h:343
game.h
protocolgame.h
ProtocolGame::login
void 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)
Definition:
protocolgame.cpp:29
item.h
src
client
protocolgame.cpp
Generated by
1.8.17
For more information visit
https://forum.opentibia.dev/