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-2018 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 
44 namespace EAthena
45 {
46 
47 extern ServerInfo mapServer;
48 
50  Ea::GameHandler()
51 {
52  gameHandler = this;
53 }
54 
56 {
57  gameHandler = nullptr;
58 }
59 
61 {
63 }
64 
66 {
67  if (Network::mInstance == nullptr)
68  return;
69 
70  Network::mInstance->connect(mapServer);
71 
72  const Token &token = static_cast<LoginHandler*>(loginHandler)->getToken();
73 
74 
76  {
77  // Change the player's ID to the account ID to match what eAthena uses
78  if (localPlayer != nullptr)
79  {
82  }
83  else
84  {
86  }
87  }
88 
89  // Send login infos
91  outMsg.writeBeingId(token.account_ID, "account id");
92  outMsg.writeBeingId(Ea::GameRecv::mCharID, "char id");
93  outMsg.writeInt32(token.session_ID1, "session key1");
94  outMsg.writeInt32(0, "tick");
95  outMsg.writeInt8(Being::genderToInt(token.sex), "sex");
98 
99  // We get 4 useless bytes before the real answer comes in (what are these?)
100 // Network::mInstance->skip(4);
101 }
102 
104 {
105  if (Network::mInstance == nullptr)
106  return false;
108 }
109 
111 {
112  if (Network::mInstance != nullptr)
114 }
115 
116 void GameHandler::quit() const
117 {
119 }
120 
121 void GameHandler::ping(const int tick) const
122 {
124  if (packetVersion >= 20101124)
125  {
126  // nothing here
127  }
128  else if (packetVersion >= 20080827)
129  {
130  outMsg.writeInt16(0, "unknown");
131  outMsg.writeInt8(0, "unknown");
132  outMsg.writeInt8(0, "unknown");
133  outMsg.writeInt8(0, "unknown");
134  }
135  else if (packetVersion >= 20070212)
136  {
137  outMsg.writeInt16(0, "unknown");
138  }
139  else if (packetVersion >= 20070108)
140  {
141  outMsg.writeInt16(0, "unknown");
142  outMsg.writeInt16(0, "unknown");
143  outMsg.writeInt8(0, "unknown");
144  }
145  else if (packetVersion >= 20050719)
146  {
147  outMsg.writeInt16(0, "unknown");
148  outMsg.writeInt16(0, "unknown");
149  outMsg.writeInt16(0, "unknown");
150  outMsg.writeInt8(0, "unknown");
151  }
152  else if (packetVersion >= 20050718)
153  {
154  outMsg.writeInt8(0, "unknown");
155  }
156  else if (packetVersion >= 20050628)
157  {
158  outMsg.writeInt16(0, "unknown");
159  outMsg.writeInt16(0, "unknown");
160  outMsg.writeInt16(0, "unknown");
161  outMsg.writeInt8(0, "unknown");
162  }
163  else if (packetVersion >= 20050509)
164  {
165  outMsg.writeInt16(0, "unknown");
166  }
167  else if (packetVersion >= 20050110)
168  {
169  outMsg.writeInt16(0, "unknown");
170  outMsg.writeInt8(0, "unknown");
171  }
172  else if (packetVersion >= 20041129)
173  {
174  outMsg.writeInt8(0, "unknown");
175  }
176  else if (packetVersion >= 20041025)
177  {
178  outMsg.writeInt8(0, "unknown");
179  outMsg.writeInt8(0, "unknown");
180  outMsg.writeInt8(0, "unknown");
181  }
182  else if (packetVersion >= 20041005)
183  {
184  outMsg.writeInt8(0, "unknown");
185  outMsg.writeInt8(0, "unknown");
186  outMsg.writeInt8(0, "unknown");
187  outMsg.writeInt8(0, "unknown");
188  }
189  else if (packetVersion >= 20040920)
190  {
191  outMsg.writeInt16(0, "unknown");
192  outMsg.writeInt16(0, "unknown");
193  outMsg.writeInt8(0, "unknown");
194  outMsg.writeInt8(0, "unknown");
195  outMsg.writeInt8(0, "unknown");
196  outMsg.writeInt8(0, "unknown");
197  }
198  else if (packetVersion >= 20040906)
199  {
200  outMsg.writeInt16(0, "unknown");
201  outMsg.writeInt8(0, "unknown");
202  outMsg.writeInt8(0, "unknown");
203  outMsg.writeInt8(0, "unknown");
204  }
205  else if (packetVersion >= 20040809)
206  {
207  outMsg.writeInt16(0, "unknown");
208  outMsg.writeInt16(0, "unknown");
209  outMsg.writeInt8(0, "unknown");
210  outMsg.writeInt8(0, "unknown");
211  outMsg.writeInt8(0, "unknown");
212  }
213  else if (packetVersion >= 20040726)
214  {
215  outMsg.writeInt16(0, "unknown");
216  outMsg.writeInt16(0, "unknown");
217  }
218  outMsg.writeInt32(tick, "tick");
219 }
220 
222 {
224 }
225 
226 } // namespace EAthena
int packetVersion
Definition: client.cpp:124
bool isConnected() const
Definition: network.h:60
bool isConnected() const
BeingId getId() const
Definition: actorsprite.h:63
int CMSG_MAP_SERVER_CONNECT
Definition: protocolout.cpp:60
int CMSG_CLIENT_QUIT
Definition: protocolout.cpp:67
int CMSG_MAP_LOADED
Definition: protocolout.cpp:66
Client * client
Definition: client.cpp:117
Definition: token.h:29
void mapLoadedEvent() const
Definition: gamehandler.cpp:60
GenderT sex
Definition: token.h:43
static uint8_t genderToInt(const GenderT sex) A_CONST
Definition: being.h:926
Net::ServerFeatures * serverFeatures
Definition: net.cpp:98
void ping(const int tick) const
Net::LoginHandler * loginHandler
Definition: net.cpp:87
bool connect(const ServerInfo &server)
Definition: network.cpp:100
int CMSG_MAP_PING
Definition: protocolout.cpp:61
LocalPlayer * localPlayer
virtual void sendVersion() const =0
virtual bool haveMapServerVersion() const =0
void disconnect()
Definition: network.cpp:138
void setId(const BeingId id)
Definition: actorsprite.h:66
BeingId account_ID
Definition: token.h:40
static Network * mInstance
Definition: network.h:56
#define createOutPacket(name)
Definition: messageout.h:36
ServerInfo mapServer
void disconnect() const
StateT getState() const
Definition: client.h:68
const BeingId BeingId_zero
Definition: beingid.h:29
BeingId mCharID
Definition: gamerecv.cpp:46
Net::GameHandler * gameHandler
Definition: net.cpp:88
void connect() const
Definition: gamehandler.cpp:65
int session_ID1
Definition: token.h:41
void disconnect2() const