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

akash gangil gangil-guest at alioth.debian.org
Sat Jun 20 18:14:03 UTC 2009


Author: gangil-guest
Date: 2009-06-20 18:14:01 +0000 (Sat, 20 Jun 2009)
New Revision: 1079

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
Log:
game started on multiple clients , but still not getting same question, so sync. needs to b achieved

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-06-20 12:57:45 UTC (rev 1078)
+++ tuxmath/branches/lan/server/server.c	2009-06-20 18:14:01 UTC (rev 1079)
@@ -147,8 +147,8 @@
     else
     {
 #ifdef LAN_DEBUG
-      printf("There are %d sockets with activity!\n", numready);
-      SDL_Delay(2000);  //We only delay when debugging?
+//      printf("There are %d sockets with activity!\n", numready);
+//      SDL_Delay(2000);  //We only delay when debugging?
 #endif
     // check all sockets with SDLNet_SocketReady and handle the active ones.
       for(j = 0; j <= (numready - 1); j++)
@@ -172,14 +172,12 @@
 
 #ifdef LAN_DEBUG
        printf("buf is %s\n", buf);
-       printf("%d\n",strncmp(buf, "start",5));
+       printf("%d\n",strncmp(buf, "next_question",13));
 #endif
        /* Now we process the buffer according to the command: */
-       if(strncmp(buf, "start",5) == 0)
+       if(strncmp(buf,"next_question",13) == 0)
        {
-         printf("I am here!\n");
-         quit = 1;
-         break;                //tell the server to stop accepting connections and start the game                           
+        goto game;            //tell the server to stop accepting connections and start the game                           
        }
 //          }//end of *if*
       }//end of *for* loop
@@ -187,11 +185,21 @@
   } // End of *while(!quit)* loop
 
 
+//for(j=0;j<num_clients;j++)                               //sending this message to all clients
+// {
+//  if(!SendMessage(LIST_SET_UP,0,client[j].csd))
+//  {
+//   printf("Unable to communicate to the client\n");
+// }
+// }
 
 
-
  
 game:
+      if (!MC_StartGame())                   //setting up the list itself
+      {
+        fprintf(stderr, "\nMC_StartGame() failed!");
+      }
       quit2 = 0;
       while (!quit2)
       {
@@ -224,11 +232,11 @@
            }                             
           
            //'a' for the setting up the question list                                           
-           if(strncmp(command, "set_up_list",11) == 0)
-           {
-             initialize = 1; 
-             command_type = NEW_GAME;              
-           } 
+//           if(strncmp(command, "set_up_list",11) == 0)
+//           {
+//             initialize = 1; 
+//             command_type = NEW_GAME;              
+//           } 
                                        
            //'b' for asking for a question(flashcard)
            if(strncmp(command, "next_question",13) == 0)
@@ -236,11 +244,11 @@
 #ifdef LAN_DEBUG
              printf("received request to send question\n");
 #endif
-             if(!initialize)
-             {
-               command_type = LIST_NOT_SETUP;                    
-             }
-             else
+//             if(!initialize)
+//             {
+//               command_type = LIST_NOT_SETUP;                    
+//             }
+//             else
                command_type = SEND_A_QUESTION;              
            } 
 
@@ -259,18 +267,18 @@
           
            switch(command_type)
            {
-             case NEW_GAME:  //mainly to setup the question list
-             {
-               if (!MC_StartGame())
-               {
-                 fprintf(stderr, "\nMC_StartGame() failed!");
-               }
-               if(!SendMessage(LIST_SET_UP,0,client[j].csd))
-               {
-                 printf("Unable to communicate to the client\n");
-               }
-               break;                                           
-             } 
+//             case NEW_GAME:  //mainly to setup the question list
+//             {
+//               if (!MC_StartGame())
+//               {
+//                 fprintf(stderr, "\nMC_StartGame() failed!");
+//               }
+//               if(!SendMessage(LIST_SET_UP,0,client[j].csd))
+//              {
+//                 printf("Unable to communicate to the client\n");
+//               }
+//               break;                                           
+//             } 
 
              case CORRECT_ANSWER:
              {

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-06-20 12:57:45 UTC (rev 1078)
+++ tuxmath/branches/lan/server/testclient.c	2009-06-20 18:14:01 UTC (rev 1079)
@@ -212,32 +212,28 @@
   int len = 0;
   char buf[NET_BUF_LEN];
 
-  //Tell server to start new game:
-  snprintf(buf, NET_BUF_LEN, "%s\n", "start");
-#ifdef LAN_DEBUG
-  printf("%s\n",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);
-  }
 
 
 #ifdef LAN_DEBUG
   printf("Entering playgame()\n");
 #endif
-
-  //Tell server to start new game:
-  snprintf(buf, NET_BUF_LEN, "%s\n", "set_up_list");
-#ifdef LAN_DEBUG
-  printf("%s\n",buf);
-#endif
+  //Ask for first question:
+  snprintf(buf, NET_BUF_LEN, "%s\n", "next_question");
   if (SDLNet_TCP_Send(sd, (void *)buf, NET_BUF_LEN) < NET_BUF_LEN)
   {
-    fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
+    fprintf(stderr, "failed on b: SDLNet_TCP_Send: %s\n", SDLNet_GetError());
     exit(EXIT_FAILURE);
   }
+  //Tell server to start new game:
+//  snprintf(buf, NET_BUF_LEN, "%s\n", "set_up_list");
+//#ifdef LAN_DEBUG
+//  printf("%s\n",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);
+// }
 
   //Ask for first question:
   snprintf(buf, NET_BUF_LEN, "%s\n", "next_question");




More information about the Tux4kids-commits mailing list