summaryrefslogtreecommitdiff
path: root/src/net/tradehandler.cpp
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-29 17:08:58 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-29 17:08:58 +0000
commit69dfa053e2d3fc50703338bb2865c33d966dda16 (patch)
treee1ba3f9fda1f3cc4a0a9b09f6f162da399a3eb2a /src/net/tradehandler.cpp
parentd61fdaf1932724f86a68484c4a05195ca270646e (diff)
downloadmana-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.gz
mana-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.bz2
mana-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.xz
mana-69dfa053e2d3fc50703338bb2865c33d966dda16.zip
Converted trading to new server.
Diffstat (limited to 'src/net/tradehandler.cpp')
-rw-r--r--src/net/tradehandler.cpp73
1 files changed, 64 insertions, 9 deletions
diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp
index b3e80675..3bf312fc 100644
--- a/src/net/tradehandler.cpp
+++ b/src/net/tradehandler.cpp
@@ -26,6 +26,9 @@
#include "messagein.h"
#include "protocol.h"
+#include "gameserver/player.h"
+
+#include "../beingmanager.h"
#include "../item.h"
#include "../localplayer.h"
@@ -34,6 +37,7 @@
#include "../gui/trade.h"
std::string tradePartnerName;
+int tradePartnerID;
/**
* Listener for request trade dialogs
@@ -43,21 +47,23 @@ namespace {
{
void action(const gcn::ActionEvent &event)
{
- player_node->tradeReply(event.getId() == "yes");
- };
+ if (event.getId() == "yes")
+ Net::GameServer::Player::requestTrade(tradePartnerID);
+ else
+ Net::GameServer::Player::acceptTrade(false);
+ }
} listener;
}
TradeHandler::TradeHandler()
{
static const Uint16 _messages[] = {
- SMSG_TRADE_REQUEST,
- SMSG_TRADE_RESPONSE,
- SMSG_TRADE_ITEM_ADD,
- SMSG_TRADE_ITEM_ADD_RESPONSE,
- SMSG_TRADE_OK,
- SMSG_TRADE_CANCEL,
- SMSG_TRADE_COMPLETE,
+ GPMSG_TRADE_REQUEST,
+ GPMSG_TRADE_CANCEL,
+ GPMSG_TRADE_START,
+ GPMSG_TRADE_COMPLETE,
+ GPMSG_TRADE_ACCEPT,
+ GPMSG_TRADE_ADD_ITEM,
0
};
handledMessages = _messages;
@@ -67,6 +73,7 @@ void TradeHandler::handleMessage(MessageIn &msg)
{
switch (msg.getId())
{
+#if 0
case SMSG_TRADE_REQUEST:
// If a trade window or request window is already open, send a
// trade cancel to any other trade request.
@@ -191,5 +198,53 @@ void TradeHandler::handleMessage(MessageIn &msg)
tradeWindow->reset();
player_node->setTrading(false);
break;
+#endif
+
+ case GPMSG_TRADE_REQUEST:
+ {
+ Being *being = beingManager->findBeing(msg.readShort());
+ if (!being)
+ {
+ Net::GameServer::Player::acceptTrade(false);
+ break;
+ }
+ player_node->setTrading(true);
+ tradePartnerName = being->getName();
+ tradePartnerID = being->getId();
+ ConfirmDialog *dlg = new ConfirmDialog("Request for trade",
+ tradePartnerName + " wants to trade with you, do you accept?");
+ dlg->addActionListener(&listener);
+ } break;
+
+ case GPMSG_TRADE_ADD_ITEM:
+ {
+ int type = msg.readShort();
+ int amount = msg.readByte();
+ tradeWindow->addItem(type, false, amount, false);
+ } break;
+
+ case GPMSG_TRADE_START:
+ tradeWindow->reset();
+ tradeWindow->setCaption("Trading with " + tradePartnerName);
+ tradeWindow->setVisible(true);
+ break;
+
+ case GPMSG_TRADE_ACCEPT:
+ tradeWindow->receivedOk(false);
+ break;
+
+ case GPMSG_TRADE_CANCEL:
+ chatWindow->chatLog("Trade canceled.", BY_SERVER);
+ tradeWindow->setVisible(false);
+ tradeWindow->reset();
+ player_node->setTrading(false);
+ break;
+
+ case GPMSG_TRADE_COMPLETE:
+ chatWindow->chatLog("Trade completed.", BY_SERVER);
+ tradeWindow->setVisible(false);
+ tradeWindow->reset();
+ player_node->setTrading(false);
+ break;
}
}