Get player count JSON
41 replies05.05.20 08:00:27 pm
I don't really know where this would fit best, but I want to get a JSON and turn it into server stats.
Example:
www.usgn.de/serverstats?1.2.3.4:6969
Will result in a file such as:
Basic right? I hope this is possible.
Example:
www.usgn.de/serverstats?1.2.3.4:6969
Will result in a file such as:
Code:
1
2
3
4
5
2
3
4
5
{
players = 4
maxplayers = 4
name = "server"
}
players = 4
maxplayers = 4
name = "server"
}
Basic right? I hope this is possible.
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
You want to develop a RESTful API to get the server stats by the server's IP address? Is it what you want?
I made a little investigation of http://www.unrealsoftware.de/usgn.php?s=cs2d and find out that you can make a GET call to
For example:
returned
It's not JSON, but I guess you can use parse it and make use of that. It's simple HTML with table tags.
Parameters of a call:
Code:
www.unrealsoftware.de/inc_pub/serverinfo.php
For example:
Code:
http://www.unrealsoftware.de/inc_pub/serverinfo.php?i=85.25.143.56&p=36955&g=0&123
returned
Code:
(visible content only, HTML tags omitted)Name: [Q][GamersCentral.de][Public]
Map: de_dust2
Players: 2 / 32 (Bots: 0)
Password: None
U.S.G.N. only: Off
Fog of War: On
Friendly Fire: Off
Lua: Uses Lua Scripts!
Game Mode: Standard
Map: de_dust2
Players: 2 / 32 (Bots: 0)
Password: None
U.S.G.N. only: Off
Fog of War: On
Friendly Fire: Off
Lua: Uses Lua Scripts!
Game Mode: Standard
It's not JSON, but I guess you can use parse it and make use of that. It's simple HTML with table tags.
Parameters of a call:
Code:
http://www.unrealsoftware.de/inc_pub/serverinfo.php?i=<IP>&p=<PORT>&g=<GAME ID, 0 for CS2D>&<SOME RANDOM NUMBER>
edited 2×, last 05.05.20 08:37:30 pm
Trust me, I'm an engineer |
DC approved
Super extra mod for CS2D (64), yeah!



Okay and how do I download a file with Lua?
socket.http
doesn't seem to exist. Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
Use
Replace ip with server ip address
Replace port with server port
EDIT: Fixed the code!
dgram
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const dgram = require("dgram")
let sock = dgram.createSocket("udp4")
let text;
sock.on('error', (err) => {
console.log(`error:\n${err.stack}`);
sock.close();
});
sock.on("message", function(msg, rinfo) {
text = `server got: ${msg} from ${rinfo.address}:${rinfo.port}`
console.log(text);
})
sock.on('listening', () => {
const address = sock.address();
console.log(`server listening ${address.address}:${address.port}`);
});
sock.send(Buffer.from("0100FB01", "hex"), port, "ip")
let sock = dgram.createSocket("udp4")
let text;
sock.on('error', (err) => {
console.log(`error:\n${err.stack}`);
sock.close();
});
sock.on("message", function(msg, rinfo) {
text = `server got: ${msg} from ${rinfo.address}:${rinfo.port}`
console.log(text);
})
sock.on('listening', () => {
const address = sock.address();
console.log(`server listening ${address.address}:${address.port}`);
});
sock.send(Buffer.from("0100FB01", "hex"), port, "ip")
Replace ip with server ip address
Replace port with server port
EDIT: Fixed the code!
edited 2×, last 05.05.20 08:59:45 pm
But how? I've tried to google but it seems complicated.
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
My way is too complicated yeah, You may use what @
Avo said, It's much easier.

Yeah but I want to download the URL into a string somehow...
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
CS2D Lua, I want to have a server specifically for doing file downloading and stuff
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
If you want simpler method, not recommended though, can cause traffic to unrealsoftware itself. Use
Avo's method.
Off-topic: I personally recommend asking for such help in unreal software discord instead, there is a specificed channel for it. There are so many good developers who are experienced at that area and there are more active developers than in here.

Off-topic: I personally recommend asking for such help in unreal software discord instead, there is a specificed channel for it. There are so many good developers who are experienced at that area and there are more active developers than in here.
edited 1×, last 05.05.20 09:24:14 pm
That's why I said It's not recommended, So the best way is using datagram. Why don't you use it
Mami Tomoe? Even If It's complicated you will need to learn it in the future so why not now? We are here we can try our best to help you

I just want something simple that works...
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
@
Gaios: it seems to happen when the IP and/or port is wrong or server is not reachable by USGN itself (due to high latency, I believe).
Edit:
Mami Tomoe has written:
You might want to see
[Lua 5.1] LuaSocket 3.0 x86 Windows/Linux/MacOS (6).

Edit:

Okay and how do I download a file with Lua?
socket.http
doesn't seem to exist.You might want to see


edited 1×, last 06.05.20 04:07:33 pm
Trust me, I'm an engineer |
DC approved
Super extra mod for CS2D (64), yeah!



What is the end goal of getting the server stats for servers, are you trying to make a "hub/lobby" or something?
Look, So now they are offering you to use LuaSocket, It's complicated too. So finally you should get back to my way, Using my way you don't have to install anything because it uses nodeJS itself to request data, Just use the code I've posted above then you're done. It gets the server map, server name. If you would like to add more you would have to find the hexadecimal address of what you would like to add.
Note: It also shows some special characters If you don't want to, Just use regular expressions to avoid that.
Note: It also shows some special characters If you don't want to, Just use regular expressions to avoid that.
edited 3×, last 06.05.20 05:05:58 pm
Careful! The
Moreover it's quite inefficient. What that PHP script does is requesting the info from the server directly via a UDP socket (that's what
The Dark Shadow explained). So when you use that you would have the full HTTP request with all its overhead in between for no good reason at all.
In general the USGN is not required at all to get information from a server (as long as you have the IP already).
The recommended approach would be to get the server details directly from the server via UDP.
http://www.unrealsoftware.de/inc_pub/serverinfo.php
PHP script is NOT a public API! You should NOT use it because I can't guarantee that this script will stay the way it is. It's very likely that it will be changed in future. That would break your stuff. Also it's not designed for mass requests. So it's a bad idea to call it often. Don't get me wrong: I don't mind if you use it (unless you plan to call it frequently, that would slow down my whole server) but it's not made for external use.Moreover it's quite inefficient. What that PHP script does is requesting the info from the server directly via a UDP socket (that's what

In general the USGN is not required at all to get information from a server (as long as you have the IP already).
The recommended approach would be to get the server details directly from the server via UDP.
And how would I do it using UDP and Lua?
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?