GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/ea/chatrecv.cpp Lines: 2 52 3.8 %
Date: 2021-03-17 Branches: 2 62 3.2 %

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

3
}  // namespace Ea