SRCDS Steam group


PHP Script A2S_INFO
#1
Hi!

Does anyone have a working php scripts which uses an UDP connection
to retrieve information about a server such as max players, current map
etc?

I've been scourging the web for a script and I've found several of them but
none of them have worked.
Reply
#2
(02-01-2011, 12:32 AM)knullapa Wrote:  Hi!

Does anyone have a working php scripts which uses an UDP connection
to retrieve information about a server such as max players, current map
etc?

I've been scourging the web for a script and I've found several of them but
none of them have worked.

Why do you need a UDP connection, when it's easier with TCP? Smile

TCP: http://forums.srcds.com/viewtopic/13249
Reply
#3
(02-01-2011, 01:44 AM)realchamp Wrote:  
(02-01-2011, 12:32 AM)knullapa Wrote:  Hi!

Does anyone have a working php scripts which uses an UDP connection
to retrieve information about a server such as max players, current map
etc?

I've been scourging the web for a script and I've found several of them but
none of them have worked.

Why do you need a UDP connection, when it's easier with TCP? Smile

TCP: http://forums.srcds.com/viewtopic/13249
The script you linked to is using a UDP connection and sadly it doesn't
work for me. If you could confirm that it's working I would be grateful.

And if you are asking why I want UDP, it's because it requires less resources
from the network. I am writing an application in c++ but for the moment in
php just to learn how to communicate with a CSS server.

If TCP is my only option, I am willing to try it.
Once again, if anyone can confirm that the linked script is working, I would be grateful.
Reply
#4
(02-01-2011, 01:56 AM)knullapa Wrote:  
(02-01-2011, 01:44 AM)realchamp Wrote:  
(02-01-2011, 12:32 AM)knullapa Wrote:  Hi!

Does anyone have a working php scripts which uses an UDP connection
to retrieve information about a server such as max players, current map
etc?

I've been scourging the web for a script and I've found several of them but
none of them have worked.

Why do you need a UDP connection, when it's easier with TCP? Smile

TCP: http://forums.srcds.com/viewtopic/13249
The script you linked to is using a UDP connection and sadly it doesn't
work for me. If you could confirm that it's working I would be grateful.

And if you are asking why I want UDP, it's because it requires less resources
from the network. I am writing an application in c++ but for the moment in
php just to learn how to communicate with a CSS server.

If TCP is my only option, I am willing to try it.
Once again, if anyone can confirm that the linked script is working, I would be grateful.

Sorry 'bout that.

I can confirm it's working here. I successfully managed to get the game from a server.

