From 98f41d64a9a1628dd132b356487415762b1409a8 Mon Sep 17 00:00:00 2001 From: Aaron Marks Date: Sun, 17 Jul 2005 03:18:31 +0000 Subject: Added server->client communications. Updated MessageHandler's to use short for message type. --- src/connectionhandler.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/connectionhandler.cpp') diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp index 2a5d6c4..d0a0d23 100644 --- a/src/connectionhandler.cpp +++ b/src/connectionhandler.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "connectionhandler.h" #include "netsession.h" @@ -192,8 +193,8 @@ ConnectionHandler::startListen(ListenThreadData *ltd) // make sure that the packet is big enough if (result >= 4) { - unsigned int messageType = - (unsigned int)*packet->data; + unsigned short messageType = + SDLNet_Read16((void*)packet->data); if (handlers.find(messageType) != handlers.end()) { // send message to appropriate handler @@ -201,8 +202,8 @@ ConnectionHandler::startListen(ListenThreadData *ltd) *comp, msg); } else { // bad message (no registered handler) - LOG_ERROR("Unhandled message received from " - << ipaddr); + LOG_ERROR("Unhandled message (" << messageType + << ") received from " << ipaddr); } } else { LOG_ERROR("Message too short from " << ipaddr); @@ -244,3 +245,18 @@ void ConnectionHandler::registerHandler( { handlers[msgId] = handler; } + +void ConnectionHandler::sendPackets() +{ + for (std::map::iterator i = clients.begin(); + i != clients.end(); i++) { + NetComputer *computer = i->first; + + while (computer->size() > 0) { + // Send queued packet + Packet *packet = computer->front(); + SDLNet_TCP_Send(i->second, packet->data, packet->length); + delete packet; + } + } +} -- cgit