SRCDS Steam group


Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[COLLECTION] PHP stuff for game servers!
#1
Hello I'd like to share all these with you Smile
!!
Announcement
All these scripts are free of charge and can be used in your own projects.
Convert SteamID to Steam Community ID:
PHP Code:
function steamid($steamid) {
  
$id explode(":"$steamid);
 
  
$id[2] = $id[2] * 2;
  
$id[2] = $id[2] + $id[1];
  
$ro "765611979";
  
$ra $id[2] + 60265728;
  
$final $ro $ra;

  
$url "http://steamcommunity.com/profiles/" $final;
  return 
$url;
}
echo 
steamid("STEAM_0:1:12345678"); // Your SteamID! 

.php   steamid.php (Size: 334 bytes / Downloads: 85)

Game queries for Counter-Strike: Source, Day of Defeat: Source, Team Fortress 2, Left 4 Dead, Left 4 Dead 2, GarrysMod, Half-Life 2(plus all sub mods) and most of HL1 engine games.
PHP Code:
// Thanks to Richard Perry.
  
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$errstr1);

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

    
stream_set_timeout($socket1);
    
stream_set_blocking($socketTRUE);
    
fwrite($socket"\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
    
$packet fread($socket4096);
    @
fclose($socket);

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

    
$header                substr($packet04);
    
$response_type         substr($packet41);
    
$network_version       ord(substr($packet51));

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

    
$packet_array          explode("\x00"substr($packet6), 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($packet02)));
    
$server['players']     = ord(substr($packet21));
    
$server['playersmax']  = ord(substr($packet31));
    
$server['bots']        = ord(substr($packet41));
    
$server['status']      = 1;
    
$server['dedicated']   =     substr($packet51); 
    
$server['os']          =     substr($packet61); 
    
$server['password']    = ord(substr($packet71)); 
    
$server['vac']         = ord(substr($packet81)); 

    return 
$server;
  }
$query query_source("127.0.0.1:27015");
echo 
$query['game']; 

.php   query.php (Size: 2.46 KB / Downloads: 239)


More to come,
- realchamp.
Reply
#2
Added some game queries Smile Have fun! Toungue
Reply
#3
Nice job! I'll have to use some of this stuff in the future!
Reply
#4
(12-24-2009, 11:54 AM)Beaverbeliever Wrote:  Nice job! I'll have to use some of this stuff in the future!

Thanks still more to come Smile
Reply
#5
Hey realchamp what would I need to change in that query script to be able to get all the player names in the server?
Reply
#6
Hey champ,

I was wondering im getting a t_echo error when i use the query script, could you help me out if possible?

Thanks,
Dan
Reply
#7
Post your code please Smile
Reply
#8
Code:
<html>
<body>
<?php

  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;
  }
?>
<?php
$query = query_source("127.0.0.1:27015")
echo $query['game'];
?>
</body>
</html>
Reply
#9
$query = query_source("127.0.0.1:27015") requires a ; at the end so it should look like

PHP Code:
<?php
$query 
query_source("127.0.0.1:27015");
echo 
$query['game'];
?>

It seems realchamp also forgot to put that in Toungue
Reply
#10
Edited Toungue
Reply
#11
holy shit thanks alot mate you rule i dident even notice that.
Reply
#12
how to install them!?!
Reply
#13
Install them? Just run the script on your webserver with PHP 5.0 <= installed.
Reply
#14
(05-21-2010, 12:28 AM)realchamp Wrote:  Install them? Just run the script on your webserver with PHP 5.0 <= installed.

This is the point, i have a web-hosting in php + Gamerserver in Win7 ultimate @ home,,

what to do?? i am confused!!!!
Reply
#15
(05-21-2010, 01:11 AM)DNG Wrote:  
(05-21-2010, 12:28 AM)realchamp Wrote:  Install them? Just run the script on your webserver with PHP 5.0 <= installed.

This is the point, i have a web-hosting in php + Gamerserver in Win7 ultimate @ home,,

what to do?? i am confused!!!!

Put the PHP file in your web folder(htdocs) and open it with your browser(http://localhost/query.php). Ofcause you'll need to make some changes to what it shall query Toungue
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)