summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2017-01-21 15:02:08 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-03-13 23:56:05 +0100
commit2efae3ffd720095222c800e016286a45c9fe1e5c (patch)
tree3a8b19daa071cf742fee52d70a0e0adf94d56c0c /src/client.cpp
parentc9492b4d37c11f35cfdc1558f771eef87fc5c972 (diff)
downloadminetest-2efae3ffd720095222c800e016286a45c9fe1e5c.tar.gz
minetest-2efae3ffd720095222c800e016286a45c9fe1e5c.tar.bz2
minetest-2efae3ffd720095222c800e016286a45c9fe1e5c.zip
[CSM] Client side modding
* 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
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 30058a2b0..faf454b35 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -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);