summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-14 10:36:39 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-14 10:36:39 +0000
commitb9772c8575708a9f28d89b3b973af73e382e9329 (patch)
treed5490d229b2ff43d033d07c1c23e36027255406c /src
parent1c46904573aa83132afc90f86381034405ae796e (diff)
downloadmana-b9772c8575708a9f28d89b3b973af73e382e9329.tar.gz
mana-b9772c8575708a9f28d89b3b973af73e382e9329.tar.bz2
mana-b9772c8575708a9f28d89b3b973af73e382e9329.tar.xz
mana-b9772c8575708a9f28d89b3b973af73e382e9329.zip
Fixed error-prone interface. Handled money as an inventory part.
Diffstat (limited to 'src')
-rw-r--r--src/net/inventoryhandler.cpp6
-rw-r--r--src/net/messagein.cpp20
-rw-r--r--src/net/messagein.h15
3 files changed, 19 insertions, 22 deletions
diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp
index ce01c3dc..354dd685 100644
--- a/src/net/inventoryhandler.cpp
+++ b/src/net/inventoryhandler.cpp
@@ -58,6 +58,12 @@ void InventoryHandler::handleMessage(MessageIn &msg)
while (msg.getUnreadLength())
{
int slot = msg.readByte();
+ if (slot == 255)
+ {
+ player_node->setMoney(msg.readLong());
+ continue;
+ }
+
int id = msg.readShort();
if (slot < EQUIPMENT_SIZE)
{
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index a1707e06..e90084ff 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -36,37 +36,33 @@ MessageIn::MessageIn(const char *data, unsigned int length):
mId = readShort();
}
-MessageIn::~MessageIn()
+int MessageIn::readByte()
{
-}
-
-char MessageIn::readByte()
-{
- char value = -1;
+ int value = -1;
if (mPos < mLength)
{
- value = mData[mPos];
+ value = (unsigned char) mData[mPos];
}
mPos += 1;
return value;
}
-short MessageIn::readShort()
+int MessageIn::readShort()
{
- short value = -1;
+ int value = -1;
if (mPos + 2 <= mLength)
{
uint16_t t;
memcpy(&t, mData + mPos, 2);
- value = ENET_NET_TO_HOST_16(t);
+ value = (unsigned short) ENET_NET_TO_HOST_16(t);
}
mPos += 2;
return value;
}
-long MessageIn::readLong()
+int MessageIn::readLong()
{
- long value = -1;
+ int value = -1;
if (mPos + 4 <= mLength)
{
uint32_t t;
diff --git a/src/net/messagein.h b/src/net/messagein.h
index cb8e44cd..37103f2c 100644
--- a/src/net/messagein.h
+++ b/src/net/messagein.h
@@ -41,16 +41,11 @@ class MessageIn
*/
MessageIn(const char *data, unsigned int length);
- /**
- * Destructor.
- */
- ~MessageIn();
-
- short getId() { return mId; } /**< Returns the message ID. */
+ int getId() { return mId; } /**< Returns the message ID. */
- char readByte(); /**< Reads a byte. */
- short readShort(); /**< Reads a short. */
- long readLong(); /**< Reads a long. */
+ int readByte(); /**< Reads a byte. */
+ int readShort(); /**< Reads a short. */
+ int readLong(); /**< Reads a long. */
/**
* Reads a 3-byte block containing tile-based coordinates.
@@ -79,7 +74,7 @@ class MessageIn
private:
const char* mData; /**< The message data. */
unsigned int mLength; /**< The length of the data. */
- short mId; /**< The message ID. */
+ unsigned short mId; /**< The message ID. */
/**
* Actual position in the packet. From 0 to packet->length.