From f0fd20fdd649eb61fa0d2444d910a2b0882e3580 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 6 Apr 2009 22:46:15 +0200 Subject: Moved many MessageOut constructions around No real point in having these abstracted away twice. We're using network interfaces now instead of functions structured in namespaces. --- src/equipment.h | 2 +- src/gui/equipmentwindow.cpp | 6 +- src/localplayer.cpp | 12 ---- src/localplayer.h | 3 - src/net/tmwserv/beinghandler.cpp | 8 +-- src/net/tmwserv/chathandler.cpp | 56 ++++++++++++++---- src/net/tmwserv/chatserver/chatserver.cpp | 95 +------------------------------ src/net/tmwserv/chatserver/chatserver.h | 16 ------ src/net/tmwserv/effecthandler.cpp | 1 - src/net/tmwserv/gameserver/player.cpp | 90 ----------------------------- src/net/tmwserv/gameserver/player.h | 12 ---- src/net/tmwserv/inventoryhandler.cpp | 23 ++++++-- src/net/tmwserv/npchandler.cpp | 33 ++++++++--- src/net/tmwserv/playerhandler.cpp | 22 +++++-- src/net/tmwserv/tradehandler.cpp | 21 +++++-- 15 files changed, 130 insertions(+), 270 deletions(-) (limited to 'src') diff --git a/src/equipment.h b/src/equipment.h index 63555361..5bebf78d 100644 --- a/src/equipment.h +++ b/src/equipment.h @@ -49,7 +49,7 @@ class Equipment * Get equipment at the given slot. */ #ifdef TMWSERV_SUPPORT - Item* getEquipment(int index) + Item *getEquipment(int index) #else int getEquipment(int index) const #endif diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 46e68ef8..ef90e674 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -175,13 +175,13 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) if (event.getId() == "unequip" && mSelected > -1) { #ifdef TMWSERV_SUPPORT // TODO: merge these! - player_node->unequipItem(mSelected); + Item *item = mEquipment->getEquipment(mSelected); #else - Item* item = (mSelected != EQUIP_AMMO_SLOT) ? + Item *item = (mSelected != EQUIP_AMMO_SLOT) ? mInventory->getItem(mEquipment->getEquipment(mSelected)) : mInventory->getItem(mEquipment->getArrows()); - player_node->unequipItem(item); #endif + player_node->unequipItem(item); mSelected = -1; } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 8d538f94..fea3bae8 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -357,18 +357,6 @@ void LocalPlayer::equipItem(Item *item) Net::getInventoryHandler()->equipItem(item); } -#ifdef TMWSERV_SUPPORT - -void LocalPlayer::unequipItem(int slot) -{ - Net::GameServer::Player::unequip(slot); - - // Tidy equipment directly to avoid weapon still shown bug, for instance - mEquipment->setEquipment(slot, 0); -} - -#endif - void LocalPlayer::unequipItem(Item *item) { Net::getInventoryHandler()->unequipItem(item); diff --git a/src/localplayer.h b/src/localplayer.h index 14f492b2..c93368a5 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -210,9 +210,6 @@ class LocalPlayer : public Player /** * Unequips an item. */ -#ifdef TMWSERV_SUPPORT - void unequipItem(int slot); -#endif void unequipItem(Item *item); void useItem(Item *item); diff --git a/src/net/tmwserv/beinghandler.cpp b/src/net/tmwserv/beinghandler.cpp index 08847d7d..0752497e 100644 --- a/src/net/tmwserv/beinghandler.cpp +++ b/src/net/tmwserv/beinghandler.cpp @@ -41,8 +41,6 @@ #include "net/tmwserv/gameserver/player.h" -const int EMOTION_TIME = 150; /**< Duration of emotion icon */ - BeingHandler::BeingHandler() { static const Uint16 _messages[] = { @@ -172,7 +170,8 @@ void BeingHandler::handleBeingEnterMessage(MessageIn &msg) void BeingHandler::handleBeingLeaveMessage(MessageIn &msg) { Being *being = beingManager->findBeing(msg.readInt16()); - if (!being) return; + if (!being) + return; beingManager->destroyBeing(being); } @@ -346,7 +345,8 @@ void BeingHandler::handleBeingLooksChangeMessage(MessageIn &msg) void BeingHandler::handleBeingDirChangeMessage(MessageIn &msg) { Being *being = beingManager->findBeing(msg.readInt16()); - if (!being) return; + if (!being) + return; int data = msg.readInt8(); switch (data) { diff --git a/src/net/tmwserv/chathandler.cpp b/src/net/tmwserv/chathandler.cpp index febffa12..5b1b28dd 100644 --- a/src/net/tmwserv/chathandler.cpp +++ b/src/net/tmwserv/chathandler.cpp @@ -21,13 +21,17 @@ #include "net/tmwserv/chathandler.h" +#include "net/tmwserv/connection.h" #include "net/tmwserv/protocol.h" #include "net/tmwserv/chatserver/chatserver.h" +#include "net/tmwserv/chatserver/internal.h" +#include "net/tmwserv/gameserver/internal.h" #include "net/tmwserv/gameserver/player.h" #include "net/messagein.h" +#include "net/messageout.h" #include "being.h" #include "beingmanager.h" @@ -293,7 +297,9 @@ void ChatHandler::handleChannelEvent(MessageIn &msg) void ChatHandler::talk(const std::string &text) { - Net::GameServer::Player::say(text); + MessageOut msg(PGMSG_SAY); + msg.writeString(text); + Net::GameServer::connection->send(msg); } void ChatHandler::me(const std::string &text) @@ -301,49 +307,75 @@ void ChatHandler::me(const std::string &text) // TODO } -void ChatHandler::privateMessage(const std::string &recipient, const std::string &text) +void ChatHandler::privateMessage(const std::string &recipient, + const std::string &text) { - Net::ChatServer::privMsg(recipient, text); + MessageOut msg(PCMSG_PRIVMSG); + msg.writeString(recipient); + msg.writeString(text); + Net::ChatServer::connection->send(msg); } void ChatHandler::channelList() { - Net::ChatServer::getChannelList(); + MessageOut msg(PCMSG_LIST_CHANNELS); + Net::ChatServer::connection->send(msg); } -void ChatHandler::enterChannel(const std::string &channel, const std::string &password) +void ChatHandler::enterChannel(const std::string &channel, + const std::string &password) { - Net::ChatServer::enterChannel(channel, password); + MessageOut msg(PCMSG_ENTER_CHANNEL); + msg.writeString(channel); + msg.writeString(password); + Net::ChatServer::connection->send(msg); } void ChatHandler::quitChannel(int channelId) { - Net::ChatServer::quitChannel(channelId); + MessageOut msg(PCMSG_QUIT_CHANNEL); + msg.writeInt16(channelId); + Net::ChatServer::connection->send(msg); } void ChatHandler::sendToChannel(int channelId, const std::string &text) { - Net::ChatServer::chat(channelId, text); + MessageOut msg(PCMSG_CHAT); + msg.writeString(text); + msg.writeInt16(channelId); + Net::ChatServer::connection->send(msg); } void ChatHandler::userList(const std::string &channel) { - Net::ChatServer::getUserList(channel); + MessageOut msg(PCMSG_LIST_CHANNELUSERS); + msg.writeString(channel); + Net::ChatServer::connection->send(msg); } void ChatHandler::setChannelTopic(int channelId, const std::string &text) { - Net::ChatServer::setChannelTopic(channelId, text); + MessageOut msg(PCMSG_TOPIC_CHANGE); + msg.writeInt16(channelId); + msg.writeString(text); + Net::ChatServer::connection->send(msg); } void ChatHandler::setUserMode(int channelId, const std::string &name, int mode) { - Net::ChatServer::setUserMode(channelId, name, mode); + MessageOut msg(PCMSG_USER_MODE); + msg.writeInt16(channelId); + msg.writeString(name); + msg.writeInt8(mode); + Net::ChatServer::connection->send(msg); } void ChatHandler::kickUser(int channelId, const std::string &name) { - Net::ChatServer::kickUser(channelId, name); + MessageOut msg(PCMSG_KICK_USER); + msg.writeInt16(channelId); + msg.writeString(name); + Net::ChatServer::connection->send(msg); } } // namespace TmwServ diff --git a/src/net/tmwserv/chatserver/chatserver.cpp b/src/net/tmwserv/chatserver/chatserver.cpp index 49a17367..c35fc782 100644 --- a/src/net/tmwserv/chatserver/chatserver.cpp +++ b/src/net/tmwserv/chatserver/chatserver.cpp @@ -31,117 +31,24 @@ using Net::ChatServer::connection; void Net::ChatServer::connect(Net::Connection *connection, - const std::string &token) + const std::string &token) { Net::ChatServer::connection = connection; MessageOut msg(PCMSG_CONNECT); - msg.writeString(token, 32); - connection->send(msg); } void Net::ChatServer::logout() { MessageOut msg(PCMSG_DISCONNECT); - - connection->send(msg); -} - -void Net::ChatServer::chat(short channel, const std::string &text) -{ - MessageOut msg(PCMSG_CHAT); - - msg.writeString(text); - msg.writeInt16(channel); - connection->send(msg); } void Net::ChatServer::announce(const std::string &text) { MessageOut msg(PCMSG_ANNOUNCE); - - msg.writeString(text); - - connection->send(msg); -} - -void Net::ChatServer::privMsg(const std::string &recipient, - const std::string &text) -{ - MessageOut msg(PCMSG_PRIVMSG); - - msg.writeString(recipient); msg.writeString(text); - - connection->send(msg); -} - -void Net::ChatServer::enterChannel(const std::string &channel, const std::string &password) -{ - MessageOut msg(PCMSG_ENTER_CHANNEL); - - msg.writeString(channel); - msg.writeString(password); - - connection->send(msg); -} - -void Net::ChatServer::quitChannel(short channel) -{ - MessageOut msg(PCMSG_QUIT_CHANNEL); - - msg.writeInt16(channel); - - connection->send(msg); -} - -void Net::ChatServer::getChannelList() -{ - MessageOut msg(PCMSG_LIST_CHANNELS); - - connection->send(msg); -} - -void Net::ChatServer::getUserList(const std::string &channel) -{ - MessageOut msg(PCMSG_LIST_CHANNELUSERS); - - msg.writeString(channel); - - connection->send(msg); -} - -void Net::ChatServer::setChannelTopic(short channel, const std::string &topic) -{ - MessageOut msg(PCMSG_TOPIC_CHANGE); - - msg.writeInt16(channel); - msg.writeString(topic); - - connection->send(msg); -} - -void Net::ChatServer::setUserMode(short channel, const std::string &user, - unsigned char mode) -{ - MessageOut msg(PCMSG_USER_MODE); - - msg.writeInt16(channel); - msg.writeString(user); - msg.writeInt8(mode); - - connection->send(msg); -} - -void Net::ChatServer::kickUser(short channel, const std::string &user) -{ - MessageOut msg(PCMSG_KICK_USER); - - msg.writeInt16(channel); - msg.writeString(user); - connection->send(msg); } diff --git a/src/net/tmwserv/chatserver/chatserver.h b/src/net/tmwserv/chatserver/chatserver.h index 8a6025a7..18859a2c 100644 --- a/src/net/tmwserv/chatserver/chatserver.h +++ b/src/net/tmwserv/chatserver/chatserver.h @@ -34,24 +34,8 @@ namespace Net void logout(); - void chat(short channel, const std::string &text); - void announce(const std::string &text); - void privMsg(const std::string &recipient, const std::string &text); - - void enterChannel(const std::string &channel, const std::string &password); - - void quitChannel(short channel); - - void getChannelList(); - - void getUserList(const std::string &channel); - - void setChannelTopic(short channel, const std::string &topic); - - void setUserMode(short channel, const std::string &user, unsigned char mode); - void kickUser(short channel, const std::string &user); } diff --git a/src/net/tmwserv/effecthandler.cpp b/src/net/tmwserv/effecthandler.cpp index d2b26fca..787a7a68 100644 --- a/src/net/tmwserv/effecthandler.cpp +++ b/src/net/tmwserv/effecthandler.cpp @@ -56,4 +56,3 @@ void EffectHandler::handleCreateEffects(MessageIn &msg) Uint16 y = msg.readInt16(); effectManager->trigger(id, x, y); } - diff --git a/src/net/tmwserv/gameserver/player.cpp b/src/net/tmwserv/gameserver/player.cpp index ec346d9f..a3e1458c 100644 --- a/src/net/tmwserv/gameserver/player.cpp +++ b/src/net/tmwserv/gameserver/player.cpp @@ -33,13 +33,6 @@ void RespawnRequestListener::action(const gcn::ActionEvent &event) Net::GameServer::Player::respawn(); } -void Net::GameServer::Player::say(const std::string &text) -{ - MessageOut msg(PGMSG_SAY); - msg.writeString(text); - Net::GameServer::connection->send(msg); -} - void Net::GameServer::Player::walk(int x, int y) { MessageOut msg(PGMSG_WALK); @@ -65,35 +58,6 @@ void Net::GameServer::Player::moveItem(int oldSlot, int newSlot, int amount) Net::GameServer::connection->send(msg); } -void Net::GameServer::Player::drop(int slot, int amount) -{ - MessageOut msg(PGMSG_DROP); - msg.writeInt8(slot); - msg.writeInt8(amount); - Net::GameServer::connection->send(msg); -} - -void Net::GameServer::Player::equip(int slot) -{ - MessageOut msg(PGMSG_EQUIP); - msg.writeInt8(slot); - Net::GameServer::connection->send(msg); -} - -void Net::GameServer::Player::unequip(int slot) -{ - MessageOut msg(PGMSG_UNEQUIP); - msg.writeInt8(slot); - Net::GameServer::connection->send(msg); -} - -void Net::GameServer::Player::useItem(int slot) -{ - MessageOut msg(PGMSG_USE_ITEM); - msg.writeInt8(slot); - Net::GameServer::connection->send(msg); -} - void Net::GameServer::Player::attack(int direction) { MessageOut msg(PGMSG_ATTACK); @@ -108,28 +72,6 @@ void Net::GameServer::Player::useSpecial(int special) Net::GameServer::connection->send(msg); } -void Net::GameServer::Player::changeAction(Being::Action action) -{ - MessageOut msg(PGMSG_ACTION_CHANGE); - msg.writeInt8(action); - Net::GameServer::connection->send(msg); -} - -void Net::GameServer::Player::talkToNPC(int id, bool restart) -{ - MessageOut msg(restart ? PGMSG_NPC_TALK : PGMSG_NPC_TALK_NEXT); - msg.writeInt16(id); - Net::GameServer::connection->send(msg); -} - -void Net::GameServer::Player::selectFromNPC(int id, int choice) -{ - MessageOut msg(PGMSG_NPC_SELECT); - msg.writeInt16(id); - msg.writeInt8(choice); - Net::GameServer::connection->send(msg); -} - void Net::GameServer::Player::requestTrade(int id) { MessageOut msg(PGMSG_TRADE_REQUEST); @@ -143,14 +85,6 @@ void Net::GameServer::Player::acceptTrade(bool accept) Net::GameServer::connection->send(msg); } -void Net::GameServer::Player::tradeItem(int slot, int amount) -{ - MessageOut msg(PGMSG_TRADE_ADD_ITEM); - msg.writeInt8(slot); - msg.writeInt8(amount); - Net::GameServer::connection->send(msg); -} - void Net::GameServer::Player::tradeMoney(int amount) { MessageOut msg(PGMSG_TRADE_SET_MONEY); @@ -158,23 +92,6 @@ void Net::GameServer::Player::tradeMoney(int amount) Net::GameServer::connection->send(msg); } -void Net::GameServer::Player::tradeWithNPC(int item, int amount) -{ - MessageOut msg(PGMSG_NPC_BUYSELL); - msg.writeInt16(item); - msg.writeInt16(amount); - Net::GameServer::connection->send(msg); -} - -void Net::GameServer::Player::sendLetter(const std::string &player, - const std::string &text) -{ - MessageOut msg(PGMSG_NPC_POST_SEND); - msg.writeString(player); - msg.writeString(text); - Net::GameServer::connection->send(msg); -} - void Net::GameServer::Player::raiseAttribute(int attribute) { MessageOut msg(PGMSG_RAISE_ATTRIBUTE); @@ -194,10 +111,3 @@ void Net::GameServer::Player::respawn() MessageOut msg(PGMSG_RESPAWN); Net::GameServer::connection->send(msg); } - -void Net::GameServer::Player::changeDir(unsigned char dir) -{ - MessageOut msg(PGMSG_DIRECTION_CHANGE); - msg.writeInt8(dir); - Net::GameServer::connection->send(msg); -} diff --git a/src/net/tmwserv/gameserver/player.h b/src/net/tmwserv/gameserver/player.h index 3f33c7d5..eddd9102 100644 --- a/src/net/tmwserv/gameserver/player.h +++ b/src/net/tmwserv/gameserver/player.h @@ -40,30 +40,18 @@ namespace Net { namespace Player { - void say(const std::string &text); void walk(int x, int y); void pickUp(int x, int y); void moveItem(int oldSlot, int newSlot, int amount); - void drop(int slot, int amount); - void equip(int slot); - void unequip(int slot); - void useItem(int slot); void attack(int direction); void useSpecial(int special); - void changeAction(Being::Action action); - void talkToNPC(int id, bool restart); - void selectFromNPC(int id, int choice); void requestTrade(int id); void acceptTrade(bool accept); - void tradeItem(int slot, int amount); void tradeMoney(int amount); - void tradeWithNPC(int item, int amount); - void sendLetter(const std::string &player, const std::string &text); void raiseAttribute(int attribute); void lowerAttribute(int attribute); void respawn(); static RespawnRequestListener respawnListener; - void changeDir(unsigned char dir); } } } diff --git a/src/net/tmwserv/inventoryhandler.cpp b/src/net/tmwserv/inventoryhandler.cpp index ac079846..103c1c51 100644 --- a/src/net/tmwserv/inventoryhandler.cpp +++ b/src/net/tmwserv/inventoryhandler.cpp @@ -21,11 +21,13 @@ #include "net/tmwserv/inventoryhandler.h" +#include "net/tmwserv/connection.h" #include "net/tmwserv/protocol.h" -#include "net/tmwserv/gameserver/player.h" +#include "net/tmwserv/gameserver/internal.h" #include "net/messagein.h" +#include "net/messageout.h" #include "equipment.h" #include "inventory.h" @@ -87,22 +89,31 @@ void InventoryHandler::handleMessage(MessageIn &msg) void InventoryHandler::equipItem(Item *item) { - Net::GameServer::Player::equip(item->getInvIndex()); + MessageOut msg(PGMSG_EQUIP); + msg.writeInt8(item->getInvIndex()); + Net::GameServer::connection->send(msg); } void InventoryHandler::unequipItem(Item *item) { - Net::GameServer::Player::unequip(item->getInvIndex()); + MessageOut msg(PGMSG_UNEQUIP); + msg.writeInt8(item->getInvIndex()); + Net::GameServer::connection->send(msg); } void InventoryHandler::useItem(Item *item) { - Net::GameServer::Player::useItem(item->getInvIndex()); + MessageOut msg(PGMSG_USE_ITEM); + msg.writeInt8(item->getInvIndex()); + Net::GameServer::connection->send(msg); } void InventoryHandler::dropItem(Item *item, int amount) { - Net::GameServer::Player::drop(item->getInvIndex(), amount); + MessageOut msg(PGMSG_DROP); + msg.writeInt8(item->getInvIndex()); + msg.writeInt8(amount); + Net::GameServer::connection->send(msg); } void InventoryHandler::splitItem(Item *item, int amount) @@ -121,7 +132,7 @@ void InventoryHandler::closeStorage() } void InventoryHandler::moveItem(StorageType source, int slot, int amount, - StorageType destination) + StorageType destination) { // TODO } diff --git a/src/net/tmwserv/npchandler.cpp b/src/net/tmwserv/npchandler.cpp index 63d341d7..5670bd69 100644 --- a/src/net/tmwserv/npchandler.cpp +++ b/src/net/tmwserv/npchandler.cpp @@ -21,11 +21,14 @@ #include "net/tmwserv/npchandler.h" +#include "net/tmwserv/connection.h" #include "net/tmwserv/protocol.h" +#include "net/tmwserv/gameserver/internal.h" #include "net/tmwserv/gameserver/player.h" #include "net/messagein.h" +#include "net/messageout.h" #include "beingmanager.h" #include "npc.h" @@ -91,12 +94,16 @@ void NpcHandler::handleMessage(MessageIn &msg) void NpcHandler::talk(int npcId) { - Net::GameServer::Player::talkToNPC(npcId, true); + MessageOut msg(PGMSG_NPC_TALK); + msg.writeInt16(npcId); + Net::GameServer::connection->send(msg); } void NpcHandler::nextDialog(int npcId) { - Net::GameServer::Player::talkToNPC(npcId, false); + MessageOut msg(PGMSG_NPC_TALK_NEXT); + msg.writeInt16(npcId); + Net::GameServer::connection->send(msg); } void NpcHandler::closeDialog(int npcId) @@ -106,7 +113,10 @@ void NpcHandler::closeDialog(int npcId) void NpcHandler::listInput(int npcId, int value) { - Net::GameServer::Player::selectFromNPC(npcId, value); + MessageOut msg(PGMSG_NPC_SELECT); + msg.writeInt16(npcId); + msg.writeInt8(value); + Net::GameServer::connection->send(msg); } void NpcHandler::integerInput(int npcId, int value) @@ -120,9 +130,12 @@ void NpcHandler::stringInput(int npcId, const std::string &value) } void NpcHandler::sendLetter(int npcId, const std::string &recipient, - const std::string &text) + const std::string &text) { - Net::GameServer::Player::sendLetter(recipient, text); + MessageOut msg(PGMSG_NPC_POST_SEND); + msg.writeString(recipient); + msg.writeString(text); + Net::GameServer::connection->send(msg); } void NpcHandler::startShopping(int beingId) @@ -142,12 +155,18 @@ void NpcHandler::sell(int beingId) void NpcHandler::buyItem(int beingId, int itemId, int amount) { - Net::GameServer::Player::tradeWithNPC(itemId, amount); + MessageOut msg(PGMSG_NPC_BUYSELL); + msg.writeInt16(itemId); + msg.writeInt16(amount); + Net::GameServer::connection->send(msg); } void NpcHandler::sellItem(int beingId, int itemId, int amount) { - Net::GameServer::Player::tradeWithNPC(itemId, amount); + MessageOut msg(PGMSG_NPC_BUYSELL); + msg.writeInt16(itemId); + msg.writeInt16(amount); + Net::GameServer::connection->send(msg); } void NpcHandler::endShopping(int beingId) diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp index f13484eb..441b5021 100644 --- a/src/net/tmwserv/playerhandler.cpp +++ b/src/net/tmwserv/playerhandler.cpp @@ -21,11 +21,14 @@ #include "net/tmwserv/playerhandler.h" +#include "net/tmwserv/connection.h" #include "net/tmwserv/protocol.h" +#include "net/tmwserv/gameserver/internal.h" #include "net/tmwserv/gameserver/player.h" #include "net/messagein.h" +#include "net/messageout.h" #include "effectmanager.h" #include "engine.h" @@ -362,13 +365,19 @@ void PlayerHandler::pickUp(FloorItem *floorItem) void PlayerHandler::setDirection(char direction) { - Net::GameServer::Player::changeDir(direction); + MessageOut msg(PGMSG_DIRECTION_CHANGE); + msg.writeInt8(direction); + Net::GameServer::connection->send(msg); } -void PlayerHandler::setDestination(int x, int y, int direction) +void PlayerHandler::setDestination(int x, int y, int /* direction */) { - Net::GameServer::Player::walk(x, y); - //Debugging fire burst + MessageOut msg(PGMSG_WALK); + msg.writeInt16(x); + msg.writeInt16(y); + Net::GameServer::connection->send(msg); + + // Debugging fire burst effectManager->trigger(15, x, y); } @@ -376,7 +385,10 @@ void PlayerHandler::changeAction(Being::Action action) { if (action == Being::SIT) player_node->setAction(action); - Net::GameServer::Player::changeAction(action); + + MessageOut msg(PGMSG_ACTION_CHANGE); + msg.writeInt8(action); + Net::GameServer::connection->send(msg); } void PlayerHandler::respawn() diff --git a/src/net/tmwserv/tradehandler.cpp b/src/net/tmwserv/tradehandler.cpp index 17a45a19..4528988b 100644 --- a/src/net/tmwserv/tradehandler.cpp +++ b/src/net/tmwserv/tradehandler.cpp @@ -21,10 +21,15 @@ #include "net/tmwserv/tradehandler.h" +#include "net/tmwserv/gameserver/internal.h" #include "net/tmwserv/gameserver/player.h" + +#include "net/tmwserv/connection.h" #include "net/tmwserv/protocol.h" #include "net/messagein.h" +#include "net/messageout.h" +#include "net/net.h" #include "beingmanager.h" #include "item.h" @@ -49,7 +54,7 @@ namespace { if (event.getId() == "yes") Net::GameServer::Player::requestTrade(tradePartnerID); else - Net::GameServer::Player::acceptTrade(false); + Net::getTradeHandler()->cancel(); } } listener; } @@ -146,7 +151,10 @@ void TradeHandler::request(Being *being) { tradePartnerName = being->getName(); tradePartnerID = being->getId(); - Net::GameServer::Player::requestTrade(tradePartnerID); + + MessageOut msg(PGMSG_TRADE_REQUEST); + msg.writeInt16(tradePartnerID); + Net::GameServer::connection->send(msg); } void TradeHandler::respond(bool accept) @@ -156,7 +164,11 @@ void TradeHandler::respond(bool accept) void TradeHandler::addItem(Item *item, int amount) { - Net::GameServer::Player::tradeItem(item->getInvIndex(), amount); + MessageOut msg(PGMSG_TRADE_ADD_ITEM); + msg.writeInt8(item->getInvIndex()); + msg.writeInt8(amount); + Net::GameServer::connection->send(msg); + tradeWindow->addItem(item->getId(), true, amount); item->increaseQuantity(-amount); } @@ -183,7 +195,8 @@ void TradeHandler::finish() void TradeHandler::cancel() { - Net::GameServer::Player::acceptTrade(false); + MessageOut msg(PGMSG_TRADE_CANCEL); + Net::GameServer::connection->send(msg); } } // namespace TmwServ -- cgit v1.2.3-70-g09d2