Skip to content
Permalink
Browse files

- 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.
  • Loading branch information...
coelckers committed Oct 6, 2019
1 parent 96006eb commit 0a611e1992cc1b2b91adb206de57bb1fda538ec0
Showing with 35 additions and 28 deletions.
  1. +8 −6 src/d_main.cpp
  2. +9 −2 src/d_net.cpp
  3. +17 −19 src/i_net.cpp
  4. +1 −1 src/i_net.h
@@ -127,7 +127,7 @@ const FIWADInfo *D_FindIWAD(TArray<FString> &wadfiles, const char *iwad, const c

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------

void D_CheckNetGame ();
bool D_CheckNetGame ();
void D_ProcessEvents ();
void G_BuildTiccmd (ticcmd_t* cmd);
void D_DoAdvanceDemo ();
@@ -2353,7 +2353,7 @@ void I_Quit()
//
//==========================================================================

static void D_DoomMain_Internal (void)
static int D_DoomMain_Internal (void)
{
int p;
const char *v;
@@ -2710,7 +2710,10 @@ static void D_DoomMain_Internal (void)
{
if (!batchrun) Printf ("D_CheckNetGame: Checking network game status.\n");
StartScreen->LoadingStatus ("Checking network game status.", 0x3f);
D_CheckNetGame ();
if (!D_CheckNetGame ())
{
return 0;
}
}

// [SP] Force vanilla transparency auto-detection to re-detect our game lumps now
@@ -2746,7 +2749,7 @@ static void D_DoomMain_Internal (void)

if (Args->CheckParm("-norun") || batchrun)
{
return;
return 1337; // special exit
}

V_Init2();
@@ -2842,8 +2845,7 @@ int D_DoomMain()
int ret = 0;
try
{
D_DoomMain_Internal();
ret = 1337;
ret = D_DoomMain_Internal();
}
catch (std::exception &error)
{
@@ -1653,7 +1653,7 @@ static void SendSetup (uint32_t playersdetected[MAXNETNODES], uint8_t gotsetup[M
// Works out player numbers among the net participants
//

void D_CheckNetGame (void)
bool D_CheckNetGame (void)
{
const char *v;
int i;
@@ -1674,8 +1674,13 @@ void D_CheckNetGame (void)
"\nIf the game is running well below expected speeds, use netmode 0 (P2P) instead.\n");
}

int result = I_InitNetwork ();
// I_InitNetwork sets doomcom and netgame
if (I_InitNetwork ())
if (result == -1)
{
return false;
}
else if (result > 0)
{
// For now, stop auto selecting PacketServer, as it's more likely to cause confusion.
//NetMode = NET_PacketServer;
@@ -1739,6 +1744,8 @@ void D_CheckNetGame (void)

if (!batchrun) Printf ("player %i of %i (%i nodes)\n",
consoleplayer+1, doomcom.numplayers, doomcom.numnodes);

return true;
}


@@ -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
{
@@ -2,7 +2,7 @@
#define __I_NET_H__

// Called by D_DoomMain.
bool I_InitNetwork (void);
int I_InitNetwork (void);
void I_NetCmd (void);

#endif

0 comments on commit 0a611e1

Please sign in to comment.
You can’t perform that action at this time.