ManaPlus
traderecv.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-2018 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/traderecv.h"
24 
25 #include "notifymanager.h"
26 
27 #include "being/playerinfo.h"
28 #include "being/playerrelation.h"
29 
30 #include "const/sound.h"
31 
33 
35 
37 
38 #include "net/messagein.h"
39 
40 #include "utils/gettext.h"
41 #include "utils/stringutils.h"
42 
44 
45 #include "debug.h"
46 
47 
49 
53 namespace
54 {
56 } // namespace
57 
58 namespace Ea
59 {
60 
62 {
63  switch (type)
64  {
65  case 0: // Too far away
68  break;
69  case 1: // Character doesn't exist
72  break;
73  case 2: // Invite request check failed...
75  break;
76  case 3: // Trade accepted
77  if (tradeWindow != nullptr)
78  {
79  tradeWindow->reset();
80  // TRANSLATORS: trade header
81  tradeWindow->setCaption(strprintf(_("Trade: You and %s"),
82  tradePartnerName.c_str()));
85  }
86  break;
87  case 4: // Trade cancelled
90  {
93  }
94  // otherwise ignore silently
95 
96  if (tradeWindow != nullptr)
97  {
99 // tradeWindow->clear();
100  }
102  break;
103  case 5:
106  break;
107  default: // Shouldn't happen as well, but to be sure
110  if (tradeWindow != nullptr)
111  tradeWindow->clear();
112  break;
113  }
114 }
115 
117 {
118  // 0 means ok from myself, 1 means ok from other;
119  if (tradeWindow != nullptr)
120  tradeWindow->receivedOk(msg.readUInt8("status") == 0U);
121  else
122  msg.readUInt8("status");
123 }
124 
126 {
128  if (tradeWindow != nullptr)
129  {
131  tradeWindow->reset();
132  }
134 }
135 
137 {
139  if (tradeWindow != nullptr)
142 }
143 
144 void TradeRecv::processTradeRequestContinue(const std::string &partner)
145 {
146  if (playerRelations.hasPermission(partner,
148  {
149  if (PlayerInfo::isTrading() == Trading_true || (confirmDlg != nullptr))
150  {
151  tradeHandler->respond(false);
152  return;
153  }
154 
155  tradePartnerName = partner;
157  if (tradeWindow != nullptr)
158  {
160  != tradePartnerName)
161  {
162  tradeWindow->clear();
163  CREATEWIDGETV(confirmDlg, ConfirmDialog,
164  // TRANSLATORS: trade message
165  _("Request for Trade"),
166  // TRANSLATORS: trade message
167  strprintf(_("%s wants to trade with you, do"
168  " you accept?"), tradePartnerName.c_str()),
170  true,
171  Modal_false,
172  nullptr);
173  confirmDlg->addActionListener(&listener);
174  }
175  else
176  {
177  tradeHandler->respond(true);
178  }
179  }
180  }
181  else
182  {
183  tradeHandler->respond(false);
184  return;
185  }
186 }
187 
188 } // namespace Ea
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:98
#define _(s)
Definition: gettext.h:34
TradeWindow * tradeWindow
Definition: tradewindow.cpp:64
const bool Visible_true
Definition: visible.h:29
const bool Trading_false
Definition: trading.h:29
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
static const std::string SOUND_REQUEST
Definition: sound.h:28
std::string tradePartnerName
Definition: popupmenu.cpp:100
bool msg(InputEvent &event)
Definition: chat.cpp:38
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
void notify(const unsigned int message)
static const unsigned int TRADE
void processTradeRequestContinue(const std::string &partner)
Definition: traderecv.cpp:144
void completeTrade()
bool hasPermission(const Being *const being, const unsigned int flags) const
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
const bool Visible_false
Definition: visible.h:29
RequestTradeListener listener
Definition: traderecv.cpp:55
virtual void respond(const bool accept) const
Definition: tradehandler.h:48
void processTradeComplete(Net::MessageIn &msg)
Definition: traderecv.cpp:136
void processTradeOk(Net::MessageIn &msg)
Definition: traderecv.cpp:116
void receivedOk(const bool own)
void initTrade(const std::string &nick)
std::string getAutoTradeNick() const
Definition: tradewindow.h:166
#define A_UNUSED
Definition: localconsts.h:151
virtual void setVisible(Visible visible)
Definition: window.cpp:773
static const unsigned int SPEECH_LOG
Net::TradeHandler * tradeHandler
Definition: net.cpp:94
void processTradeCancel(Net::MessageIn &msg)
Definition: traderecv.cpp:125
const bool Trading_true
Definition: trading.h:29
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:48
void setCaption(const std::string &caption)
Definition: window.h:530
PlayerRelationsManager playerRelations
void processTradeResponseContinue(const uint8_t type)
Definition: traderecv.cpp:61
Trading isTrading()
Definition: playerinfo.cpp:388
void setTrading(const Trading trading)
Definition: playerinfo.cpp:393