diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/game.cpp | 11 | ||||
-rw-r--r-- | src/net/tradehandler.cpp | 43 | ||||
-rw-r--r-- | src/net/tradehandler.h | 18 |
4 files changed, 68 insertions, 12 deletions
@@ -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 |