From 289eb1b62e2ae3cd1de5c815a670af7cf0b9660e Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 20 Feb 2016 11:22:24 +0100
Subject: [PATCH] Server: Transform PLUGIN command to God command, save its
 input.

---
 SERVER_COMMANDS             | 8 ++++----
 server/commands.py          | 1 +
 server/config/commands.py   | 2 +-
 server/config/world_data.py | 1 +
 server/io.py                | 5 ++++-
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/SERVER_COMMANDS b/SERVER_COMMANDS
index e959f25..41759aa 100644
--- a/SERVER_COMMANDS
+++ b/SERVER_COMMANDS
@@ -52,10 +52,6 @@ game world is set active.
 Meta commands
 -------------
 
-PLUGIN [string]
-Run plugin code in ./plugins/[argument], with argument only consisting of
-alphanumeric characters and underscores.
-
 PING
 Write "PONG" line to ./server_run/out file.
 
@@ -95,6 +91,10 @@ inventory.
 God commands
 ------------
 
+PLUGIN [string]
+Run plugin code in ./plugins/[argument], with argument only consisting of
+alphanumeric characters and underscores.
+
 TURN [0 to 65535]
 Set world turn to argument. (Initial value: 0.)
 
diff --git a/server/commands.py b/server/commands.py
index a3b68bc..a1f97c9 100644
--- a/server/commands.py
+++ b/server/commands.py
@@ -17,6 +17,7 @@ def command_plugin(str_plugin):
     if (str_plugin.replace("_", "").isalnum()
         and os.access("plugins/server/" + str_plugin, os.F_OK)):
         exec(open("plugins/server/" + str_plugin).read())
+        world_db["PLUGIN"] += [str_plugin]
         return
     print("Bad plugin name:", str_plugin)
 
diff --git a/server/config/commands.py b/server/config/commands.py
index 84ac8e2..96c31cc 100644
--- a/server/config/commands.py
+++ b/server/config/commands.py
@@ -20,7 +20,7 @@ be ignored in replay mode if read from server input file), and ([2]) a function
 to be called on it.
 """
 commands_db = {
-    "PLUGIN": (1, True, command_plugin),
+    "PLUGIN": (1, False, command_plugin),
     "QUIT": (0, True, command_quit),
     "PING": (0, True, command_ping),
     "THINGS_HERE": (2, True, command_thingshere),
diff --git a/server/config/world_data.py b/server/config/world_data.py
index e9c6bac..e8639c5 100644
--- a/server/config/world_data.py
+++ b/server/config/world_data.py
@@ -10,6 +10,7 @@ world_db = {
     "PLAYER_TYPE": 0,
     "WORLD_ACTIVE": 0,
     "MAP": False,
+    "PLUGIN": [],
     "ThingActions": {},
     "ThingTypes": {},
     "Things": {}
diff --git a/server/io.py b/server/io.py
index 0357b2e..ab3bbff 100644
--- a/server/io.py
+++ b/server/io.py
@@ -180,9 +180,12 @@ def save_world():
 
     string = ""
     for key in sorted(world_db.keys()):
-        if (not isinstance(world_db[key], dict)) and key != "MAP" and \
+        if (not isinstance(world_db[key], dict) and
+            not isinstance(world_db[key], list)) and key != "MAP" and \
            key != "WORLD_ACTIVE":
             string = string + key + " " + str(world_db[key]) + "\n"
+    for plugin in world_db["PLUGIN"]:
+        string = string + "PLUGIN " + plugin + "\n"
     string = string + mapsetter("MAP")()
     string = string + helper("ThingActions", "TA_ID")
     string = string + helper("ThingTypes", "TT_ID", {"TT_CORPSE_ID": False})
-- 
2.30.2