ManaPlus
gamehandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
24 
25 #include "client.h"
26 
27 #include "being/localplayer.h"
28 
29 #include "net/serverfeatures.h"
30 
31 #include "net/ea/token.h"
32 
33 #include "net/ea/gamerecv.h"
34 
36 #include "net/eathena/messageout.h"
37 #include "net/eathena/network.h"
39 
40 #include "debug.h"
41 
42 extern int packetVersion;
43 extern int packetVersionMain;
44 extern int packetVersionRe;
45 extern int packetVersionZero;
46 
47 namespace EAthena
48 {
49 
50 extern ServerInfo mapServer;
51 
53  Ea::GameHandler()
54 {
55  gameHandler = this;
56 }
57 
59 {
60  gameHandler = nullptr;
61 }
62 
64 {
65  createOutPacket(CMSG_MAP_LOADED);
66 }
67 
69 {
70  if (Network::mInstance == nullptr)
71  return;
72 
74 
75  const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
76 
77 
79  {
80  // Change the player's ID to the account ID to match what eAthena uses
81  if (localPlayer != nullptr)
82  {
85  }
86  else
87  {
89  }
90  }
91 
92  // Send login infos
93  createOutPacket(CMSG_MAP_SERVER_CONNECT);
94  outMsg.writeBeingId(token.account_ID, "account id");
95  outMsg.writeBeingId(Ea::GameRecv::mCharID, "char id");
96  outMsg.writeInt32(token.session_ID1, "session key1");
97  outMsg.writeInt32(0, "tick");
98  outMsg.writeInt8(Being::genderToInt(token.sex), "sex");
101 
102  // We get 4 useless bytes before the real answer comes in (what are these?)
103 // Network::mInstance->skip(4);
104 }
105 
107 {
108  if (Network::mInstance == nullptr)
109  return false;
111 }
112 
114 {
115  if (Network::mInstance != nullptr)
117 }
118 
119 void GameHandler::quit() const
120 {
121  createOutPacket(CMSG_CLIENT_QUIT);
122 }
123 
124 void GameHandler::ping(const int tick) const
125 {
126  createOutPacket(CMSG_MAP_PING);
127  if (packetVersion >= 20101124)
128  {
129  // nothing here
130  }
131  else if (packetVersion >= 20080827)
132  {
133  outMsg.writeInt16(0, "unknown");
134  outMsg.writeInt8(0, "unknown");
135  outMsg.writeInt8(0, "unknown");
136  outMsg.writeInt8(0, "unknown");
137  }
138  else if (packetVersion >= 20070212)
139  {
140  outMsg.writeInt16(0, "unknown");
141  }
142  else if (packetVersion >= 20070108)
143  {
144  outMsg.writeInt16(0, "unknown");
145  outMsg.writeInt16(0, "unknown");
146  outMsg.writeInt8(0, "unknown");
147  }
148  else if (packetVersion >= 20050719)
149  {
150  outMsg.writeInt16(0, "unknown");
151  outMsg.writeInt16(0, "unknown");
152  outMsg.writeInt16(0, "unknown");
153  outMsg.writeInt8(0, "unknown");
154  }
155  else if (packetVersion >= 20050718)
156  {
157  outMsg.writeInt8(0, "unknown");
158  }
159  else if (packetVersion >= 20050628)
160  {
161  outMsg.writeInt16(0, "unknown");
162  outMsg.writeInt16(0, "unknown");
163  outMsg.writeInt16(0, "unknown");
164  outMsg.writeInt8(0, "unknown");
165  }
166  else if (packetVersion >= 20050509)
167  {
168  outMsg.writeInt16(0, "unknown");
169  }
170  else if (packetVersion >= 20050110)
171  {
172  outMsg.writeInt16(0, "unknown");
173  outMsg.writeInt8(0, "unknown");
174  }
175  else if (packetVersion >= 20041129)
176  {
177  outMsg.writeInt8(0, "unknown");
178  }
179  else if (packetVersion >= 20041025)
180  {
181  outMsg.writeInt8(0, "unknown");
182  outMsg.writeInt8(0, "unknown");
183  outMsg.writeInt8(0, "unknown");
184  }
185  else if (packetVersion >= 20041005)
186  {
187  outMsg.writeInt8(0, "unknown");
188  outMsg.writeInt8(0, "unknown");
189  outMsg.writeInt8(0, "unknown");
190  outMsg.writeInt8(0, "unknown");
191  }
192  else if (packetVersion >= 20040920)
193  {
194  outMsg.writeInt16(0, "unknown");
195  outMsg.writeInt16(0, "unknown");
196  outMsg.writeInt8(0, "unknown");
197  outMsg.writeInt8(0, "unknown");
198  outMsg.writeInt8(0, "unknown");
199  outMsg.writeInt8(0, "unknown");
200  }
201  else if (packetVersion >= 20040906)
202  {
203  outMsg.writeInt16(0, "unknown");
204  outMsg.writeInt8(0, "unknown");
205  outMsg.writeInt8(0, "unknown");
206  outMsg.writeInt8(0, "unknown");
207  }
208  else if (packetVersion >= 20040809)
209  {
210  outMsg.writeInt16(0, "unknown");
211  outMsg.writeInt16(0, "unknown");
212  outMsg.writeInt8(0, "unknown");
213  outMsg.writeInt8(0, "unknown");
214  outMsg.writeInt8(0, "unknown");
215  }
216  else if (packetVersion >= 20040726)
217  {
218  outMsg.writeInt16(0, "unknown");
219  outMsg.writeInt16(0, "unknown");
220  }
221  outMsg.writeInt32(tick, "tick");
222 }
223 
225 {
226  createOutPacket(CMSG_CLIENT_QUIT);
227 }
228 
230 {
231  createOutPacket(CMSG_REQ_REMAIN_TIME);
232 }
233 
234 void GameHandler::ping2() const
235 {
236  if (packetVersionMain < 20190227 &&
237  packetVersionRe < 20190220 &&
238  packetVersionZero < 20190220)
239  {
240  return;
241  }
242  createOutPacket(CMSG_MAP_PING2);
243 }
244 
245 } // namespace EAthena
Ea::Network::disconnect
void disconnect()
Definition: network.cpp:138
EAthena::GameHandler::isConnected
bool isConnected() const
Definition: gamehandler.cpp:106
Net::ServerFeatures::haveMapServerVersion
virtual bool haveMapServerVersion() const =0
EAthena::GameHandler::connect
void connect() const
Definition: gamehandler.cpp:68
EAthena
Definition: guildtab.cpp:40
Token::session_ID1
int session_ID1
Definition: token.h:41
gamerecv.h
EAthena::Network::mInstance
static Network * mInstance
Definition: network.h:56
packetVersionZero
int packetVersionZero
Definition: client.cpp:127
EAthena::GameHandler::reqRemainTime
void reqRemainTime() const
Definition: gamehandler.cpp:229
protocolout.h
Token
Definition: token.h:29
packetVersion
int packetVersion
Definition: client.cpp:124
ActorSprite::getId
BeingId getId() const
Definition: actorsprite.h:63
EAthena::GameHandler
Definition: gamehandler.h:31
Ea::GameRecv::mCharID
BeingId mCharID
Definition: gamerecv.cpp:46
packetVersionMain
int packetVersionMain
Definition: client.cpp:125
Token::account_ID
BeingId account_ID
Definition: token.h:40
network.h
Ea::Network::connect
bool connect(const ServerInfo &server)
Definition: network.cpp:100
Client::getState
StateT getState() const
Definition: client.h:68
serverFeatures
Net::ServerFeatures * serverFeatures
Definition: net.cpp:100
localplayer.h
State::CONNECT_GAME
@ CONNECT_GAME
Definition: state.h:47
localPlayer
LocalPlayer * localPlayer
Definition: localplayer.cpp:108
messageout.h
EAthena::GameHandler::GameHandler
GameHandler()
Definition: gamehandler.cpp:52
EAthena::GameHandler::quit
void quit() const
Definition: gamehandler.cpp:119
EAthena::mapServer
ServerInfo mapServer
Definition: charserverrecv.cpp:64
Being::genderToInt
static uint8_t genderToInt(const GenderT sex) A_CONST
Definition: being.h:926
Token::sex
GenderT sex
Definition: token.h:43
EAthena::GameHandler::disconnect
void disconnect() const
Definition: gamehandler.cpp:113
EAthena::GameHandler::~GameHandler
~GameHandler()
Definition: gamehandler.cpp:58
loginHandler
Net::LoginHandler * loginHandler
Definition: net.cpp:89
Ea::Network::isConnected
bool isConnected() const
Definition: network.h:60
EAthena::GameHandler::disconnect2
void disconnect2() const
Definition: gamehandler.cpp:224
gameHandler
Net::GameHandler * gameHandler
Definition: net.cpp:90
createOutPacket
#define createOutPacket(name)
Definition: messageout.h:36
EAthena::GameHandler::mapLoadedEvent
void mapLoadedEvent() const
Definition: gamehandler.cpp:63
ActorSprite::setId
void setId(const BeingId id)
Definition: actorsprite.h:66
Ea
Definition: adminhandler.cpp:30
loginhandler.h
EAthena::GameHandler::ping
void ping(const int tick) const
Definition: gamehandler.cpp:124
client
Client * client
Definition: client.cpp:117
serverfeatures.h
gamehandler.h
BeingId_zero
const BeingId BeingId_zero
Definition: beingid.h:29
ServerInfo
Definition: serverinfo.h:36
token.h
EAthena::GameHandler::ping2
void ping2() const
Definition: gamehandler.cpp:234
Net::LoginHandler::sendVersion
virtual void sendVersion() const =0
packetVersionRe
int packetVersionRe
Definition: client.cpp:126
EAthena::LoginHandler
Definition: loginhandler.h:31
client.h
debug.h