[CSM] Client side modding
authorLoic Blot <loic.blot@unix-experience.fr>
Sat, 21 Jan 2017 14:02:08 +0000 (15:02 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Mon, 13 Mar 2017 22:56:05 +0000 (23:56 +0100)
* rename GameScripting to ServerScripting
* Make getBuiltinLuaPath static serverside
* Add on_shutdown callback
* Add on_receiving_chat_message & on_sending_chat_message callbacks
* ScriptApiBase: use IGameDef instead of Server
  This permits to share common attribute between client & server
* Enable mod security in client side modding without conditions

39 files changed:
builtin/client/init.lua [new file with mode: 0644]
builtin/client/register.lua [new file with mode: 0644]
builtin/init.lua
src/client.cpp
src/client.h
src/content_abm.cpp
src/content_sao.cpp
src/emerge.cpp
src/environment.cpp
src/game.cpp
src/gamedef.h
src/guiFormSpecMenu.cpp
src/inventorymanager.cpp
src/network/clientpackethandler.cpp
src/network/serverpackethandler.cpp
src/script/CMakeLists.txt
src/script/clientscripting.cpp [new file with mode: 0644]
src/script/clientscripting.h [new file with mode: 0644]
src/script/cpp_api/CMakeLists.txt
src/script/cpp_api/s_base.cpp
src/script/cpp_api/s_base.h
src/script/cpp_api/s_client.cpp [new file with mode: 0644]
src/script/cpp_api/s_client.h [new file with mode: 0644]
src/script/cpp_api/s_security.cpp
src/script/lua_api/CMakeLists.txt
src/script/lua_api/l_client.cpp [new file with mode: 0644]
src/script/lua_api/l_client.h [new file with mode: 0644]
src/script/lua_api/l_env.cpp
src/script/lua_api/l_env.h
src/script/lua_api/l_object.cpp
src/script/scripting_game.cpp [deleted file]
src/script/scripting_game.h [deleted file]
src/script/serverscripting.cpp [new file with mode: 0644]
src/script/serverscripting.h [new file with mode: 0644]
src/server.cpp
src/server.h
src/serverenvironment.cpp
src/serverenvironment.h
src/unittest/test.cpp

diff --git a/builtin/client/init.lua b/builtin/client/init.lua
new file mode 100644 (file)
index 0000000..d14301a
--- /dev/null
@@ -0,0 +1,22 @@
+-- Minetest: builtin/client/init.lua
+local scriptpath = core.get_builtin_path()..DIR_DELIM
+local clientpath = scriptpath.."client"..DIR_DELIM
+
+dofile(clientpath .. "register.lua")
+
+-- This is an example function to ensure it's working properly, should be removed before merge
+core.register_on_shutdown(function()
+       print("shutdown client")
+end)
+
+-- This is an example function to ensure it's working properly, should be removed before merge
+core.register_on_receiving_chat_messages(function(message)
+       print("Received message " .. message)
+       return false
+end)
+
+-- This is an example function to ensure it's working properly, should be removed before merge
+core.register_on_sending_chat_messages(function(message)
+       print("Sending message " .. message)
+       return false
+end)
diff --git a/builtin/client/register.lua b/builtin/client/register.lua
new file mode 100644 (file)
index 0000000..c793195
--- /dev/null
@@ -0,0 +1,62 @@
+
+core.callback_origins = {}
+
+function core.run_callbacks(callbacks, mode, ...)
+       assert(type(callbacks) == "table")
+       local cb_len = #callbacks
+       if cb_len == 0 then
+               if mode == 2 or mode == 3 then
+                       return true
+               elseif mode == 4 or mode == 5 then
+                       return false
+               end
+       end
+       local ret
+       for i = 1, cb_len do
+               local cb_ret = callbacks[i](...)
+
+               if mode == 0 and i == 1 or mode == 1 and i == cb_len then
+                       ret = cb_ret
+               elseif mode == 2 then
+                       if not cb_ret or i == 1 then
+                               ret = cb_ret
+                       end
+               elseif mode == 3 then
+                       if cb_ret then
+                               return cb_ret
+                       end
+                       ret = cb_ret
+               elseif mode == 4 then
+                       if (cb_ret and not ret) or i == 1 then
+                               ret = cb_ret
+                       end
+               elseif mode == 5 and cb_ret then
+                       return cb_ret
+               end
+       end
+       return ret
+end
+
+--
+-- Callback registration
+--
+
+local function make_registration()
+       local t = {}
+       local registerfunc = function(func)
+               t[#t + 1] = func
+               core.callback_origins[func] = {
+                       mod = core.get_current_modname() or "??",
+                       name = debug.getinfo(1, "n").name or "??"
+               }
+               --local origin = core.callback_origins[func]
+               --print(origin.name .. ": " .. origin.mod .. " registering cbk " .. tostring(func))
+       end
+       return t, registerfunc
+end
+
+core.registered_on_shutdown, core.register_on_shutdown = make_registration()
+core.registered_on_receiving_chat_messages, core.register_on_receiving_chat_messages = make_registration()
+core.registered_on_sending_chat_messages, core.register_on_sending_chat_messages = make_registration()
+
+
index b34ad14a0d647ca78c7456b0d2dfee4a928e52c4..590f7fa8cf8da804e4899a85005c2d8b276c0702 100644 (file)
@@ -27,6 +27,7 @@ minetest = core
 -- Load other files
 local scriptdir = core.get_builtin_path() .. DIR_DELIM
 local gamepath = scriptdir .. "game" .. DIR_DELIM
+local clientpath = scriptdir .. "client" .. DIR_DELIM
 local commonpath = scriptdir .. "common" .. DIR_DELIM
 local asyncpath = scriptdir .. "async" .. DIR_DELIM
 
@@ -45,6 +46,8 @@ elseif INIT == "mainmenu" then
        end
 elseif INIT == "async" then
        dofile(asyncpath .. "init.lua")
+elseif INIT == "client" then
+       dofile(clientpath .. "init.lua")
 else
        error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))
 end
