GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/chatrecv.cpp Lines: 2 59 3.4 %
Date: 2017-11-29 Branches: 2 60 3.3 %

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/chatrecv.h"
24
25
#include "actormanager.h"
26
#include "configuration.h"
27
#include "notifymanager.h"
28
29
#include "being/being.h"
30
31
#include "enums/resources/notifytypes.h"
32
33
#include "gui/windows/chatwindow.h"
34
35
#include "gui/widgets/tabs/chat/chattab.h"
36
37
#include "net/messagein.h"
38
39
#include "utils/gettext.h"
40
41
#include "debug.h"
42
43
namespace Ea
44
{
45
46
namespace ChatRecv
47
{
48
2
    WhisperQueue mSentWhispers;
49
    time_t mMotdTime = 0;
50
    bool mShowAllLang = false;
51
    bool mShowMotd = false;
52
    bool mSkipping = true;
53
}  // namespace ChatRecv
54
55
std::string ChatRecv::getPopLastWhisperNick()
56
{
57
    std::string nick;
58
    if (mSentWhispers.empty())
59
    {
60
        nick = "user";
61
    }
62
    else
63
    {
64
        nick = mSentWhispers.front();
65
        mSentWhispers.pop();
66
    }
67
    return nick;
68
}
69
70
std::string ChatRecv::getLastWhisperNick()
71
{
72
    std::string nick;
73
    if (mSentWhispers.empty())
74
        nick = "user";
75
    else
76
        nick = mSentWhispers.front();
77
    return nick;
78
}
79
80
void ChatRecv::processWhisperResponseContinue(Net::MessageIn &msg,
81
                                              const uint8_t type)
82
{
83
    const std::string nick = getPopLastWhisperNick();
84
    switch (type)
85
    {
86
        case 0x00:
87
            // Success (don't need to report)
88
            break;
89
        case 0x01:
90
            if (chatWindow != nullptr)
91
            {
92
                chatWindow->addWhisper(nick,
93
                    // TRANSLATORS: chat message
94
                    strprintf(_("Whisper could not be sent, %s is offline."),
95
                        nick.c_str()),
96
                        ChatMsgType::BY_SERVER);
97
            }
98
            break;
99
        case 0x02:
100
            if (chatWindow != nullptr)
101
            {
102
                chatWindow->addWhisper(nick,
103
                    // TRANSLATORS: chat message
104
                    strprintf(_("Whisper could not "
105
                    "be sent, ignored by %s."), nick.c_str()),
106
                    ChatMsgType::BY_SERVER);
107
            }
108
            break;
109
        case 0x03:
110
            if (chatWindow != nullptr)
111
            {
112
                chatWindow->addWhisper(nick,
113
                    // TRANSLATORS: chat message
114
                    _("Whisper could not "
115
                    "be sent, you ignored by all players."),
116
                    ChatMsgType::BY_SERVER);
117
            }
118
            break;
119
        default:
120
            UNIMPLEMENTEDPACKETFIELD(type);
121
            break;
122
    }
123
    BLOCK_END("ChatRecv::processWhisperResponse")
124
}
125
126
void ChatRecv::processMVPEffect(Net::MessageIn &msg)
127
{
128
    BLOCK_START("ChatRecv::processMVPEffect")
129
    // Display MVP player
130
    const BeingId id = msg.readBeingId("being id");
131
    if (localChatTab != nullptr &&
132
        actorManager != nullptr &&
133
        config.getBoolValue("showMVP"))
134
    {
135
        const Being *const being = actorManager->findBeing(id);
136
        if (being == nullptr)
137
            NotifyManager::notify(NotifyTypes::MVP_PLAYER, "");
138
        else
139
            NotifyManager::notify(NotifyTypes::MVP_PLAYER, being->getName());
140
    }
141
    BLOCK_END("ChatRecv::processMVPEffect")
142
}
143
144
void ChatRecv::processIgnoreAllResponse(Net::MessageIn &msg)
145
{
146
    BLOCK_START("ChatRecv::processIgnoreAllResponse")
147
    const uint8_t action = msg.readUInt8("action");
148
    const uint8_t fail = msg.readUInt8("result");
149
    if (localChatTab == nullptr)
150
    {
151
        BLOCK_END("ChatRecv::processIgnoreAllResponse")
152
        return;
153
    }
154
155
    switch (action)
156
    {
157
        case 0:
158
        {
159
            switch (fail)
160
            {
161
                case 0:
162
                    NotifyManager::notify(NotifyTypes::WHISPERS_IGNORED);
163
                    break;
164
                default:
165
                    NotifyManager::notify(NotifyTypes::
166
                        WHISPERS_IGNORE_FAILED);
167
                    break;
168
            }
169
            break;
170
        }
171
        case 1:
172
        {
173
            switch (fail)
174
            {
175
                case 0:
176
                    NotifyManager::notify(NotifyTypes::WHISPERS_UNIGNORED);
177
                    break;
178
                default:
179
                    NotifyManager::notify(NotifyTypes::
180
                        WHISPERS_UNIGNORE_FAILED);
181
                    break;
182
            }
183
            break;
184
        }
185
        default:
186
            // unknown result
187
            break;
188
    }
189
    BLOCK_END("ChatRecv::processIgnoreAllResponse")
190
}
191
192

6
}  // namespace Ea