ManaPlus
loginhandler.cpp
Go to the documentation of this file.
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 
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"
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 
49  Ea::LoginHandler()
50 {
51  loginHandler = this;
52 }
53 
55 {
56  loginHandler = nullptr;
57 }
58 
60 {
61  if (Network::mInstance == nullptr)
62  return;
63 
66  {
67  sendVersion();
68  }
69  else
70  {
71  if (client->getState() != State::LOGIN)
73  }
74 }
75 
77 {
78  if (Network::mInstance == nullptr)
79  return false;
80 
82 }
83 
85 {
86  if (Network::mInstance != nullptr &&
88  {
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  {
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 
141 {
142  return &charServer;
143 }
144 
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");
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 
168 {
169  updateProtocol();
170 }
171 
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
int BeingId
Definition: beingid.h:30
void setState(const StateT state)
Definition: client.h:66
StateT getState() const
Definition: client.h:69
void sendOtpCode(const std::string &code) const
void updatePacketVersion() const
void disconnect() const
ServerInfo * getCharServer() const
bool isConnected() const
void sendVersion() const
void sendLoginRegister(const std::string &username, const std::string &password, const std::string &email) const
void sendMobileCode(const BeingId accountId, const std::string &code) const
void changePassword(const std::string &oldPassword, const std::string &newPassword) 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 flushSend() const =0
ServerInfo mServer
Definition: loginhandler.h:116
const ServerInfo & getServer() const
Definition: loginhandler.h:46
virtual bool haveServerVersion() const =0
Client * client
Definition: client.cpp:118
int serverVersion
Definition: client.cpp:124
bool packets_zero
Definition: client.cpp:133
int packetVersionRe
Definition: client.cpp:127
int packetVersionMain
Definition: client.cpp:126
#define CLIENT_PROTOCOL_VERSION
Definition: network.h:33
Net::GeneralHandler * generalHandler
Definition: net.cpp:88
#define restrict
Definition: localconsts.h:165
Net::LoginHandler * loginHandler
Definition: net.cpp:90
#define createOutPacket(name)
Definition: messageout.h:37
void updateProtocol()
ServerInfo charServer
ServerTypeT getNetworkType()
Definition: net.cpp:189
@ LOGIN
Definition: state.h:40
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101