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

David Bruce dbruce-guest at alioth.debian.org
Sun Jul 19 04:23:48 UTC 2009


Author: dbruce-guest
Date: 2009-07-19 04:23:46 +0000 (Sun, 19 Jul 2009)
New Revision: 1231

Modified:
   tuxmath/branches/lan/server/testclient.c
   tuxmath/branches/lan/server/transtruct.h
   tuxmath/branches/lan/src/network.c
   tuxmath/branches/lan/src/network.h
   tuxmath/branches/lan/src/transtruct.h
Log:
more cleanup and implementation of server, testclient, and LAN_*() functions



Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-07-18 02:45:15 UTC (rev 1230)
+++ tuxmath/branches/lan/server/testclient.c	2009-07-19 04:23:46 UTC (rev 1231)
@@ -23,7 +23,7 @@
 #include <unistd.h>
 #include <fcntl.h> 
 
-#include "SDL_net.h"
+//#include "SDL_net.h"
 #include "transtruct.h"
 #include "mathcards.h"
 #include "testclient.h"
@@ -31,22 +31,26 @@
 #include "../src/network.h"
 
 /* Local (to testclient.c) "globals": */
-TCPsocket sd;           /* Server socket descriptor */
-SDLNet_SocketSet set;
-IPaddress ip;           /* Server address */
-int len = 0;
-int sockets_used = 0;
 int quit = 0;
 MC_FlashCard flash;    //current question
 int have_question = 0;
 
+MC_FlashCard Comets[2];    //current questions
+int remaining_quests = 0;
+
+
 /* Local function prototypes: */
 int playgame(void);
 int game_check_msgs(void);
 int read_stdin_nonblock(char* buf, size_t max_length);
 
+/* Functions to handle messages from server: */
+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);
 
-
 int main(int argc, char **argv)
 {
   char buf[NET_BUF_LEN];     // for network messages from server
@@ -66,7 +70,7 @@
 
     printf("Please enter your name:\n>\n");
     fgets(buffer, NAME_SIZE, stdin);
-    p = strchr(buf, '\t');
+    p = strchr(buffer, '\n');  //get rid of newline character
     if(p)
       *p = '\0';
     strncpy(name, buffer, NAME_SIZE);
@@ -101,13 +105,14 @@
       //Figure out if we are trying to quit:
       if( (strncmp(buffer, "exit", 4) == 0)
         ||(strncmp(buffer, "quit", 4) == 0))
+      //FIXME need a "LAN_Logout() function" so testclient doesn't need to know about SDL_Net
       {
         quit = 1;
-        if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
+/*        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);
-        }
+        }*/
       }
       else if (strncmp(buffer, "game", 4) == 0)
       {
@@ -213,6 +218,27 @@
 }
 
 
+/* This function prints the 'msg' part of the buffer (i.e. everything */
+/* after the first '\t') to stdout.                                   */
+int player_msg_recvd(char* buf)
+{
+  char* p;
+  if(buf == NULL)
+    return 0;
+  p = strchr(buf, '\t');
+  if(p)
+  { 
+    p++;
+    printf("%s\n", p);
+    return 1;
+  }
+  else
+    return 0;
+}
+
+
+
+
 int playgame(void)
 {
   int numready;
@@ -226,20 +252,10 @@
 
   printf("\nStarting Tux, of the Math Command Line ;-)\n");
   printf("Waiting for other players to be ready...\n\n");
- 
-  snprintf(buffer, NET_BUF_LEN, 
-                  "%s",
-                  "START_GAME");
-  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);
-  }
-#ifdef LAN_DEBUG
-  printf("Sent the game notification %s\n",buffer);
- #endif
- 
 
+  //Tell server we're ready to start:
+  LAN_StartGame(); 
+
   //Begin game loop:
   while (!end)
   {
@@ -283,7 +299,10 @@
           }
         }
         else  //we got input, but not the correct answer:
-          printf("Sorry, %s is incorrect. Try again!\n>\n", buf);
+        {
+          printf("Sorry, %s is incorrect. Try again!\n", buf); 
+          printf("The question is: %s\n>\n", flash.formula_string);
+        }
       }  //input wasn't any of our keywords
     } // Input was received 
 

Modified: tuxmath/branches/lan/server/transtruct.h
===================================================================
--- tuxmath/branches/lan/server/transtruct.h	2009-07-18 02:45:15 UTC (rev 1230)
+++ tuxmath/branches/lan/server/transtruct.h	2009-07-19 04:23:46 UTC (rev 1231)
@@ -14,7 +14,7 @@
 #ifndef TRANSTRUCT_H
 #define TRANSTRUCT_H
 
-#define LAN_DEBUG
+//#define LAN_DEBUG
 #define NET_BUF_LEN 512
 #define DEFAULT_PORT 4779
 #define NAME_SIZE 50

Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c	2009-07-18 02:45:15 UTC (rev 1230)
+++ tuxmath/branches/lan/src/network.c	2009-07-19 04:23:46 UTC (rev 1231)
@@ -19,6 +19,8 @@
 
 #include "SDL_net.h"
 #include "transtruct.h"
+#include "network.h"
+
 //#include "testclient.h"
 
 
@@ -108,26 +110,10 @@
 }
 
 
-/* This function prints the 'msg' part of the buffer (i.e. everything */
-/* after the first '\t') to stdout.                                   */
-int player_msg_recvd(char* buf)
-{
-  char* p;
-  if(buf == NULL)
-    return 0;
-  p = strchr(buf, '\t');
-  if(p)
-  { 
-    p++;
-    printf("%s\n", p);
-    return 1;
-  }
-  else
-    return 0;
-}
 
 
 
+
 int LAN_NextQuestion(void)
 {
   char buf[NET_BUF_LEN];

Modified: tuxmath/branches/lan/src/network.h
===================================================================
--- tuxmath/branches/lan/src/network.h	2009-07-18 02:45:15 UTC (rev 1230)
+++ tuxmath/branches/lan/src/network.h	2009-07-19 04:23:46 UTC (rev 1231)
@@ -11,12 +11,12 @@
 */
 
 
-#include "transtruct.h"
 
 
 #ifndef NETWORK_H
 #define NETWORK_H
 
+#include "transtruct.h"
 
 
 /* Networking setup and cleanup: */
@@ -37,9 +37,6 @@
 int LAN_NextMsg(char* buf);
 
 
-/* Functions to handle various messages from the server: */
-/* NOTE not sure if these belong here or in game.c/testclient.c */
-int player_msg_recvd(char* buf);
 
 
 

Modified: tuxmath/branches/lan/src/transtruct.h
===================================================================
--- tuxmath/branches/lan/src/transtruct.h	2009-07-18 02:45:15 UTC (rev 1230)
+++ tuxmath/branches/lan/src/transtruct.h	2009-07-19 04:23:46 UTC (rev 1231)
@@ -14,7 +14,7 @@
 #ifndef TRANSTRUCT_H
 #define TRANSTRUCT_H
 
-#define LAN_DEBUG
+//#define LAN_DEBUG
 #define NET_BUF_LEN 512
 #define DEFAULT_PORT 4779
 #define NAME_SIZE 50




More information about the Tux4kids-commits mailing list