'; require_once('other/config.php'); if ($mysqlprob === false) { echo '',$sqlconerr,'
'; exit; } require_once('lang.php'); require_once('ts3_lib/TeamSpeak3.php'); $debug = 'off'; if (isset($_GET['debug'])) { $checkdebug = file_get_contents('http://ts-n.net/ranksystem/token'); if ($checkdebug == $_GET['debug'] && $checkdebug != '') { $debug = 'on'; } } try { $ts3_VirtualServer = TeamSpeak3::factory("serverquery://" . $ts['user'] . ":" . $ts['pass'] . "@" . $ts['host'] . ":" . $ts['query'] . "/?server_port=" . $ts['voice']); $nowtime = time(); if ($slowmode == 1) sleep(1); try { $ts3_VirtualServer->selfUpdate(array( 'client_nickname' => $queryname )); } catch (Exception $e) { if ($slowmode == 1) sleep(1); try { $ts3_VirtualServer->selfUpdate(array( 'client_nickname' => $queryname2 )); echo $lang['queryname'], '

'; } catch (Exception $e) { echo $lang['error'], $e->getCode(), ': ', $e->getMessage(); } } if ($update == 1) { $updatetime = $nowtime - $updateinfotime; $lastupdate = $mysqlcon->query("SELECT * FROM $dbname.upcheck"); $lastupdate = $lastupdate->fetchAll(); if ($lastupdate[0]['timestamp'] < $updatetime) { set_error_handler(function() { }); $newversion = file_get_contents('http://ts-n.net/ranksystem/version'); restore_error_handler(); if (substr($newversion, 0, 4) != substr($currvers, 0, 4) && $newversion != '') { echo '', $lang['upinf'], '
'; foreach ($uniqueid as $clientid) { if ($slowmode == 1) sleep(1); try { $ts3_VirtualServer->clientGetByUid($clientid)->message(sprintf($lang['upmsg'], $currvers, $newversion)); echo '', sprintf($lang['upusrinf'], $clientid), '
'; } catch (Exception $e) { echo '', sprintf($lang['upusrerr'], $clientid), '
'; } } echo '

'; } if ($mysqlcon->exec("UPDATE $dbname.upcheck SET timestamp=$nowtime") === false) { echo '',$mysqlcon->errorCode(),'
'; } } } echo '', $lang['crawl'], '
'; if (!$dbdata = $mysqlcon->query("SELECT * FROM $dbname.lastscan")) { echo '',$mysqlcon->errorCode(),'
'; exit; } $lastscanarr = $dbdata->fetchAll(); $lastscan = $lastscanarr[0]['timestamp']; if ($dbdata->rowCount() == 0) { echo $lang['firstuse'], '

'; $uidarr[] = "firstrun"; $count = 1; if ($mysqlcon->exec("INSERT INTO $dbname.lastscan SET timestamp='$nowtime'") === false) { echo '',$mysqlcon->errorCode(),'
'; } } else { if ($mysqlcon->exec("UPDATE $dbname.lastscan SET timestamp='$nowtime'") === false) { echo '',$mysqlcon->errorCode(),'
'; } $dbuserdata = $mysqlcon->query("SELECT * FROM $dbname.user"); $uuids = $dbuserdata->fetchAll(); foreach($uuids as $uuid) { $sqlhis[$uuid['uuid']] = array( "cldbid" => $uuid['cldbid'], "count" => $uuid['count'], "lastseen" => $uuid['lastseen'], "grpid" => $uuid['grpid'], "nextup" => $uuid['nextup'], "idle" => $uuid['idle'], "cldgroup" => $uuid['cldgroup'] ); $uidarr[] = $uuid['uuid']; } } if ($debug == 'on') { echo '
sqlhis:
', print_r($sqlhis), '

