Skip to content
Permalink
Browse files

Add confirmation on new player registration (#6849)

* Attempt to add registration confirmation

Using SRP auth mechanism, if server sent AUTH_MECHANISM_FIRST_SRP that means the player isn't exist.
Also tell player about the server and chosen username.
Local game has localhost as IP address of the server.
Add RenderingEngine::draw_menu_scene() to draw GUI and clouds background.
aborted -> connection_aborted

* Rewrite information message text

Client::promptConfirmRegister() -> Client::promptConfirmRegistration()
  • Loading branch information...
srifqi authored and nerzhul committed Jan 13, 2018
1 parent fad263d commit 792752997c5ae2aaa4f54d0a2e2af2a96d7d1e9f
@@ -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) {
@@ -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;
@@ -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();

@@ -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);
@@ -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);
@@ -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)
{
@@ -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);

@@ -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"
@@ -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()
@@ -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);
@@ -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;
@@ -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();
@@ -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
@@ -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

0 comments on commit 7927529

Please sign in to comment.
You can’t perform that action at this time.