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

akash gangil gangil-guest at alioth.debian.org
Sat Jun 20 12:57:46 UTC 2009


Author: gangil-guest
Date: 2009-06-20 12:57:45 +0000 (Sat, 20 Jun 2009)
New Revision: 1078

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
Log:
works for a single player , working on multi-player

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-06-20 12:03:20 UTC (rev 1077)
+++ tuxmath/branches/lan/server/server.c	2009-06-20 12:57:45 UTC (rev 1078)
@@ -172,10 +172,12 @@
 
 #ifdef LAN_DEBUG
        printf("buf is %s\n", buf);
+       printf("%d\n",strncmp(buf, "start",5));
 #endif
        /* Now we process the buffer according to the command: */
-       if(strcmp(buf, "set_up_list") == 0)
+       if(strncmp(buf, "start",5) == 0)
        {
+         printf("I am here!\n");
          quit = 1;
          break;                //tell the server to stop accepting connections and start the game                           
        }
@@ -202,8 +204,8 @@
          if(client[j].flag==0)
          continue;                                           
 
-         if(!(SDLNet_SocketReady(client[j].csd)))             //check if that client is ready or not..
-         continue;                                           //if that client is not ready then move to next one
+//         if(!(SDLNet_SocketReady(client[j].csd)))             //check if that client is ready or not..
+//         continue;                                           //if that client is not ready then move to next one
 
          if (SDLNet_TCP_Recv(client[j].csd, buffer, NET_BUF_LEN) > 0)
          {
@@ -216,20 +218,20 @@
                          command,
                          &id);  
      
-           if(strcmp(command, "CORRECT_ANSWER") == 0)
+           if(strncmp(command, "CORRECT_ANSWER",14) == 0)
            {
              command_type = CORRECT_ANSWER;              
            }                             
           
            //'a' for the setting up the question list                                           
-           if(strcmp(command, "set_up_list") == 0)
+           if(strncmp(command, "set_up_list",11) == 0)
            {
              initialize = 1; 
              command_type = NEW_GAME;              
            } 
                                        
            //'b' for asking for a question(flashcard)
-           if(strcmp(command, "next_question") == 0)
+           if(strncmp(command, "next_question",13) == 0)
            {
 #ifdef LAN_DEBUG
              printf("received request to send question\n");
@@ -242,14 +244,14 @@
                command_type = SEND_A_QUESTION;              
            } 
 
-           if(strcmp(command, "exit") == 0) /* Terminate this connection */
+           if(strncmp(command, "exit",4) == 0) /* Terminate this connection */
            {
              client[i].flag=0;
              SDLNet_TCP_Close(client[j].csd);
              printf("Terminating client connection\n");
            }
 
-           if(strcmp(command, "quit") == 0) /* Quit the program */
+           if(strncmp(command, "quit",4) == 0) /* Quit the program */
            {
              quit2 = 1;
              printf("Quit program....Server is shutting down...\n");

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-06-20 12:03:20 UTC (rev 1077)
+++ tuxmath/branches/lan/server/testclient.c	2009-06-20 12:57:45 UTC (rev 1078)
@@ -25,7 +25,7 @@
 #include "mathcards.h"
 #include "testclient.h"
 
-#define LAN_DEBUG
+//#define LAN_DEBUG
 
 TCPsocket sd;           /* Server socket descriptor */
 SDLNet_SocketSet set;
@@ -212,7 +212,19 @@
   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
 
@@ -244,11 +256,6 @@
     while(numready > 0)
     {
      
-
-     SDL_Delay(5000);
-
-
-
       char command[NET_BUF_LEN];
       int i = 0;
 
@@ -297,7 +304,7 @@
     } // End of loop for checking server activity
 
 #ifdef LAN_DEBUG
-    printf("No active sockets within timeout interval\n");
+    printf(".\n");
 #endif
 
     //Now we check for any user responses
@@ -305,7 +312,7 @@
     { 
       printf("Question is: %s\n", flash.formula_string);
       printf("Enter answer:\n>");
-      fgets(buf, sizeof(buf), stdin);
+      gets(buf);
       printf("buf is %s\n", buf);
       if ((strncmp(buf, "quit", 4) == 0)
         ||(strncmp(buf, "exit", 4) == 0)




More information about the Tux4kids-commits mailing list