From 18281ae4011b57dfd9a9e257861ebdbefa5368cf Mon Sep 17 00:00:00 2001
From: Salanto <62221668+Salanto@users.noreply.github.com>
Date: Sun, 19 Sep 2021 17:00:14 +0200
Subject: [PATCH] Implement clearcm command

---
 bin/config_sample/text/commandhelp.json |  7 ++++++-
 core/include/aoclient.h                 | 12 +++++++++++-
 core/src/commands/moderation.cpp        | 13 +++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/bin/config_sample/text/commandhelp.json b/bin/config_sample/text/commandhelp.json
index 4ea9940..1838537 100644
--- a/bin/config_sample/text/commandhelp.json
+++ b/bin/config_sample/text/commandhelp.json
@@ -628,5 +628,10 @@
       "name":"help",
       "usage":"/help <Command>",
       "text":"Shows you information about a command, if available. The only argument is the command name. About Syntax : <Argument> are mandatory arguments. 'Argument' are optional arguments. [Argument|OtherArgument] is that two argument types are valid, but only one can be used."
-   }
+   },
+   {
+      "name":"clearcm",
+      "usage":"/clearcm",
+      "text":"Removes all CMs from the current area. This command takes no arguments."
+   },
 ]
\ No newline at end of file
diff --git a/core/include/aoclient.h b/core/include/aoclient.h
index 758fed5..31ee401 100644
--- a/core/include/aoclient.h
+++ b/core/include/aoclient.h
@@ -1265,6 +1265,15 @@ class AOClient : public QObject {
      */
     void cmdNoticeGlobal(int argc, QStringList argv);
 
+    /**
+     * @brief Removes all CMs from the current area.
+     *
+     * @details This command is a bandaid fix to the issue that clients may end up ghosting when improperly disconnected from the server.
+     *
+     * @iscommand
+     */
+    void cmdClearCM(int argc, QStringList argv);
+
     ///@}
 
     /**
@@ -2145,7 +2154,8 @@ class AOClient : public QObject {
         {"notice",             {ACLFlags.value("SEND_NOTICE"),  1, &AOClient::cmdNotice}},
         {"noticeg",            {ACLFlags.value("SEND_NOTICE"),  1, &AOClient::cmdNoticeGlobal}},
         {"togglejukebox",      {ACLFlags.value("None"),         0, &AOClient::cmdToggleJukebox}},
-        {"help",               {ACLFlags.value("NONE"),         1, &AOClient::cmdHelp}}
+        {"help",               {ACLFlags.value("NONE"),         1, &AOClient::cmdHelp}},
+        {"clearcm",            {ACLFlags.value("KICK"),         0, &AOClient::cmdClearCM}}
     };
 
     /**
diff --git a/core/src/commands/moderation.cpp b/core/src/commands/moderation.cpp
index 523dee2..bbd4bb4 100644
--- a/core/src/commands/moderation.cpp
+++ b/core/src/commands/moderation.cpp
@@ -592,3 +592,16 @@ void AOClient::cmdNoticeGlobal(int argc, QStringList argv)
 
     sendNotice(argv.join(" "), true);
 }
+
+void AOClient::cmdClearCM(int argc, QStringList argv)
+{
+    Q_UNUSED(argc);
+    Q_UNUSED(argv);
+
+    AreaData* l_area = server->m_areas.value(m_current_area);
+    foreach (int l_client_id,l_area->owners()) {
+        l_area->removeOwner(l_client_id);
+    }
+    arup(ARUPType::CM, true);
+    sendServerMessage("Removed all CMs from this area.");
+}