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 | |
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.
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/gui/trade.cpp | 44 | ||||
-rw-r--r-- | src/gui/trade.h | 5 | ||||
-rw-r--r-- | src/localplayer.cpp | 104 | ||||
-rw-r--r-- | src/localplayer.h | 3 | ||||
-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 |
15 files changed, 224 insertions, 132 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ab63df80..a7060318 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -193,6 +193,7 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ net/messageout.cpp \ net/messageout.h \ net/npchandler.h \ + net/net.cpp \ net/net.h \ net/partyhandler.h \ net/playerhandler.h \ diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index fba5f600..504396c5 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -38,6 +38,7 @@ #include "gui/widgets/layout.h" #include "net/net.h" +#include "net/tradehandler.h" #ifdef TMWSERV_SUPPORT #include "net/tmwserv/gameserver/player.h" #else @@ -136,18 +137,14 @@ void TradeWindow::setMoney(int amount) mMoneyLabel->setCaption(strprintf(_("You get %s."), Units::formatCurrency(amount).c_str())); mMoneyLabel->adjustSize(); -#ifdef TMWSERV_SUPPORT setStatus(PREPARING); -#endif } -#ifdef TMWSERV_SUPPORT void TradeWindow::addItem(int id, bool own, int quantity) { (own ? mMyInventory : mPartnerInventory)->addItem(id, quantity); setStatus(PREPARING); } -#endif #ifdef EATHENA_SUPPORT void TradeWindow::addItem(int id, bool own, int quantity, bool equipment) @@ -193,9 +190,7 @@ void TradeWindow::reset() mMoneyLabel->setCaption(strprintf(_("You get %s."), "")); mMoneyField->setEnabled(true); mMoneyField->setText(""); -#ifdef TMWSERV_SUPPORT setStatus(PREPARING); -#endif } #ifdef TMWSERV_SUPPORT @@ -233,18 +228,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { - // Net::getTradeHandler()->addItem(item->getInvIndex(), quantity); -#ifdef TMWSERV_SUPPORT - Net::GameServer::Player::tradeItem(item->getInvIndex(), quantity); - addItem(item->getId(), true, quantity); - item->increaseQuantity(-quantity); -#else - // TODO: Our newer version of eAthena doesn't register this following - // function. Detect the actual server version, and re-enable this - // for that version only. - //addItem(item->getId(), true, quantity, item->isEquipment()); - tradeHandler->addItem(item->getInvIndex(), quantity); -#endif + Net::getTradeHandler()->addItem(item, quantity); } void TradeWindow::valueChanged(const gcn::SelectionEvent &event) @@ -261,7 +245,6 @@ void TradeWindow::valueChanged(const gcn::SelectionEvent &event) mMyItemContainer->selectNone(); } -#ifdef TMWSERV_SUPPORT void TradeWindow::setStatus(Status s) { if (s == mStatus) return; @@ -271,7 +254,6 @@ void TradeWindow::setStatus(Status s) (s == PREPARING ? _("Propose trade") : _("Confirm trade")); mTradeButton->setEnabled(s != PROPOSING); } -#endif void TradeWindow::action(const gcn::ActionEvent &event) { @@ -306,9 +288,7 @@ void TradeWindow::action(const gcn::ActionEvent &event) new ItemAmountWindow(ItemAmountWindow::TradeAdd, this, item); } -#ifdef TMWSERV_SUPPORT setStatus(PREPARING); -#endif } else if (event.getId() == "cancel") { @@ -316,12 +296,7 @@ void TradeWindow::action(const gcn::ActionEvent &event) reset(); player_node->setTrading(false); - // Net::getTradeHandler()->cancel(); -#ifdef TMWSERV_SUPPORT - Net::GameServer::Player::acceptTrade(false); -#else - tradeHandler->cancel(); -#endif + Net::getTradeHandler()->cancel(); } #ifdef EATHENA_SUPPORT else if (event.getId() == "ok") @@ -345,12 +320,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) #endif else if (event.getId() == "trade") { -#ifdef TMWSERV_SUPPORT - Net::GameServer::Player::acceptTrade(true); + Net::getTradeHandler()->finish(); setStatus(PROPOSING); -#else - tradeHandler->finish(); -#endif } #ifdef TMWSERV_SUPPORT else if (event.getId() == "money") @@ -365,10 +336,5 @@ void TradeWindow::action(const gcn::ActionEvent &event) void TradeWindow::close() { - // Net::getTradeHandler()->cancel(); -#ifdef TMWSERV_SUPPORT - Net::GameServer::Player::acceptTrade(false); -#else - tradeHandler->cancel(); -#endif + Net::getTradeHandler()->cancel(); } diff --git a/src/gui/trade.h b/src/gui/trade.h index e2767c5b..7f5f8a11 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -118,7 +118,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener void close(); private: -#ifdef TMWSERV_SUPPORT enum Status { PREPARING, /**< Players are adding items. */ @@ -130,7 +129,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener * Sets the current status of the trade. */ void setStatus(Status); -#endif typedef const std::auto_ptr<Inventory> InventoryPtr; InventoryPtr mMyInventory; @@ -147,9 +145,8 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener #endif gcn::TextField *mMoneyField; -#ifdef TMWSERV_SUPPORT Status mStatus; -#else +#ifdef EATHENA_SUPPORT bool mOkOther, mOkMe; #endif }; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 031ff342..d22468c1 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -43,7 +43,11 @@ #include "gui/storagewindow.h" #endif +#include "net/inventoryhandler.h" #include "net/net.h" +#include "net/playerhandler.h" +#include "net/tradehandler.h" + #ifdef TMWSERV_SUPPORT #include "effectmanager.h" #include "guild.h" @@ -52,11 +56,8 @@ #include "net/tmwserv/chatserver/guild.h" #include "net/tmwserv/chatserver/party.h" #else -#include "net/ea/inventoryhandler.h" #include "net/ea/partyhandler.h" -#include "net/ea/playerhandler.h" #include "net/ea/skillhandler.h" -#include "net/ea/tradehandler.h" #endif #include "resources/animation.h" @@ -353,12 +354,7 @@ void LocalPlayer::moveInvItem(Item *item, int newIndex) void LocalPlayer::equipItem(Item *item) { - // Net::getInventoryHandler()->equipItem(item); -#ifdef TMWSERV_SUPPORT // Ready for replacement - Net::GameServer::Player::equip(item->getInvIndex()); -#else - inventoryHandler->equipItem(item); -#endif + Net::getInventoryHandler()->equipItem(item); } #ifdef TMWSERV_SUPPORT @@ -371,41 +367,28 @@ void LocalPlayer::unequipItem(int slot) mEquipment->setEquipment(slot, 0); } -#else +#endif void LocalPlayer::unequipItem(Item *item) { - // Net::getInventoryHandler()->unequipItem(item); -#ifdef TMWSERV_SUPPORT // Ready for replacement - Net::GameServer::Player::unequip(item->getInvIndex()); -#else - inventoryHandler->unequipItem(item); -#endif + Net::getInventoryHandler()->unequipItem(item); // Tidy equipment directly to avoid weapon still shown bug, for instance +#ifdef TMWSERV_SUPPORT + mEquipment->setEquipment(item->getInvIndex(), 0); +#else mEquipment->removeEquipment(item->getInvIndex()); -} - #endif +} void LocalPlayer::useItem(Item *item) { - // Net::getInventoryHandler()->useItem(item); -#ifdef TMWSERV_SUPPORT // Ready for replacement - Net::GameServer::Player::useItem(item->getInvIndex()); -#else - inventoryHandler->useItem(item); -#endif + Net::getInventoryHandler()->useItem(item); } void LocalPlayer::dropItem(Item *item, int quantity) { - // Net::getInventoryHandler()->dropItem(item, quantity); -#ifdef TMWSERV_SUPPORT // Ready for replacement - Net::GameServer::Player::drop(item->getInvIndex(), quantity); -#else - inventoryHandler->dropItem(item, quantity); -#endif + Net::getInventoryHandler()->dropItem(item, quantity); } #ifdef TMWSERV_SUPPORT @@ -432,13 +415,7 @@ void LocalPlayer::pickUp(FloorItem *item) if (dx * dx + dy * dy < 4) { - // Net::getPlayerHandler()->pickUp(item); -#ifdef TMWSERV_SUPPORT // Ready for replacement - int id = item->getId(); - Net::GameServer::Player::pickUp(id >> 16, id & 0xFFFF); -#else - playerHandler->pickUp(item); -#endif + Net::getPlayerHandler()->pickUp(item); mPickUpTarget = NULL; } else @@ -550,12 +527,7 @@ void LocalPlayer::walk(unsigned char dir) else if (dir) { // If the being can't move, just change direction - // Net::getPlayerHandler()->setDirection(dir); -#ifdef TMWSERV_SUPPORT // Ready for replacement - Net::GameServer::Player::changeDir(dir); -#else - // TODO: Communicate this to the server -#endif + Net::getPlayerHandler()->setDirection(dir); setDirection(dir); } } @@ -631,14 +603,7 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) mDestX = x; mDestY = y; - // Net::getPlayerHandler()->setDestination(x, y, mDirection); -#ifdef TMWSERV_SUPPORT // Ready for replacement - Net::GameServer::Player::walk(x, y); - //Debugging fire burst - effectManager->trigger(15,x,y); -#else - playerHandler->setDestination(x, y, mDirection); -#endif + Net::getPlayerHandler()->setDestination(x, y, mDirection); } mPickUpTarget = NULL; @@ -701,13 +666,7 @@ void LocalPlayer::toggleSit() default: return; } - // Net::getPlayerHandler()->changeAction(newAction); -#ifdef TMWSERV_SUPPORT // Ready for replacement - setAction(newAction); - Net::GameServer::Player::changeAction(newAction); -#else - playerHandler->changeAction(newAction); -#endif + Net::getPlayerHandler()->changeAction(newAction); } void LocalPlayer::emote(Uint8 emotion) @@ -716,36 +675,20 @@ void LocalPlayer::emote(Uint8 emotion) return; mLastAction = tick_time; - // Net::getPlayerHandler()->emote(emotion); -#ifdef EATHENA_SUPPORT // Ready for replacement - playerHandler->emote(emotion); -#endif + Net::getPlayerHandler()->emote(emotion); } -#ifdef EATHENA_SUPPORT void LocalPlayer::tradeReply(bool accept) { if (!accept) mTrading = false; - // Net::getTradeHandler()->respond(accept); - - tradeHandler->respond(accept); + Net::getTradeHandler()->respond(accept); } -#endif void LocalPlayer::trade(Being *being) const { - // Net::getTradeHandler()->request(being); -#ifdef TMWSERV_SUPPORT - extern std::string tradePartnerName; - extern int tradePartnerID; - tradePartnerName = being->getName(); - tradePartnerID = being->getId(); - Net::GameServer::Player::requestTrade(tradePartnerID); -#else - tradeHandler->request(being); -#endif + Net::getTradeHandler()->request(being); } bool LocalPlayer::tradeRequestOk() const @@ -862,7 +805,7 @@ void LocalPlayer::attack(Being *target, bool keep) sound.playSfx("sfx/fist-swish.ogg"); } - playerHandler->attack(target); + Net::getPlayerHandler()->attack(target); if (!keep) stopAttack(); @@ -883,10 +826,7 @@ void LocalPlayer::stopAttack() void LocalPlayer::revive() { - // Net::getPlayerHandler()->respawn(); -#ifdef EATHENA_SUPPORT // Ready for replacement - playerHandler->respawn(); -#endif + Net::getPlayerHandler()->respawn(); } #ifdef TMWSERV_SUPPORT diff --git a/src/localplayer.h b/src/localplayer.h index 45174e64..14f492b2 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -212,9 +212,8 @@ class LocalPlayer : public Player */ #ifdef TMWSERV_SUPPORT void unequipItem(int slot); -#else - void unequipItem(Item *item); #endif + void unequipItem(Item *item); void useItem(Item *item); 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) {} |