diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg
index bd11c2944b..bcdc83eee6 100644
--- a/binaries/data/config/default.cfg
+++ b/binaries/data/config/default.cfg
@@ -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
diff --git a/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml b/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml
index aeea6c07d6..1b8a47c24a 100644
--- a/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml
+++ b/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.xml
@@ -6,7 +6,7 @@
Login:
diff --git a/binaries/data/mods/public/gui/prelobby/common/terms/terms.js b/binaries/data/mods/public/gui/prelobby/common/terms/terms.js
index 0d0903df83..e7475b9668 100644
--- a/binaries/data/mods/public/gui/prelobby/common/terms/terms.js
+++ b/binaries/data/mods/public/gui/prelobby/common/terms/terms.js
@@ -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));
+}
diff --git a/binaries/data/mods/public/gui/prelobby/login/login.js b/binaries/data/mods/public/gui/prelobby/login/login.js
index 6d4a981b64..b6deffe067 100644
--- a/binaries/data/mods/public/gui/prelobby/login/login.js
+++ b/binaries/data/mods/public/gui/prelobby/login/login.js
@@ -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
diff --git a/binaries/data/mods/public/gui/prelobby/register/register.js b/binaries/data/mods/public/gui/prelobby/register/register.js
index 00f23c5f1d..1e8ba09d74 100644
--- a/binaries/data/mods/public/gui/prelobby/register/register.js
+++ b/binaries/data/mods/public/gui/prelobby/register/register.js
@@ -28,6 +28,7 @@ function continueButton()
function onRegistered()
{
saveCredentials();
+ saveTermsAcceptance();
setFeedback(translate("Registered"));
diff --git a/source/ps/scripting/JSInterface_Main.cpp b/source/ps/scripting/JSInterface_Main.cpp
index 6a6767c6ba..035fcfd247 100644
--- a/source/ps/scripting/JSInterface_Main.cpp
+++ b/source/ps/scripting/JSInterface_Main.cpp
@@ -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(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("Exit");
@@ -122,4 +138,5 @@ void JSI_Main::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction("HotkeyIsPressed");
scriptInterface.RegisterFunction("GetFPS");
scriptInterface.RegisterFunction("GetTextWidth");
+ scriptInterface.RegisterFunction("CalculateMD5");
}
diff --git a/source/ps/scripting/JSInterface_Main.h b/source/ps/scripting/JSInterface_Main.h
index 01260bb080..824df63ce3 100644
--- a/source/ps/scripting/JSInterface_Main.h
+++ b/source/ps/scripting/JSInterface_Main.h
@@ -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);
}