From 80dbd1f2a3b5cd2c473eb10e0a1cbf2060887b9c Mon Sep 17 00:00:00 2001 From: elexis Date: Mon, 11 Jun 2018 15:59:22 +0000 Subject: [PATCH] Rewrite the prelobby pages and add the Terms of Service, Terms of Use and the agreement checkbox to the login page. Ensure lobby players cannot join without acceptance of the terms in case they change, fixes #5218, as agreed in last staff meeting. Separate lobby entrance, lobby login and lobby register GUI page. Since bffe917914 they were squashed into a single GUI page; Adding lots of hardcode to set the visibility of GUI objects; Reinventing a GUI page manager in JS; Unintentionally persisting data between pages; Requiring lots of errorprone case distinctions which are unneeded once relevant GUI objects and code is loaded exclusively. Add the remember-password checkbox from b6b547d5f8 / D822 to the registration page too. Revert the revert of ccb534259d in 9f9db45a03 and continue to prefer objects with separate functions per C++ GUI message type, reducing the nesting of conditionals per function and reveal codeflow by making input and output variables explicit. Fix oversight in 0940db3fc0 by moving the registrationrate string from 0e2d2610c9 from the "disconnect" to the "error" case. Differential Revision: https://code.wildfiregames.com/D1568 Few comments by: Vladislav, Imarok, gallaecio This was SVN commit r21847. --- binaries/data/config/default.cfg | 1 + .../public/gui/page_prelobby_entrance.xml | 10 + ...e_prelobby.xml => page_prelobby_login.xml} | 2 +- .../public/gui/page_prelobby_register.xml | 10 + .../data/mods/public/gui/pregame/mainmenu.xml | 2 +- .../common/credentials/confirmpassword.xml | 10 + .../common/credentials/credentials.js | 86 +++++ .../common/credentials/credentials.xml | 22 ++ .../common/credentials/rememberpassword.xml | 9 + .../gui/prelobby/common/feedback/feedback.js | 39 +++ .../gui/prelobby/common/feedback/feedback.xml | 15 + .../{ => common/terms}/Terms_of_Service.txt | 0 .../{ => common/terms}/Terms_of_Use.txt | 0 .../public/gui/prelobby/common/terms/terms.js | 38 ++ .../gui/prelobby/common/terms/terms.xml | 21 ++ .../public/gui/prelobby/entrance/entrance.js | 20 ++ .../public/gui/prelobby/entrance/entrance.xml | 38 ++ .../mods/public/gui/prelobby/login/login.js | 42 +++ .../mods/public/gui/prelobby/login/login.xml | 34 ++ .../data/mods/public/gui/prelobby/prelobby.js | 330 ------------------ .../mods/public/gui/prelobby/prelobby.xml | 110 ------ .../public/gui/prelobby/register/register.js | 38 ++ .../public/gui/prelobby/register/register.xml | 38 ++ binaries/data/mods/public/l10n/messages.json | 4 +- 24 files changed, 475 insertions(+), 444 deletions(-) create mode 100644 binaries/data/mods/public/gui/page_prelobby_entrance.xml rename binaries/data/mods/public/gui/{page_prelobby.xml => page_prelobby_login.xml} (83%) create mode 100644 binaries/data/mods/public/gui/page_prelobby_register.xml create mode 100644 binaries/data/mods/public/gui/prelobby/common/credentials/confirmpassword.xml create mode 100644 binaries/data/mods/public/gui/prelobby/common/credentials/credentials.js create mode 100644 binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml create mode 100644 binaries/data/mods/public/gui/prelobby/common/credentials/rememberpassword.xml create mode 100644 binaries/data/mods/public/gui/prelobby/common/feedback/feedback.js create mode 100644 binaries/data/mods/public/gui/prelobby/common/feedback/feedback.xml rename binaries/data/mods/public/gui/prelobby/{ => common/terms}/Terms_of_Service.txt (100%) rename binaries/data/mods/public/gui/prelobby/{ => common/terms}/Terms_of_Use.txt (100%) create mode 100644 binaries/data/mods/public/gui/prelobby/common/terms/terms.js create mode 100644 binaries/data/mods/public/gui/prelobby/common/terms/terms.xml create mode 100644 binaries/data/mods/public/gui/prelobby/entrance/entrance.js create mode 100644 binaries/data/mods/public/gui/prelobby/entrance/entrance.xml create mode 100644 binaries/data/mods/public/gui/prelobby/login/login.js create mode 100644 binaries/data/mods/public/gui/prelobby/login/login.xml delete mode 100644 binaries/data/mods/public/gui/prelobby/prelobby.js delete mode 100644 binaries/data/mods/public/gui/prelobby/prelobby.xml create mode 100644 binaries/data/mods/public/gui/prelobby/register/register.js create mode 100644 binaries/data/mods/public/gui/prelobby/register/register.xml diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index bd11c2944b..5a99b338af 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -413,6 +413,7 @@ extended = true ; Whether to display the chat history history = 0 ; Number of past messages to display on join room = "arena23" ; Default MUC room to join server = "lobby.wildfiregames.com" ; Address of lobby server +;server = "localhost" ; Address of lobby server xpartamupp = "wfgbot23" ; Name of the server-side XMPP-account that manage games echelon = "echelon23" ; Name of the server-side XMPP-account that manages ratings buddies = "," ; Comma separated list of playernames that the current user has marked as buddies diff --git a/binaries/data/mods/public/gui/page_prelobby_entrance.xml b/binaries/data/mods/public/gui/page_prelobby_entrance.xml new file mode 100644 index 0000000000..de3cfdc667 --- /dev/null +++ b/binaries/data/mods/public/gui/page_prelobby_entrance.xml @@ -0,0 +1,10 @@ + + + common/modern/setup.xml + common/modern/styles.xml + common/modern/sprites.xml + + common/global.xml + + prelobby/entrance/entrance.xml + diff --git a/binaries/data/mods/public/gui/page_prelobby.xml b/binaries/data/mods/public/gui/page_prelobby_login.xml similarity index 83% rename from binaries/data/mods/public/gui/page_prelobby.xml rename to binaries/data/mods/public/gui/page_prelobby_login.xml index 653e276ac4..76d998f286 100644 --- a/binaries/data/mods/public/gui/page_prelobby.xml +++ b/binaries/data/mods/public/gui/page_prelobby_login.xml @@ -6,5 +6,5 @@ common/global.xml - prelobby/prelobby.xml + prelobby/login/login.xml diff --git a/binaries/data/mods/public/gui/page_prelobby_register.xml b/binaries/data/mods/public/gui/page_prelobby_register.xml new file mode 100644 index 0000000000..14658487d4 --- /dev/null +++ b/binaries/data/mods/public/gui/page_prelobby_register.xml @@ -0,0 +1,10 @@ + + + common/modern/setup.xml + common/modern/styles.xml + common/modern/sprites.xml + + common/global.xml + + prelobby/register/register.xml + diff --git a/binaries/data/mods/public/gui/pregame/mainmenu.xml b/binaries/data/mods/public/gui/pregame/mainmenu.xml index 0ecd4d4ca9..49a91ab0b6 100644 --- a/binaries/data/mods/public/gui/pregame/mainmenu.xml +++ b/binaries/data/mods/public/gui/pregame/mainmenu.xml @@ -320,7 +320,7 @@ if (!Engine.StartXmppClient) return; closeMenu(); - Engine.PushGuiPage("page_prelobby.xml"); + Engine.PushGuiPage("page_prelobby_entrance.xml"); if (!Engine.StartXmppClient) diff --git a/binaries/data/mods/public/gui/prelobby/common/credentials/confirmpassword.xml b/binaries/data/mods/public/gui/prelobby/common/credentials/confirmpassword.xml new file mode 100644 index 0000000000..f1ad1e7db6 --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/credentials/confirmpassword.xml @@ -0,0 +1,10 @@ + + + + Password again: + + + + updateFeedback(); + + diff --git a/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.js b/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.js new file mode 100644 index 0000000000..f1d68ecfe4 --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.js @@ -0,0 +1,86 @@ +function checkUsername(register) +{ + let username = Engine.GetGUIObjectByName("username").caption; + if (!username) + return translate("Please enter your username"); + + if (register && (!username.match(/^[a-z0-9._-]*$/i) || username.length > 20)) + return translate("Invalid username"); + + return ""; +} + +function checkPassword(register) +{ + if (!Engine.GetGUIObjectByName("password").caption) + return register ? + translateWithContext("register", "Please enter your password") : + translateWithContext("login", "Please enter your password"); + + return ""; +} + +function checkPasswordConfirmation() +{ + let password1 = Engine.GetGUIObjectByName("password").caption; + if (!password1) + return translate("Please enter your password again"); + + let password2 = Engine.GetGUIObjectByName("passwordRepeat").caption; + if (password1 != password2) + return translate("Passwords do not match"); + + return ""; +} + +function initRememberPassword() +{ + Engine.GetGUIObjectByName("rememberPassword").checked = + Engine.ConfigDB_GetValue("user", "lobby.rememberpassword") == "true"; +} + +function toggleRememberPassword() +{ + let checkbox = Engine.GetGUIObjectByName("rememberPassword"); + let enabled = Engine.ConfigDB_GetValue("user", "lobby.rememberpassword") == "true"; + if (!checkbox.checked && enabled && Engine.ConfigDB_GetValue("user", "lobby.password")) + messageBox( + 360, 160, + translate("Are you sure you want to delete the password after connecting?"), + translate("Confirmation"), + [translate("No"), translate("Yes")], + [ + () => { checkbox.checked = true; }, + () => { saveSettingAndWriteToUserConfig("lobby.rememberpassword", String(!enabled)); } + ]); + else + saveSettingAndWriteToUserConfig("lobby.rememberpassword", String(!enabled)); +} + +function getEncryptedPassword() +{ + let typedUnencryptedPassword = Engine.GetGUIObjectByName("password").caption; + let storedEncryptedPassword = Engine.ConfigDB_GetValue("user", "lobby.password"); + + if (typedUnencryptedPassword == storedEncryptedPassword.substr(0, 10)) + return storedEncryptedPassword; + + return Engine.EncryptPassword( + typedUnencryptedPassword, + Engine.GetGUIObjectByName("username").caption); +} + +function saveCredentials() +{ + let username = Engine.GetGUIObjectByName("username").caption; + saveSettingAndWriteToUserConfig("playername.multiplayer", username); + saveSettingAndWriteToUserConfig("lobby.login", username); + + if (Engine.ConfigDB_GetValue("user", "lobby.rememberpassword") == "true") + saveSettingAndWriteToUserConfig("lobby.password", getEncryptedPassword()); + else + { + Engine.ConfigDB_RemoveValue("user", "lobby.password"); + Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + } +} diff --git a/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml b/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml new file mode 100644 index 0000000000..cb0c15a35c --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml @@ -0,0 +1,22 @@ + + + + + + Login: + + + updateFeedback(); + + > + + + + Password: + + + updateFeedback(); + + + + diff --git a/binaries/data/mods/public/gui/prelobby/common/credentials/rememberpassword.xml b/binaries/data/mods/public/gui/prelobby/common/credentials/rememberpassword.xml new file mode 100644 index 0000000000..a032aff9cf --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/credentials/rememberpassword.xml @@ -0,0 +1,9 @@ + + + + toggleRememberPassword(); + + + Remember Password + + diff --git a/binaries/data/mods/public/gui/prelobby/common/feedback/feedback.js b/binaries/data/mods/public/gui/prelobby/common/feedback/feedback.js new file mode 100644 index 0000000000..9a9ebe5d80 --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/feedback/feedback.js @@ -0,0 +1,39 @@ +var g_LobbyMessages = { + "error": message => { + setFeedback(message.text || + translate("Unknown error. This usually occurs because the same IP address is not allowed to register more than one account within one hour.")); + Engine.StopXmppClient(); + }, + "disconnected": message => { + setFeedback(message.reason); + Engine.StopXmppClient(); + } +}; + +function onTick() +{ + while (true) + { + let message = Engine.LobbyGuiPollNewMessage(); + if (!message) + break; + + if (message.type == "system" && message.level) + g_LobbyMessages[message.level](message); + else + warn("Unknown prelobby message: " + uneval(message)); + } +} + +function setFeedback(feedbackText) +{ + Engine.GetGUIObjectByName("feedback").caption = feedbackText; + Engine.GetGUIObjectByName("continue").enabled = !feedbackText; +} + +function cancelButton() +{ + if (Engine.HasXmppClient()) + Engine.StopXmppClient(); + Engine.PopGuiPage(); +} diff --git a/binaries/data/mods/public/gui/prelobby/common/feedback/feedback.xml b/binaries/data/mods/public/gui/prelobby/common/feedback/feedback.xml new file mode 100644 index 0000000000..5c19f5a09b --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/feedback/feedback.xml @@ -0,0 +1,15 @@ + + + onTick(); + + + + + Cancel + cancelButton(); + + + + continueButton(); + + diff --git a/binaries/data/mods/public/gui/prelobby/Terms_of_Service.txt b/binaries/data/mods/public/gui/prelobby/common/terms/Terms_of_Service.txt similarity index 100% rename from binaries/data/mods/public/gui/prelobby/Terms_of_Service.txt rename to binaries/data/mods/public/gui/prelobby/common/terms/Terms_of_Service.txt diff --git a/binaries/data/mods/public/gui/prelobby/Terms_of_Use.txt b/binaries/data/mods/public/gui/prelobby/common/terms/Terms_of_Use.txt similarity index 100% rename from binaries/data/mods/public/gui/prelobby/Terms_of_Use.txt rename to binaries/data/mods/public/gui/prelobby/common/terms/Terms_of_Use.txt diff --git a/binaries/data/mods/public/gui/prelobby/common/terms/terms.js b/binaries/data/mods/public/gui/prelobby/common/terms/terms.js new file mode 100644 index 0000000000..0d0903df83 --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/terms/terms.js @@ -0,0 +1,38 @@ +var g_Terms = { + "Service": { + "title": translate("Terms of Service"), + "instruction": translate("Please read the Terms of Service"), + "file": "prelobby/common/terms/Terms_of_Service", + "read": false + }, + "Use": { + "title": translate("Terms of Use"), + "instruction": translate("Please read the Terms of Use"), + "file": "prelobby/common/terms/Terms_of_Use", + "read": false + } +}; + +function openTerms(terms) +{ + g_Terms[terms].read = true; + Engine.GetGUIObjectByName("agreeTerms").enabled = g_Terms.Service.read && g_Terms.Use.read; + + Engine.PushGuiPage("page_manual.xml", { + "page": g_Terms[terms].file, + "title": g_Terms[terms].title, + "callback": "updateFeedback" + }); +} + +function checkTerms() +{ + for (let page in g_Terms) + if (!g_Terms[page].read) + return g_Terms[page].instruction; + + if (!Engine.GetGUIObjectByName("agreeTerms").checked) + return translate("Please agree to the Terms of Service and Terms of Use"); + + return ""; +} diff --git a/binaries/data/mods/public/gui/prelobby/common/terms/terms.xml b/binaries/data/mods/public/gui/prelobby/common/terms/terms.xml new file mode 100644 index 0000000000..29e542f6bc --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/common/terms/terms.xml @@ -0,0 +1,21 @@ + + + + Terms of Service + openTerms("Service"); + + + + Terms of Use + openTerms("Use"); + + + + I have read and agree to the Terms of Service and Terms of Use: + + + + updateFeedback(); + + + diff --git a/binaries/data/mods/public/gui/prelobby/entrance/entrance.js b/binaries/data/mods/public/gui/prelobby/entrance/entrance.js new file mode 100644 index 0000000000..6c702d7fa5 --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/entrance/entrance.js @@ -0,0 +1,20 @@ +function init() +{ + if (Engine.ConfigDB_GetValue("user", "lobby.login")) + loginButton(); +} + +function loginButton() +{ + Engine.PushGuiPage("page_prelobby_login.xml"); +} + +function registerButton() +{ + Engine.PushGuiPage("page_prelobby_register.xml"); +} + +function cancelButton() +{ + Engine.PopGuiPage(); +} diff --git a/binaries/data/mods/public/gui/prelobby/entrance/entrance.xml b/binaries/data/mods/public/gui/prelobby/entrance/entrance.xml new file mode 100644 index 0000000000..72c5f2100b --- /dev/null +++ b/binaries/data/mods/public/gui/prelobby/entrance/entrance.xml @@ -0,0 +1,38 @@ + + + + +