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
1=== modified file 'src/network/gamehost.cc'
2--- src/network/gamehost.cc 2019-04-29 16:22:08 +0000
3+++ src/network/gamehost.cc 2019-05-08 15:04:09 +0000
4@@ -1621,13 +1621,13 @@
5
6 // Assign the player a name, preferably the name chosen by the client
7 if (playername.empty()) // Make sure there is at least a name base.
8- playername = _("Player");
9+ playername = "Player";
10 std::string effective_name = playername;
11
12 if (has_user_name(effective_name, client.usernum)) {
13- uint32_t i = 2;
14+ uint32_t i = 1;
15 do {
16- effective_name = (boost::format(_("Player %u")) % i++).str();
17+ effective_name = (boost::format("%s%u") % playername % i++).str();
18 } while (has_user_name(effective_name, client.usernum));
19 }
20
21
22=== modified file 'src/network/internet_gaming.cc'
23--- src/network/internet_gaming.cc 2019-05-05 22:50:03 +0000
24+++ src/network/internet_gaming.cc 2019-05-08 15:04:09 +0000
25@@ -487,7 +487,7 @@
26 InternetGame* ing = new InternetGame();
27 ing->name = packet.string();
28 ing->build_id = packet.string();
29- ing->connectable = (packet.string() == INTERNET_GAME_SETUP);
30+ ing->connectable = packet.string();
31 gamelist_.push_back(*ing);
32
33 bool found = false;
34@@ -498,10 +498,13 @@
35 break;
36 }
37 }
38- if (!found)
39+ if (!found && ing->connectable != INTERNET_GAME_RUNNING &&
40+ (ing->build_id == build_id() || (ing->build_id.compare(0, 6, "build-") != 0
41+ && build_id().compare(0, 6, "build-") != 0))) {
42 format_and_add_chat(
43- "", "", true,
44- (boost::format(_("The game %s is now available")) % ing->name).str());
45+ "", "", true,
46+ (boost::format(_("The game %s is now available")) % ing->name).str());
47+ }
48
49 delete ing;
50 ing = nullptr;
51
52=== modified file 'src/network/internet_gaming.h'
53--- src/network/internet_gaming.h 2019-02-23 11:00:49 +0000
54+++ src/network/internet_gaming.h 2019-05-08 15:04:09 +0000
55@@ -43,7 +43,7 @@
56 struct InternetGame {
57 std::string name;
58 std::string build_id;
59- bool connectable;
60+ std::string connectable;
61 };
62
63 /**
64@@ -178,6 +178,11 @@
65 return true;
66 }
67
68+ void format_and_add_chat(const std::string& from,
69+ const std::string& to,
70+ bool system,
71+ const std::string& msg);
72+
73 private:
74 InternetGaming();
75
76@@ -202,11 +207,6 @@
77 bool str2bool(std::string);
78 std::string bool2str(bool);
79
80- void format_and_add_chat(const std::string& from,
81- const std::string& to,
82- bool system,
83- const std::string& msg);
84-
85 /**
86 * Does the real work of the login.
87 * \param relogin Whether this is a relogin. Only difference is that
88
89=== modified file 'src/ui_basic/editbox.cc'
90--- src/ui_basic/editbox.cc 2019-04-09 16:43:49 +0000
91+++ src/ui_basic/editbox.cc 2019-05-08 15:04:09 +0000
92@@ -85,7 +85,8 @@
93 : Panel(parent, x, y, w, h > 0 ? h : text_height(font_size) + 2 * margin_y),
94 m_(new EditBoxImpl),
95 history_active_(false),
96- history_position_(-1) {
97+ history_position_(-1),
98+ warning_(false) {
99 set_thinks(false);
100
101 m_->background_style = g_gr->styles().editbox_style(style);
102@@ -346,7 +347,7 @@
103 draw_background(dst, *m_->background_style);
104
105 // Draw border.
106- if (get_w() >= 2 && get_h() >= 2) {
107+ if (get_w() >= 2 && get_h() >= 2 && !warning_) {
108 static const RGBColor black(0, 0, 0);
109
110 // bottom edge
111@@ -359,6 +360,25 @@
112 // left edge
113 dst.fill_rect(Recti(0, 0, 1, get_h() - 1), black);
114 dst.fill_rect(Recti(1, 0, 1, get_h() - 2), black);
115+
116+ } else {
117+ // Draw a red border for warnings.
118+ static const RGBColor red(255, 22, 22);
119+
120+ // bottom edge
121+ dst.fill_rect(Recti(0, get_h() - 2, get_w(), 2), red);
122+ // right edge
123+ dst.fill_rect(Recti(get_w() - 2, 0, 2, get_h() -2), red);
124+ // top edge
125+ dst.fill_rect(Recti(0, 0, get_w() - 1, 1), red);
126+ dst.fill_rect(Recti(0, 1, get_w() - 2, 1), red);
127+ dst.brighten_rect(Recti(0, 0, get_w() - 1, 1), BUTTON_EDGE_BRIGHT_FACTOR);
128+ dst.brighten_rect(Recti(0, 1, get_w() - 2, 1), BUTTON_EDGE_BRIGHT_FACTOR);
129+ // left edge
130+ dst.fill_rect(Recti(0, 0, 1, get_h() - 1), red);
131+ dst.fill_rect(Recti(1, 0, 1, get_h() - 2), red);
132+ dst.brighten_rect(Recti(0, 0, 1, get_h() - 1), BUTTON_EDGE_BRIGHT_FACTOR);
133+ dst.brighten_rect(Recti(1, 0, 1, get_h() - 2), BUTTON_EDGE_BRIGHT_FACTOR);
134 }
135
136 if (has_focus()) {
137
138=== modified file 'src/ui_basic/editbox.h'
139--- src/ui_basic/editbox.h 2019-02-23 11:00:49 +0000
140+++ src/ui_basic/editbox.h 2019-05-08 15:04:09 +0000
141@@ -72,6 +72,14 @@
142
143 void draw(RenderTarget&) override;
144
145+ void set_warning(bool warn) {
146+ warning_ = warn;
147+ }
148+
149+ bool has_warning() {
150+ return warning_;
151+ }
152+
153 private:
154 std::unique_ptr<EditBoxImpl> m_;
155
156@@ -80,6 +88,7 @@
157 bool history_active_;
158 int16_t history_position_;
159 std::string history_[CHAT_HISTORY_SIZE];
160+ bool warning_;
161 };
162 } // namespace UI
163
164
165=== modified file 'src/ui_fsmenu/internet_lobby.cc'
166--- src/ui_fsmenu/internet_lobby.cc 2019-05-05 00:22:27 +0000
167+++ src/ui_fsmenu/internet_lobby.cc 2019-05-08 15:04:09 +0000
168@@ -63,7 +63,7 @@
169 // Text labels
170 title(this, get_w() / 2, get_h() / 20, _("Metaserver Lobby"), UI::Align::kCenter),
171 clients_(this, get_w() * 4 / 125, get_h() * 15 / 100, _("Clients online:")),
172- opengames_(this, get_w() * 17 / 25, get_h() * 15 / 100, _("List of games:")),
173+ opengames_(this, get_w() * 17 / 25, get_h() * 15 / 100, _("Open Games:")),
174 servername_(this, get_w() * 17 / 25, get_h() * 63 / 100, _("Name of your server:")),
175
176 // Buttons
177@@ -223,28 +223,37 @@
178 // List and button cleanup
179 opengames_list_.clear();
180 hostgame_.set_enabled(true);
181+ edit_servername_.set_tooltip("");
182+ edit_servername_.set_warning(false);
183 joingame_.set_enabled(false);
184 std::string localservername = edit_servername_.text();
185+ std::string localbuildid = build_id();
186
187 if (games != nullptr) { // If no communication error occurred, fill the list.
188 for (const InternetGame& game : *games) {
189 const Image* pic;
190- if (game.connectable) {
191- if (game.build_id == build_id())
192- pic = g_gr->images().get("images/ui_basic/continue.png");
193- else {
194+ if (game.connectable == INTERNET_GAME_SETUP && game.build_id == localbuildid) {
195+ // only clients with the same build number are displayed
196+ pic = g_gr->images().get("images/ui_basic/continue.png");
197+ opengames_list_.add(game.name, game, pic, false, game.build_id);
198+ } else if (game.connectable == INTERNET_GAME_SETUP &&
199+ game.build_id.compare(0, 6, "build-") != 0 &&
200+ localbuildid.compare(0, 6, "build-") != 0) {
201+ // only development clients are allowed to see games openend by such
202 pic = g_gr->images().get("images/ui_basic/different.png");
203- }
204- } else {
205- pic = g_gr->images().get("images/ui_basic/stop.png");
206+ opengames_list_.add(game.name, game, pic, false, game.build_id);
207 }
208 // If one of the servers has the same name as the local name of the
209 // clients server, we disable the 'hostgame' button to avoid having more
210 // than one server with the same name.
211 if (game.name == localservername) {
212 hostgame_.set_enabled(false);
213+ edit_servername_.set_warning(true);
214+ edit_servername_.set_tooltip(
215+ (boost::format("%s%s%s%s%s%s%s%s") % _("The game ") % "<font bold=yes color="
216+ % UI_FONT_CLR_WARNING.hex_value() % ">" % game.name % "</font>"
217+ % _(" is already running. ") % _("Please choose a different name.")).str());
218 }
219- opengames_list_.add(game.name, game, pic, false, game.build_id);
220 }
221 }
222 }
223@@ -341,10 +350,8 @@
224 // remove focus from chat
225 if (opengames_list_.has_selection()) {
226 const InternetGame* game = &opengames_list_.get_selected();
227- if (game->connectable)
228+ if (game->connectable == INTERNET_GAME_SETUP)
229 joingame_.set_enabled(true);
230- else
231- joingame_.set_enabled(false);
232 }
233 }
234
235@@ -353,7 +360,7 @@
236 // if the game is open try to connect it, if not do nothing.
237 if (opengames_list_.has_selection()) {
238 const InternetGame* game = &opengames_list_.get_selected();
239- if (game->connectable)
240+ if (game->connectable == INTERNET_GAME_SETUP)
241 clicked_joingame();
242 }
243 }
244@@ -362,7 +369,8 @@
245 void FullscreenMenuInternetLobby::change_servername() {
246 // Allow client to enter a servername manually
247 hostgame_.set_enabled(true);
248-
249+ edit_servername_.set_tooltip("");
250+ edit_servername_.set_warning(false);
251 // Check whether a server of that name is already open.
252 // And disable 'hostgame' button if yes.
253 const std::vector<InternetGame>* games = InternetGaming::ref().games();
254@@ -370,6 +378,11 @@
255 for (const InternetGame& game : *games) {
256 if (game.name == edit_servername_.text()) {
257 hostgame_.set_enabled(false);
258+ edit_servername_.set_warning(true);
259+ edit_servername_.set_tooltip(
260+ (boost::format("%s%s%s%s%s%s%s%s") % _("The game ") % "<font bold=yes color="
261+ % UI_FONT_CLR_WARNING.hex_value() % ">" % game.name % "</font>"
262+ % _(" is already running. ") % _("Please choose a different name.")).str());
263 }
264 }
265 }
266
267=== modified file 'src/ui_fsmenu/multiplayer.cc'
268--- src/ui_fsmenu/multiplayer.cc 2019-02-23 11:00:49 +0000
269+++ src/ui_fsmenu/multiplayer.cc 2019-05-08 15:04:09 +0000
270@@ -58,21 +58,46 @@
271 vbox_.add_inf_space();
272 vbox_.add(&back, UI::Box::Resizing::kFullSize);
273
274- Section& s = g_options.pull_section("global");
275- auto_log_ = s.get_bool("auto_log", false);
276- if (auto_log_) {
277- showloginbox =
278+ showloginbox =
279 new UI::Button(this, "login_dialog", 0, 0, 0, 0, UI::ButtonStyle::kFsMenuSecondary,
280 g_gr->images().get("images/ui_basic/continue.png"), _("Show login dialog"));
281- showloginbox->sigclicked.connect(
282+ showloginbox->sigclicked.connect(
283 boost::bind(&FullscreenMenuMultiPlayer::show_internet_login, boost::ref(*this)));
284- }
285 layout();
286 }
287
288 /// called if the showloginbox button was pressed
289 void FullscreenMenuMultiPlayer::show_internet_login() {
290- auto_log_ = false;
291+ Section& s = g_options.pull_section("global");
292+ LoginBox lb(*this);
293+ if (lb.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kOk) {
294+ nickname_ = lb.get_nickname();
295+ s.set_string("nickname", nickname_);
296+ /// NOTE: The password is only stored (in memory and on disk) and transmitted (over the
297+ /// network
298+ /// to the metaserver) as cryptographic hash. This does NOT mean that the password is
299+ /// stored
300+ /// securely on the local disk. While the password should be secure while transmitted to
301+ /// the
302+ /// metaserver (no-one can use the transmitted data to log in as the user) this is not the
303+ /// case
304+ /// for local storage. The stored hash of the password makes it hard to look at the
305+ /// configuration
306+ /// file and figure out the plaintext password to, e.g., log in on the forum. However, the
307+ /// stored hash can be copied to another system and used to log in as the user on the
308+ /// metaserver.
309+ // Further note: SHA-1 is considered broken and shouldn't be used anymore. But since the
310+ // passwords on the server are protected by SHA-1 we have to use it here, too
311+ if (lb.get_password() != "*****") {
312+ password_ = crypto::sha1(lb.get_password());
313+ s.set_string("password_sha1", password_);
314+ }
315+
316+ register_ = lb.registered();
317+ s.set_bool("registered", lb.registered());
318+ } else {
319+ return;
320+ }
321 internet_login();
322 }
323
324@@ -90,37 +115,14 @@
325 */
326 void FullscreenMenuMultiPlayer::internet_login() {
327 Section& s = g_options.pull_section("global");
328- if (auto_log_) {
329- nickname_ = s.get_string("nickname", _("nobody"));
330- password_ = s.get_string("password_sha1", "nobody");
331- register_ = s.get_bool("registered", false);
332- } else {
333- LoginBox lb(*this);
334- if (lb.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kOk) {
335- nickname_ = lb.get_nickname();
336- /// NOTE: The password is only stored (in memory and on disk) and transmitted (over the
337- /// network
338- /// to the metaserver) as cryptographic hash. This does NOT mean that the password is
339- /// stored
340- /// securely on the local disk. While the password should be secure while transmitted to
341- /// the
342- /// metaserver (no-one can use the transmitted data to log in as the user) this is not the
343- /// case
344- /// for local storage. The stored hash of the password makes it hard to look at the
345- /// configuration
346- /// file and figure out the plaintext password to, e.g., log in on the forum. However, the
347- /// stored hash can be copied to another system and used to log in as the user on the
348- /// metaserver.
349- // Further note: SHA-1 is considered broken and shouldn't be used anymore. But since the
350- // passwords on the server are protected by SHA-1 we have to use it here, too
351- password_ = crypto::sha1(lb.get_password());
352- register_ = lb.registered();
353-
354- s.set_bool("registered", lb.registered());
355- s.set_bool("auto_log", lb.set_automaticlog());
356- } else {
357- return;
358- }
359+
360+ nickname_ = s.get_string("nickname", _(" "));
361+ password_ = s.get_string("password_sha1", "nobody");
362+ register_ = s.get_bool("registered", false);
363+
364+ if (nickname_ == " ") {
365+ show_internet_login();
366+ return;
367 }
368
369 // Try to connect to the metaserver
370
371=== modified file 'src/ui_fsmenu/multiplayer.h'
372--- src/ui_fsmenu/multiplayer.h 2019-02-23 11:00:49 +0000
373+++ src/ui_fsmenu/multiplayer.h 2019-05-08 15:04:09 +0000
374@@ -61,7 +61,6 @@
375 std::string nickname_;
376 std::string password_;
377 bool register_;
378- bool auto_log_;
379 };
380
381 #endif // end of include guard: WL_UI_FSMENU_MULTIPLAYER_H
382
383=== modified file 'src/ui_fsmenu/netsetup_lan.cc'
384--- src/ui_fsmenu/netsetup_lan.cc 2019-04-09 16:43:49 +0000
385+++ src/ui_fsmenu/netsetup_lan.cc 2019-05-08 15:04:09 +0000
386@@ -136,6 +136,7 @@
387
388 void FullscreenMenuNetSetupLAN::think() {
389 FullscreenMenuBase::think();
390+ change_playername();
391
392 discovery.run();
393 }
394@@ -186,7 +187,7 @@
395 assert(opengames.has_selection());
396 const NetOpenGame* const game = opengames.get_selected();
397 // Only join games that are open
398- if (game->info.state == LAN_GAME_OPEN) {
399+ if (game->info.state == LAN_GAME_OPEN || !playername.has_warning()) {
400 clicked_joingame();
401 }
402 }
403@@ -247,6 +248,24 @@
404 }
405
406 void FullscreenMenuNetSetupLAN::change_playername() {
407+ playername.set_warning(false);
408+ playername.set_tooltip("");
409+ hostgame.set_enabled(true);
410+
411+ if (playername.text().find_first_not_of("abcdefghijklmnopqrstuvwxyz"
412+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.+-_") <= playername.text().size()
413+ || playername.text().empty()) {
414+ playername.set_warning(true);
415+ playername.set_tooltip(_("Enter a valid nickname. This value may contain only "
416+ "English letters, numbers, and @ . + - _ characters."));
417+ joingame.set_enabled(false);
418+ hostgame.set_enabled(false);
419+ return;
420+ }
421+ if (!hostname.text().empty()) {
422+ joingame.set_enabled(true);
423+ }
424+
425 g_options.pull_section("global").set_string("nickname", playername.text());
426 }
427
428
429=== modified file 'src/wui/login_box.cc'
430--- src/wui/login_box.cc 2019-02-23 11:00:49 +0000
431+++ src/wui/login_box.cc 2019-05-08 15:04:09 +0000
432@@ -26,7 +26,7 @@
433 #include "ui_basic/messagebox.h"
434
435 LoginBox::LoginBox(Panel& parent)
436- : Window(&parent, "login_box", 0, 0, 500, 220, _("Metaserver login")) {
437+ : Window(&parent, "login_box", 0, 0, 500, 260, _("Metaserver login")) {
438 center_to_parent();
439
440 int32_t margin = 10;
441@@ -36,59 +36,53 @@
442 eb_nickname = new UI::EditBox(this, 150, margin, 330, 20, 2, UI::PanelStyle::kWui);
443 eb_password = new UI::EditBox(this, 150, 40, 330, 20, 2, UI::PanelStyle::kWui);
444
445- pwd_warning =
446- new UI::MultilineTextarea(this, margin, 65, 505, 50, UI::PanelStyle::kWui,
447- _("WARNING: Password will be shown and saved readable!"));
448-
449- cb_register = new UI::Checkbox(this, Vector2i(margin, 110), _("Log in to a registered account"),
450+ cb_register = new UI::Checkbox(this, Vector2i(margin, 70), _("Log in to a registered account"),
451 "", get_inner_w() - 2 * margin);
452- cb_auto_log = new UI::Checkbox(this, Vector2i(margin, 135),
453- _("Automatically use this login information from now on."), "",
454- get_inner_w() - 2 * margin);
455-
456- UI::Button* loginbtn = new UI::Button(
457+
458+ register_account = new UI::MultilineTextarea(this, margin, 105, 470, 140, UI::PanelStyle::kWui,
459+ _("To register an account, please visit our website: \n\n"
460+ "https://widelands.org/accounts/register/ \n\n"
461+ "Log in to your newly created account and set an \n"
462+ "online gaming password on your profile page."));
463+
464+ loginbtn = new UI::Button(
465 this, "login",
466 UI::g_fh->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 :
467 (get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2,
468 get_inner_h() - 20 - margin, 200, 20, UI::ButtonStyle::kWuiPrimary, _("Login"));
469- loginbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_ok, boost::ref(*this)));
470- UI::Button* cancelbtn = new UI::Button(
471+
472+ cancelbtn = new UI::Button(
473 this, "cancel",
474 UI::g_fh->fontset()->is_rtl() ? (get_inner_w() / 2 - 200) / 2 + get_inner_w() / 2 :
475 (get_inner_w() / 2 - 200) / 2,
476 loginbtn->get_y(), 200, 20, UI::ButtonStyle::kWuiSecondary, _("Cancel"));
477+
478+ loginbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_ok, boost::ref(*this)));
479 cancelbtn->sigclicked.connect(boost::bind(&LoginBox::clicked_back, boost::ref(*this)));
480+ eb_nickname->changed.connect(boost::bind(&LoginBox::change_playername, this));
481
482 Section& s = g_options.pull_section("global");
483 eb_nickname->set_text(s.get_string("nickname", _("nobody")));
484 cb_register->set_state(s.get_bool("registered", false));
485+
486+ if (registered()) {
487+ eb_password->set_text("*****");
488+ } else {
489+ eb_password->set_can_focus(false);
490+ }
491+
492 eb_nickname->focus();
493 }
494
495+/// think function of the UI (main loop)
496+void LoginBox::think() {
497+ verify_input();
498+}
499+
500 /**
501 * called, if "login" is pressed.
502 */
503 void LoginBox::clicked_ok() {
504- // Check if all needed input fields are valid
505- if (eb_nickname->text().empty()) {
506- UI::WLMessageBox mb(
507- this, _("Empty Nickname"), _("Please enter a nickname!"), UI::WLMessageBox::MBoxType::kOk);
508- mb.run<UI::Panel::Returncodes>();
509- return;
510- }
511- if (eb_nickname->text().find(' ') <= eb_nickname->text().size()) {
512- UI::WLMessageBox mb(this, _("Space in Nickname"),
513- _("Sorry, but spaces are not allowed in nicknames!"),
514- UI::WLMessageBox::MBoxType::kOk);
515- mb.run<UI::Panel::Returncodes>();
516- return;
517- }
518- if (eb_password->text().empty() && cb_register->get_state()) {
519- UI::WLMessageBox mb(this, _("Empty Password"), _("Please enter your password!"),
520- UI::WLMessageBox::MBoxType::kOk);
521- mb.run<UI::Panel::Returncodes>();
522- return;
523- }
524 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kOk);
525 }
526
527@@ -97,6 +91,11 @@
528 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
529 }
530
531+/// Calles when nickname was changed
532+void LoginBox::change_playername() {
533+ cb_register->set_state(false);
534+}
535+
536 bool LoginBox::handle_key(bool down, SDL_Keysym code) {
537 if (down) {
538 switch (code.sym) {
539@@ -113,3 +112,43 @@
540 }
541 return UI::Panel::handle_key(down, code);
542 }
543+
544+void LoginBox::verify_input() {
545+ // Check if all needed input fields are valid
546+ loginbtn->set_enabled(true);
547+ eb_nickname->set_tooltip("");
548+ eb_password->set_tooltip("");
549+ eb_nickname->set_warning(false);
550+ eb_password->set_warning(false);
551+
552+ if (eb_nickname->text().empty()) {
553+ eb_nickname->set_warning(true);
554+ eb_nickname->set_tooltip(_("Please enter a nickname!"));
555+ loginbtn->set_enabled(false);
556+ }
557+
558+ if (eb_nickname->text().find_first_not_of("abcdefghijklmnopqrstuvwxyz"
559+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.+-_") <= eb_nickname->text().size()) {
560+ eb_nickname->set_warning(true);
561+ eb_nickname->set_tooltip(_("Enter a valid nickname. This value may contain only "
562+ "English letters, numbers, and @ . + - _ characters."));
563+ loginbtn->set_enabled(false);
564+
565+ }
566+
567+ if (eb_password->text().empty() && cb_register->get_state()) {
568+ eb_password->set_warning(true);
569+ eb_password->set_tooltip(_("Please enter your password!"));
570+ eb_password->focus();
571+ loginbtn->set_enabled(false);
572+ }
573+
574+ if (!eb_password->text().empty() && !cb_register->get_state()) {
575+ eb_password->set_text("");
576+ eb_password->set_can_focus(false);
577+ }
578+
579+ if (eb_password->has_focus() && eb_password->text() == "*****") {
580+ eb_password->set_text("");
581+ }
582+}
583
584=== modified file 'src/wui/login_box.h'
585--- src/wui/login_box.h 2019-02-23 11:00:49 +0000
586+++ src/wui/login_box.h 2019-05-08 15:04:09 +0000
587@@ -29,6 +29,10 @@
588 struct LoginBox : public UI::Window {
589 explicit LoginBox(UI::Panel&);
590
591+ void think() override;
592+
593+ void verify_input();
594+
595 std::string get_nickname() {
596 return eb_nickname->text();
597 }
598@@ -38,9 +42,6 @@
599 bool registered() {
600 return cb_register->get_state();
601 }
602- bool set_automaticlog() {
603- return cb_auto_log->get_state();
604- }
605
606 /// Handle keypresses
607 bool handle_key(bool down, SDL_Keysym code) override;
608@@ -48,14 +49,16 @@
609 private:
610 void clicked_back();
611 void clicked_ok();
612+ void change_playername();
613
614+ UI::Button* loginbtn;
615+ UI::Button* cancelbtn;
616 UI::EditBox* eb_nickname;
617 UI::EditBox* eb_password;
618 UI::Checkbox* cb_register;
619- UI::Checkbox* cb_auto_log;
620 UI::Textarea* ta_nickname;
621 UI::Textarea* ta_password;
622- UI::MultilineTextarea* pwd_warning;
623+ UI::MultilineTextarea* register_account;
624 };
625
626 #endif // end of include guard: WL_WUI_LOGIN_BOX_H

Subscribers

People subscribed via source and target branches

to status/vote changes: