Skip to content

Commit

Permalink
Fix clients and/or host crashing due to the last client clicking read…
Browse files Browse the repository at this point in the history
…y too many times. Based on patch by Buggy.

Throw in a few checks for changing player position or team, too.

Closes ticket:2346.

Changelog: Fixed crash for all players when the last player clicks "Ready" too many times.
  • Loading branch information
Cyp committed Nov 25, 2010
1 parent 528c9f4 commit b665e9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/netplay/netplay.c
Expand Up @@ -255,7 +255,7 @@ extern LOBBY_ERROR_TYPES LobbyError; // from src/multiint.c
** ie ("trunk", "2.1.3", ...)
************************************************************************************
**/
char VersionString[VersionStringSize] = "2.3 svn"; // used for display in the lobby, not the actual version check
char VersionString[VersionStringSize] = "2.3 git"; // used for display in the lobby, not the actual version check
static int NETCODE_VERSION_MAJOR = 2; // major netcode version, used for compatibility check
static int NETCODE_VERSION_MINOR = 95; // minor netcode version, used for compatibility check
static int NETCODE_HASH = 0; // unused for now
Expand Down
33 changes: 18 additions & 15 deletions src/multiint.c
Expand Up @@ -1558,9 +1558,9 @@ BOOL recvTeamRequest()
{
UBYTE player, team;

if(!NetPlay.isHost) // only host should act
if (!NetPlay.isHost || !bHosted) // Only host should act, and only if the game hasn't started yet.
{
ASSERT(false, "Host only routine detected for client!");
ASSERT(NetPlay.isHost, "Host only routine detected for client!");
return true;
}

Expand Down Expand Up @@ -1614,9 +1614,9 @@ BOOL recvReadyRequest()
UBYTE player;
BOOL bReady;

if(!NetPlay.isHost) // only host should act
if (!NetPlay.isHost || !bHosted) // Only host should act, and only if the game hasn't started yet.
{
ASSERT(false, "Host only routine detected for client!");
ASSERT(NetPlay.isHost, "Host only routine detected for client!");
return true;
}

Expand Down Expand Up @@ -1760,9 +1760,9 @@ BOOL recvColourRequest()
{
UBYTE player, col;

if(!NetPlay.isHost) // only host should act
if (!NetPlay.isHost || !bHosted) // Only host should act, and only if the game hasn't started yet.
{
ASSERT(false, "Host only routine detected for client!");
ASSERT(NetPlay.isHost, "Host only routine detected for client!");
return true;
}

Expand Down Expand Up @@ -1793,9 +1793,9 @@ BOOL recvPositionRequest()
{
UBYTE player, position;

if(!NetPlay.isHost) // only host should act
if (!NetPlay.isHost || !bHosted) // Only host should act, and only if the game hasn't started yet.
{
ASSERT(false, "Host only routine detected for client!");
ASSERT(NetPlay.isHost, "Host only routine detected for client!");
return true;
}

Expand Down Expand Up @@ -2820,6 +2820,11 @@ static void processMultiopWidgets(UDWORD id)
/* Start a multiplayer or skirmish game */
void startMultiplayerGame(void)
{
if (!bHosted)
{
debug(LOG_ERROR, "Multiple start requests received when we already started.");
return;
}
decideWRF(); // set up swrf & game.map
bMultiPlayer = true;
bMultiMessages = true;
Expand Down Expand Up @@ -2975,14 +2980,12 @@ void frontendMultiMessages(void)
break;

case NET_READY_REQUEST:
if (NetPlay.isHost)
recvReadyRequest();

// If hosting and game not yet started, try to start the game if everyone is ready.
if (NetPlay.isHost && bHosted && multiplayPlayersReady(false))
{
recvReadyRequest();
if (multiplayPlayersReady(false))
{
// if hosting try to start the game if everyone is ready
startMultiplayerGame();
}
startMultiplayerGame();
}
break;

Expand Down

0 comments on commit b665e9d

Please sign in to comment.