]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
[CSM] Add event on_connect player API lua (#5540)
authorVincent Glize <vincentglize@hotmail.fr>
Sat, 8 Apr 2017 06:20:30 +0000 (08:20 +0200)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 8 Apr 2017 06:20:30 +0000 (08:20 +0200)
* Add event on_connect player API lua

builtin/client/register.lua
clientmods/preview/init.lua
doc/client_lua_api.md
src/client.cpp
src/script/cpp_api/s_client.cpp
src/script/cpp_api/s_client.h

index 1c3966eda335db3a3b24451a199fbfb5dd86b443..e6ce25654111262176f521ca54162e25e729a7da 100644 (file)
@@ -60,6 +60,7 @@ end
 
 core.registered_globalsteps, core.register_globalstep = make_registration()
 core.registered_on_shutdown, core.register_on_shutdown = make_registration()
+core.registered_on_connect, core.register_on_connect = 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()
 core.registered_on_death, core.register_on_death = make_registration()
index 3c96fae555e7203f03460cb1e1cc0be179a71570..5c0628bfe8a08a694cdb29786f9ef57abc5caba0 100644 (file)
@@ -6,6 +6,10 @@ core.register_on_shutdown(function()
        print("[PREVIEW] shutdown client")
 end)
 
+core.register_on_connect(function()
+       print("[PREVIEW] Player connection completed")
+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("[PREVIEW] Received message " .. message)
index 6d62de8a2eceff66cd698e0cd9c073b43b8e5ed4..d68f90deca62fd52ef64cf921c7a2f7408142e12 100644 (file)
@@ -639,6 +639,8 @@ Call these functions only at load time!
     * **Warning**: If the client terminates abnormally (i.e. crashes), the registered
       callbacks **will likely not be run**. Data should be saved at
       semi-frequent intervals as well as on server shutdown.
+* `minetest.register_on_connect(func())`
+    * Called at the end of client connection (when player is loaded onto map)
 * `minetest.register_on_receiving_chat_message(func(name, message))`
     * Called always when a client receive a message
     * Return `true` to mark the message as handled, which means that it will not be shown to chat
index e710624d5e6fbbc632083e685f10c1ed029c1050..3a3e33cfde7db8ddd070900a76d3f448f7dc9ab1 100644 (file)
@@ -1864,6 +1864,10 @@ void Client::afterContentReceived(IrrlichtDevice *device)
 
        m_state = LC_Ready;
        sendReady();
+
+       if (g_settings->getBool("enable_client_modding"))
+               m_script->on_connect();
+
        text = wgettext("Done!");
        draw_load_screen(text, device, guienv, 0, 100);
        infostream<<"Client::afterContentReceived() done"<<std::endl;
index 666fd693d865281afd64f0ef6f9bd2074ae01afb..a8a7d5e262b99ae8101f74812e9d0eecc34b9a86 100644 (file)
@@ -35,6 +35,17 @@ void ScriptApiClient::on_shutdown()
        runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
 }
 
+void ScriptApiClient::on_connect()
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // get registered connect hooks
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_connect");
+       // Call callback
+       runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+}
+
 bool ScriptApiClient::on_sending_message(const std::string &message)
 {
        SCRIPTAPI_PRECHECKHEADER
index 9afc66d61f80f3afd2fb4ab1af1723bc77d37167..50e5e0d8a3dfadcf316c1ea211b9ba109a354062 100644 (file)
@@ -36,6 +36,8 @@ class ScriptApiClient : virtual public ScriptApiBase
 public:
        // Calls on_shutdown handlers
        void on_shutdown();
+       
+       void on_connect();
 
        // Chat message handlers
        bool on_sending_message(const std::string &message);