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