GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/charserverrecv.cpp Lines: 1 28 3.6 %
Date: 2021-03-17 Branches: 0 32 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
 *  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/charserverrecv.h"
25
26
#include "client.h"
27
28
#include "gui/windows/charcreatedialog.h"
29
#include "gui/windows/okdialog.h"
30
31
#include "gui/widgets/createwidget.h"
32
33
#include "net/character.h"
34
#include "net/charserverhandler.h"
35
#include "net/messagein.h"
36
37
#include "utils/gettext.h"
38
39
#include "debug.h"
40
41
namespace Ea
42
{
43
44
void CharServerRecv::processCharLoginError(Net::MessageIn &msg)
45
{
46
    BLOCK_START("CharServerRecv::processCharLoginError")
47
    switch (msg.readUInt8("error"))
48
    {
49
        case 0:
50
            // TRANSLATORS: error message
51
            errorMessage = _("Access denied. Most likely, there are "
52
                             "too many players on this server.");
53
            break;
54
        case 1:
55
            // TRANSLATORS: error message
56
            errorMessage = _("Cannot use this ID.");
57
            break;
58
        default:
59
            // TRANSLATORS: error message
60
            errorMessage = _("Unknown char-server failure.");
61
            break;
62
    }
63
    client->setState(State::ERROR);
64
    BLOCK_END("CharServerRecv::processCharLoginError")
65
}
66
67
void CharServerRecv::processCharCreateFailed(Net::MessageIn &msg)
68
{
69
    BLOCK_START("CharServerRecv::processCharCreateFailed")
70
    switch (msg.readUInt8("error"))
71
    {
72
        case 1:
73
        case 0:
74
        default:
75
            // TRANSLATORS: error message
76
            errorMessage = _("Failed to create character. Most "
77
                "likely the name is already taken.");
78
            break;
79
        case 2:
80
            // TRANSLATORS: error message
81
            errorMessage = _("Wrong name.");
82
            break;
83
        case 3:
84
            // TRANSLATORS: error message
85
            errorMessage = _("Incorrect stats.");
86
            break;
87
        case 4:
88
            // TRANSLATORS: error message
89
            errorMessage = _("Incorrect hair.");
90
            break;
91
        case 5:
92
            // TRANSLATORS: error message
93
            errorMessage = _("Incorrect slot.");
94
            break;
95
        case 6:
96
            // TRANSLATORS: error message
97
            errorMessage = _("Incorrect race.");
98
            break;
99
        case 7:
100
            // TRANSLATORS: error message
101
            errorMessage = _("Incorrect look.");
102
            break;
103
    }
104
    CREATEWIDGET(OkDialog,
105
        // TRANSLATORS: error message header
106
        _("Error"),
107
        errorMessage,
108
        // TRANSLATORS: ok dialog button
109
        _("OK"),
110
        DialogType::ERROR,
111
        Modal_true,
112
        ShowCenter_true,
113
        nullptr,
114
        260);
115
    if (Net::CharServerHandler::mCharCreateDialog != nullptr)
116
        Net::CharServerHandler::mCharCreateDialog->unlock();
117
    BLOCK_END("CharServerRecv::processCharCreateFailed")
118
}
119
120
void CharServerRecv::processCharDelete(Net::MessageIn &msg A_UNUSED)
121
{
122
    BLOCK_START("CharServerRecv::processCharDelete")
123
    Net::CharServerHandler::mCharacters.remove(
124
        Net::CharServerHandler::mSelectedCharacter);
125
    delete Net::CharServerHandler::mSelectedCharacter;
126
    Net::CharServerHandler::mSelectedCharacter = nullptr;
127
    Net::CharServerHandler::updateCharSelectDialog();
128
    Net::CharServerHandler::unlockCharSelectDialog();
129
    CREATEWIDGET(OkDialog,
130
        // TRANSLATORS: info message header
131
        _("Info"),
132
        // TRANSLATORS: info message
133
        _("Character deleted."),
134
        // TRANSLATORS: ok dialog button
135
        _("OK"),
136
        DialogType::OK,
137
        Modal_true,
138
        ShowCenter_true,
139
        nullptr,
140
        260);
141
    BLOCK_END("CharServerRecv::processCharDelete")
142
}
143
144
2
}  // namespace Ea