From 593e65eef0d43f2ff61dc1b4f3160c0a16b5f015 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Fri, 5 Jan 2007 20:12:51 +0000 Subject: Simplified handling of verbosity levels. Optimized code by generating only needed messages. --- src/net/connection.cpp | 11 +++++++---- src/net/connectionhandler.cpp | 17 +++++++++-------- src/net/netcomputer.cpp | 5 ++--- 3 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src/net') diff --git a/src/net/connection.cpp b/src/net/connection.cpp index 8a5c8d0..faff533 100644 --- a/src/net/connection.cpp +++ b/src/net/connection.cpp @@ -79,7 +79,7 @@ void Connection::send(MessageOut const &msg, bool reliable, unsigned channel) } else { - LOG_WARN("Failure to create packet!", 0); + LOG_ERROR("Failure to create packet!"); } } @@ -92,12 +92,15 @@ void Connection::process() switch (event.type) { case ENET_EVENT_TYPE_RECEIVE: - if (event.packet->dataLength >= 2) { + if (event.packet->dataLength >= 2) + { MessageIn msg((char *)event.packet->data, event.packet->dataLength); processMessage(msg); - } else { - LOG_ERROR("Message too short.", 0); + } + else + { + LOG_WARN("Message too short."); } // Clean up the packet now that we are done using it. enet_packet_destroy(event.packet); diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp index 7782a74..69ac933 100644 --- a/src/net/connectionhandler.cpp +++ b/src/net/connectionhandler.cpp @@ -49,7 +49,7 @@ bool ConnectionHandler::startListen(enet_uint16 port) address.host = ENET_HOST_ANY; address.port = port; - LOG_INFO("Listening on port " << port << "...", 0); + LOG_INFO("Listening on port " << port << "..."); host = enet_host_create(&address /* the address to bind the server host to */, MAX_CLIENTS /* allow up to MAX_CLIENTS clients and/or outgoing connections */, 0 /* assume any amount of incoming bandwidth */, @@ -96,7 +96,7 @@ void ConnectionHandler::process() LOG_INFO("A new client connected from " << ip4ToString(event.peer->address.host) << ":" << event.peer->address.port << " to port " << - host->address.port, 0); + host->address.port); NetComputer *comp = computerConnected(event.peer); clients.push_back(comp); @@ -124,13 +124,13 @@ void ConnectionHandler::process() if (event.packet->dataLength >= 2) { MessageIn msg((char *)event.packet->data, event.packet->dataLength); - LOG_INFO("Received message " << msg.getId() << " (" - << event.packet->dataLength << " B) from " - << *comp, 2); + LOG_DEBUG("Received message " << msg.getId() << " (" + << event.packet->dataLength << " B) from " + << *comp); processMessage(comp, msg); } else { - LOG_ERROR("Message too short from " << *comp, 0); + LOG_ERROR("Message too short from " << *comp); } /* Clean up the packet now that we're done using it. */ @@ -140,7 +140,7 @@ void ConnectionHandler::process() case ENET_EVENT_TYPE_DISCONNECT: { NetComputer *comp = (NetComputer *)event.peer->data; - LOG_INFO(ip4ToString(event.peer->address.host) << " disconnected.", 0); + LOG_INFO(ip4ToString(event.peer->address.host) << " disconnected."); // Reset the peer's client information. computerDisconnected(comp); clients.erase(std::find(clients.begin(), clients.end(), comp)); @@ -155,7 +155,8 @@ void ConnectionHandler::process() void ConnectionHandler::sendToEveryone(const MessageOut &msg) { for (NetComputers::iterator i = clients.begin(), i_end = clients.end(); - i != i_end; ++i) { + i != i_end; ++i) + { (*i)->send(msg); } } diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp index f963db5..3e4a4db 100644 --- a/src/net/netcomputer.cpp +++ b/src/net/netcomputer.cpp @@ -63,8 +63,7 @@ void NetComputer::send(const MessageOut &msg, bool reliable, unsigned int channel) { - LOG_INFO("Sending packet of length " << msg.getLength() << " to " - << *this, 2); + LOG_DEBUG("Sending packet of length " << msg.getLength() << " to " << *this); ENetPacket *packet; packet = enet_packet_create(msg.getData(), @@ -77,7 +76,7 @@ NetComputer::send(const MessageOut &msg, bool reliable, } else { - LOG_WARN("Failure to create packet!", 0); + LOG_ERROR("Failure to create packet!"); } } -- cgit