From 07a19fe8cd145feec360d1caf7edf0c0291f4411 Mon Sep 17 00:00:00 2001
From: in1tiate <radwoodward@vikings.grayson.edu>
Date: Thu, 11 Mar 2021 04:52:54 -0600
Subject: [PATCH] don't allow for locked areas with no cm

---
 src/aoclient.cpp | 7 +++++++
 src/commands.cpp | 7 ++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/aoclient.cpp b/src/aoclient.cpp
index 984999a..71ffe0a 100644
--- a/src/aoclient.cpp
+++ b/src/aoclient.cpp
@@ -68,10 +68,17 @@ void AOClient::clientDisconnected()
             false;
         server->updateCharsTaken(server->areas[current_area]);
     }
+    bool update_locks;
     for (AreaData* area : server->areas) {
         area->owners.removeAll(id);
         area->invited.removeAll(id);
+        if (area->owners.isEmpty() && area->locked != AreaData::FREE) {
+            area->locked = AreaData::FREE;
+            update_locks = true;
+        }
     }
+    if (update_locks)
+        arup(ARUPType::LOCKED, true);
     arup(ARUPType::CM, true);
 }
 
diff --git a/src/commands.cpp b/src/commands.cpp
index f29f88b..f347a85 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -504,8 +504,13 @@ void AOClient::cmdUnCM(int argc, QStringList argv)
     area->invited.removeAll(id);
     sendServerMessage("You are no longer CM in this area.");
     arup(ARUPType::CM, true);
-    if (area->owners.isEmpty())
+    if (area->owners.isEmpty()) {
         area->invited.clear();
+        if (area->locked != AreaData::FREE) {
+            area->locked = AreaData::FREE;
+            arup(ARUPType::LOCKED, true);
+        }
+    }
 }
 
 void AOClient::cmdInvite(int argc, QStringList argv)