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

David Bruce dbruce-guest at alioth.debian.org
Thu Jun 18 20:00:50 UTC 2009


Author: dbruce-guest
Date: 2009-06-18 20:00:47 +0000 (Thu, 18 Jun 2009)
New Revision: 1069

Modified:
   tuxmath/branches/lan/server/mathcards.c
   tuxmath/branches/lan/server/mathcards.h
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/server.h
   tuxmath/branches/lan/server/testclient.c
   tuxmath/branches/lan/server/transtruct.h
Log:
merged minor differences in these files



Modified: tuxmath/branches/lan/server/mathcards.c
===================================================================
--- tuxmath/branches/lan/server/mathcards.c	2009-06-18 17:55:44 UTC (rev 1068)
+++ tuxmath/branches/lan/server/mathcards.c	2009-06-18 20:00:47 UTC (rev 1069)
@@ -193,10 +193,12 @@
 int questions_pending = 0;
 int unanswered = 0;
 int starting_length = 0;
+//NOTE these are no longer used:
 int max_formula_size = 0; //max length in chars of a flashcard's formula
 int max_answer_size = 0; //and of its answer
 
 /* For keeping track of timing data */
+/*FIXME do we really need any of these? */
 float* time_per_question_list = NULL;
 int length_time_per_question_list = 0;
 int length_alloc_time_per_question_list = 0;
