Mana
Loading...
Searching...
No Matches
loginhandler.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "client.h"
25#include "log.h"
26
27#include "net/logindata.h"
28
29#include "net/tmwa/messagein.h"
30#include "net/tmwa/messageout.h"
31#include "net/tmwa/network.h"
32#include "net/tmwa/protocol.h"
33
34#include "utils/dtor.h"
35#include "utils/gettext.h"
36#include "utils/stringutils.h"
37
39
40namespace TmwAthena {
41
43
48
50{
51 static const Uint16 _messages[] = {
57 0
58 };
59 handledMessages = _messages;
60 loginHandler = this;
61}
62
67
69{
70 int code, worldCount;
71
72 switch (msg.getId())
73 {
75 {
76 // 0: acc not found, 1: success, 2: password mismatch, 3: pass too short
77 int errMsg = msg.readInt8();
78 // Successful pass change
79 if (errMsg == 1)
80 {
82 }
83 // pass change failed
84 else
85 {
86 switch (errMsg)
87 {
88 case 0:
89 errorMessage = _("Account was not found. Please re-login.");
90 break;
91 case 2:
92 errorMessage = _("Old password incorrect.");
93 break;
94 case 3:
95 errorMessage = _("New password too short.");
96 break;
97 default:
98 errorMessage = _("Unknown error.");
99 break;
100 }
102 }
103 }
104 break;
105
106 case SMSG_UPDATE_HOST: {
107 int len = msg.readInt16() - 4;
108 mUpdateHost = msg.readString(len);
110
111 Log::info("Received update host \"%s\" from login server.",
112 mUpdateHost.c_str());
113 break;
114 }
115 case SMSG_LOGIN_DATA:
116 // Skip the length word
117 msg.skip(2);
118
119 clearWorlds();
120
121 worldCount = (msg.getLength() - 47) / 32;
122
126 msg.skip(30); // unused
127 mToken.sex = static_cast<SEX>(msg.readInt8());
128
129 for (int i = 0; i < worldCount; i++)
130 {
131 auto *world = new WorldInfo;
132
133 world->address = msg.readInt32();
134 world->port = msg.readInt16();
135 world->name = msg.readString(20);
136 world->online_users = msg.readInt16();
137 world->updateHost = mUpdateHost;
138 msg.readInt16(); // maintenance
139 msg.readInt16(); // is_new
140
141 Log::info("Network: Server: %s (%s:%d)",
142 world->name.c_str(),
143 ipToString(world->address),
144 world->port);
145
146 mWorlds.push_back(world);
147 }
149 break;
150
151 case SMSG_LOGIN_ERROR:
152 code = msg.readInt8();
153 Log::info("Login::error code: %i", code);
154
155 switch (code)
156 {
157 case 0:
158 errorMessage = _("Unregistered ID.");
159 break;
160 case 1:
161 errorMessage = _("Wrong password.");
162 break;
163 case 2:
164 errorMessage = _("Account expired.");
165 break;
166 case 3:
167 errorMessage = _("Rejected from server.");
168 break;
169 case 4:
170 errorMessage = _("You have been permanently banned from "
171 "the game. Please contact the GM team.");
172 break;
173 case 5:
174 errorMessage = _("Client too old.");
175 break;
176 case 6:
177 errorMessage = strprintf(_("You have been temporarily "
178 "banned from the game until "
179 "%s.\nPlease contact the GM "
180 "team via the forums."),
181 msg.readString(20).c_str());
182 break;
183 case 7:
184 errorMessage = _("Server overpopulated.");
185 break;
186 case 9:
187 errorMessage = _("This user name is already taken.");
188 break;
189 case 99:
190 errorMessage = _("Username permanently erased.");
191 break;
192 default:
193 errorMessage = _("Unknown error.");
194 break;
195 }
197 break;
198
200 {
201 const uint8_t b1 = msg.readInt8(); // -1
202 const uint8_t b2 = msg.readInt8(); // T
203 const uint8_t b3 = msg.readInt8(); // M
204 msg.readInt8(); // W
205 const uint32_t options = msg.readInt32();
206
207 if (b1 == 255) // old TMWA
208 mServerVersion = 0;
209 else if (b1 >= 0x0d) // new TMWA
210 mServerVersion = (b1 << 16) | (b2 << 8) | b3;
211 else // eAthena
212 mServerVersion = 0;
213
214 if (mServerVersion > 0)
215 Log::info("TMW server version: x%06x", mServerVersion);
216 else
217 Log::info("Server without version");
218
220
221 // Leave this last
222 mVersionResponse = true;
223 }
224 break;
225 }
226}
227
233
238
244
249
251{
252 // Not supported, so move on
254}
255
262
264{
265 // TODO
266}
267
268void LoginHandler::changeEmail(const std::string &email)
269{
270 // TODO
271}
272
273void LoginHandler::changePassword(const std::string &username,
274 const std::string &oldPassword,
275 const std::string &newPassword)
276{
278 outMsg.writeString(oldPassword, 24);
279 outMsg.writeString(newPassword, 24);
280}
281
282void LoginHandler::chooseServer(unsigned int server)
283{
284 if (server >= mWorlds.size())
285 return;
286
288
290 {
293 }
294 else
295 {
296 charServer.hostname = ipToString(mWorlds[server]->address);
297 }
298
299 charServer.port = mWorlds[server]->port;
300
302}
303
305{
306 std::string username = loginData->username;
307 username.append(loginData->gender == Gender::Female ? "_F" : "_M");
308
310}
311
312void LoginHandler::unregisterAccount(const std::string &username,
313 const std::string &password)
314{
315 // TODO
316}
317
318void LoginHandler::sendLoginRegister(const std::string &username,
319 const std::string &password)
320{
322 outMsg.writeInt32(8); // client version
323 outMsg.writeString(username, 24);
324 outMsg.writeString(password, 24);
325
326 /*
327 * eAthena calls the last byte "client version 2", but it isn't used at
328 * at all. We're retasking it, as a bit mask:
329 * 0 - can handle the 0x63 "update host" packet
330 * 1 - defaults to the first char-server (instead of the last)
331 */
332 outMsg.writeInt8(0x03);
333}
334
336{
337 return mWorlds;
338}
339
341{
343 mWorlds.clear();
344}
345
346} // namespace TmwAthena
static void setState(State state)
Definition client.h:169
Gender gender
Definition logindata.h:42
std::string updateHost
Definition logindata.h:37
unsigned short characterSlots
The number of character slots.
Definition logindata.h:47
std::string username
Definition logindata.h:33
std::string password
Definition logindata.h:34
ServerInfo mServer
const uint16_t * handledMessages
void clear()
Definition serverinfo.h:56
std::string hostname
Definition serverinfo.h:42
uint16_t port
Definition serverinfo.h:43
bool persistentIp
Definition serverinfo.h:49
Worlds getWorlds() const override
void sendLoginRegister(const std::string &username, const std::string &password)
void changePassword(const std::string &username, const std::string &oldPassword, const std::string &newPassword) override
void getRegistrationDetails() override
void unregisterAccount(const std::string &username, const std::string &password) override
void loginAccount(LoginData *loginData) override
void changeEmail(const std::string &email) override
bool isRegistrationEnabled() override
void handleMessage(MessageIn &msg) override
void disconnect() override
void registerAccount(LoginData *loginData) override
bool isConnected() override
void chooseServer(unsigned int server) override
Used for parsing an incoming message from eAthena.
Definition messagein.h:35
std::string readString(int length=-1)
Reads a string.
void skip(unsigned int length)
Skips a given number of bytes.
uint16_t readInt16()
Reads an unsigned 16-bit integer from the message.
Definition messagein.cpp:57
uint8_t readInt8()
Reads an unsigned 8-bit integer from the message.
Definition messagein.cpp:46
uint16_t getId() const
Returns the message ID.
Definition messagein.h:42
uint32_t readInt32()
Reads an unsigned 32-bit integer from the message.
Definition messagein.cpp:69
unsigned int getLength() const
Returns the message length.
Definition messagein.h:47
Used for building an outgoing message to eAthena.
Definition messageout.h:35
void writeInt32(uint32_t value)
Writes an unsigned 32-bit integer to the message.
void writeInt8(uint8_t value)
Writes an unsigned 8-bit integer to the message.
void writeString(const std::string &string, int length=-1)
Writes a string.
bool isConnected() const
Definition network.h:75
bool connect(const ServerInfo &server)
Definition network.cpp:278
const ServerInfo & getServer() const
Definition network.h:60
std::string errorMessage
Definition client.cpp:94
LoginData loginData
Definition client.cpp:95
@ STATE_CHANGEPASSWORD_SUCCESS
Definition client.h:82
@ STATE_REGISTER
Definition client.h:78
@ STATE_ACCOUNTCHANGE_ERROR
Definition client.h:76
@ STATE_WORLD_SELECT
Definition client.h:66
@ STATE_ERROR
Definition client.h:60
@ STATE_UPDATE
Definition client.h:68
void delete_all(Container &c)
Definition dtor.h:46
#define _(s)
Definition gettext.h:38
ManaServ::LoginHandler * loginHandler
Definition net.cpp:51
Net::LoginHandler * loginHandler
Definition net.cpp:51
void info(const char *log_text,...) LOG_PRINTF_ATTR
Warning: buffers and other variables are shared, so there can be only one connection active at a time...
ServerInfo charServer
@ SMSG_CHAR_PASSWORD_RESPONSE
Definition protocol.h:145
@ SMSG_LOGIN_ERROR
Definition protocol.h:141
@ SMSG_UPDATE_HOST
Definition protocol.h:138
@ CMSG_LOGIN_REGISTER
Definition protocol.h:139
@ CMSG_CHAR_PASSWORD_CHANGE
Definition protocol.h:144
@ CMSG_SERVER_VERSION_REQUEST
Definition protocol.h:313
@ SMSG_SERVER_VERSION_RESPONSE
Definition protocol.h:314
@ SMSG_LOGIN_DATA
Definition protocol.h:140
unsigned char uint8_t
Definition sha256.cpp:81
unsigned int uint32_t
Definition sha256.cpp:82
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
const char * ipToString(int address)
Converts the given IP address to a string.
int session_ID1
Definition token.h:31
int session_ID2
Definition token.h:32
int address
Definition worldinfo.h:28
std::vector< WorldInfo * > Worlds
Definition worldinfo.h:35