[Tux4kids-commits] r1274 - in tuxmath/branches/lan: server src
David Bruce
dbruce-guest at alioth.debian.org
Sat Jul 25 14:50:33 UTC 2009
Author: dbruce-guest
Date: 2009-07-25 14:50:31 +0000 (Sat, 25 Jul 2009)
New Revision: 1274
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/testclient.c
tuxmath/branches/lan/src/network.c
tuxmath/branches/lan/src/network.h
Log:
server autodetection
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-07-25 13:35:15 UTC (rev 1273)
+++ tuxmath/branches/lan/server/server.c 2009-07-25 14:50:31 UTC (rev 1274)
@@ -262,15 +262,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
+ // between multiple servers on same network (e.g. "Mrs. Adams' Class");
out = SDLNet_AllocPacket(NET_BUF_LEN);
out->address.host = in->address.host;
out->address.port = in->address.port;
sprintf(out->data, "TUXMATH_SERVER");
out->len = strlen("TUXMATH_SERVER") + 1;
- // Send server reply:
sent = SDLNet_UDP_Send(udpsock, -1, out);
+
SDLNet_FreePacket(out);
}
}
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-07-25 13:35:15 UTC (rev 1273)
+++ tuxmath/branches/lan/server/testclient.c 2009-07-25 14:50:31 UTC (rev 1274)
@@ -79,7 +79,7 @@
}
else if(servers_found == 1) //One server - connect without player intervention
{
- if(!LAN_AutoSetup())
+ if(!LAN_AutoSetup(0)) //i.e.first (and only) entry in list
{
printf("setup_client() failed - exiting.\n");
exit(EXIT_FAILURE);
Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c 2009-07-25 13:35:15 UTC (rev 1273)
+++ tuxmath/branches/lan/src/network.c 2009-07-25 14:50:31 UTC (rev 1274)
@@ -121,12 +121,24 @@
return num_servers;
}
-//For the simple case where a single server is found and we
-//want to connect transparently to the user:
-int LAN_AutoSetup(void)
+
+char* LAN_ServerName(int i)
{
+ if(servers[i].ip.host != 0)
+ return servers[i].name;
+ else
+ return NULL;
+}
+
+
+
+//For the simple case where a single server is found, i is
+//always 0. Otherwise the player has to review the choices
+//via LAN_ServerName(i) to get the index
+int LAN_AutoSetup(int i)
+{
/* Open a connection based on autodetection routine: */
- if (!(sd = SDLNet_TCP_Open(&servers[0].ip)))
+ if (!(sd = SDLNet_TCP_Open(&servers[i].ip)))
{
fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
return 0;
Modified: tuxmath/branches/lan/src/network.h
===================================================================
--- tuxmath/branches/lan/src/network.h 2009-07-25 13:35:15 UTC (rev 1273)
+++ tuxmath/branches/lan/src/network.h 2009-07-25 14:50:31 UTC (rev 1274)
@@ -28,7 +28,8 @@
/* Networking setup and cleanup: */
int LAN_DetectServers(void);
-int LAN_AutoSetup(void);
+int LAN_AutoSetup(int i);
+char* LAN_ServerName(int i);
int LAN_Setup(char* host, int port);
void LAN_Cleanup(void);
More information about the Tux4kids-commits
mailing list