summaryrefslogtreecommitdiff
path: root/src/net/messagein.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-22 19:45:03 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-22 19:45:56 +0100
commit0c43d04b438d41c277ae80402d4b4888db1a0b64 (patch)
tree3aaeb75ecd1bcbe85decedab5f1fa426fe0411e3 /src/net/messagein.cpp
parenta7f5eaeb7f643658d356533a608f0f18d85b6d32 (diff)
parent401802c1d7a1b3d659bdc53a45d9a6292fc1121e (diff)
downloadmana-0c43d04b438d41c277ae80402d4b4888db1a0b64.tar.gz
mana-0c43d04b438d41c277ae80402d4b4888db1a0b64.tar.bz2
mana-0c43d04b438d41c277ae80402d4b4888db1a0b64.tar.xz
mana-0c43d04b438d41c277ae80402d4b4888db1a0b64.zip
Merged the tmwserv client with the eAthena client
This merge involved major changes on both sides, and as such took several weeks. Lots of things are expected to be broken now, however, we now have a single code base to improve and extend, which can be compiled to support either eAthena or tmwserv. In the coming months, the plan is to work towards a client that supports both eAthena and tmwserv, without needing to be recompiled. Conflicts: Everywhere!
Diffstat (limited to 'src/net/messagein.cpp')
-rw-r--r--src/net/messagein.cpp89
1 files changed, 56 insertions, 33 deletions
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index a288d936..813b440f 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -19,11 +19,16 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <cassert>
+#include "messagein.h"
+
+#ifdef TMWSERV_SUPPORT
+#include <enet/enet.h>
+#else
#include <SDL.h>
#include <SDL_endian.h>
+#endif
-#include "messagein.h"
+#include <cassert>
#define MAKEWORD(low,high) \
((unsigned short)(((unsigned char)(low)) | \
@@ -38,32 +43,68 @@ MessageIn::MessageIn(const char *data, unsigned int length):
mId = readInt16();
}
-Sint8 MessageIn::readInt8()
+int MessageIn::readInt8()
{
- assert(mPos < mLength);
- return mData[mPos++];
+ int value = -1;
+ if (mPos < mLength)
+ {
+ value = (unsigned char) mData[mPos];
+ }
+ mPos += 1;
+ return value;
}
-Sint16 MessageIn::readInt16()
+int MessageIn::readInt16()
{
- assert(mPos + 2 <= mLength);
- mPos += 2;
+ int value = -1;
+ if (mPos + 2 <= mLength)
+ {
+#ifdef TMWSERV_SUPPORT
+ uint16_t t;
+ memcpy(&t, mData + mPos, 2);
+ value = (unsigned short) ENET_NET_TO_HOST_16(t);
+#else
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- return SDL_Swap16(*(Sint16*)(mData + (mPos - 2)));
+ value = SDL_Swap16(*(Sint16*)(mData + mPos));
#else
- return (*(Sint16*)(mData + (mPos - 2)));
+ value = (*(Sint16*)(mData + mPos));
#endif
+#endif // TMWSERV_SUPPORT
+ }
+ mPos += 2;
+ return value;
}
-Sint32 MessageIn::readInt32()
+int MessageIn::readInt32()
{
- assert(mPos + 4 <= mLength);
- mPos += 4;
+ int value = -1;
+ if (mPos + 4 <= mLength)
+ {
+#ifdef TMWSERV_SUPPORT
+ uint32_t t;
+ memcpy(&t, mData + mPos, 4);
+ value = ENET_NET_TO_HOST_32(t);
+#else
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- return SDL_Swap32(*(Sint32*)(mData + (mPos - 4)));
+ value = SDL_Swap32(*(Sint32*)(mData + mPos));
#else
- return (*(Sint32*)(mData + (mPos - 4)));
+ value = (*(Sint32*)(mData + mPos));
#endif
+#endif // TMWSERV_SUPPORT
+ }
+ mPos += 4;
+ return value;
+}
+
+void MessageIn::readCoordinates(Uint16 &x, Uint16 &y)
+{
+ if (mPos + 3 <= mLength)
+ {
+ unsigned char const *p = reinterpret_cast< unsigned char const * >(mData + mPos);
+ x = p[0] | ((p[1] & 0x07) << 8);
+ y = (p[1] >> 3) | ((p[2] & 0x3F) << 5);
+ }
+ mPos += 3;
}
void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction)
@@ -164,21 +205,3 @@ std::string MessageIn::readString(int length)
mPos += length;
return readString;
}
-
-Sint8& operator<<(Sint8 &lhs, MessageIn &msg)
-{
- lhs = msg.readInt8();
- return lhs;
-}
-
-Sint16& operator<<(Sint16 &lhs, MessageIn &msg)
-{
- lhs = msg.readInt16();
- return lhs;
-}
-
-Sint32& operator<<(Sint32 &lhs, MessageIn &msg)
-{
- lhs = msg.readInt32();
- return lhs;
-}