- refactored the exit calls out of the networking code
These ones were particularly bad examples of misusing the exit handlers by temporarily installing one themselves and then calling exit to clean stuff up. Now they just return an error code to D_DoomMain to perform a regular exit.
This commit is contained in:
parent
96006eb94f
commit
0a611e1992
4 changed files with 35 additions and 28 deletions
|
|
@ -652,7 +652,7 @@ bool Host_SendAllHere (void *userdata)
|
|||
return gotack[MAXNETNODES] == doomcom.numnodes - 1;
|
||||
}
|
||||
|
||||
void HostGame (int i)
|
||||
bool HostGame (int i)
|
||||
{
|
||||
PreGamePacket packet;
|
||||
int numplayers;
|
||||
|
|
@ -667,7 +667,6 @@ void HostGame (int i)
|
|||
if (numplayers > MAXNETNODES)
|
||||
{
|
||||
I_FatalError("You cannot host a game with %d players. The limit is currently %d.", numplayers, MAXNETNODES);
|
||||
return;
|
||||
}
|
||||
|
||||
if (numplayers == 1)
|
||||
|
|
@ -677,7 +676,7 @@ void HostGame (int i)
|
|||
doomcom.id = DOOMCOM_ID;
|
||||
doomcom.numplayers = doomcom.numnodes = 1;
|
||||
doomcom.consoleplayer = 0;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
StartNetwork (false);
|
||||
|
|
@ -689,14 +688,13 @@ void HostGame (int i)
|
|||
|
||||
doomcom.numnodes = 1;
|
||||
|
||||
atterm(SendAbort);
|
||||
|
||||
StartScreen->NetInit ("Waiting for players", numplayers);
|
||||
|
||||
// Wait for numplayers-1 different connections
|
||||
if (!StartScreen->NetLoop (Host_CheckForConnects, (void *)(intptr_t)numplayers))
|
||||
{
|
||||
exit(0);
|
||||
SendAbort();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now inform everyone of all machines involved in the game
|
||||
|
|
@ -706,11 +704,10 @@ void HostGame (int i)
|
|||
|
||||
if (!StartScreen->NetLoop (Host_SendAllHere, (void *)gotack))
|
||||
{
|
||||
exit(0);
|
||||
SendAbort();
|
||||
return false;
|
||||
}
|
||||
|
||||
popterm ();
|
||||
|
||||
// Now go
|
||||
StartScreen->NetMessage ("Go");
|
||||
packet.Fake = PRE_FAKE;
|
||||
|
|
@ -735,6 +732,7 @@ void HostGame (int i)
|
|||
{
|
||||
sendplayer[i] = i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// This routine is used by a guest to notify the host of its presence.
|
||||
|
|
@ -844,7 +842,7 @@ bool Guest_WaitForOthers (void *userdata)
|
|||
return false;
|
||||
}
|
||||
|
||||
void JoinGame (int i)
|
||||
bool JoinGame (int i)
|
||||
{
|
||||
if ((i == Args->NumArgs() - 1) ||
|
||||
(Args->GetArg(i+1)[0] == '-') ||
|
||||
|
|
@ -858,28 +856,28 @@ void JoinGame (int i)
|
|||
sendplayer[1] = 0;
|
||||
doomcom.numnodes = 2;
|
||||
|
||||
atterm(SendAbort);
|
||||
|
||||
// Let host know we are here
|
||||
StartScreen->NetInit ("Contacting host", 0);
|
||||
|
||||
if (!StartScreen->NetLoop (Guest_ContactHost, NULL))
|
||||
{
|
||||
exit(0);
|
||||
SendAbort();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait for everyone else to connect
|
||||
if (!StartScreen->NetLoop (Guest_WaitForOthers, 0))
|
||||
{
|
||||
exit(0);
|
||||
SendAbort();
|
||||
return false;
|
||||
}
|
||||
|
||||
popterm ();
|
||||
|
||||
|
||||
StartScreen->NetMessage ("Total players: %d", doomcom.numnodes);
|
||||
|
||||
doomcom.id = DOOMCOM_ID;
|
||||
doomcom.numplayers = doomcom.numnodes;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int PrivateNetOf(in_addr in)
|
||||
|
|
@ -939,7 +937,7 @@ static bool NodesOnSameNetwork()
|
|||
//
|
||||
// Returns true if packet server mode might be a good idea.
|
||||
//
|
||||
bool I_InitNetwork (void)
|
||||
int I_InitNetwork (void)
|
||||
{
|
||||
int i;
|
||||
const char *v;
|
||||
|
|
@ -969,11 +967,11 @@ bool I_InitNetwork (void)
|
|||
// player x: -join <player 1's address>
|
||||
if ( (i = Args->CheckParm ("-host")) )
|
||||
{
|
||||
HostGame (i);
|
||||
if (!HostGame (i)) return -1;
|
||||
}
|
||||
else if ( (i = Args->CheckParm ("-join")) )
|
||||
{
|
||||
JoinGame (i);
|
||||
if (!JoinGame (i)) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue