-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.js
103 lines (84 loc) · 2.78 KB
/
check.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var http = require('http');
var config = require('./config');
var utils = require('./utils');
var status = [
{"minecraft.net":"green:Online:100.0"},
{"account.mojang.com":"green:Online:100.0"},
{"authserver.mojang.com":"green:Online:100.0"},
{"skins.minecraft.net":"green:Online:100.0"},
{"auth.mojang.com":"green:Online:100.0"},
{"login.minecraft.net":"green:Online:100.0"},
{"session.minecraft.net":"green:Online:100.0"},
{"version": config.version},
{"lastcheck": utils.getUTCTime()}
];
var checks = [];
status.forEach(function (element, index, array) {
checks.push([]);
});
var getStatus = function () {
return status;
};
exports.getStatus = getStatus;
var checkService = function (url, caller, index) {
// Make request
utils.request(url, function (reply) {
var stat = utils.parseReply(reply);
if (stat.indexOf("red") !== -1) { // Offline
checks[index].push(false);
} else {
checks[index].push(true);
}
var newService = {};
newService[caller] = stat + utils.calculateUptime(checks[index])
status[index] = newService;
utils.log("Updated with " + url);
utils.log("-> " + status[index][caller].split(":")[1] + " (" + status[index][caller].split(":")[2] + "%)");
});
};
exports.checkService = checkService;
statusCheck = function (callback) {
callback = callback || function () {};
status.forEach(function (element, index, array) {
// Minecraft website
if (element["minecraft.net"]) {
checkService("http://minecraft.net", "minecraft.net", index);
return;
}
// Account server
if (element["account.mojang.com"]) {
checkService("https://account.mojang.com", "account.mojang.com", index);
return;
}
// Authenticantion server
if (element["authserver.mojang.com"]) {
checkService("https://authserver.mojang.com/authenticate", "account.mojang.com", index);
return;
}
// Skins server
if (element["skins.minecraft.net"]) {
checkService("http://s3.amazonaws.com/MinecraftSkins/BurningFurnace.png", "skins.minecraft.net", index);
return;
}
// Account server (Legacy)
if (element["auth.mojang.com"]) {
checkService("https://auth.mojang.com/", "auth.mojang.com", index);
return;
}
// Login server (Legacy)
if (element["login.minecraft.net"]) {
checkService("http://login.minecraft.net/session", "login.minecraft.net", index);
return;
}
// Session server (Legacy)
if (element["session.minecraft.net"]) {
checkService("http://session.minecraft.net/game/joinserver.jsp", "session.minecraft.net", index);
return;
}
if (element["lastcheck"]) {
status[index] = {'lastcheck': utils.getUTCTime()};
};
});
callback(status);
};
exports.statusCheck = statusCheck;