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

Proposed by Toni Förster
Status: Superseded
Proposed branch: lp:~widelands-dev/widelands/bug-1797702-spaces-in-names
Merge into: lp:widelands
Diff against target: 626 lines (+214/-107)
11 files modified
src/network/gamehost.cc (+3/-3)
src/network/internet_gaming.cc (+7/-4)
src/network/internet_gaming.h (+6/-6)
src/ui_basic/editbox.cc (+22/-2)
src/ui_basic/editbox.h (+9/-0)
src/ui_fsmenu/internet_lobby.cc (+27/-14)
src/ui_fsmenu/multiplayer.cc (+40/-38)
src/ui_fsmenu/multiplayer.h (+0/-1)
src/ui_fsmenu/netsetup_lan.cc (+20/-1)
src/wui/login_box.cc (+72/-33)
src/wui/login_box.h (+8/-5)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1797702-spaces-in-names
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+367122@code.launchpad.net

This proposal has been superseded by a proposal from 2019-05-08.

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()

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:09 +0000
@@ -1621,13 +1621,13 @@
16211621
1622 // Assign the player a name, preferably the name chosen by the client1622 // Assign the player a name, preferably the name chosen by the client
1623 if (playername.empty()) // Make sure there is at least a name base.1623 if (playername.empty()) // Make sure there is at least a name base.
1624 playername = _("Player");1624 playername = "Player";
1625 std::string effective_name = playername;1625 std::string effective_name = playername;
16261626
1627 if (has_user_name(effective_name, client.usernum)) {1627 if (has_user_name(effective_name, client.usernum)) {
1628 uint32_t i = 2;1628 uint32_t i = 1;
1629 do {1629 do {
1630 effective_name = (boost::format(_("Player %u")) % i++).str();1630 effective_name = (boost::format("%s%u") % playername % i++).str();
1631 } while (has_user_name(effective_name, client.usernum));1631 } while (has_user_name(effective_name, client.usernum));
1632 }1632 }
16331633
16341634
=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc 2019-05-05 22:50:03 +0000
+++ src/network/internet_gaming.cc 2019-05-08 15:04:09 +0000
@@ -487,7 +487,7 @@
487 InternetGame* ing = new InternetGame();487 InternetGame* ing = new InternetGame();
488 ing->name = packet.string();488 ing->name = packet.string();
489 ing->build_id = packet.string();489 ing->build_id = packet.string();
490 ing->connectable = (packet.string() == INTERNET_GAME_SETUP);490 ing->connectable = packet.string();
491 gamelist_.push_back(*ing);491 gamelist_.push_back(*ing);
492492
493 bool found = false;493 bool found = false;
@@ -498,10 +498,13 @@
498 break;498 break;
499 }499 }
500 }500 }
501 if (!found)501 if (!found && ing->connectable != INTERNET_GAME_RUNNING &&
502 (ing->build_id == build_id() || (ing->build_id.compare(0, 6, "build-") != 0
503 && build_id().compare(0, 6, "build-") != 0))) {
502 format_and_add_chat(504 format_and_add_chat(
503 "", "", true,505 "", "", true,
504 (boost::format(_("The game %s is now available")) % ing->name).str());506 (boost::format(_("The game %s is now available")) % ing->name).str());
507 }
505508
506 delete ing;509 delete ing;
507 ing = nullptr;510 ing = nullptr;
508511
=== modified file 'src/network/internet_gaming.h'
--- src/network/internet_gaming.h 2019-02-23 11:00:49 +0000
+++ src/network/internet_gaming.h 2019-05-08 15:04:09 +0000
@@ -43,7 +43,7 @@
43struct InternetGame {43struct InternetGame {
44 std::string name;44 std::string name;
45 std::string build_id;45 std::string build_id;
46 bool connectable;46 std::string connectable;
47};47};
4848
49/**49/**
@@ -178,6 +178,11 @@
178 return true;178 return true;
179 }179 }
180180
181 void format_and_add_chat(const std::string& from,
182 const std::string& to,
183 bool system,
184 const std::string& msg);
185
181private:186private:
182 InternetGaming();187 InternetGaming();
183188
@@ -202,11 +207,6 @@
202 bool str2bool(std::string);207 bool str2bool(std::string);
203 std::string bool2str(bool);208 std::string bool2str(bool);
204209
205 void format_and_add_chat(const std::string& from,
206 const std::string& to,
207 bool system,
208 const std::string& msg);
209
210 /**210 /**
211 * Does the real work of the login.211 * Does the real work of the login.
212 * \param relogin Whether this is a relogin. Only difference is that212 * \param relogin Whether this is a relogin. Only difference is that
213213
=== modified file 'src/ui_basic/editbox.cc'
--- src/ui_basic/editbox.cc 2019-04-09 16:43:49 +0000
+++ src/ui_basic/editbox.cc 2019-05-08 15:04:09 +0000
@@ -85,7 +85,8 @@
85 : Panel(parent, x, y, w, h > 0 ? h : text_height(font_size) + 2 * margin_y),85 : Panel(parent, x, y, w, h > 0 ? h : text_height(font_size) + 2 * margin_y),
86 m_(new EditBoxImpl),86 m_(new EditBoxImpl),
87 history_active_(false),87 history_active_(false),
88 history_position_(-1) {88 history_position_(-1),
89 warning_(false) {
89 set_thinks(false);90 set_thinks(false);
9091
91 m_->background_style = g_gr->styles().editbox_style(style);92 m_->background_style = g_gr->styles().editbox_style(style);
@@ -346,7 +347,7 @@
346 draw_background(dst, *m_->background_style);347 draw_background(dst, *m_->background_style);
347348
348 // Draw border.349 // Draw border.
349 if (get_w() >= 2 && get_h() >= 2) {350 if (get_w() >= 2 && get_h() >= 2 && !warning_) {
350 static const RGBColor black(0, 0, 0);351 static const RGBColor black(0, 0, 0);
351352
352 // bottom edge353 // bottom edge
@@ -359,6 +360,25 @@
359 // left edge360 // left edge
360 dst.fill_rect(Recti(0, 0, 1, get_h() - 1), black);361 dst.fill_rect(Recti(0, 0, 1, get_h() - 1), black);
361 dst.fill_rect(Recti(1, 0, 1, get_h() - 2), black);362 dst.fill_rect(Recti(1, 0, 1, get_h() - 2), black);
363
364 } else {
365 // Draw a red border for warnings.
366 static const RGBColor red(255, 22, 22);
367
368 // bottom edge
369 dst.fill_rect(Recti(0, get_h() - 2, get_w(), 2), red);
370 // right edge
371 dst.fill_rect(Recti(get_w() - 2, 0, 2, get_h() -2), red);
372 // top edge
373 dst.fill_rect(Recti(0, 0, get_w() - 1, 1), red);
374 dst.fill_rect(Recti(0, 1, get_w() - 2, 1), red);
375 dst.brighten_rect(Recti(0, 0, get_w() - 1, 1), BUTTON_EDGE_BRIGHT_FACTOR);
376 dst.brighten_rect(Recti(0, 1, get_w() - 2, 1), BUTTON_EDGE_BRIGHT_FACTOR);
377 // left edge
378 dst.fill_rect(Recti(0, 0, 1, get_h() - 1), red);
379 dst.fill_rect(Recti(1, 0, 1, get_h() - 2), red);
380 dst.brighten_rect(Recti(0, 0, 1, get_h() - 1), BUTTON_EDGE_BRIGHT_FACTOR);
381 dst.brighten_rect(Recti(1, 0, 1, get_h() - 2), BUTTON_EDGE_BRIGHT_FACTOR);
362 }382 }
363383
364 if (has_focus()) {384 if (has_focus()) {
365385
=== modified file 'src/ui_basic/editbox.h'
--- src/ui_basic/editbox.h 2019-02-23 11:00:49 +0000
+++ src/ui_basic/editbox.h 2019-05-08 15:04:09 +0000
@@ -72,6 +72,14 @@
7272
73 void draw(RenderTarget&) override;73 void draw(RenderTarget&) override;
7474
75 void set_warning(bool warn) {
76 warning_ = warn;
77 }
78
79 bool has_warning() {
80 return warning_;
81 }
82
75private:83private:
76 std::unique_ptr<EditBoxImpl> m_;84 std::unique_ptr<EditBoxImpl> m_;
7785
@@ -80,6 +88,7 @@
80 bool history_active_;88 bool history_active_;
81 int16_t history_position_;89 int16_t history_position_;
82 std::string history_[CHAT_HISTORY_SIZE];90 std::string history_[CHAT_HISTORY_SIZE];
91 bool warning_;
83};92};
84} // namespace UI93} // namespace UI
8594
8695
=== modified file 'src/ui_fsmenu/internet_lobby.cc'
--- src/ui_fsmenu/internet_lobby.cc 2019-05-05 00:22:27 +0000
+++ src/ui_fsmenu/internet_lobby.cc 2019-05-08 15:04:09 +0000
@@ -63,7 +63,7 @@
63 // Text labels63 // Text labels
64 title(this, get_w() / 2, get_h() / 20, _("Metaserver Lobby"), UI::Align::kCenter),64 title(this, get_w() / 2, get_h() / 20, _("Metaserver Lobby"), UI::Align::kCenter),
65 clients_(this, get_w() * 4 / 125, get_h() * 15 / 100, _("Clients online:")),65 clients_(this, get_w() * 4 / 125, get_h() * 15 / 100, _("Clients online:")),
66 opengames_(this, get_w() * 17 / 25, get_h() * 15 / 100, _("List of games:")),66 opengames_(this, get_w() * 17 / 25, get_h() * 15 / 100, _("Open Games:")),
67 servername_(this, get_w() * 17 / 25, get_h() * 63 / 100, _("Name of your server:")),67 servername_(this, get_w() * 17 / 25, get_h() * 63 / 100, _("Name of your server:")),
6868
69 // Buttons69 // Buttons
@@ -223,28 +223,37 @@
223 // List and button cleanup223 // List and button cleanup
224 opengames_list_.clear();224 opengames_list_.clear();
225 hostgame_.set_enabled(true);225 hostgame_.set_enabled(true);
226 edit_servername_.set_tooltip("");
227 edit_servername_.set_warning(false);
226 joingame_.set_enabled(false);228 joingame_.set_enabled(false);
227 std::string localservername = edit_servername_.text();229 std::string localservername = edit_servername_.text();
230 std::string localbuildid = build_id();
228231
229 if (games != nullptr) { // If no communication error occurred, fill the list.232 if (games != nullptr) { // If no communication error occurred, fill the list.
230 for (const InternetGame& game : *games) {233 for (const InternetGame& game : *games) {
231 const Image* pic;234 const Image* pic;
232 if (game.connectable) {235 if (game.connectable == INTERNET_GAME_SETUP && game.build_id == localbuildid) {
233 if (game.build_id == build_id())236 // only clients with the same build number are displayed
234 pic = g_gr->images().get("images/ui_basic/continue.png");237 pic = g_gr->images().get("images/ui_basic/continue.png");
235 else {238 opengames_list_.add(game.name, game, pic, false, game.build_id);
239 } else if (game.connectable == INTERNET_GAME_SETUP &&
240 game.build_id.compare(0, 6, "build-") != 0 &&
241 localbuildid.compare(0, 6, "build-") != 0) {
242 // only development clients are allowed to see games openend by such
236 pic = g_gr->images().get("images/ui_basic/different.png");243 pic = g_gr->images().get("images/ui_basic/different.png");
237 }244 opengames_list_.add(game.name, game, pic, false, game.build_id);
238 } else {
239 pic = g_gr->images().get("images/ui_basic/stop.png");
240 }245 }
241 // If one of the servers has the same name as the local name of the246 // If one of the servers has the same name as the local name of the
242 // clients server, we disable the 'hostgame' button to avoid having more247 // clients server, we disable the 'hostgame' button to avoid having more
243 // than one server with the same name.248 // than one server with the same name.
244 if (game.name == localservername) {249 if (game.name == localservername) {
245 hostgame_.set_enabled(false);250 hostgame_.set_enabled(false);
251 edit_servername_.set_warning(true);
252 edit_servername_.set_tooltip(
253 (boost::format("%s%s%s%s%s%s%s%s") % _("The game ") % "<font bold=yes color="
254 % UI_FONT_CLR_WARNING.hex_value() % ">" % game.name % "</font>"
255 % _(" is already running. ") % _("Please choose a different name.")).str());
246 }256 }
247 opengames_list_.add(game.name, game, pic, false, game.build_id);
248 }257 }
249 }258 }
250}259}
@@ -341,10 +350,8 @@
341 // remove focus from chat350 // remove focus from chat
342 if (opengames_list_.has_selection()) {351 if (opengames_list_.has_selection()) {
343 const InternetGame* game = &opengames_list_.get_selected();352 const InternetGame* game = &opengames_list_.get_selected();
344 if (game->connectable)353 if (game->connectable == INTERNET_GAME_SETUP)
345 joingame_.set_enabled(true);354 joingame_.set_enabled(true);
346 else
347 joingame_.set_enabled(false);
348 }355 }
349}356}
350357
@@ -353,7 +360,7 @@
353 // if the game is open try to connect it, if not do nothing.360 // if the game is open try to connect it, if not do nothing.
354 if (opengames_list_.has_selection()) {361 if (opengames_list_.has_selection()) {
355 const InternetGame* game = &opengames_list_.get_selected();362 const InternetGame* game = &opengames_list_.get_selected();
356 if (game->connectable)363 if (game->connectable == INTERNET_GAME_SETUP)
357 clicked_joingame();364 clicked_joingame();
358 }365 }
359}366}
@@ -362,7 +369,8 @@
362void FullscreenMenuInternetLobby::change_servername() {369void FullscreenMenuInternetLobby::change_servername() {
363 // Allow client to enter a servername manually370 // Allow client to enter a servername manually
364 hostgame_.set_enabled(true);371 hostgame_.set_enabled(true);
365372 edit_servername_.set_tooltip("");
373 edit_servername_.set_warning(false);
366 // Check whether a server of that name is already open.374 // Check whether a server of that name is already open.
367 // And disable 'hostgame' button if yes.375 // And disable 'hostgame' button if yes.
368 const std::vector<InternetGame>* games = InternetGaming::ref().games();376 const std::vector<InternetGame>* games = InternetGaming::ref().games();
@@ -370,6 +378,11 @@
370 for (const InternetGame& game : *games) {378 for (const InternetGame& game : *games) {
371 if (game.name == edit_servername_.text()) {379 if (game.name == edit_servername_.text()) {
372 hostgame_.set_enabled(false);380 hostgame_.set_enabled(false);
381 edit_servername_.set_warning(true);
382 edit_servername_.set_tooltip(
383 (boost::format("%s%s%s%s%s%s%s%s") % _("The game ") % "<font bold=yes color="
384 % UI_FONT_CLR_WARNING.hex_value() % ">" % game.name % "</font>"
385 % _(" is already running. ") % _("Please choose a different name.")).str());
373 }386 }
374 }387 }
375 }388 }
376389
=== modified file 'src/ui_fsmenu/multiplayer.cc'
--- src/ui_fsmenu/multiplayer.cc 2019-02-23 11:00:49 +0000
+++ src/ui_fsmenu/multiplayer.cc 2019-05-08 15:04:09 +0000
@@ -58,21 +58,46 @@
58 vbox_.add_inf_space();58 vbox_.add_inf_space();
59 vbox_.add(&back, UI::Box::Resizing::kFullSize);59 vbox_.add(&back, UI::Box::Resizing::kFullSize);
6060
61 Section& s = g_options.pull_section("global");61 showloginbox =
62 auto_log_ = s.get_bool("auto_log", false);
63 if (auto_log_) {
64 showloginbox =
65 new UI::Button(this, "login_dialog", 0, 0, 0, 0, UI::ButtonStyle::kFsMenuSecondary,62 new UI::Button(this, "login_dialog", 0, 0, 0, 0, UI::ButtonStyle::kFsMenuSecondary,
66 g_gr->images().get("images/ui_basic/continue.png"), _("Show login dialog"));63 g_gr->images().get("images/ui_basic/continue.png"), _("Show login dialog"));
67 showloginbox->sigclicked.connect(64 showloginbox->sigclicked.connect(
68 boost::bind(&FullscreenMenuMultiPlayer::show_internet_login, boost::ref(*this)));65 boost::bind(&FullscreenMenuMultiPlayer::show_internet_login, boost::ref(*this)));
69 }
70 layout();66 layout();
71}67}
7268
73/// called if the showloginbox button was pressed69/// called if the showloginbox button was pressed
74void FullscreenMenuMultiPlayer::show_internet_login() {70void FullscreenMenuMultiPlayer::show_internet_login() {
75 auto_log_ = false;71 Section& s = g_options.pull_section("global");
72 LoginBox lb(*this);
73 if (lb.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kOk) {
74 nickname_ = lb.get_nickname();
75 s.set_string("nickname", nickname_);
76 /// NOTE: The password is only stored (in memory and on disk) and transmitted (over the
77 /// network
78 /// to the metaserver) as cryptographic hash. This does NOT mean that the password is
79 /// stored
80 /// securely on the local disk. While the password should be secure while transmitted to
81 /// the
82 /// metaserver (no-one can use the transmitted data to log in as the user) this is not the
83 /// case
84 /// for local storage. The stored hash of the password makes it hard to look at the
85 /// configuration
86 /// file and figure out the plaintext password to, e.g., log in on the forum. However, the
87 /// stored hash can be copied to another system and used to log in as the user on the
88 /// metaserver.
89 // Further note: SHA-1 is considered broken and shouldn't be used anymore. But since the
90 // passwords on the server are protected by SHA-1 we have to use it here, too
91 if (lb.get_password() != "*****") {
92 password_ = crypto::sha1(lb.get_password());
93 s.set_string("password_sha1", password_);
94 }
95
96 register_ = lb.registered();
97 s.set_bool("registered", lb.registered());
98 } else {
99 return;
100 }
76 internet_login();101 internet_login();
77}102}
78103
@@ -90,37 +115,14 @@
90 */115 */
91void FullscreenMenuMultiPlayer::internet_login() {116void FullscreenMenuMultiPlayer::internet_login() {
92 Section& s = g_options.pull_section("global");117 Section& s = g_options.pull_section("global");
93 if (auto_log_) {118
94 nickname_ = s.get_string("nickname", _("nobody"));119 nickname_ = s.get_string("nickname", _(" "));
95 password_ = s.get_string("password_sha1", "nobody");120 password_ = s.get_string("password_sha1", "nobody");
96 register_ = s.get_bool("registered", false);121 register_ = s.get_bool("registered", false);
97 } else {122
98 LoginBox lb(*this);123 if (nickname_ == " ") {
99 if (lb.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kOk) {124 show_internet_login();
100 nickname_ = lb.get_nickname();125 return;
101 /// NOTE: The password is only stored (in memory and on disk) and transmitted (over the
102 /// network
103 /// to the metaserver) as cryptographic hash. This does NOT mean that the password is
104 /// stored
105 /// securely on the local disk. While the password should be secure while transmitted to
106 /// the
107 /// metaserver (no-one can use the transmitted data to log in as the user) this is not the
108 /// case
109 /// for local storage. The stored hash of the password makes it hard to look at the
110 /// configuration
111 /// file and figure out the plaintext password to, e.g., log in on the forum. However, the
112 /// stored hash can be copied to another system and used to log in as the user on the
113 /// metaserver.
114 // Further note: SHA-1 is considered broken and shouldn't be used anymore. But since the
115 // passwords on the server are protected by SHA-1 we have to use it here, too
116 password_ = crypto::sha1(lb.get_password());
117 register_ = lb.registered();
118
119 s.set_bool("registered", lb.registered());
120 s.set_bool("auto_log", lb.set_automaticlog());
121 } else {
122 return;
123 }
124 }126 }
125127
126 // Try to connect to the metaserver128 // Try to connect to the metaserver
127129
=== modified file 'src/ui_fsmenu/multiplayer.h'
--- src/ui_fsmenu/multiplayer.h 2019-02-23 11:00:49 +0000
+++ src/ui_fsmenu/multiplayer.h 2019-05-08 15:04:09 +0000
@@ -61,7 +61,6 @@
61 std::string nickname_;61 std::string nickname_;
62 std::string password_;62 std::string password_;
63 bool register_;63 bool register_;
64 bool auto_log_;
65};64};
6665
67#endif // end of include guard: WL_UI_FSMENU_MULTIPLAYER_H66#endif // end of include guard: WL_UI_FSMENU_MULTIPLAYER_H
6867
=== 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:09 +0000
@@ -136,6 +136,7 @@
136136
137void FullscreenMenuNetSetupLAN::think() {137void FullscreenMenuNetSetupLAN::think() {
138 FullscreenMenuBase::think();138 FullscreenMenuBase::think();
139 change_playername();
139140
140 discovery.run();141 discovery.run();
141}142}
@@ -186,7 +187,7 @@
186 assert(opengames.has_selection());187 assert(opengames.has_selection());
187 const NetOpenGame* const game = opengames.get_selected();188 const NetOpenGame* const game = opengames.get_selected();
188 // Only join games that are open189 // Only join games that are open
189 if (game->info.state == LAN_GAME_OPEN) {190 if (game->info.state == LAN_GAME_OPEN || !playername.has_warning()) {
190 clicked_joingame();191 clicked_joingame();
191 }192 }
192}193}
@@ -247,6 +248,24 @@
247}248}
248249
249void FullscreenMenuNetSetupLAN::change_playername() {250void FullscreenMenuNetSetupLAN::change_playername() {
251 playername.set_warning(false);
252 playername.set_tooltip("");
253 hostgame.set_enabled(true);
254
255 if (playername.text().find_first_not_of("abcdefghijklmnopqrstuvwxyz"
256 "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.+-_") <= playername.text().size()
257 || playername.text().empty()) {
258 playername.set_warning(true);
259 playername.set_tooltip(_("Enter a valid nickname. This value may contain only "
260 "English letters, numbers, and @ . + - _ characters."));
261 joingame.set_enabled(false);
262 hostgame.set_enabled(false);
263 return;
264 }
265 if (!hostname.text().empty()) {
266 joingame.set_enabled(true);
267 }
268
250 g_options.pull_section("global").set_string("nickname", playername.text());269 g_options.pull_section("global").set_string("nickname", playername.text());
251}270}
252271
253272
=== modified file 'src/wui/login_box.cc'
--- src/wui/login_box.cc 2019-02-23 11:00:49 +0000
+++ src/wui/login_box.cc 2019-05-08 15:04:09 +0000
@@ -26,7 +26,7 @@
26#include "ui_basic/messagebox.h"26#include "ui_basic/messagebox.h"
2727
28LoginBox::LoginBox(Panel& parent)28LoginBox::LoginBox(Panel& parent)
29 : Window(&parent, "login_box", 0, 0, 500, 220, _("Metaserver login")) {29 : Window(&parent, "login_box", 0, 0, 500, 260, _("Metaserver login")) {
30 center_to_parent();30 center_to_parent();
3131
32 int32_t margin = 10;32 int32_t margin = 10;
@@ -36,59 +36,53 @@
36 eb_nickname = new UI::EditBox(this, 150, margin, 330, 20, 2, UI::PanelStyle::kWui);36 eb_nickname = new UI::EditBox(this, 150, margin, 330, 20, 2, UI::PanelStyle::kWui);
37 eb_password = new UI::EditBox(this, 150, 40, 330, 20, 2, UI::PanelStyle::kWui);37 eb_password = new UI::EditBox(this, 150, 40, 330, 20, 2, UI::PanelStyle::kWui);
3838
39 pwd_warning =39 cb_register = new UI::Checkbox(this, Vector2i(margin, 70), _("Log in to a registered account"),
40 new UI::MultilineTextarea(this, margin, 65, 505, 50, UI::PanelStyle::kWui,
41 _("WARNING: Password will be shown and saved readable!"));
42
43 cb_register = new UI::Checkbox(this, Vector2i(margin, 110), _("Log in to a registered account"),
44 "", get_inner_w() - 2 * margin);40 "", get_inner_w() - 2 * margin);
45 cb_auto_log = new UI::Checkbox(this, Vector2i(margin, 135),41
46 _("Automatically use this login information from now on."), "",42 register_account = new UI::MultilineTextarea(this, margin, 105, 470, 140, UI::PanelStyle::kWui,
47 get_inner_w() - 2 * margin);43 _("To register an account, please visit our website: \n\n"
4844 "https://widelands.org/accounts/register/ \n\n"
49 UI::Button* loginbtn = new UI::Button(45 "Log in to your newly created account and set an \n"
46 "online gaming password on your profile page."));
47
48 loginbtn = new UI::Button(
50 this, "login",49 this, "login",
51 UI::g_fh->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 :50 UI::g_fh->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 :
52 (get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2,51 (get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2,
53 get_inner_h() - 20 - margin, 200, 20, UI::ButtonStyle::kWuiPrimary, _("Login"));52 get_inner_h() - 20 - margin, 200, 20, UI::ButtonStyle::kWuiPrimary, _("Login"));
54 loginbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_ok, boost::ref(*this)));53
55 UI::Button* cancelbtn = new UI::Button(54 cancelbtn = new UI::Button(
56 this, "cancel",55 this, "cancel",
57 UI::g_fh->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2 :56 UI::g_fh->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2 :
58 (get_inner_w() / 2 - 200) / 2,57 (get_inner_w() / 2 - 200) / 2,
59 loginbtn->get_y(), 200, 20, UI::ButtonStyle::kWuiSecondary, _("Cancel"));58 loginbtn->get_y(), 200, 20, UI::ButtonStyle::kWuiSecondary, _("Cancel"));
59
60 loginbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_ok, boost::ref(*this)));
60 cancelbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_back, boost::ref(*this)));61 cancelbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_back, boost::ref(*this)));
62 eb_nickname->changed.connect(boost::bind(&LoginBox::change_playername, this));
6163
62 Section& s = g_options.pull_section("global");64 Section& s = g_options.pull_section("global");
63 eb_nickname->set_text(s.get_string("nickname", _("nobody")));65 eb_nickname->set_text(s.get_string("nickname", _("nobody")));
64 cb_register->set_state(s.get_bool("registered", false));66 cb_register->set_state(s.get_bool("registered", false));
67
68 if (registered()) {
69 eb_password->set_text("*****");
70 } else {
71 eb_password->set_can_focus(false);
72 }
73
65 eb_nickname->focus();74 eb_nickname->focus();
66}75}
6776
77/// think function of the UI (main loop)
78void LoginBox::think() {
79 verify_input();
80}
81
68/**82/**
69 * called, if "login" is pressed.83 * called, if "login" is pressed.
70 */84 */
71void LoginBox::clicked_ok() {85void LoginBox::clicked_ok() {
72 // Check if all needed input fields are valid
73 if (eb_nickname->text().empty()) {
74 UI::WLMessageBox mb(
75 this, _("Empty Nickname"), _("Please enter a nickname!"), UI::WLMessageBox::MBoxType::kOk);
76 mb.run<UI::Panel::Returncodes>();
77 return;
78 }
79 if (eb_nickname->text().find(' ') <= eb_nickname->text().size()) {
80 UI::WLMessageBox mb(this, _("Space in Nickname"),
81 _("Sorry, but spaces are not allowed in nicknames!"),
82 UI::WLMessageBox::MBoxType::kOk);
83 mb.run<UI::Panel::Returncodes>();
84 return;
85 }
86 if (eb_password->text().empty() && cb_register->get_state()) {
87 UI::WLMessageBox mb(this, _("Empty Password"), _("Please enter your password!"),
88 UI::WLMessageBox::MBoxType::kOk);
89 mb.run<UI::Panel::Returncodes>();
90 return;
91 }
92 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kOk);86 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kOk);
93}87}
9488
@@ -97,6 +91,11 @@
97 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);91 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
98}92}
9993
94/// Calles when nickname was changed
95void LoginBox::change_playername() {
96 cb_register->set_state(false);
97}
98
100bool LoginBox::handle_key(bool down, SDL_Keysym code) {99bool LoginBox::handle_key(bool down, SDL_Keysym code) {
101 if (down) {100 if (down) {
102 switch (code.sym) {101 switch (code.sym) {
@@ -113,3 +112,43 @@
113 }112 }
114 return UI::Panel::handle_key(down, code);113 return UI::Panel::handle_key(down, code);
115}114}
115
116void LoginBox::verify_input() {
117 // Check if all needed input fields are valid
118 loginbtn->set_enabled(true);
119 eb_nickname->set_tooltip("");
120 eb_password->set_tooltip("");
121 eb_nickname->set_warning(false);
122 eb_password->set_warning(false);
123
124 if (eb_nickname->text().empty()) {
125 eb_nickname->set_warning(true);
126 eb_nickname->set_tooltip(_("Please enter a nickname!"));
127 loginbtn->set_enabled(false);
128 }
129
130 if (eb_nickname->text().find_first_not_of("abcdefghijklmnopqrstuvwxyz"
131 "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.+-_") <= eb_nickname->text().size()) {
132 eb_nickname->set_warning(true);
133 eb_nickname->set_tooltip(_("Enter a valid nickname. This value may contain only "
134 "English letters, numbers, and @ . + - _ characters."));
135 loginbtn->set_enabled(false);
136
137 }
138
139 if (eb_password->text().empty() && cb_register->get_state()) {
140 eb_password->set_warning(true);
141 eb_password->set_tooltip(_("Please enter your password!"));
142 eb_password->focus();
143 loginbtn->set_enabled(false);
144 }
145
146 if (!eb_password->text().empty() && !cb_register->get_state()) {
147 eb_password->set_text("");
148 eb_password->set_can_focus(false);
149 }
150
151 if (eb_password->has_focus() && eb_password->text() == "*****") {
152 eb_password->set_text("");
153 }
154}
116155
=== modified file 'src/wui/login_box.h'
--- src/wui/login_box.h 2019-02-23 11:00:49 +0000
+++ src/wui/login_box.h 2019-05-08 15:04:09 +0000
@@ -29,6 +29,10 @@
29struct LoginBox : public UI::Window {29struct LoginBox : public UI::Window {
30 explicit LoginBox(UI::Panel&);30 explicit LoginBox(UI::Panel&);
3131
32 void think() override;
33
34 void verify_input();
35
32 std::string get_nickname() {36 std::string get_nickname() {
33 return eb_nickname->text();37 return eb_nickname->text();
34 }38 }
@@ -38,9 +42,6 @@
38 bool registered() {42 bool registered() {
39 return cb_register->get_state();43 return cb_register->get_state();
40 }44 }
41 bool set_automaticlog() {
42 return cb_auto_log->get_state();
43 }
4445
45 /// Handle keypresses46 /// Handle keypresses
46 bool handle_key(bool down, SDL_Keysym code) override;47 bool handle_key(bool down, SDL_Keysym code) override;
@@ -48,14 +49,16 @@
48private:49private:
49 void clicked_back();50 void clicked_back();
50 void clicked_ok();51 void clicked_ok();
52 void change_playername();
5153
54 UI::Button* loginbtn;
55 UI::Button* cancelbtn;
52 UI::EditBox* eb_nickname;56 UI::EditBox* eb_nickname;
53 UI::EditBox* eb_password;57 UI::EditBox* eb_password;
54 UI::Checkbox* cb_register;58 UI::Checkbox* cb_register;
55 UI::Checkbox* cb_auto_log;
56 UI::Textarea* ta_nickname;59 UI::Textarea* ta_nickname;
57 UI::Textarea* ta_password;60 UI::Textarea* ta_password;
58 UI::MultilineTextarea* pwd_warning;61 UI::MultilineTextarea* register_account;
59};62};
6063
61#endif // end of include guard: WL_WUI_LOGIN_BOX_H64#endif // end of include guard: WL_WUI_LOGIN_BOX_H

Subscribers

People subscribed via source and target branches

to status/vote changes: