widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #17029
[Merge] lp:~widelands-dev/widelands/bug-1797702-spaces-in-names-clean-start into lp:widelands
Toni Förster has proposed merging lp:~widelands-dev/widelands/bug-1797702-spaces-in-names-clean-start into lp:widelands with lp:~widelands-dev/widelands/bug-1827786-metaserver-login-box-clean-start as a prerequisite.
Commit message:
rework netsetup
- allowed characters are limited
- login with empty username not allowed
- if username ist taken append number
- don't join game with empty username
editbox
- added has_warning()
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1797702-spaces-in-names-clean-start/+merge/367314
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1797702-spaces-in-names-clean-start into lp:widelands.
=== modified file 'src/network/gamehost.cc'
--- src/network/gamehost.cc 2019-05-11 18:50:30 +0000
+++ src/network/gamehost.cc 2019-05-11 23:01:57 +0000
@@ -1621,13 +1621,13 @@
// Assign the player a name, preferably the name chosen by the client
if (playername.empty()) // Make sure there is at least a name base.
- playername = _("Player");
+ playername = "Player";
std::string effective_name = playername;
if (has_user_name(effective_name, client.usernum)) {
- uint32_t i = 2;
+ uint32_t i = 1;
do {
- effective_name = (boost::format(_("Player %u")) % i++).str();
+ effective_name = (boost::format("%s%u") % playername % i++).str();
} while (has_user_name(effective_name, client.usernum));
}
=== modified file 'src/ui_basic/editbox.h'
--- src/ui_basic/editbox.h 2019-05-11 23:01:57 +0000
+++ src/ui_basic/editbox.h 2019-05-11 23:01:57 +0000
@@ -76,6 +76,10 @@
warning_ = warn;
}
+ bool has_warning() {
+ return warning_;
+ }
+
private:
std::unique_ptr<EditBoxImpl> m_;
=== modified file 'src/ui_fsmenu/netsetup_lan.cc'
--- src/ui_fsmenu/netsetup_lan.cc 2019-05-11 18:50:30 +0000
+++ src/ui_fsmenu/netsetup_lan.cc 2019-05-11 23:01:57 +0000
@@ -136,6 +136,7 @@
void FullscreenMenuNetSetupLAN::think() {
FullscreenMenuBase::think();
+ change_playername();
discovery.run();
}
@@ -186,7 +187,7 @@
assert(opengames.has_selection());
const NetOpenGame* const game = opengames.get_selected();
// Only join games that are open
- if (game->info.state == LAN_GAME_OPEN) {
+ if (game->info.state == LAN_GAME_OPEN || !playername.has_warning()) {
clicked_joingame();
}
}
@@ -247,6 +248,24 @@
}
void FullscreenMenuNetSetupLAN::change_playername() {
+ playername.set_warning(false);
+ playername.set_tooltip("");
+ hostgame.set_enabled(true);
+
+ if (playername.text().find_first_not_of("abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.+-_") <= playername.text().size()
+ || playername.text().empty()) {
+ playername.set_warning(true);
+ playername.set_tooltip(_("Enter a valid nickname. This value may contain only "
+ "English letters, numbers, and @ . + - _ characters."));
+ joingame.set_enabled(false);
+ hostgame.set_enabled(false);
+ return;
+ }
+ if (!hostname.text().empty()) {
+ joingame.set_enabled(true);
+ }
+
g_options.pull_section("global").set_string("nickname", playername.text());
}
References