GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/loginrecv.cpp Lines: 3 33 9.1 %
Date: 2021-03-17 Branches: 2 21 9.5 %

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
 *  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/ea/loginrecv.h"
25
26
#include "client.h"
27
28
#include "fs/paths.h"
29
30
#include "gui/windows/logindialog.h"
31
32
#include "utils/gettext.h"
33
34
#include "net/logindata.h"
35
#include "net/messagein.h"
36
37
#include "debug.h"
38
39
namespace Ea
40
{
41
42
namespace LoginRecv
43
{
44
1
    std::string mUpdateHost;
45
1
    Worlds mWorlds;
46
    Token mToken;
47
    bool mVersionResponse = false;
48
    bool mRegistrationEnabled = true;
49
}  // namespace LoginRecv
50
51
void LoginRecv::processUpdateHost(Net::MessageIn &msg)
52
{
53
    const int len = msg.readInt16("len") - 4;
54
    mUpdateHost = msg.readString(len, "update host");
55
56
    if (!checkPath(mUpdateHost))
57
    {
58
        mUpdateHost.clear();
59
        logger->log1("Warning: incorrect update server name");
60
    }
61
    loginData.updateHost = mUpdateHost;
62
63
    logger->log("Received update host \"%s\" from login server.",
64
        mUpdateHost.c_str());
65
}
66
67
void LoginRecv::processLoginError(Net::MessageIn &msg)
68
{
69
    const uint8_t code = msg.readUInt8("error");
70
    logger->log("Login::error code: %u", CAST_U32(code));
71
    std::string date = msg.readString(20, "date");
72
73
    switch (code)
74
    {
75
        case 0:
76
            // TRANSLATORS: error message
77
            errorMessage = _("Unregistered ID.");
78
            break;
79
        case 1:
80
            // TRANSLATORS: error message
81
            errorMessage = _("Wrong password.");
82
            LoginDialog::savedPassword.clear();
83
            break;
84
        case 2:
85
            // TRANSLATORS: error message
86
            errorMessage = _("Account expired.");
87
            break;
88
        case 3:
89
            // TRANSLATORS: error message
90
            errorMessage = _("Rejected from server.");
91
            break;
92
        case 4:
93
            // TRANSLATORS: error message
94
            errorMessage = _("You have been permanently banned from "
95
                              "the game. Please contact the GM team.");
96
            break;
97
        case 5:
98
            // TRANSLATORS: error message
99
            errorMessage = _("Client too old or wrong server type.\n"
100
                "Please update client on http://manaplus.org");
101
            break;
102
        case 6:
103
            // TRANSLATORS: error message
104
            errorMessage = strprintf(_("You have been temporarily "
105
                "banned from the game until %s.\nPlease contact the GM "
106
                "team via the forums."), date.c_str());
107
            break;
108
        case 7:
109
            // TRANSLATORS: error message
110
            errorMessage = _("Server overpopulated.");
111
            break;
112
        case 9:
113
            // TRANSLATORS: error message
114
            errorMessage = _("This user name is already taken.");
115
            break;
116
        case 10:
117
            // TRANSLATORS: error message
118
            errorMessage = _("Wrong name.");
119
            break;
120
        case 11:
121
            // TRANSLATORS: error message
122
            errorMessage = _("Incorrect email.");
123
            break;
124
        case 99:
125
            // TRANSLATORS: error message
126
            errorMessage = _("Username permanently erased.");
127
            break;
128
        default:
129
            // TRANSLATORS: error message
130
            errorMessage = _("Unknown error.");
131
            break;
132
    }
133
    client->setState(State::ERROR);
134
}
135
136

3
}  // namespace Ea