2013-11-07 21:07:24 +01:00
|
|
|
var g_LobbyIsConnecting = false;
|
|
|
|
var g_EncrytedPassword = "";
|
2013-12-18 01:56:59 +01:00
|
|
|
var g_PasswordInputIsHidden = false;
|
2014-04-30 02:46:57 +02:00
|
|
|
var g_TermsOfServiceRead = false;
|
|
|
|
var g_TermsOfUseRead = false;
|
|
|
|
var g_hasSystemMessage = false;
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
function init()
|
|
|
|
{
|
|
|
|
g_EncrytedPassword = Engine.ConfigDB_GetValue("user", "lobby.password");
|
2014-04-30 02:46:57 +02:00
|
|
|
if (Engine.ConfigDB_GetValue("user", "lobby.login") && g_EncrytedPassword)
|
|
|
|
switchPage("connect");
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function lobbyStop()
|
|
|
|
{
|
2014-01-04 11:14:53 +01:00
|
|
|
Engine.GetGUIObjectByName("feedback").caption = "";
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
if (g_LobbyIsConnecting == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_LobbyIsConnecting = false;
|
|
|
|
Engine.StopXmppClient();
|
|
|
|
}
|
|
|
|
|
2014-04-30 02:46:57 +02:00
|
|
|
function lobbyStartConnect()
|
2013-11-07 21:07:24 +01:00
|
|
|
{
|
2013-12-18 01:56:59 +01:00
|
|
|
if (g_LobbyIsConnecting)
|
2013-11-07 21:07:24 +01:00
|
|
|
return;
|
|
|
|
|
2013-11-10 23:42:48 +01:00
|
|
|
if (Engine.HasXmppClient())
|
|
|
|
Engine.StopXmppClient();
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
var username = Engine.GetGUIObjectByName("connectUsername").caption;
|
|
|
|
var password = Engine.GetGUIObjectByName("connectPassword").caption;
|
|
|
|
var feedback = Engine.GetGUIObjectByName("feedback");
|
2013-12-31 01:01:27 +01:00
|
|
|
var room = Engine.ConfigDB_GetValue("user", "lobby.room");
|
2014-01-26 06:39:55 +01:00
|
|
|
var history = Number(Engine.ConfigDB_GetValue("user", "lobby.history"));
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2014-04-20 22:51:48 +02:00
|
|
|
feedback.caption = translate("Connecting...");
|
2013-11-07 21:07:24 +01:00
|
|
|
// If they enter a different password, re-encrypt.
|
2013-12-31 01:01:27 +01:00
|
|
|
if (password != g_EncrytedPassword.substring(0, 10))
|
2013-11-07 21:07:24 +01:00
|
|
|
g_EncrytedPassword = Engine.EncryptPassword(password, username);
|
2013-12-31 01:01:27 +01:00
|
|
|
// We just use username as nick for simplicity.
|
2014-01-26 06:39:55 +01:00
|
|
|
Engine.StartXmppClient(username, g_EncrytedPassword, room, username, history);
|
2013-11-07 21:07:24 +01:00
|
|
|
g_LobbyIsConnecting = true;
|
|
|
|
Engine.ConnectXmppClient();
|
|
|
|
}
|
|
|
|
|
|
|
|
function lobbyStartRegister()
|
|
|
|
{
|
2014-04-30 02:46:57 +02:00
|
|
|
if (g_LobbyIsConnecting)
|
2013-11-07 21:07:24 +01:00
|
|
|
return;
|
2013-11-10 23:42:48 +01:00
|
|
|
|
|
|
|
if (Engine.HasXmppClient())
|
|
|
|
Engine.StopXmppClient();
|
|
|
|
|
2014-04-30 02:46:57 +02:00
|
|
|
var account = Engine.GetGUIObjectByName("registerUsername").caption;
|
|
|
|
var password = Engine.GetGUIObjectByName("registerPassword").caption;
|
2014-01-04 11:14:53 +01:00
|
|
|
var feedback = Engine.GetGUIObjectByName("feedback");
|
2013-11-07 21:07:24 +01:00
|
|
|
|
2014-04-20 22:51:48 +02:00
|
|
|
feedback.caption = translate("Registering...");
|
2014-03-07 02:52:06 +01:00
|
|
|
g_EncrytedPassword = Engine.EncryptPassword(password, account);
|
2013-11-07 21:07:24 +01:00
|
|
|
Engine.StartRegisterXmppClient(account, g_EncrytedPassword);
|
|
|
|
g_LobbyIsConnecting = true;
|
|
|
|
Engine.ConnectXmppClient();
|
|
|
|
}
|
|
|
|
|
2014-04-30 02:46:57 +02:00
|
|
|
function onTick()
|
2013-12-31 01:01:27 +01:00
|
|
|
{
|
2014-04-30 02:46:57 +02:00
|
|
|
var pageRegisterHidden = Engine.GetGUIObjectByName("pageRegister").hidden;
|
|
|
|
if (pageRegisterHidden)
|
2013-12-31 01:01:27 +01:00
|
|
|
{
|
2014-04-30 02:46:57 +02:00
|
|
|
var username = Engine.GetGUIObjectByName("connectUsername").caption;
|
|
|
|
var password = Engine.GetGUIObjectByName("connectPassword").caption;
|
2013-12-31 01:01:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-30 02:46:57 +02:00
|
|
|
var username = Engine.GetGUIObjectByName("registerUsername").caption;
|
|
|
|
var password = Engine.GetGUIObjectByName("registerPassword").caption;
|
2013-12-31 01:01:27 +01:00
|
|
|
}
|
2014-01-04 11:14:53 +01:00
|
|
|
var passwordAgain = Engine.GetGUIObjectByName("registerPasswordAgain").caption;
|
2014-04-30 02:46:57 +02:00
|
|
|
var agreeTerms = Engine.GetGUIObjectByName("registerAgreeTerms");
|
2014-01-04 11:14:53 +01:00
|
|
|
var feedback = Engine.GetGUIObjectByName("feedback");
|
2014-04-30 02:46:57 +02:00
|
|
|
var continueButton = Engine.GetGUIObjectByName("continue");
|
|
|
|
var sanitizedName = sanitizePlayerName(username, true, true);
|
|
|
|
|
|
|
|
// Do not change feedback while connecting.
|
|
|
|
if (g_LobbyIsConnecting) {}
|
|
|
|
// Do not show feedback on the welcome screen.
|
|
|
|
else if (!Engine.GetGUIObjectByName("pageWelcome").hidden)
|
|
|
|
{
|
|
|
|
feedback.caption = "";
|
|
|
|
}
|
|
|
|
// Check that they entered a username.
|
|
|
|
else if (!username)
|
|
|
|
{
|
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Please enter your username");
|
|
|
|
}
|
|
|
|
// Check that they are using a valid username.
|
2013-12-31 01:01:27 +01:00
|
|
|
else if (username != sanitizedName)
|
|
|
|
{
|
2014-04-30 02:46:57 +02:00
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Usernames can't contain [, ], unicode, whitespace, or commas");
|
|
|
|
}
|
|
|
|
// Check that they entered a password.
|
|
|
|
else if (!password)
|
|
|
|
{
|
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Please enter your password");
|
2013-12-31 01:01:27 +01:00
|
|
|
}
|
2014-04-30 02:46:57 +02:00
|
|
|
// Allow them to connect if tests pass up to this point.
|
2013-12-31 01:01:27 +01:00
|
|
|
else if (pageRegisterHidden)
|
|
|
|
{
|
2014-04-30 02:46:57 +02:00
|
|
|
if (!g_hasSystemMessage)
|
2013-12-31 01:01:27 +01:00
|
|
|
feedback.caption = "";
|
2014-04-30 02:46:57 +02:00
|
|
|
continueButton.enabled = true;
|
|
|
|
}
|
|
|
|
// Check that they entered their password again.
|
|
|
|
else if (!passwordAgain)
|
|
|
|
{
|
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Please enter your password again");
|
|
|
|
}
|
|
|
|
// Check that the passwords match.
|
|
|
|
else if (passwordAgain != password)
|
|
|
|
{
|
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Passwords do not match");
|
|
|
|
}
|
|
|
|
// Check that they read the Terms of Service.
|
|
|
|
else if (!g_TermsOfServiceRead)
|
|
|
|
{
|
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Please read the Terms of Service");
|
|
|
|
}
|
|
|
|
// Check that they read the Terms of Use.
|
|
|
|
else if (!g_TermsOfUseRead)
|
|
|
|
{
|
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Please read the Terms of Use");
|
|
|
|
}
|
|
|
|
// Check that they agree to the terms of service and use.
|
|
|
|
else if (!agreeTerms.checked)
|
|
|
|
{
|
|
|
|
continueButton.enabled = false;
|
|
|
|
feedback.caption = translate("Please agree to the Terms of Service and Terms of Use");
|
|
|
|
}
|
|
|
|
// Allow them to register.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!g_hasSystemMessage)
|
|
|
|
feedback.caption = "";
|
|
|
|
continueButton.enabled = true;
|
2013-12-31 01:01:27 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 21:07:24 +01:00
|
|
|
if (!g_LobbyIsConnecting)
|
|
|
|
// The Xmpp Client has not been created
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The XmppClient has been created, we are waiting
|
|
|
|
// to be connected or to receive an error.
|
|
|
|
|
|
|
|
//Receive messages
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
var message = Engine.LobbyGuiPollMessage();
|
|
|
|
if (!message)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (message.type == "muc" && message.level == "join")
|
|
|
|
{
|
|
|
|
// We are connected, switch to the lobby page
|
|
|
|
Engine.PopGuiPage();
|
2013-12-31 01:01:27 +01:00
|
|
|
// Use username as nick.
|
|
|
|
var nick = sanitizePlayerName(username, true, true);
|
2013-11-07 21:07:24 +01:00
|
|
|
|
|
|
|
// Switch to lobby
|
|
|
|
Engine.SwitchGuiPage("page_lobby.xml");
|
|
|
|
// Store nick, login, and password
|
|
|
|
Engine.ConfigDB_CreateValue("user", "playername", nick);
|
|
|
|
Engine.ConfigDB_CreateValue("user", "lobby.login", username);
|
|
|
|
// We only store the encrypted password, so make sure to re-encrypt it if changed before saving.
|
2013-12-31 01:01:27 +01:00
|
|
|
if (password != g_EncrytedPassword.substring(0, 10))
|
2013-11-07 21:07:24 +01:00
|
|
|
g_EncrytedPassword = Engine.EncryptPassword(password, username);
|
|
|
|
Engine.ConfigDB_CreateValue("user", "lobby.password", g_EncrytedPassword);
|
|
|
|
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (message.type == "system" && message.text == "registered")
|
|
|
|
{
|
|
|
|
// Great, we are registered. Switch to the connection window.
|
2013-12-31 01:01:27 +01:00
|
|
|
feedback.caption = toTitleCase(message.text);
|
2013-11-07 21:07:24 +01:00
|
|
|
Engine.StopXmppClient();
|
|
|
|
g_LobbyIsConnecting = false;
|
2014-04-30 02:46:57 +02:00
|
|
|
Engine.GetGUIObjectByName("connectUsername").caption = username;
|
|
|
|
Engine.GetGUIObjectByName("connectPassword").caption = password;
|
|
|
|
switchPage("connect");
|
2013-11-07 21:07:24 +01:00
|
|
|
}
|
|
|
|
else if(message.type == "system" && (message.level == "error" || message.text == "disconnected"))
|
|
|
|
{
|
2014-04-30 02:46:57 +02:00
|
|
|
g_hasSystemMessage = true;
|
2013-12-31 01:01:27 +01:00
|
|
|
feedback.caption = toTitleCase(message.text);
|
2013-11-07 21:07:24 +01:00
|
|
|
Engine.StopXmppClient();
|
|
|
|
g_LobbyIsConnecting = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-30 02:46:57 +02:00
|
|
|
|
|
|
|
function switchPage(page)
|
|
|
|
{
|
|
|
|
// First hide everything.
|
|
|
|
if (!Engine.GetGUIObjectByName("pageWelcome").hidden)
|
|
|
|
{
|
|
|
|
Engine.GetGUIObjectByName("pageWelcome").hidden = true;
|
|
|
|
}
|
|
|
|
else if (!Engine.GetGUIObjectByName("pageRegister").hidden)
|
|
|
|
{
|
|
|
|
Engine.GetGUIObjectByName("pageRegister").hidden = true;
|
|
|
|
Engine.GetGUIObjectByName("continue").hidden = true;
|
|
|
|
var dialog = Engine.GetGUIObjectByName("dialog");
|
|
|
|
var newSize = dialog.size;
|
|
|
|
newSize.bottom -= 150;
|
|
|
|
dialog.size = newSize;
|
|
|
|
}
|
|
|
|
else if (!Engine.GetGUIObjectByName("pageConnect").hidden)
|
|
|
|
{
|
|
|
|
Engine.GetGUIObjectByName("pageConnect").hidden = true;
|
|
|
|
Engine.GetGUIObjectByName("continue").hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then show appropriate page.
|
|
|
|
switch(page)
|
|
|
|
{
|
|
|
|
case "welcome":
|
|
|
|
Engine.GetGUIObjectByName("pageWelcome").hidden = false;
|
|
|
|
break;
|
|
|
|
case "register":
|
|
|
|
var dialog = Engine.GetGUIObjectByName("dialog");
|
|
|
|
var newSize = dialog.size;
|
|
|
|
newSize.bottom += 150;
|
|
|
|
dialog.size = newSize;
|
|
|
|
Engine.GetGUIObjectByName("pageRegister").hidden = false;
|
|
|
|
Engine.GetGUIObjectByName("continue").caption = translate("Register");
|
|
|
|
Engine.GetGUIObjectByName("continue").hidden = false;
|
|
|
|
break;
|
|
|
|
case "connect":
|
|
|
|
Engine.GetGUIObjectByName("pageConnect").hidden = false;
|
|
|
|
Engine.GetGUIObjectByName("continue").caption = translate("Connect");
|
|
|
|
Engine.GetGUIObjectByName("continue").hidden = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-30 06:38:53 +02:00
|
|
|
function openTermsOfService()
|
|
|
|
{
|
|
|
|
g_TermsOfServiceRead = true;
|
|
|
|
Engine.PushGuiPage("page_manual.xml", {
|
|
|
|
"page":"lobby/Terms_of_Service",
|
|
|
|
"title":translate("Terms of Service"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function openTermsOfUse()
|
|
|
|
{
|
|
|
|
g_TermsOfUseRead = true;
|
|
|
|
Engine.PushGuiPage("page_manual.xml", {
|
|
|
|
"page":"lobby/Terms_of_Use",
|
|
|
|
"title":translate("Terms of Use"),
|
|
|
|
})
|
|
|
|
}
|
2014-04-30 02:46:57 +02:00
|
|
|
|