[Tux4kids-commits] r1209 - tuxmath/branches/lan/server

David Bruce dbruce-guest at alioth.debian.org
Wed Jul 15 00:35:33 UTC 2009


Author: dbruce-guest
Date: 2009-07-15 00:35:32 +0000 (Wed, 15 Jul 2009)
New Revision: 1209

Modified:
   tuxmath/branches/lan/server/server.c
Log:
clean up of nickname setting code



Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-07-14 22:36:34 UTC (rev 1208)
+++ tuxmath/branches/lan/server/server.c	2009-07-15 00:35:32 UTC (rev 1209)
@@ -327,35 +327,14 @@
 
   client[slot].sock = temp_sock;
 
-  /* We are receiving the client's name that was entered:       */
-  /* NOTE this will block if the client doesn't send anything,  */
-  /* making an easy target for a DOS attack - DSB               */
-  if( SDLNet_TCP_Recv(client[slot].sock, buffer, NET_BUF_LEN) > 0)
+  /* Add client socket to set: */
+  sockets_used = SDLNet_TCP_AddSocket(client_set, client[slot].sock);
+  if(sockets_used == -1) //No way this should happen
   {
-    strncpy(client[slot].name, buffer, NAME_SIZE);
-    printf(" JOINED  :::   %s\n", client[slot].name);
-    //Announcement for all clients:
-    snprintf(buffer, NET_BUF_LEN, 
-          "Player %s has connected to the server\n",
-           client[slot].name);             
-    broadcast_msg(buffer);
-
-
-    /* Add client socket to set: */
-    sockets_used = SDLNet_TCP_AddSocket(client_set, client[slot].sock);
-    if(sockets_used == -1) //No way this should happen
-    {
-      printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
-      cleanup_server();
-      exit(EXIT_FAILURE);
-    }
+    printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
+    cleanup_server();
+    exit(EXIT_FAILURE);
   }
-  else   //This means the socket didn't connect successfully
-  {
-    printf("SDLNet_TCP_Recv() failed");
-    remove_client(slot);
-    return;   // Leave num_clients unchanged
-  }
 
   /* At this point num_clients can be updated: */
   num_clients = sockets_used;
@@ -575,7 +554,9 @@
   char* p;
   if(buf == NULL)
     return 0;
+  printf("in msg_set_name() buf is: %s\n");
   p = strchr(buf, '\t');
+  printf("p - buf is: %d\n", p - buf);
   if(p)
   { 
     p++;




More information about the Tux4kids-commits mailing list