You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
274 lines
7.2 KiB
274 lines
7.2 KiB
/* network menu */
|
|
|
|
#include "bomberclone.h"
|
|
#include "network.h"
|
|
#include "packets.h"
|
|
#include "gfx.h"
|
|
#include "menu.h"
|
|
|
|
extern int UpdateRects_nr;
|
|
|
|
|
|
void
|
|
netmenu ()
|
|
{
|
|
int menuselect = 0;
|
|
|
|
if (bman.gamename[0] == 0)
|
|
sprintf (bman.gamename, "%s's Game", bman.playername);
|
|
|
|
while (menuselect != -1 && bman.state != GS_quit) {
|
|
menu_new ("Multiplayer", 250, 200);
|
|
menu_create_button ("Host a Game", -1, 70, 200, 0);
|
|
menu_create_button ("Join a Game", -1, 110, 200, 1);
|
|
menu_create_button ("Network Options", -1, 150, 200, 2);
|
|
menuselect = menu_loop ();
|
|
menu_delete ();
|
|
|
|
switch (menuselect) {
|
|
case (0): // Create a Game
|
|
bman.sock = -1;
|
|
host_multiplayer_game ();
|
|
break;
|
|
case (1): // Join a Game
|
|
join_multiplayer_game ();
|
|
break;
|
|
case (2): // Options
|
|
network_options ();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
network_options ()
|
|
{
|
|
int menuselect = 0, done = 0, net_ai_typ, i;
|
|
_charlist nrplayerlist[MAX_PLAYERS];
|
|
_charlist *selnrplayer = &nrplayerlist[bman.maxplayer-1];
|
|
|
|
/* fill in the nrplayerlist */
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
sprintf (nrplayerlist[i].text, "%d", (i+1));
|
|
if (i < MAX_PLAYERS-1)
|
|
nrplayerlist[i].next = &nrplayerlist[i+1];
|
|
else
|
|
nrplayerlist[i].next = NULL;
|
|
}
|
|
|
|
while (menuselect != -1 && !done && bman.state != GS_quit) {
|
|
/* fill in net_ai_typ */
|
|
net_ai_typ = (PF_INET != bman.net_ai_family);
|
|
menu_new ("Network Options", 400, 380);
|
|
menu_create_label ("Number Of Players", 60, 75, 0);
|
|
menu_create_list ("Players", 270, 55, 55, 70, nrplayerlist, &selnrplayer, 1);
|
|
menu_create_entry ("Gamename", -1, 150, 300, &bman.gamename, LEN_GAMENAME, MENU_entrytext, 2);
|
|
menu_create_entry ("UDP Port:", -1, 180, 200, &bman.port, LEN_PORT, MENU_entrytext,3);
|
|
#ifndef _WIN32
|
|
menu_create_bool ("IPV6", 50, 215, 100, &net_ai_typ, 4);
|
|
#endif
|
|
menu_create_bool ("Firewall", 270, 215, 100, &bman.firewall, 5);
|
|
menu_create_bool ("Use OpenGameCache", -1, 250, 350, &bman.notifygamemaster, 6);
|
|
menu_create_entry ("OpenGameCache:", -1, 280, 350, &bman.ogcserver, LEN_SERVERNAME, MENU_entrytext, 7);
|
|
menu_create_entry ("Local OGC Port", -1, 310, 350, &bman.ogc_port, LEN_PORT, MENU_entrytext, 8);
|
|
menu_create_button ("Ok", -1, 350, 150, 0);
|
|
menuselect = menu_loop ();
|
|
bman.maxplayer = (selnrplayer - &nrplayerlist[0]) + 1;
|
|
menu_delete ();
|
|
|
|
/* fix net_ai_typ */
|
|
#ifndef _WIN32 // fix for windows i don't know how to get there ipv6 mode.
|
|
if (net_ai_typ)
|
|
bman.net_ai_family = PF_INET6;
|
|
else
|
|
#endif
|
|
bman.net_ai_family = PF_INET;
|
|
|
|
switch (menuselect) {
|
|
case (0): // all options made Save Config
|
|
done = 1;
|
|
config_write ();
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
void
|
|
multiplayer_firstrun ()
|
|
{
|
|
int i;
|
|
/*
|
|
reset some gamedata
|
|
*/
|
|
bman.p_nr = -1;
|
|
bman.state = GS_wait;
|
|
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
players[i].net.addr.host[0] = 0;
|
|
players[i].net.addr.port[0] = 0;
|
|
players[i].name[0] = 0;
|
|
players[i].gfx_nr = -1;
|
|
players[i].gfx = NULL;
|
|
players[i].net.timestamp = timestamp;
|
|
players[i].points = 0;
|
|
players[i].wins = 0;
|
|
players[i].net.pingreq = 20;
|
|
players[i].net.pingack = 22;
|
|
players[i].state = 0;
|
|
}
|
|
|
|
bman.lastwinner = -1;
|
|
bman.players_nr_s = 1;
|
|
};
|
|
|
|
|
|
/*
|
|
* We will host a network game
|
|
*/
|
|
void host_multiplayer_game () {
|
|
if (bman.firewall) {
|
|
menu_displaymessage("Error", NULL, "You can not start a network game", "with the firewall option on.", NULL);
|
|
return;
|
|
}
|
|
multiplayer_firstrun ();
|
|
|
|
if (network_init () < 0) {
|
|
d_printf ("network_init () FAILED\n");
|
|
return;
|
|
}
|
|
|
|
/* prepare the server */
|
|
strncpy (players[0].name, bman.playername, LEN_PLAYERNAME);
|
|
bman.p_nr = bman.p_servnr = 0;
|
|
players[0].state = PSF_used;
|
|
if (bman.notifygamemaster)
|
|
send_ogc_update (); /* send the information that we started an server */
|
|
|
|
multiplayer_game ();
|
|
net_send_servermode ();
|
|
network_shutdown ();
|
|
};
|
|
|
|
|
|
/* the loop for the multiplayer games */
|
|
void multiplayer_game () {
|
|
|
|
while (bman.state != GS_startup && bman.state != GS_quit) {
|
|
/* check players and in_pl lists */
|
|
wait_for_players ();
|
|
|
|
if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) {
|
|
net_new_game ();
|
|
game_start ();
|
|
if (GT_MP_PTPM) {
|
|
bman.state = GS_update;
|
|
net_send_mapinfo (); // maybe we have to make a break
|
|
net_send_servermode (); // between mapinfo and servermode
|
|
}
|
|
net_transmit_gamedata ();
|
|
|
|
if (bman.state == GS_ready || bman.state == GS_running) {
|
|
if (GT_MP_PTPM)
|
|
net_send_servermode ();
|
|
|
|
game_loop ();
|
|
if (bman.state == GS_running)
|
|
bman.state = GS_wait;
|
|
|
|
bman.lastwinner = -1;
|
|
game_end ();
|
|
|
|
if (GT_MP_PTPM) {
|
|
net_send_servermode ();
|
|
net_send_players ();
|
|
}
|
|
}
|
|
else
|
|
game_end ();
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
/* We will join a network game */
|
|
void
|
|
join_multiplayer_game ()
|
|
{
|
|
int i, old_ai_family;
|
|
|
|
old_ai_family = bman.net_ai_family;
|
|
|
|
multiplayer_firstrun ();
|
|
if (network_init () < 0) {
|
|
d_printf ("network_init () FAILED\n");
|
|
return;
|
|
}
|
|
|
|
net_getserver (); /* show Serverlist */
|
|
|
|
/* if the AI Family Changed, restart the whole network */
|
|
if (old_ai_family != bman.net_ai_family) {
|
|
network_shutdown ();
|
|
if (network_init () < 0) {
|
|
d_printf ("network_init () FAILED\n");
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (bman.servername[0] != 0) {
|
|
/* join the server, convert to a usable sockaddr first */
|
|
network_server_port (bman.servername, players[0].net.addr.host,
|
|
LEN_SERVERNAME, players[0].net.addr.port, LEN_PORT);
|
|
|
|
d_printf ("Connect To: %s[:%s]\n", players[0].net.addr.host,
|
|
players[0].net.addr.port);
|
|
|
|
dns_filladdr (players[0].net.addr.host, LEN_SERVERNAME, players[0].net.addr.port,
|
|
LEN_PORT, bman.net_ai_family, &players[0].net.addr.sAddr);
|
|
players[0].net.addr.port[0] = players[0].net.addr.host[0] = 0;
|
|
dns_filladdr (players[0].net.addr.host, LEN_SERVERNAME, players[0].net.addr.port,
|
|
LEN_PORT, bman.net_ai_family, &players[0].net.addr.sAddr);
|
|
|
|
/* and join the server */
|
|
if (bman.firewall)
|
|
i = NETF_firewall;
|
|
else
|
|
i = 0;
|
|
|
|
bman.p_nr = -1;
|
|
send_joingame (&players[0].net.addr, bman.playername);
|
|
|
|
/* go into the normal multiplayer loop */
|
|
multiplayer_game ();
|
|
}
|
|
|
|
network_shutdown ();
|
|
};
|
|
|
|
|
|
/* Network Help Screen */
|
|
void network_helpscreen () {
|
|
menu_new ("Network Help Screen", 400, 380);
|
|
menu_create_label ("F1", 60, 50, 1);
|
|
menu_create_label ("Display this Helpscreen", 180, 54, 0);
|
|
|
|
menu_create_label ("F2", 60, 80, 1);
|
|
menu_create_label ("Change/Show Mapsettings", 180, 84, 0);
|
|
|
|
menu_create_label ("F3", 60, 110, 1);
|
|
menu_create_label ("Add one AI Player", 180, 114, 0);
|
|
|
|
menu_create_label ("Shift-F3", 10, 140, 1);
|
|
menu_create_label ("Delete one AI P.", 180, 144, 0);
|
|
|
|
menu_create_label ("F4", 60, 170, 1);
|
|
menu_create_label ("Start the Game", 180, 174, 0);
|
|
|
|
menu_loop ();
|
|
menu_delete ();
|
|
};
|