English Get player count JSON

44 replies
Goto Page
To the start Previous 1 2 3 Next To the start
05.05.20 08:00:27 pm
Up
Mami Tomoe
User
Offline Off
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:
Code:
1
2
3
4
5
{
     players = 4
     maxplayers = 4
     name = "server"
}


Basic right? I hope this is possible.
fish
05.05.20 08:19:20 pm
Up
Starkkz
Moderator
Offline Off
You want to develop a RESTful API to get the server stats by the server's IP address? Is it what you want?
lol
05.05.20 08:23:08 pm
Up
Avo
User
Offline Off
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
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:
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:
Code:
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
Trust me, I'm an engineer | user DC approved file cs2d Super extra mod for CS2D (64), yeah!
05.05.20 08:41:14 pm
Up
Mami Tomoe
User
Offline Off
Okay and how do I download a file with Lua?
socket.http
doesn't seem to exist.
fish
05.05.20 08:48:06 pm
Up
The Dark Shadow
User
Offline Off
Use
dgram


Code:
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
05.05.20 08:53:46 pm
Up
Mami Tomoe
User
Offline Off
But how? I've tried to google but it seems complicated.
fish
05.05.20 08:57:35 pm
Up
The Dark Shadow
User
Offline Off
My way is too complicated yeah, You may use what @user Avo said, It's much easier.
05.05.20 08:59:40 pm
Up
Mami Tomoe
User
Offline Off
Yeah but I want to download the URL into a string somehow...
fish
05.05.20 09:02:47 pm
Up
TrialAndError
User
Offline Off
@user Mami Tomoe: Are you using pure lua or CS2D
05.05.20 09:05:45 pm
Up
Mami Tomoe
User
Offline Off
CS2D Lua, I want to have a server specifically for doing file downloading and stuff
fish
05.05.20 09:13:16 pm
Up
The Dark Shadow
User
Offline Off
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
06.05.20 10:24:51 am
Up
Gaios
Security Supporter
Offline Off
Spoiler >

I get Timeout.
06.05.20 01:51:11 pm
Up
The Dark Shadow
User
Offline Off
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
06.05.20 02:43:09 pm
Up
Mami Tomoe
User
Offline Off
I just want something simple that works...
fish
06.05.20 02:45:21 pm
Up
Avo
User
Offline Off
@user 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:
user Mami Tomoe has written:
Okay and how do I download a file with Lua?
socket.http
doesn't seem to exist.

You might want to see file us [Lua 5.1] LuaSocket 3.0 x86 Windows/Linux/MacOS (6).
edited 1×, last 06.05.20 04:07:33 pm
Trust me, I'm an engineer | user DC approved file cs2d Super extra mod for CS2D (64), yeah!
06.05.20 04:18:49 pm
Up
TrialAndError
User
Offline Off
What is the end goal of getting the server stats for servers, are you trying to make a "hub/lobby" or something?
06.05.20 04:46:06 pm
Up
The Dark Shadow
User
Offline Off
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
06.05.20 06:05:53 pm
Up
DC
Admin
Offline Off
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
06.05.20 07:44:39 pm
Up
Mami Tomoe
User
Offline Off
And how would I do it using UDP and Lua?
fish
07.05.20 11:51:37 am
Up
Devil-Thanh
GAME BANNED
Offline Off
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 Next To the start