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 
24 #include "net/tmwa/loginhandler.h"
25 
26 #include "net/serverfeatures.h"
27 
28 #include "net/ea/loginrecv.h"
29 
30 #include "net/tmwa/messageout.h"
31 #include "net/tmwa/network.h"
32 #include "net/tmwa/protocolout.h"
33 
34 #include "debug.h"
35 
36 extern unsigned int tmwServerVersion;
37 extern int itemIdLen;
38 
39 namespace TmwAthena
40 {
41 
42 extern ServerInfo charServer;
43 
45  Ea::LoginHandler()
46 {
47  loginHandler = this;
48 }
49 
51 {
52  loginHandler = nullptr;
53 }
54 
56 {
57  if (Network::mInstance == nullptr)
58  return;
59 
62  {
63  createOutPacket(CMSG_SERVER_VERSION_REQUEST);
64  }
65 }
66 
68 {
69  if (Network::mInstance == nullptr)
70  return false;
71 
74 }
75 
77 {
78  if (Network::mInstance != nullptr &&
80  {
82  }
83 }
84 
85 void LoginHandler::changePassword(const std::string &restrict oldPassword,
86  const std::string &restrict newPassword)
87  const
88 {
89  createOutPacket(CMSG_CHAR_PASSWORD_CHANGE);
90  outMsg.writeStringNoLog(oldPassword, 24, "old password");
91  outMsg.writeStringNoLog(newPassword, 24, "new password");
92 }
93 
94 void LoginHandler::sendLoginRegister(const std::string &restrict username,
95  const std::string &restrict password,
96  const std::string &restrict email
97  A_UNUSED) const
98 {
99  createOutPacket(CMSG_LOGIN_REGISTER);
100  if (tmwServerVersion < 0x100408)
101  {
102  // hack to avoid bug in tmwa...
103  outMsg.writeInt32(5,
104  "client protocol version");
105  }
106  else
107  {
108  outMsg.writeInt32(CLIENT_PROTOCOL_VERSION,
109  "client protocol version");
110  }
111  outMsg.writeString(username, 24, "login");
112  outMsg.writeStringNoLog(password, 24, "password");
113 
114  /*
115  * eAthena calls the last byte "client version 2", but it isn't used at
116  * at all. We're retasking it, as a bit mask:
117  * 0 - can handle the 0x63 "update host" packet
118  * 1 - defaults to the first char-server (instead of the last)
119  */
120  outMsg.writeInt8(0x03, "flags");
121 }
122 
124 {
125  return &charServer;
126 }
127 
129 {
130 }
131 
133 {
134 }
135 
136 void LoginHandler::ping() const
137 {
138 }
139 
141 {
142  itemIdLen = 2;
143 }
144 
146  const std::string &code A_UNUSED) const
147 {
148 }
149 
150 void LoginHandler::sendOtpCode(const std::string &code A_UNUSED) const
151 {
152 }
153 
154 } // namespace TmwAthena
int BeingId
Definition: beingid.h:30
bool isConnected() const
Definition: network.h:61
bool connect(const ServerInfo &server)
Definition: network.cpp:101
void disconnect()
Definition: network.cpp:139
ServerInfo mServer
Definition: loginhandler.h:116
const ServerInfo & getServer() const
Definition: loginhandler.h:46
virtual bool haveServerVersion() const =0
void sendLoginRegister(const std::string &username, const std::string &password, const std::string &email) const
ServerInfo * getCharServer() const A_CONST
void sendOtpCode(const std::string &code) const
static void requestUpdateHosts()
void changePassword(const std::string &oldPassword, const std::string &newPassword) const
void updatePacketVersion() const
void sendMobileCode(const BeingId accountId, const std::string &code) const
static Network * mInstance
Definition: network.h:54
#define CLIENT_PROTOCOL_VERSION
Definition: network.h:33
#define restrict
Definition: localconsts.h:165
#define A_UNUSED
Definition: localconsts.h:160
Net::LoginHandler * loginHandler
Definition: net.cpp:90
#define createOutPacket(name)
Definition: messageout.h:37
bool mVersionResponse
Definition: loginrecv.cpp:47
ServerInfo charServer
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101
unsigned int tmwServerVersion
Definition: client.cpp:134
int itemIdLen
Definition: client.cpp:130