1
0
forked from 0ad/0ad

Persist the lobby Terms Of Use and Terms Of Service checkbox if the logged in user and the accepted versions of the pages didn't change since last login, refs #5218.

This way the user is only forced to read the Terms again that changed or
if the user logged in from a different machine.
Use md5sum since it is sufficiently resistant against collisions and
doesn't freeze the window for 2 seconds like EncryptPassword / SHA256
does, refs #4399.
Use 0 instead of empty string in default.cfg, refs #3990.

Differential Revision: https://code.wildfiregames.com/D1575
Partial review by: Vladislav
This was SVN commit r21850.
This commit is contained in:
elexis 2018-06-21 16:38:08 +00:00
parent fe41404ba8
commit 468d963e78
7 changed files with 62 additions and 1 deletions

View File

@ -413,6 +413,8 @@ 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
terms_of_service = "0" ; Version (hash) of the Terms of Service that the user has accepted
terms_of_use = "0" ; Version (hash) of the Terms of Use that the user has accepted
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

View File

@ -6,7 +6,7 @@
<translatableAttribute id="caption">Login:</translatableAttribute>
</object>
<object name="username" type="input" size="40%+10 0 100%-20 24" style="ModernInput">
<action on="TextEdit">updateFeedback();</action>
<action on="TextEdit">onUsernameEdit();</action>
</object>
</object>

View File

@ -3,12 +3,14 @@ var g_Terms = {
"title": translate("Terms of Service"),
"instruction": translate("Please read the Terms of Service"),
"file": "prelobby/common/terms/Terms_of_Service",
"config": "lobby.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",
"config": "lobby.terms_of_use",
"read": false
}
};
@ -36,3 +38,32 @@ function checkTerms()
return "";
}
function getTermsHash(page)
{
return Engine.CalculateMD5(
Engine.GetGUIObjectByName("username").caption +
Engine.ReadFile("gui/" + g_Terms[page].file + ".txt"));
}
function loadTermsAcceptance()
{
let acceptedTerms = true;
for (let page in g_Terms)
{
let acceptedPage = Engine.ConfigDB_GetValue("user", g_Terms[page].config) == getTermsHash(page);
g_Terms[page].read = acceptedPage;
acceptedTerms &= acceptedPage;
}
let agreeTerms = Engine.GetGUIObjectByName("agreeTerms");
agreeTerms.checked = acceptedTerms;
agreeTerms.enabled = Object.keys(g_Terms).every(page => g_Terms[page].read);
}
function saveTermsAcceptance()
{
for (let page in g_Terms)
if (g_Terms[page].read && Engine.GetGUIObjectByName("agreeTerms").checked)
saveSettingAndWriteToUserConfig(g_Terms[page].config, getTermsHash(page));
}

View File

@ -8,6 +8,7 @@ function init()
Engine.GetGUIObjectByName("username").caption = Engine.ConfigDB_GetValue("user", "lobby.login");
Engine.GetGUIObjectByName("password").caption = Engine.ConfigDB_GetValue("user", "lobby.password").substr(0, 10);
loadTermsAcceptance();
initRememberPassword();
updateFeedback();
@ -18,6 +19,13 @@ function updateFeedback()
setFeedback(checkUsername(false) || checkPassword(false) || checkTerms());
}
// Remember which user agreed to the terms
function onUsernameEdit()
{
loadTermsAcceptance();
updateFeedback();
}
function continueButton()
{
setFeedback(translate("Connecting…"));
@ -35,6 +43,7 @@ function continueButton()
function onLogin(message)
{
saveCredentials();
saveTermsAcceptance();
Engine.SwitchGuiPage("page_lobby.xml", {
"dialog": false

View File

@ -28,6 +28,7 @@ function continueButton()
function onRegistered()
{
saveCredentials();
saveTermsAcceptance();
setFeedback(translate("Registered"));

View File

@ -23,6 +23,7 @@
#include "graphics/MapReader.h"
#include "lib/sysdep/sysdep.h"
#include "lib/utf8.h"
#include "maths/MD5.h"
#include "ps/CStrIntern.h"
#include "ps/GUID.h"
#include "ps/GameSetup/Atlas.h"
@ -109,6 +110,21 @@ int JSI_Main::GetTextWidth(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const
return width;
}
std::string JSI_Main::CalculateMD5(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& input)
{
u8 digest[MD5::DIGESTSIZE];
MD5 m;
m.Update(static_cast<const u8*>(input.c_str()), input.length());
m.Final(digest);
char digeststr[MD5::DIGESTSIZE*2+1];
for (size_t i = 0; i < MD5::DIGESTSIZE; ++i)
sprintf_s(digeststr+2*i, 3, "%02x", (unsigned int)digest[i]);
return digeststr;
}
void JSI_Main::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<void, &QuitEngine>("Exit");
@ -122,4 +138,5 @@ void JSI_Main::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<bool, std::string, &HotkeyIsPressed_>("HotkeyIsPressed");
scriptInterface.RegisterFunction<int, &GetFps>("GetFPS");
scriptInterface.RegisterFunction<int, std::string, std::wstring, &GetTextWidth>("GetTextWidth");
scriptInterface.RegisterFunction<std::string, std::string, &CalculateMD5>("CalculateMD5");
}

View File

@ -33,6 +33,7 @@ namespace JSI_Main
bool HotkeyIsPressed_(ScriptInterface::CxPrivate* pCxPrivate, const std::string& hotkeyName);
int GetFps(ScriptInterface::CxPrivate* pCxPrivate);
int GetTextWidth(ScriptInterface::CxPrivate* pCxPrivate, const std::string& fontName, const std::wstring& text);
std::string CalculateMD5(ScriptInterface::CxPrivate* pCxPrivate, const std::string& input);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
}