core.display_chat_message(dump(core.get_player_names()))
end
})
+
+core.register_chatcommand("disconnect", {
+ description = "Exit to main menu",
+ func = function(param)
+ core.disconnect()
+ end,
+})
### Client Environment
* `minetest.get_player_names()`
* Returns list of player names on server
+* `minetest.disconnect()`
+ * Disconnect from the server and exit to main menu.
+ * Returns `false` if the client is already disconnecting otherwise returns `true`.
### Misc.
* `minetest.parse_json(string[, nullvalue])`: returns something
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));
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
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();
float m_mod_storage_save_timer;
GameUIFlags *m_game_ui_flags;
+ bool m_shutdown;
DISABLE_CLASS_COPY(Client);
};
#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);
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)
{
API_FCT(get_node);
API_FCT(get_node_or_nil);
API_FCT(get_wielded_item);
+ API_FCT(disconnect);
}
// 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);