PCS Game Hosting
  Forum Index    Search    Usergroups    Edit your profile    Members    Arcade    Ranks

 Reputation    Medals    Staff    Statistics    Board Rules    Forum FAQ    Private MessagesLogin, Check Messages    Log in 

Search for at
Soldier Of Fortune 2 Advanced Search

Post new topicReply to topicprinter-friendly viewThank Post
   Soldier Of Fortune 2 Forum Index » Content management system » Query a server with PHP
 View previous topic :: View next topic  
Author Message

In Game: Teo

Joined: Sep 21, 2009
Last Visit: Jun 18, 2018
Age: 37
Posts: 1154
Location: Milan
Reputation: 4942
votes: 6
Medals: 6 (View more...)
Super Dedicated User (Amount: 1)

Status: Offline
PostPosted: Mon Sep 09, 2013 10:52 am
PostPost subject: No icon Query a server with PHP
Reply with quote

I will provide 2 php functions which you can use to query a server and then format the query results. This is only for the AS2_INFO query. It returns the server's hostname, map, game, and gamemode.

The query function: (note: It returns the data urlencode()-ed, so that it is easier to work with the strange characters returned by the query.)

/* SOURCE ENGINE QUERY FUNCTION, requires the server ip:port */
function source_query($ip)
$cut explode(":"$ip);
$HL2_address $cut[0];
$HL2_port $cut[1];

$HL2_command "\377\377\377\377TSource Engine Query\0";
$HL2_socket fsockopen("udp://".$HL2_address$HL2_port$errno$errstr,3);
fwrite($HL2_socket$HL2_command); $JunkHead fread($HL2_socket,4);
$CheckStatus socket_get_status($HL2_socket);

$CheckStatus["unread_bytes"] == 0)

$do 1;
$str fread($HL2_socket,1);
$HL2_stats.= $str;
$status socket_get_status($HL2_socket);
$status["unread_bytes"] == 0)
$do 0;

$x 0;
while (
$x <= strlen($HL2_stats))
$result.= substr($HL2_stats$x1);    
$result urlencode($result); // the output
return $result;

And now for the function that formats the query results: (note: it assumes the exact output of the above query function. The query info is returned into an array with the keys: hostname, map, game, gamemode )

/* FORMAT SOURCE ENGINE QUERY (assumes the query's results were urlencode()'ed!) */
function format_source_query($string)
$string str_replace('%07','',$string);
$string str_replace("%00","|||",$string);
$sinfo urldecode($string);
$sinfo explode('|||',$sinfo);
$info['hostname'] = $sinfo[0];
$info['map'] = $sinfo[1];
$info['game'] = $sinfo[2];
if (
$info['game'] == 'garrysmod') { $info['game'] = "Garry's Mod"; }
elseif (
$info['game'] == 'cstrike') { $info['game'] = "Counter-Strike: Source"; }
elseif (
$info['game'] == 'dod') { $info['game'] = "Day of Defeat: Source"; }
$info['gamemode'] = $sinfo[3];

Finally, an example of how to use all of this would be:

$query source_query($ip); // $ip MUST contain IP:PORT
$q format_source_query($query);

"Hostname: ".$q['hostname'];
"Map: ".$q['map'];
"Game: ".$q['game'];
"Gamemode: ".$q['gamemode']; 

resurces: (xfire) toasty2

https://www.proclanservers.com  Pissed Off  Rent your SoF2 Server   Die!   Rock
Back to top
View user's profile Send private message Send e-mail Visit poster's website Visit member's Facebook: http://www.facebook.com/ricordalo
Display posts from previous:
Post new topicReply to topic printer-friendly viewThank Post
Soldier Of Fortune 2 Forum Index »  Content management system
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts xS~mod 8.0 8 system 8376 Tue Aug 20, 2013 2:50 am
gedo View latest post
No new posts Mod tutorial 10 VenOm 6579 Sun Dec 30, 2012 9:01 pm
Teo View latest post
This topic is locked: you cannot edit posts or make replies. Graavie's mod 4 Graavie 3751 Thu Oct 18, 2012 8:22 pm
Teo View latest post
No new posts Psychooo MoD v.2 7 CroPsychooo 4852 Sun Dec 11, 2011 10:41 am
music View latest post
No new posts Deurkruk's mod 2 Deurkruk 2433 Tue Jul 19, 2011 1:47 pm
Deurkruk View latest post

Back to Top

SOF2.ORG Multiplayer Community © 2018 All times are UTC + 2 Hours [DST enabled]

Copyright ©