diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 11 | ||||
-rw-r--r-- | src/net/tradehandler.cpp | 43 | ||||
-rw-r--r-- | src/net/tradehandler.h | 18 |
3 files changed, 61 insertions, 11 deletions
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 |