/* 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[] = { {0, "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[] = { {0, "Game Name:"}, {1, "Max Players:"}, {2, "Network"}, {3, "Notify Masterserver"}, {4, "Masterserver"}, {5, "Return To Multiplayer Menu"}, {-1, ""} }; 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"); if (bman.notifygamemaster) sprintf (menu[3].text, "Notify MasterServer: Yes"); else sprintf (menu[3].text, "Notify MasterServer: No"); sprintf (menu[4].text, "MasterServer %s", bman.gamemaster); 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): // Change the Notification if (bman.notifygamemaster) bman.notifygamemaster = 0; else bman.notifygamemaster = 1; break; case (4): // Masterserver Address menu_get_text ("Address of the MasterServer", bman.gamemaster, LEN_SERVERNAME + LEN_PORT + 2); break; case (5): 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 () { 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_send_servermode (); gfx_game_init (); 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 (); } gfx_game_shutdown (); } } 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)) { gfx_game_init (); bman.state = GS_update; net_new_gamedata (); if (bman.state == GS_ready || bman.state == GS_running) game_loop (); gfx_game_shutdown (); } else bman.state = GS_startup; } network_shutdown (); };