parent
c017067ed9
commit
6e2b215d07
@ -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.
|
||||
* @param {function} callback A function that will be called with a boolean argument indicating validity.
|
||||
@ -79,6 +125,16 @@ function checkLogin(callback) {
|
||||
if (localStorage.getItem("configured") == null) {
|
||||
router.navigate("/signin");
|
||||
} else {
|
||||
isServerAlive(function (yes) {
|
||||
if (yes) {
|
||||
callAPI("version", {
|
||||
username: localStorage.getItem("username"),
|
||||
password: localStorage.getItem("password")
|
||||
}, function (data) {
|
||||
$.getJSON("package.json", {}, function (local) {
|
||||
if (compareVersions(local.version, data.version) < 0) {
|
||||
router.navigate("/upgrade");
|
||||
} else {
|
||||
checkLogin(function (valid) {
|
||||
if (valid) {
|
||||
callAPI("playerexists", {
|
||||
@ -97,4 +153,11 @@ if (localStorage.getItem("configured") == null) {
|
||||
router.navigate("/signin");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
router.navigate("/connection");
|
||||
}
|
||||
});
|
||||
}
|
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',
|
||||
name: 'settings',
|
||||
|
Loading…
x
Reference in New Issue
Block a user