index 30058a2b0b490bfc1f86560c40e4b1338a1be38c..faf454b359049ceffc87af7feba19bcf9ca588ed 100644 (file)
@@ -32,28 +32,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client.h"
 #include "network/clientopcodes.h"
 #include "filesys.h"
-#include "porting.h"
 #include "mapblock_mesh.h"
 #include "mapblock.h"
 #include "minimap.h"
-#include "settings.h"
+#include "mods.h"
 #include "profiler.h"
 #include "gettext.h"
-#include "log.h"
-#include "nodemetadata.h"
-#include "itemdef.h"
-#include "shader.h"
 #include "clientmap.h"
 #include "clientmedia.h"
-#include "sound.h"
-#include "IMeshCache.h"
-#include "config.h"
 #include "version.h"
 #include "drawscene.h"
 #include "database-sqlite3.h"
 #include "serialization.h"
 #include "guiscalingfilter.h"
-#include "raycast.h"
+#include "script/clientscripting.h"
 
 extern gui::IGUIEnvironment* guienv;
 
@@ -269,10 +261,36 @@ Client::Client(
        m_cache_use_tangent_vertices = m_cache_enable_shaders && (
                g_settings->getBool("enable_bumpmapping") ||
                g_settings->getBool("enable_parallax_occlusion"));
+
+       m_script = new ClientScripting(this);
+}
+
+void Client::initMods()
+{
+       std::string script_path = getBuiltinLuaPath() + DIR_DELIM "init.lua";
+
+       m_script->loadMod(script_path, BUILTIN_MOD_NAME);
+}
+
+const std::string Client::getBuiltinLuaPath()
+{
+       return porting::path_share + DIR_DELIM + "builtin";
+}
+
+const std::vector<ModSpec>& Client::getMods() const
+{
+       static std::vector<ModSpec> client_modspec_temp;
+       return client_modspec_temp;
+}
+
+const ModSpec* Client::getModSpec(const std::string &modname) const
+{
+       return NULL;
 }
 
 void Client::Stop()
 {
+       m_script->on_shutdown();
        //request all client managed threads to stop
        m_mesh_update_thread.stop();
        // Save local server map
@@ -280,6 +298,8 @@ void Client::Stop()
                infostream << "Local map saving ended." << std::endl;
                m_localdb->endSave();
        }
+
+       delete m_script;
 }
 
 bool Client::isShutdown()
@@ -1553,6 +1573,11 @@ void Client::typeChatMessage(const std::wstring &message)
        if(message == L"")
                return;
 
+       // If message was ate by script API, don't send it to server
+       if (m_script->on_sending_message(wide_to_utf8(message))) {
+               return;
+       }
+
        // Send to others
        sendChatMessage(message);
 
index b33358d94c5570e519ea28c4f416def3243c62e1..2fdade61a6c3317eac54a708892c3cea780abde1 100644 (file)
@@ -305,6 +305,8 @@ private:
        std::map<u16, u16> m_packets;
 };
 
+class ClientScripting;
+
 class Client : public con::PeerHandler, public InventoryManager, public IGameDef
 {
 public:
@@ -328,6 +330,8 @@ public:
 
        ~Client();
 
+       void initMods();
+
        /*
         request all threads managed by client to be stopped
         */
@@ -428,6 +432,10 @@ public:
        ClientEnvironment& getEnv() { return m_env; }
        ITextureSource *tsrc() { return getTextureSource(); }
        ISoundManager *sound() { return getSoundManager(); }
+       static const std::string getBuiltinLuaPath();
+
+       virtual const std::vector<ModSpec> &getMods() const;
+       virtual const ModSpec* getModSpec(const std::string &modname) const;
 
        // Causes urgent mesh updates (unlike Map::add/removeNodeWithEvent)
        void removeNode(v3s16 p);
@@ -692,6 +700,8 @@ private:
        bool m_cache_enable_shaders;
        bool m_cache_use_tangent_vertices;
 
+       ClientScripting *m_script;
+
        DISABLE_CLASS_COPY(Client);
 };
 
