summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-10-18 10:56:40 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-10-18 10:56:40 +0000
commit8e0634da5736489ce5da5ab2ba9802c6c11e73cf (patch)
treea295338f18915022322664b46c22377093a3cbf3
parentd7bf8a4b11a88d2fc49fbe996c22ca5512d25e75 (diff)
downloadmana-client-8e0634da5736489ce5da5ab2ba9802c6c11e73cf.tar.gz
mana-client-8e0634da5736489ce5da5ab2ba9802c6c11e73cf.tar.bz2
mana-client-8e0634da5736489ce5da5ab2ba9802c6c11e73cf.tar.xz
mana-client-8e0634da5736489ce5da5ab2ba9802c6c11e73cf.zip
Implemented automatic denying of trade requests based on a patch
submitted by Quiche_on_a_leash.
-rw-r--r--ChangeLog8
-rw-r--r--src/game.cpp11
-rw-r--r--src/net/tradehandler.cpp43
-rw-r--r--src/net/tradehandler.h18
4 files changed, 68 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 6dd39259..44f6698c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
-2007-10-07 Philipp Sehmisch <tmw@crushnet.org>
+2007-10-18 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/game.cpp, src/net/tradehandler.h, src/net/tradehandler.cpp:
+ Implemented automatic denying of trade requests based on a patch
+ submitted by Quiche_on_a_leash.
+
+2007-10-07 Philipp Sehmisch <tmw@crushnet.org>
* data/graphics/maps/new_18-1.tmx: Fixed some collision layer problems.
diff --git a/src/game.cpp b/src/game.cpp
index ca6f4993..e8feb3ea 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -614,6 +614,17 @@ void Game::handleInput()
viewport->toggleDebugPath();
used = true;
break;
+
+ case SDLK_t:
+ // Toggle accepting of incoming trade requests
+ {
+ TradeHandler *th = static_cast<TradeHandler*>(
+ mTradeHandler.get());
+ th->setAcceptTradeRequests(
+ !th->acceptTradeRequests());
+ }
+ used = true;
+ break;
}
// Emotions
diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp
index 0b4cb512..57060684 100644
--- a/src/net/tradehandler.cpp
+++ b/src/net/tradehandler.cpp
@@ -48,7 +48,8 @@ namespace {
} listener;
}
-TradeHandler::TradeHandler()
+TradeHandler::TradeHandler():
+ mAcceptTradeRequests(true)
{
static const Uint16 _messages[] = {
SMSG_TRADE_REQUEST,
@@ -63,6 +64,16 @@ TradeHandler::TradeHandler()
handledMessages = _messages;
}
+void TradeHandler::setAcceptTradeRequests(bool acceptTradeRequests)
+{
+ mAcceptTradeRequests = acceptTradeRequests;
+ if (mAcceptTradeRequests) {
+ chatWindow->chatLog("Accepting incoming trade requests", BY_SERVER);
+ } else {
+ chatWindow->chatLog("Ignoring incoming trade requests", BY_SERVER);
+ }
+}
+
void TradeHandler::handleMessage(MessageIn *msg)
{
switch (msg->getId())
@@ -74,19 +85,28 @@ void TradeHandler::handleMessage(MessageIn *msg)
// Note that it would be nice if the server would prevent this
// situation, and that the requesting player would get a
// special message about the player being occupied.
- if (!player_node->tradeRequestOk())
+ tradePartnerName = msg->readString(24);
+
+ if (mAcceptTradeRequests)
+ {
+ if (!player_node->tradeRequestOk())
+ {
+ player_node->tradeReply(false);
+ break;
+ }
+
+ player_node->setTrading(true);
+ ConfirmDialog *dlg;
+ dlg = new ConfirmDialog("Request for trade",
+ tradePartnerName +
+ " wants to trade with you, do you accept?");
+ dlg->addActionListener(&listener);
+ }
+ else
{
player_node->tradeReply(false);
break;
}
-
- player_node->setTrading(true);
- tradePartnerName = msg->readString(24);
- ConfirmDialog *dlg;
- dlg = new ConfirmDialog("Request for trade",
- tradePartnerName +
- " wants to trade with you, do you accept?");
- dlg->addActionListener(&listener);
break;
case SMSG_TRADE_RESPONSE:
@@ -113,7 +133,8 @@ void TradeHandler::handleMessage(MessageIn *msg)
tradeWindow->setVisible(true);
break;
case 4: // Trade cancelled
- chatWindow->chatLog("Trade cancelled.", BY_SERVER);
+ chatWindow->chatLog("Trade with " + tradePartnerName +
+ " cancelled", BY_SERVER);
tradeWindow->setVisible(false);
player_node->setTrading(false);
break;
diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h
index a1971004..00f2cf38 100644
--- a/src/net/tradehandler.h
+++ b/src/net/tradehandler.h
@@ -34,6 +34,24 @@ class TradeHandler : public MessageHandler
TradeHandler();
void handleMessage(MessageIn *msg);
+
+ /**
+ * Returns whether trade requests are accepted.
+ *
+ * @see setAcceptTradeRequests
+ */
+ bool acceptTradeRequests() const
+ { return mAcceptTradeRequests; }
+
+ /**
+ * Sets whether trade requests are accepted. When set to false, trade
+ * requests are automatically denied. When true, a popup will ask the
+ * player whether he wants to trade.
+ */
+ void setAcceptTradeRequests(bool acceptTradeRequests);
+
+ private:
+ bool mAcceptTradeRequests;
};
#endif