From 269016cb010757a52e728279efcbac2e5efe4027 Mon Sep 17 00:00:00 2001 From: jsalmon3 <> Date: Mon, 17 Feb 2003 18:09:44 +0000 Subject: [PATCH] Fix for replays and players that quit --- src/action/command.cpp | 29 +++++++++++++++++++++++++++++ src/include/actions.h | 2 ++ src/network/commands.cpp | 2 ++ src/network/network.cpp | 21 ++------------------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/action/command.cpp b/src/action/command.cpp index 7b85dd79a..6248f1322 100644 --- a/src/action/command.cpp +++ b/src/action/command.cpp @@ -130,6 +130,35 @@ local void ClearSavedAction(Unit* unit) -- Commands ----------------------------------------------------------------------------*/ +/** +** Player quit. +** +** @param player Player number that quit. +*/ +global void CommandQuit(int player) +{ + int i; + + if (Players[player].TotalNumUnits != 0) { + // Set player to neutral, remove allied/enemy/shared vision status + Players[player].Type = PlayerNeutral; + for (i = 0; i < NumPlayers; ++i) { + if (i == player) { + continue; + } + Players[i].Allied &= ~(1 << player); + Players[i].Enemy &= ~(1 << player); + Players[i].SharedVision &= ~(1 << player); + Players[player].Allied &= ~(1 << i); + Players[player].Enemy &= ~(1 << i); + Players[player].SharedVision &= ~(1 << i); + } + SetMessage("Player \"%s\" has left the game", Players[player].Name); + } else { + SetMessage("Player \"%s\" has been killed", Players[player].Name); + } +} + /** ** Stop unit. ** diff --git a/src/include/actions.h b/src/include/actions.h index 650ee55b3..aea4433fb 100644 --- a/src/include/actions.h +++ b/src/include/actions.h @@ -69,6 +69,8 @@ extern int BurnBuildingDamageRate; /// HP per second to damage buildings ** by the user the function with Send prefix should be used. */ + /// Prepare command quit +extern void CommandQuit(int player); /// Prepare command stop extern void CommandStopUnit(Unit* unit); /// Prepare command stand ground diff --git a/src/network/commands.cpp b/src/network/commands.cpp index 3e0e3cb70..4fdbf217d 100644 --- a/src/network/commands.cpp +++ b/src/network/commands.cpp @@ -598,6 +598,8 @@ local void DoNextReplay(void) } else { HandleCheats(val); } + } else if( !strcmp(name,"quit") ) { + CommandQuit(posx); } else { DebugLevel0Fn("Invalid name: %s" _C_ name); } diff --git a/src/network/network.cpp b/src/network/network.cpp index 21d6df97f..d23b57d9c 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -620,25 +620,6 @@ local void NetworkRemovePlayer(int player) { int i; - if (Players[player].TotalNumUnits != 0) { - // Set player to neutral, remove allied/enemy/shared vision status - Players[player].Type = PlayerNeutral; - for (i = 0; i < NumPlayers; ++i) { - if (i == player) { - continue; - } - Players[i].Allied &= ~(1 << player); - Players[i].Enemy &= ~(1 << player); - Players[i].SharedVision &= ~(1 << player); - Players[player].Allied &= ~(1 << i); - Players[player].Enemy &= ~(1 << i); - Players[player].SharedVision &= ~(1 << i); - } - SetMessage("Player \"%s\" has left the game", Players[player].Name); - } else { - SetMessage("Player \"%s\" has been killed", Players[player].Name); - } - // Remove player from Hosts and clear NetworkIn for (i = 0; i < HostsCount; ++i) { if (Hosts[i].PlyNr == player) { @@ -942,6 +923,8 @@ local void ParseNetworkCommand(const NetworkCommandQueue *ncq) break; case MessageQuit: NetworkRemovePlayer(ncq->Data.X); + CommandLog("quit",NoUnitP,FlushCommands,ncq->Data.X,-1,NoUnitP,NULL,-1); + CommandQuit(ncq->Data.X); break; case MessageExtendedCommand: { const NetworkExtendedCommand *nec;