/* network menu */ #include "bomberclone.h" #include "network.h" #include "packets.h" #include "gamesrv.h" #include "gfx.h" extern int UpdateRects_nr; void networkmenu_joingame () { int i; gamesrv_getserver (); for (i = 0; bman.servername[i] != 0; i++) if (bman.servername[i] == ' ') bman.servername[i] = ':'; /* connect if we have an Servername */ if (bman.servername[0] != 0) { bman.sock = -1; bman.gametype = GT_multi; bman.multitype = MT_ptps; join_multiplayer_game (); bman.servername[0] = 0; } }; void netmenu () { int menuselect = 0; _menu menu[] = { {1, "Join A Netgame"}, {1, "Create A New Netgame"}, {2, "Options"}, {3, "Return To Main Menu"}, {-1, ""} }; if (bman.gamename[0] == 0) sprintf (bman.gamename, "%s's Game", bman.playername); while (menuselect != -1 && bman.state != GS_quit) { menuselect = menu_loop ("Multiplayer", menu, menuselect); switch (menuselect) { case (0): // Join a Game networkmenu_joingame (); break; case (1): // Create a new Game bman.sock = -1; bman.gametype = GT_multi; bman.multitype = MT_ptpm; host_multiplayer_game (); break; case (2): // Options networkmenu_options (); break; case (3): menuselect = -1; break; } } } void networkmenu_options () { int menuselect = 0; char text[255]; _menu menu[] = { {1, "Game Name:"}, {1, "Max Players:"}, {2, "Network"}, {3, "UDP Port"}, {4, "Behind a Firewall"}, {5, "Notify Masterserver"}, {6, "Masterserver"}, {7, "Broadcastes Chat"}, {8, "Return To Multiplayer Menu"}, {-1, ""} }; #ifdef _WIN32 menu[2].index=0; #endif while (menuselect != -1 && bman.state != GS_quit) { sprintf (menu[0].text, "Gamename: %s", bman.gamename); sprintf (menu[1].text, "Max Players: %d/%d", bman.maxplayer, MAX_PLAYERS); if (bman.net_ai_family == PF_INET) sprintf (menu[2].text, "Network: IPv4"); else sprintf (menu[2].text, "Network: IPv6"); sprintf (menu[3].text, "UDP Port: %s", bman.port); if (bman.firewall) sprintf (menu[4].text, "Firewall: ON"); else sprintf (menu[4].text, "Firewall: OFF"); if (bman.notifygamemaster) sprintf (menu[5].text, "Notify MasterServer: Yes"); else sprintf (menu[5].text, "Notify MasterServer: No"); if (bman.notifygamemaster) { sprintf (menu[6].text, "MasterServer %s", bman.gamemaster); menu[6].index = 6; } else menu[6].text[0] = menu[6].index = 0; if (bman.broadcasted_chat && bman.notifygamemaster) { sprintf (menu[7].text, "Broadcasted Chat: ON"); menu[7].index = 7; } else if (bman.notifygamemaster) { sprintf (menu[7].text, "Broadcasted Chat: OFF"); menu[7].index = 7; } else menu[7].index = menu[7].text[0] = 0; menuselect = menu_loop ("Multiplayer Options", menu, menuselect); switch (menuselect) { case (0): // change the game name menu_get_text ("Name of the Game:", bman.gamename, 32); break; case (1): // Max Number of Players sprintf (text, "%d", bman.maxplayer); menu_get_text ("Max Players", text, 2); bman.maxplayer = atoi (text); if (bman.maxplayer > MAX_PLAYERS) bman.maxplayer = MAX_PLAYERS; if (bman.maxplayer < 2) bman.maxplayer = 2; break; case (2): #ifndef _WIN32 if (bman.net_ai_family == PF_INET) bman.net_ai_family = PF_INET6; else bman.net_ai_family = PF_INET; #endif break; case (3): // UDP Port menu_get_text ("UDP Port", bman.port, LEN_PORT + 1); break; case (4): // Firewall Option bman.firewall = 1 - bman.firewall ; break; case (5): // Change the Notification bman.notifygamemaster = 1 - bman.notifygamemaster; break; case (6): // Masterserver Address menu_get_text ("Address of the MasterServer", bman.gamemaster, LEN_SERVERNAME + LEN_PORT + 2); break; case (7): bman.broadcasted_chat = 1 - bman.broadcasted_chat; break; case (8): menuselect = -1; break; } } }; void multiplayer_firstrun () { int i; /* reset some gamedata */ bman.p_nr = -1; bman.state = GS_wait; for (i = 0; i < MAX_PLAYERS; i++) { bman.players[i].name[0] = 0; bman.players[i].gfx_nr = -1; bman.players[i].gfx = NULL; } /* init the network */ if (network_init () < 0) { d_printf ("network_init () FAILED\n"); return; } }; /* We will host a network game */ void host_multiplayer_game () { if (bman.firewall) { menu_displaymessage ("Firewall Option", "You can't start a game with Firewall enabled."); return; } multiplayer_firstrun (); while (bman.state != GS_startup && bman.state != GS_quit) { /* check players and in_pl lists */ wait_for_players (); if (bman.p_nr != -1) { bman.state = GS_update; net_new_game (); init_map_tileset(); net_send_servermode (); game_start (); net_new_gamedata (); if (bman.state == GS_ready || bman.state == GS_running) { net_send_servermode (); game_loop (); if (bman.state == GS_running) bman.state = GS_wait; bman.lastwinner = -1; game_end (); net_send_servermode (); net_send_players (); } } } network_shutdown (); }; /* We will join a network game */ void join_multiplayer_game () { multiplayer_firstrun (); while (bman.state != GS_startup && bman.state != GS_quit) { wait_for_players (); if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) { game_start (); bman.state = GS_update; net_new_game (); net_new_gamedata (); if (bman.state == GS_ready || bman.state == GS_running) game_loop (); } else bman.state = GS_startup; } network_shutdown (); };