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