@@ -284,8 +286,7 @@
   /* bail out if no struct */
   if (!math_opts)
   {
-
-    mcdprintf("\nError: math_opts null or invalid");
+    mcdprintf("\nError: malloc couldn't allocate math_opts for some reason\n");
     mcdprintf("\nLeaving MC_Initialize()\n");
 
     fprintf(stderr, "\nUnable to initialize math_options");
@@ -295,7 +296,7 @@
   /* set defaults */
   for (i = 0; i < NOPTS; ++i)
     {
-    math_opts->iopts[i] = MC_DEFAULTS[i];
+      math_opts->iopts[i] = MC_DEFAULTS[i];
     }
 
   /* if no negatives to be used, reset any negatives to 0 */
@@ -370,24 +371,14 @@
 
   mcdprintf("max answer, formula size: %d, %d\n",
             max_answer_size, max_formula_size);
-  /* set up new list with pointer to top: */
-// if(n==1)                             				//if selects server , n==1 from titlescreen.c 
-//  { 
-   question_list = generate_list();
 
-   next_wrong_quest = 0;
-   /* initialize counters for new game: */
-   quest_list_length = list_length(question_list);
+  question_list = generate_list();
+
+  next_wrong_quest = 0;
+  /* initialize counters for new game: */
+  quest_list_length = list_length(question_list);
   
-//   SendQuestionList(question_list,quest_list_length);
-//  } 
-  
-//if(n==0)							//if selects client , n==0 from titlescreen.c
-//{
-//   next_wrong_quest = 0;
-//   ReceiveQuestionList(question_list,quest_list_length);
- 
-//}
+
   /* Note: the distinction between quest_list_length and  */
   /* unanswered is that the latter includes questions     */
   /* that are currently "in play" by the user interface - */
@@ -442,7 +433,8 @@
 
     /* initialize lists for new game: */
     delete_list(question_list);
-    if(!randomize_list(&wrong_quests)) {
+    if(!randomize_list(&wrong_quests))
+    {
       fprintf(stderr, "Error during randomization of wrong_quests!\n");
       /* Punt on trying wrong question list, just run normal game */
       return MC_StartGame();
@@ -476,13 +468,13 @@
 }
 
 
-/*  MC_NextQuestion() takes a pointer to an allocated     */
-/*  MC_MathQuestion struct and fills in the fields for    */
-/*  use by the user interface program. It basically is    */
-/*  like taking the next flashcard from the pile. The     */
-/*  node containing the question is removed from the list.*/
-/*  Returns 1 if question found, 0 if list empty/invalid  */
-/*  or if argument pointer is invalid.                    */
+/*  MC_NextQuestion() takes a pointer to an allocated      */
+/*  MC_MathQuestion struct and fills in the fields for     */
+/*  use by the user interface program. It basically is     */
+/*  like taking the next flashcard from the pile. The      */
+/*  node containing the question is removed from the list. */
+/*  Returns 1 if question found, 0 if list empty/invalid   */
+/*  or if argument pointer is invalid.                     */
 int MC_NextQuestion(MC_FlashCard* fc)
 {
   mcdprintf("\nEntering MC_NextQuestion()\n");
@@ -1166,6 +1158,7 @@
   }
 }
 
+
 void print_vect_list(FILE* fp, MC_MathQuestion** vect, int length)
 {
   if (!vect)
@@ -1182,6 +1175,8 @@
   mcdprintf("Leaving print_vect_list()\n");
 }
 
+
+
 #ifdef MC_DEBUG
 void print_card(MC_FlashCard card)
 {
@@ -1230,6 +1225,9 @@
 // }
 #endif
 
+
+
+
 int list_length(MC_MathQuestion* list)
 {
   int length = 0;
@@ -1499,7 +1497,7 @@
 
   generate_random_flashcard_id+=1;
   mcdprintf("Entering generate_random_flashcard()\n");
-  printf("%d\n",generate_random_flashcard_id);
+  mcdprintf("%d\n",generate_random_flashcard_id);
   do
     pt = rand() % MC_NUM_PTYPES;
   while ( (pt == MC_PT_TYPING && !MC_GetOpt(TYPING_PRACTICE_ALLOWED) ) ||
@@ -1559,10 +1557,10 @@
   char tempstr[MC_FORMULA_LEN];
   MC_FlashCard ret;
   MC_Operation op;
-  static int id=0;
+  static int id = 0;
 
-  id+=1;
-  printf(".");
+  id += 1;
+  mcdprintf(".");
   if (length > MAX_FORMULA_NUMS)
     return DEFAULT_CARD;
   if (length <= 2)
@@ -1739,12 +1737,16 @@
   MC_MathQuestion* end_of_list = NULL;
   MC_MathQuestion* tnode = NULL;
 
+#ifdef MC_DEBUG
   MC_PrintMathOptions(stdout, 0);
+#endif
+
   if (!(MC_GetOpt(ARITHMETIC_ALLOWED) ||
       MC_GetOpt(TYPING_PRACTICE_ALLOWED) ||
       MC_GetOpt(COMPARISON_ALLOWED) ) )
     return NULL;
 
+  //FIXME - remind me, why are we doing this??
   //randomize list length by a "bell curve" centered on average
   if (length && MC_GetOpt(VARY_LIST_LENGTH) )
   {
@@ -1817,7 +1819,7 @@
           tnode->card = generate_random_flashcard();
           list = insert_node(list, end_of_list, tnode);
           end_of_list = tnode;
-          mcdprintf("%d...", list_length(list) );
+//          mcdprintf("%d.", list_length(list) );
         }
       }
       else if (length < cl) //if too many questions, chop off tail end of list

Modified: tuxmath/branches/lan/server/mathcards.h
===================================================================
--- tuxmath/branches/lan/server/mathcards.h	2009-06-18 17:55:44 UTC (rev 1068)
+++ tuxmath/branches/lan/server/mathcards.h	2009-06-18 20:00:47 UTC (rev 1069)
@@ -15,7 +15,7 @@
 #ifndef MATHCARDS_H
 #define MATHCARDS_H
 
-#define MC_DEBUG
+//#define MC_DEBUG
 #ifdef MC_DEBUG
 #define mcdprintf(...) printf(__VA_ARGS__)
 #else

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-06-18 17:55:44 UTC (rev 1068)
+++ tuxmath/branches/lan/server/server.c	2009-06-18 20:00:47 UTC (rev 1069)
@@ -34,11 +34,12 @@
   int quit, quit2;
   char buffer[NET_BUF_LEN];
   int command_type = -1;
+  //     size_t length;
   MC_FlashCard flash;
   static int initialize = 0;
   int id;
 
-  printf("Started tuxmathserver, waiting for client to connect:\n");
+  printf("Started tuxmathserver, waiting for client to connect:\n>\n");
 
   if (!MC_Initialize())
   {
@@ -81,9 +82,14 @@
       /* Get the remote address */
       if ((remoteIP = SDLNet_TCP_GetPeerAddress(csd)))
         /* Print the address, converting in the host format */
-        printf("Host connected: IP = %x, Port = %d\n",
+      {
+        printf("Client connected\n>\n");
+#ifdef LAN_DEBUG
+        printf("Client: IP = %x, Port = %d\n",
 	       SDLNet_Read32(&remoteIP->host),
 	       SDLNet_Read16(&remoteIP->port));
+#endif
+      }
       else
         fprintf(stderr, "SDLNet_TCP_GetPeerAddress: %s\n", SDLNet_GetError());
                         
@@ -94,25 +100,31 @@
         if (SDLNet_TCP_Recv(csd, buffer, NET_BUF_LEN) > 0)
         {
           command_type = -1;
-          printf("Client say: %s\n", buffer);
+#ifdef LAN_DEBUG  
+          printf("Buffer received from client: %s\n", buffer);
+#endif
           sscanf (buffer,"%s %d\n",
                          command,
                          &id);  
      
-          if(strcmp(command,"CORRECT_ANSWER") == 0)
+          if(strcmp(command, "CORRECT_ANSWER") == 0)
           {
             command_type = CORRECT_ANSWER;              
-          }                                      
-          //'a' for the setting up the question list                   
-          else if(strcmp(command,"a") == 0)
+          }                             
+          
+          //'a' for the setting up the question list                                           
+          if(strcmp(command, "a") == 0)
           {
-            initialize=1; 
+            initialize = 1; 
             command_type = NEW_GAME;              
           } 
+                                       
           //'b' for asking for a question(flashcard)
-          else if(strcmp(command,"b") == 0)
+          if(strcmp(command, "b") == 0)
           {
+#ifdef LAN_DEBUG
             printf("received request to send question\n");
+#endif
             if(!initialize)
             {
               command_type = LIST_NOT_SETUP;                    
@@ -120,18 +132,19 @@
             else
               command_type = SEND_A_QUESTION;              
           } 
-          else if(strcmp(command, "exit") == 0) /* Terminate this connection */
+
+          if(strcmp(command, "exit") == 0) /* Terminate this connection */
           {
             quit2 = 1;
-            printf("Terminate connection\n");
+            printf("Terminating client connection\n");
           }
-          else if(strcmp(command, "quit") == 0) /* Quit the program */
+
+          if(strcmp(command, "quit") == 0) /* Quit the program */
           {
             quit2 = 1;
             quit = 1;
             printf("Quit program\n");
           }
-          else;
           
           switch(command_type)
           {
@@ -150,7 +163,7 @@
 
             case CORRECT_ANSWER:
             {
-              if(!SendMessage(ANSWER_CORRECT,id))
+              if(!SendMessage(ANSWER_CORRECT, 0))
               {
                 printf("Unable to communicate to the client\n");
               }
@@ -175,13 +188,14 @@
               }
               else
               {                                     
+#ifdef LAN_DEBUG
                 printf("WILL SEND >>\n");  
                 printf("QUESTION_ID       :      %d\n", flash.question_id);
                 printf("FORMULA_STRING    :      %s\n", flash.formula_string);
                 printf("ANSWER STRING     :      %s\n", flash.answer_string);
                 printf("ANSWER            :      %d\n",flash.answer);
                 printf("DIFFICULTY        :      %d\n",flash.difficulty);
-
+#endif
                 if(!SendQuestion(flash))
                 {
                   printf("Unable to send Question\n");
@@ -216,6 +230,7 @@
 int SendQuestion(MC_FlashCard flash)
 {
   int x;
+
   char buf[NET_BUF_LEN];
   snprintf(buf, NET_BUF_LEN, 
                 "%s\t%d\t%d\t%d\t%s\t%s\n",
@@ -225,9 +240,12 @@
                 flash.answer,
                 flash.answer_string,
                 flash.formula_string);
-  printf("buf is: %s\n", buf);
   x = SDLNet_TCP_Send(csd, buf, sizeof(buf));
+
+#ifdef LAN_DEBUG
   printf("SendQuestion() - buf sent:::: %d bytes\n", x);
+  printf("buf is: %s\n", buf);
+#endif
 
   if (x == 0)
     return 0;
@@ -239,58 +257,36 @@
   or anything the client is made to be informed*/
 int SendMessage(int message, int z)         
 {
- int x,len;
+ int x, len;
  char buf[NET_BUF_LEN];
+ char msg[100];  
 
- switch(message)
- {
-   case NO_QUESTION_LIST:
-   {
-     char msg[100] = "Please! first setup the question list by typing <a>";
-     snprintf(buf, NET_BUF_LEN, 
-                 "%s\t%s\n",
-                 "SEND_MESSAGE",
-                 msg);
-     printf("buf is: %s\n", buf);
-     x = SDLNet_TCP_Send(csd, buf, sizeof(buf));
-     printf("SendMessage() - buf sent:::: %d bytes\n", x);
-     break;
-   }
-  
-   case ANSWER_CORRECT:
-   {
-     char msg[100];  
-     sprintf(msg,"%s   %d   %s",
-                "Question ID:",
-                z,
-                "was answered correctly by the client");
-     snprintf(buf, NET_BUF_LEN, 
-                  "%s\t%s\n",
-                  "SEND_MESSAGE",
-                  msg);
-     printf("buf is: %s\n", buf);
-     x = SDLNet_TCP_Send(csd, buf, sizeof(buf));
-     printf("SendMessage() - buf sent:::: %d bytes\n", x);
-     break;
-   } 
-  
+ /* Create appropriate message: */
+  switch(message)
+  {
+    case NO_QUESTION_LIST:
+      sprintf(msg,"%s", "Please! first setup the question list by typing <a>\n");
+      break;
+    case ANSWER_CORRECT:
+      sprintf(msg,"%s %d %s", "Question ID:",
+              z, "was answered correctly by the client\n");
+      break;
    case LIST_SET_UP:
-   {
-     char msg[100] = "Question list was successfully setup";
-     snprintf(buf, NET_BUF_LEN, 
-                 "%s\t%s\n",
-                 "SEND_MESSAGE",
-                 msg);
-     printf("buf is: %s\n", buf);
-     x = SDLNet_TCP_Send(csd, buf, sizeof(buf));
-     printf("SendMessage() - buf sent:::: %d bytes\n", x);
-     break;
-   } 
-  
+      sprintf(msg,"%s", "Question list was successfully setup\n");
+      break;
    default :
-     break;
- }
-  
+     fprintf(stderr, "SendMessage() - unrecognized message type\n");
+     return 0;
+  }
+  //transmit:
+  snprintf(buf, NET_BUF_LEN, "%s\t%s\n", "SEND_MESSAGE", msg);
+  x = SDLNet_TCP_Send(csd, buf, NET_BUF_LEN);
+
+#ifdef LAN_DEBUG
+  printf("buf is: %s\n", buf);
+  printf("SendMessage() - buf sent:::: %d bytes\n", x);
+#endif
+
   return 1;
 }
 

Modified: tuxmath/branches/lan/server/server.h
===================================================================
--- tuxmath/branches/lan/server/server.h	2009-06-18 17:55:44 UTC (rev 1068)
+++ tuxmath/branches/lan/server/server.h	2009-06-18 20:00:47 UTC (rev 1069)
@@ -2,10 +2,10 @@
 
         server.h
 
-        Description: As of now it conatinsthe enum, which identifies
+        Description: As of now it conatins the enum, which identifies
         the network commands , as they are added(WORK IN PROGRESS).
 
-        Author: David Bruce ,Akash Gangil and the TuxMath team, (C) 2009
+        Author: David Bruce, Akash Gangil and the TuxMath team, (C) 2009
 
         Copyright: See COPYING file that comes with this distribution (briefly, GNU GPL version 2 or later)
 

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-06-18 17:55:44 UTC (rev 1068)
+++ tuxmath/branches/lan/server/testclient.c	2009-06-18 20:00:47 UTC (rev 1069)
@@ -1,5 +1,5 @@
 /*
-*  C Implementation: testclient.c
+*  C Implementation: server.c
 *
 *       Description: Test client program for LAN-based play in Tux,of Math Command.
 *
@@ -25,12 +25,12 @@
 #include "mathcards.h"
 #include "testclient.h"
 
-TCPsocket sd;           /* Socket descriptor */
+TCPsocket sd;           /* Server socket descriptor */
 SDLNet_SocketSet set;
 
 MC_FlashCard flash;    //current question
 int Make_Flashcard(char *buf, MC_FlashCard* fc);
-int MC_AnsweredCorrectly(MC_FlashCard* fc);
+int LAN_AnsweredCorrectly(MC_FlashCard* fc);
 int playgame(void);
 
 
@@ -71,7 +71,7 @@
 
   // Create a socket set to handle up to 16 sockets
   // NOTE 16 taken from example - almost certainly don't need that many
-  set = SDLNet_AllocSocketSet(1);                         // it has to be one since this is client and it has to communicate with ONLY 1 SERVER.
+  set = SDLNet_AllocSocketSet(1);
   if(!set) {
     printf("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError());
     exit(EXIT_FAILURE);
@@ -83,17 +83,18 @@
     // perhaps you need to restart the set and make it bigger...
   }
 
-  printf("Welcome to the Tux Math Test Client!\n");
-  printf("Type:\n"
-             "'game' to start math game;\n"
-             "'exit' to end client leaving server running;\n"
-             "'quit' to end both client and server\n\n");
 
+
   /* Send messages */
   quit = 0;
   while (!quit)
-  {
-   //Get user input from command line and send it to server: 
+  { 
+    //Get user input from command line and send it to server: 
+    printf("Welcome to the Tux Math Test Client!\n");
+    printf("Type:\n"
+             "'game' to start math game;\n"
+             "'exit' to end client leaving server running;\n"
+             "'quit' to end both client and server\n>\n"); 
     scanf("%s", buffer);
 
     //Figure out if we are trying to quit:
@@ -110,21 +111,20 @@
     }
     else if (strcmp(buffer, "game") == 0)
     {
+      printf("Starting math game:\n");
       playgame();
+      printf("Math game finished.\n");
     }
     else
     {
       printf("Command not recognized. Type:\n"
              "'game' to start math game;\n"
              "'exit' to end client leaving server running;\n"
-             "'quit' to end both client and server\n\n");
+             "'quit' to end both client and server\n\n>\n");
     }
   }
  
   SDLNet_TCP_Close(sd);
-  SDLNet_FreeSocketSet(set);
-  set=NULL; //this helps us remember that this set is not allocated
-
   SDLNet_Quit();
  
   return EXIT_SUCCESS;
@@ -132,7 +132,7 @@
 
 
 
-int MC_AnsweredCorrectly(MC_FlashCard* fc)
+int LAN_AnsweredCorrectly(MC_FlashCard* fc)
 {
   int len;
   char buffer[NET_BUF_LEN];
@@ -142,7 +142,7 @@
                   "CORRECT_ANSWER",
                   fc->question_id);
   len = strlen(buffer) + 1;
-  if (SDLNet_TCP_Send(sd, (void *)buffer, len) < len)
+  if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
   {
     fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
     exit(EXIT_FAILURE);
@@ -155,57 +155,61 @@
 
 int Make_Flashcard(char* buf, MC_FlashCard* fc)
 {
-  int i, j, tab = 0, s = 0;
+  int i = 0, j, tab = 0, s = 0;
   char formula[MC_FORMULA_LEN];
   sscanf (buf,"%*s%d%d%d%s",
               &fc->question_id,
               &fc->difficulty,
               &fc->answer,
-              fc->answer_string);                          /* can't formula_string in sscanf in here cause it includes spaces*/
+              fc->answer_string); /* can't formula_string in sscanf in here cause it includes spaces*/
  
- /*doing all this cause sscanf will break on encountering space in formula_string*/
-   while(*buf!='\n')
-   {
-    if(*buf=='\t')
-    tab++; 
-    buf++;
+  /*doing all this cause sscanf will break on encountering space in formula_string*/
+  /* NOTE changed to index notation so we keep within NET_BUF_LEN */
+  while(buf[i]!='\n' && i < NET_BUF_LEN)
+  {
+    if(buf[i]=='\t')
+      tab++; 
+    i++;
     if(tab == 5)
-    break;
-   }
+      break;
+  }
 
-  while((*buf!='\n') 
+  while((buf[i] != '\n') 
     && (s < MC_FORMULA_LEN - 1)) //Must leave room for terminating null
   {
-    formula[s]=*buf;
-    buf++;
+    formula[s] = buf[i] ;
+    i++;
     s++;
   }
-
   formula[s]='\0';
   strcpy(fc->formula_string, formula); 
 
+#ifdef LAN_DEBUG
   printf ("card is:\n");
   printf("QUESTION_ID       :      %d\n",fc->question_id);
   printf("FORMULA_STRING    :      %s\n",fc->formula_string);
   printf("ANSWER STRING     :      %s\n",fc->answer_string);
   printf("ANSWER            :      %d\n",fc->answer);
   printf("DIFFICULTY        :      %d\n",fc->difficulty);  
-  
-  return 1;
+#endif
+
+return 1;
 } 
 
 int playgame(void)
 {
   int numready;
   int command_type;
-  int ans;
+  int ans = 0;
   int x, i = 0;
   int end = 0;
   int have_question = 0;
   int len = 0;
   char buf[NET_BUF_LEN];
 
+#ifdef LAN_DEBUG
   printf("Entering playgame()\n");
+#endif
 
   //Tell server to start new game:
   snprintf(buf, NET_BUF_LEN, "%s\n", "a");
@@ -234,9 +238,8 @@
       char command[NET_BUF_LEN];
       int i = 0;
 
-      //This is supposed to check to see if there is activity and time out
-      // after 1000 ms if no activity
-      numready = SDLNet_CheckSockets(set, 1000);
+      //This is supposed to check to see if there is activity:
+      numready = SDLNet_CheckSockets(set, 0);
       if(numready == -1)
       {
         printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
@@ -245,7 +248,9 @@
       }
       else
       {
+#ifdef LAN_DEBUG
         printf("There are %d sockets with activity!\n", numready);
+#endif
         // check all sockets with SDLNet_SocketReady and handle the active ones.
         if(SDLNet_SocketReady(sd))
         {
@@ -261,8 +266,10 @@
 
           command[i] = '\0';
 
+#ifdef LAN_DEBUG
           printf("buf is %s\n", buf);
           printf("command is %s\n", command);
+#endif
           /* Now we process the buffer according to the command: */
           if(strcmp(command, "SEND_QUESTION") == 0)
           {
@@ -275,42 +282,59 @@
       }
     } // End of loop for checking server activity
 
+#ifdef LAN_DEBUG
     printf("No active sockets within timeout interval\n");
+#endif
 
-
-
     //Now we check for any user responses
     while(have_question && !end)
     { 
       printf("Question is: %s\n", flash.formula_string);
-      printf("Enter answer:\n");
-      scanf("%d",&ans);
-      if (ans == 999)
+      printf("Enter answer:\n>");
+      fgets(buf, sizeof(buf), stdin);
+      printf("buf is %s\n", buf);
+      if ((strncmp(buf, "quit", 4) == 0)
+        ||(strncmp(buf, "exit", 4) == 0)
+	||(strncmp(buf, "q", 1) == 0))
+      {
         end = 1;
-      else if(ans == flash.answer)
-      {  
-        have_question = 0;
-        //Tell server we answered it right:
-        if(!MC_AnsweredCorrectly(&flash))
-        {
-          printf("Unable to communicate the same to server\n");
-          exit(EXIT_FAILURE);
+      }
+      else
+      {
+        /*NOTE atoi() will return zero for any string that is not
+	a valid int, not just '0' - should not be a big deal for
+	our test program - DSB */
+        ans = atoi(buf);
+        if(ans == flash.answer)
+        {  
+          have_question = 0;
+          //Tell server we answered it right:
+          if(!LAN_AnsweredCorrectly(&flash))
+          {
+            printf("Unable to communicate the same to server\n");
+            exit(EXIT_FAILURE);
+          }
+
+          //and ask it to send us the next one:
+          snprintf(buf, NET_BUF_LEN, "%s\n", "b");
+
+#ifdef LAN_DEBUG
+          printf("requesting next question, buf: %s", buf);
+#endif
+          if (SDLNet_TCP_Send(sd, (void *)buf, NET_BUF_LEN) < NET_BUF_LEN)
+          {
+            fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
+            exit(EXIT_FAILURE);
+          }
         }
-        //and ask it to send us the next one:
-        //Ask for first question:
-        snprintf(buf, NET_BUF_LEN, "%s\n", "b");
-        printf("requesting next question, buf: %s", buf);
-        if (SDLNet_TCP_Send(sd, (void *)buf, NET_BUF_LEN) < NET_BUF_LEN)
-        {
-          fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
-          exit(EXIT_FAILURE);
-        }
-      }
-      else  //incorrect answer:
-        printf("Sorry try again!\n");
+        else  //incorrect answer:
+          printf("Sorry, incorrect. Try again!\n");
+      }  //isint() returned false:
     }
   } //End of game loop 
+#ifdef LAN_DEBUG
   printf("Leaving playgame()\n");
+#endif
 }
 
 

Modified: tuxmath/branches/lan/server/transtruct.h
===================================================================
--- tuxmath/branches/lan/server/transtruct.h	2009-06-18 17:55:44 UTC (rev 1068)
+++ tuxmath/branches/lan/server/transtruct.h	2009-06-18 20:00:47 UTC (rev 1069)
@@ -14,13 +14,16 @@
 #ifndef TRANSTRUCT_H
 #define TRANSTRUCT_H
 
+//#define LAN_DEBUG
+#define NET_BUF_LEN 512
+#define DEFAULT_PORT 4778
+
 #define MC_USE_NEWARC
 #define MC_FORMULA_LEN 40
 #define MC_ANSWER_LEN 5
 
-#define NET_BUF_LEN 512
-#define DEFAULT_PORT 4778
 
+
 #ifndef MC_USE_NEWARC
 /* struct for individual "flashcard" */
 typedef struct MC_FlashCard {




More information about the Tux4kids-commits mailing list