[Tux4kids-commits] r1592 - tuxmath/trunk/src

David Bruce dbruce-guest at alioth.debian.org
Thu Oct 15 23:09:21 UTC 2009


Author: dbruce-guest
Date: 2009-10-15 23:09:21 +0000 (Thu, 15 Oct 2009)
New Revision: 1592

Modified:
   tuxmath/trunk/src/game.c
   tuxmath/trunk/src/server.c
   tuxmath/trunk/src/transtruct.h
Log:
implementation of messaging for scores in network game

Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c	2009-10-14 23:20:51 UTC (rev 1591)
+++ tuxmath/trunk/src/game.c	2009-10-15 23:09:21 UTC (rev 1592)
@@ -149,8 +149,10 @@
 int remaining_quests = 0;
 static int comet_counter = 0;
 static int lan_players = 0;
-//FIXME add arrays for lan player names and scores
+char lan_pnames[MAX_CLIENTS][NAME_SIZE];
+int lan_pscores[MAX_CLIENTS];
 /****************************************************************/
+
 typedef struct {
   int x_is_blinking;
   int extra_life_is_blinking;
@@ -213,7 +215,7 @@
 int add_quest_recvd(char* buf);
 int remove_quest_recvd(char* buf);
 int connected_players_recvd(char* buf);
-int update_scores_recvd(char* buf);
+int update_score_recvd(char* buf);
 int erase_comet_on_screen(comet_type* comet_ques);
 void print_current_quests(void);
 MC_FlashCard* search_queue_by_id(int id);
@@ -517,7 +519,7 @@
 
 void game_handle_net_msg(char* buf)
 {
-  DEBUGMSG(debug_game, "Received server message: %s\n", buf);
+  DEBUGMSG(debug_lan, "Received server message: %s\n", buf);
 
   if(strncmp(buf, "PLAYER_MSG", strlen("PLAYER_MSG")) == 0)
   {
@@ -552,9 +554,9 @@
     connected_players_recvd(buf);
   }
 
-  else if(strncmp(buf, "UPDATE_SCORES", strlen("UPDATE_SCORES")) == 0)
+  else if(strncmp(buf, "UPDATE_SCORE", strlen("UPDATE_SCORE")) == 0)
   {
-    update_scores_recvd(buf);
+    update_score_recvd(buf);
   }
 
   else if(strncmp(buf, "MISSION_ACCOMPLISHED", strlen("MISSION_ACCOMPLISHED")) == 0)
@@ -661,13 +663,77 @@
 /* who has disconnected.                                    */
 int connected_players_recvd(char* buf)
 {
-  return 1;
+  int n = 0;
+  int i = 0;
+  char* p = NULL;
+
+  if(!buf)
+    return 0;
+
+  p = strchr(buf, '\t');
+  if(!p)
+    return 0;
+  p++;
+  n = atoi(p);
+
+  DEBUGMSG(debug_game, "connected_players_recvd() for n = %d\n", n);
+
+  if(n < 0 || n > MAX_CLIENTS)
+  {
+    fprintf(stderr, "connected_players_recvd() - illegal value: %d\n", n);
+    return -1;
+  }
+  lan_players = n;
+
+  /* Reset array - we should be getting new values in immediately */
+  /* following messages.                                          */
+  for(i = 0; i < MAX_CLIENTS; i++)
+  {
+    lan_pnames[i][0] = '\0';
+    lan_pscores[i] = -1;
+  }
+  return n;
 }
 
 /* Receive the name and current score of a currently-connected */
 /* LAN player.                                                 */
-int update_scores_recvd(char* buf)
+int update_score_recvd(char* buf)
 {
+  int i = 0;
+  char* p = NULL;
+
+  if(buf == NULL)
+    return 0;
+  // get i:
+  p = strchr(buf, '\t');
+  if(!p)
+    return 0;
+  p++;
+  i = atoi(p);
+
+  //get name:
+  p = strchr(p, '\t');
+  if(!p)
+    return 0;
+  p++;
+  strncpy(lan_pnames[i], p, NAME_SIZE);
+  //This has most likely copied the score field as well, so replace the
+  //tab delimiter with a null:
+  {
+    char* p2 = strchr(lan_pnames[i], '\t');
+    if (p2)
+      *p2 = '\0';
+  }
+
+  //Now get score:
+  p = strchr(p, '\t');
+  if(p)
+    lan_pscores[i] = atoi(p);
+
+  DEBUGMSG(debug_lan, "update_score_recvd() - buf is: %s\n", buf);
+  DEBUGMSG(debug_lan, "i is: %d\tname is: %s\tscore is: %d\n", 
+           i, lan_pnames[i], lan_pscores[i]);
+
   return 1;
 }
 

Modified: tuxmath/trunk/src/server.c
===================================================================
--- tuxmath/trunk/src/server.c	2009-10-14 23:20:51 UTC (rev 1591)
+++ tuxmath/trunk/src/server.c	2009-10-15 23:09:21 UTC (rev 1592)
@@ -35,7 +35,6 @@
 #endif
 
 
-#define MAX_CLIENTS 16
 #define MAX_ARGS 16
 
 

Modified: tuxmath/trunk/src/transtruct.h
===================================================================
--- tuxmath/trunk/src/transtruct.h	2009-10-14 23:20:51 UTC (rev 1591)
+++ tuxmath/trunk/src/transtruct.h	2009-10-15 23:09:21 UTC (rev 1592)
@@ -18,6 +18,7 @@
 #define DEFAULT_PORT 4779
 #define NAME_SIZE 50
 #define MAX_SERVERS 50
+#define MAX_CLIENTS 16
 
 #define MC_USE_NEWARC
 #define MC_FORMULA_LEN 40




More information about the Tux4kids-commits mailing list