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

David Bruce dbruce-guest at alioth.debian.org
Sat Jul 25 15:43:28 UTC 2009


Author: dbruce-guest
Date: 2009-07-25 15:43:26 +0000 (Sat, 25 Jul 2009)
New Revision: 1275

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/server.h
   tuxmath/branches/lan/server/testclient.c
   tuxmath/branches/lan/src/network.c
Log:
-server autodetection
-added server name string

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-07-25 14:50:31 UTC (rev 1274)
+++ tuxmath/branches/lan/server/server.c	2009-07-25 15:43:26 UTC (rev 1275)
@@ -82,7 +82,8 @@
 
 
 /*  ------------   "Local globals" for server.c: ----------  */
-UDPsocket udpsock = NULL;     /* Used to listen for client's server autodetection          */
+char server_name[NAME_SIZE];  /* User-visible name for server selection                     */
+UDPsocket udpsock = NULL;     /* Used to listen for client's server autodetection           */
 TCPsocket server_sock = NULL; /* Socket descriptor for server to accept client TCP sockets. */
 IPaddress ip;
 SDLNet_SocketSet client_set = NULL, temp_sock = NULL, temp_set = NULL;
@@ -147,6 +148,7 @@
 {
   int i = 0;
 
+  // Zero out our client list:
   for(i = 0; i < MAX_CLIENTS; i++)
   {
     client[i].game_ready = 0;   /* waiting for user to OK game start */
@@ -154,6 +156,9 @@
     client[i].sock = NULL;      /* sockets start out unconnected     */
   }
 
+  /* Set name (will get this from config file in future): */
+  strncpy(server_name, DEFAULT_SERVER_NAME, NAME_SIZE);
+
   //this sets up mathcards with hard-coded defaults - no settings
   //read from config file here:
   if (!MC_Initialize())
@@ -162,7 +167,7 @@
     return 0;
   }
 
-  if(SDL_Init(0)==-1)
+  if(SDL_Init(0) == -1)
   {
     printf("SDL_Init: %s\n", SDL_GetError());
     return 0;;
@@ -262,14 +267,17 @@
     UDPpacket* out;
     IPaddress bcast_ip;
     int sent = 0;
-    // Send "I am here" reply so client knows where to connect socket:
-    // TODO add configurable identifying string so user can distinguish 
+    char buf[NET_BUF_LEN];
+    // Send "I am here" reply so client knows where to connect socket,
+    // with configurable identifying string so user can distinguish 
     // between multiple servers on same network (e.g. "Mrs. Adams' Class");
     out = SDLNet_AllocPacket(NET_BUF_LEN); 
+
+    snprintf(buf, NET_BUF_LEN, "%s\t%s", "TUXMATH_SERVER", server_name);
+    snprintf(out->data, NET_BUF_LEN, "%s", buf);
+    out->len = strlen(buf) + 1;
     out->address.host = in->address.host;
     out->address.port = in->address.port;
-    sprintf(out->data, "TUXMATH_SERVER");
-    out->len = strlen("TUXMATH_SERVER") + 1;
 
     sent = SDLNet_UDP_Send(udpsock, -1, out);
 

Modified: tuxmath/branches/lan/server/server.h
===================================================================
--- tuxmath/branches/lan/server/server.h	2009-07-25 14:50:31 UTC (rev 1274)
+++ tuxmath/branches/lan/server/server.h	2009-07-25 15:43:26 UTC (rev 1275)
@@ -17,6 +17,7 @@
 
 #include "SDL_net.h"
 #define NAME_SIZE 50
+#define DEFAULT_SERVER_NAME "TuxMath LAN Server"
 
 typedef struct client_type {
   int game_ready;                 //game_ready = 1 , if client has said OK to start, and 0 otherwise

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-07-25 14:50:31 UTC (rev 1274)
+++ tuxmath/branches/lan/server/testclient.c	2009-07-25 15:43:26 UTC (rev 1275)
@@ -79,11 +79,15 @@
   }
   else if(servers_found  == 1)  //One server - connect without player intervention
   {
+    printf("Single server found - connecting automatically...");
+
     if(!LAN_AutoSetup(0))  //i.e.first (and only) entry in list
     {
       printf("setup_client() failed - exiting.\n");
       exit(EXIT_FAILURE);
     }
+
+    printf("connected\n");
   } 
   else  // More than one server - will have to get player selection 
   {

Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c	2009-07-25 14:50:31 UTC (rev 1274)
+++ tuxmath/branches/lan/src/network.c	2009-07-25 15:43:26 UTC (rev 1275)
@@ -85,9 +85,13 @@
 
   //Here we will need to send every few sec onds until we hear back from server
   //and get its ip address:  IPaddress bcast_ip;
-
+  printf("\nAutodetecting TuxMath servers:");
+  fflush(stdout);
   while(!done)
   {
+    printf(".");
+    fflush(stdout);
+
     sent = SDLNet_UDP_Send(udpsock, -1, out);
     if(!sent)
     {
@@ -115,6 +119,9 @@
     Throttle(1000); //repeat once per second
   }
 
+  printf("done\n\n");
+
+
   SDLNet_FreePacket(out); 
   SDLNet_FreePacket(in); 
   print_server_list();




More information about the Tux4kids-commits mailing list