Forum

> > CS2D > General > Get player count JSON
ForenübersichtCS2D-ÜbersichtGeneral-ÜbersichtEinloggen, um zu antworten

Englisch Get player count JSON

61 Antworten
Seite
Zum Anfang Vorherige 1 2 3 4 Nächste Zum Anfang

alt Get player count JSON

Mami Tomoe
User Off Offline

Zitieren
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.

alt Re: Get player count JSON

Starkkz
Moderator Off Offline

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

alt Re: Get player count JSON

Avo
User Off Offline

Zitieren
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 >
2× editiert, zuletzt 05.05.20 20:37:30

alt Re: Get player count JSON

The Dark Shadow
User Off Offline

Zitieren
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!
2× editiert, zuletzt 05.05.20 20:59:45

alt Re: Get player count JSON

The Dark Shadow
User Off Offline

Zitieren
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.
1× editiert, zuletzt 05.05.20 21:24:14

alt Re: Get player count JSON

Gaios
Reviewer Off Offline

Zitieren
Spoiler >

I get Timeout.

alt Re: Get player count JSON

The Dark Shadow
User Off Offline

Zitieren
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

alt Re: Get player count JSON

The Dark Shadow
User Off Offline

Zitieren
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.
3× editiert, zuletzt 06.05.20 17:05:58

alt Re: Get player count JSON

DC
Admin Off Offline

Zitieren
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.

alt Re: Get player count JSON

Devil-Thanh
GAME BANNED Off Offline

Zitieren
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..
Zum Anfang Vorherige 1 2 3 4 Nächste Zum Anfang
Einloggen, um zu antwortenGeneral-ÜbersichtCS2D-ÜbersichtForenübersicht