From cac600733f8383c521e78555e79d25c2042de20e Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Mon, 10 Aug 2015 20:45:18 -0500 Subject: [PATCH] - Added Remove console command. --- src/d_net.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ src/d_protocol.h | 1 + src/p_interaction.cpp | 19 +++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/src/d_net.cpp b/src/d_net.cpp index bc5ccdba9..66b8c5dc3 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2082,6 +2082,33 @@ static int KillAll(const PClass *cls) } return killcount; +} + +static int RemoveClass(const PClass *cls) +{ + AActor *actor; + int removecount = 0; + bool player = false; + TThinkerIterator iterator(cls); + while ((actor = iterator.Next())) + { + if (actor->IsA(cls)) + { + // [MC]Do not remove LIVE players. + if (actor->IsKindOf(RUNTIME_CLASS(APlayerPawn)) && actor->player != NULL) + { + player = true; + continue; + } + removecount++; + actor->ClearCounters(); + actor->Destroy(); + } + } + if (player) + Printf("Cannot remove live players!\n"); + return removecount; + } // [RH] Execute a special "ticcmd". The type byte should // have already been read, and the stream is positioned @@ -2555,6 +2582,27 @@ void Net_DoCommand (int type, BYTE **stream, int player) } break; + case DEM_REMOVE: + { + char *classname = ReadString(stream); + int removecount = 0; + const PClass *cls = PClass::FindClass(classname); + if (cls != NULL && cls->ActorInfo != NULL) + { + removecount = RemoveClass(cls); + const PClass *cls_rep = cls->GetReplacement(); + if (cls != cls_rep) + { + removecount += RemoveClass(cls_rep); + } + Printf("Removed %d actors of type %s.\n", removecount, classname); + } + else + { + Printf("%s is not an actor class.\n", classname); + } + } + break; case DEM_CONVREPLY: case DEM_CONVCLOSE: diff --git a/src/d_protocol.h b/src/d_protocol.h index 8b6e777d5..73b042470 100644 --- a/src/d_protocol.h +++ b/src/d_protocol.h @@ -164,6 +164,7 @@ enum EDemoCommand DEM_RUNNAMEDSCRIPT, // 65 String: Script name, Byte: Arg count + Always flag; each arg is a 4-byte int DEM_REVERTCAMERA, // 66 DEM_SETSLOTPNUM, // 67 Byte: player number, the rest is the same as DEM_SETSLOT + DEM_REMOVE, // 68 }; // The following are implemented by cht_DoCheat in m_cheat.cpp diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index cbbd87978..276a88c75 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -1841,3 +1841,22 @@ CCMD (kill) } C_HideConsole (); } + +CCMD(remove) +{ + if (argv.argc() == 2) + { + if (CheckCheatmode()) + return; + + Net_WriteByte(DEM_REMOVE); + Net_WriteString(argv[1]); + C_HideConsole(); + } + else + { + Printf("Usage: remove \n"); + return; + } + +} \ No newline at end of file