-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (29 loc) · 914 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (29 loc) · 914 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
const express = require('express');
const Gamedig = require('gamedig');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/server-info', async (req, res) => {
const { ip, port } = req.query;
if (!ip || !port) {
return res.status(400).json({ error: 'ip and port are required query params' });
}
try {
// Selon ton jeu : cs16 (pour Counter-Strike 1.6), csgo (pour CS:GO), etc.
const result = await Gamedig.query({
type: 'cs16',
host: ip,
port: parseInt(port)
});
res.json({
serverName: result.name,
map: result.map,
players: result.players.length,
maxPlayers: result.maxplayers
});
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.listen(PORT, () => {
console.log(`API listening on port ${PORT}`);
});