[Tux4kids-commits] r1476 - in tuxmath/branches/lan: server src
David Bruce
dbruce-guest at alioth.debian.org
Wed Sep 2 10:50:26 UTC 2009
Author: dbruce-guest
Date: 2009-09-02 10:50:25 +0000 (Wed, 02 Sep 2009)
New Revision: 1476
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/src/game.c
tuxmath/branches/lan/src/highscore.c
tuxmath/branches/lan/src/highscore.h
tuxmath/branches/lan/src/network.c
tuxmath/branches/lan/src/network.h
tuxmath/branches/lan/src/titlescreen.c
Log:
Handle game-in-progress correctly
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-09-01 17:55:15 UTC (rev 1475)
+++ tuxmath/branches/lan/server/server.c 2009-09-02 10:50:25 UTC (rev 1476)
@@ -369,9 +369,8 @@
if(game_in_progress)
{
snprintf(buffer, NET_BUF_LEN,
- "%s\t%s",
- "PLAYER_MSG",
- "Sorry, the game has started...... =(");
+ "%s",
+ "GAME_IN_PROGRESS");
SDLNet_TCP_Send(temp_sock, buffer, NET_BUF_LEN);
//hang up:
SDLNet_TCP_Close(temp_sock);
Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c 2009-09-01 17:55:15 UTC (rev 1475)
+++ tuxmath/branches/lan/src/game.c 2009-09-02 10:50:25 UTC (rev 1476)
@@ -281,11 +281,19 @@
if(Opts_LanMode())
{
#ifdef HAVE_LIBSDL_NET
- while(!check_messages(buf))
+ int status = check_messages(buf);
+ while(!status)
{
seperate_commmand_and_buf(command, buf);
game_handle_net_messages(buf, command);
+ status = check_messages(buf);
}
+
+ if(status == -1)
+ {
+ game_cleanup();
+ return GAME_OVER_ERROR;
+ }
#else
fprintf(stderr, "Warning - LAN mode selected but SDL_net not available!\n");
Opts_SetLanMode(0);
Modified: tuxmath/branches/lan/src/highscore.c
===================================================================
--- tuxmath/branches/lan/src/highscore.c 2009-09-01 17:55:15 UTC (rev 1475)
+++ tuxmath/branches/lan/src/highscore.c 2009-09-02 10:50:25 UTC (rev 1476)
@@ -745,7 +745,7 @@
}
-void Standby(const char* heading, const char* sub)
+int Standby(const char* heading, const char* sub)
{
SDL_Rect loc;
@@ -838,7 +838,7 @@
{
if (inRect(stopRect, event.button.x, event.button.y ))
{
- finished = 1;
+ finished = -1;
playsound(SND_TOCK);
break;
}
@@ -852,12 +852,18 @@
//print any unrecognized messages to stderr with a warning - DSB
while(!check_messages(buf))
{
- if(strncmp(buf,"GO_TO_GAME",strlen("GO_TO_GAME"))==0)
+ if(strncmp(buf,"GO_TO_GAME",strlen("GO_TO_GAME")) == 0)
{
finished = 1;
playsound(SND_TOCK);
break;
- }
+ }
+ else if(strncmp(buf, "GAME_IN_PROGRESS", strlen("GAME_IN_PROGRESS")) == 0)
+ {
+ finished = -1;
+ playsound(SND_TOCK);
+ break;
+ }
}
/* --- make tux blink --- */
@@ -891,6 +897,8 @@
/* Turn off SDL Unicode lookup (because has some overhead): */
SDL_EnableUNICODE(SDL_DISABLE);
+ /* 1 means we start game, -1 means we go back to menu */
+ return finished;
}
Modified: tuxmath/branches/lan/src/highscore.h
===================================================================
--- tuxmath/branches/lan/src/highscore.h 2009-09-01 17:55:15 UTC (rev 1475)
+++ tuxmath/branches/lan/src/highscore.h 2009-09-02 10:50:25 UTC (rev 1476)
@@ -20,7 +20,7 @@
void DisplayHighScores(int level);
void HighScoreNameEntry(char* pl_name);
void NameEntry(char* pl_name, const char* heading, const char* sub);
-void Standby(const char* heading, const char* sub);
+int Standby(const char* heading, const char* sub);
int detecting_servers(const char* heading, const char* sub);
void Ready(const char* heading);
Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c 2009-09-01 17:55:15 UTC (rev 1475)
+++ tuxmath/branches/lan/src/network.c 2009-09-02 10:50:25 UTC (rev 1476)
@@ -182,55 +182,55 @@
-int LAN_Setup(char *host, int port)
-{
- IPaddress ip; /* Server address */
+// int LAN_Setup(char *host, int port)
+// {
+// IPaddress ip; /* Server address */
+//
+// if(SDL_Init(0)==-1)
+// {
+// printf("SDL_Init: %s\n", SDL_GetError());
+// return 0;;
+// }
+//
+// if (SDLNet_Init() < 0)
+// {
+// fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
+// return 0;
+// }
+//
+// /* Resolve the host we are connecting to */
+// if (SDLNet_ResolveHost(&ip, host, port) < 0)
+// {
+// fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
+// return 0;
+// }
+//
+// /* Open a connection with the IP provided (listen on the host's port) */
+// if (!(sd = SDLNet_TCP_Open(&ip)))
+// {
+// fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
+// return 0;
+// }
+//
+// /* We create a socket set so we can check for activity: */
+// set = SDLNet_AllocSocketSet(1);
+// if(!set)
+// {
+// printf("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError());
+// return 0;
+// }
+//
+// if(SDLNet_TCP_AddSocket(set, sd) == -1)
+// {
+// printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
+// // perhaps you need to restart the set and make it bigger...
+// }
+//
+//
+// return 1;
+// }
- if(SDL_Init(0)==-1)
- {
- printf("SDL_Init: %s\n", SDL_GetError());
- return 0;;
- }
- if (SDLNet_Init() < 0)
- {
- fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
- return 0;
- }
-
- /* Resolve the host we are connecting to */
- if (SDLNet_ResolveHost(&ip, host, port) < 0)
- {
- fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
- return 0;
- }
-
- /* Open a connection with the IP provided (listen on the host's port) */
- if (!(sd = SDLNet_TCP_Open(&ip)))
- {
- fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
- return 0;
- }
-
- /* We create a socket set so we can check for activity: */
- set = SDLNet_AllocSocketSet(1);
- if(!set)
- {
- printf("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError());
- return 0;
- }
-
- if(SDLNet_TCP_AddSocket(set, sd) == -1)
- {
- printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
- // perhaps you need to restart the set and make it bigger...
- }
-
-
- return 1;
-}
-
-
void LAN_Cleanup(void)
{
if(sd)
@@ -263,17 +263,6 @@
-// int LAN_NextQuestion(void)
-// {
-// char buf[NET_BUF_LEN];
-//
-// snprintf(buf, NET_BUF_LEN,
-// "%s",
-// "NEXT_QUESTION");
-// return say_to_server(buf);
-// }
-
-
/* Appears a return value of 0 means message received, 1 means no socket activity */
int check_messages(char buf[NET_BUF_LEN])
{
@@ -298,8 +287,8 @@
buf[0] = '\0';
if(SDLNet_TCP_Recv(sd, buf, NET_BUF_LEN) <= 0)
{
- fprintf(stderr, "In play_game(), SDLNet_TCP_Recv() failed!\n");
- exit(EXIT_FAILURE);
+ fprintf(stderr, "In check_messages(), SDLNet_TCP_Recv() failed!\n");
+ return -1;
}
return 0;
}
Modified: tuxmath/branches/lan/src/network.h
===================================================================
--- tuxmath/branches/lan/src/network.h 2009-09-01 17:55:15 UTC (rev 1475)
+++ tuxmath/branches/lan/src/network.h 2009-09-02 10:50:25 UTC (rev 1476)
@@ -31,7 +31,7 @@
int LAN_AutoSetup(int i);
char* LAN_ServerName(int i);
char* LAN_ConnectedServerName(void);
-int LAN_Setup(char* host, int port);
+//int LAN_Setup(char* host, int port);
void LAN_Cleanup(void);
int LAN_SetName(char* name);
Modified: tuxmath/branches/lan/src/titlescreen.c
===================================================================
--- tuxmath/branches/lan/src/titlescreen.c 2009-09-01 17:55:15 UTC (rev 1475)
+++ tuxmath/branches/lan/src/titlescreen.c 2009-09-02 10:50:25 UTC (rev 1476)
@@ -708,17 +708,6 @@
Opts_SetDemoMode(0);
if (Opts_GetGlobalOpt(MENU_MUSIC)) //Turn menu music off for game
{audioMusicUnload();}
-// #ifdef HAVE_LIBSDL_NET
-// if(!LAN_Setup("localhost", DEFAULT_PORT))
-// {
-// printf("Unable to connect to the server\n");
-// LAN_Cleanup();
-// return 0;
-// }
-//
-// LAN_SetName("player A");
-// LAN_StartGame();
-// #endif
game();
RecalcTitlePositions();
if (Opts_GetGlobalOpt(MENU_MUSIC)) //Turn menu music back on
@@ -896,17 +885,24 @@
{
if(detecting_servers(_("Detecting Servers"), _("Please Wait")))
{
+ int stdby;
char buf[256];
snprintf(buf, 256, _("Connected to server: %s"), LAN_ConnectedServerName());
NameEntry(player_name, buf, _("Enter your Name:"));
LAN_SetName(player_name);
Ready(_("Click OK when Ready"));
LAN_StartGame();
- Standby(_("Waiting For Other Players"),_("To Connect"));
-
- Opts_SetLanMode(1); // Tells game() we are playing over network
- game();
- Opts_SetLanMode(0); // Go back to local play
+ stdby = Standby(_("Waiting For Other Players"),_("To Connect"));
+ if (stdby == 1)
+ {
+ Opts_SetLanMode(1); // Tells game() we are playing over network
+ game();
+ Opts_SetLanMode(0); // Go back to local play
+ }
+ else
+ {
+ ShowMessage(NULL, _("Sorry, game already in progress."), NULL, NULL);
+ }
}
else
{
@@ -1228,17 +1224,6 @@
if (read_named_config_file("demo"))
{
audioMusicUnload();
-#ifdef HAVE_LIBSDL_NET
- if(!LAN_Setup("localhost", DEFAULT_PORT))
- {
- printf("Unable to connect to the server\n");
- LAN_Cleanup();
- return 0;
- }
-
- LAN_SetName("player A");
- LAN_StartGame();
-#endif
game();
RecalcTitlePositions();
if (Opts_GetGlobalOpt(MENU_MUSIC)) {
More information about the Tux4kids-commits
mailing list