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