summaryrefslogtreecommitdiff
path: root/src/net/tmwserv
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-04-03 07:39:18 -0600
committerJared Adams <jaxad0127@gmail.com>2009-04-03 07:39:18 -0600
commit754cc498156371d0b6d32de0e58d7256236ed676 (patch)
tree54abf2170a48e72dffdf8a2ba7ded5386fc28813 /src/net/tmwserv
parentd13b3eaca82e3547c84f60b9b135464ff3a51cf0 (diff)
downloadmana-754cc498156371d0b6d32de0e58d7256236ed676.tar.gz
mana-754cc498156371d0b6d32de0e58d7256236ed676.tar.bz2
mana-754cc498156371d0b6d32de0e58d7256236ed676.tar.xz
mana-754cc498156371d0b6d32de0e58d7256236ed676.zip
Fill in TMWServ's TradeHandler
Also started temparary implementation of the Net::getXHandler() methods and started using them.
Diffstat (limited to 'src/net/tmwserv')
-rw-r--r--src/net/tmwserv/inventoryhandler.cpp3
-rw-r--r--src/net/tmwserv/inventoryhandler.h2
-rw-r--r--src/net/tmwserv/playerhandler.cpp3
-rw-r--r--src/net/tmwserv/playerhandler.h2
-rw-r--r--src/net/tmwserv/tradehandler.cpp49
-rw-r--r--src/net/tmwserv/tradehandler.h21
6 files changed, 79 insertions, 1 deletions
diff --git a/src/net/tmwserv/inventoryhandler.cpp b/src/net/tmwserv/inventoryhandler.cpp
index a342c1d3..cedeb465 100644
--- a/src/net/tmwserv/inventoryhandler.cpp
+++ b/src/net/tmwserv/inventoryhandler.cpp
@@ -37,6 +37,8 @@
#include "resources/iteminfo.h"
+Net::InventoryHandler *inventoryHandler;
+
InventoryHandler::InventoryHandler()
{
static const Uint16 _messages[] = {
@@ -45,6 +47,7 @@ InventoryHandler::InventoryHandler()
0
};
handledMessages = _messages;
+ inventoryHandler = this;
}
void InventoryHandler::handleMessage(MessageIn &msg)
diff --git a/src/net/tmwserv/inventoryhandler.h b/src/net/tmwserv/inventoryhandler.h
index 3d7fce1a..5dd788ef 100644
--- a/src/net/tmwserv/inventoryhandler.h
+++ b/src/net/tmwserv/inventoryhandler.h
@@ -50,4 +50,6 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler
StorageType destination);
};
+extern Net::InventoryHandler *inventoryHandler;
+
#endif
diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp
index 4643dd8a..a02c9a29 100644
--- a/src/net/tmwserv/playerhandler.cpp
+++ b/src/net/tmwserv/playerhandler.cpp
@@ -93,6 +93,8 @@ namespace {
} deathListener;
}
+Net::PlayerHandler *playerHandler;
+
PlayerHandler::PlayerHandler()
{
static const Uint16 _messages[] = {
@@ -107,6 +109,7 @@ PlayerHandler::PlayerHandler()
0
};
handledMessages = _messages;
+ playerHandler = this;
}
void PlayerHandler::handleMessage(MessageIn &msg)
diff --git a/src/net/tmwserv/playerhandler.h b/src/net/tmwserv/playerhandler.h
index 572c8712..17b1f684 100644
--- a/src/net/tmwserv/playerhandler.h
+++ b/src/net/tmwserv/playerhandler.h
@@ -58,4 +58,6 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler
void handleMapChangeMessage(MessageIn &msg);
};
+extern Net::PlayerHandler *playerHandler;
+
#endif
diff --git a/src/net/tmwserv/tradehandler.cpp b/src/net/tmwserv/tradehandler.cpp
index 8b3e06c6..07ed81e6 100644
--- a/src/net/tmwserv/tradehandler.cpp
+++ b/src/net/tmwserv/tradehandler.cpp
@@ -54,6 +54,8 @@ namespace {
} listener;
}
+Net::TradeHandler *tradeHandler;
+
TradeHandler::TradeHandler():
mAcceptTradeRequests(true)
{
@@ -68,6 +70,7 @@ TradeHandler::TradeHandler():
0
};
handledMessages = _messages;
+ tradeHandler = this;
}
void TradeHandler::setAcceptTradeRequests(bool acceptTradeRequests)
@@ -136,3 +139,49 @@ void TradeHandler::handleMessage(MessageIn &msg)
break;
}
}
+
+void TradeHandler::request(Being *being)
+{
+ extern std::string tradePartnerName;
+ extern int tradePartnerID;
+ tradePartnerName = being->getName();
+ tradePartnerID = being->getId();
+ Net::GameServer::Player::requestTrade(tradePartnerID);
+}
+
+void TradeHandler::respond(bool accept)
+{
+ // TODO
+}
+
+void TradeHandler::addItem(Item *item, int amount)
+{
+ Net::GameServer::Player::tradeItem(item->getInvIndex(), amount);
+ tradeWindow->addItem(item->getId(), true, amount);
+ item->increaseQuantity(-amount);
+}
+
+void TradeHandler::removeItem(int slotNum, int amount)
+{
+ // TODO
+}
+
+void TradeHandler::setMoney(int amount)
+{
+ // TODO
+}
+
+void TradeHandler::confirm()
+{
+ // TODO
+}
+
+void TradeHandler::finish()
+{
+ // TODO
+}
+
+void TradeHandler::cancel()
+{
+ Net::GameServer::Player::acceptTrade(false);
+}
diff --git a/src/net/tmwserv/tradehandler.h b/src/net/tmwserv/tradehandler.h
index a064bbce..1abb30e3 100644
--- a/src/net/tmwserv/tradehandler.h
+++ b/src/net/tmwserv/tradehandler.h
@@ -23,8 +23,9 @@
#define NET_TMWSERV_TRADEHANDLER_H
#include "net/messagehandler.h"
+#include "net/tradehandler.h"
-class TradeHandler : public MessageHandler
+class TradeHandler : public MessageHandler, public Net::TradeHandler
{
public:
TradeHandler();
@@ -46,8 +47,26 @@ class TradeHandler : public MessageHandler
*/
void setAcceptTradeRequests(bool acceptTradeRequests);
+ void request(Being *being);
+
+ void respond(bool accept);
+
+ void addItem(Item *item, int amount);
+
+ void removeItem(int slotNum, int amount);
+
+ void setMoney(int amount);
+
+ void confirm();
+
+ void finish();
+
+ void cancel();
+
private:
bool mAcceptTradeRequests;
};
+extern Net::TradeHandler *tradeHandler;
+
#endif