-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (27 loc) · 958 Bytes
/
Copy pathserver.js
File metadata and controls
33 lines (27 loc) · 958 Bytes
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
const express = require('express');
const { GameDig } = require('gamedig');
const app = express();
app.get('/query', async (req, res) => {
const ip = req.query.ip;
const port = parseInt(req.query.port) || 2476;
if (!ip) return res.status(400).json({ error: 'Missing IP' });
try {
const state = await GameDig.query({
type: 'csgo',
host: ip,
port: port,
maxAttempts: 3
});
const players = state.players.map(p => ({
name: p.name || 'Unknown',
score: p.raw?.score || 0,
time: p.raw?.time ? new Date(p.raw.time * 1000).toISOString().substr(11, 8) : 'Online'
}));
res.json({ players });
} catch (error) {
res.status(500).json({ error: 'Game server offline' });
}
});
const listener = app.listen(process.env.PORT || 3000, () => {
console.log('Proxy running on port ' + listener.address().port);
});