diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-07-29 17:08:58 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-07-29 17:08:58 +0000 |
commit | 69dfa053e2d3fc50703338bb2865c33d966dda16 (patch) | |
tree | e1ba3f9fda1f3cc4a0a9b09f6f162da399a3eb2a /src/net | |
parent | d61fdaf1932724f86a68484c4a05195ca270646e (diff) | |
download | mana-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.gz mana-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.bz2 mana-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.xz mana-69dfa053e2d3fc50703338bb2865c33d966dda16.zip |
Converted trading to new server.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/gameserver/player.cpp | 22 | ||||
-rw-r--r-- | src/net/gameserver/player.h | 3 | ||||
-rw-r--r-- | src/net/protocol.h | 23 | ||||
-rw-r--r-- | src/net/tradehandler.cpp | 73 |
4 files changed, 99 insertions, 22 deletions
diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp index daf76c3e..c91923d8 100644 --- a/src/net/gameserver/player.cpp +++ b/src/net/gameserver/player.cpp @@ -95,3 +95,25 @@ void Net::GameServer::Player::selectFromNPC(int id, int choice) msg.writeByte(choice); Net::GameServer::connection->send(msg); } + +void Net::GameServer::Player::requestTrade(int id) +{ + MessageOut msg(PGMSG_TRADE_REQUEST); + msg.writeShort(id); + Net::GameServer::connection->send(msg); +} + +void Net::GameServer::Player::acceptTrade(bool accept) +{ + MessageOut msg(accept ? PGMSG_TRADE_ACCEPT : PGMSG_TRADE_CANCEL); + Net::GameServer::connection->send(msg); +} + +void Net::GameServer::Player::tradeItem(int slot, int amount) +{ + MessageOut msg(PGMSG_TRADE_ADD_ITEM); + msg.writeByte(slot); + msg.writeByte(amount); + Net::GameServer::connection->send(msg); +} + diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h index cb6927ba..8b4cde5b 100644 --- a/src/net/gameserver/player.h +++ b/src/net/gameserver/player.h @@ -43,6 +43,9 @@ namespace Net 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); } } } diff --git a/src/net/protocol.h b/src/net/protocol.h index 1a20b0a4..8af31dbb 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -74,16 +74,8 @@ #define SMSG_PLAYER_CHAT 0x008e /**< Player talks */ #define SMSG_GM_CHAT 0x009a /**< GM announce */ #define SMSG_WALK_RESPONSE 0x0087 -#define SMSG_TRADE_REQUEST 0x00e5 /**< Receiving a request to trade */ -#define SMSG_TRADE_RESPONSE 0x00e7 -#define SMSG_TRADE_ITEM_ADD 0x00e9 -#define SMSG_TRADE_ITEM_ADD_RESPONSE 0x01b1 /**< Not standard eAthena! */ -#define SMSG_TRADE_OK 0x00ec -#define SMSG_TRADE_CANCEL 0x00ee -#define SMSG_TRADE_COMPLETE 0x00f0 // Packets from client to server -#define CMSG_TRADE_RESPONSE 0x00e6 #define CMSG_ITEM_PICKUP 0x009f #define CMSG_MAP_LOADED 0x007d #define CMSG_NPC_BUY_REQUEST 0x00c8 @@ -94,12 +86,7 @@ #define CMSG_NPC_SELL_REQUEST 0x00c9 #define CMSG_SKILL_LEVELUP_REQUEST 0x0112 #define CMSG_STAT_UPDATE_REQUEST 0x00bb -#define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8 -#define CMSG_TRADE_CANCEL_REQUEST 0x00ed -#define CMSG_TRADE_ADD_COMPLETE 0x00eb -#define CMSG_TRADE_OK 0x00ef #define CMSG_NPC_TALK 0x0090 -#define CMSG_TRADE_REQUEST 0x00e4 #define CMSG_PLAYER_INVENTORY_USE 0x00a7 #define CMSG_PLAYER_INVENTORY_DROP 0x00a2 #define CMSG_PLAYER_EQUIP 0x00a9 @@ -183,6 +170,16 @@ enum { PGMSG_NPC_TALK = 0x02B2, // W being id PGMSG_NPC_TALK_NEXT = 0x02B3, // W being id PGMSG_NPC_SELECT = 0x02B4, // W being id, B choice + PGMSG_TRADE_REQUEST = 0x02C0, // W being id + GPMSG_TRADE_REQUEST = 0x02C1, // W being id + GPMSG_TRADE_START = 0x02C2, // - + GPMSG_TRADE_COMPLETE = 0x02C3, // - + PGMSG_TRADE_CANCEL = 0x02C4, // - + GPMSG_TRADE_CANCEL = 0x02C5, // - + PGMSG_TRADE_ACCEPT = 0x02C6, // - + GPMSG_TRADE_ACCEPT = 0x02C7, // - + PGMSG_TRADE_ADD_ITEM = 0x02C8, // B slot, B amount + GPMSG_TRADE_ADD_ITEM = 0x02C9, // W item id, B amount PGMSG_USE_ITEM = 0x0300, // L item id GPMSG_USE_RESPONSE = 0x0301, // B error GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }* 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; } } |