[Tux4kids-commits] r1238 - in tuxmath/branches/lan: server src

David Bruce dbruce-guest at alioth.debian.org
Mon Jul 20 01:57:32 UTC 2009


Author: dbruce-guest
Date: 2009-07-20 01:57:32 +0000 (Mon, 20 Jul 2009)
New Revision: 1238

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
   tuxmath/branches/lan/src/game.c
   tuxmath/branches/lan/src/highscore.c
   tuxmath/branches/lan/src/network.c
Log:
some work on testclient - multiple question support



Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-07-19 22:58:26 UTC (rev 1237)
+++ tuxmath/branches/lan/server/server.c	2009-07-20 01:57:32 UTC (rev 1238)
@@ -977,9 +977,7 @@
 
 
 
-/* Sends a string to be displayed to player: */
-/* NOTE similar in concept to SendMessage(), but I think that */
-/* SendMessage() is too complicated -DSB                      */
+/* Sends a string for the client to display to player: */
 int player_msg(int i, char* msg)
 {
   char buf[NET_BUF_LEN];

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-07-19 22:58:26 UTC (rev 1237)
+++ tuxmath/branches/lan/server/testclient.c	2009-07-20 01:57:32 UTC (rev 1238)
@@ -35,27 +35,37 @@
 MC_FlashCard flash;    //current question
 int have_question = 0;
 
-MC_FlashCard Comets[2];    //current questions
+MC_FlashCard comets[2];    //current questions
 int remaining_quests = 0;
 
 
 /* Local function prototypes: */
 int playgame(void);
-int game_check_msgs(void);
+int erase_flashcard(MC_FlashCard* fc);
 int read_stdin_nonblock(char* buf, size_t max_length);
 
 /* Functions to handle messages from server: */
+int game_check_msgs(void);
 int add_quest_recvd(char* buf);
 int remove_quest_recvd(char* buf);
 int player_msg_recvd(char* buf);
 int total_quests_recvd(char* buf);
 int mission_accompl_recvd(char* buf);
 
+/* Display to player: */
+void print_current_status(void);
+
+/* Main function: ------------------------------------- */
+
 int main(int argc, char **argv)
 {
   char buf[NET_BUF_LEN];     // for network messages from server
   char buffer[NET_BUF_LEN];  // for command-line input
 
+  /* Start out with our "comets" empty: */
+  erase_flashcard(&comets[0]);
+  erase_flashcard(&comets[1]);
+
   /* Connect to server, create socket set, get player nickname, etc: */
   if(!LAN_Setup(argv[1], DEFAULT_PORT))
   {
@@ -172,6 +182,7 @@
       {
         have_question = 1; 
         printf("The question is: %s\n>\n", flash.formula_string);
+        print_current_status();
       }
       else
         printf("Unable to parse buffer into FlashCard\n");
@@ -183,6 +194,7 @@
       {
         have_question = 1; 
         printf("The question is: %s\n>\n", flash.formula_string);
+        print_current_status();
       }
       else
         printf("Unable to parse buffer into FlashCard\n");
@@ -239,6 +251,10 @@
 
 
 
+
+
+
+
 int playgame(void)
 {
   int numready;
@@ -302,6 +318,7 @@
         {
           printf("Sorry, %s is incorrect. Try again!\n", buf); 
           printf("The question is: %s\n>\n", flash.formula_string);
+          print_current_status();
         }
       }  //input wasn't any of our keywords
     } // Input was received 
@@ -340,3 +357,29 @@
   return bytes_read;
 }
 
+/* Display the current questions and the number of remaining questions: */
+void print_current_status(void)
+{
+  printf("Remaining questions: %d\n", remaining_quests);
+  if(comets[0].question_id != -1)
+    printf("Comet Zero - question %d:\t%s\n", comets[0].question_id, comets[0].formula_string);
+  else
+    printf("Comet Zero:\tEmpty\n");
+  if(comets[1].question_id != -1)
+    printf("Comet One - question %d:\t%s\n", comets[1].question_id, comets[1].formula_string);
+  else
+    printf("Comet One:\tEmpty\n");
+}
+
+
+int erase_flashcard(MC_FlashCard* fc)
+{
+  if(!fc)
+    return 0;
+  fc->formula_string[0] = '\0';
+  fc->answer_string[0] = '\0';
+  int question_id = -1;
+  int answer = 0;
+  int difficulty = 0;
+  return 1;
+}
\ No newline at end of file

Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c	2009-07-19 22:58:26 UTC (rev 1237)
+++ tuxmath/branches/lan/src/game.c	2009-07-20 01:57:32 UTC (rev 1238)
@@ -259,8 +259,8 @@
 #ifdef HAVE_LIBSDL_NET
    while(!check_messages(buf))
    {
-     seperate_commmand_and_buf(command,buf);
-     game_handle_net_messages(buf,command);   
+     seperate_commmand_and_buf(command, buf);
+     game_handle_net_messages(buf, command);
    }
 #endif    
  
@@ -495,11 +495,15 @@
 /*Do we want a well defined function for each of the condition
   like on each message a function should be called , or is it ok like this
   I think this is better--akash*/
+/* As long the code for each command is really short, we can just have it here.
+   But if it starts to get long, I would have a function for each that is 
+   local to this file and located immediately below this function - DSB */
+
 void game_handle_net_messages(char buf[NET_BUF_LEN],char command[NET_BUF_LEN])
 {
   if(strncmp(command,"PLAYER_MSG",strlen("PLAYER_MSG"))==0)
   {
-    printf("buf is %s\n",buf);                                                  //basically here we can have any funct. as of now just printing it to stdout
+    printf("buf is %s\n", buf);                                                  //basically here we can have any funct. as of now just printing it to stdout
   }
 
   else if(strncmp(command,"SEND_QUESTION",strlen("SEND_QUESTION"))==0)
@@ -521,9 +525,11 @@
   {
     game_over_won=1;
   }
-  
+  /* FIXME need to handle unrecognized messages, maybe just printf()
+     with a warning until they get implemented - DSB             */
 }
 
+
 /* 
 Set one to four lines of text to display at the game's start. Eventually
 this should stylishly fade out over the first few moments of the game.
@@ -538,6 +544,8 @@
   start_message_chosen = 1;
 }
 
+
+
 int game_initialize(void)
 {
   int i,img;

Modified: tuxmath/branches/lan/src/highscore.c
===================================================================
--- tuxmath/branches/lan/src/highscore.c	2009-07-19 22:58:26 UTC (rev 1237)
+++ tuxmath/branches/lan/src/highscore.c	2009-07-20 01:57:32 UTC (rev 1238)
@@ -845,6 +845,10 @@
         }
       }
     }
+   //FIXME - so we pull all the messages out of the socket and ignore anything
+   //that isn't "GO_TO_GAME" - why are we ignoring them?  We cannot assume the
+   //server is going to send us what we expect. At a minimum, we need to 
+   //print any unrecognized messages to stderr with a warning - DSB
    while(!check_messages(buf))
    {
      if(strncmp(buf,"GO_TO_GAME",strlen("GO_TO_GAME"))==0)

Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c	2009-07-19 22:58:26 UTC (rev 1237)
+++ tuxmath/branches/lan/src/network.c	2009-07-20 01:57:32 UTC (rev 1238)
@@ -125,6 +125,7 @@
 }
 
 
+/* Appears a return value of 0 means message received, 1 means no socket activity */
 int check_messages(char buf[NET_BUF_LEN])
 { 
   int numready;




More information about the Tux4kids-commits mailing list