Код
<?php
set_time_limit ( 1800 );
require ('config.php');
function execute($sock, $str) {
socket_send($sock, $str.'|', strlen($str) + 1, NULL);
}
function lock2key($_LOCK) {
$lockLength = strlen ($_LOCK);
$h = ord($_LOCK{0}) ^ ord( $_LOCK{ $lockLength - 1} ) ^ ord( $_LOCK{ $lockLength - 2} ) ^ 5;
while ($h > 255) {$h = $h - 256;}
$h = (($h<<4) & 240) | (($h>>4) & 15);
$a = $h;
if ($a == '126' || // '~'
$a == '124' || // '|'
$a == '96' || // '`'
$a == '36' || // '$'
$a == '5' || // '^E'
$a == '0') // NUL
{
$LockToKey = "/%DCN";
if ($a < 100)
$LockToKey .="0";
if ($a < 10)
$LockToKey .="0";
$LockToKey .= $a;
$LockToKey .= "%/";
} else {
$LockToKey = chr ($a);
}
for ($j = 1; $j < strlen($_LOCK); $j++) {
$h = ord($_LOCK{$j}) ^ ord($_LOCK{$j-1});
while ($h > 255) {$h = $h - 256;}
$h = (($h<<4) & 240) | (($h>>4) & 15);
$a = $h;
if ($a == '126' || // '~'
$a == '124' || // '|'
$a == '96' || // '`'
$a == '36' || // '$'
$a == '5' || // '^E'
$a == '0') // NUL
{
$LockToKey .= "/%DCN";
if ($a < 100)
$LockToKey .="0";
if ($a < 10)
$LockToKey .="0";
$LockToKey .= $a;
$LockToKey .= "%/";
} else {
$LockToKey .= chr ($a);
}
}
return $LockToKey;
}
$mysql = mysql_connect($host, $user, $userpass) or die("<font color='red'>Ошибка соединения с MySQL!</font><br>");
mysql_select_db($bd, $mysql) or die("<font color='red'>Ошибка базы данных MySQL!</font><br>");
$result = @mysql_query("SELECT * FROM `".$dbtable."` ORDER BY `".$dbtable."`.`ID` ASC ");
while ($data = @mysql_fetch_assoc($result)) {
$useri = 0;
$share = 0;
if ($fp=@fsockopen($data['Adres'],$data['Port'],$ERROR_NO,$ERROR_STR,(float)4))
{
fclose($fp);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!socket_connect($socket, $data['Adres'], $data['Port'])) {
echo 'Error..';
return;
}
while ($buffer = socket_read($socket, 2048, PHP_BINARY_READ)) {
$linie = explode('|', $buffer);
for ($i = 0; $i < sizeof($linie); ++$i) {
$user = explode(' ', $linie[$i]);
switch($user[0]) {
case '$Lock':
execute($socket, '$Supports UserCommand NoGetINFO NoHello UserIP2 TTHSearch OpPlus Feed MCTo HubTopic BotList ClientID MiniSlots GetZBlock ADCGet TTHL TTHF ClientID CHUNK GetCID BotINFO');
execute($socket, '$Key '.lock2key($user[1]));
execute($socket, '$ValidateNick '.$nick);
break;
case '$Hello':
if ($user[1] == $nick) {
execute($socket, '$Version 1,0091');
execute($socket, '$GetNickList');
execute($socket, '$MyINFO $ALL '.$nick.' PingBot <FlylinkDC++ V:(r386),M:P,H:21/0/1,S:15>$ $100 $jkoff13@mail.ru$670969607454$');
execute($socket, '$BotINFO {HubListPinger} hublist pinger');
}
break;
case '$HubINFO':
$hubinfo = $linie[$i];
break 3;
break;
case '$MyINFO':
$myinfo = explode('$', $linie[$i]);
$share = $share + $myinfo[6];
$useri = $useri + 1;
break;
case '$OpList':
break;
}
}
}
socket_close($socket);
$hubinfo = str_replace( "HubINFO ", "", $hubinfo);
$hubinfo = explode('$', $hubinfo);
$hubinfo[3] = str_replace(".px.", " ", $hubinfo[3]);
$hubinfo[1] = str_replace("<", "<", $hubinfo[1]);
$hubinfo[1] = str_replace(">", ">", $hubinfo[1]);
$hubinfo[3] = str_replace("<", "<", $hubinfo[3]);
$hubinfo[3] = str_replace(">", ">", $hubinfo[3]);
mysql_query("UPDATE `".$dbtable."` SET Name = '".$hubinfo[1]."', Descr = '".$hubinfo[3]."',
Maxusers = '".$hubinfo[4]."', MinShare = '".$hubinfo[5]."', MinSlots = '".$hubinfo[6]."',
MaxHubs = '".$hubinfo[7]."', Soft = '".$hubinfo[8]."' WHERE id = ".$data['ID']."");
mysql_query("UPDATE `".$dbtable."` SET Users = ".$useri.", Status = 'Online', Share = ".floatval($share)." WHERE id = ".$data['ID']."");
if ($useri > $data['Userspeak'])
{
mysql_query("UPDATE `".$dbtable."` SET Userspeak = ".$useri." WHERE id = ".$data['ID']."");
}
if ($share > $data['Sharepeak'])
{
mysql_query("UPDATE `".$dbtable."` SET Sharepeak = ".floatval($share)." WHERE id = ".$data['ID']."");
}
}
else
{
mysql_query("UPDATE `".$dbtable."` SET Status = 'Offline' WHERE id = ".$data['ID']."");
mysql_query("UPDATE `".$dbtable."` SET Users = '0' WHERE id = ".$data['ID']."");
mysql_query("UPDATE `".$dbtable."` SET Share = '0' WHERE id = ".$data['ID']."");
}
echo $useri."<br>".floatval($share)."<br><br>";
}
mysql_close($mysql)
?>