From 3b50b2766aeb09c9fc0ad0ea07426bb2187df3d7 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 17 Jul 2015 16:40:41 +0200 Subject: 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. --- src/client/clientlauncher.cpp | 24 +++++++++++++++--------- src/client/clientlauncher.h | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src/client') diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 50f0690d8..bad5c384c 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -168,8 +168,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) ChatBackend chat_backend; // If an error occurs, this is set to something by menu(). - // It is then displayed before the menu shows on the next call to menu() + // It is then displayed before the menu shows on the next call to menu() std::string error_message; + bool reconnect_requested = false; bool first_loop = true; @@ -197,7 +198,8 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) */ guiroot = guienv->addStaticText(L"", core::rect(0, 0, 10000, 10000)); - bool game_has_run = launch_game(error_message, game_params, cmd_args); + bool game_has_run = launch_game(error_message, reconnect_requested, + game_params, cmd_args); // If skip_main_menu, we only want to startup once if (skip_main_menu && !first_loop) @@ -233,6 +235,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) receiver->m_touchscreengui = new TouchScreenGUI(device, receiver); g_touchscreengui = receiver->m_touchscreengui; #endif + the_game( kill, random_input, @@ -245,6 +248,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) current_port, error_message, chat_backend, + &reconnect_requested, gamespec, simple_singleplayer_mode ); @@ -325,14 +329,16 @@ bool ClientLauncher::init_engine(int log_level) } bool ClientLauncher::launch_game(std::string &error_message, - GameParams &game_params, const Settings &cmd_args) + bool reconnect_requested, GameParams &game_params, + const Settings &cmd_args) { // Initialize menu data MainMenuData menudata; - menudata.address = address; - menudata.name = playername; - menudata.port = itos(game_params.socket_port); - menudata.errormessage = error_message; + menudata.address = address; + menudata.name = playername; + menudata.port = itos(game_params.socket_port); + menudata.script_data.errormessage = error_message; + menudata.script_data.reconnect_requested = reconnect_requested; error_message.clear(); @@ -379,11 +385,11 @@ bool ClientLauncher::launch_game(std::string &error_message, } } - if (!menudata.errormessage.empty()) { + if (!menudata.script_data.errormessage.empty()) { /* The calling function will pass this back into this function upon the * next iteration (if any) causing it to be displayed by the GUI */ - error_message = menudata.errormessage; + error_message = menudata.script_data.errormessage; return false; } diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h index 09f8c039a..49ceefc52 100644 --- a/src/client/clientlauncher.h +++ b/src/client/clientlauncher.h @@ -92,8 +92,8 @@ protected: void init_args(GameParams &game_params, const Settings &cmd_args); bool init_engine(int log_level); - bool launch_game(std::string &error_message, GameParams &game_params, - const Settings &cmd_args); + bool launch_game(std::string &error_message, bool reconnect_requested, + GameParams &game_params, const Settings &cmd_args); void main_menu(MainMenuData *menudata); bool create_engine_device(int log_level); -- cgit v1.2.3