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

akash gangil gangil-guest at alioth.debian.org
Sat Jul 4 15:56:43 UTC 2009


Author: gangil-guest
Date: 2009-07-04 15:56:42 +0000 (Sat, 04 Jul 2009)
New Revision: 1143

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
Log:
Working on score acknowledgement

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-07-04 15:41:28 UTC (rev 1142)
+++ tuxmath/branches/lan/server/server.c	2009-07-04 15:56:42 UTC (rev 1143)
@@ -48,7 +48,7 @@
 void game_msg_exit(int i);
 void start_game(int i);
 int SendQuestion(MC_FlashCard flash, TCPsocket client_sock);
-int SendMessage(int message, int z, TCPsocket client_sock);
+int SendMessage(int message, int ques_id,char *name, TCPsocket client_sock);
 
 
 
@@ -457,8 +457,21 @@
 
 void game_msg_correct_answer(int i,int id)
 {
-  int n; 
+  int n;
   printf("question id %d was answered correctly by %s",id,client[i].name);             
+ 
+ /*Send score notification to all the clients except the one who answered it*/
+ for(n = 0; n < MAX_CLIENTS && client[n].sock; n++)
+  {
+    if(n==id)      /*I dont think , we would like to send it to the client who answered it*/
+    continue;
+    if(!SendMessage(ANSWER_CORRECT,id,client[i].name,client[n].sock))
+    {
+      printf("Unable to score changes\n");
+    }
+  }
+
+
   if (!MC_NextQuestion(&flash))
   { 
     /* no more questions available */
@@ -702,7 +715,7 @@
 
 /*Function to send any messages to the client be it any warnings
   or anything the client is made to be informed*/
-int SendMessage(int message, int z,TCPsocket client_sock)         
+int SendMessage(int message, int ques_id,char *name,TCPsocket client_sock)         
 {
  int x, len;
  char buf[NET_BUF_LEN];
@@ -715,8 +728,8 @@
       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");
+      sprintf(msg,"%s %d %s %s", "Question ID:",
+              ques_id, "was answered correctly by the client",name);
       break;
    case LIST_SET_UP:
       sprintf(msg,"%s", "Question list was successfully setup\n");

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-07-04 15:41:28 UTC (rev 1142)
+++ tuxmath/branches/lan/server/testclient.c	2009-07-04 15:56:42 UTC (rev 1143)
@@ -99,12 +99,14 @@
 
   /* first just take in the name */
   printf("Enter your Name.\n");
-  check1 = fgets(buffer, NET_BUF_LEN, stdin);
-  strncpy(name, check1, strlen(check1));
+  check1=gets(name);
+  if(check1==NULL)
+  printf(" gets() failed...\n");
+ 
   snprintf(buffer, NET_BUF_LEN, 
-                       "%s",
+                       "%s\n",
                        name);
-
+ 
   if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
   {
    fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
@@ -357,7 +359,13 @@
           else if(strncmp(command,"SEND_MESSAGE", strlen("SEND_MESSAGE")) == 0)
           {
             // Presumably we want to print the message to stdout
+            printf("%s\n", buf);
           }
+          else if(strncmp(command,"NOTIFICATION",strlen("NOTIFICATION")) == 0)
+          {
+             printf("%s\n", buf);
+          }
+
           else if(strncmp(command,"PING", strlen("PING")) == 0)
           {
             server_pinged();




More information about the Tux4kids-commits mailing list