summaryrefslogtreecommitdiffstats
path: root/src/Net
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-09-07 21:39:11 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-09-07 21:39:11 +0200
commitce10864739759813d7376e447fae96abef23598d (patch)
tree3e4d9c732a6836dcfb66889fd204e1177800c518 /src/Net
parent7d5b81e9936b1c778fd6408f3f22478e9ab9486b (diff)
downloadmad-ce10864739759813d7376e447fae96abef23598d.tar
mad-ce10864739759813d7376e447fae96abef23598d.zip
Einige Vereinfachungen und Bugfixes
Diffstat (limited to 'src/Net')
-rw-r--r--src/Net/Connection.cpp8
-rw-r--r--src/Net/Packet.h15
2 files changed, 12 insertions, 11 deletions
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp
index ac3121d..6a30d11 100644
--- a/src/Net/Connection.cpp
+++ b/src/Net/Connection.cpp
@@ -77,13 +77,13 @@ void Connection::packetHeaderReceiveHandler(const void *data, unsigned long leng
header = *reinterpret_cast<const Packet::Data*>(data);
if(header.length == 0) {
- signal(this, Packet(static_cast<Packet::Type>(header.type), header.requestId));
+ signal(this, Packet((Packet::Type)ntohs(header.type), ntohs(header.requestId)));
enterReceiveLoop();
}
else {
state = PACKET_DATA;
- rawReceive(header.length, sigc::mem_fun(this, &Connection::packetDataReceiveHandler));
+ rawReceive(ntohs(header.length), sigc::mem_fun(this, &Connection::packetDataReceiveHandler));
}
}
@@ -91,13 +91,13 @@ void Connection::packetDataReceiveHandler(const void *data, unsigned long length
if(state != PACKET_DATA)
return;
- if(length != header.length) {
+ if(length != ntohs(header.length)) {
// TODO: Error
doDisconnect();
return;
}
- signal(this, Packet(static_cast<Packet::Type>(header.type), header.requestId, data, length));
+ signal(this, Packet((Packet::Type)ntohs(header.type), ntohs(header.requestId), data, length));
enterReceiveLoop();
}
diff --git a/src/Net/Packet.h b/src/Net/Packet.h
index cd734a4..08bc9be 100644
--- a/src/Net/Packet.h
+++ b/src/Net/Packet.h
@@ -22,6 +22,7 @@
#include <cstdlib>
#include <cstring>
+#include <netinet/in.h>
namespace Mad {
namespace Net {
@@ -48,10 +49,10 @@ class Packet {
Packet(Type type, unsigned short requestId, const void *data = NULL, unsigned short length = 0) {
rawData = (Data*)std::malloc(sizeof(Data)+length);
- rawData->type = type;
- rawData->requestId = requestId;
+ rawData->type = htons(type);
+ rawData->requestId = htons(requestId);
rawData->reserved = 0;
- rawData->length = length;
+ rawData->length = htons(length);
if(length)
std::memcpy(rawData->data, data, length);
@@ -79,15 +80,15 @@ class Packet {
}
Type getType() const {
- return (Type)rawData->type;
+ return (Type)ntohs(rawData->type);
}
unsigned short getRequestId() const {
- return rawData->requestId;
+ return ntohs(rawData->requestId);
}
unsigned short getLength() const {
- return rawData->length;
+ return ntohs(rawData->length);
}
const unsigned char* getData() const {
@@ -99,7 +100,7 @@ class Packet {
}
unsigned long getRawDataLength() const {
- return sizeof(Data) + rawData->length;
+ return sizeof(Data) + ntohs(rawData->length);
}
};