Old 24-05-2007   #1 (permalink)
Member
 
Depodra's Avatar
 
Join Date: Jun 2006
Location: Toowoomba, QLD, AU.
Posts: 116
Rep Power: 3
Send a message via MSN to Depodra
Default Crude PHP Souce Engine Query

PHP Code:

function readString($string, &$i) {
    
$begin $i;
    
$strlen strlen($string);
    for (
$i; ($i $strlen) && ($string{$i} != chr(0)); $i++);
    
$result substr($string$begin$i-$begin);
    
$i++;
        
    return 
$result;
}

// Set IP/Port Variables
$ip $_GET['ip'];
$port $_GET['port'];
// Make, and check the connection
if (!$socket fsockopen('udp://' $ip$port)) {
    die(
'Could not connect to the socket.');
} else {
    
// If connection is successful, set the query string
    
$querystring "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00";
    
// Request String Hex
    // FF FF FF FF 54 53
    // 6F 75 72 63 65 20
    // 45 6E 67 69 6E 65
    // 20 51 75 65 72 79 00
}
$timeout 200;
$wait 0;
// Write to the socket (send packet to server)
fwrite($socket$querystring);
// Very simple timeout feature
while($wait $timeout) {
    
// Read the socket, data read will go to $string
    
$string fread($socket4096);
    
$wait += 10;

    if(!empty(
$string)) {
        
// Write data returned to $data array at integer incremental keys
        
$data[] = $string;
        
$ips[] = $ip;
        
$ports[] = $port;
        if(
strlen($string) < 4096)
            break;
        }
    }
}
// Close the connection to the server
fclose($socket);

$key 0;
foreach (
$data as $status) {
    
$thisip $ips[$key];
    
$thisport $ports[$key];
    
$key++;
    
$explod    explode("\x00"$status);
    if (
$explod[4] != 'Counter-Strike') {
        
$i 5;
        
$output['net_protocol']       = ord($status{$i++});
        
$output['hostname']           = readString($status$i);
        
$output['map']                = readString($status$i);
        
$output['game_dir']           = readString($status$i);
        
$output['game_type']          = readString($status$i);
        
$output['appid']              = ord($status{$i++}.$status{$i++});
        
$output['num_players']        = ord($status{$i++});
        
$output['max_players']        = ord($status{$i++});
        
$output['bot_players']        = ord($status{$i++});
        
$output['dedicated']          = $status{$i++};
        
$output['server_os']          = $status{$i++};
        
$output['needpass']           = ord($status{$i++});
        
$output['secure']             = ord($status{$i++});
    } else {
        
$output['hostname']           = $explod[1];
        
$output['map']                = $explod[2];
        
$output['game_dir']           = $explod[3];
        
$output['game_type']          = $explod[4];
        if ((
$explod[6]{2} == 'p') || ($explod[6]{2} == 'l') || $explod[6]{2} == 'd'))  {
            
$output['num_players']    = ord($explod[5]);
            
$output['max_players']    = ord($explod[6]{0});
            
$output['dedicated']      = $explod[6]{2};
            
$output['server_os']      = $explod[6]{3};
            
$output['needpass']       = ord($explod[6]{4});
            
$output['secure']         = ord($explod[6]{5});
        } else {
            
$output['num_players']    = ord($explod[5]);
            
$output['max_players']    = ord($explod[5]{1});
            
$output['dedicated']      = $explod[5]{3};
            
$output['server_os']      = $explod[5]{4};
            
$output['needpass']       = ord($explod[5]{5});
            
$output['secure']         = ord($explod[5]{6});
        }
    }

If anybody was in need of a source server query (works with goldsource), there's a crude one.

It's being implemented in the AusMasters Server Status check I put together.
__________________
"I still say a church steeple with a lightning rod on top shows a lack of confidence" ~ Doug McLeod

Last edited by Depodra; 24-05-2007 at 05:34 PM..
Depodra is offline   Reply With Quote
Old 24-05-2007   #2 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Nice work. That may come in handy one day.
chX is offline   Reply With Quote
Old 24-05-2007   #3 (permalink)
Honorary Member
 
doublethink's Avatar
 
Join Date: Jun 2006
Location: Sydney NSW
Posts: 1,784
Rep Power: 4
Default

Quote:
Originally Posted by Depodra View Post
If anybody was in need of a source server query (works with goldsource), there's a crude one.

It's being implemented in the AusMasters Server Status check I put together.
Working version:

http://scott.evolove.net/test/source...0.154.83:21500

Had to make a few syntax fixes to get it working tho.

That reminds me - I was tinkering with this ages back to get a full web rcon management system going but it never got finished:

http://scott.evolove.net/test/server..._info_full.php
doublethink is offline   Reply With Quote
Old 24-05-2007   #4 (permalink)
Member
 
Depodra's Avatar
 
Join Date: Jun 2006
Location: Toowoomba, QLD, AU.
Posts: 116
Rep Power: 3
Send a message via MSN to Depodra
Default

Quote:
Originally Posted by doublethink View Post
Working version:

http://scott.evolove.net/test/source...0.154.83:21500

Had to make a few syntax fixes to get it working tho.

That reminds me - I was tinkering with this ages back to get a full web rcon management system going but it never got finished:

http://scott.evolove.net/test/server..._info_full.php
Yeah, I just weakly pulled it out of the full source I have.
__________________
"I still say a church steeple with a lightning rod on top shows a lack of confidence" ~ Doug McLeod
Depodra is offline   Reply With Quote
Old 24-05-2007   #5 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by doublethink View Post
Working version:

http://scott.evolove.net/test/source...0.154.83:21500

Had to make a few syntax fixes to get it working tho.

That reminds me - I was tinkering with this ages back to get a full web rcon management system going but it never got finished:

http://scott.evolove.net/test/server..._info_full.php
The second one looked pretty good, minus a bit of the code which seems to not get parsed or something.

Try and finish it if you have time, would come in handy.
chX is offline   Reply With Quote
Old 24-05-2007   #6 (permalink)
Member
 
Depodra's Avatar
 
Join Date: Jun 2006
Location: Toowoomba, QLD, AU.
Posts: 116
Rep Power: 3
Send a message via MSN to Depodra
Default

The array printed in the middle is due to him using print_r($array);. Probably so he could debug the info and make it easier for him to read.
__________________
"I still say a church steeple with a lightning rod on top shows a lack of confidence" ~ Doug McLeod
Depodra is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +10. The time now is 10:02 AM.


Powered by vBulletin® Version 3.7.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0