diff options
author | red-001 <red-001@outlook.ie> | 2017-04-01 12:40:56 +0100 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-04-01 13:40:56 +0200 |
commit | 63ac62ec8abe30f0d6dd2cfe0ddaab291c36893f (patch) | |
tree | 76707d22d37fc2fd29e5c5326f3848780599eb36 /src | |
parent | 813a9a36b22a4e2d7383622311b6f52e31a94733 (diff) | |
download | minetest-63ac62ec8abe30f0d6dd2cfe0ddaab291c36893f.tar.gz minetest-63ac62ec8abe30f0d6dd2cfe0ddaab291c36893f.tar.bz2 minetest-63ac62ec8abe30f0d6dd2cfe0ddaab291c36893f.zip |
[CSM] Add function and chat command to disconnect from server. (#5487)
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 10 | ||||
-rw-r--r-- | src/client.h | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_client.cpp | 18 | ||||
-rw-r--r-- | src/script/lua_api/l_client.h | 3 |
4 files changed, 27 insertions, 5 deletions
diff --git a/src/client.cpp b/src/client.cpp index 8bbaa83bd..e710624d5 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -260,7 +260,8 @@ Client::Client( m_localdb(NULL), m_script(NULL), m_mod_storage_save_timer(10.0f), - m_game_ui_flags(game_ui_flags) + m_game_ui_flags(game_ui_flags), + m_shutdown(false) { // Add local player m_env.setLocalPlayer(new LocalPlayer(this, playername)); @@ -346,6 +347,7 @@ const ModSpec* Client::getModSpec(const std::string &modname) const void Client::Stop() { + m_shutdown = true; // Don't disable this part when modding is disabled, it's used in builtin m_script->on_shutdown(); //request all client managed threads to stop @@ -361,14 +363,12 @@ void Client::Stop() bool Client::isShutdown() { - - if (!m_mesh_update_thread.isRunning()) return true; - - return false; + return m_shutdown || !m_mesh_update_thread.isRunning(); } Client::~Client() { + m_shutdown = true; m_con.Disconnect(); m_mesh_update_thread.stop(); diff --git a/src/client.h b/src/client.h index 84adf81d8..e565acd93 100644 --- a/src/client.h +++ b/src/client.h @@ -737,6 +737,7 @@ private: float m_mod_storage_save_timer; GameUIFlags *m_game_ui_flags; + bool m_shutdown; DISABLE_CLASS_COPY(Client); }; diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 7cb89188d..5f9474702 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -25,8 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gettext.h" #include "l_internal.h" #include "lua_api/l_item.h" +#include "mainmenumanager.h" #include "util/string.h" +extern MainGameCallback *g_gamecallback; + int ModApiClient::l_get_current_modname(lua_State *L) { lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME); @@ -107,6 +110,20 @@ int ModApiClient::l_send_respawn(lua_State *L) return 0; } +// disconnect() +int ModApiClient::l_disconnect(lua_State *L) +{ + // Stops badly written Lua code form causing boot loops + if (getClient(L)->isShutdown()) { + lua_pushboolean(L, false); + return 1; + } + + g_gamecallback->disconnect(); + lua_pushboolean(L, true); + return 1; +} + // gettext(text) int ModApiClient::l_gettext(lua_State *L) { @@ -178,4 +195,5 @@ void ModApiClient::Initialize(lua_State *L, int top) API_FCT(get_node); API_FCT(get_node_or_nil); API_FCT(get_wielded_item); + API_FCT(disconnect); } diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index b79cc670d..d7f92ac1c 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -41,6 +41,9 @@ private: // send_respawn() static int l_send_respawn(lua_State *L); + // disconnect() + static int l_disconnect(lua_State *L); + // gettext(text) static int l_gettext(lua_State *L); |