Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config/stk_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ void STKConfig::init_defaults()
m_banana_item_return_ticks = -100;
m_bubblegum_item_return_ticks = -100;

m_max_username_length = 50;

m_score_increase.clear();
m_leader_intervals.clear();
m_switch_items.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/config/stk_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ class STKConfig : public NoCopy
* version. */
std::set<std::string> m_network_capabilities;

int m_max_username_length;


private:
/** True if stk_config has been loaded. This is necessary if the
* --stk-config command line parameter has been specified to avoid
Expand Down
32 changes: 21 additions & 11 deletions src/states_screens/online/register_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "utils/log.hpp"
#include "utils/translation.hpp"

#include "config/stk_config.hpp"

#ifdef __SWITCH__
extern "C" {
#define u64 uint64_t
Expand Down Expand Up @@ -254,10 +256,21 @@ void RegisterScreen::makeEntryFieldsVisible()
/** If necessary creates the local user.
* \param local_name Name of the local user.
*/
void RegisterScreen::handleLocalName(const stringw &local_name)
bool RegisterScreen::handleLocalName(const stringw &local_name)
{
if (local_name.size() == 0)
return;
if (local_name.empty())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've put actual + symbols in your code, this won't even compile properly.

{
m_info_widget->setErrorColor();
m_info_widget->setText(_("User name cannot be empty."), false);
return false;
}

if (local_name.size() > stk_config->m_max_username_length){
m_info_widget->setErrorColor();
m_info_widget->setText(_("Username is too long '%s'.", local_name),
false);
return false;
}

// If a local player with that name does not exist, create one
if(!PlayerManager::get()->getPlayer(local_name))
Expand All @@ -283,14 +296,17 @@ void RegisterScreen::handleLocalName(const stringw &local_name)
m_info_widget->setErrorColor();
m_info_widget->setText(_("Could not create player '%s'.", local_name),
false);
return false;
}
}
else
{
m_info_widget->setErrorColor();
m_info_widget->setText(_("Could not create player '%s'.", local_name),
false);
return false;
}
return true;
} // handleLocalName

// -----------------------------------------------------------------------------
Expand All @@ -301,15 +317,9 @@ void RegisterScreen::doRegister()
{
stringw local_name = getWidget<TextBoxWidget>("local_username")
->getText().trim();

if (local_name.empty())
{
m_info_widget->setErrorColor();
m_info_widget->setText(_("User name cannot be empty."), false);
return;
}

handleLocalName(local_name);
if (!handleLocalName(local_name))
return;

// If no online account is requested, don't register
if(m_account_mode==ACCOUNT_EXISTING_ONLINE)
Expand Down
2 changes: 1 addition & 1 deletion src/states_screens/online/register_screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RegisterScreen : public GUIEngine::Screen,
friend class GUIEngine::ScreenSingleton<RegisterScreen>;

void makeEntryFieldsVisible();
void handleLocalName(const irr::core::stringw &local_name);
bool handleLocalName(const irr::core::stringw &local_name);
void doRegister();
void init() OVERRIDE;
RegisterScreen();
Expand Down