index ee444ae7794ede033a09e077c76a98cd8488b259..2ab3a968c1223707efbcb287ebc4db3d91bd7e6c 100644 (file)
@@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "mapblock.h" // For getNodeBlockPos
 #include "map.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "log.h"
 
 void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef) {
index d4a218505f21429d37ab0612bf9de92c2a5cda90..93662b035ed82a71ff044b251f2e552531380600 100644 (file)
@@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nodedef.h"
 #include "remoteplayer.h"
 #include "server.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "genericobject.h"
 
 std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
index 1c9719c4898104d4e33638d277385aa1817a452b..8719a9eb37c9d0719db9d8af789d7784c5bd3207 100644 (file)
@@ -40,7 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mg_schematic.h"
 #include "nodedef.h"
 #include "profiler.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "server.h"
 #include "serverobject.h"
 #include "settings.h"
index 8c1aad9d3274796c075bc223f40af08035b91165..737d93ecdba0c49dd6850973aa395a3681f03b11 100644 (file)
@@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "environment.h"
 #include "collision.h"
 #include "serverobject.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "server.h"
 #include "daynightratio.h"
 #include "emerge.h"
index 55b2ccec9d8d3df487ea4ed388ccadf4f5a2fe6e..9868142f7527794365e5c1cd3d17df1c8b362f95 100644 (file)
@@ -2222,6 +2222,8 @@ bool Game::connectToServer(const std::string &playername,
 
                fps_control.last_time = device->getTimer()->getTime();
 
+               client->initMods();
+
                while (device->run()) {
 
                        limitFps(&fps_control, &dtime);
index cb624bd6ac8bda7441488a7894521ddc593fd8e4..16b53e24f7b5a7e173c83b059da5b03e5df7d8ca 100644 (file)
@@ -39,6 +39,7 @@ namespace irr { namespace scene {
        class ISceneManager;
 }}
 
+struct ModSpec;
 /*
        An interface for fetching game-global definitions like tool and
        mapnode properties
@@ -68,7 +69,11 @@ public:
        ICraftDefManager *cdef()     { return getCraftDefManager(); }
 
        MtEventManager   *event()    { return getEventManager(); }
-       IRollbackManager *rollback() { return getRollbackManager();}
+       IRollbackManager *rollback() { return getRollbackManager(); }
+
+       virtual const std::vector<ModSpec> &getMods() const = 0;
+       virtual const ModSpec* getModSpec(const std::string &modname) const = 0;
+       virtual std::string getWorldPath() const { return ""; }
 };
 
 #endif
index ae3fad7c682348612a5fe5da8ca9e3de107715ec..19cac6241f3596e7b734ab9b91c921a66b253ebe 100644 (file)
@@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "filesys.h"
 #include "gettime.h"
 #include "gettext.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "porting.h"
 #include "settings.h"
 #include "client.h"
index 469e7396bf049a7c53cd5e310c0f4b49709a11e0..6ebc2994bcf79f36e901b01453379d4379b92158 100644 (file)
@@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "inventorymanager.h"
 #include "log.h"
 #include "serverenvironment.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "serverobject.h"
 #include "settings.h"
 #include "craftdef.h"
index b11f73e869d452677dec5607a8a383874394542a..f1c44c7d81ee925ab92bd689568d5c1f24ac7d51 100644 (file)
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "server.h"
 #include "util/strfnd.h"
 #include "network/clientopcodes.h"
+#include "script/clientscripting.h"
 #include "util/serialize.h"
 #include "util/srp.h"
 #include "tileanimation.h"
@@ -411,7 +412,10 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt)
                message += (wchar_t)read_wchar;
        }
 
-       m_chat_queue.push(message);
+       // If chat message not consummed by client lua API
+       if (!m_script->on_receiving_message(wide_to_utf8(message))) {
+               m_chat_queue.push(message);
+       }
 }
 
 void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
index ac428e8edf6bb7205368fd70d844a689187e0b5f..b707c6fad38d672a2fac38b1c33c427b922b6f9f 100644 (file)
@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nodedef.h"
 #include "player.h"
 #include "rollback_interface.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "settings.h"
 #include "tool.h"
 #include "version.h"
index 5ef672ca91a4e7820eb496a14c75bc3fabdd1d2f..c96ccc8160c0db0c9fb346b8394d85f640b213a3 100644 (file)
@@ -3,16 +3,17 @@ add_subdirectory(cpp_api)
 add_subdirectory(lua_api)
 
 # Used by server and client
-set(common_SCRIPT_SRCS 
-       ${CMAKE_CURRENT_SOURCE_DIR}/scripting_game.cpp
+set(common_SCRIPT_SRCS
+       ${CMAKE_CURRENT_SOURCE_DIR}/serverscripting.cpp
        ${common_SCRIPT_COMMON_SRCS}
        ${common_SCRIPT_CPP_API_SRCS}
        ${common_SCRIPT_LUA_API_SRCS}
        PARENT_SCOPE)
 
 # Used by client only
-set(client_SCRIPT_SRCS 
+set(client_SCRIPT_SRCS
        ${CMAKE_CURRENT_SOURCE_DIR}/scripting_mainmenu.cpp
+       ${CMAKE_CURRENT_SOURCE_DIR}/clientscripting.cpp
        ${client_SCRIPT_COMMON_SRCS}
        ${client_SCRIPT_CPP_API_SRCS}
        ${client_SCRIPT_LUA_API_SRCS}
diff --git a/src/script/clientscripting.cpp b/src/script/clientscripting.cpp
new file mode 100644 (file)
index 0000000..43bc6f9
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "clientscripting.h"
+#include "client.h"
+#include "cpp_api/s_internal.h"
+#include "lua_api/l_client.h"
+#include "lua_api/l_util.h"
+
+ClientScripting::ClientScripting(Client *client):
+       ScriptApiBase()
+{
+       setGameDef(client);
+
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Security is mandatory client side
+       initializeSecurity();
+
+       lua_getglobal(L, "core");
+       int top = lua_gettop(L);
+
+       InitializeModApi(L, top);
+       lua_pop(L, 1);
+
+       // Push builtin initialization type
+       lua_pushstring(L, "client");
+       lua_setglobal(L, "INIT");
+
+       infostream << "SCRIPTAPI: Initialized client game modules" << std::endl;
+}
+
+void ClientScripting::InitializeModApi(lua_State *L, int top)
+{
+       ModApiUtil::Initialize(L, top);
+       ModApiClient::Initialize(L, top);
+}
diff --git a/src/script/clientscripting.h b/src/script/clientscripting.h
new file mode 100644 (file)
index 0000000..e2a91f6
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef CLIENT_SCRIPTING_H_
+#define CLIENT_SCRIPTING_H_
+
+#include "cpp_api/s_base.h"
+#include "cpp_api/s_client.h"
+#include "cpp_api/s_security.h"
+
+class Client;
+class ClientScripting:
+       virtual public ScriptApiBase,
+       public ScriptApiSecurity,
+       public ScriptApiClient
+{
+public:
+       ClientScripting(Client *client);
+
+private:
+       virtual void InitializeModApi(lua_State *L, int top);
+};
+#endif
index be4d0131e170089e95679259ed64438198339b3e..4b13356a89a0933df1b73fd3436daf153dea4db1 100644 (file)
@@ -13,6 +13,7 @@ set(common_SCRIPT_CPP_API_SRCS
        PARENT_SCOPE)
 
 set(client_SCRIPT_CPP_API_SRCS
+       ${CMAKE_CURRENT_SOURCE_DIR}/s_client.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/s_mainmenu.cpp
        PARENT_SCOPE)
 
index cbe5735a77ae9d657e75eee48478999a8be02207..6a843810f9b4b9f3a1d7ff76d6dd1ac0989f675b 100644 (file)
@@ -23,12 +23,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "lua_api/l_object.h"
 #include "common/c_converter.h"
 #include "serverobject.h"
-#include "debug.h"
 #include "filesys.h"
-#include "log.h"
 #include "mods.h"
 #include "porting.h"
 #include "util/string.h"
+#include "server.h"
+#ifndef SERVER
+#include "client.h"
+#endif
 
 
 extern "C" {
@@ -69,7 +71,8 @@ public:
 */
 
 ScriptApiBase::ScriptApiBase() :
-       m_luastackmutex()
+       m_luastackmutex(),
+       m_gamedef(NULL)
 {
 #ifdef SCRIPTAPI_LOCK_DEBUG
        m_lock_recursion_count = 0;
@@ -113,7 +116,6 @@ ScriptApiBase::ScriptApiBase() :
        // Default to false otherwise
        m_secure = false;
 
-       m_server = NULL;
        m_environment = NULL;
        m_guiengine = NULL;
 }
@@ -333,3 +335,14 @@ void ScriptApiBase::objectrefGet(lua_State *L, u16 id)
        lua_remove(L, -2); // object_refs
        lua_remove(L, -2); // core
 }
+
+Server* ScriptApiBase::getServer()
+{
+       return dynamic_cast<Server *>(m_gamedef);
+}
+#ifndef SERVER
+Client* ScriptApiBase::getClient()
+{
+       return dynamic_cast<Client *>(m_gamedef);
+}
+#endif
index c27235255499334ef6c50ff132a8e21bdf39d3cd..19d71df6517f27660f0ef2ec225ab3fd94709271 100644 (file)
@@ -55,6 +55,10 @@ extern "C" {
        setOriginFromTableRaw(index, __FUNCTION__)
 
 class Server;
+#ifndef SERVER
+class Client;
+#endif
+class IGameDef;
 class Environment;
 class GUIEngine;
 class ServerActiveObject;
@@ -75,7 +79,11 @@ public:
        void addObjectReference(ServerActiveObject *cobj);
        void removeObjectReference(ServerActiveObject *cobj);
 
-       Server* getServer() { return m_server; }
+       IGameDef *getGameDef() { return m_gamedef; }
+       Server* getServer();
+#ifndef SERVER
+       Client* getClient();
+#endif
 
        std::string getOrigin() { return m_last_run_mod; }
        void setOriginDirect(const char *origin);
@@ -98,7 +106,7 @@ protected:
        void scriptError(int result, const char *fxn);
        void stackDump(std::ostream &o);
 
-       void setServer(Server* server) { m_server = server; }
+       void setGameDef(IGameDef* gamedef) { m_gamedef = gamedef; }
 
        Environment* getEnv() { return m_environment; }
        void setEnv(Environment* env) { m_environment = env; }
@@ -122,7 +130,7 @@ private:
 
        lua_State*      m_luastack;
 
-       Server*         m_server;
+       IGameDef*       m_gamedef;
        Environment*    m_environment;
        GUIEngine*      m_guiengine;
 };
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp
new file mode 100644 (file)
index 0000000..08af8eb
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "s_client.h"
+#include "s_internal.h"
+
+void ScriptApiClient::on_shutdown()
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get registered shutdown hooks
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_shutdown");
+       // Call callbacks
+       runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+}
+
+bool ScriptApiClient::on_sending_message(const std::string &message)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_chat_messages
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_sending_chat_messages");
+       // Call callbacks
+       lua_pushstring(L, message.c_str());
+       runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+       bool ate = lua_toboolean(L, -1);
+       return ate;
+}
+
+bool ScriptApiClient::on_receiving_message(const std::string &message)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_chat_messages
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_receiving_chat_messages");
+       // Call callbacks
+       lua_pushstring(L, message.c_str());
+       runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+       bool ate = lua_toboolean(L, -1);
+       return ate;
+}
diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h
new file mode 100644 (file)
index 0000000..08fdd8f
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef S_CLIENT_H_
+#define S_CLIENT_H_
+
+#include "cpp_api/s_base.h"
+
+class ScriptApiClient: virtual public ScriptApiBase
+{
+public:
+       // Calls on_shutdown handlers
+       void on_shutdown();
+
+       // Chat message handlers
+       bool on_sending_message(const std::string &message);
+       bool on_receiving_message(const std::string &message);
+};
+#endif
index be2b884cc4f94d8b92ee01311ab75131705c442a..f85cd0c9c37364de6a9211be9a57da54631ed455 100644 (file)
@@ -382,9 +382,9 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
        lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI);
        ScriptApiBase *script = (ScriptApiBase *) lua_touserdata(L, -1);
        lua_pop(L, 1);
