Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add confirmation on new player registration #6849

Merged
merged 4 commits into from Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/client.cpp
Expand Up @@ -318,6 +318,10 @@ void Client::step(float dtime)
initial_step = false;
}
else if(m_state == LC_Created) {
if (m_is_registration_confirmation_state) {
// Waiting confirmation
return;
}
float &counter = m_connection_reinit_timer;
counter -= dtime;
if(counter <= 0.0) {
Expand Down Expand Up @@ -974,6 +978,18 @@ void Client::sendInit(const std::string &playerName)
Send(&pkt);
}

void Client::promptConfirmRegistration(AuthMechanism chosen_auth_mechanism)
{
m_chosen_auth_mech = chosen_auth_mechanism;
m_is_registration_confirmation_state = true;
}

void Client::confirmRegistration()
{
m_is_registration_confirmation_state = false;
startAuth(m_chosen_auth_mech);
}

void Client::startAuth(AuthMechanism chosen_auth_mechanism)
{
m_chosen_auth_mech = chosen_auth_mechanism;
Expand Down
4 changes: 4 additions & 0 deletions src/client.h
Expand Up @@ -345,6 +345,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{ return m_proto_ver; }

bool connectedToServer();
void confirmRegistration();
bool m_is_registration_confirmation_state = false;
bool m_simple_singleplayer_mode;

float mediaReceiveProgress();

Expand Down Expand Up @@ -448,6 +451,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
static AuthMechanism choseAuthMech(const u32 mechs);

void sendInit(const std::string &playerName);
void promptConfirmRegistration(AuthMechanism chosen_auth_mechanism);
void startAuth(AuthMechanism chosen_auth_mechanism);
void sendDeletedBlocks(std::vector<v3s16> &blocks);
void sendGotBlocks(v3s16 block);
Expand Down
20 changes: 20 additions & 0 deletions src/client/renderingengine.cpp
Expand Up @@ -410,6 +410,26 @@ void RenderingEngine::_draw_load_screen(const std::wstring &text,
guitext->remove();
}

/*
Draws the menu scene including (optional) cloud background.
*/
void RenderingEngine::_draw_menu_scene(gui::IGUIEnvironment *guienv,
float dtime, bool clouds)
{
bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
if (cloud_menu_background) {
g_menuclouds->step(dtime * 3);
g_menuclouds->render();
get_video_driver()->beginScene(
true, true, video::SColor(255, 140, 186, 250));
g_menucloudsmgr->drawAll();
} else
get_video_driver()->beginScene(true, true, video::SColor(255, 0, 0, 0));

guienv->drawAll();
get_video_driver()->endScene();
}

std::vector<core::vector3d<u32>> RenderingEngine::getSupportedVideoModes()
{
IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
Expand Down
9 changes: 9 additions & 0 deletions src/client/renderingengine.h
Expand Up @@ -110,6 +110,12 @@ class RenderingEngine
text, guienv, tsrc, dtime, percent, clouds);
}

inline static void draw_menu_scene(
gui::IGUIEnvironment *guienv, float dtime, bool clouds)
{
s_singleton->_draw_menu_scene(guienv, dtime, clouds);
}

inline static void draw_scene(video::SColor skycolor, bool show_hud,
bool show_minimap, bool draw_wield_tool, bool draw_crosshair)
{
Expand Down Expand Up @@ -138,6 +144,9 @@ class RenderingEngine
ITextureSource *tsrc, float dtime = 0, int percent = 0,
bool clouds = true);

void _draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime = 0,
bool clouds = true);

void _draw_scene(video::SColor skycolor, bool show_hud, bool show_minimap,
bool draw_wield_tool, bool draw_crosshair);

Expand Down
42 changes: 30 additions & 12 deletions src/game.cpp
Expand Up @@ -41,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "gettext.h"
#include "gui/guiChatConsole.h"
#include "gui/guiConfirmRegistration.h"
#include "gui/guiFormSpecMenu.h"
#include "gui/guiKeyChangeMenu.h"
#include "gui/guiPasswordChange.h"
Expand Down Expand Up @@ -1302,6 +1303,7 @@ class Game {

EventManager *eventmgr = nullptr;
QuicktuneShortcutter *quicktune = nullptr;
bool registration_confirmation_shown = false;

std::unique_ptr<GameUI> m_game_ui;
GUIChatConsole *gui_chat_console = nullptr; // Free using ->Drop()
Expand Down Expand Up @@ -1900,10 +1902,10 @@ bool Game::initGui()

bool Game::connectToServer(const std::string &playername,
const std::string &password, std::string *address, u16 port,
bool *connect_ok, bool *aborted)
bool *connect_ok, bool *connection_aborted)
{
*connect_ok = false; // Let's not be overly optimistic
*aborted = false;
*connection_aborted = false;
bool local_server_mode = false;

showOverlayMessage("Resolving address...", 0, 15);
Expand Down Expand Up @@ -1946,6 +1948,8 @@ bool Game::connectToServer(const std::string &playername,
if (!client)
return false;

client->m_simple_singleplayer_mode = simple_singleplayer_mode;

infostream << "Connecting to server at ";
connect_address.print(&infostream);
infostream << std::endl;
Expand Down Expand Up @@ -1985,6 +1989,9 @@ bool Game::connectToServer(const std::string &playername,
}

// Break conditions
if (*connection_aborted)
break;

if (client->accessDenied()) {
*error_message = "Access denied. Reason: "
+ client->accessDeniedReason();
Expand All @@ -1994,21 +2001,32 @@ bool Game::connectToServer(const std::string &playername,
}

if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
*aborted = true;
*connection_aborted = true;
infostream << "Connect aborted [Escape]" << std::endl;
break;
}

wait_time += dtime;
// Only time out if we aren't waiting for the server we started
if (!address->empty() && wait_time > 10) {
*error_message = "Connection timed out.";
errorstream << *error_message << std::endl;
break;
}
if (client->m_is_registration_confirmation_state) {
if (registration_confirmation_shown) {
// Keep drawing the GUI
RenderingEngine::draw_menu_scene(guienv, dtime, true);
} else {
registration_confirmation_shown = true;
(new GUIConfirmRegistration(guienv, guienv->getRootGUIElement(), -1,
&g_menumgr, client, playername, password, *address, connection_aborted))->drop();
}
} else {
wait_time += dtime;
// Only time out if we aren't waiting for the server we started
if (!address->empty() && wait_time > 10) {
*error_message = "Connection timed out.";
errorstream << *error_message << std::endl;
break;
}

// Update status
showOverlayMessage("Connecting to server...", dtime, 20);
// Update status
showOverlayMessage("Connecting to server...", dtime, 20);
}
}
} catch (con::PeerNotFoundException &e) {
// TODO: Should something be done here? At least an info/error
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
@@ -1,5 +1,6 @@
set(gui_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiEngine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiFormSpecMenu.cpp
Expand Down