← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1797702-spaces-in-names into lp:widelands

 

Toni Förster has proposed merging lp:~widelands-dev/widelands/bug-1797702-spaces-in-names into lp:widelands with lp:~widelands-dev/widelands/bug-1827786-metaserver-login-box 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)
Related bugs:
  Bug #1797702 in widelands: "Player names in chat commands can't contain whitespace"
  https://bugs.launchpad.net/widelands/+bug/1797702

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1797702-spaces-in-names/+merge/367123
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1797702-spaces-in-names into lp:widelands.
=== modified file 'src/network/gamehost.cc'
--- src/network/gamehost.cc	2019-04-29 16:22:08 +0000
+++ src/network/gamehost.cc	2019-05-08 15:04:54 +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-08 15:04:53 +0000
+++ src/ui_basic/editbox.h	2019-05-08 15:04:54 +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-04-09 16:43:49 +0000
+++ src/ui_fsmenu/netsetup_lan.cc	2019-05-08 15:04:54 +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());
 }
 


Follow ups