GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/loginhandler.cpp Lines: 0 61 0.0 %
Date: 2017-11-29 Branches: 0 52 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-2017  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
101
    client->setState(State::UPDATE);
102
}
103
104
void LoginHandler::registerAccount(const LoginData *const loginData1) const
105
{
106
    if (loginData1 == nullptr)
107
        return;
108
109
    std::string username = loginData1->username;
110
    switch (loginData1->gender)
111
    {
112
        case Gender::FEMALE:
113
            username.append("_F");
114
            break;
115
        case Gender::MALE:
116
            username.append("_M");
117
            break;
118
        case Gender::OTHER:
119
            username.append("_O");
120
            break;
121
        case Gender::UNSPECIFIED:
122
        default:
123
            break;
124
    }
125
126
    sendLoginRegister(username, loginData1->password, loginData1->email);
127
}
128
129
const Worlds &LoginHandler::getWorlds() const
130
{
131
    return LoginRecv::mWorlds;
132
}
133
134
void LoginHandler::clearWorlds() const
135
{
136
    delete_all(LoginRecv::mWorlds);
137
    LoginRecv::mWorlds.clear();
138
}
139
140
void LoginHandler::loginOrRegister(LoginData *const data) const
141
{
142
    if (data == nullptr)
143
        return;
144
145
    logger->log("Username is %s", data->username.c_str());
146
147
    // Send login infos
148
    if (data->registerLogin)
149
        registerAccount(data);
150
    else
151
        loginAccount(data);
152
153
    // Clear the password, avoids auto login when returning to login
154
    data->password.clear();
155
156
    const bool remember = data->remember;
157
    if (remember)
158
        serverConfig.setValue("username", data->username);
159
    else
160
        serverConfig.setValue("username", "");
161
    serverConfig.setValue("remember", remember);
162
}
163
164
void LoginHandler::logout() const
165
{
166
}
167
168
void LoginHandler::changeEmail(const std::string &email A_UNUSED) const
169
{
170
}
171
172
void LoginHandler::unregisterAccount(const std::string &username A_UNUSED,
173
                                     const std::string &password
174
                                     A_UNUSED) const
175
{
176
}
177
178
const Token &LoginHandler::getToken() const
179
{
180
    return LoginRecv::mToken;
181
}
182
183
}  // namespace Ea