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

akash gangil gangil-guest at alioth.debian.org
Mon Jun 15 17:34:13 UTC 2009


Author: gangil-guest
Date: 2009-06-15 17:34:11 +0000 (Mon, 15 Jun 2009)
New Revision: 1051

Modified:
   tuxmath/branches/lan/server/mathcards.c
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
   tuxmath/branches/lan/server/transtruct.h
Log:
Each question has a NO: or id (which start from 1,2,3... and so on )

Modified: tuxmath/branches/lan/server/mathcards.c
===================================================================
--- tuxmath/branches/lan/server/mathcards.c	2009-06-15 10:15:44 UTC (rev 1050)
+++ tuxmath/branches/lan/server/mathcards.c	2009-06-15 17:34:11 UTC (rev 1051)
@@ -1184,7 +1184,8 @@
 void print_card(MC_FlashCard card)
 {
   printf("\nprint_card():");
-  printf("formula_string = %s\nanswer_string = %s\ndifficulty = %d\n\n",
+  printf("question_id=%d\nformula_string = %s\nanswer_string = %s\ndifficulty = %d\n\n",
+         card.question_id,
          card.formula_string,
          card.answer_string,
          card.difficulty);
@@ -1452,6 +1453,7 @@
   mcdprintf("Card is: '%s', '%s'\n", dest->formula_string, dest->answer_string);
   dest->answer = src->answer;
   dest->difficulty = src->difficulty;
+  dest->question_id = src->question_id;
 }
 
 void free_node(MC_MathQuestion* mq) //no, not that freenode.
@@ -1491,9 +1493,11 @@
   int length;
   MC_ProblemType pt;
   MC_FlashCard ret;
+  static int generate_random_flashcard_id=0;
 
+  generate_random_flashcard_id+=1;
   mcdprintf("Entering generate_random_flashcard()\n");
-
+  printf("%d\n",generate_random_flashcard_id);
   do
     pt = rand() % MC_NUM_PTYPES;
   while ( (pt == MC_PT_TYPING && !MC_GetOpt(TYPING_PRACTICE_ALLOWED) ) ||
@@ -1514,6 +1518,7 @@
     snprintf(ret.answer_string, max_answer_size, "%d", num);
     ret.answer = num;
     ret.difficulty = 10;
+    ret.question_id=generate_random_flashcard_id;
   }
   else //if (pt == MC_PT_ARITHMETIC)
   {
@@ -1552,7 +1557,9 @@
   char tempstr[max_formula_size];
   MC_FlashCard ret;
   MC_Operation op;
+  static int id=0;
 
+  id+=1;
   printf(".");
   if (length > MAX_FORMULA_NUMS)
     return DEFAULT_CARD;
@@ -1714,6 +1721,7 @@
     strncat(ret.formula_string, " = ?", max_formula_size - strlen(ret.formula_string) );
     reformat_arithmetic(&ret, format );     
   }
+  ret.question_id=id;
   return ret;
 }
 

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-06-15 10:15:44 UTC (rev 1050)
+++ tuxmath/branches/lan/server/server.c	2009-06-15 17:34:11 UTC (rev 1051)
@@ -146,7 +146,9 @@
                                                       return 0;
                                                     }
                                                    
