summaryrefslogtreecommitdiff
path: root/src/network/core/packet.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-01-12 20:19:49 +0000
committerrubidium <rubidium@openttd.org>2007-01-12 20:19:49 +0000
commitf66b373b52b2daef69507c402577a1a02b65c40b (patch)
tree23bff1b129004614fd68cb0c30436a14bbe240e9 /src/network/core/packet.cpp
parentee1021d29c6baa6380faf17e270fd5194d2b330c (diff)
downloadopenttd-f66b373b52b2daef69507c402577a1a02b65c40b.tar.xz
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
Diffstat (limited to 'src/network/core/packet.cpp')
-rw-r--r--src/network/core/packet.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index 511e0c675..fe10af48f 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -6,7 +6,6 @@
#include "../../macros.h"
#include "../../string.h"
#include "../../helpers.hpp"
-#include "../network_data.h"
#include "packet.h"
@@ -111,17 +110,15 @@ void NetworkSend_string(Packet *packet, const char* data)
*/
-extern NetworkRecvStatus CloseConnection(NetworkClientState *cs);
-
/** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */
-static inline bool CanReadFromPacket(NetworkClientState *cs, const Packet *packet, const uint bytes_to_read)
+static inline bool CanReadFromPacket(NetworkSocketHandler *cs, const Packet *packet, const uint bytes_to_read)
{
- /* Don't allow reading from a closed socket */
- if (HasClientQuit(cs)) return false;
+ /* Don't allow reading from a quit client/client who send bad data */
+ if (cs->HasClientQuit()) return false;
/* Check if variable is within packet-size */
if (packet->pos + bytes_to_read > packet->size) {
- CloseConnection(cs);
+ cs->CloseConnection();
return false;
}
@@ -138,7 +135,7 @@ void NetworkRecv_ReadPacketSize(Packet *packet)
packet->size += (uint16)packet->buffer[1] << 8;
}
-uint8 NetworkRecv_uint8(NetworkClientState *cs, Packet *packet)
+uint8 NetworkRecv_uint8(NetworkSocketHandler *cs, Packet *packet)
{
uint8 n;
@@ -148,7 +145,7 @@ uint8 NetworkRecv_uint8(NetworkClientState *cs, Packet *packet)
return n;
}
-uint16 NetworkRecv_uint16(NetworkClientState *cs, Packet *packet)
+uint16 NetworkRecv_uint16(NetworkSocketHandler *cs, Packet *packet)
{
uint16 n;
@@ -159,7 +156,7 @@ uint16 NetworkRecv_uint16(NetworkClientState *cs, Packet *packet)
return n;
}
-uint32 NetworkRecv_uint32(NetworkClientState *cs, Packet *packet)
+uint32 NetworkRecv_uint32(NetworkSocketHandler *cs, Packet *packet)
{
uint32 n;
@@ -172,7 +169,7 @@ uint32 NetworkRecv_uint32(NetworkClientState *cs, Packet *packet)
return n;
}
-uint64 NetworkRecv_uint64(NetworkClientState *cs, Packet *packet)
+uint64 NetworkRecv_uint64(NetworkSocketHandler *cs, Packet *packet)
{
uint64 n;
@@ -190,13 +187,13 @@ uint64 NetworkRecv_uint64(NetworkClientState *cs, Packet *packet)
}
/** Reads a string till it finds a '\0' in the stream */
-void NetworkRecv_string(NetworkClientState *cs, Packet *p, char *buffer, size_t size)
+void NetworkRecv_string(NetworkSocketHandler *cs, Packet *p, char *buffer, size_t size)
{
PacketSize pos;
char *bufp = buffer;
/* Don't allow reading from a closed socket */
- if (HasClientQuit(cs)) return;
+ if (cs->HasClientQuit()) return;
pos = p->pos;
while (--size > 0 && pos < p->size && (*buffer++ = p->buffer[pos++]) != '\0') {}