-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuptime.html
513 lines (442 loc) · 22 KB
/
uptime.html
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="/assets/MadeYouLook.gif" id="favicon">
<link rel="stylesheet" href="https://use.typekit.net/cya2xsd.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Server Status</title>
<link rel="stylesheet" href="/css/uptime.css">
<link rel="stylesheet" href="/css/shared.css">
</head>
<body>
<nav id="navbar">
<div class="logo-container">
<a href="/"><img src="assets/logos/logo-whiteout.png" alt="Logo" class="navbar-logo"></a>
</div>
<button class="hamburger" id="hamburger">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</button>
<div class="menu-items right-menu" id="nav-menu">
<a href="https://files.npcz.gg">Abyss</a>
<a href="https://discord.gg/npc">Discord</a>
<a href="https://store.npcz.gg">Store</a>
<a href="/sandbox/rules">Guidelines</a>
<a href="https://discord.gg/npc">Report</a>
<a href="/">Home</a>
</div>
</nav>
<div class="total-players-banner">
<div class="total-players-content">
<span class="total-players-label">Total Players Online:</span>
<span class="total-players-count">0</span>
</div>
</div>
<div class="container-container">
<!-- Server panels will be dynamically inserted here -->
</div>
<div class="footer-gradient">
<div id="text-footer">
<div class="footer-column">
<img src="assets/logos/logo-whiteout.png" width="150" height="150" alt="Footer Logo">
</div>
<div class="footer-column">
<h3>About</h3>
<p>NPCZ is a server network focused around zombie<br>survival experiences on Garry's Mod. EST 2016</p>
</div>
<div class="footer-column">
<h3>Support</h3>
<p>Having Issues? Contact us at: <a href="mailto:[email protected]">[email protected]</a></p>
<p>Or create a support ticket in our <a href="https://discord.com/npc">Discord</a>.</p>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var navbar = document.getElementById('navbar');
window.addEventListener('scroll', function() {
if (window.pageYOffset > 0) {
navbar.classList.add('blur');
} else {
navbar.classList.remove('blur');
}
});
const hamburger = document.getElementById('hamburger');
const navMenu = document.getElementById('nav-menu');
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('active');
hamburger.classList.toggle('active');
});
});
</script>
<script>
const servers = [
{
id: 'sandbox',
name: 'Sandbox',
ip: '193.243.190.18',
port: 27015,
link: '/sandbox/connect.html',
},
{
id: 'zbox',
name: 'ZBox',
ip: '193.243.190.18',
port: 27064,
link: '/zbox/connect.html',
},
{
id: 'shelter',
name: 'Shelter',
ip: '193.243.190.18',
port: 27025,
link: '/shelter/connect.html',
},
{
id: 'horde',
name: 'Horde',
ip: '193.243.190.18',
port: 27065,
link: '/horde/connect.html',
},
{
id: 'zgrad1',
name: 'ZGRAD US1',
ip: '193.243.190.18',
port: 27066,
link: '/horde/connect.html',
},
{
id: 'harrison1',
name: 'Harrison US1',
ip: '193.243.190.18',
port: 27051,
},
{
id: 'harrison2',
name: 'Harrison US2',
ip: '193.243.190.18',
port: 27052,
},
{
id: 'harrison3',
name: 'Harrison US3',
ip: '193.243.190.18',
port: 27053,
},
];
function formatDuration(duration) {
const parts = duration.split(':').map(Number);
if (parts.length === 3) {
const hours = parts[0];
const minutes = parts[1];
return `${hours}h ${minutes}m`;
} else if (parts.length === 2) {
const minutes = parts[0];
return `${minutes} minutes`;
} else {
return duration;
}
}
const RATE_LIMIT_DURATION = 5000;
servers.forEach(server => {
server.lastRefreshTime = 0;
});
function updateTotalPlayers(servers) {
const totalPlayers = servers.reduce((sum, server) => sum + (server.currentPlayers || 0), 0);
document.querySelector('.total-players-count').textContent = totalPlayers;
}
const serverPromises = servers.map(server => {
return fetch(`https://gameserveranalytics.com/api/v2/query?game=source&ip=${server.ip}&port=${server.port}&type=info`)
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(serverInfo => {
console.log(`${server.name} Server Info:`, serverInfo);
if (
(serverInfo && serverInfo.status && serverInfo.status.toLowerCase() === 'online') ||
(serverInfo && (serverInfo.players !== undefined || serverInfo.map))
) {
server.online = true;
server.currentPlayers = serverInfo.players || serverInfo.num_players || serverInfo.playercount || 0;
server.maxPlayers = serverInfo.maxplayers || serverInfo.max_players || serverInfo.maxclients || 0;
server.mapName = serverInfo.map || 'Unknown Map';
if (server.currentPlayers > 0) {
return fetch(`https://gameserveranalytics.com/api/v2/query?game=source&ip=${server.ip}&port=${server.port}&type=players`)
.then(response => {
if (!response.ok) throw new Error('Failed to fetch players data');
return response.json();
})
.then(data => {
server.playersList = data;
});
} else {
server.playersList = [];
}
} else {
throw new Error('Server is offline');
}
})
.catch(error => {
console.error(`Error fetching data for ${server.name}:`, error);
server.online = false;
server.currentPlayers = 0;
server.maxPlayers = 0;
server.mapName = 'Unknown Map';
server.playersList = [];
});
});
Promise.all(serverPromises).then(() => {
servers.sort((a, b) => b.currentPlayers - a.currentPlayers);
updateTotalPlayers(servers);
const container = document.querySelector('.container-container');
servers.forEach(server => {
const serverPanel = document.createElement('div');
serverPanel.classList.add('server-panel');
const serverHeader = document.createElement('div');
serverHeader.classList.add('server-header');
const serverTitle = document.createElement('h2');
serverTitle.textContent = server.name;
serverHeader.appendChild(serverTitle);
const statusContainer = document.createElement('div');
statusContainer.classList.add('status-container');
const serverStatus = document.createElement('span');
serverStatus.id = `${server.id}-status`;
serverStatus.textContent = server.online ? 'Online' : 'Offline';
serverStatus.classList.add('server-status');
if (!server.online) {
serverStatus.classList.add('offline');
}
const boltSVG = document.createElementNS("http://www.w3.org/2000/svg", "svg");
boltSVG.setAttribute("xmlns", "http://www.w3.org/2000/svg");
boltSVG.setAttribute("viewBox", "0 0 24 24");
boltSVG.classList.add('status-bolt');
const boltPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
boltPath.setAttribute("d", "M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm-1 16v-5H7l6-7v5h4l-6 7z");
boltSVG.appendChild(boltPath);
serverStatus.appendChild(boltSVG);
statusContainer.appendChild(serverStatus);
const refreshButton = document.createElementNS("http://www.w3.org/2000/svg", "svg");
refreshButton.setAttribute("xmlns", "http://www.w3.org/2000/svg");
refreshButton.setAttribute("viewBox", "0 0 24 24");
refreshButton.classList.add('refresh-button');
refreshButton.setAttribute('data-server-id', server.id);
refreshButton.setAttribute('aria-label', `Refresh ${server.name} status`);
const refreshPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
refreshPath.setAttribute("d", "M10 11H7.101l.001-.009a4.956 4.956 0 0 1 .752-1.787 5.054 5.054 0 0 1 2.2-1.811c.302-.128.617-.226.938-.291a5.078 5.078 0 0 1 2.018 0 4.978 4.978 0 0 1 2.525 1.361l1.416-1.412a7.036 7.036 0 0 0-2.224-1.501 6.921 6.921 0 0 0-1.315-.408 7.079 7.079 0 0 0-2.819 0 6.94 6.94 0 0 0-1.316.409 7.04 7.04 0 0 0-3.08 2.534 6.978 6.978 0 0 0-1.054 2.505c-.028.135-.043.273-.063.41H2l4 4 4-4zm4 2h2.899l-.001.008a4.976 4.976 0 0 1-2.103 3.138 4.943 4.943 0 0 1-1.787.752 5.073 5.073 0 0 1-2.017 0 4.956 4.956 0 0 1-1.787-.752 5.072 5.072 0 0 1-.74-.61L7.05 16.95a7.032 7.032 0 0 0 2.225 1.5c.424.18.867.317 1.315.408a7.07 7.07 0 0 0 2.818 0 7.031 7.031 0 0 0 4.395-2.945 6.974 6.974 0 0 0 1.053-2.503c.027-.135.043-.273.063-.41H22l-4-4-4 4z");
refreshButton.appendChild(refreshPath);
statusContainer.appendChild(refreshButton);
serverHeader.appendChild(statusContainer);
serverPanel.appendChild(serverHeader);
const serverInfo = document.createElement('div');
serverInfo.classList.add('server-info');
const playerCount = document.createElement('p');
playerCount.id = `${server.id}-playercount`;
if (server.online) {
const playerCountText = server.currentPlayers > 0
? `${server.currentPlayers}/${server.maxPlayers} players online`
: 'No players online';
playerCount.textContent = playerCountText;
} else {
playerCount.textContent = 'Server Offline';
}
serverInfo.appendChild(playerCount);
const mapName = document.createElement('p');
mapName.id = `${server.id}-map`;
mapName.textContent = `Current Map: ${server.mapName}`;
serverInfo.appendChild(mapName);
serverPanel.appendChild(serverInfo);
const joinButton = document.createElement('a');
joinButton.href = server.link;
joinButton.classList.add('join-button');
joinButton.textContent = `Join ${server.name}`;
if (!server.online) {
joinButton.classList.add('disabled');
joinButton.onclick = (e) => e.preventDefault();
}
serverPanel.appendChild(joinButton);
if (server.playersList && server.playersList.length > 0) {
const playersTable = document.createElement('table');
playersTable.classList.add('player-table');
const thead = document.createElement('thead');
const headerRow = document.createElement('tr');
const headers = ['Name', 'Playtime'];
headers.forEach(headerText => {
const th = document.createElement('th');
th.textContent = headerText;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
playersTable.appendChild(thead);
const tbody = document.createElement('tbody');
server.playersList.forEach(player => {
const row = document.createElement('tr');
const nameCell = document.createElement('td');
nameCell.textContent = player.name && player.name.trim() ? player.name : 'Connecting...';
row.appendChild(nameCell);
const timeCell = document.createElement('td');
timeCell.textContent = formatDuration(player.duration_formatted);
row.appendChild(timeCell);
tbody.appendChild(row);
});
playersTable.appendChild(tbody);
serverPanel.appendChild(playersTable);
}
container.appendChild(serverPanel);
});
});
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('.container-container').addEventListener('click', function(event) {
const refreshButton = event.target.closest('.refresh-button');
if (refreshButton) {
const serverId = refreshButton.getAttribute('data-server-id');
const server = servers.find(s => s.id === serverId);
if (!server) {
console.error(`Server with ID ${serverId} not found.`);
return;
}
const currentTime = Date.now();
if (currentTime - server.lastRefreshTime < RATE_LIMIT_DURATION) {
alert('Please wait before refreshing again.');
return;
}
server.lastRefreshTime = currentTime;
refreshButton.classList.add('active', 'spin');
fetch(`https://gameserveranalytics.com/api/v2/query?game=source&ip=${server.ip}&port=${server.port}&type=info`)
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(serverInfo => {
if (
(serverInfo && serverInfo.status && serverInfo.status.toLowerCase() === 'online') ||
(serverInfo && (serverInfo.players !== undefined || serverInfo.map))
) {
server.online = true;
server.currentPlayers = serverInfo.players || serverInfo.num_players || serverInfo.playercount || 0;
server.maxPlayers = serverInfo.maxplayers || serverInfo.max_players || serverInfo.maxclients || 0;
server.mapName = serverInfo.map || 'Unknown Map';
if (server.currentPlayers > 0) {
return fetch(`https://gameserveranalytics.com/api/v2/query?game=source&ip=${server.ip}&port=${server.port}&type=players`)
.then(response => {
if (!response.ok) throw new Error('Failed to fetch players data');
return response.json();
})
.then(data => {
server.playersList = data;
});
} else {
server.playersList = [];
}
} else {
throw new Error('Server is offline');
}
})
.catch(error => {
console.error(`Error refreshing data for ${server.name}:`, error);
server.online = false;
server.currentPlayers = 0;
server.maxPlayers = 0;
server.mapName = 'Unknown Map';
server.playersList = [];
})
.finally(() => {
setTimeout(() => {
updateTotalPlayers(servers);
updateServerPanelUI(server);
refreshButton.classList.remove('active', 'spin');
}, 1000);
});
}
});
function updateServerPanelUI(server) {
const statusElement = document.getElementById(`${server.id}-status`);
if (statusElement) {
statusElement.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
node.textContent = server.online ? 'Online' : 'Offline';
}
});
if (server.online) {
statusElement.classList.remove('offline');
} else {
statusElement.classList.add('offline');
}
}
const playerCountElement = document.getElementById(`${server.id}-playercount`);
if (playerCountElement) {
if (server.online) {
const playerCountText = server.currentPlayers > 0
? `${server.currentPlayers}/${server.maxPlayers} players online`
: 'No players online';
playerCountElement.textContent = playerCountText;
} else {
playerCountElement.textContent = 'Server Offline';
}
}
const mapNameElement = document.getElementById(`${server.id}-map`);
if (mapNameElement) {
mapNameElement.textContent = `Current Map: ${server.mapName}`;
}
const joinButton = document.querySelector(`.join-button[href="${server.link}"]`);
if (joinButton) {
if (server.online) {
joinButton.classList.remove('disabled');
joinButton.onclick = null;
joinButton.href = server.link;
} else {
joinButton.classList.add('disabled');
joinButton.onclick = (e) => e.preventDefault();
}
}
const serverPanel = joinButton.closest('.server-panel');
if (serverPanel) {
const existingTable = serverPanel.querySelector('.player-table');
if (existingTable) {
existingTable.remove();
}
if (server.playersList && server.playersList.length > 0) {
const playersTable = document.createElement('table');
playersTable.classList.add('player-table');
const thead = document.createElement('thead');
const headerRow = document.createElement('tr');
const headers = ['Name', 'Playtime'];
headers.forEach(headerText => {
const th = document.createElement('th');
th.textContent = headerText;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
playersTable.appendChild(thead);
const tbody = document.createElement('tbody');
server.playersList.forEach(player => {
const row = document.createElement('tr');
const nameCell = document.createElement('td');
nameCell.textContent = player.name && player.name.trim() ? player.name : 'Connecting...';
row.appendChild(nameCell);
const timeCell = document.createElement('td');
timeCell.textContent = formatDuration(player.duration_formatted);
row.appendChild(timeCell);
tbody.appendChild(row);
});
playersTable.appendChild(tbody);
serverPanel.appendChild(playersTable);
}
}
}
});
</script>
<script>
function changeFavicon() {
const favicon = document.getElementById('favicon');
favicon.href = 'favicon.ico';
}
setTimeout(changeFavicon, 200);
</script>
</body>
</html>