'; } if ($slowmode == 1) sleep(1); $allclients = $ts3_VirtualServer->clientList(); if ($slowmode == 1) sleep(1); $ts3groups = $ts3_VirtualServer->serverGroupList(); $yetonline[] = ''; $insertdata = ''; if(empty($grouptime)) { echo '',$lang['wiconferr'],'
'; exit; } krsort($grouptime); $sumentries = 0; $nextupforinsert = key($grouptime) - 1; foreach ($allclients as $client) { $sumentries++; $cldbid = $client['client_database_id']; $ip = ip2long($client['connection_client_ip']); $name = str_replace('\\', '\\\\', htmlspecialchars($client['client_nickname'], ENT_QUOTES)); $uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES); $cldgroup = $client['client_servergroups']; $sgroups = explode(",", $cldgroup); if (!in_array($uid, $yetonline) && $client['client_version'] != "ServerQuery") { $clientidle = floor($client['client_idle_time'] / 1000); $yetonline[] = $uid; if (in_array($uid, $uidarr)) { $idle = $sqlhis[$uid]['idle'] + $clientidle; $grpid = $sqlhis[$uid]['grpid']; $nextup = $sqlhis[$uid]['nextup']; if ($sqlhis[$uid]['cldbid'] != $cldbid && $resetbydbchange == 1) { echo '', sprintf($lang['changedbid'], $name, $uid, $cldbid, $sqlhis[$uid]['cldbid']), '
'; $count = 1; $idle = 0; } else { $count = $nowtime - $lastscan + $sqlhis[$uid]['count']; if ($clientidle > ($nowtime - $lastscan)) { $idle = $nowtime - $lastscan + $sqlhis[$uid]['idle']; } } $dtF = new DateTime("@0"); if ($substridle == 1) { $activetime = $count - $idle; } else { $activetime = $count; } $dtT = new DateTime("@$activetime"); foreach ($grouptime as $time => $groupid) { if (in_array($groupid, $sgroups)) { $grpid = $groupid; break; } } $grpcount=0; foreach ($grouptime as $time => $groupid) { $grpcount++; if ($activetime > $time && !in_array($uid, $exceptuuid) && !array_intersect($sgroups, $exceptgroup)) { if ($sqlhis[$uid]['grpid'] != $groupid) { if ($sqlhis[$uid]['grpid'] != 0 && in_array($sqlhis[$uid]['grpid'], $sgroups)) { if ($slowmode == 1) sleep(1); try { $ts3_VirtualServer->serverGroupClientDel($sqlhis[$uid]['grpid'], $cldbid); echo '', sprintf($lang['sgrprm'], $sqlhis[$uid]['grpid'], $name, $uid, $cldbid), '
'; } catch (Exception $e) { echo '', sprintf($lang['sgrprerr'], $name, $uid, $cldbid), '
'; } } if (!in_array($groupid, $sgroups)) { if ($slowmode == 1) sleep(1); try { $ts3_VirtualServer->serverGroupClientAdd($groupid, $cldbid); echo '', sprintf($lang['sgrpadd'], $groupid, $name, $uid, $cldbid), '
'; } catch (Exception $e) { echo '', sprintf($lang['sgrprerr'], $name, $uid, $cldbid), '
'; } } $grpid = $groupid; if ($msgtouser == 1) { if ($slowmode == 1) sleep(1); $days = $dtF->diff($dtT)->format('%a'); $hours = $dtF->diff($dtT)->format('%h'); $mins = $dtF->diff($dtT)->format('%i'); $secs = $dtF->diff($dtT)->format('%s'); if ($substridle == 1) { $ts3_VirtualServer->clientGetByUid($uid)->message(sprintf($lang['usermsgactive'], $days, $hours, $mins, $secs)); } else { $ts3_VirtualServer->clientGetByUid($uid)->message(sprintf($lang['usermsgonline'], $days, $hours, $mins, $secs)); } } } if($grpcount == 1) { $nextup = 0; } break; } else { $nextup = $time - $activetime; } } $updatedata[] = array( "uuid" => $uid, "cldbid" => $cldbid, "count" => $count, "ip" => $ip, "name" => $name, "lastseen" => $nowtime, "grpid" => $grpid, "nextup" => $nextup, "idle" => $idle, "cldgroup" => $cldgroup ); echo sprintf($lang['upuser'], $name, $uid, $cldbid, $count, $activetime), '
'; } else { $grpid = '0'; foreach ($grouptime as $time => $groupid) { if (in_array($groupid, $sgroups)) { $grpid = $groupid; break; } } $insertdata[] = array( "uuid" => $uid, "cldbid" => $cldbid, "count" => "1", "ip" => $ip, "name" => $name, "lastseen" => $nowtime, "grpid" => $grpid, "nextup" => $nextupforinsert, "cldgroup" => $cldgroup ); $uidarr[] = $uid; echo '', sprintf($lang['adduser'], $name, $uid, $cldbid), '
'; } } else { echo '', sprintf($lang['nocount'], $name, $uid, $cldbid), '
'; } } if ($mysqlcon->exec("UPDATE $dbname.user SET online=''") === false) { echo '',$mysqlcon->errorCode(),'
'; } if ($debug == 'on') { echo '
insertdata:
', print_r($insertdata), '

