summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2015-07-17 16:40:41 +0200
committerest31 <MTest31@outlook.com>2015-07-23 07:38:13 +0200
commit3b50b2766aeb09c9fc0ad0ea07426bb2187df3d7 (patch)
tree5ae54f8dcfc2b496a4937dc8ccf524d7c99f4e23 /src/script
parent1e0e85f82e030e761c36ba5a12427bec0fb4e4f2 (diff)
downloadminetest-3b50b2766aeb09c9fc0ad0ea07426bb2187df3d7.tar.gz
minetest-3b50b2766aeb09c9fc0ad0ea07426bb2187df3d7.tar.bz2
minetest-3b50b2766aeb09c9fc0ad0ea07426bb2187df3d7.zip
Optional reconnect functionality
Enable the server to request the client to reconnect. This can be done with the now extended minetest.request_shutdown([reason], [reconnect]) setting.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_mainmenu.cpp10
-rw-r--r--src/script/cpp_api/s_mainmenu.h11
-rw-r--r--src/script/lua_api/l_mainmenu.cpp22
-rw-r--r--src/script/lua_api/l_server.cpp4
-rw-r--r--src/script/lua_api/l_server.h2
5 files changed, 30 insertions, 19 deletions
diff --git a/src/script/cpp_api/s_mainmenu.cpp b/src/script/cpp_api/s_mainmenu.cpp
index 0bb247fa0..7430b0f4f 100644
--- a/src/script/cpp_api/s_mainmenu.cpp
+++ b/src/script/cpp_api/s_mainmenu.cpp
@@ -21,15 +21,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cpp_api/s_internal.h"
#include "common/c_converter.h"
-void ScriptApiMainMenu::setMainMenuErrorMessage(std::string errormessage)
+void ScriptApiMainMenu::setMainMenuData(MainMenuDataForScript *data)
{
SCRIPTAPI_PRECHECKHEADER
lua_getglobal(L, "gamedata");
int gamedata_idx = lua_gettop(L);
lua_pushstring(L, "errormessage");
- lua_pushstring(L, errormessage.c_str());
+ if (!data->errormessage.empty()) {
+ lua_pushstring(L, data->errormessage.c_str());
+ } else {
+ lua_pushnil(L);
+ }
lua_settable(L, gamedata_idx);
+ setboolfield(L, gamedata_idx, "reconnect_requested",
+ data->reconnect_requested);
lua_pop(L, 1);
}
diff --git a/src/script/cpp_api/s_mainmenu.h b/src/script/cpp_api/s_mainmenu.h
index 6994b578b..8d5895817 100644
--- a/src/script/cpp_api/s_mainmenu.h
+++ b/src/script/cpp_api/s_mainmenu.h
@@ -22,16 +22,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cpp_api/s_base.h"
#include "util/string.h"
+#include "../guiMainMenu.h"
-class ScriptApiMainMenu
- : virtual public ScriptApiBase
-{
+class ScriptApiMainMenu : virtual public ScriptApiBase {
public:
/**
- * set gamedata.errormessage to inform lua of an error
- * @param errormessage the error message
+ * Hand over MainMenuDataForScript to lua to inform lua of the content
+ * @param data the data
*/
- void setMainMenuErrorMessage(std::string errormessage);
+ void setMainMenuData(MainMenuDataForScript *data);
/**
* process events received from formspec
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index d209582e9..92311d6fc 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -114,15 +114,19 @@ int ModApiMainMenu::l_start(lua_State *L)
bool valid = false;
-
- engine->m_data->selected_world = getIntegerData(L, "selected_world",valid) -1;
- engine->m_data->simple_singleplayer_mode = getBoolData(L,"singleplayer",valid);
- engine->m_data->name = getTextData(L,"playername");
- engine->m_data->password = getTextData(L,"password");
- engine->m_data->address = getTextData(L,"address");
- engine->m_data->port = getTextData(L,"port");
- engine->m_data->serverdescription = getTextData(L,"serverdescription");
- engine->m_data->servername = getTextData(L,"servername");
+ MainMenuData *data = engine->m_data;
+
+ data->selected_world = getIntegerData(L, "selected_world",valid) -1;
+ data->simple_singleplayer_mode = getBoolData(L,"singleplayer",valid);
+ data->do_reconnect = getBoolData(L, "do_reconnect", valid);
+ if (!data->do_reconnect) {
+ data->name = getTextData(L,"playername");
+ data->password = getTextData(L,"password");
+ data->address = getTextData(L,"address");
+ data->port = getTextData(L,"port");
+ }
+ data->serverdescription = getTextData(L,"serverdescription");
+ data->servername = getTextData(L,"servername");
//close menu next time
engine->m_startgame = true;
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 558cc0885..96c0327df 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -30,7 +30,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// request_shutdown()
int ModApiServer::l_request_shutdown(lua_State *L)
{
- getServer(L)->requestShutdown();
+ const char *msg = lua_tolstring(L, 1, NULL);
+ bool reconnect = lua_toboolean(L, 2);
+ getServer(L)->requestShutdown(msg ? msg : "", reconnect);
return 0;
}
diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h
index fd85a8975..e14bef043 100644
--- a/src/script/lua_api/l_server.h
+++ b/src/script/lua_api/l_server.h
@@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class ModApiServer : public ModApiBase {
private:
- // request_shutdown()
+ // request_shutdown([message], [reconnect])
static int l_request_shutdown(lua_State *L);
// get_server_status()