-						     printf("WILL SEND >>\n");  
+						    printf("WILL SEND >>\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);
@@ -202,38 +204,21 @@
       char *ch;
       int x;
 
-     x=SDLNet_TCP_Send(csd,&(fc->difficulty),sizeof(fc->difficulty));
-       printf("no:(1):::DIFFICULTY::::Sent %d bytes\n",x);
-//      SDLNet_TCP_Recv(csd,ch,1);                                     //will send in the next item only when the first one is receive
-//     if(*ch=='1')
-//      {
-        x=SDLNet_TCP_Send(csd,&(fc->answer),sizeof(fc->answer));
+      x=SDLNet_TCP_Send(csd,&(fc->question_id),sizeof(fc->question_id));
+      printf("no:(1):::QUESTION_ID::::Sent %d bytes\n",x);
+      
+      x=SDLNet_TCP_Send(csd,&(fc->difficulty),sizeof(fc->difficulty));
+      printf("no:(2):::DIFFICULTY::::Sent %d bytes\n",x);
 
-       printf("no:(2)::::ANSWER:::Sent %d bytes\n",x);
-//       SDLNet_TCP_Recv(csd,ch,1);
-//        if(*ch=='1')
-//        { 
+      x=SDLNet_TCP_Send(csd,&(fc->answer),sizeof(fc->answer));
+      printf("no:(3)::::ANSWER:::Sent %d bytes\n",x);
 
-       x=SDLNet_TCP_Send(csd,fc->answer_string,strlen(fc->answer_string)+1);
-        
-       printf("no:(3):::ANSWER_STRING::::Sent %d bytes\n",x);
+      x=SDLNet_TCP_Send(csd,fc->answer_string,strlen(fc->answer_string)+1);
+      printf("no:(4):::ANSWER_STRING::::Sent %d bytes\n",x);
 
-//	 SDLNet_TCP_Recv(csd,ch,1);
-//          if(*ch=='1')
-//           {
       x=SDLNet_TCP_Send(csd,fc->formula_string,strlen(fc->formula_string)+1);
-
-       printf("no:(4):::FORMULA_STRING::::Sent %d bytes\n",x);
+      printf("no:(5):::FORMULA_STRING::::Sent %d bytes\n",x);
     
-
-//            SDLNet_TCP_Recv(csd,ch,1);
-//             if(*ch=='1')
-//              {		
-//	       return 0;
-//              }
-//            }
-//        }
-//      }
       return 1;
 
 }

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-06-15 10:15:44 UTC (rev 1050)
+++ tuxmath/branches/lan/server/testclient.c	2009-06-15 17:34:11 UTC (rev 1051)
@@ -116,34 +116,32 @@
        char ch[5];
        int x,i=0;
 
+       x=SDLNet_TCP_Recv(sd,&(fc->question_id),sizeof(fc->question_id));
+       printf("no:(1):::QUESTION_ID::::Received %d bytes\n",x);
+ 
        x=SDLNet_TCP_Recv(sd,&(fc->difficulty),sizeof(fc->difficulty));
-       printf("no:(1):::DIFFICULTY::::Received %d bytes\n",x);
+       printf("no:(2):::DIFFICULTY::::Received %d bytes\n",x);
  
-       //	SDLNet_TCP_Send(sd,ch,1); 		                  // send a conformation that the 1st item has been received				
        x=SDLNet_TCP_Recv(sd,&(fc->answer),sizeof(fc->answer));
-       printf("no:(2):::ANSWER::::Received %d bytes\n",x);
+       printf("no:(3):::ANSWER::::Received %d bytes\n",x);
 
-
-//        SDLNet_TCP_Send(sd,ch,1);
        do{
-	x=SDLNet_TCP_Recv(sd,&ch[i],1);      
-       printf("<<<SUB-PACKET%d>>>no:(3):::ANSWER_STRING::::Received %d bytes\n",i,x);
+       x=SDLNet_TCP_Recv(sd,&ch[i],1);      
+       printf("<<<SUB-PACKET%d>>>no:(4):::ANSWER_STRING::::Received %d bytes\n",i,x);
        i++;
        }while(ch[i-1]!='\0');
        strncpy(fc->answer_string,ch,i+1);
 
-//        SDLNet_TCP_Send(sd,ch,1);
        x=SDLNet_TCP_Recv(sd,fc->formula_string,13);
-       printf("no:(4):::FORMULA_STRING::::Received %d bytes\n",x);
+       printf("no:(5):::FORMULA_STRING::::Received %d bytes\n",x);
        
        printf("RECEIVED >>\n");
-       printf("DIFFICULTY     >>          %d\n",fc->difficulty);  
-       printf("ANSWER         >>          %d\n",fc->answer);  
-       printf("ANSWER_STRING  >>          %s\n",fc->answer_string);  
+       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);  
        
- //        SDLNet_TCP_Send(sd,ch,1);
-       
        return 1;
 }
 

Modified: tuxmath/branches/lan/server/transtruct.h
===================================================================
--- tuxmath/branches/lan/server/transtruct.h	2009-06-15 10:15:44 UTC (rev 1050)
+++ tuxmath/branches/lan/server/transtruct.h	2009-06-15 17:34:11 UTC (rev 1051)
@@ -33,6 +33,7 @@
 typedef struct _MC_FlashCard {
   char* formula_string;
   char* answer_string;
+  int question_id;
   int answer;
   int difficulty;
 } MC_FlashCard;




More information about the Tux4kids-commits mailing list