Forum

> > CS2D > General > Get player count JSON
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Get player count JSON

61 replies
Page
To the start Previous 1 2 3 4 Next To the start

old Get player count JSON

Mami Tomoe
User Off Offline

Quote
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:
1
2
3
4
5
{
	players = 4
	maxplayers = 4
	name = "server"
}

Basic right? I hope this is possible.

old Re: Get player count JSON

Starkkz
Moderator Off Offline

Quote
You want to develop a RESTful API to get the server stats by the server's IP address? Is it what you want?

old Re: Get player count JSON

Avo
User Off Offline

Quote
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
www.unrealsoftware.de/inc_pub/serverinfo.php

For example:
http://www.unrealsoftware.de/inc_pub/serverinfo.php?i=85.25.143.56&p=36955&g=0&123

returned
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
(visible content only, HTML tags omitted)

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:
http://www.unrealsoftware.de/inc_pub/serverinfo.php?i=<IP>&p=<PORT>&g=<GAME ID, 0 for CS2D>&<SOME RANDOM NUMBER>

Spoiler >


Fragments of HTML and JS code that helped me to figure it out >
edited 2×, last 05.05.20 08:37:30 pm

old Re: Get player count JSON

The Dark Shadow
User Off Offline

Quote
Use
dgram


1
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")

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

old Re: Get player count JSON

The Dark Shadow
User Off Offline

Quote
If you want simpler method, not recommended though, can cause traffic to unrealsoftware itself. Use user 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.
edited 1×, last 05.05.20 09:24:14 pm

old Re: Get player count JSON

Gaios
Reviewer Off Offline

Quote
Spoiler >

I get Timeout.

old Re: Get player count JSON

The Dark Shadow
User Off Offline

Quote
That's why I said It's not recommended, So the best way is using datagram. Why don't you use it user 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

old Re: Get player count JSON

The Dark Shadow
User Off Offline

Quote
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.
edited 3×, last 06.05.20 05:05:58 pm

old Re: Get player count JSON

DC
Admin Off Offline

Quote
Careful! The
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 user 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.

old Re: Get player count JSON

Devil-Thanh
GAME BANNED Off Offline

Quote
I'm using nodejs childprocess to run cs2d dedicated server, then read the output console from it and use firebase to get stuffs on server. Got it works with realtime chat log and player list, server info, etc..
To the start Previous 1 2 3 4 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview