Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Run
npm start
```

## get a server status

Now you can make a request like this:

`localhost:8080/?ip=192.168.1.3&port=27015`
Expand Down Expand Up @@ -65,4 +67,13 @@ You can then access this information through `/servers`.

```
["192.168.1.1:27015","10.0.0.1:27015","1.1.1.1:27020"]
```
```

### servers.txt statuses (statusall)

If you're using a `servers.txt` file, you can make a request like this:

`localhost:8080/statusall`

If the `servers.txt` has valid RCON addresses, it will return an array of objects exact same as `get a server status` section,
of all servers described on it.
25 changes: 25 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ app.get("/servers", (req, res) => {
}
});

app.get("/statusall", (req, res) => {
if (!fs.existsSync("./servers.txt")) {
res.status(200).send({
status: "error",
message: "no servers.txt found"
})
}
else {
const data = fs.readFileSync("./servers.txt").toString();
const servers = data.split(/\r?\n/)

Promise.all(servers.map(server => {
let parts = server.split(/\:/)
return getStatus(parts[0], parts[1])
})).then(allServersResult => {
res.status(200).send(allServersResult);
}, (error) => {
res.status(200).send({
status: "error",
message: error.toString()
});
});
}
})

function start() {
// Start http server
http.createServer(app).listen(http_port, () => {
Expand Down