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

akash gangil gangil-guest at alioth.debian.org
Fri Jul 10 20:59:31 UTC 2009


Author: gangil-guest
Date: 2009-07-10 20:59:30 +0000 (Fri, 10 Jul 2009)
New Revision: 1179

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
Log:
Correcting some of *my* mistakes

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-07-10 15:14:55 UTC (rev 1178)
+++ tuxmath/branches/lan/server/server.c	2009-07-10 20:59:30 UTC (rev 1179)
@@ -429,7 +429,7 @@
 
 void handle_client_nongame_msg(int i,char *buffer)
 {
-  if(strncmp(buffer, "START_GAME", 10) == 0)
+  if(strncmp(buffer, "START_GAME", strlen("START_GAME")) == 0)
   {
     start_game(i);
   }
@@ -450,8 +450,7 @@
                   &id);
 
 
-
-  if(strncmp(command, "CORRECT_ANSWER", 14) == 0)
+  if(strncmp(command, "CORRECT_ANSWER", strlen("CORRECT_ANSWER")) == 0)
   {
     game_msg_correct_answer(i,id);
   }                            
@@ -462,7 +461,7 @@
   }
 
 
-  else if(strncmp(command, "MISSION_ACCOMPLISHED",strlen("MISSION_ACCOMPLISHED")) == 0) /* Send Total Questions left */
+  else if(strncmp(command, "MISSION_ACCOMPLISHED",strlen("MISSION_ACCOMPLISHED")) == 0) /* Check to see if mission is over*/
   {
     game_msg_mission_accomplished(i);
   }
@@ -472,12 +471,12 @@
     game_msg_next_question();
   }
 
-  else if(strncmp(command, "exit",4) == 0) /* Terminate this connection */
+  else if(strncmp(command, "exit",strlen("exit")) == 0) /* Terminate this connection */
   {
     game_msg_exit(i);
   }
 
-  else if(strncmp(command, "quit",4) == 0) /* Quit the program */
+  else if(strncmp(command, "quit",strlen("quit")) == 0) /* Quit the program */
   {
     game_msg_quit(i);
     return(1);
@@ -492,22 +491,20 @@
 
 void game_msg_total_questions_left(int i)
 {
- int x;
- char *ch;
- x=MC_TotalQuestionsLeft();
- ch=(char*)x;
+ int total_questions_left;
+ char ch[10];
+ total_questions_left=MC_TotalQuestionsLeft();
+ snprintf(ch,10,"%d",total_questions_left); 
  player_msg(i,ch);
 }
 
 void game_msg_mission_accomplished(int i)
 {
-  int x;
-  char *ch;
-
-  x=MC_MissionAccomplished();
-  ch=(char*)x;
-  player_msg(i,ch);
- 
+ int total_questions_left;
+ char ch[10];
+ total_questions_left=MC_MissionAccomplished();
+ snprintf(ch,10,"%d",total_questions_left); 
+ player_msg(i,ch);
 }
 
 void game_msg_correct_answer(int i, int id)

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-07-10 15:14:55 UTC (rev 1178)
+++ tuxmath/branches/lan/server/testclient.c	2009-07-10 20:59:30 UTC (rev 1179)
@@ -45,7 +45,7 @@
 int playgame(void);
 void server_pinged(void);
 
-int player_msg_recvd(char* buf);
+int player_msg_recvd(char *command,char* buf);
 int read_stdin_nonblock(char* buf, size_t max_length);
 void throttle(int loop_msec);
 
@@ -294,7 +294,35 @@
 
 return 1;
 } 
+int evaluate(char statement[20])
+{
+  int ans,x;
+  char command[NET_BUF_LEN];
+  int len;
+  char buffer[NET_BUF_LEN];
+  char buf[NET_BUF_LEN];
 
+   snprintf(buffer, NET_BUF_LEN, 
+                  "%s\n",
+                  statement);
+   len = strlen(buffer) + 1;
+   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);
+   }
+        x = SDLNet_TCP_Recv(sd, buf, NET_BUF_LEN);
+          if( x <= 0)
+          {
+            fprintf(stderr, "In play_game(), SDLNet_TCP_Recv() failed!\n");
+            exit(EXIT_FAILURE);
+          }
+  player_msg_recvd(buf,command);
+  ans=atoi(command);
+
+  return ans;
+}
+
 int playgame(void)
 {
   int numready;
@@ -378,7 +406,8 @@
           }
 
           command[i] = '\0';
-
+printf("this is the value of mission accomplished... %d ...\n",evaluate("TOTAL_QUESTIONS_LEFT"));
+evaluate("TOTAL_QUESTIONS_LEFT");
 #ifdef LAN_DEBUG
 //          printf("buf is %s\n", buf);
 //          printf("command is %s\n", command);
@@ -402,7 +431,7 @@
           }
           else if(strncmp(command,"PLAYER_MSG", strlen("PLAYER_MSG")) == 0)
           {
-            player_msg_recvd(buf);
+            player_msg_recvd(NULL,buf);
           }
 	  else if(strncmp(command,"PING", strlen("PING")) == 0)
           {
@@ -432,7 +461,7 @@
       }
       else if(strncmp(buf,"PLAYER_MSG", strlen("PLAYER_MSG")) == 0)
       {
-        player_msg_recvd(buf);
+        player_msg_recvd(NULL,buf);
       } 
       else
       {
@@ -467,13 +496,13 @@
 
 //Goes past the title field in the tab-delimited buffer
 //and prints the rest to stdout:
-int player_msg_recvd(char* buf)
+int player_msg_recvd(char *command,char* buf)
 {
-  char* p = strchr(buf, '\t');
-  if(p)
+  command = strchr(buf, '\t');
+  if(command)
   { 
-    p++;
-    printf("%s\n", p);
+    command++;
+    printf("%s\n", command);
     return 1;
   }
   else




More information about the Tux4kids-commits mailing list