-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.js
66 lines (54 loc) · 1.47 KB
/
checker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var statusUrl = 'http://www.dragongoserver.net/status.php';
var quickStatusUrl = 'http://www.dragongoserver.net/quick_status.php'
function checkServerStatus(callback)
{
var request = new XMLHttpRequest();
request.open("GET", quickStatusUrl, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
return callback(request.responseText)
}
}
request.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 1984 00:00:00 GMT");
request.send();
}
function parseStatus(statusString)
{
var lines = statusString.split('\n')
var games = []
for (var i = 0; i < lines.length; i++) {
var line = lines[i]
if (line.indexOf("Error") != -1) {
return 'Error'
}
/* Ignoring Warnings and blank lines */
if (line.indexOf("[") == 0 || line == "") {
continue
}
/* Just to be clear: this is struct :) */
var gameObject = {
"id": null,
"opponent": null,
"color": null,
"timestamp": null,
"time_rem": null
}
var pieces = line.split(',')
var cleanup = function(text) {
return text.trim().replace(/\'/g, "")
}
/* Check line, just in case */
if (pieces.length > 4) {
gameObject.id = cleanup(pieces[1])
gameObject.opponent = cleanup(pieces[2])
gameObject.color = cleanup(pieces[3]) == "W" ? "○" : "●";
gameObject.timestamp = cleanup(pieces[4])
gameObject.time_rem = cleanup(pieces[5])
games.push(gameObject)
}
else {
console.log("Error: DGS returned game in strange format")
}
}
return games
}