summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-13 20:40:16 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-13 20:40:16 +0000
commitd3e938c478570be44c497607262fe8ca7145b171 (patch)
tree24f0e39e7f46d0ce17ba3f135137f8c7b024a2cf /src/net
parent0bc585c7299ed1c9bccfaf0aa6b2cc7c4327d1ca (diff)
downloadmana-client-d3e938c478570be44c497607262fe8ca7145b171.tar.gz
mana-client-d3e938c478570be44c497607262fe8ca7145b171.tar.bz2
mana-client-d3e938c478570be44c497607262fe8ca7145b171.tar.xz
mana-client-d3e938c478570be44c497607262fe8ca7145b171.zip
Started conversion of buy/sell to new server.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/buysellhandler.cpp75
-rw-r--r--src/net/protocol.h5
2 files changed, 31 insertions, 49 deletions
diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp
index 2f22b0e6..9b96ced7 100644
--- a/src/net/buysellhandler.cpp
+++ b/src/net/buysellhandler.cpp
@@ -44,6 +44,8 @@ extern Window *buySellDialog;
BuySellHandler::BuySellHandler()
{
static const Uint16 _messages[] = {
+ GPMSG_NPC_BUY,
+ GPMSG_NPC_SELL,
0
};
handledMessages = _messages;
@@ -51,6 +53,14 @@ BuySellHandler::BuySellHandler()
void BuySellHandler::handleMessage(MessageIn &msg)
{
+ Being *being = beingManager->findBeing(msg.readShort());
+ if (!being || being->getType() != Being::NPC)
+ {
+ return;
+ }
+
+ current_npc = static_cast< NPC * >(being);
+
switch (msg.getId())
{
#if 0
@@ -62,65 +72,34 @@ void BuySellHandler::handleMessage(MessageIn &msg)
buySellDialog->setVisible(true);
current_npc = dynamic_cast<NPC*>(beingManager->findBeing(msg.readLong()));
break;
+#endif
- case SMSG_NPC_BUY:
- msg.readShort(); // length
- n_items = (msg.getLength() - 4) / 11;
+ case GPMSG_NPC_BUY:
buyDialog->reset();
buyDialog->setMoney(player_node->getMoney());
buyDialog->setVisible(true);
- for (int k = 0; k < n_items; k++)
+ while (msg.getUnreadLength())
{
- Sint32 value = msg.readLong();
- msg.readLong(); // DCvalue
- msg.readByte(); // type
- Sint16 itemId = msg.readShort();
- buyDialog->addItem(itemId, value);
- }
- break;
-
- case SMSG_NPC_SELL:
- msg.readShort(); // length
- n_items = (msg.getLength() - 4) / 10;
- if (n_items > 0) {
- sellDialog->setMoney(player_node->getMoney());
- sellDialog->reset();
- sellDialog->setVisible(true);
-
- for (int k = 0; k < n_items; k++)
- {
- Sint16 index = msg.readShort();
- Sint32 value = msg.readLong();
- msg.readLong(); // OCvalue
-
- Item *item = player_node->getInvItem(index);
- if (item && !(item->isEquipped())) {
- sellDialog->addItem(item, value);
- }
- }
- }
- else {
- chatWindow->chatLog("Nothing to sell", BY_SERVER);
- current_npc = 0;
+ int itemId = msg.readShort();
+ int amount = msg.readShort();
+ int value = msg.readShort();
+ buyDialog->addItem(itemId, amount, value);
}
break;
- case SMSG_NPC_BUY_RESPONSE:
- if (msg.readByte() == 0) {
- chatWindow->chatLog("Thanks for buying", BY_SERVER);
- } else {
- chatWindow->chatLog("Unable to buy", BY_SERVER);
- }
- break;
+ case GPMSG_NPC_SELL:
+ sellDialog->setMoney(player_node->getMoney());
+ sellDialog->reset();
+ sellDialog->setVisible(true);
- case SMSG_NPC_SELL_RESPONSE:
- if (msg.readByte() == 0) {
- chatWindow->chatLog("Thanks for selling", BY_SERVER);
- } else {
- chatWindow->chatLog("Unable to sell", BY_SERVER);
+ while (msg.getUnreadLength())
+ {
+ int itemId = msg.readShort();
+ int amount = msg.readShort();
+ int value = msg.readShort();
+ sellDialog->addItem(itemId, amount, value);
}
break;
-#endif
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index a524304a..6bbe7919 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -98,11 +98,14 @@ enum {
GPMSG_BEING_ATTACK = 0x0291, // W being id
PGMSG_SAY = 0x02A0, // S text
GPMSG_SAY = 0x02A1, // W being id, S text
- GPMSG_NPC_CHOICE = 0x02B0, // W being id, B* text
+ GPMSG_NPC_CHOICE = 0x02B0, // W being id, { S text }*
GPMSG_NPC_MESSAGE = 0x02B1, // W being id, B* text
PGMSG_NPC_TALK = 0x02B2, // W being id
PGMSG_NPC_TALK_NEXT = 0x02B3, // W being id
PGMSG_NPC_SELECT = 0x02B4, // W being id, B choice
+ GPMSG_NPC_BUY = 0x02B5, // W being id, { W item id, W amount, W cost }*
+ GPMSG_NPC_SELL = 0x02B6, // W being id, { W item id, W amount, W cost }*
+ PGMSG_NPC_BUYSELL = 0x02B7, // W item id, W amount
PGMSG_TRADE_REQUEST = 0x02C0, // W being id
GPMSG_TRADE_REQUEST = 0x02C1, // W being id
GPMSG_TRADE_START = 0x02C2, // -