release 1.3.13
This commit is contained in:
@@ -5,15 +5,18 @@ function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,&$db_cache) {
|
||||
$sqlexec = '';
|
||||
|
||||
$job_begin = $db_cache['job_check']['calc_user_limit']['timestamp'];
|
||||
$job_end = ceil(count($db_cache['all_user']) / 10) * 10;
|
||||
if ($job_begin >= $job_end) {
|
||||
|
||||
$limit_calc = ceil(count($db_cache['all_user']) / 600);
|
||||
if($limit_calc < 5) $limit_calc = 5;
|
||||
|
||||
if ($job_begin >= (ceil(count($db_cache['all_user']) / $limit_calc) * $limit_calc)) {
|
||||
$job_begin = 0;
|
||||
$job_end = 10;
|
||||
$job_end = $limit_calc;
|
||||
} else {
|
||||
$job_end = $job_begin + 10;
|
||||
$job_end = $job_begin + $limit_calc;
|
||||
}
|
||||
|
||||
$sqlhis = array_slice($db_cache['all_user'],$job_begin ,10);
|
||||
$sqlhis = array_slice($db_cache['all_user'],$job_begin ,$limit_calc);
|
||||
|
||||
$cldbids = '';
|
||||
foreach ($sqlhis as $uuid => $userstats) {
|
||||
@@ -23,8 +26,8 @@ function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,&$db_cache) {
|
||||
|
||||
$weekago = $db_cache['job_check']['last_snapshot_id']['timestamp'] - 28;
|
||||
$monthago = $db_cache['job_check']['last_snapshot_id']['timestamp'] - 120;
|
||||
if ($weekago < 1) $weekago = $weekago + 121;
|
||||
if ($monthago < 1) $monthago = $monthago + 121;
|
||||
if ($weekago < 1) $weekago += 121;
|
||||
if ($monthago < 1) $monthago += 121;
|
||||
|
||||
if(isset($sqlhis) && $sqlhis != NULL) {
|
||||
enter_logfile($cfg,6,"Update User Stats between ".$job_begin." and ".$job_end.":");
|
||||
@@ -35,79 +38,90 @@ function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,&$db_cache) {
|
||||
$allupdateuuid = '';
|
||||
|
||||
foreach ($sqlhis as $uuid => $userstats) {
|
||||
check_shutdown($cfg); usleep($cfg['teamspeak_query_command_delay']);
|
||||
if($userstats['lastseen'] > ($nowtime - 2678400)) {
|
||||
check_shutdown($cfg); usleep($cfg['teamspeak_query_command_delay']);
|
||||
|
||||
$keybase = array_search($db_cache['job_check']['last_snapshot_id']['timestamp'], array_column($userdata[$userstats['cldbid']], 'id'));
|
||||
$keyweek = array_search($weekago, array_column($userdata[$userstats['cldbid']], 'id'));
|
||||
$keymonth = array_search($monthago, array_column($userdata[$userstats['cldbid']], 'id'));
|
||||
if(isset($userdata[$userstats['cldbid']]) && $userdata[$userstats['cldbid']] != NULL) {
|
||||
$keybase = array_search($db_cache['job_check']['last_snapshot_id']['timestamp'], array_column($userdata[$userstats['cldbid']], 'id'));
|
||||
$keyweek = array_search($weekago, array_column($userdata[$userstats['cldbid']], 'id'));
|
||||
$keymonth = array_search($monthago, array_column($userdata[$userstats['cldbid']], 'id'));
|
||||
|
||||
if(isset($userdata[$userstats['cldbid']]) && isset($userdata[$userstats['cldbid']][$keyweek]) && $userdata[$userstats['cldbid']][$keyweek]['id'] == $weekago) {
|
||||
$count_week = $userdata[$userstats['cldbid']][$keybase]['count'] - $userdata[$userstats['cldbid']][$keyweek]['count'];
|
||||
$idle_week = $userdata[$userstats['cldbid']][$keybase]['idle'] - $userdata[$userstats['cldbid']][$keyweek]['idle'];
|
||||
$active_week = $count_week - $idle_week;
|
||||
} else {
|
||||
$count_week = 0;
|
||||
$idle_week = 0;
|
||||
$active_week = 0;
|
||||
}
|
||||
if(isset($userdata[$userstats['cldbid']]) && isset($userdata[$userstats['cldbid']][$keymonth]) && $userdata[$userstats['cldbid']][$keymonth]['id'] == $monthago) {
|
||||
$count_month = $userdata[$userstats['cldbid']][$keybase]['count'] - $userdata[$userstats['cldbid']][$keymonth]['count'];
|
||||
$idle_month = $userdata[$userstats['cldbid']][$keybase]['idle'] - $userdata[$userstats['cldbid']][$keymonth]['idle'];
|
||||
$active_month = $count_month - $idle_month;
|
||||
} else {
|
||||
$count_month = 0;
|
||||
$idle_month = 0;
|
||||
$active_month = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
$clientinfo = $ts3->clientInfoDb($userstats['cldbid']);
|
||||
$clientdesc = $mysqlcon->quote($clientinfo['client_description'], ENT_QUOTES);
|
||||
if($clientinfo['client_totalconnections'] > 16777215) $clientinfo['client_totalconnections'] = 16777215;
|
||||
} catch (Exception $e) {
|
||||
if($e->getCode() == 512 || $e->getCode() == 1281) {
|
||||
enter_logfile($cfg,6,"Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") known by Ranksystem is missing in TS database, perhaps its already deleted or cldbid changed. Try to search for client by uuid.");
|
||||
try {
|
||||
$getcldbid = $ts3->clientFindDb($uuid, TRUE);
|
||||
if($getcldbid[0] != $userstats['cldbid']) {
|
||||
enter_logfile($cfg,4," Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") known by the Ranksystem changed its cldbid. New cldbid is ".$getcldbid[0].".");
|
||||
if($cfg['rankup_client_database_id_change_switch'] == 1) {
|
||||
$db_cache['all_user'][$uuid]['cldbid'] = $getcldbid[0];
|
||||
$sqlexec .= "UPDATE `$dbname`.`user` SET `count`=0,`idle`=0 WHERE `uuid`='$uuid';\nUPDATE `$dbname`.`stats_user` SET `count_week`=0,`count_month`=0,`idle_week`=0,`idle_month`=0,`active_week`=0,`active_month`=0 WHERE `uuid`='$uuid';\nDELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$userstats['cldbid']}';\n";
|
||||
enter_logfile($cfg,4," ".sprintf($lang['changedbid'], $userstats['name'], $uuid, $userstats['cldbid'], $getcldbid[0]));
|
||||
} else {
|
||||
$sqlexec .= "UPDATE `$dbname`.`user` SET `cldbid`={$getcldbid[0]} WHERE `uuid`='$uuid';\n";
|
||||
// select current user_snapshot entries and insert this with the new database-ID
|
||||
foreach($userdata[$userstats['cldbid']] as $id => $data) {
|
||||
$allinsert .= "($id,'{$getcldbid[0]}',{$data['count']},{$data['idle']}),";
|
||||
}
|
||||
if ($allinsert != '') {
|
||||
$allinsert = substr($allinsert, 0, -1);
|
||||
$sqlexec .= "INSERT INTO `$dbname`.`user_snapshot` (`id`,`cldbid`,`count`,`idle`) VALUES $allinsert ON DUPLICATE KEY UPDATE `count`=VALUES(`count`),`idle`=VALUES(`idle`);\nDELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$userstats['cldbid']}';\n";
|
||||
}
|
||||
unset($allinsert);
|
||||
enter_logfile($cfg,4," Store new cldbid ".$getcldbid[0]." for client (uuid: ".$uuid." old cldbid: ".$userstats['cldbid'].")");
|
||||
}
|
||||
} else {
|
||||
enter_logfile($cfg,3," Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") is missing in TS database, but TeamSpeak answers on question with the same cldbid (".$getcldbid[0].").. It's weird!");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
if($e->getCode() == 2568) {
|
||||
enter_logfile($cfg,4,$e->getCode() . ': ' . $e->getMessage()."; Error due command clientdbfind (permission: b_virtualserver_client_dbsearch needed).");
|
||||
} else {
|
||||
enter_logfile($cfg,6,$e->getCode() . ': ' . $e->getMessage()."; Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") is missing in TS database, it seems to be deleted. Run the !clean command to correct this.");
|
||||
$sqlexec .= "UPDATE `$dbname`.`stats_user` SET `count_week`=0,`count_month`=0,`idle_week`=0,`idle_month`=0,`active_week`=0,`active_month`=0,`removed`=1 WHERE `uuid`='$uuid';\n";
|
||||
}
|
||||
if(isset($userdata[$userstats['cldbid']]) && isset($userdata[$userstats['cldbid']][$keyweek]) && $userdata[$userstats['cldbid']][$keyweek]['id'] == $weekago) {
|
||||
$count_week = $userdata[$userstats['cldbid']][$keybase]['count'] - $userdata[$userstats['cldbid']][$keyweek]['count'];
|
||||
$idle_week = $userdata[$userstats['cldbid']][$keybase]['idle'] - $userdata[$userstats['cldbid']][$keyweek]['idle'];
|
||||
$active_week = $count_week - $idle_week;
|
||||
if($count_week < 0 || $count_week < $idle_week) $count_week = 0;
|
||||
if($idle_week < 0 || $count_week < $idle_week) $idle_week = 0;
|
||||
if($active_week < 0 || $count_week < $idle_week) $active_week = 0;
|
||||
} else {
|
||||
$count_week = $idle_week = $active_week = 0;
|
||||
}
|
||||
if(isset($userdata[$userstats['cldbid']]) && isset($userdata[$userstats['cldbid']][$keymonth]) && $userdata[$userstats['cldbid']][$keymonth]['id'] == $monthago) {
|
||||
$count_month = $userdata[$userstats['cldbid']][$keybase]['count'] - $userdata[$userstats['cldbid']][$keymonth]['count'];
|
||||
$idle_month = $userdata[$userstats['cldbid']][$keybase]['idle'] - $userdata[$userstats['cldbid']][$keymonth]['idle'];
|
||||
$active_month = $count_month - $idle_month;
|
||||
if($idle_month < 0 || $count_month < $idle_month) $idle_month = 0;
|
||||
if($count_month < 0 || $count_month < $idle_month) $count_month = 0;
|
||||
if($active_month < 0 || $count_month < $idle_month) $active_month = 0;
|
||||
} else {
|
||||
$count_month = $idle_month = $active_month = 0;
|
||||
}
|
||||
} else {
|
||||
enter_logfile($cfg,2,$lang['errorts3'].$e->getCode().': '.$e->getMessage()."; Error due command clientdbinfo for client-database-ID {$userstats['cldbid']} (permission: b_virtualserver_client_dbinfo needed).");
|
||||
$count_week = $idle_week = $active_week = $count_month = $idle_month = $active_month = 0;
|
||||
}
|
||||
|
||||
$clientdesc = $clientinfo['client_base64HashClientUID'] = $mysqlcon->quote('', ENT_QUOTES);
|
||||
$clientinfo['client_totalconnections'] = $clientinfo['client_total_bytes_uploaded'] = $clientinfo['client_total_bytes_downloaded'] = 0;
|
||||
}
|
||||
try {
|
||||
$clientinfo = $ts3->clientInfoDb($userstats['cldbid']);
|
||||
$clientdesc = $mysqlcon->quote($clientinfo['client_description'], ENT_QUOTES);
|
||||
if($clientinfo['client_totalconnections'] > 16777215) $clientinfo['client_totalconnections'] = 16777215;
|
||||
} catch (Exception $e) {
|
||||
if($e->getCode() == 512 || $e->getCode() == 1281) {
|
||||
enter_logfile($cfg,6,"Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") known by Ranksystem is missing in TS database, perhaps its already deleted or cldbid changed. Try to search for client by uuid.");
|
||||
try {
|
||||
$getcldbid = $ts3->clientFindDb($uuid, TRUE);
|
||||
if($getcldbid[0] != $userstats['cldbid']) {
|
||||
enter_logfile($cfg,4," Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") known by the Ranksystem changed its cldbid. New cldbid is ".$getcldbid[0].".");
|
||||
if($cfg['rankup_client_database_id_change_switch'] == 1) {
|
||||
$db_cache['all_user'][$uuid]['cldbid'] = $getcldbid[0];
|
||||
$sqlexec .= "UPDATE `$dbname`.`user` SET `count`=0,`idle`=0 WHERE `uuid`='$uuid';\nUPDATE `$dbname`.`stats_user` SET `count_week`=0,`count_month`=0,`idle_week`=0,`idle_month`=0,`active_week`=0,`active_month`=0 WHERE `uuid`='$uuid';\nDELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$userstats['cldbid']}';\n";
|
||||
enter_logfile($cfg,4," ".sprintf($lang['changedbid'], $userstats['name'], $uuid, $userstats['cldbid'], $getcldbid[0]));
|
||||
} else {
|
||||
$sqlexec .= "UPDATE `$dbname`.`user` SET `cldbid`={$getcldbid[0]} WHERE `uuid`='$uuid';\n";
|
||||
// select current user_snapshot entries and insert this with the new database-ID
|
||||
if(isset($userdata[$userstats['cldbid']])) {
|
||||
$allinsert = '';
|
||||
foreach($userdata[$userstats['cldbid']] as $id => $data) {
|
||||
$allinsert .= "($id,'{$getcldbid[0]}',{$data['count']},{$data['idle']}),";
|
||||
}
|
||||
if ($allinsert != '') {
|
||||
$allinsert = substr($allinsert, 0, -1);
|
||||
$sqlexec .= "INSERT INTO `$dbname`.`user_snapshot` (`id`,`cldbid`,`count`,`idle`) VALUES $allinsert ON DUPLICATE KEY UPDATE `count`=VALUES(`count`),`idle`=VALUES(`idle`);\nDELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$userstats['cldbid']}';\n";
|
||||
}
|
||||
unset($allinsert);
|
||||
}
|
||||
enter_logfile($cfg,4," Store new cldbid ".$getcldbid[0]." for client (uuid: ".$uuid." old cldbid: ".$userstats['cldbid'].")");
|
||||
}
|
||||
} else {
|
||||
enter_logfile($cfg,3," Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") is missing in TS database, but TeamSpeak answers on question with the same cldbid (".$getcldbid[0].").. It's weird!");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
if($e->getCode() == 2568) {
|
||||
enter_logfile($cfg,4,$e->getCode() . ': ' . $e->getMessage()."; Error due command clientdbfind (permission: b_virtualserver_client_dbsearch needed).");
|
||||
} else {
|
||||
enter_logfile($cfg,6,$e->getCode() . ': ' . $e->getMessage()."; Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") is missing in TS database, it seems to be deleted. Run the !clean command to correct this.");
|
||||
$sqlexec .= "UPDATE `$dbname`.`stats_user` SET `count_week`=0,`count_month`=0,`idle_week`=0,`idle_month`=0,`active_week`=0,`active_month`=0,`removed`=1 WHERE `uuid`='$uuid';\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
enter_logfile($cfg,2,$lang['errorts3'].$e->getCode().': '.$e->getMessage()."; Error due command clientdbinfo for client-database-ID {$userstats['cldbid']} (permission: b_virtualserver_client_dbinfo needed).");
|
||||
}
|
||||
|
||||
$allupdateuuid .= "('$uuid',$count_week,$count_month,$idle_week,$idle_month,$active_week,$active_month,{$clientinfo['client_totalconnections']},'{$clientinfo['client_base64HashClientUID']}',{$clientinfo['client_total_bytes_uploaded']},{$clientinfo['client_total_bytes_downloaded']},$clientdesc,$nowtime),";
|
||||
$clientdesc = $clientinfo['client_base64HashClientUID'] = $mysqlcon->quote('', ENT_QUOTES);
|
||||
$clientinfo['client_totalconnections'] = $clientinfo['client_total_bytes_uploaded'] = $clientinfo['client_total_bytes_downloaded'] = 0;
|
||||
}
|
||||
|
||||
$allupdateuuid .= "('$uuid',$count_week,$count_month,$idle_week,$idle_month,$active_week,$active_month,{$clientinfo['client_totalconnections']},'{$clientinfo['client_base64HashClientUID']}',{$clientinfo['client_total_bytes_uploaded']},{$clientinfo['client_total_bytes_downloaded']},$clientdesc,$nowtime),";
|
||||
}
|
||||
}
|
||||
unset($sqlhis,$userdataweekbegin,$userdataend,$userdatamonthbegin,$clientinfo,$count_week,$idle_week,$active_week,$count_month,$idle_month,$active_month,$clientdesc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user