From f73534640a18709921519ee43110292cf658e67f Mon Sep 17 00:00:00 2001 From: Vincent Glize Date: Sat, 8 Apr 2017 08:20:30 +0200 Subject: [PATCH] [CSM] Add event on_connect player API lua (#5540) * Add event on_connect player API lua --- builtin/client/register.lua | 1 + clientmods/preview/init.lua | 4 ++++ doc/client_lua_api.md | 2 ++ src/client.cpp | 4 ++++ src/script/cpp_api/s_client.cpp | 11 +++++++++++ src/script/cpp_api/s_client.h | 2 ++ 6 files changed, 24 insertions(+) diff --git a/builtin/client/register.lua b/builtin/client/register.lua index 1c3966eda..e6ce25654 100644 --- a/builtin/client/register.lua +++ b/builtin/client/register.lua @@ -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() diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index 3c96fae55..5c0628bfe 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -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) diff --git a/doc/client_lua_api.md b/doc/client_lua_api.md index 6d62de8a2..d68f90dec 100644 --- a/doc/client_lua_api.md +++ b/doc/client_lua_api.md @@ -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 diff --git a/src/client.cpp b/src/client.cpp index e710624d5..3a3e33cfd 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -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"<