-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
205 lines (188 loc) · 4.41 KB
/
index.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
const axios = require('axios');
const DEFAULT_OPTIONS = {
timeout: 10000
};
class Server {
constructor(ip, options) {
if (!ip) throw Error('Please provide an IP.');
this.ip = ip;
this.options = Object.assign(DEFAULT_OPTIONS, options);
}
getPlayers() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/players.json`, { timeout: this.options.timeout })
.then(function(body) {
let players = body.data;
send(players.length);
})
.catch(function(error) {
err(error);
});
});
}
getPlayersAll() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/players.json`, { timeout: this.options.timeout })
.then(function(body) {
let players = body.data;
send(players);
})
.catch(function(error) {
err(error);
});
});
}
getServerStatus() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let server_status = {
online: true,
}
send(server_status);
})
.catch(function(error) {
let server_status = {
online: false,
url: error.config.url,
method: error.config.method
}
if (error.response == undefined) send(server_status)
});
});
}
getResources() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let resources = body.data.resources;
send(resources);
})
.catch(function(error) {
err(error);
});
});
}
getOnesync() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let onesync = body.data.vars.onesync_enabled;
send(onesync);
})
.catch(function(error) {
err(error);
});
});
}
getMaxPlayers() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let maxClients = body.data.vars.sv_maxClients;
send(maxClients);
})
.catch(function(error) {
err(error);
});
});
}
getLocale() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let locale = body.data.vars.locale;
send(locale);
})
.catch(function(error) {
err(error);
});
});
}
getGamename() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let gamename = body.data.vars.gamename;
send(gamename);
})
.catch(function(error) {
err(error);
});
});
}
getEnhancedHostSupport() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let enhancedHostSupport = body.data.vars.sv_enhancedHostSupport;
send(enhancedHostSupport);
})
.catch(function(error) {
err(error);
});
});
}
getlicenseKeyToken() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let licenseKeyToken = body.data.vars.sv_licenseKeyToken;
send(licenseKeyToken);
})
.catch(function(error) {
err(error);
});
});
}
getScriptHookAllowed() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let scriptHookAllowed = body.data.vars.sv_scriptHookAllowed;
send(scriptHookAllowed);
})
.catch(function(error) {
err(error);
});
});
}
getTags() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let tags = body.data.vars.tags;
send(tags);
})
.catch(function(error) {
err(error);
});
});
}
getServer() {
return new Promise((send, err) => {
axios
.get(`http:https://${this.ip}/info.json`, { timeout: this.options.timeout })
.then(function(body) {
let server = body.data;
send(server);
})
.catch(function(error) {
err(error);
});
});
}
}
module.exports.Server = Server;