[CSM] Remove `on_connect` callback (#6941)

Fixes #6939
This commit is contained in:
red-001 2018-01-21 17:27:27 +00:00 committed by Loïc Blot
parent 5dab742645
commit 49ff1d2ea8
6 changed files with 13 additions and 45 deletions

View File

@ -60,7 +60,6 @@ end
core.registered_globalsteps, core.register_globalstep = make_registration() core.registered_globalsteps, core.register_globalstep = make_registration()
core.registered_on_shutdown, core.register_on_shutdown = 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_message, core.register_on_receiving_chat_message = make_registration() core.registered_on_receiving_chat_message, core.register_on_receiving_chat_message = make_registration()
core.registered_on_sending_chat_message, core.register_on_sending_chat_message = make_registration() core.registered_on_sending_chat_message, core.register_on_sending_chat_message = make_registration()
core.registered_on_death, core.register_on_death = make_registration() core.registered_on_death, core.register_on_death = make_registration()

View File

@ -7,21 +7,19 @@ dofile("preview:example.lua")
core.register_on_shutdown(function() core.register_on_shutdown(function()
print("[PREVIEW] shutdown client") print("[PREVIEW] shutdown client")
end) end)
local id = 0 local id = nil
core.register_on_connect(function()
print("[PREVIEW] Player connection completed")
local server_info = core.get_server_info()
print("Server version: " .. server_info.protocol_version)
print("Server ip: " .. server_info.ip)
print("Server address: " .. server_info.address)
print("Server port: " .. server_info.port)
mod_channel = core.mod_channel_join("experimental_preview")
core.after(4, function() local server_info = core.get_server_info()
if mod_channel:is_writeable() then print("Server version: " .. server_info.protocol_version)
mod_channel:send_all("preview talk to experimental") print("Server ip: " .. server_info.ip)
end print("Server address: " .. server_info.address)
end) print("Server port: " .. server_info.port)
mod_channel = core.mod_channel_join("experimental_preview")
core.after(4, function()
if mod_channel:is_writeable() then
mod_channel:send_all("preview talk to experimental")
end
end) end)
core.after(1, function() core.after(1, function()

View File

@ -651,8 +651,6 @@ Call these functions only at load time!
* **Warning**: If the client terminates abnormally (i.e. crashes), the registered * **Warning**: If the client terminates abnormally (i.e. crashes), the registered
callbacks **will likely not be run**. Data should be saved at callbacks **will likely not be run**. Data should be saved at
semi-frequent intervals as well as on server shutdown. 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(message))` * `minetest.register_on_receiving_chat_message(func(message))`
* Called always when a client receive a 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 * Return `true` to mark the message as handled, which means that it will not be shown to chat
@ -784,8 +782,6 @@ Call these functions only at load time!
* Client joins channel `channel_name`, and creates it, if necessary. You * Client joins channel `channel_name`, and creates it, if necessary. You
should listen from incoming messages with `minetest.register_on_modchannel_message` should listen from incoming messages with `minetest.register_on_modchannel_message`
call to receive incoming messages. Warning, this function is asynchronous. call to receive incoming messages. Warning, this function is asynchronous.
* You should use a minetest.register_on_connect(function() ... end) to perform
a successful channel join on client startup.
### Particles ### Particles
* `minetest.add_particle(particle definition)` * `minetest.add_particle(particle definition)`
@ -935,18 +931,7 @@ Please do not try to access the reference until the camera is initialized, other
* Returns aspect ratio of screen * Returns aspect ratio of screen
### LocalPlayer ### LocalPlayer
An interface to retrieve information about the player. The player is An interface to retrieve information about the player.
not accessible until the client is fully done loading and therefore
not at module init time.
To get the localplayer handle correctly, use `on_connect()` as follows:
```lua
local localplayer
minetest.register_on_connect(function()
localplayer = minetest.localplayer
end)
```
Methods: Methods:

View File

@ -1698,7 +1698,6 @@ void Client::afterContentReceived()
if (g_settings->getBool("enable_client_modding")) { if (g_settings->getBool("enable_client_modding")) {
m_script->on_client_ready(m_env.getLocalPlayer()); m_script->on_client_ready(m_env.getLocalPlayer());
m_script->on_connect();
} }
text = wgettext("Done!"); text = wgettext("Done!");

View File

@ -36,17 +36,6 @@ void ScriptApiClient::on_shutdown()
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST); 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) bool ScriptApiClient::on_sending_message(const std::string &message)
{ {
SCRIPTAPI_PRECHECKHEADER SCRIPTAPI_PRECHECKHEADER

View File

@ -40,8 +40,6 @@ public:
// Calls on_shutdown handlers // Calls on_shutdown handlers
void on_shutdown(); void on_shutdown();
void on_connect();
// Chat message handlers // Chat message handlers
bool on_sending_message(const std::string &message); bool on_sending_message(const std::string &message);
bool on_receiving_message(const std::string &message); bool on_receiving_message(const std::string &message);