summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2005-06-13 20:41:51 +0000
committerYohann Ferreira <bertram@cegetel.net>2005-06-13 20:41:51 +0000
commit19ecdfa678a24fd30d48d6e9001d39be53e2e6df (patch)
tree858304b33b038fc12c6fb66f5c5dfd6e1d17345d
parent0d64e2728309e3fe97c9cbbd97ea6a722fc5dffb (diff)
downloadmanaserv-19ecdfa678a24fd30d48d6e9001d39be53e2e6df.tar.gz
manaserv-19ecdfa678a24fd30d48d6e9001d39be53e2e6df.tar.bz2
manaserv-19ecdfa678a24fd30d48d6e9001d39be53e2e6df.tar.xz
manaserv-19ecdfa678a24fd30d48d6e9001d39be53e2e6df.zip
First corrections of messageIn class.
-rw-r--r--src/messagein.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/messagein.cpp b/src/messagein.cpp
index 3fc72e5a..b17d816b 100644
--- a/src/messagein.cpp
+++ b/src/messagein.cpp
@@ -46,10 +46,9 @@ char MessageIn::readByte()
{
if (packet) // if Packet exists
{
- if ( pos < (packet->length - 1) ) // if there is enough to read
+ if ( pos < packet->length ) // if there is enough to read
{
- pos++;
- return packet->data[pos - 1];
+ return packet->data[pos++];
}
else
{
@@ -65,7 +64,7 @@ short MessageIn::readShort()
{
if (packet) // if Packet exists
{
- if ( (pos + sizeof(short)) <= (packet->length - 1) )
+ if ( (pos + sizeof(short)) <= packet->length )
{
pos += sizeof(short);
return (short) SDLNet_Read16(&(packet->data[pos - sizeof(short)]));
@@ -84,7 +83,7 @@ long MessageIn::readLong()
{
if (packet) // if Packet exists
{
- if ( (pos + sizeof(long)) <= (packet->length - 1) )
+ if ( (pos + sizeof(long)) <= packet->length )
{
pos += sizeof(long);
return (long) SDLNet_Read32(&(packet->data[pos - sizeof(long)]));
@@ -113,7 +112,7 @@ std::string MessageIn::readString(int length)
if ( length != -1 ) // if the length isn't specified, read it in the packet
{
// If the length of the packet is sufficient for us to read the length of the string
- if ( (pos + sizeof(short)) <= (packet->length - 1) )
+ if ( (pos + sizeof(short)) <= packet->length )
{
// We first read the length of the string given by the short before it.
stringLength = (short)SDLNet_Read16(&(packet->data[pos]));
@@ -122,7 +121,7 @@ std::string MessageIn::readString(int length)
else
{
// Place us to the end as the size is a short
- pos = packet->length - 1;
+ pos = packet->length;
}
}
else // if the length is specified
@@ -132,7 +131,7 @@ std::string MessageIn::readString(int length)
if ( stringLength > 0 )
{
- if ( (pos + stringLength) <= (packet->length - 1) ) // If there's enough length to copy
+ if ( (pos + stringLength) <= packet->length ) // If there's enough length to copy
{
char tempChar[stringLength+1];
memcpy(&tempChar, packet->data, stringLength);
@@ -159,4 +158,4 @@ std::string MessageIn::readString(int length)
}
} // End if there is a packet
return "";
-} \ No newline at end of file
+}