parent
c017067ed9
commit
6e2b215d07
@ -40,4 +40,4 @@
|
|||||||
"android"
|
"android"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -55,6 +55,52 @@ router.on("pageInit", function (pagedata) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the server is alive.
|
||||||
|
* @param {function} callback
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
function isServerAlive(callback) {
|
||||||
|
callAPIRawResponse("ping", {
|
||||||
|
username: localStorage.getItem("username"),
|
||||||
|
password: localStorage.getItem("password")
|
||||||
|
}, function (data) {
|
||||||
|
callback(true);
|
||||||
|
}, function (msg, xhr) {
|
||||||
|
app.preloader.hide();
|
||||||
|
if (xhr.status == 401) {
|
||||||
|
callback(true);
|
||||||
|
} else if (xhr.status == 400) {
|
||||||
|
callback(true);
|
||||||
|
} else {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two version strings.
|
||||||
|
* http://stackoverflow.com/a/16187766/2534036
|
||||||
|
* @param {string} a
|
||||||
|
* @param {string} b
|
||||||
|
* @returns a number < 0 if a < b, a number > 0 if a > b, 0 if a = b
|
||||||
|
*/
|
||||||
|
function compareVersions(a, b) {
|
||||||
|
var i, diff;
|
||||||
|
var regExStrip0 = /(\.0+)+$/;
|
||||||
|
var segmentsA = a.replace(regExStrip0, '').split('.');
|
||||||
|
var segmentsB = b.replace(regExStrip0, '').split('.');
|
||||||
|
var l = Math.min(segmentsA.length, segmentsB.length);
|
||||||
|
|
||||||
|
for (i = 0; i < l; i++) {
|
||||||
|
diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
|
||||||
|
if (diff) {
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return segmentsA.length - segmentsB.length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the saved username and password are valid.
|
* Check if the saved username and password are valid.
|
||||||
* @param {function} callback A function that will be called with a boolean argument indicating validity.
|
* @param {function} callback A function that will be called with a boolean argument indicating validity.
|
||||||
@ -79,22 +125,39 @@ function checkLogin(callback) {
|
|||||||
if (localStorage.getItem("configured") == null) {
|
if (localStorage.getItem("configured") == null) {
|
||||||
router.navigate("/signin");
|
router.navigate("/signin");
|
||||||
} else {
|
} else {
|
||||||
checkLogin(function (valid) {
|
isServerAlive(function (yes) {
|
||||||
if (valid) {
|
if (yes) {
|
||||||
callAPI("playerexists", {
|
callAPI("version", {
|
||||||
username: localStorage.getItem("username"),
|
username: localStorage.getItem("username"),
|
||||||
password: localStorage.getItem("password")
|
password: localStorage.getItem("password")
|
||||||
}, function (resp) {
|
}, function (data) {
|
||||||
if (resp.exists == true) {
|
$.getJSON("package.json", {}, function (local) {
|
||||||
router.navigate("/home");
|
if (compareVersions(local.version, data.version) < 0) {
|
||||||
} else {
|
router.navigate("/upgrade");
|
||||||
router.navigate("/chooseteam");
|
} else {
|
||||||
}
|
checkLogin(function (valid) {
|
||||||
}, function (msg) {
|
if (valid) {
|
||||||
router.navigate("/signin");
|
callAPI("playerexists", {
|
||||||
|
username: localStorage.getItem("username"),
|
||||||
|
password: localStorage.getItem("password")
|
||||||
|
}, function (resp) {
|
||||||
|
if (resp.exists == true) {
|
||||||
|
router.navigate("/home");
|
||||||
|
} else {
|
||||||
|
router.navigate("/chooseteam");
|
||||||
|
}
|
||||||
|
}, function (msg) {
|
||||||
|
router.navigate("/signin");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
router.navigate("/signin");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
router.navigate("/signin");
|
router.navigate("/connection");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "TerranQuest-Web",
|
"name": "TerranQuest-Web",
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^5.8.1",
|
"@fortawesome/fontawesome-free": "^5.8.1",
|
||||||
"framework7": "^4.3.0",
|
"framework7": "^4.3.0",
|
||||||
"jquery": "^3.4.0",
|
"jquery": "^3.4.0",
|
||||||
"mapbox-gl": "^0.54.0",
|
"mapbox-gl": "^0.54.0",
|
||||||
"three": "^0.104.0"
|
"three": "^0.104.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
www/pages/connection.html
Normal file
25
www/pages/connection.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
|
||||||
|
<div class="page" data-name="connection">
|
||||||
|
|
||||||
|
<div class="navbar">
|
||||||
|
<div class="navbar-inner">
|
||||||
|
<div class="title">No Connection</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="page-content">
|
||||||
|
|
||||||
|
<div class="block text-center">
|
||||||
|
<p>TerranQuest can't connect to the game server.
|
||||||
|
<br />
|
||||||
|
<span class="button button-outline button-large button-raised margin-top" onclick="restartApplication()">Try Again</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
23
www/pages/upgrade.html
Normal file
23
www/pages/upgrade.html
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
|
||||||
|
<div class="page" data-name="upgrade">
|
||||||
|
|
||||||
|
<div class="navbar">
|
||||||
|
<div class="navbar-inner">
|
||||||
|
<div class="title">Upgrade Required</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="page-content">
|
||||||
|
|
||||||
|
<div class="block text-center">
|
||||||
|
<p>This version of TerranQuest is too old to work properly with the
|
||||||
|
game server.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
@ -57,6 +57,16 @@ var routes = [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/upgrade',
|
||||||
|
url: './pages/upgrade.html',
|
||||||
|
name: 'upgrade'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/connection',
|
||||||
|
url: './pages/connection.html',
|
||||||
|
name: 'connection'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/settings',
|
path: '/settings',
|
||||||
name: 'settings',
|
name: 'settings',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user