summaryrefslogtreecommitdiff
path: root/src/connectionhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/connectionhandler.cpp')
-rw-r--r--src/connectionhandler.cpp129
1 files changed, 0 insertions, 129 deletions
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
index c70f34e4..b0a85f71 100644
--- a/src/connectionhandler.cpp
+++ b/src/connectionhandler.cpp
@@ -100,135 +100,6 @@ ConnectionHandler::ConnectionHandler()
void
ConnectionHandler::startListen(ListenThreadData *ltd)
{
- /*
- // Allocate a socket set
- SDLNet_SocketSet set = SDLNet_AllocSocketSet(MAX_CLIENTS);
- if (!set) {
- LOG_FATAL("SDLNet_AllocSocketSet: " << SDLNet_GetError(), 0)
- exit(1);
- }
-
- // Add the server socket to the socket set
- if (SDLNet_TCP_AddSocket(set, ltd->socket) < 0) {
- LOG_FATAL("SDLNet_AddSocket: " << SDLNet_GetError(), 0)
- exit(1);
- }
-
- // Keep checking for socket activity while running
- while (ltd->running) {
- int numready = SDLNet_CheckSockets(set, 100);
-
- if (numready == -1) {
- LOG_ERROR("SDLNet_CheckSockets: " << SDLNet_GetError(), 0)
- // When this is a system error, perror may help us
- perror("SDLNet_CheckSockets");
- }
- else if (numready > 0) {
- LOG_INFO(numready << " socket(s) with activity!", 0)
-
- // Check server socket
- if (SDLNet_SocketReady(ltd->socket)) {
- TCPsocket client = SDLNet_TCP_Accept(ltd->socket);
-
- if (client) {
- // Add the client socket to the socket set
- if (SDLNet_TCP_AddSocket(set, client) < 0) {
- LOG_ERROR("SDLNet_AddSocket: " << SDLNet_GetError(), 0)
- }
- else {
- NetComputer *comp = new NetComputer(this, client);
- clients.push_back(comp);
- computerConnected(comp);
- LOG_INFO(clients.size() << " client(s) connected", 0)
- }
- }
- }
-
- // Check client sockets
- NetComputers::iterator i;
-
- for (i = clients.begin(); i != clients.end(); )
- {
- NetComputer *comp = *i;
- TCPsocket s = (*i)->getSocket();
-
- if (SDLNet_SocketReady(s))
- {
- char buffer[1024];
- int result = SDLNet_TCP_Recv(s, buffer, 1024);
- if (result <= 0) {
- SDLNet_TCP_DelSocket(set, s);
- SDLNet_TCP_Close(s);
- computerDisconnected(comp);
- delete comp;
- comp = NULL;
- }
- else {
- // Copy the incoming data to the in buffer of this
- // client
- //buffer[result] = 0;
- //LOG_INFO("Received: " << buffer << ", Length: "
- // << result);
- LOG_INFO("Received length: " << result, 2);
-
-#ifdef SCRIPT_SUPPORT
- // 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.
-
- //script->message(buffer);
-#endif
-
- // 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
- // representation
- std::string ipaddr = ip4ToString(
- SDLNet_TCP_GetPeerAddress(s)->host);
-
- // Make sure that the packet is big enough (> short)
- if (result >= 2)
- {
- Packet *packet = new Packet(buffer, result);
- MessageIn msg(packet); // (MessageIn frees packet)
-
- short messageId = msg.getId();
-
- if (handlers.find(messageId) != handlers.end())
- {
- // send message to appropriate handler
- handlers[messageId]->receiveMessage(
- *comp, msg);
- }
- else {
- // bad message (no registered handler)
- LOG_ERROR("Unhandled message (" << messageId
- << ") received from " << ipaddr, 0);
- }
- }
- else {
- LOG_ERROR("Message too short from " << ipaddr, 0);
- }
- }
- }
-
- // Traverse to next client, possibly deleting current
- if (comp == NULL) {
- i = clients.erase(i);
- }
- else {
- i++;
- }
- }
- }
- }
-
- // - Disconnect all clients (close sockets)
-
- SDLNet_FreeSocketSet(set);*/
-
while (ltd->running)
{
ENetEvent event;