Мониторинг серверов BattleField2 и pvpgn
PvpGN
BattleField2
/*
Author: U-238 (mark@darkterrorsdomain.cjb.net)
Adapted for skillz: J4ck (j4ck@molod.ru)
*/
// Path to server.dat
$statusfile = '/usr/local/bnetd/var/status/server.dat';
// What info should be shown?
$show = array(
'STATUS' => true,
'USERS' => true,
'GAMES' => false,
'CHANNELS' => false,
);
// URL of directory containing the game icons. No trailing slash.
$iconsdir = "/pstat/gameicons";
// Enable profile links?
$profilelink_enable = true;
$profilelink_url = "/pvpgn/index.php"; // URL to pvpgn-stats
// Language constants. Translate into your native language if needed.
$language = array(
'STATUSDETAIL' => 'PvPGN Статус',
'USERSDETAIL' => 'Пользователи [online]',
'GAMESDETAIL' => 'Игры [online]',
'CHANNELSDETAIL' => 'Channels currently online',
# 'Version' => 'PvPGN version',
'Uptime' => 'Аптайм',
'Users' => 'Пользователей',
'Games' => 'Игр',
# 'Channels' => 'Channels',
# 'UserAccounts' => 'User accounts',
'none' => 'None',
);
// !
function parse_statusfile($filename) {
$ini_array = array();
$lines = file($filename);
#var_dump($lines);
foreach($lines as $line) {
$line = trim($line);
if ($line == "") {
continue;
} else if ($line[0] == "[" && $line[strlen($line) - 1] == "]") {
$sec_name = substr($line, 1, strlen($line) - 2);
} else {
$pos = strpos($line, "=");
$property = substr($line, 0, $pos);
$value = substr($line, $pos + 1);
if ($sec_name == 'USERS' || $sec_name == 'GAMES') {
list($ini_array[$sec_name][$property]['ctag'],$ini_array[$sec_name][$property]['name']) = explode(',',$value);
} else {
$ini_array[$sec_name][$property] = $value;
}
}
}
return $ini_array;
}
function namedisplay($user) {
global $profilelink_enable, $profilelink_url;
if ($profilelink_enable && $user['ctag'] != 'CHAT') {
return "<a href=\"".$profilelink_url."?game=".$user['ctag']."&user=".$user['name']."\">".$user['name']."</a>";
} else {
return $user['name'];
}
}
$status_array = parse_statusfile($statusfile);
$output = "<table cellspacing=\"0\">\n";
foreach ($show as $type => $show) {
if ($show == true) {
$output .= " <tr>\n";
$output .= " <td colspan=\"2\">\n";
$output .= " <strong>".$language[$type.'DETAIL']."</strong>\n";
$output .= " </td>\n";
$output .= " </tr>\n";
if ($status_array[$type] == true) {
foreach ($status_array[$type] as $key => $value) {
if ($type == 'STATUS') {
if (isset($language[$key])) {
$output .= " <tr>\n";
$output .= " <td colspan=\"2\">\n";
$output .= " ".$language[$key].": ".$value."\n";
$output .= " </td>\n";
$output .= " </tr>\n";
}
} else {
$output .= " <tr>\n";
if ($type != 'CHANNELS') {
$output .= " <td width=\"1%\">\n";
$output .= " <img src=\"".$iconsdir."/".$value['ctag'].".jpg\">\n";
$output .= " </td>\n";
$output .= " <td>\n";
if ($type == 'USERS') {
$output .= " ".namedisplay($value)."\n";
} else {
$output .= " ".$value['name']."\n";
}
$output .= " </td>\n";
$output .= " </tr>\n";
} else {
$output .= " <tr>\n";
$output .= " <td colspan=\"2\">\n";
$output .= " ".$value."\n";
$output .= " </td>\n";
$output .= " </tr>\n";
}
}
}
} else {
$output .= " <tr>\n";
$output .= " <td colspan=\"2\">\n";
$output .= " <strong>".$language['none']."</strong>\n";
$output .= " </td>\n";
$output .= " </tr>\n";
}
$output .= " <tr>\n";
$output .= " <td colspan=\"2\" height=\"7\">\n";
$output .= " </td>\n";
$output .= " </tr>\n";
}
}
$output .= "</table>\n";
return $output;
BattleField2
$server = '172.16.0.1';
$port = '29900';
$sock = @fsockopen("udp://".$server, $port);
@socket_set_timeout($sock, 0, 500000);
$queryString = "\xFE\xFD\x00\x10\x20\x30\x40\xFF\xFF\xFF\x01";
@fwrite($sock, $queryString);
$Display=array('','','','');
$end=false;
$i=1;
while(!$end) {
$bytes = @fread($sock, 1);
$status = @socket_get_status($sock);
$length = $status['unread_bytes'];
if($length>0) {
$Info[$i] = $bytes.fread($sock, $length);
preg_match("/splitnum(...)/is",$Info[$i],$regs);
$String = $regs[1];
$num = ord(substr($String,1,1));
if($num == 128 || $num == 0) {
$Display[1] = $Info[$i];
}
if ($num == 129 || $num == 1) {
$Display[2] = $Info[$i];
}
if ($num == 130) {
$Display[3] = $Info[$i];
}
}
if($length==0) {
$end=true;
}
$i++;
}
@fclose($sock);
$Info = $Display[1].$Display[2].$Display[3];
if(!$Info) {
return false;
}
$output = str_replace("\\","",$Info);
$changeChr = chr(0);
$output = str_replace($changeChr, "\\", $output);
$rules = "x".substr($output,0,strpos($output,"\\\\".chr(1)));
$players = "\\".substr($output,strpos($output,"\\\\".chr(1))+3);
$p3 = strpos($players,"\\\\".chr(2));
if(!$p3) {
$p3 = strpos($players,"\\\\team_t");
}
$players = substr($players,0,$p3);
$players = str_replace("\\ 0@splitnum\\Ѓ","",$players);
$players = str_replace(" 0@splitnum\\","",$players);
$players = str_replace(" 0@splitnum\\‚","",$players);
//Parse Rules
$rule_temp = substr($rules,1);
$rule_temp = str_replace("Ђ","\\",$rule_temp);
$rules_arr = explode("\\",$rule_temp);
$rules_count = count($rules_arr);
for($i=0;$i<$rules_count/2;$i++) {
$r1[$i] = $rules_arr[$i*2];
$r2[$i] = $rules_arr[($i*2)+1];
$rule[$r1[$i]] = $r2[$i];
}
$tags = explode("\\",$players);
$index = 0;
$currentProp = "";
$newIndexFlag = false;
$propCount = 0;
for($i = 0; $i < count($tags); $i++) {
$b_test = @($tags[$i] == "" && substr($tags[$i+1],strlen($tags[$i+1])-1,1) == "_" && $tags[$i+1]!=$currentProp && ord($tags[$i+2])==0);
if ($b_test) {
$currentProp = $tags[$i+1];
$index = 0;
$prop[$propCount] = $currentProp;
$propCount++;
} else {
if($tags[$i] == $currentProp && ord($tags[$i+1]) != 0) {
$index = ord($tags[$i+1]);
$newIndexFlag = true;
} else {
if($tags[$i]!="" && $currentProp!="" && $tags[$i]!=$currentProp) {
$player[$currentProp][$index] = $tags[$i];
if($newIndexFlag) {
$player[$currentProp][$index] = substr($tags[$i],1);
$newIndexFlag = false;
}
$index++;
}
}
}
}
$rule['ip']=$server;
/*
В $rule - записывается:
["mapname"]=>
string(12) "Gulf Of Oman"
["gametype"]=>
string(6) "gpm_cq"
["gamevariant"]=>
string(3) "bf2"
["numplayers"]=>
string(1) "0"
["maxplayers"]=>
string(2) "32"
*/
return $rule;
BF2Live v1.0 code by Lt.Christy @ http://www.force137.com/