summaryrefslogtreecommitdiff
path: root/src/connectionhandler.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-19 01:40:32 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-19 01:40:32 +0000
commitcb25562fc18a169ee5fe2e2440b5267cbe0b9c6e (patch)
tree02f19cdc16f875cd5b53b19c364ea0a6b65104f8 /src/connectionhandler.cpp
parent62395df8a674475cd7b277e964cc5512fa6e7576 (diff)
downloadmanaserv-cb25562fc18a169ee5fe2e2440b5267cbe0b9c6e.tar.gz
manaserv-cb25562fc18a169ee5fe2e2440b5267cbe0b9c6e.tar.bz2
manaserv-cb25562fc18a169ee5fe2e2440b5267cbe0b9c6e.tar.xz
manaserv-cb25562fc18a169ee5fe2e2440b5267cbe0b9c6e.zip
Changing the way the message ID is read.
Diffstat (limited to 'src/connectionhandler.cpp')
-rw-r--r--src/connectionhandler.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
index 338913f8..ad42adcf 100644
--- a/src/connectionhandler.cpp
+++ b/src/connectionhandler.cpp
@@ -149,7 +149,8 @@ ConnectionHandler::startListen(ListenThreadData *ltd)
NetComputer *comp = *i;
TCPsocket s = (*i)->getSocket();
- if (SDLNet_SocketReady(s)) {
+ if (SDLNet_SocketReady(s))
+ {
char buffer[1024];
int result = SDLNet_TCP_Recv(s, buffer, 1024);
if (result <= 0) {
@@ -171,7 +172,7 @@ ConnectionHandler::startListen(ListenThreadData *ltd)
<< result);
#ifdef SCRIPT_SUPPORT
- // this could be good if you wanted to extend the
+ // This could be good if you wanted to extend the
// server protocol using a scripting language. This
// could be attained by using allowing scripts to
// "hook" certain messages.
@@ -179,33 +180,35 @@ ConnectionHandler::startListen(ListenThreadData *ltd)
//script->message(buffer);
#endif
- // if the scripting subsystem didn't hook the message
+ // If the scripting subsystem didn't hook the message
// it will be handled by the default message handler.
- // convert the client IP address to string
+ // Convert the client IP address to string
// representation
std::string ipaddr = ip4ToString(
SDLNet_TCP_GetPeerAddress(s)->host);
- // generate packet
- Packet *packet = new Packet(buffer, result);
- MessageIn msg(packet); // (MessageIn frees packet)
+ // Make sure that the packet is big enough
+ if (result >= 4)
+ {
+ Packet *packet = new Packet(buffer, result);
+ MessageIn msg(packet); // (MessageIn frees packet)
- // make sure that the packet is big enough
- if (result >= 4) {
- unsigned short messageType =
- SDLNet_Read16((void*)packet->data);
- if (handlers.find(messageType) != handlers.end())
+ short messageId = msg.getId();
+
+ if (handlers.find(messageId) != handlers.end())
{
// send message to appropriate handler
- handlers[messageType]->receiveMessage(
+ handlers[messageId]->receiveMessage(
*comp, msg);
- } else {
+ }
+ else {
// bad message (no registered handler)
- LOG_ERROR("Unhandled message (" << messageType
+ LOG_ERROR("Unhandled message (" << messageId
<< ") received from " << ipaddr);
}
- } else {
+ }
+ else {
LOG_ERROR("Message too short from " << ipaddr);
}
}
@@ -213,10 +216,7 @@ ConnectionHandler::startListen(ListenThreadData *ltd)
// Traverse to next client, possibly deleting current
if (comp == NULL) {
- std::list<NetComputer*>::iterator ii = i;
- ii++;
- clients.erase(i);
- i = ii;
+ i = clients.erase(i);
}
else {
i++;