diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-04-03 07:39:18 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-04-03 07:39:18 -0600 |
commit | 754cc498156371d0b6d32de0e58d7256236ed676 (patch) | |
tree | 54abf2170a48e72dffdf8a2ba7ded5386fc28813 /src/net | |
parent | d13b3eaca82e3547c84f60b9b135464ff3a51cf0 (diff) | |
download | mana-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')
-rw-r--r-- | src/net/ea/tradehandler.cpp | 4 | ||||
-rw-r--r-- | src/net/ea/tradehandler.h | 2 | ||||
-rw-r--r-- | src/net/net.cpp | 111 | ||||
-rw-r--r-- | src/net/tmwserv/inventoryhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/tmwserv/inventoryhandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwserv/playerhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/tmwserv/playerhandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwserv/tradehandler.cpp | 49 | ||||
-rw-r--r-- | src/net/tmwserv/tradehandler.h | 21 | ||||
-rw-r--r-- | src/net/tradehandler.h | 2 |
10 files changed, 194 insertions, 5 deletions
diff --git a/src/net/ea/tradehandler.cpp b/src/net/ea/tradehandler.cpp index f711f3c4..b7f8e369 100644 --- a/src/net/ea/tradehandler.cpp +++ b/src/net/ea/tradehandler.cpp @@ -238,10 +238,10 @@ void TradeHandler::respond(bool accept) outMsg.writeInt8(accept ? 3 : 4); } -void TradeHandler::addItem(int slotNum, int amount) +void TradeHandler::addItem(Item *item, int amount) { MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); - outMsg.writeInt16(slotNum + INVENTORY_OFFSET); + outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET); outMsg.writeInt32(amount); } diff --git a/src/net/ea/tradehandler.h b/src/net/ea/tradehandler.h index b6e0fdf8..451939f9 100644 --- a/src/net/ea/tradehandler.h +++ b/src/net/ea/tradehandler.h @@ -37,7 +37,7 @@ class TradeHandler : public MessageHandler, public Net::TradeHandler void respond(bool accept); - void addItem(int slotNum, int amount); + void addItem(Item *item, int amount); void removeItem(int slotNum, int amount); diff --git a/src/net/net.cpp b/src/net/net.cpp new file mode 100644 index 00000000..c4dcf0a4 --- /dev/null +++ b/src/net/net.cpp @@ -0,0 +1,111 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "net/net.h" + +#include "net/adminhandler.h" +#include "net/charhandler.h" +#include "net/chathandler.h" +#include "net/generalhandler.h" +#include "net/guildhandler.h" +#include "net/inventoryhandler.h" +#include "net/loginhandler.h" +#include "net/maphandler.h" +#include "net/npchandler.h" +#include "net/partyhandler.h" +#include "net/playerhandler.h" +#include "net/skillhandler.h" +#include "net/tradehandler.h" + +#ifdef TMWSERV_SUPPORT +#include "net/tmwserv/inventoryhandler.h" +#include "net/tmwserv/playerhandler.h" +#include "net/tmwserv/tradehandler.h" +#else +#include "net/ea/inventoryhandler.h" +#include "net/ea/playerhandler.h" +#include "net/ea/tradehandler.h" +#endif + +Net::AdminHandler *Net::getAdminHandler() +{ + // TODO +} + +Net::CharHandler *Net::getCharHandler() +{ + // TODO +} + +Net::ChatHandler *Net::getChatHandler() +{ + // TODO +} + +Net::GeneralHandler *Net::getGeneralHandler() +{ + // TODO +} + +Net::GuildHandler *Net::getGuildHandler() +{ + // TODO +} + +Net::InventoryHandler *Net::getInventoryHandler() +{ + return inventoryHandler; +} + +Net::LoginHandler *Net::getLoginHandler() +{ + // TODO +} + +Net::MapHandler *Net::getMapHandler() +{ + // TODO +} + +Net::NpcHandler *Net::getNpcHandler() +{ + // TODO +} + +Net::PartyHandler *Net::getPartyHandler() +{ + // TODO +} + +Net::PlayerHandler *Net::getPlayerHandler() +{ + return playerHandler; +} + +Net::SkillHandler *Net::getSkillHandler() +{ + // TODO +} + +Net::TradeHandler *Net::getTradeHandler() +{ + return tradeHandler; +} 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 diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h index 671e7566..5bad1b11 100644 --- a/src/net/tradehandler.h +++ b/src/net/tradehandler.h @@ -34,7 +34,7 @@ class TradeHandler virtual void respond(bool accept) {} - virtual void addItem(int slotNum, int amount) {} + virtual void addItem(Item *item, int amount) {} virtual void removeItem(int slotNum, int amount) {} |