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

6
}  // namespace Ea