Skip to content

Commit

Permalink
close #751
Browse files Browse the repository at this point in the history
  • Loading branch information
Areso committed Feb 15, 2023
1 parent 1cec724 commit f4ea43c
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 72 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ <h3 id="lblTabInn">Welcome to Inn!</h3>
<!--UNITS STATS-->
<script async src="js/objects_units.js"></script>
<!--ONLINE OPTIONS-->
<script async src="js/mech_online.js"></script>
<script async src="js/lib/mech_online.js"></script>
<script>
function accordion(elem, targetClass){
document.addEventListener('click', function (e) {
Expand Down
4 changes: 3 additions & 1 deletion js/lib/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LIBRARIES
The game uses following external dependencies, shipped with the game:
1. bind.js by Remy, MIT License, https://github.com/remy/bind.js/, sha1sum e0e56ef93d5cb88286bb68df7481d98de1fdc6b7
1. bind.js / bind.min.js by Remy, MIT License, https://github.com/remy/bind.js/, sha1sum e0e56ef93d5cb88286bb68df7481d98de1fdc6b7
2. rivets.bundled.min.js by mikeric, MIT License, https://github.com/mikeric/rivets
3. mech_online by Areso, MIT License
152 changes: 82 additions & 70 deletions js/mech_online.js → js/lib/mech_online.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,77 +44,89 @@ setUpBackendTimers()
// config.isOnline = true
// setUpBackendTimers()
//functions
function isLoginFilled() {
let login = document.getElementById("login").value;
login = login.replace(" ","");
if (login.length>0) { return true } else { return false }
}
function isPasswordFilled() {
let password = document.getElementById("password").value;
password = password.replace(" ","");
if (password.length>0) { return true } else { return false }
}
function remoteRegLogin() {
if (reglogin==="reg"){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 201) {
if (config.debug){
console.log(session);
console.log(this.responseText)
}
resp_data = JSON.parse(this.responseText);
session = resp_data["session"];
msg = "registered successfully";
postEventLog(msg);
msg = "you got a 'registered user' badge and 10 ambers";
postEventLog(msg);
pullAmberTimer = setInterval(pullAmber, 3000);
}
};
fpullMessages();
login = document.getElementById("login").value;
password = document.getElementById("password").value;
email = document.getElementById("password").value;
dataToParse = login + delimiter;
dataToParse += password + delimiter;
dataToParse += email;
endpoint = webserver + "/api/v1.1/register_user";
xhttp.open("POST", endpoint, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(dataToParse);
}
if (reglogin==="login"){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
if (config.debug){
console.log(session);
console.log(this.responseText);
}
resp_data = JSON.parse(this.responseText);
session = resp_data["session"];
game.role = resp_data["role"];
game.nickname = resp_data["login"];
msg = "login successfull";
postEventLog(msg);
fpullMessages();
if (config.isOnline === false){
config.isOnline = true;
setUpBackendTimers();
enableOnlineCounter();
}
if (typeof setupNickname === "function") { setupNickname() };
pullAmberTimer = setInterval(pullAmber, 3000);
}
if (this.readyState === 4 && this.status !== 200) {
if (config.debug){
console.log(session);
console.log(this.responseText);
}
resp_data = JSON.parse(this.responseText);
msg = "login unsuccessfull, please try again";
postEventLog(msg);
}
};
login = document.getElementById("login").value;
password = document.getElementById("password").value;
dataToParse = login+delimiter+password;
endpoint = webserver + "/api/v1.1/login_user";
xhttp.open("POST", endpoint, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(dataToParse);
}
if (reglogin==="reg"){
if (isLoginFilled && isPasswordFilled) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 201) {
if (config.debug){
console.log(session);
console.log(this.responseText)
}
resp_data = JSON.parse(this.responseText);
session = resp_data["session"];
msg = "registered successfully";
postEventLog(msg);
msg = "you got a 'registered user' badge and 10 ambers";
postEventLog(msg);
pullAmberTimer = setInterval(pullAmber, 3000);
}
};
login = document.getElementById("login").value;
password = document.getElementById("password").value;
email = document.getElementById("password").value;
dataToParse = login + delimiter;
dataToParse += password + delimiter;
dataToParse += email;
endpoint = webserver + "/api/v1.1/register_user";
xhttp.open("POST", endpoint, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(dataToParse);
} else {
showModal(0, '', getAck, locObj.requiredFieldsNotFilled.txt, locObj.okay.txt, '')
}
}
if (reglogin==="login"){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
if (config.debug){
console.log(session);
console.log(this.responseText);
}
resp_data = JSON.parse(this.responseText);
session = resp_data["session"];
game.role = resp_data["role"];
game.nickname = resp_data["login"];
msg = "login successfull";
postEventLog(msg);
if (config.isOnline === false){
config.isOnline = true;
setUpBackendTimers();
enableOnlineCounter();
}
if (typeof setupNickname === "function") { setupNickname() };
pullAmberTimer = setInterval(pullAmber, 3000);
}
if (this.readyState === 4 && this.status !== 200) {
if (config.debug){
console.log(session);
console.log(this.responseText);
}
resp_data = JSON.parse(this.responseText);
msg = "login unsuccessfull, please try again";
postEventLog(msg);
}
};
login = document.getElementById("login").value;
password = document.getElementById("password").value;
dataToParse = login+delimiter+password;
endpoint = webserver + "/api/v1.1/login_user";
xhttp.open("POST", endpoint, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(dataToParse);
}
}
function fpullMessages() {
var xhttp = new XMLHttpRequest();
Expand Down
1 change: 1 addition & 0 deletions langs/de-DE.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ locObj.moneyDecreased = {"txt":"Euer Reichtum verringerte sich", "loc":"happens
locObj.popIncreased = {"txt":"Die Bevölkerung wuchs", "loc":"happens when s-to-s population value increased"};
locObj.popDecreased = {"txt":"Die Bevölkerung ging zurück", "loc":"happens when s-to-s population value decreased"};
locObj.buildUpgradeHouse = {"txt":"Eure Stadt ist am Bevölkerungslimit. Errichtet neue Häuser oder rüstet bestehende auf", "loc":"the endturn tip in case of overpopulating"};
locObj.requiredFieldsNotFilled = {"txt": "Required fields are not filled!", "loc":"happens in case of empty fields like login, password, etc"};
locObj.savedSuccessfully = {"txt":"Spiel erfolgreich gespeichert", "loc":"when manual save completed successfully"};
locObj.loadedSuccessfully = {"txt":"Spiel erfolgreich geladen", "loc":"when loaded completed successfully"};
locObj.dialogLoadGame = {"txt":"Spiel laden? Nicht gespeicherter Fortschritt geht dabei verloren!", "loc":"confirmation dialogue over loading game"};
Expand Down
1 change: 1 addition & 0 deletions langs/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ locObj.moneyDecreased = {"txt":"amount of money is decreased", "loc":"happens wh
locObj.popIncreased = {"txt":"population is increased", "loc":"happens when s-to-s population value increased"};
locObj.popDecreased = {"txt":"population is decreased", "loc":"happens when s-to-s population value decreased"};
locObj.buildUpgradeHouse = {"txt":"your city is reached population limit. Build new houses or upgrade existing ones", "loc":"the endturn tip in case of overpopulating"};
locObj.requiredFieldsNotFilled = {"txt": "Required fields are not filled!", "loc":"happens in case of empty fields like login, password, etc"};
locObj.savedSuccessfully = {"txt":"game saved successfully", "loc":"when manual save completed successfully"};
locObj.loadedSuccessfully = {"txt":"game loaded successfully", "loc":"when loaded completed successfully"};
locObj.dialogLoadGame = {"txt":"Load game? You will lose any unsaved progress!", "loc":"confirmation dialogue over loading game"};
Expand Down
1 change: 1 addition & 0 deletions langs/eo.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ locObj.moneyIncreased = {"txt":"kvanto da mono pliiĝas", "loc":"happens when s-
locObj.moneyDecreased = {"txt":"kvanto da mono malpliiĝas", "loc":"happens when s-to-s money value decreased"};
locObj.popIncreased = {"txt":"loĝantaro pliiĝas", "loc":"happens when s-to-s population value increased"};
locObj.popDecreased = {"txt":"loĝantaro malpliiĝas", "loc":"happens when s-to-s population value decreased"};
locObj.requiredFieldsNotFilled = {"txt": "Required fields are not filled!", "loc":"happens in case of empty fields like login, password, etc"};
locObj.buildUpgradeHouse = {"txt":"via urbo atingas loĝantaran limon. Konstruu novajn domojn aŭ ĝisdatigu ekzistantajn domojn", "loc":"the endturn tip in case of overpopulating"};
locObj.savedSuccessfully = {"txt":"ludo konservis sukcese", "loc":"when manual save completed successfully"};
locObj.loadedSuccessfully = {"txt":"ludo ŝarĝis sukcese", "loc":"when loaded completed successfully"};
Expand Down
1 change: 1 addition & 0 deletions langs/es-ES.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ locObj.moneyDecreased = {"txt":"Tu riqueza se redujo", "loc":"happens when s-to-
locObj.popIncreased = {"txt":"La población creció", "loc":"happens when s-to-s population value increased"};
locObj.popDecreased = {"txt":"La población se redujo", "loc":"happens when s-to-s population value decreased"};
locObj.buildUpgradeHouse = {"txt":"Tu ciudad alcanzó el límite de población. Construye nuevas casas o mejora las existentes", "loc":"the endturn tip in case of overpopulating"};
locObj.requiredFieldsNotFilled = {"txt": "Required fields are not filled!", "loc":"happens in case of empty fields like login, password, etc"};
locObj.savedSuccessfully = {"txt":"Juego guardado exitosamente", "loc":"when manual save completed successfully"};
locObj.loadedSuccessfully = {"txt":"Juego cargado exitosamente", "loc":"when loaded completed successfully"};
locObj.dialogLoadGame = {"txt":"¿Cargar juego? Perderás cualquier avance no guardado", "loc":"confirmation dialogue over loading game"};
Expand Down
1 change: 1 addition & 0 deletions langs/fr-FR.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ locObj.moneyIncreased = {"txt":"Votre richesse augmente", "loc":"happens when s-
locObj.moneyDecreased = {"txt":"Votre richesse diminue", "loc":"happens when s-to-s money value decreased"};
locObj.popIncreased = {"txt":"La population augmente", "loc":"happens when s-to-s population value increased"};
locObj.popDecreased = {"txt":"La population diminue", "loc":"happens when s-to-s population value decreased"};
locObj.requiredFieldsNotFilled = {"txt": "Required fields are not filled!", "loc":"happens in case of empty fields like login, password, etc"};
locObj.buildUpgradeHouse = {"txt":"Votre cité a atteint sa limite de population. Construisez de nouvelles maisons ou améliorez celles qui existent", "loc":"the endturn tip in case of overpopulating"};
locObj.savedSuccessfully = {"txt":"Sauvegarde réussie", "loc":"when manual save completed successfully"};
locObj.loadedSuccessfully = {"txt":"Chargement réussi", "loc":"when loaded completed successfully"};
Expand Down
1 change: 1 addition & 0 deletions langs/ru-RU.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ locObj.moneyIncreased = {"txt":"казна пополняется, милорд!
locObj.moneyDecreased = {"txt":"казна пустеет, милорд", "loc":"happens when s-to-s money value decreased"};
locObj.popIncreased = {"txt":"население растет!", "loc":"happens when s-to-s population value increased"};
locObj.popDecreased = {"txt":"население убывает", "loc":"happens when s-to-s population value decreased"};
locObj.requiredFieldsNotFilled = {"txt": "Требуемые поля не заполнены!", "loc":"happens in case of empty fields like login, password, etc"};
locObj.buildUpgradeHouse = {"txt":"ваш город достиг максимальной численности; постройте или улучшите дома", "loc":"the endturn tip in case of overpopulating"};
locObj.savedSuccessfully = {"txt":"игра сохранена успешно", "loc":"when manual save completed successfully"};
locObj.loadedSuccessfully = {"txt":"игра загружена успешно", "loc":"when loaded completed successfully"};
Expand Down

0 comments on commit f4ea43c

Please sign in to comment.