[Tux4kids-commits] r1281 - in tuxmath/branches/lan: server src
akash gangil
gangil-guest at alioth.debian.org
Mon Jul 27 14:51:05 UTC 2009
Author: gangil-guest
Date: 2009-07-27 14:51:04 +0000 (Mon, 27 Jul 2009)
New Revision: 1281
Modified:
tuxmath/branches/lan/server/testclient.c
tuxmath/branches/lan/src/game.c
tuxmath/branches/lan/src/highscore.c
tuxmath/branches/lan/src/highscore.h
tuxmath/branches/lan/src/titlescreen.c
Log:
Automatically connects to server in graphical tuxmath , if there is only one server , working on multiple thing
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-07-27 02:31:58 UTC (rev 1280)
+++ tuxmath/branches/lan/server/testclient.c 2009-07-27 14:51:04 UTC (rev 1281)
@@ -66,7 +66,7 @@
char buf[NET_BUF_LEN]; // for network messages from server
char buffer[NET_BUF_LEN]; // for command-line input
int servers_found = 0;
- int server_number= -1;
+ int server_number = -1;
Uint32 server_ip = 0;
Uint16 server_port = DEFAULT_PORT;
@@ -90,7 +90,12 @@
printf("connected\n");
}
+<<<<<<< .mine
+
+ else // More than one server - will have to get player selection
+=======
else // More than one server - will have to get player selection:
+>>>>>>> .r1280
{
while(server_number < 0 || server_number >= servers_found)
{
Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c 2009-07-27 02:31:58 UTC (rev 1280)
+++ tuxmath/branches/lan/src/game.c 2009-07-27 14:51:04 UTC (rev 1281)
@@ -243,6 +243,7 @@
return 0;
}
+
if (Opts_HelpMode()) {
game_handle_help();
game_cleanup();
@@ -675,7 +676,7 @@
else if(strncmp(command,"TOTAL_QUESTIONS",strlen("TOTAL_QUESTIONS"))==0)
{
sscanf(buf,"%*s %d",&total_questions_left);
- if(!total_questions_left)
+ if(!total_questions_left)
game_over_other=1;
}
Modified: tuxmath/branches/lan/src/highscore.c
===================================================================
--- tuxmath/branches/lan/src/highscore.c 2009-07-27 02:31:58 UTC (rev 1280)
+++ tuxmath/branches/lan/src/highscore.c 2009-07-27 14:51:04 UTC (rev 1281)
@@ -891,8 +891,162 @@
}
+void detecting_servers(const char* heading, const char* sub)
+{
+
+ SDL_Rect loc;
+ SDL_Rect TuxRect,
+ stopRect;
+ char buf[NET_BUF_LEN];
+ int finished = 0;
+ int tux_frame = 0;
+ Uint32 frame = 0;
+ Uint32 start = 0;
+ int servers_found = 0;
+
+ sprite* Tux = LoadSprite("tux/bigtux", IMG_ALPHA);
+
+
+ /* We need to get Unicode vals from SDL keysyms */
+ SDL_EnableUNICODE(SDL_ENABLE);
+
+#ifdef TUXMATH_DEBUG
+ fprintf(stderr, "\nEnter HighScoreNameEntry()\n" );
+#endif
+
+
+ /* Draw background: */
+ if (current_bkg())
+ SDL_BlitSurface(current_bkg(), NULL, screen, NULL);
+
+ /* Red "Stop" circle in upper right corner to go back to main menu: */
+ if (images[IMG_STOP])
+ {
+ stopRect.w = images[IMG_STOP]->w;
+ stopRect.h = images[IMG_STOP]->h;
+ stopRect.x = screen->w - images[IMG_STOP]->w;
+ stopRect.y = 0;
+ SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
+ }
+
+ if (Tux && Tux->frame[0]) /* make sure sprite has at least one frame */
+ {
+ TuxRect.w = Tux->frame[0]->w;
+ TuxRect.h = Tux->frame[0]->h;
+ TuxRect.x = 0;
+ TuxRect.y = screen->h - Tux->frame[0]->h;
+ }
+
+ /* Draw heading: */
+ {
+ SDL_Surface* s = BlackOutline(_(heading),
+ DEFAULT_MENU_FONT_SIZE, &white);
+ if (s)
+ {
+ loc.x = (screen->w/2) - (s->w/2);
+ loc.y = 110;
+ SDL_BlitSurface(s, NULL, screen, &loc);
+ SDL_FreeSurface(s);
+ }
+
+ s = BlackOutline(_(sub),
+ DEFAULT_MENU_FONT_SIZE, &white);
+ if (s)
+ {
+ loc.x = (screen->w/2) - (s->w/2);
+ loc.y = 140;
+ SDL_BlitSurface(s, NULL, screen, &loc);
+ SDL_FreeSurface(s);
+ }
+ }
+
+ /* and update: */
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+
+
+ while (!finished)
+ {
+ start = SDL_GetTicks();
+
+ while (SDL_PollEvent(&event))
+ {
+ switch (event.type)
+ {
+ case SDL_QUIT:
+ {
+ cleanup();
+ }
+
+ case SDL_MOUSEBUTTONDOWN:
+ /* "Stop" button - go to main menu: */
+ {
+ if (inRect(stopRect, event.button.x, event.button.y ))
+ {
+ finished = 1;
+ playsound(SND_TOCK);
+ break;
+ }
+ }
+ }
+ }
+ //Scan local network to find running server:
+ servers_found = LAN_DetectServers();
+ if(servers_found < 1)
+ {
+ printf("No server could be found - exiting.\n");
+ exit(EXIT_FAILURE);
+ }
+ 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);
+ }
+ finished = 1;
+ break;
+ printf("connected\n");
+ }
+
+ /* --- make tux blink --- */
+ switch (frame % TUX6)
+ {
+ case 0: tux_frame = 1; break;
+ case TUX1: tux_frame = 2; break;
+ case TUX2: tux_frame = 3; break;
+ case TUX3: tux_frame = 4; break;
+ case TUX4: tux_frame = 3; break;
+ case TUX5: tux_frame = 2; break;
+ default: tux_frame = 0;
+ }
+
+ if (Tux && tux_frame)
+ {
+ SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &TuxRect);
+ SDL_UpdateRect(screen, TuxRect.x, TuxRect.y, TuxRect.w, TuxRect.h);
+ }
+
+ /* Wait so we keep frame rate constant: */
+ while ((SDL_GetTicks() - start) < 33)
+ {
+ SDL_Delay(20);
+ }
+ frame++;
+ } // End of while (!finished) loop
+
+ FreeSprite(Tux);
+
+ /* Turn off SDL Unicode lookup (because has some overhead): */
+ SDL_EnableUNICODE(SDL_DISABLE);
+
+}
+
+
/* Zero-out the array before use: */
void initialize_scores(void)
{
Modified: tuxmath/branches/lan/src/highscore.h
===================================================================
--- tuxmath/branches/lan/src/highscore.h 2009-07-27 02:31:58 UTC (rev 1280)
+++ tuxmath/branches/lan/src/highscore.h 2009-07-27 14:51:04 UTC (rev 1281)
@@ -21,6 +21,7 @@
void HighScoreNameEntry(char* pl_name);
void NameEntry(char* pl_name, const char* heading, const char* sub);
void Standby(const char* heading, const char* sub);
+void detecting_servers(const char* heading, const char* sub);
void Ready(const char* heading);
int check_score_place(int diff_level, int new_score);
Modified: tuxmath/branches/lan/src/titlescreen.c
===================================================================
--- tuxmath/branches/lan/src/titlescreen.c 2009-07-27 02:31:58 UTC (rev 1280)
+++ tuxmath/branches/lan/src/titlescreen.c 2009-07-27 14:51:04 UTC (rev 1281)
@@ -870,7 +870,8 @@
{
int mode = -1;
int b;
-
+ int servers_found = 0;
+
const char* menu_text[3] =
{N_("Host"),
N_("Join"),
@@ -881,7 +882,8 @@
modesprites[0] = sprite_list[SPRITE_SERVER];
modesprites[1] = sprite_list[SPRITE_CLIENT];
modesprites[2] = sprite_list[SPRITE_MAIN];
- while (1)
+
+ while (1)
{
//choose mode
mode = choose_menu_item(menu_text,modesprites,3,NULL,NULL);
@@ -892,26 +894,45 @@
// run_server_menu();
if(mode == 1)
- { NameEntry(host, _("Enter the name or ip address"),
- _("(of the Host)"));
- NameEntry(player_name, _("Enter you name"),
+ {
+ detecting_servers(_("Detecting Servers"),_("Please Wait"));
+
+/* if(servers_found < 1)
+ {
+ printf("No server could be found - exiting.\n");
+ exit(EXIT_FAILURE);
+ }
+ 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");
+ }
+*/
+ NameEntry(player_name, _("Enter your Name:"),
_(""));
+// if(!LAN_Setup(host, DEFAULT_PORT))
+// {
+// printf("Unable to connect to the server\n");
+// LAN_Cleanup();
+// return 0;
+// }
- if(!LAN_Setup(host, DEFAULT_PORT))
- {
- printf("Unable to connect to the server\n");
- LAN_Cleanup();
- return 0;
- }
- LAN_SetName(player_name);
- Ready(_("Click OK when Ready"));
- LAN_StartGame();
- Standby(_("Waiting For Other Players"),_("To Connect"));
- game();
- }
+ LAN_SetName(player_name);
+ Ready(_("Click OK when Ready"));
+ LAN_StartGame();
+ Standby(_("Waiting For Other Players"),_("To Connect"));
+ game();
+ }
- }
+ }
return 0;
@@ -1019,15 +1040,20 @@
{
audioMusicUnload();
#ifdef HAVE_LIBSDL_NET
- if(!LAN_Setup("localhost", DEFAULT_PORT))
- {
- printf("Unable to connect to the server\n");
- LAN_Cleanup();
- return 0;
- }
+detecting_servers(_("Detecting Servers"),_("Please Wait"));
+ NameEntry(player_name, _("Enter your Name:"),
+ _(""));
+ LAN_SetName(player_name);
+ Ready(_("Click OK when Ready"));
+ LAN_StartGame();
+// if(!LAN_Setup("localhost", DEFAULT_PORT))
+// {
+// printf("Unable to connect to the server\n");
+// LAN_Cleanup();
+// return 0;
+// }
- LAN_SetName("player A");
- LAN_StartGame();
+// LAN_SetName("player A");
#endif
game();
RecalcTitlePositions();
More information about the Tux4kids-commits
mailing list