From 87be1a8a52a5485d1cf90240cbf628004cbd5350 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 13 May 2006 18:12:22 +0000 Subject: Applied patch by Guillaume Melquiond which adds ENet check and adds timer.cpp/h to the Makefile.am. Also fixed some compilation warnings. --- src/connectionhandler.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/connectionhandler.cpp') diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp index b0a85f71..b7d1b1ba 100644 --- a/src/connectionhandler.cpp +++ b/src/connectionhandler.cpp @@ -103,7 +103,7 @@ ConnectionHandler::startListen(ListenThreadData *ltd) while (ltd->running) { ENetEvent event; - + // Wait up to 1000 milliseconds for an event. while (enet_host_service(ltd->host, &event, 1000) > 0) { @@ -119,19 +119,19 @@ ConnectionHandler::startListen(ListenThreadData *ltd) computerConnected(comp); /*LOG_INFO(ltd->host->peerCount << " client(s) connected", 0);*/ - + // Store any relevant client information here. event.peer->data = (void *)comp; } break; - + case ENET_EVENT_TYPE_RECEIVE: { LOG_INFO("A packet of length " << event.packet->dataLength << " was received from " << event.peer->address.host, 2); - + NetComputer *comp = (NetComputer *)event.peer->data; - + #ifdef SCRIPT_SUPPORT // This could be good if you wanted to extend the // server protocol using a scripting language. This @@ -171,11 +171,11 @@ ConnectionHandler::startListen(ListenThreadData *ltd) else { LOG_ERROR("Message too short from " << ipaddr, 0); } - + /* Clean up the packet now that we're done using it. */ enet_packet_destroy(event.packet); } break; - + case ENET_EVENT_TYPE_DISCONNECT: { NetComputer *comp = (NetComputer *)event.peer->data; @@ -186,12 +186,14 @@ ConnectionHandler::startListen(ListenThreadData *ltd) delete comp; event.peer->data = NULL; } break; + + default: break; } } } - + // - Disconnect all clients (close sockets) - + // TODO: probably there's a better way. ENetPeer *currentPeer; @@ -265,9 +267,9 @@ void ConnectionHandler::sendAround(tmwserv::BeingPtr beingPtr, MessageOut &msg) i != clients.end(); i++) { // See if the other being is near enough, then send the message - if (abs((*i)->getCharacter().get()->getX() - beingPtr.get()->getX()) <= AROUND_AREA_IN_TILES ) + if (abs((*i)->getCharacter().get()->getX() - beingPtr.get()->getX()) <= (int)AROUND_AREA_IN_TILES ) { - if (abs((*i)->getCharacter().get()->getY() - beingPtr.get()->getY()) <= AROUND_AREA_IN_TILES ) + if (abs((*i)->getCharacter().get()->getY() - beingPtr.get()->getY()) <= (int)AROUND_AREA_IN_TILES ) { (*i)->send(msg.getPacket()); break; -- cgit v1.2.3-70-g09d2