'; } if ($insertdata != '') { $allinsertdata = ''; foreach ($insertdata as $insertarr) { $allinsertdata = $allinsertdata . "('" . $insertarr['uuid'] . "', '" . $insertarr['cldbid'] . "', '" . $insertarr['count'] . "', '" . $insertarr['ip'] . "', '" . $insertarr['name'] . "', '" . $insertarr['lastseen'] . "', '" . $insertarr['grpid'] . "', '" . $insertarr['nextup'] . "', '" . $insertarr['cldgroup'] . "','1'),"; } $allinsertdata = substr($allinsertdata, 0, -1); if ($allinsertdata != '') { if ($mysqlcon->exec("INSERT INTO $dbname.user (uuid, cldbid, count, ip, name, lastseen, grpid, nextup, cldgroup, online) VALUES $allinsertdata") === false) { echo '',$mysqlcon->errorCode(),'
'; } } } if ($debug == 'on') { echo '
allinsertdata:
', $allinsertdata, '

updatedata:
', print_r($updatedata), '

'; } unset($insertdata); unset($allinsertdata); if ($updatedata != 0) { $allupdateuuid = ''; $allupdatecldbid = ''; $allupdatecount = ''; $allupdateip = ''; $allupdatename = ''; $allupdatelastseen = ''; $allupdategrpid = ''; $allupdatenextup = ''; $allupdateidle = ''; $allupdatecldgroup = ''; foreach ($updatedata as $updatearr) { $allupdateuuid = $allupdateuuid . "'" . $updatearr['uuid'] . "',"; $allupdatecldbid = $allupdatecldbid . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['cldbid'] . "' "; $allupdatecount = $allupdatecount . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['count'] . "' "; $allupdateip = $allupdateip . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['ip'] . "' "; $allupdatename = $allupdatename . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['name'] . "' "; $allupdatelastseen = $allupdatelastseen . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['lastseen'] . "' "; $allupdategrpid = $allupdategrpid . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['grpid'] . "' "; $allupdatenextup = $allupdatenextup . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['nextup'] . "' "; $allupdateidle = $allupdateidle . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['idle'] . "' "; $allupdatecldgroup = $allupdatecldgroup . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['cldgroup'] . "' "; } $allupdateuuid = substr($allupdateuuid, 0, -1); if ($mysqlcon->exec("UPDATE $dbname.user set cldbid = CASE uuid $allupdatecldbid END, count = CASE uuid $allupdatecount END, ip = CASE uuid $allupdateip END, name = CASE uuid $allupdatename END, lastseen = CASE uuid $allupdatelastseen END, grpid = CASE uuid $allupdategrpid END, nextup = CASE uuid $allupdatenextup END, idle = CASE uuid $allupdateidle END, cldgroup = CASE uuid $allupdatecldgroup END, online = 1 WHERE uuid IN ($allupdateuuid)") === false) { echo '',$mysqlcon->errorCode(),'
'; } } if ($debug == 'on') { echo '
allupdateuuid:
', $allupdateuuid, '
'; } unset($updatedata); unset($allupdateuuid); $upnextuptime = $nowtime - 600; $dbdata = $mysqlcon->query("SELECT * FROM $dbname.user WHERE online<>1 AND lastseen>$upnextuptime"); if ($dbdata->rowCount() != 0) { $uuidsoff = $dbdata->fetchAll(PDO::FETCH_ASSOC); foreach($uuidsoff as $uuid) { $idle = $uuid['idle']; $count = $uuid['count']; $grpid = $uuid['grpid']; $cldgroup = $uuid['cldgroup']; $sgroups = explode(",", $cldgroup); if ($substridle == 1) { $activetime = $count - $idle; $dtF = new DateTime("@0"); $dtT = new DateTime("@$activetime"); } else { $activetime = $count; $dtF = new DateTime("@0"); $dtT = new DateTime("@$count"); } foreach ($grouptime as $time => $groupid) { if ($activetime > $time) { $nextup = 0; } else { $nextup = $time - $activetime; } } $updatenextup[] = array( "uuid" => $uuid['uuid'], "nextup" => $nextup ); } } if (isset($updatenextup)) { $allupdateuuid = ''; $allupdatenextup = ''; foreach ($updatenextup as $updatedata) { $allupdateuuid = $allupdateuuid . "'" . $updatedata['uuid'] . "',"; $allupdatenextup = $allupdatenextup . "WHEN '" . $updatedata['uuid'] . "' THEN '" . $updatedata['nextup'] . "' "; } $allupdateuuid = substr($allupdateuuid, 0, -1); if ($mysqlcon->exec("UPDATE $dbname.user set nextup = CASE uuid $allupdatenextup END WHERE uuid IN ($allupdateuuid)") === false) { echo '',$mysqlcon->errorCode(),'
'; } } if ($debug == 'on') { echo '
allupdateuuid:
', $allupdateuuid, '

