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

David Bruce dbruce-guest at alioth.debian.org
Wed Oct 14 10:29:41 UTC 2009


Author: dbruce-guest
Date: 2009-10-14 10:29:40 +0000 (Wed, 14 Oct 2009)
New Revision: 1590

Modified:
   tuxmath/trunk/src/game.c
   tuxmath/trunk/src/server.c
Log:
Implement message-sending for LAN player names and scores

Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c	2009-10-13 20:59:31 UTC (rev 1589)
+++ tuxmath/trunk/src/game.c	2009-10-14 10:29:40 UTC (rev 1590)
@@ -148,6 +148,8 @@
 MC_FlashCard quest_queue[QUEST_QUEUE_SIZE];    //current questions
 int remaining_quests = 0;
 static int comet_counter = 0;
+static int lan_players = 0;
+//FIXME add arrays for lan player names and scores
 /****************************************************************/
 typedef struct {
   int x_is_blinking;
@@ -210,6 +212,8 @@
 void game_handle_net_msg(char* buf);
 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 erase_comet_on_screen(comet_type* comet_ques);
 void print_current_quests(void);
 MC_FlashCard* search_queue_by_id(int id);
@@ -543,6 +547,16 @@
       game_over_other = 1;
   }
 
+  else if(strncmp(buf, "CONNECTED_PLAYERS", strlen("CONNECTED_PLAYERS")) == 0)
+  {
+    connected_players_recvd(buf);
+  }
+
+  else if(strncmp(buf, "UPDATE_SCORES", strlen("UPDATE_SCORES")) == 0)
+  {
+    update_scores_recvd(buf);
+  }
+
   else if(strncmp(buf, "MISSION_ACCOMPLISHED", strlen("MISSION_ACCOMPLISHED")) == 0)
   {
     game_over_won = 1;
@@ -640,6 +654,23 @@
 }
 
 
+/* Here we have been told how many LAN players are still    */
+/* in the game. This should always be followed by a series  */
+/* of UPDATE_SCORES messages, each with the name and score  */
+/* of a player. We clear out the array to get rid of anyone */
+/* who has disconnected.                                    */
+int connected_players_recvd(char* buf)
+{
+  return 1;
+}
+
+/* Receive the name and current score of a currently-connected */
+/* LAN player.                                                 */
+int update_scores_recvd(char* buf)
+{
+  return 1;
+}
+
 /* Return a pointer to an empty comet slot, */
 /* returning NULL if no vacancy found:      */
 

Modified: tuxmath/trunk/src/server.c
===================================================================
--- tuxmath/trunk/src/server.c	2009-10-13 20:59:31 UTC (rev 1589)
+++ tuxmath/trunk/src/server.c	2009-10-14 10:29:40 UTC (rev 1590)
@@ -69,9 +69,10 @@
 int calc_score(int difficulty, float t);
 
 //message sending:
-int send_counter_updates(void);
 int add_question(MC_FlashCard* fc);
 int remove_question(int id);
+int send_counter_updates(void);
+int send_score_updates(void);
 //int SendQuestion(MC_FlashCard flash, TCPsocket client_sock);
 int SendMessage(int message, int ques_id, char* name, TCPsocket client_sock);
 int player_msg(int i, char* msg);
@@ -850,6 +851,8 @@
   game_msg_next_question();
   //and update the game counters:
   send_counter_updates();
+  //and the scores:
+  send_score_updates();
 }
 
 
@@ -1043,6 +1046,43 @@
   return 1;
 }
 
+
+int send_score_updates(void)
+{
+  int i = 0;
+
+  /* Count how many players are active and send number to clients: */
+  {
+    int connected_players = 0;
+    char buf[NET_BUF_LEN];
+    for(i = 0; i < MAX_CLIENTS; i++)
+      if((client[i].game_ready == 1) && (client[i].sock != NULL))
+        connected_players++;
+
+    snprintf(buf, NET_BUF_LEN, "%s\t%d", "CONNECTED_PLAYERS",
+             connected_players);
+    transmit_all(buf);
+  }
+
+  /* Now send out all the names and scores: */
+  for(i = 0; i < MAX_CLIENTS; i++)
+  {
+    if((client[i].game_ready == 1)
+    && (client[i].sock != NULL))
+    {
+      char buf[NET_BUF_LEN];
+      snprintf(buf, NET_BUF_LEN, "%s\t%d\t%s\t%d", "UPDATE_SCORE",
+               i,
+               client[i].name,
+               client[i].score);
+      transmit_all(buf);
+    }
+  }
+
+  return 1;
+}
+
+
 /* Sends a new question to all clients: */
 int add_question(MC_FlashCard* fc)
 {




More information about the Tux4kids-commits mailing list