GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/loginhandler.cpp Lines: 0 59 0.0 %
Date: 2020-06-04 Branches: 0 48 0.0 %

Line Branch Exec Source
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
42
LoginHandler::LoginHandler() :
43
    Net::LoginHandler()
44
{
45
    LoginRecv::mVersionResponse = false;
46
    LoginRecv::mRegistrationEnabled = true;
47
    LoginRecv::mUpdateHost.clear();
48
    LoginRecv::mWorlds.clear();
49
    LoginRecv::mToken.clear();
50
}
51
52
LoginHandler::~LoginHandler()
53
{
54
    delete_all(LoginRecv::mWorlds);
55
}
56
57
bool LoginHandler::isRegistrationEnabled() const
58
{
59
    return LoginRecv::mRegistrationEnabled;
60
}
61
62
void LoginHandler::getRegistrationDetails() const
63
{
64
    // Not supported, so move on
65
    client->setState(State::REGISTER);
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
86
    ServerInfo *const charServer = getCharServer();
87
    if (charServer != nullptr)
88
    {
89
        if (config.getBoolValue("usePersistentIP") || persistentIp)
90
        {
91
            charServer->hostname = settings.serverName;
92
        }
93
        else
94
        {
95
            charServer->hostname = ipToString(
96
                LoginRecv::mWorlds[server]->address);
97
        }
98
        charServer->port = LoginRecv::mWorlds[server]->port;
99
    }
100
    charServer->althostname = mServer.althostname;
101
102
    client->setState(State::UPDATE);
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
130
const Worlds &LoginHandler::getWorlds() const
131
{
132
    return LoginRecv::mWorlds;
133
}
134
135
void LoginHandler::clearWorlds() const
136
{
137
    delete_all(LoginRecv::mWorlds);
138
    LoginRecv::mWorlds.clear();
139
}
140
141
void LoginHandler::loginOrRegister(LoginData *const data) const
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)
150
        registerAccount(data);
151
    else
152
        loginAccount(data);
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
175
void LoginHandler::logout() const
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
189
const Token &LoginHandler::getToken() const
190
{
191
    return LoginRecv::mToken;
192
}
193
194
}  // namespace Ea