[Tux4kids-commits] r1315 - in tuxmath/branches/lan: server src

David Bruce dbruce-guest at alioth.debian.org
Fri Jul 31 22:36:16 UTC 2009


Author: dbruce-guest
Date: 2009-07-31 22:36:16 +0000 (Fri, 31 Jul 2009)
New Revision: 1315

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
   tuxmath/branches/lan/src/network.c
Log:
Refined string handling to allow whitespace in server name string
e.g. "TuxMath - Mrs. Wilson's Third Grade"



Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-07-31 21:33:03 UTC (rev 1314)
+++ tuxmath/branches/lan/server/server.c	2009-07-31 22:36:16 UTC (rev 1315)
@@ -108,10 +108,21 @@
     exit(EXIT_FAILURE);
   }
 
-  printf("Enter the SERVER's NAME: \n");
+  /* Get server name: */
+  /* FIXME we should save this to disc so it doesn't */
+  /* have to be entered every time.                  */
+  printf("Enter the SERVER's NAME: \n>");
+  fflush(stdout);
   fgets(server_name, NAME_SIZE, stdin);
- 
-  /*    ------------- Main server loop:  ------------------   */
+
+  /* If no nickname received, use default: */
+  if(strlen(server_name) == 1)
+     strcpy(server_name, "TuxMath Server");
+  
+  printf("Waiting for clients to connect:\n>");
+  fflush(stdout);
+
+ /*    ------------- Main server loop:  ------------------   */
   while (!quit)
   {
     /* Respond to any clients pinging us to find the server: */
@@ -905,7 +916,7 @@
   if(MC_MissionAccomplished())
   {
     char buf[NET_BUF_LEN];
-    snprintf(buf, NET_BUF_LEN, "%s", "GAME_OVER_WON");
+    snprintf(buf, NET_BUF_LEN, "%s", "MISSION_ACCOMPLISHED");
     transmit_all(buf);
   }
 
@@ -1078,8 +1089,8 @@
     return 0;
   }
   
-  //NOTE Do we really want to remove client if we don't transmit
-  //the entire buffer? Maybe we need send_all()...
+  //NOTE SDLNet's Send() keeps sending until the requested length is
+  //sent, so it really is an error if we send less thatn NET_BUF_LEN
   snprintf(buf, NET_BUF_LEN, "%s", msg);
   if(SDLNet_TCP_Send(client[i].sock, buf, NET_BUF_LEN) < NET_BUF_LEN)
   {

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-07-31 21:33:03 UTC (rev 1314)
+++ tuxmath/branches/lan/server/testclient.c	2009-07-31 22:36:16 UTC (rev 1315)
@@ -422,6 +422,7 @@
           //Tell server we answered it right:
           LAN_AnsweredCorrectly(fc);
           erase_flashcard(fc);  
+          print_current_quests();
         }
         else  //we got input, but not the correct answer:
         {
@@ -498,7 +499,7 @@
   fc->formula_string[0] = '\0';
   fc->answer_string[0] = '\0';
   fc->question_id = -1;
-  fc->answer = 0;
+  fc->answer = -9999;
   fc->difficulty = 0;
   return 1;
 }

Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c	2009-07-31 21:33:03 UTC (rev 1314)
+++ tuxmath/branches/lan/src/network.c	2009-07-31 22:36:16 UTC (rev 1315)
@@ -463,6 +463,7 @@
 {
   int i = 0;
   int already_in = 0;
+  char* p = NULL;
 
   if(!pkt)
     return 0;
@@ -481,7 +482,12 @@
   {
     servers[i].ip.host = pkt->address.host;
     servers[i].ip.port = pkt->address.port;
-    sscanf(pkt->data,"%*s %s\n",servers[i].name);
+    // not using sscanf() because server_name could contain whitespace:
+    p = strchr(pkt->data, '\t');
+    p++;
+    if(p)
+      strncpy(servers[i].name, p, NAME_SIZE);
+
     i++;
   }
 




More information about the Tux4kids-commits mailing list