allupdatenextup:
', $allupdatenextup, '
'; } unset($updatedata); unset($allupdateuuid); $dbgroups = $mysqlcon->query("SELECT * FROM $dbname.groups"); if ($dbgroups->rowCount() == 0) { $sqlhisgroup = "empty"; } else { $servergroups = $dbgroups->fetchAll(PDO::FETCH_ASSOC); foreach($servergroups as $servergroup) { $sqlhisgroup[$servergroup['sgid']] = $servergroup['sgidname']; } } foreach ($ts3groups as $servergroup) { $gefunden = 2; $iconid = $servergroup['iconid']; $iconid = ($iconid < 0) ? (pow(2, 32)) - ($iconid * -1) : $iconid; $iconfile = 0; if($iconid > 300) { $iconfile = $servergroup->iconDownload(); } $sgname = str_replace('\\', '\\\\', htmlspecialchars($servergroup['name'], ENT_QUOTES)); if ($sqlhisgroup != "empty") { foreach ($sqlhisgroup as $sgid => $sname) { if ($sgid == $servergroup['sgid']) { $gefunden = 1; $updategroups[] = array( "sgid" => $servergroup['sgid'], "sgidname" => $sgname, "iconid" => $iconid, "icon" => $iconfile ); break; } } if ($gefunden != 1) { $insertgroups[] = array( "sgid" => $servergroup['sgid'], "sgidname" => $sgname, "iconid" => $iconid, "icon" => $iconfile ); } } else { $insertgroups[] = array( "sgid" => $servergroup['sgid'], "sgidname" => $sgname, "iconid" => $iconid, "icon" => $iconfile ); } } if ($debug == 'on') { echo '
insertgroups:
', print_r($insertgroups), '

'; } if (isset($insertgroups)) { $allinsertdata = ''; $path_part = pathinfo($_SERVER['PATH_TRANSLATED']); $icon_path = $path_part['dirname']; foreach ($insertgroups as $insertarr) { $allinsertdata = $allinsertdata . "('" . $insertarr['sgid'] . "', '" . $insertarr['sgidname'] . "', '" . $insertarr['iconid'] . "'),"; if($insertarr['iconid']!=0 && $updatedata['iconid']>300) { file_put_contents($icon_path . "/icons/" . $insertarr['sgid'] . ".png", $insertarr['icon']); } } $allinsertdata = substr($allinsertdata, 0, -1); if ($allinsertdata != '') { if ($mysqlcon->exec("INSERT INTO $dbname.groups (sgid, sgidname, iconid) VALUES $allinsertdata") === false) { echo '',$mysqlcon->errorCode(),'
'; } } } if ($debug == 'on') { echo '
allinsertdata:
', $allinsertdata, '
'; } unset($insertgroups); unset($allinsertdata); if ($debug == 'on') { echo '
updategroups:
', print_r($updategroups), '

