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  *
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 
23 #include "net/ea/loginhandler.h"
24 
25 #include "client.h"
26 #include "configuration.h"
27 #include "logger.h"
28 #include "settings.h"
29 
30 #include "utils/cast.h"
31 #include "utils/dtor.h"
32 
33 #include "net/logindata.h"
34 
35 #include "net/ea/loginrecv.h"
36 
37 #include "debug.h"
38 
39 namespace Ea
40 {
41 
43  Net::LoginHandler()
44 {
47  LoginRecv::mUpdateHost.clear();
48  LoginRecv::mWorlds.clear();
50 }
51 
53 {
55 }
56 
58 {
60 }
61 
63 {
64  // Not supported, so move on
66 }
67 
68 void LoginHandler::loginAccount(LoginData *const loginData1) const
69 {
70  if (loginData1 != nullptr)
71  {
72  loginData1->resetCharacterSlots();
73  sendLoginRegister(loginData1->username, loginData1->password, "");
74  }
75 }
76 
77 void LoginHandler::chooseServer(const unsigned int server,
78  const bool persistentIp) const
79 {
80  if (CAST_SIZE(server) >= LoginRecv::mWorlds.size() ||
81  (LoginRecv::mWorlds[server] == nullptr))
82  {
83  return;
84  }
85 
87  if (charServer != nullptr)
88  {
89  if (config.getBoolValue("usePersistentIP") || persistentIp)
90  {
92  }
93  else
94  {
96  LoginRecv::mWorlds[server]->address);
97  }
98  charServer->port = LoginRecv::mWorlds[server]->port;
99  }
101 
103 }
104 
105 void LoginHandler::registerAccount(const LoginData *const loginData1) const
106 {
107  if (loginData1 == nullptr)
108  return;
109 
110  std::string username = loginData1->username;
111  switch (loginData1->gender)
112  {
113  case Gender::FEMALE:
114  username.append("_F");
115  break;
116  case Gender::MALE:
117  username.append("_M");
118  break;
119  case Gender::HIDDEN:
120  username.append("_O");
121  break;
122  case Gender::UNSPECIFIED:
123  default:
124  break;
125  }
126 
127  sendLoginRegister(username, loginData1->password, loginData1->email);
128 }
129 
131 {
132  return LoginRecv::mWorlds;
133 }
134 
136 {
138  LoginRecv::mWorlds.clear();
139 }
140 
142 {
143  if (data == nullptr)
144  return;
145 
146  logger->log("Username is %s", data->username.c_str());
147 
148  // Send login infos
149  if (data->registerLogin)
151  else
153 
154  const bool remember = data->remember;
155  if (remember)
156  {
157  serverConfig.setValue("username", data->username);
158 #ifdef SAVE_PASSWORD
159  serverConfig.setValue("password", data->password);
160 #endif
161  }
162  else
163  {
164  serverConfig.setValue("username", "");
165 #ifdef SAVE_PASSWORD
166  serverConfig.setValue("password", "");
167 #endif
168  }
169  serverConfig.setValue("remember", remember);
170 
171  // Clear the password, avoids auto login when returning to login
172  data->password.clear();
173 }
174 
176 {
177 }
178 
179 void LoginHandler::changeEmail(const std::string &email A_UNUSED) const
180 {
181 }
182 
183 void LoginHandler::unregisterAccount(const std::string &username A_UNUSED,
184  const std::string &password
185  A_UNUSED) const
186 {
187 }
188 
190 {
191  return LoginRecv::mToken;
192 }
193 
194 } // namespace Ea
LoginData::password
std::string password
Definition: logindata.h:59
Settings::serverName
std::string serverName
Definition: settings.h:113
State::REGISTER
@ REGISTER
Definition: state.h:53
cast.h
ServerInfo::althostname
std::string althostname
Definition: serverinfo.h:45
CAST_SIZE
#define CAST_SIZE
Definition: cast.h:33
Ea::LoginHandler::registerAccount
void registerAccount(const LoginData *const loginData) const
Definition: loginhandler.cpp:105
settings.h
Ea::LoginHandler::sendLoginRegister
virtual void sendLoginRegister(const std::string &username, const std::string &password, const std::string &email) const =0
logger.h
Ea::LoginHandler::isRegistrationEnabled
bool isRegistrationEnabled() const
Definition: loginhandler.cpp:57
Net::LoginHandler::mServer
ServerInfo mServer
Definition: loginhandler.h:115
loginrecv.h
Ea::LoginRecv::mRegistrationEnabled
bool mRegistrationEnabled
Definition: loginrecv.cpp:47
ServerInfo::port
uint16_t port
Definition: serverinfo.h:57
Token
Definition: token.h:29
settings
Settings settings
Definition: settings.cpp:31
loginhandler.h
Gender::MALE
@ MALE
Definition: gender.h:30
LoginData::username
std::string username
Definition: logindata.h:58
Gender::HIDDEN
@ HIDDEN
Definition: gender.h:33
Ea::LoginHandler::getToken
const Token & getToken() const A_CONST
Definition: loginhandler.cpp:189
A_UNUSED
#define A_UNUSED
Definition: localconsts.h:159
Ea::LoginHandler::unregisterAccount
void unregisterAccount(const std::string &username, const std::string &password) const
Definition: loginhandler.cpp:183
LoginData::email
std::string email
Definition: logindata.h:66
Gender::FEMALE
@ FEMALE
Definition: gender.h:31
Ea::LoginHandler::getRegistrationDetails
void getRegistrationDetails() const
Definition: loginhandler.cpp:62
Net
Definition: characterdisplay.h:36
Ea::LoginHandler
Definition: loginhandler.h:35
ServerInfo::hostname
std::string hostname
Definition: serverinfo.h:44
logger
Logger * logger
Definition: logger.cpp:88
Configuration::setValue
void setValue(const std::string &key, const std::string &value)
Definition: configuration.cpp:238
Ea::LoginHandler::~LoginHandler
~LoginHandler()
Definition: loginhandler.cpp:52
State::UPDATE
@ UPDATE
Definition: state.h:43
Client::setState
void setState(const StateT state)
Definition: client.h:65
ipToString
const char * ipToString(const uint32_t address)
Definition: stringutils.cpp:85
LoginData::gender
GenderT gender
Definition: logindata.h:70
Gender::UNSPECIFIED
@ UNSPECIFIED
Definition: gender.h:32
Ea::LoginHandler::clearWorlds
void clearWorlds() const
Definition: loginhandler.cpp:135
data
uint32_t data
Definition: maptypeproperty2.h:3
Ea::LoginRecv::mUpdateHost
std::string mUpdateHost
Definition: loginrecv.cpp:43
Ea::LoginHandler::chooseServer
void chooseServer(const unsigned int server, const bool persistentIp) const
Definition: loginhandler.cpp:77
Ea::LoginHandler::loginAccount
void loginAccount(LoginData *const loginData) const
Definition: loginhandler.cpp:68
Ea::LoginHandler::changeEmail
void changeEmail(const std::string &email) const
Definition: loginhandler.cpp:179
Ea::LoginHandler::loginOrRegister
void loginOrRegister(LoginData *const data) const
Definition: loginhandler.cpp:141
serverConfig
Configuration serverConfig
Definition: configuration.cpp:52
Ea::LoginRecv::mWorlds
Worlds mWorlds
Definition: loginrecv.cpp:44
config
Configuration config
Definition: configuration.cpp:51
LoginData
Definition: logindata.h:34
Ea::LoginRecv::mVersionResponse
bool mVersionResponse
Definition: loginrecv.cpp:46
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
EmoteDB::size
int size()
Definition: emotedb.cpp:305
Worlds
std::vector< WorldInfo * > Worlds
Definition: worldinfo.h:58
Ea
Definition: adminhandler.cpp:30
Ea::LoginHandler::getCharServer
virtual ServerInfo * getCharServer() const =0
configuration.h
client
Client * client
Definition: client.cpp:117
Token::clear
void clear()
Definition: token.h:45
Ea::LoginHandler::LoginHandler
LoginHandler()
Definition: loginhandler.cpp:42
Ea::LoginHandler::getWorlds
const Worlds & getWorlds() const A_CONST
Definition: loginhandler.cpp:130
LoginData::resetCharacterSlots
void resetCharacterSlots()
Definition: logindata.h:104
dtor.h
Ea::LoginHandler::logout
void logout() const
Definition: loginhandler.cpp:175
ServerInfo
Definition: serverinfo.h:36
logindata.h
Ea::LoginRecv::mToken
Token mToken
Definition: loginrecv.cpp:45
client.h
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268
debug.h
EAthena::charServer
ServerInfo charServer
Definition: charserverrecv.cpp:63
Configuration::getBoolValue
bool getBoolValue(const std::string &key) const
Definition: configuration.cpp:596