-       const Server *server = script->getServer();
-
-       if (!server) return false;
+       const IGameDef *gamedef = script->getGameDef();
+       if (!gamedef)
+               return false;
 
        // Get mod name
        lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
@@ -400,7 +400,7 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
                // Allow paths in mod path
                // Don't bother if write access isn't important, since it will be handled later
                if (write_required || write_allowed != NULL) {
-                       const ModSpec *mod = server->getModSpec(mod_name);
+                       const ModSpec *mod = gamedef->getModSpec(mod_name);
                        if (mod) {
                                str = fs::AbsolutePath(mod->path);
                                if (!str.empty() && fs::PathStartsWith(abs_path, str)) {
@@ -414,7 +414,7 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
 
        // Allow read-only access to all mod directories
        if (!write_required) {
-               const std::vector<ModSpec> mods = server->getMods();
+               const std::vector<ModSpec> mods = gamedef->getMods();
                for (size_t i = 0; i < mods.size(); ++i) {
                        str = fs::AbsolutePath(mods[i].path);
                        if (!str.empty() && fs::PathStartsWith(abs_path, str)) {
@@ -423,7 +423,7 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
                }
        }
 
-       str = fs::AbsolutePath(server->getWorldPath());
+       str = fs::AbsolutePath(gamedef->getWorldPath());
        if (!str.empty()) {
                // Don't allow access to other paths in the world mod/game path.
                // These have to be blocked so you can't override a trusted mod
index e82560696b2b47880d4d18187c0e2019b85e4434..ea3d75ffa6438acbec17f5fa481d9a35b473861f 100644 (file)
@@ -23,5 +23,6 @@ set(common_SCRIPT_LUA_API_SRCS
        PARENT_SCOPE)
 
 set(client_SCRIPT_LUA_API_SRCS
+       ${CMAKE_CURRENT_SOURCE_DIR}/l_client.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/l_mainmenu.cpp
        PARENT_SCOPE)
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
new file mode 100644 (file)
index 0000000..9c47860
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "l_client.h"
+#include "l_internal.h"
+
+int ModApiClient::l_get_current_modname(lua_State *L)
+{
+       lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
+       return 1;
+}
+
+void ModApiClient::Initialize(lua_State *L, int top)
+{
+       API_FCT(get_current_modname);
+}
diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h
new file mode 100644 (file)
index 0000000..332f001
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef L_CLIENT_H_
+#define L_CLIENT_H_
+
+#include "lua_api/l_base.h"
+
+class ModApiClient : public ModApiBase
+{
+private:
+       // get_current_modname()
+       static int l_get_current_modname(lua_State *L);
+
+public:
+       static void Initialize(lua_State *L, int top);
+};
+
+#endif
index 2722e35a4d8357bc5d5b1df4472286b7ee0ed44f..442c4b99a1b45c29a7a16185f6aaa4213f403ce2 100644 (file)
@@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "lua_api/l_vmanip.h"
 #include "common/c_converter.h"
 #include "common/c_content.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "environment.h"
 #include "server.h"
 #include "nodedef.h"
@@ -49,7 +49,7 @@ struct EnumString ModApiEnvMod::es_ClearObjectsMode[] =
 void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
                u32 active_object_count, u32 active_object_count_wider)
 {
-       GameScripting *scriptIface = env->getScriptIface();
+       ServerScripting *scriptIface = env->getScriptIface();
        scriptIface->realityCheck();
 
        lua_State *L = scriptIface->getStack();
@@ -92,7 +92,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
 
 void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n)
 {
-       GameScripting *scriptIface = env->getScriptIface();
+       ServerScripting *scriptIface = env->getScriptIface();
        scriptIface->realityCheck();
 
        lua_State *L = scriptIface->getStack();
index 21b235f841beacccdae54de959bdf814ce787268..3229594113627d3ea5066e5cf7342f54840e5cb3 100644 (file)
@@ -242,7 +242,7 @@ public:
 };
 
 struct ScriptCallbackState {
-       GameScripting *script;
+       ServerScripting *script;
        int callback_ref;
        int args_ref;
        unsigned int refcount;
index 9352812ab19218f7c63c9f4f6b8c22c2e1ba91c2..be454ad4513f18f60c0df9bd39f0c18ff4f56a43 100644 (file)
@@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "content_sao.h"
 #include "server.h"
 #include "hud.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 
 struct EnumString es_HudElementType[] =
 {
diff --git a/src/script/scripting_game.cpp b/src/script/scripting_game.cpp
deleted file mode 100644 (file)
index 4da7522..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
-Minetest
-Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "scripting_game.h"
-#include "server.h"
-#include "log.h"
-#include "settings.h"
-#include "cpp_api/s_internal.h"
-#include "lua_api/l_areastore.h"
-#include "lua_api/l_base.h"
-#include "lua_api/l_craft.h"
-#include "lua_api/l_env.h"
-#include "lua_api/l_inventory.h"
-#include "lua_api/l_item.h"
-#include "lua_api/l_itemstackmeta.h"
-#include "lua_api/l_mapgen.h"
-#include "lua_api/l_nodemeta.h"
-#include "lua_api/l_nodetimer.h"
-#include "lua_api/l_noise.h"
-#include "lua_api/l_object.h"
-#include "lua_api/l_particles.h"
-#include "lua_api/l_rollback.h"
-#include "lua_api/l_server.h"
-#include "lua_api/l_util.h"
-#include "lua_api/l_vmanip.h"
-#include "lua_api/l_settings.h"
-#include "lua_api/l_http.h"
-#include "lua_api/l_storage.h"
-
-extern "C" {
-#include "lualib.h"
-}
-
-GameScripting::GameScripting(Server* server)
-{
-       setServer(server);
-
-       // setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
-       // once the environment has been created
-
-       SCRIPTAPI_PRECHECKHEADER
-
-       if (g_settings->getBool("secure.enable_security")) {
-               initializeSecurity();
-       }
-
-       lua_getglobal(L, "core");
-       int top = lua_gettop(L);
-
-       lua_newtable(L);
-       lua_setfield(L, -2, "object_refs");
-
-       lua_newtable(L);
-       lua_setfield(L, -2, "luaentities");
-
-       // Initialize our lua_api modules
-       InitializeModApi(L, top);
-       lua_pop(L, 1);
-
-       // Push builtin initialization type
-       lua_pushstring(L, "game");
-       lua_setglobal(L, "INIT");
-
-       infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
-}
-
-void GameScripting::InitializeModApi(lua_State *L, int top)
-{
-       // Initialize mod api modules
-       ModApiCraft::Initialize(L, top);
-       ModApiEnvMod::Initialize(L, top);
-       ModApiInventory::Initialize(L, top);
-       ModApiItemMod::Initialize(L, top);
-       ModApiMapgen::Initialize(L, top);
-       ModApiParticles::Initialize(L, top);
-       ModApiRollback::Initialize(L, top);
-       ModApiServer::Initialize(L, top);
-       ModApiUtil::Initialize(L, top);
-       ModApiHttp::Initialize(L, top);
-       ModApiStorage::Initialize(L, top);
-
-       // Register reference classes (userdata)
-       InvRef::Register(L);
-       ItemStackMetaRef::Register(L);
-       LuaAreaStore::Register(L);
-       LuaItemStack::Register(L);
-       LuaPerlinNoise::Register(L);
-       LuaPerlinNoiseMap::Register(L);
-       LuaPseudoRandom::Register(L);
-       LuaPcgRandom::Register(L);
-       LuaSecureRandom::Register(L);
-       LuaVoxelManip::Register(L);
-       NodeMetaRef::Register(L);
-       NodeTimerRef::Register(L);
-       ObjectRef::Register(L);
-       LuaSettings::Register(L);
-       StorageRef::Register(L);
-}
-
-void log_deprecated(const std::string &message)
-{
-       log_deprecated(NULL, message);
-}
diff --git a/src/script/scripting_game.h b/src/script/scripting_game.h
deleted file mode 100644 (file)
index 970b3e8..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-Minetest
-Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#ifndef SCRIPTING_GAME_H_
-#define SCRIPTING_GAME_H_
-
-#include "cpp_api/s_base.h"
-#include "cpp_api/s_entity.h"
-#include "cpp_api/s_env.h"
-#include "cpp_api/s_inventory.h"
-#include "cpp_api/s_node.h"
-#include "cpp_api/s_player.h"
-#include "cpp_api/s_server.h"
-#include "cpp_api/s_security.h"
-
-/*****************************************************************************/
-/* Scripting <-> Game Interface                                              */
-/*****************************************************************************/
-
-class GameScripting :
-               virtual public ScriptApiBase,
-               public ScriptApiDetached,
-               public ScriptApiEntity,
-               public ScriptApiEnv,
-               public ScriptApiNode,
-               public ScriptApiPlayer,
-               public ScriptApiServer,
-               public ScriptApiSecurity
-{
-public:
-       GameScripting(Server* server);
-
-       // use ScriptApiBase::loadMod() to load mods
-
-private:
-       void InitializeModApi(lua_State *L, int top);
-};
-
-void log_deprecated(const std::string &message);
-
-#endif /* SCRIPTING_GAME_H_ */
diff --git a/src/script/serverscripting.cpp b/src/script/serverscripting.cpp
new file mode 100644 (file)
index 0000000..215b2cf
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "serverscripting.h"
+#include "server.h"
+#include "log.h"
+#include "settings.h"
+#include "cpp_api/s_internal.h"
+#include "lua_api/l_areastore.h"
+#include "lua_api/l_base.h"
+#include "lua_api/l_craft.h"
+#include "lua_api/l_env.h"
+#include "lua_api/l_inventory.h"
+#include "lua_api/l_item.h"
+#include "lua_api/l_itemstackmeta.h"
+#include "lua_api/l_mapgen.h"
+#include "lua_api/l_nodemeta.h"
+#include "lua_api/l_nodetimer.h"
+#include "lua_api/l_noise.h"
+#include "lua_api/l_object.h"
+#include "lua_api/l_particles.h"
+#include "lua_api/l_rollback.h"
+#include "lua_api/l_server.h"
+#include "lua_api/l_util.h"
+#include "lua_api/l_vmanip.h"
+#include "lua_api/l_settings.h"
+#include "lua_api/l_http.h"
+#include "lua_api/l_storage.h"
+
+extern "C" {
+#include "lualib.h"
+}
+
+ServerScripting::ServerScripting(Server* server)
+{
+       setGameDef(server);
+
+       // setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
+       // once the environment has been created
+
+       SCRIPTAPI_PRECHECKHEADER
+
+       if (g_settings->getBool("secure.enable_security")) {
+               initializeSecurity();
+       }
+
+       lua_getglobal(L, "core");
+       int top = lua_gettop(L);
+
+       lua_newtable(L);
+       lua_setfield(L, -2, "object_refs");
+
+       lua_newtable(L);
+       lua_setfield(L, -2, "luaentities");
+
+       // Initialize our lua_api modules
+       InitializeModApi(L, top);
+       lua_pop(L, 1);
+
+       // Push builtin initialization type
+       lua_pushstring(L, "game");
+       lua_setglobal(L, "INIT");
+
+       infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
+}
+
+void ServerScripting::InitializeModApi(lua_State *L, int top)
+{
+       // Initialize mod api modules
+       ModApiCraft::Initialize(L, top);
+       ModApiEnvMod::Initialize(L, top);
+       ModApiInventory::Initialize(L, top);
+       ModApiItemMod::Initialize(L, top);
+       ModApiMapgen::Initialize(L, top);
+       ModApiParticles::Initialize(L, top);
+       ModApiRollback::Initialize(L, top);
+       ModApiServer::Initialize(L, top);
+       ModApiUtil::Initialize(L, top);
+       ModApiHttp::Initialize(L, top);
+       ModApiStorage::Initialize(L, top);
+
+       // Register reference classes (userdata)
+       InvRef::Register(L);
+       ItemStackMetaRef::Register(L);
+       LuaAreaStore::Register(L);
+       LuaItemStack::Register(L);
+       LuaPerlinNoise::Register(L);
+       LuaPerlinNoiseMap::Register(L);
+       LuaPseudoRandom::Register(L);
+       LuaPcgRandom::Register(L);
+       LuaSecureRandom::Register(L);
+       LuaVoxelManip::Register(L);
+       NodeMetaRef::Register(L);
+       NodeTimerRef::Register(L);
+       ObjectRef::Register(L);
+       LuaSettings::Register(L);
+       StorageRef::Register(L);
+}
+
+void log_deprecated(const std::string &message)
+{
+       log_deprecated(NULL, message);
+}
diff --git a/src/script/serverscripting.h b/src/script/serverscripting.h
new file mode 100644 (file)
index 0000000..fd97ea4
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef SERVER_SCRIPTING_H_
+#define SERVER_SCRIPTING_H_
+
+#include "cpp_api/s_base.h"
+#include "cpp_api/s_entity.h"
+#include "cpp_api/s_env.h"
+#include "cpp_api/s_inventory.h"
+#include "cpp_api/s_node.h"
+#include "cpp_api/s_player.h"
+#include "cpp_api/s_server.h"
+#include "cpp_api/s_security.h"
+
+/*****************************************************************************/
+/* Scripting <-> Server Game Interface                                       */
+/*****************************************************************************/
+
+class ServerScripting:
+               virtual public ScriptApiBase,
+               public ScriptApiDetached,
+               public ScriptApiEntity,
+               public ScriptApiEnv,
+               public ScriptApiNode,
+               public ScriptApiPlayer,
+               public ScriptApiServer,
+               public ScriptApiSecurity
+{
+public:
+       ServerScripting(Server* server);
+
+       // use ScriptApiBase::loadMod() to load mods
+
+private:
+       void InitializeModApi(lua_State *L, int top);
+};
+
+void log_deprecated(const std::string &message);
+
+#endif /* SCRIPTING_GAME_H_ */
index 8b9f46f85a76c42a529a9a380a35a860141857bb..3adbf40cc5fed5e17dcc00adab4a56da81ff43cf 100644 (file)
@@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "profiler.h"
 #include "log.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "nodedef.h"
 #include "itemdef.h"
 #include "craftdef.h"
@@ -269,7 +269,7 @@ Server::Server(
        // Initialize scripting
        infostream<<"Server: Initializing Lua"<<std::endl;
 
-       m_script = new GameScripting(this);
+       m_script = new ServerScripting(this);
 
        std::string script_path = getBuiltinLuaPath() + DIR_DELIM "init.lua";
 
@@ -3411,7 +3411,7 @@ void Server::getModNames(std::vector<std::string> &modlist)
                modlist.push_back(it->name);
 }
 
-std::string Server::getBuiltinLuaPath()
+const std::string Server::getBuiltinLuaPath()
 {
        return porting::path_share + DIR_DELIM + "builtin";
 }
index 3eee67b78ebe66fc83e52dd05ffd1884e03deecc..417d31bd82ffb344da8128629d0f73cfa332e53f 100644 (file)
@@ -53,7 +53,7 @@ class PlayerSAO;
 class IRollbackManager;
 struct RollbackAction;
 class EmergeManager;
-class GameScripting;
+class ServerScripting;
 class ServerEnvironment;
 struct SimpleSoundSpec;
 class ServerThread;
@@ -274,7 +274,7 @@ public:
        Inventory* createDetachedInventory(const std::string &name, const std::string &player="");
 
        // Envlock and conlock should be locked when using scriptapi
-       GameScripting *getScriptIface(){ return m_script; }
+       ServerScripting *getScriptIface(){ return m_script; }
 
        // actions: time-reversed list
        // Return value: success/failure
@@ -295,8 +295,8 @@ public:
        IWritableNodeDefManager* getWritableNodeDefManager();
        IWritableCraftDefManager* getWritableCraftDefManager();
 
-       const std::vector<ModSpec> &getMods() const { return m_mods; }
-       const ModSpec* getModSpec(const std::string &modname) const;
+       virtual const std::vector<ModSpec> &getMods() const { return m_mods; }
+       virtual const ModSpec* getModSpec(const std::string &modname) const;
        void getModNames(std::vector<std::string> &modlist);
        std::string getBuiltinLuaPath();
        inline const std::string &getWorldPath() const { return m_path_world; }
@@ -540,7 +540,7 @@ private:
 
        // Scripting
        // Envlock and conlock should be locked when using Lua
-       GameScripting *m_script;
+       ServerScripting *m_script;
 
        // Item definition manager
        IWritableItemDefManager *m_itemdef;
index f3f489092a504b0060882b52efffe62ed81774ea..ecc7c31501256b07af0c5ad3af767c8474f42dac 100644 (file)
@@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "profiler.h"
 #include "raycast.h"
 #include "remoteplayer.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
 #include "server.h"
 #include "voxelalgorithms.h"
 #include "util/serialize.h"
@@ -352,7 +352,7 @@ void ActiveBlockList::update(std::vector<v3s16> &active_positions,
 */
 
 ServerEnvironment::ServerEnvironment(ServerMap *map,
-       GameScripting *scriptIface, Server *server,
+       ServerScripting *scriptIface, Server *server,
        const std::string &path_world) :
        m_map(map),
        m_script(scriptIface),
index b7056c00cd8687ef984debefaed99be8d75a3aeb..b7796b5f149b42721faea14bab36440eb7c0df70 100644 (file)
@@ -33,7 +33,7 @@ class ServerEnvironment;
 class ActiveBlockModifier;
 class ServerActiveObject;
 class Server;
-class GameScripting;
+class ServerScripting;
 
 /*
        {Active, Loading} block modifier interface.
@@ -194,7 +194,7 @@ typedef UNORDERED_MAP<u16, ServerActiveObject *> ActiveObjectMap;
 class ServerEnvironment : public Environment
 {
 public:
-       ServerEnvironment(ServerMap *map, GameScripting *scriptIface,
+       ServerEnvironment(ServerMap *map, ServerScripting *scriptIface,
                Server *server, const std::string &path_world);
        ~ServerEnvironment();
 
@@ -203,7 +203,7 @@ public:
        ServerMap & getServerMap();
 
        //TODO find way to remove this fct!
-       GameScripting* getScriptIface()
+       ServerScripting* getScriptIface()
        { return m_script; }
 
        Server *getGameDef()
@@ -381,7 +381,7 @@ private:
        // The map
        ServerMap *m_map;
        // Lua state
-       GameScripting* m_script;
+       ServerScripting* m_script;
        // Server definition
        Server *m_server;
        // World path
index 41ccf0d2d134e38e8f31393130f817676100f360..9beb0afa6de2a53e8345132351684deea36ea233 100644 (file)
@@ -19,10 +19,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "test.h"
 
-#include "log.h"
 #include "nodedef.h"
 #include "itemdef.h"
 #include "gamedef.h"
+#include "mods.h"
 
 content_t t_CONTENT_STONE;
 content_t t_CONTENT_GRASS;
@@ -59,6 +59,13 @@ public:
 
        void defineSomeNodes();
 
+       virtual const std::vector<ModSpec> &getMods() const
+       {
+               static std::vector<ModSpec> testmodspec;
+               return testmodspec;
+       }
+       virtual const ModSpec* getModSpec(const std::string &modname) const { return NULL; }
+
 private:
        IItemDefManager *m_itemdef;
        INodeDefManager *m_nodedef;