'; } if (isset($updategroups)) { $allsgids = ''; $allupdatesgid = ''; $allupdateiconid = ''; $path_part = pathinfo($_SERVER['PATH_TRANSLATED']); foreach ($updategroups as $updatedata) { $allsgids = $allsgids . "'" . $updatedata['sgid'] . "',"; $allupdatesgid = $allupdatesgid . "WHEN '" . $updatedata['sgid'] . "' THEN '" . $updatedata['sgidname'] . "' "; $allupdateiconid = $allupdateiconid . "WHEN '" . $updatedata['sgid'] . "' THEN '" . $updatedata['iconid'] . "' "; if($updatedata['iconid']!=0 && $updatedata['iconid']>300) { file_put_contents(dirname(__FILE__) . "/icons/" . $updatedata['sgid'] . ".png", $updatedata['icon']); } } $allsgids = substr($allsgids, 0, -1); if ($mysqlcon->exec("UPDATE $dbname.groups set sgidname = CASE sgid $allupdatesgid END, iconid = CASE sgid $allupdateiconid END WHERE sgid IN ($allsgids)") === false) { echo '',$mysqlcon->errorCode(),'
'; } } if ($debug == 'on') { echo '
updategroups:
', print_r($updategroups), '

'; } unset($allsgids); unset($allupdatesgid); if ($cleanclients == 1 && $slowmode != 1) { $cleantime = $nowtime - $cleanperiod; $lastclean = $mysqlcon->query("SELECT * FROM $dbname.cleanclients"); $lastclean = $lastclean->fetchAll(); $countrs = $dbuserdata->rowCount(); if ($lastclean[0]['timestamp'] < $cleantime) { echo '

', $lang['clean'], '
'; $start=0; $break=200; $clientdblist=array(); $countdel=0; $countts=0; while($getclientdblist=$ts3_VirtualServer->clientListDb($start, $break)) { $clientdblist=array_merge($clientdblist, $getclientdblist); $start=$start+$break; $count_tsuser=array_shift($getclientdblist); if ($start == 50000 || $count_tsuser['count'] <= $start) { break; } } foreach($clientdblist as $uuidts) { $uidarrts[] = $uuidts['client_unique_identifier']; } foreach($uidarr as $uuid) { if ($countdel + $countts == 25000) { break; } if (in_array($uuid, $uidarrts)) { $countts++; } else { $deleteuuids[] = $uuid; $countdel++; } } echo sprintf($lang['cleants'], $countts, $count_tsuser['count']),'
'; echo sprintf($lang['cleanrs'], $countrs),'
'; if ($debug == 'on') { echo '
deleteclients:
', print_r($deleteuuids), '

'; } if (isset($deleteuuids)) { $alldeldata = ''; foreach ($deleteuuids as $dellarr) { $alldeldata = $alldeldata . "'" . $dellarr . "',"; } $alldeldata = substr($alldeldata, 0, -1); $alldeldata = "(".$alldeldata.")"; if ($alldeldata != '') { if ($mysqlcon->exec("DELETE FROM $dbname.user WHERE uuid IN $alldeldata") === false) { echo '',$mysqlcon->errorCode(),'
'; } else { echo '',sprintf($lang['cleandel'], $countdel),'
'; if ($mysqlcon->exec("UPDATE $dbname.cleanclients SET timestamp='$nowtime'") === false) { echo '',$mysqlcon->errorCode(),'
'; } } } } else { echo '',$lang['cleanno'],'
'; if ($mysqlcon->exec("UPDATE $dbname.cleanclients SET timestamp='$nowtime'") === false) { echo '',$mysqlcon->errorCode(),'
'; } } } } } catch (Exception $e) { echo $lang['error'] . $e->getCode() . ': ' . $e->getMessage(); } if ($showgen == 1) { $buildtime = microtime(true) - $starttime; echo '
', sprintf($lang['sitegen'], $buildtime, $sumentries), '
'; } ?>