1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-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 |
|
|
|
24 |
|
|
#include "net/eathena/loginhandler.h" |
25 |
|
|
|
26 |
|
|
#include "client.h" |
27 |
|
|
|
28 |
|
|
#include "net/generalhandler.h" |
29 |
|
|
#include "net/net.h" |
30 |
|
|
#include "net/serverfeatures.h" |
31 |
|
|
|
32 |
|
|
#include "net/eathena/messageout.h" |
33 |
|
|
#include "net/eathena/network.h" |
34 |
|
|
#include "net/eathena/updateprotocol.h" |
35 |
|
|
#include "net/eathena/protocolout.h" |
36 |
|
|
|
37 |
|
|
#include "debug.h" |
38 |
|
|
|
39 |
|
|
extern int packetVersionMain; |
40 |
|
|
extern int packetVersionRe; |
41 |
|
|
extern bool packets_zero; |
42 |
|
|
|
43 |
|
|
namespace EAthena |
44 |
|
|
{ |
45 |
|
|
|
46 |
|
|
extern ServerInfo charServer; |
47 |
|
|
|
48 |
|
|
LoginHandler::LoginHandler() : |
49 |
|
|
Ea::LoginHandler() |
50 |
|
|
{ |
51 |
|
|
loginHandler = this; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
LoginHandler::~LoginHandler() |
55 |
|
|
{ |
56 |
|
|
loginHandler = nullptr; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
void LoginHandler::connect() const |
60 |
|
|
{ |
61 |
|
|
if (Network::mInstance == nullptr) |
62 |
|
|
return; |
63 |
|
|
|
64 |
|
|
Network::mInstance->connect(mServer); |
65 |
|
|
if (serverFeatures->haveServerVersion()) |
66 |
|
|
{ |
67 |
|
|
sendVersion(); |
68 |
|
|
} |
69 |
|
|
else |
70 |
|
|
{ |
71 |
|
|
if (client->getState() != State::LOGIN) |
72 |
|
|
client->setState(State::LOGIN); |
73 |
|
|
} |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
bool LoginHandler::isConnected() const |
77 |
|
|
{ |
78 |
|
|
if (Network::mInstance == nullptr) |
79 |
|
|
return false; |
80 |
|
|
|
81 |
|
|
return Network::mInstance->isConnected(); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
void LoginHandler::disconnect() const |
85 |
|
|
{ |
86 |
|
|
if (Network::mInstance != nullptr && |
87 |
|
|
Network::mInstance->getServer() == mServer) |
88 |
|
|
{ |
89 |
|
|
Network::mInstance->disconnect(); |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
void LoginHandler::changePassword(const std::string &restrict oldPassword, |
94 |
|
|
const std::string &restrict newPassword) |
95 |
|
|
const |
96 |
|
|
{ |
97 |
|
|
if (serverVersion == 0) |
98 |
|
|
return; |
99 |
|
|
createOutPacket(CMSG_CHAR_PASSWORD_CHANGE); |
100 |
|
|
outMsg.writeStringNoLog(oldPassword, 24, "old password"); |
101 |
|
|
outMsg.writeStringNoLog(newPassword, 24, "new password"); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
void LoginHandler::sendLoginRegister(const std::string &restrict username, |
105 |
|
|
const std::string &restrict password, |
106 |
|
|
const std::string &restrict email) const |
107 |
|
|
{ |
108 |
|
|
if (email.empty()) |
109 |
|
|
{ |
110 |
|
|
if (Net::getNetworkType() == ServerType::EATHENA) |
111 |
|
|
{ |
112 |
|
|
createOutPacket(CMSG_LOGIN_REGISTER_HAN); |
113 |
|
|
outMsg.writeInt32(20, "client version"); |
114 |
|
|
outMsg.writeString(username, 24, "login"); |
115 |
|
|
outMsg.writeStringNoLog(password, 24, "password"); |
116 |
|
|
outMsg.writeInt8(0x03, "client type"); |
117 |
|
|
outMsg.writeString("127.0.0.1", 16, "ip address"); |
118 |
|
|
outMsg.writeString("001122334455", 13, "mac address"); |
119 |
|
|
outMsg.writeInt8(0, "is gravity id"); |
120 |
|
|
} |
121 |
|
|
else |
122 |
|
|
{ |
123 |
|
|
createOutPacket(CMSG_LOGIN_REGISTER); |
124 |
|
|
outMsg.writeInt32(20, "client version"); |
125 |
|
|
outMsg.writeString(username, 24, "login"); |
126 |
|
|
outMsg.writeStringNoLog(password, 24, "password"); |
127 |
|
|
outMsg.writeInt8(0x03, "client type"); |
128 |
|
|
} |
129 |
|
|
} |
130 |
|
|
else |
131 |
|
|
{ |
132 |
|
|
createOutPacket(CMSG_LOGIN_REGISTER4); |
133 |
|
|
outMsg.writeString(username, 24, "login"); |
134 |
|
|
outMsg.writeStringNoLog(password, 24, "password"); |
135 |
|
|
outMsg.writeInt8(0x03, "client type"); |
136 |
|
|
outMsg.writeString(email, 40, "email"); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
ServerInfo *LoginHandler::getCharServer() const |
141 |
|
|
{ |
142 |
|
|
return &charServer; |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
void LoginHandler::sendVersion() const |
146 |
|
|
{ |
147 |
|
|
createOutPacket(CMSG_SERVER_VERSION_REQUEST); |
148 |
|
|
outMsg.writeInt32(CLIENT_PROTOCOL_VERSION, "protocol version"); |
149 |
|
|
outMsg.writeInt32(0, "unused"); |
150 |
|
|
outMsg.writeInt32(0, "unused"); |
151 |
|
|
outMsg.writeInt32(0, "unused"); |
152 |
|
|
outMsg.writeInt32(0, "unused"); |
153 |
|
|
generalHandler->flushSend(); |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
void LoginHandler::ping() const |
157 |
|
|
{ |
158 |
|
|
createOutPacket(CMSG_LOGIN_PING); |
159 |
|
|
outMsg.writeInt32(0, "unused"); |
160 |
|
|
outMsg.writeInt32(0, "unused"); |
161 |
|
|
outMsg.writeInt32(0, "unused"); |
162 |
|
|
outMsg.writeInt32(0, "unused"); |
163 |
|
|
outMsg.writeInt32(0, "unused"); |
164 |
|
|
outMsg.writeInt32(0, "unused"); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
void LoginHandler::updatePacketVersion() const |
168 |
|
|
{ |
169 |
|
|
updateProtocol(); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
void LoginHandler::sendMobileCode(const BeingId accountId, |
173 |
|
|
const std::string &code) const |
174 |
|
|
{ |
175 |
|
|
if (packetVersionMain < 20181114 && |
176 |
|
|
packetVersionRe < 20181114) |
177 |
|
|
{ |
178 |
|
|
return; |
179 |
|
|
} |
180 |
|
|
createOutPacket(CMSG_LOGIN_MOBILE_OTP); |
181 |
|
|
outMsg.writeInt16(14, "len"); |
182 |
|
|
outMsg.writeBeingId(accountId, "account id"); |
183 |
|
|
outMsg.writeStringNoLog(code, 6, "code"); |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
void LoginHandler::sendOtpCode(const std::string &code) const |
187 |
|
|
{ |
188 |
|
|
if (packetVersionMain < 20181114 && |
189 |
|
|
packetVersionRe < 20181114 && |
190 |
|
|
packets_zero == false) |
191 |
|
|
{ |
192 |
|
|
return; |
193 |
|
|
} |
194 |
|
|
createOutPacket(CMSG_LOGIN_OTP_CODE); |
195 |
|
|
outMsg.writeStringNoLog(code, 9, "code"); |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
} // namespace EAthena |