summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-29 17:08:58 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-29 17:08:58 +0000
commit69dfa053e2d3fc50703338bb2865c33d966dda16 (patch)
treee1ba3f9fda1f3cc4a0a9b09f6f162da399a3eb2a /src
parentd61fdaf1932724f86a68484c4a05195ca270646e (diff)
downloadmana-client-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.gz
mana-client-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.bz2
mana-client-69dfa053e2d3fc50703338bb2865c33d966dda16.tar.xz
mana-client-69dfa053e2d3fc50703338bb2865c33d966dda16.zip
Converted trading to new server.
Diffstat (limited to 'src')
-rw-r--r--src/gui/trade.cpp49
-rw-r--r--src/localplayer.cpp22
-rw-r--r--src/net/gameserver/player.cpp22
-rw-r--r--src/net/gameserver/player.h3
-rw-r--r--src/net/protocol.h23
-rw-r--r--src/net/tradehandler.cpp73
6 files changed, 117 insertions, 75 deletions
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 14b1afa6..63855704 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -37,6 +37,9 @@
#include "../inventory.h"
#include "../item.h"
+#include "../localplayer.h"
+
+#include "../net/gameserver/player.h"
#include "../resources/iteminfo.h"
@@ -213,12 +216,9 @@ void TradeWindow::receivedOk(bool own)
void TradeWindow::tradeItem(Item *item, int quantity)
{
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeShort(item->getInvIndex());
- outMsg.writeLong(quantity);
- */
+ Net::GameServer::Player::tradeItem(item->getInvIndex(), quantity);
+ addItem(item->getId(), true, quantity, item->isEquipment());
+ item->increaseQuantity(-quantity);
}
void TradeWindow::selectionChanged(const SelectionEvent &event)
@@ -262,13 +262,10 @@ void TradeWindow::action(const gcn::ActionEvent &event)
if (event.getId() == "add")
{
+ chatWindow->chatLog("Adding item.", BY_SERVER);
if (!item)
{
- return;
- }
-
- if (mMyInventory->getFreeSlot() < 1)
- {
+ chatWindow->chatLog("Nothing to add.", BY_SERVER);
return;
}
@@ -288,34 +285,14 @@ void TradeWindow::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "cancel")
{
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST);
- */
+ setVisible(false);
+ reset();
+ player_node->setTrading(false);
+ Net::GameServer::Player::acceptTrade(false);
}
else if (event.getId() == "ok")
{
- std::stringstream tempMoney(mMoneyField->getText());
- int tempInt;
- if (tempMoney >> tempInt)
- {
- mMoneyField->setText(toString(tempInt));
-
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeShort(0);
- outMsg.writeLong(tempInt);
- */
- } else {
- mMoneyField->setText("");
- }
- mMoneyField->setEnabled(false);
-
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE);
- */
+ Net::GameServer::Player::acceptTrade(true);
}
else if (event.getId() == "trade")
{
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 4d42c7aa..5945127f 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -274,25 +274,13 @@ void LocalPlayer::emote(Uint8 emotion)
*/
}
-void LocalPlayer::tradeReply(bool accept)
-{
- if (!accept)
- mTrading = false;
-
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_TRADE_RESPONSE);
- outMsg.writeByte(accept ? 3 : 4);
- */
-}
-
void LocalPlayer::trade(Being *being) const
{
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_TRADE_REQUEST);
- outMsg.writeLong(being->getId());
- */
+ extern std::string tradePartnerName;
+ extern int tradePartnerID;
+ tradePartnerName = being->getName();
+ tradePartnerID = being->getId();
+ Net::GameServer::Player::requestTrade(tradePartnerID);
}
bool LocalPlayer::tradeRequestOk() const
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;
}
}