ManaPlus
chatrecv.cpp
Go to the documentation of this file.
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 
33 
34 #include "gui/windows/chatwindow.h"
35 
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 {
50  time_t mMotdTime = 0;
51  bool mShowAllLang = false;
52  bool mShowMotd = false;
53  bool mSkipping = true;
54 } // namespace ChatRecv
55 
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 
72 {
73  std::string nick;
74  if (mSentWhispers.empty())
75  nick = "user";
76  else
77  nick = mSentWhispers.front();
78  return nick;
79 }
80 
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()),
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()),
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."),
118  }
119  break;
120  default:
122  break;
123  }
124  BLOCK_END("ChatRecv::processWhisperResponse")
125 }
126 
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)
139  else
141  }
142  BLOCK_END("ChatRecv::processMVPEffect")
143 }
144 
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:
164  break;
165  default:
168  break;
169  }
170  break;
171  }
172  case 1:
173  {
174  switch (fail)
175  {
176  case 0:
178  break;
179  default:
182  break;
183  }
184  break;
185  }
186  default:
187  // unknown result
188  break;
189  }
190  BLOCK_END("ChatRecv::processIgnoreAllResponse")
191 }
192 
193 } // namespace Ea
ActorManager * actorManager
int BeingId
Definition: beingid.h:30
ChatTab * localChatTab
Definition: chattab.cpp:62
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
Being * findBeing(const BeingId id) const
Definition: being.h:96
const std::string & getName() const
Definition: being.h:232
void addWhisper(const std::string &nick, const std::string &mes, const ChatMsgTypeT own)
bool getBoolValue(const std::string &key) const
Configuration config
#define _(s)
Definition: gettext.h:35
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
bool msg(InputEvent &event)
Definition: chat.cpp:39
bool mShowAllLang
Definition: chatrecv.cpp:51
time_t mMotdTime
Definition: chatrecv.cpp:50
void processWhisperResponseContinue(Net::MessageIn &msg, const uint8_t type)
Definition: chatrecv.cpp:81
bool mShowMotd
Definition: chatrecv.cpp:52
std::string getPopLastWhisperNick()
Definition: chatrecv.cpp:56
void processIgnoreAllResponse(Net::MessageIn &msg)
Definition: chatrecv.cpp:145
std::string getLastWhisperNick()
Definition: chatrecv.cpp:71
bool mSkipping
Definition: chatrecv.cpp:53
WhisperQueue mSentWhispers
Definition: chatrecv.cpp:49
void processMVPEffect(Net::MessageIn &msg)
Definition: chatrecv.cpp:127
std::queue< std::string > WhisperQueue
Definition: chathandler.h:34
void notify(const unsigned int message)
@ WHISPERS_IGNORE_FAILED
Definition: notifytypes.h:104
@ WHISPERS_UNIGNORE_FAILED
Definition: notifytypes.h:106
@ WHISPERS_UNIGNORED
Definition: notifytypes.h:105
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
std::string strprintf(const char *const format,...)