Maybe this is something for you.
http://developer.valvesoftware.com/wiki/Source_RCON_Protocol
Go to the links in the bottom.
Reply
#5
Now this makes me really dubious. I've tried this script a thousand of times on different hosts (xampp - localhost, one.com - domain)
and several different IP - Addresses but none of them have worked with this script. Just to be 100 percent sure, did you connect to a CSS
server and used exactly this script?
Code:
function query_source($address)
  {
    $array = explode(":", $address);

    $server['status'] = 0;
    $server['ip']     = $array[0];
    $server['port']   = $array[1];

    if (!$server['ip'] || !$server['port']) { exit("EMPTY OR INVALID ADDRESS"); }

    $socket = @fsockopen("udp://{$server['ip']}", $server['port'], $errno, $errstr, 1);

    if (!$socket) { return $server; }

    stream_set_timeout($socket, 1);
    stream_set_blocking($socket, TRUE);
    fwrite($socket, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
    $packet = fread($socket, 4096);
    @fclose($socket);

    if (!$packet) { return $server; }

    $header                = substr($packet, 0, 4);
    $response_type         = substr($packet, 4, 1);
    $network_version       = ord(substr($packet, 5, 1));

    if ($response_type != "I") { exit("NOT A SOURCE SERVER"); }

    $packet_array          = explode("\x00", substr($packet, 6), 5);
    $server['name']        = $packet_array[0];
    $server['map']         = $packet_array[1];
    $server['game']        = $packet_array[2];
    $server['description'] = $packet_array[3];
    $packet                = $packet_array[4];
    $app_id                = array_pop(unpack("S", substr($packet, 0, 2)));
    $server['players']     = ord(substr($packet, 2, 1));
    $server['playersmax']  = ord(substr($packet, 3, 1));
    $server['bots']        = ord(substr($packet, 4, 1));
    $server['status']      = 1;
    $server['dedicated']   =     substr($packet, 5, 1);
    $server['os']          =     substr($packet, 6, 1);
    $server['password']    = ord(substr($packet, 7, 1));
    $server['vac']         = ord(substr($packet, 8, 1));

    return $server;
  }
$query = query_source("127.0.0.1:27015");
echo $query['game'];
As soon as I try this script the connection times out, no matter host nor server.

And thanks for the link but I am not interested in rcon since it requires the rcon password and doesn't have the same
features as a UDP connection (you need to use rcon status instead of A2S_INFO etc.)

I've also tried to use SSQ but not even this library has worked. I'll have to do more testing, but as I said, could you tell me what host and
game-type your server were when you retrieved the information?

EDIT: Now I've tried this script on two additional webhosts and countless of server IPs without success... (CSS)
Reply
#6
I tested it on a friends zombie server. Yes it is a Counter-Strike: Source server on Linux.

These are my specs:
Linux Debian
Lighttpd (webserver)
PHP Version 5.2.6-1+lenny9
Reply
#7
Man, this is really bugging me. I've tried the script on both 110mb and one.com.
I've been using game-monitor to find several different servers on both OS.

Since not a single server is working I modified the script so I could change IP more
frequently without success. The most annyoing thing is that "rcon challenge" and A2A_PING
is working - but not A2S_INFO.

You can try to ping your server on this address, and see if it works for you @ http://atomen.110mb.com/temp.php?ip=ip_here
Reply
#8
Try the following here.

Code:
function query_source($address)
  {
    $array = explode(":", $address);

    $server['status'] = 0;
    $server['ip']     = $array[0];
    $server['port']   = $array[1];

    if (!$server['ip'] || !$server['port']) { exit("EMPTY OR INVALID ADDRESS"); }

    $socket = @fsockopen("udp://{$server['ip']}", $server['port'], $errno, $errstr, 1);

    if (!$socket) { return $server; }

    stream_set_timeout($socket, 1);
    stream_set_blocking($socket, TRUE);
    fwrite($socket, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
    $packet = fread($socket, 4096);
    @fclose($socket);

    if (!$packet) { return $server; }

    $header                = substr($packet, 0, 4);
    $response_type         = substr($packet, 4, 1);
    $network_version       = ord(substr($packet, 5, 1));

    if ($response_type != "I") { exit("NOT A SOURCE SERVER"); }

    $packet_array          = explode("\x00", substr($packet, 6), 5);
    $server['name']        = $packet_array[0];
    $server['map']         = $packet_array[1];
    $server['game']        = $packet_array[2];
    $server['description'] = $packet_array[3];
    $packet                = $packet_array[4];
    $app_id                = array_pop(unpack("S", substr($packet, 0, 2)));
    $server['players']     = ord(substr($packet, 2, 1));
    $server['playersmax']  = ord(substr($packet, 3, 1));
    $server['bots']        = ord(substr($packet, 4, 1));
    $server['status']      = 1;
    $server['dedicated']   =     substr($packet, 5, 1);
    $server['os']          =     substr($packet, 6, 1);
    $server['password']    = ord(substr($packet, 7, 1));
    $server['vac']         = ord(substr($packet, 8, 1));

    return $server;
  }
print_r(query_source("127.0.0.1:27015"));
This should print all the info it receives.

Also I couldn't receive anything from the link you provided. Sad
Got the following:
Response:
Reply
#9
(02-02-2011, 03:13 AM)realchamp Wrote:  Try the following here.

Code:
function query_source($address)
  {
    $array = explode(":", $address);

    $server['status'] = 0;
    $server['ip']     = $array[0];
    $server['port']   = $array[1];

    if (!$server['ip'] || !$server['port']) { exit("EMPTY OR INVALID ADDRESS"); }

    $socket = @fsockopen("udp://{$server['ip']}", $server['port'], $errno, $errstr, 1);

    if (!$socket) { return $server; }

    stream_set_timeout($socket, 1);
    stream_set_blocking($socket, TRUE);
    fwrite($socket, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
    $packet = fread($socket, 4096);
    @fclose($socket);

    if (!$packet) { return $server; }

    $header                = substr($packet, 0, 4);
    $response_type         = substr($packet, 4, 1);
    $network_version       = ord(substr($packet, 5, 1));

    if ($response_type != "I") { exit("NOT A SOURCE SERVER"); }

    $packet_array          = explode("\x00", substr($packet, 6), 5);
    $server['name']        = $packet_array[0];
    $server['map']         = $packet_array[1];
    $server['game']        = $packet_array[2];
    $server['description'] = $packet_array[3];
    $packet                = $packet_array[4];
    $app_id                = array_pop(unpack("S", substr($packet, 0, 2)));
    $server['players']     = ord(substr($packet, 2, 1));
    $server['playersmax']  = ord(substr($packet, 3, 1));
    $server['bots']        = ord(substr($packet, 4, 1));
    $server['status']      = 1;
    $server['dedicated']   =     substr($packet, 5, 1);
    $server['os']          =     substr($packet, 6, 1);
    $server['password']    = ord(substr($packet, 7, 1));
    $server['vac']         = ord(substr($packet, 8, 1));

    return $server;
  }
print_r(query_source("127.0.0.1:27015"));
This should print all the info it receives.

Also I couldn't receive anything from the link you provided. Sad
Got the following:
Response:
I am using the script you posted I've only enabled it to work with GET requests. Though I've also used the original script without ANY modifications but it still doesn't work.

This just keeps getting weirder...

The thing is, I've tried so many different scripts, on different platforms, with different servers and even with
different programming languages but none. Not a single script has worked - though they all have in common that ping
and "rcon challenge" command works (A2S_SERVERQUERY_GETCHALLENGE also works, haven't tried A2S_PLAYER).
Reply
#10
(02-02-2011, 03:52 AM)knullapa Wrote:  
(02-02-2011, 03:13 AM)realchamp Wrote:  Try the following here.

Code:
function query_source($address)
  {
    $array = explode(":", $address);

    $server['status'] = 0;
    $server['ip']     = $array[0];
    $server['port']   = $array[1];

    if (!$server['ip'] || !$server['port']) { exit("EMPTY OR INVALID ADDRESS"); }

    $socket = @fsockopen("udp://{$server['ip']}", $server['port'], $errno, $errstr, 1);

    if (!$socket) { return $server; }

    stream_set_timeout($socket, 1);
    stream_set_blocking($socket, TRUE);
    fwrite($socket, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
    $packet = fread($socket, 4096);
    @fclose($socket);

    if (!$packet) { return $server; }

    $header                = substr($packet, 0, 4);
    $response_type         = substr($packet, 4, 1);
    $network_version       = ord(substr($packet, 5, 1));

    if ($response_type != "I") { exit("NOT A SOURCE SERVER"); }

    $packet_array          = explode("\x00", substr($packet, 6), 5);
    $server['name']        = $packet_array[0];
    $server['map']         = $packet_array[1];
    $server['game']        = $packet_array[2];
    $server['description'] = $packet_array[3];
    $packet                = $packet_array[4];
    $app_id                = array_pop(unpack("S", substr($packet, 0, 2)));
    $server['players']     = ord(substr($packet, 2, 1));
    $server['playersmax']  = ord(substr($packet, 3, 1));
    $server['bots']        = ord(substr($packet, 4, 1));
    $server['status']      = 1;
    $server['dedicated']   =     substr($packet, 5, 1);
    $server['os']          =     substr($packet, 6, 1);
    $server['password']    = ord(substr($packet, 7, 1));
    $server['vac']         = ord(substr($packet, 8, 1));

    return $server;
  }
print_r(query_source("127.0.0.1:27015"));
This should print all the info it receives.

Also I couldn't receive anything from the link you provided. Sad
Got the following:
Response:
I am using the script you posted I've only enabled it to work with GET requests. Though I've also used the original script without ANY modifications but it still doesn't work.

This just keeps getting weirder...

The thing is, I've tried so many different scripts, on different platforms, with different servers and even with
different programming languages but none. Not a single script has worked - though they all have in common that ping
and "rcon challenge" command works (A2S_SERVERQUERY_GETCHALLENGE also works, haven't tried A2S_PLAYER).
Perhaps your provider is blocking socket connections? Have you tried locally? Like on your own PC.
Reply
#11
(02-02-2011, 04:14 AM)realchamp Wrote:  Perhaps your provider is blocking socket connections? Have you tried locally? Like on your own PC.
Sadly I have tried on two different PCs both locally without success.
I just can't understand...

I've also used WireShark to analyze network packets and I've been
sending them just as shown (in WireShark)

Okay, update. I've installed the script you posted (didn't notice the print_r) and ATM it does work
on my local xampp installation with my local server (CS 1.6). I haven't tried with global servers yet.
Hmm.... Okay wtf. Seems to work on all servers ATM. I'll continue to investigate...
Reply
#12
(02-02-2011, 04:19 AM)knullapa Wrote:  
(02-02-2011, 04:14 AM)realchamp Wrote:  Perhaps your provider is blocking socket connections? Have you tried locally? Like on your own PC.
Sadly I have tried on two different PCs both locally without success.
I just can't understand...

I've also used WireShark to analyze network packets and I've been
sending them just as shown (in WireShark)

Okay, update. I've installed the script you posted (didn't notice the print_r) and ATM it does work
on my local xampp installation with my local server (CS 1.6). I haven't tried with global servers yet.
Hmm.... Okay wtf. Seems to work on all servers ATM. I'll continue to investigate...
I still think that sockets weren't allowed on your previously host. Try with the print_r on your host and see if you get some info out there. Smile
Reply
#13
One problem still persists. If you might remember I was using PHP just to learn how to communicate with a CS server.
I have a working script in PHP but the script, or rather code, I'm using for my c++ application does not.

It is the same as with my other PHP scripts. Only A2A_PING, "rcon challenge" and A2S_SERVERQUERY_GETCHALLENGE works.
Now I'm really wondering how come only these works and not A2S_INFO. This program is also running on my localhost - my computer, but without success.

If I figure out just why only these 3 works I might be able to fix the problem with A2S_INFO but I have no idea.
A last option would be to connect to a php script on my localhost to retrieve the server information but that would decrease the performance a lot in c++ terms.
Reply
#14
Hello.
I need to query a goldsrc server. ( HL1 )
It doesnt work with the scripts found here. Can someone help?
Reply
#15
(02-04-2011, 10:59 PM)semprom Wrote:  Hello.
I need to query a goldsrc server. ( HL1 )
It doesnt work with the scripts found here. Can someone help?

If you get any errors post them here please.

Else look at VALVe's Wiki for queries to HL1 engine and replace it with the stuff in the code above.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)