summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-16 21:18:11 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-16 21:18:11 +0000
commitd3175115354bb2417f01877a96d0068e2f2c875d (patch)
tree3fe6dde2b7922eb12bc376687ae18a59971d908e /src/net
parent43a80fa64acb7f02cf5305b4a3d2ef6040b4b8c9 (diff)
downloadmana-client-d3175115354bb2417f01877a96d0068e2f2c875d.tar.gz
mana-client-d3175115354bb2417f01877a96d0068e2f2c875d.tar.bz2
mana-client-d3175115354bb2417f01877a96d0068e2f2c875d.tar.xz
mana-client-d3175115354bb2417f01877a96d0068e2f2c875d.zip
Rename {read,write}{Byte,Short,Long} to {read,write}Int{8,16,32}.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/messagein.cpp48
-rw-r--r--src/net/messagein.h21
-rw-r--r--src/net/messageout.cpp49
-rw-r--r--src/net/messageout.h13
-rw-r--r--src/net/protocol.cpp8
5 files changed, 67 insertions, 72 deletions
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index 25bf2f07..9f2b38f7 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -38,49 +38,47 @@ MessageIn::MessageIn(const char *data, unsigned int length):
mPos(0)
{
// Read the message ID
- mId = readShort();
+ mId = readInt16();
}
-char
-MessageIn::readByte()
+Sint8
+MessageIn::readInt8()
{
assert(mPos < mLength);
return mData[mPos++];
}
-short
-MessageIn::readShort()
+Sint16
+MessageIn::readInt16()
{
assert(mPos + 2 <= mLength);
mPos += 2;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- return SDL_Swap16(*(short*)(mData + (mPos - 2)));
+ return SDL_Swap16(*(Sint16*)(mData + (mPos - 2)));
#else
- return (*(short*)(mData + (mPos - 2)));
+ return (*(Sint16*)(mData + (mPos - 2)));
#endif
}
-long
-MessageIn::readLong()
+Sint32
+MessageIn::readInt32()
{
assert(mPos + 4 <= mLength);
mPos += 4;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- return SDL_Swap32(*(long*)(mData + (mPos - 4)));
+ return SDL_Swap32(*(Sint32*)(mData + (mPos - 4)));
#else
- return (*(long*)(mData + (mPos - 4)));
+ return (*(Sint32*)(mData + (mPos - 4)));
#endif
}
void
-MessageIn::readCoordinates(unsigned short &x,
- unsigned short &y,
- unsigned char &direction)
+MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction)
{
assert(mPos + 3 <= mLength);
const char *data = mData + mPos;
- short temp;
+ Sint16 temp;
temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff);
x = temp >> 6;
@@ -93,13 +91,13 @@ MessageIn::readCoordinates(unsigned short &x,
}
void
-MessageIn::readCoordinatePair(unsigned short &srcX, unsigned short &srcY,
- unsigned short &dstX, unsigned short &dstY)
+MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY,
+ Uint16 &dstX, Uint16 &dstY)
{
assert(mPos + 5 <= mLength);
const char *data = mData + mPos;
- short temp;
+ Sint16 temp;
temp = MAKEWORD(data[3], data[2] & 0x000f);
dstX = temp >> 2;
@@ -129,7 +127,7 @@ MessageIn::readString(int length)
// Get string length
if (length < 0) {
- stringLength = readShort();
+ stringLength = readInt16();
} else {
stringLength = length;
}
@@ -149,20 +147,20 @@ MessageIn::readString(int length)
return read;
}
-char& operator<<(char &lhs, MessageIn &msg)
+Sint8& operator<<(Sint8 &lhs, MessageIn &msg)
{
- lhs = msg.readByte();
+ lhs = msg.readInt8();
return lhs;
}
-short& operator<<(short &lhs, MessageIn &msg)
+Sint16& operator<<(Sint16 &lhs, MessageIn &msg)
{
- lhs = msg.readShort();
+ lhs = msg.readInt16();
return lhs;
}
-long& operator<<(long &lhs, MessageIn &msg)
+Sint32& operator<<(Sint32 &lhs, MessageIn &msg)
{
- lhs = msg.readLong();
+ lhs = msg.readInt32();
return lhs;
}
diff --git a/src/net/messagein.h b/src/net/messagein.h
index 087d325c..d97cd8b6 100644
--- a/src/net/messagein.h
+++ b/src/net/messagein.h
@@ -25,15 +25,16 @@
#define _TMW_MESSAGEIN_
#include <string>
+#include <SDL_types.h>
/**
* Used for parsing an incoming message.
*/
class MessageIn
{
- friend char& operator<<(char &lhs, MessageIn &msg);
- friend short& operator<<(short &lhs, MessageIn &msg);
- friend long& operator<<(long &lhs, MessageIn &msg);
+ friend Sint8& operator<<(Sint8 &lhs, MessageIn &msg);
+ friend Sint16& operator<<(Sint16 &lhs, MessageIn &msg);
+ friend Sint32& operator<<(Sint32 &lhs, MessageIn &msg);
public:
/**
@@ -53,26 +54,24 @@ class MessageIn
unsigned int
getLength() { return mLength; }
- char readByte(); /**< Reads a byte. */
- short readShort(); /**< Reads a short. */
- long readLong(); /**< Reads a long. */
+ Sint8 readInt8(); /**< Reads a byte. */
+ Sint16 readInt16(); /**< Reads a short. */
+ Sint32 readInt32(); /**< Reads a long. */
/**
* Reads a special 3 byte block used by eAthena, containing x and y
* coordinates and direction.
*/
void
- readCoordinates(unsigned short &x,
- unsigned short &y,
- unsigned char &direction);
+ readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction);
/**
* Reads a special 5 byte block used by eAthena, containing a source
* and destination coordinate pair.
*/
void
- readCoordinatePair(unsigned short &srcX, unsigned short &srcY,
- unsigned short &dstX, unsigned short &dstY);
+ readCoordinatePair(Uint16 &srcX, Uint16 &srcY,
+ Uint16 &dstX, Uint16 &dstY);
/**
* Skips a given number of bytes.
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 713d49be..9b27a6a5 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -57,39 +57,36 @@ void MessageOut::expand(size_t bytes)
mDataSize = bytes;*/
}
-void MessageOut::writeByte(char value)
+void MessageOut::writeInt8(Sint8 value)
{
- expand(mPos + sizeof(char));
+ expand(mPos + sizeof(Sint8));
mData[mPos] = value;
- mPos += sizeof(char);
- out_size += sizeof(char);
+ mPos += sizeof(Sint8);
+ out_size += sizeof(Sint8);
}
-void MessageOut::writeShort(short value)
+void MessageOut::writeInt16(Sint16 value)
{
- expand(mPos + sizeof(short));
+ expand(mPos + sizeof(Sint16));
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- (*(short *)(mData + mPos)) = SDL_Swap16(value);
+ (*(Sint16 *)(mData + mPos)) = SDL_Swap16(value);
#else
- (*(short *)(mData + mPos)) = value;
+ (*(Sint16 *)(mData + mPos)) = value;
#endif
- mPos += sizeof(short);
- out_size += sizeof(short);
+ mPos += sizeof(Sint16);
+ out_size += sizeof(Sint16);
}
-/*
- writeLong should use an int because long is 8 bytes in x86_64 arch !
-*/
-void MessageOut::writeLong(int value)
+void MessageOut::writeInt32(Sint32 value)
{
- expand(mPos + sizeof(int));
+ expand(mPos + sizeof(Sint32));
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- (*(int *)(mData + mPos)) = SDL_Swap32(value);
+ (*(Sint32 *)(mData + mPos)) = SDL_Swap32(value);
#else
- (*(int *)(mData + mPos)) = value;
+ (*(Sint32 *)(mData + mPos)) = value;
#endif
- mPos += sizeof(int);
- out_size += sizeof(int);
+ mPos += sizeof(Sint32);
+ out_size += sizeof(Sint32);
}
void MessageOut::writeString(const std::string &string, int length)
@@ -99,7 +96,7 @@ void MessageOut::writeString(const std::string &string, int length)
if (length < 0)
{
// Write the length at the start if not fixed
- writeShort(string.length());
+ writeInt16(string.length());
expand(mPos + string.length());
}
else
@@ -133,20 +130,20 @@ const Packet *MessageOut::getPacket()
return mPacket;
}
-MessageOut& operator<<(MessageOut &msg, const char &rhs)
+MessageOut& operator<<(MessageOut &msg, const Sint8 &rhs)
{
- msg.writeByte(rhs);
+ msg.writeInt8(rhs);
return msg;
}
-MessageOut& operator<<(MessageOut &msg, const short &rhs)
+MessageOut& operator<<(MessageOut &msg, const Sint16 &rhs)
{
- msg.writeShort(rhs);
+ msg.writeInt16(rhs);
return msg;
}
-MessageOut& operator<<(MessageOut &msg, const long &rhs)
+MessageOut& operator<<(MessageOut &msg, const Sint32 &rhs)
{
- msg.writeLong(rhs);
+ msg.writeInt32(rhs);
return msg;
}
diff --git a/src/net/messageout.h b/src/net/messageout.h
index 04a5ba91..b2ee506e 100644
--- a/src/net/messageout.h
+++ b/src/net/messageout.h
@@ -25,6 +25,7 @@
#define _TMW_MESSAGEOUT_
#include <iosfwd>
+#include <SDL_types.h>
class Packet;
@@ -33,9 +34,9 @@ class Packet;
*/
class MessageOut
{
- friend MessageOut& operator<<(MessageOut &msg, const char &rhs);
- friend MessageOut& operator<<(MessageOut &msg, const short &rhs);
- friend MessageOut& operator<<(MessageOut &msg, const long &rhs);
+ friend MessageOut& operator<<(MessageOut &msg, const Sint8 &rhs);
+ friend MessageOut& operator<<(MessageOut &msg, const Sint16 &rhs);
+ friend MessageOut& operator<<(MessageOut &msg, const Sint32 &rhs);
public:
/**
@@ -48,9 +49,9 @@ class MessageOut
*/
~MessageOut();
- void writeByte(char value); /**< Writes a byte. */
- void writeShort(short value); /**< Writes a short. */
- void writeLong(int value); /**< Writes a long. */
+ void writeInt8(Sint8 value); /**< Writes a byte. */
+ void writeInt16(Sint16 value); /**< Writes a short. */
+ void writeInt32(Sint32 value); /**< Writes a long. */
/**
* Writes a string. If a fixed length is not given (-1), it is stored
diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp
index 516afa59..e57be110 100644
--- a/src/net/protocol.cpp
+++ b/src/net/protocol.cpp
@@ -73,16 +73,16 @@ void walk(unsigned short x, unsigned short y, unsigned char direction)
char temp[3];
MessageOut outMsg;
set_coordinates(temp, x, y, direction);
- outMsg.writeShort(0x0085);
+ outMsg.writeInt16(0x0085);
outMsg.writeString(temp, 3);
}
void action(char type, int id)
{
MessageOut outMsg;
- outMsg.writeShort(0x0089);
- outMsg.writeLong(id);
- outMsg.writeByte(type);
+ outMsg.writeInt16(0x0089);
+ outMsg.writeInt32(id);
+ outMsg.writeInt8(type);
}
Being* attack(unsigned short x, unsigned short y, unsigned char direction)