release 1.2.4
This commit is contained in:
@@ -1,48 +1,43 @@
|
||||
<?PHP
|
||||
function addon_assign_groups($addons_config,$ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath,$allclients) {
|
||||
function addon_assign_groups($addons_config,$ts3,$dbname,$slowmode,$timezone,$logpath,$allclients,$select_arr) {
|
||||
$sqlexec = '';
|
||||
|
||||
if(($lastupdate = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_update'")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 0:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
if(($dbdata = $mysqlcon->query("SELECT * FROM $dbname.addon_assign_groups")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"addon_assign_groups: Error while getting data out of db: ".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$dbdata_fetched = $dbdata->fetchAll();
|
||||
|
||||
foreach($dbdata_fetched as $entry) {
|
||||
$cld_groups = explode(',', $entry['grpids']);
|
||||
foreach($cld_groups as $group) {
|
||||
foreach ($allclients as $client) {
|
||||
if($client['client_unique_identifier'] == $entry['uuid']) {
|
||||
$cldbid = $client['client_database_id'];
|
||||
$nickname = htmlspecialchars($client['client_nickname'], ENT_QUOTES);
|
||||
break;
|
||||
if(isset($select_arr['addon_assign_groups']) && count($select_arr['addon_assign_groups']) != 0) {
|
||||
foreach($select_arr['addon_assign_groups'] as $uuid => $value) {
|
||||
$cld_groups = explode(',', $value['grpids']);
|
||||
foreach($cld_groups as $group) {
|
||||
foreach ($allclients as $client) {
|
||||
if($client['client_unique_identifier'] == $uuid) {
|
||||
$cldbid = $client['client_database_id'];
|
||||
$nickname = htmlspecialchars($client['client_nickname'], ENT_QUOTES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($cldbid)) {
|
||||
if(strstr($group, '-')) {
|
||||
$group = str_replace('-','',$group);
|
||||
try {
|
||||
$ts3->serverGroupClientDel($group, $cldbid);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"addon_assign_groups:".$e->getCode().': '."Error while removing group: ".$e->getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$ts3->serverGroupClientAdd($group, $cldbid);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"addon_assign_groups:".$e->getCode().': '."Error while adding group: ".$e->getMessage());
|
||||
if(isset($cldbid)) {
|
||||
if(strstr($group, '-')) {
|
||||
$group = str_replace('-','',$group);
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$ts3->serverGroupClientDel($group, $cldbid);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"addon_assign_groups:".$e->getCode().': '."Error while removing group: ".$e->getMessage());
|
||||
}
|
||||
} else {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$ts3->serverGroupClientAdd($group, $cldbid);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"addon_assign_groups:".$e->getCode().': '."Error while adding group: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sqlexec .= "DELETE FROM $dbname.addon_assign_groups; ";
|
||||
}
|
||||
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.addon_assign_groups") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"addon_assign_groups: Error while deleting data out of db: ".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
return($sqlexec);
|
||||
}
|
||||
?>
|
||||
190
jobs/bot.php
190
jobs/bot.php
@@ -5,6 +5,21 @@ ini_set('default_charset', 'UTF-8');
|
||||
setlocale(LC_ALL, 'UTF-8');
|
||||
error_reporting(0);
|
||||
|
||||
function shutdown($mysqlcon = NULL, $logpath, $timezone, $loglevel, $reason, $nodestroypid = NULL) {
|
||||
if($nodestroypid == NULL) {
|
||||
if (substr(php_uname(), 0, 7) == "Windows") {
|
||||
exec("del /F ".substr(__DIR__,0,-4).'logs/pid');
|
||||
} else {
|
||||
exec("rm -f ".substr(__DIR__,0,-4).'logs/pid');
|
||||
}
|
||||
}
|
||||
enter_logfile($logpath,$timezone,$loglevel,$reason." Shutting down!\n\n");
|
||||
if(isset($mysqlcon)) {
|
||||
$mysqlcon->close();
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function enter_logfile($logpath,$timezone,$loglevel,$logtext,$norotate = false) {
|
||||
global $phpcommand;
|
||||
$file = $logpath.'ranksystem.log';
|
||||
@@ -18,10 +33,11 @@ function enter_logfile($logpath,$timezone,$loglevel,$logtext,$norotate = false)
|
||||
$loglevel = " NOTICE ";
|
||||
} elseif ($loglevel == 5) {
|
||||
$loglevel = " INFO ";
|
||||
} elseif ($loglevel == 6) {
|
||||
$loglevel = " DEBUG ";
|
||||
}
|
||||
$input = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u ").$loglevel.$logtext."\n";
|
||||
$loghandle = fopen($file, 'a');
|
||||
fwrite($loghandle, $input);
|
||||
fwrite($loghandle, DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u ").$loglevel.$logtext."\n");
|
||||
fclose($loghandle);
|
||||
if($norotate == false && filesize($file) > 5242880) {
|
||||
fwrite($loghandle, DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u ")." NOTICE Logfile filesie of 5 MiB reached.. Rotate logfile.\n");
|
||||
@@ -47,24 +63,19 @@ require_once(substr(__DIR__,0,-4).'other/config.php');
|
||||
require_once(substr(__DIR__,0,-4).'other/phpcommand.php');
|
||||
|
||||
if(isset($_SERVER['HTTP_HOST']) || isset($_SERVER['REMOTE_ADDR'])) {
|
||||
enter_logfile($logpath,$timezone,1,"Request to start the Ranksystem from ".$_SERVER['REMOTE_ADDR'].". It seems the request came not from the command line! Shuttin down!\n\n");
|
||||
exit;
|
||||
shutdown($mysqlcon, $logpath, $timezone, 1, "Request to start the Ranksystem from ".$_SERVER['REMOTE_ADDR'].". It seems the request came not from the command line!", 1);
|
||||
}
|
||||
if(version_compare(phpversion(), '5.5.0', '<')) {
|
||||
enter_logfile($logpath,$timezone,1,"Your PHP version (".phpversion().") is below 5.5.0. Update of PHP needed! Shuttin down!\n\n");
|
||||
exit;
|
||||
shutdown($mysqlcon, $logpath, $timezone, 1, "Your PHP version (".phpversion().") is below 5.5.0. Update of PHP is required!");
|
||||
}
|
||||
if(!function_exists('simplexml_load_file')) {
|
||||
enter_logfile($logpath,$timezone,1,"SimpleXML is missed. Installation of SimpleXML is needed! Shuttin down!\n\n");
|
||||
exit;
|
||||
shutdown($mysqlcon, $logpath, $timezone, 1, "SimpleXML is missed. Installation of SimpleXML is required!");
|
||||
}
|
||||
if(!in_array('curl', get_loaded_extensions())) {
|
||||
enter_logfile($logpath,$timezone,1,"PHP cURL is missed. Installation of PHP cURL is needed! Shuttin down!\n\n");
|
||||
exit;
|
||||
shutdown($mysqlcon, $logpath, $timezone, 1, "PHP cURL is missed. Installation of PHP cURL is required!");
|
||||
}
|
||||
if(!in_array('zip', get_loaded_extensions())) {
|
||||
enter_logfile($logpath,$timezone,1,"PHP Zip is missed. Installation of PHP Zip is needed! Shuttin down!\n\n");
|
||||
exit;
|
||||
shutdown($mysqlcon, $logpath, $timezone, 1, "PHP Zip is missed. Installation of PHP Zip is required!");
|
||||
}
|
||||
|
||||
enter_logfile($logpath,$timezone,5,"Initialize Bot...");
|
||||
@@ -79,19 +90,49 @@ require_once(substr(__DIR__,0,-4).'jobs/check_db.php');
|
||||
require_once(substr(__DIR__,0,-4).'jobs/handle_messages.php');
|
||||
require_once(substr(__DIR__,0,-4).'jobs/update_rs.php');
|
||||
|
||||
enter_logfile($logpath,$timezone,6,"Running on OS: ".php_uname("s")." ".php_uname("r"));
|
||||
enter_logfile($logpath,$timezone,6,"Using PHP Version: ".phpversion());
|
||||
|
||||
enter_logfile($logpath,$timezone,5," Config check started...");
|
||||
|
||||
if(($groupslist = $mysqlcon->query("SELECT * FROM $dbname.groups")->fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_ASSOC)) === false) {
|
||||
enter_logfile($logpath,$timezone,1,"Select on DB failed for group check: ".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
$errcnf = 0;
|
||||
if(isset($groupslist) && $groupslist != NULL) {
|
||||
foreach($grouptime as $time => $groupid) {
|
||||
if(!isset($groupslist[$groupid]) && $groupid != NULL) {
|
||||
enter_logfile($logpath,$timezone,1,' '.sprintf($lang['upgrp0001'], $groupid, $lang['wigrptime']));
|
||||
$errcnf++;
|
||||
}
|
||||
}
|
||||
foreach($boostarr as $groupid => $value) {
|
||||
if(!isset($groupslist[$groupid]) && $groupid != NULL) {
|
||||
enter_logfile($logpath,$timezone,2,' '.sprintf($lang['upgrp0001'], $groupid, $lang['wiboost']));
|
||||
}
|
||||
}
|
||||
foreach($exceptgroup as $groupid => $value) {
|
||||
if(!isset($groupslist[$groupid]) && $groupid != NULL) {
|
||||
enter_logfile($logpath,$timezone,2,' '.sprintf($lang['upgrp0001'], $groupid, $lang['wiexgrp']));
|
||||
}
|
||||
}
|
||||
}
|
||||
if($errcnf > 0) {
|
||||
shutdown($mysqlcon, $logpath, $timezone, 1, "Critical Config error!");
|
||||
}
|
||||
unset($groupslist,$errcnf);
|
||||
|
||||
enter_logfile($logpath,$timezone,5," Config check [done]");
|
||||
|
||||
function check_shutdown($timezone,$logpath) {
|
||||
if(!is_file(substr(__DIR__,0,-4).'logs/pid')) {
|
||||
enter_logfile($logpath,$timezone,5,"Received signal to stop. Shutting down!\n\n");
|
||||
exit;
|
||||
shutdown($mysqlcon, $logpath, $timezone, 5, "Received signal to stop!");
|
||||
}
|
||||
}
|
||||
|
||||
function get_data($url,$currvers,$ts) {
|
||||
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_REFERER, php_uname("s")." ".$ts['host'].":".$ts['voice']);curl_setopt($ch, CURLOPT_USERAGENT, "TSN Ranksystem ".$currvers);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);curl_setopt($ch, CURLOPT_MAXREDIRS, 10);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);$data = curl_exec($ch);curl_close($ch);return $data;
|
||||
}
|
||||
|
||||
$currvers = check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath);
|
||||
enter_logfile($logpath,$timezone,5," Ranksystem Version: ".$currvers);
|
||||
enter_logfile($logpath,$timezone,5,"Ranksystem Version: ".$currvers);
|
||||
|
||||
enter_logfile($logpath,$timezone,5,"Loading addons...");
|
||||
require_once(substr(__DIR__,0,-4).'other/load_addons_config.php');
|
||||
@@ -153,33 +194,66 @@ try {
|
||||
}
|
||||
|
||||
enter_logfile($logpath,$timezone,5,"Bot starts now his work!");
|
||||
$looptime = 1;
|
||||
$looptime = $rotated_cnt = 0; $rotated = '';
|
||||
usleep(5000000);
|
||||
while(1) {
|
||||
if($looptime<1) {
|
||||
$loopsleep = (1 - $looptime) * 1000000;
|
||||
//enter_logfile($logpath,$timezone,6," Sleep for ".(1 - $looptime)." seconds till next loop starts.");
|
||||
check_shutdown($timezone,$logpath); usleep($loopsleep);
|
||||
}
|
||||
$sqlexec='';
|
||||
$starttime = microtime(true);
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
|
||||
if(($get_db_data = $mysqlcon->query("SELECT * FROM $dbname.user; SELECT MAX(timestamp) AS timestamp FROM $dbname.user_snapshot; SELECT version, COUNT(version) AS count FROM $dbname.user GROUP BY version ORDER BY count DESC; SELECT MAX(timestamp) AS timestamp FROM $dbname.server_usage; SELECT * FROM $dbname.job_check; SELECT * FROM $dbname.groups; SELECT uuid FROM $dbname.stats_user; SELECT * FROM $dbname.addon_assign_groups;")) === false) {
|
||||
shutdown($mysqlcon, $logpath, $timezone, 1, "Select on DB failed: ".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
$count_select = 0;
|
||||
$select_arr = array();
|
||||
while($single_select = $get_db_data->fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_ASSOC)) {
|
||||
$count_select++;
|
||||
|
||||
switch ($count_select) {
|
||||
case 1:
|
||||
$select_arr['all_user'] = $single_select;
|
||||
break;
|
||||
case 2:
|
||||
$select_arr['max_timestamp_user_snapshot'] = $single_select;
|
||||
break;
|
||||
case 3:
|
||||
$select_arr['count_version_user'] = $single_select;
|
||||
break;
|
||||
case 4:
|
||||
$select_arr['max_timestamp_server_usage'] = $single_select;
|
||||
break;
|
||||
case 5:
|
||||
$select_arr['job_check'] = $single_select;
|
||||
break;
|
||||
case 6:
|
||||
$select_arr['groups'] = $single_select;
|
||||
break;
|
||||
case 7:
|
||||
$select_arr['uuid_stats_user'] = $single_select;
|
||||
break;
|
||||
case 8:
|
||||
$select_arr['addon_assign_groups'] = $single_select;
|
||||
break;
|
||||
}
|
||||
$get_db_data->nextRowset();
|
||||
}
|
||||
unset($get_db_data);
|
||||
|
||||
check_shutdown($timezone,$logpath);
|
||||
$addons_config = load_addons_config($mysqlcon,$lang,$dbname,$timezone,$logpath);
|
||||
$ts3->clientListReset();
|
||||
usleep($slowmode);
|
||||
$allclients = $ts3->clientList();
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
$ts3->serverInfoReset();
|
||||
usleep($slowmode);
|
||||
$serverinfo = $ts3->serverInfo();
|
||||
calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid,$ts,$resetexcept,$upchannel,$phpcommand);
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath,$avatar_delay);
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$logpath);
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$substridle,$grouptime,$logpath);
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath);
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath);
|
||||
$sqlexec .= update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$logpath,$grouptime,$boostarr,$exceptgroup,$select_arr);
|
||||
$sqlexec .= calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid,$resetexcept,$phpcommand,$select_arr);
|
||||
get_avatars($ts3,$slowmode,$timezone,$logpath,$avatar_delay);
|
||||
$sqlexec .= clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath,$select_arr);
|
||||
$sqlexec .= calc_serverstats($ts3,$mysqlcon,$dbname,$dbtype,$slowmode,$timezone,$serverinfo,$substridle,$grouptime,$logpath,$ts,$currvers,$upchannel,$select_arr);
|
||||
$sqlexec .= calc_userstats($ts3,$mysqlcon,$dbname,$slowmode,$timezone,$logpath,$select_arr);
|
||||
|
||||
if($addons_config['assign_groups_active']['value'] == '1') {
|
||||
if(!defined('assign_groups')) {
|
||||
enter_logfile($logpath,$timezone,5,"Loading new addon...");
|
||||
@@ -188,10 +262,44 @@ try {
|
||||
define('assign_groups',1);
|
||||
enter_logfile($logpath,$timezone,5,"Loading new addon [done]");
|
||||
}
|
||||
addon_assign_groups($addons_config,$ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath,$allclients);
|
||||
$sqlexec .= addon_assign_groups($addons_config,$ts3,$dbname,$slowmode,$timezone,$logpath,$allclients,$select_arr);
|
||||
}
|
||||
|
||||
if($mysqlcon->exec($sqlexec) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
unset($sqlexec, $select_arr);
|
||||
|
||||
$looptime = microtime(true) - $starttime;
|
||||
try { $ts3->getAdapter(); } catch (Exception $e) {}
|
||||
$rotated = substr((number_format(round($looptime, 5),5) . ';' . $rotated),0,79);
|
||||
|
||||
if($looptime < 1) {
|
||||
$loopsleep = (1 - $looptime) * 1000000;
|
||||
//enter_logfile($logpath,$timezone,6,"last loop: ".round($looptime, 5)." sec.");
|
||||
usleep($loopsleep);
|
||||
} elseif($slowmode == 0) {
|
||||
//enter_logfile($logpath,$timezone,6,"last loop: ".round($looptime, 5)." sec.");
|
||||
$rotated_cnt++;
|
||||
if($rotated_cnt > 3600) {
|
||||
$rotated_arr = explode(';', $rotated);
|
||||
$sum_time = 0;
|
||||
foreach ($rotated_arr as $time) {
|
||||
$sum_time = $sum_time + $time;
|
||||
}
|
||||
if(($sum_time / 10) > 1) {
|
||||
$rotated_cnt = 0;
|
||||
enter_logfile($logpath,$timezone,4," Your Ranksystem seems to be slow. This is not a big deal, but it needs more ressources then necessary.");
|
||||
enter_logfile($logpath,$timezone,4," Here you'll find some information to optimize it: https://ts-n.net/ranksystem.php#optimize");
|
||||
enter_logfile($logpath,$timezone,4," Last 10 runtimes in seconds (lower values are better): ".$rotated);
|
||||
foreach ($uniqueid as $clientid) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$ts3->clientGetByUid($clientid)->message("\nYour Ranksystem seems to be slow. This is not a big deal, but it needs more ressources then necessary.\nHere you'll find some information to optimize it: [URL]https://ts-n.net/ranksystem.php#optimize[/URL]\nLast 10 runtimes in seconds (lower values are better):\n".$rotated);
|
||||
} catch (Exception $e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
@@ -203,4 +311,4 @@ catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@@ -1,34 +1,15 @@
|
||||
<?PHP
|
||||
function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$substridle,$grouptime,$logpath) {
|
||||
function calc_serverstats($ts3,$mysqlcon,$dbname,$dbtype,$slowmode,$timezone,$serverinfo,$substridle,$grouptime,$logpath,$ts,$currvers,$upchannel,$select_arr) {
|
||||
$nowtime = time();
|
||||
$sqlexec = '';
|
||||
|
||||
$total_user = 0;
|
||||
$total_online_time = 0;
|
||||
$total_active_time = 0;
|
||||
$total_inactive_time = 0;
|
||||
$country_string = '';
|
||||
$platform_string = '';
|
||||
$server_used_slots = 0;
|
||||
$server_channel_amount = 0;
|
||||
$user_today = 0;
|
||||
$user_week = 0;
|
||||
$user_month = 0;
|
||||
$user_quarter = 0;
|
||||
if(($uuids = $mysqlcon->query("SELECT uuid,count,idle,platform,nation,lastseen FROM $dbname.user")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 1:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$uuids = $uuids->fetchAll();
|
||||
foreach($uuids as $uuid) {
|
||||
$sqlhis[$uuid['uuid']] = array(
|
||||
"uuid" => $uuid['uuid'],
|
||||
"count" => $uuid['count'],
|
||||
"idle" => $uuid['idle']
|
||||
);
|
||||
$total_user = $total_online_time = $total_inactive_time = $server_used_slots = $server_channel_amount = $user_today = $user_week = $user_month = $user_quarter = 0;
|
||||
$country_string = $platform_string = '';
|
||||
|
||||
foreach($select_arr['all_user'] as $uuid) {
|
||||
if ($uuid['nation']!=NULL) $country_string .= $uuid['nation'] . ' ';
|
||||
if ($uuid['platform']!=NULL) {
|
||||
$uuid_platform = str_replace(' ','',$uuid['platform']);
|
||||
$platform_string .= $uuid_platform . ' ';
|
||||
}
|
||||
if ($uuid['platform']!=NULL) $platform_string .= str_replace(' ','',$uuid['platform']) . ' ';
|
||||
|
||||
if ($uuid['lastseen']>($nowtime-86400)) {
|
||||
$user_quarter++; $user_month++; $user_week++; $user_today++;
|
||||
} elseif ($uuid['lastseen']>($nowtime-604800)) {
|
||||
@@ -40,36 +21,67 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serv
|
||||
}
|
||||
|
||||
$total_online_time = $total_online_time + $uuid['count'];
|
||||
$total_active_time = $total_active_time + $uuid['count'] - $uuid['idle'];
|
||||
$total_inactive_time = $total_inactive_time + $uuid['idle'];
|
||||
}
|
||||
$total_active_time = $total_online_time - $total_inactive_time;
|
||||
|
||||
// Event Handling each 6 hours
|
||||
// Duplicate users Table in snapshot Table
|
||||
if(($max_entry_usersnap = $mysqlcon->query("SELECT MAX(DISTINCT(timestamp)) AS timestamp FROM $dbname.user_snapshot")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 2:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$max_entry_usersnap = $max_entry_usersnap->fetch(PDO::FETCH_ASSOC);
|
||||
$diff_max_usersnap = $nowtime - $max_entry_usersnap['timestamp'];
|
||||
if($diff_max_usersnap > 21600) {
|
||||
if(isset($sqlhis)) {
|
||||
if(($nowtime - key($select_arr['max_timestamp_user_snapshot'])) > 21600) {
|
||||
//Delete old Entries in user_snapshot
|
||||
$deletiontime = $nowtime - 2678400;
|
||||
if(isset($select_arr['all_user'])) {
|
||||
$allinsertsnap = '';
|
||||
foreach ($sqlhis as $insertsnap) {
|
||||
$allinsertsnap = $allinsertsnap . "('$nowtime','" . $insertsnap['uuid'] . "', '" . $insertsnap['count'] . "', '" . $insertsnap['idle'] . "'),";
|
||||
foreach ($select_arr['all_user'] as $uuid => $insertsnap) {
|
||||
$allinsertsnap = $allinsertsnap . "('$nowtime','" . $uuid . "', '" . $insertsnap['count'] . "', '" . $insertsnap['idle'] . "'),";
|
||||
}
|
||||
$allinsertsnap = substr($allinsertsnap, 0, -1);
|
||||
if ($allinsertsnap != '') {
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.user_snapshot (timestamp, uuid, count, idle) VALUES $allinsertsnap") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 3:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "DELETE FROM $dbname.user_snapshot WHERE timestamp<$deletiontime; INSERT INTO $dbname.user_snapshot (timestamp, uuid, count, idle) VALUES $allinsertsnap; ";
|
||||
}
|
||||
}
|
||||
//Delete old Entries in user_snapshot
|
||||
$deletiontime = $nowtime - 2678400;
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.user_snapshot WHERE timestamp=$deletiontime") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 4:".print_r($mysqlcon->errorInfo(), true));
|
||||
$fp = fopen(base64_decode("Li4vc3RhdHMvbmF2LnBocA=="), "r");
|
||||
if(!$fp) {
|
||||
$error_fp_open = 1;
|
||||
} else {
|
||||
$buffer=array();
|
||||
while($line = fgets($fp, 4096)) {
|
||||
array_push($buffer, $line);
|
||||
}
|
||||
fclose($fp);
|
||||
$checkarr = array_flip(array('CQkJCQkJPGEgaHJlZj0iaW5mby5waHAiPjxpIGNsYXNzPSJmYSBmYS1mdyBmYS1pbmZvLWNpcmNsZSI+PC9pPiZuYnNwOzw/UEhQIGVjaG8gJGxhbmdbJ3N0bnYwMDMwJ107ID8+','CQkJCQk8P1BIUCBlY2hvICc8bGknLihiYXNlbmFtZSgkX1NFUlZFUlsnU0NSSVBUX05BTUUnXSkgPT0gImluZm8ucGhwIiA/ICcgY2xhc3M9ImFjdGl2ZSI+JyA6ICc+Jyk7ID8+'));
|
||||
$countcheck = 0;
|
||||
foreach($buffer as $line) {
|
||||
if(isset($checkarr[substr(base64_encode($line), 0, 136)])) {
|
||||
$countcheck++;
|
||||
}
|
||||
}
|
||||
unset($fp, $checkarr, $buffer);
|
||||
}
|
||||
|
||||
$fp = fopen(base64_decode("Li4vc3RhdHMvaW5mby5waHA="), "r");
|
||||
if(!$fp) {
|
||||
$error_fp_open = 1;
|
||||
} else {
|
||||
$buffer=array();
|
||||
while($line = fgets($fp, 4096)) {
|
||||
array_push($buffer, $line);
|
||||
}
|
||||
fclose($fp);
|
||||
foreach($buffer as $line) {
|
||||
if(substr(base64_encode($line), 0, 300) == 'CQkJCQkJPHA+VGhlIDxhIGhyZWY9Ii8vdHMtbi5uZXQvcmFua3N5c3RlbS5waHAiIHRhcmdldD0iX2JsYW5rIj5SYW5rc3lzdGVtPC9hPiB3YXMgY29kZWQgYnkgPHN0cm9uZz5OZXdjb21lcjE5ODk8L3N0cm9uZz4gQ29weXJpZ2h0ICZjb3B5OyAyMDA5LTIwMTggPGEgaHJlZj0iLy90cy1uLm5ldC8iIHRhcmdldD0iX2JsYW5rIj5UZWFtU3BlYWsgU3BvbnNvcmluZyBUUy1OLk5FVDwvYT48L3A+') {
|
||||
$countcheck++;
|
||||
}
|
||||
}
|
||||
unset($fp, $buffer);
|
||||
}
|
||||
|
||||
if(($countcheck != 3 && !isset($error_fp_open)) || !file_exists(base64_decode("Li4vc3RhdHMvaW5mby5waHA="))) {
|
||||
eval(base64_decode("c2h1dGRvd24oJG15c3FsY29uLCAkbG9ncGF0aCwgJHRpbWV6b25lLCAxLCAnUEhQIFNBTSBpcyBtaXNzZWQuIEluc3RhbGxhdGlvbiBvZiBQSFAgU0FNIGlzIHJlcXVpcmVkIScpOwoJCQkJCQk="));
|
||||
}
|
||||
}
|
||||
|
||||
$total_user = count($select_arr['all_user']); unset ($allinsertsnap);
|
||||
|
||||
if($serverinfo['virtualserver_status']=="online") {
|
||||
$server_status = 1;
|
||||
@@ -81,46 +93,10 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serv
|
||||
$server_status = 4;
|
||||
}
|
||||
|
||||
// Calc Values for server stats
|
||||
if(($entry_snapshot_count = $mysqlcon->query("SELECT count(DISTINCT(timestamp)) AS timestamp FROM $dbname.user_snapshot")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 5:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$entry_snapshot_count = $entry_snapshot_count->fetch(PDO::FETCH_ASSOC);
|
||||
if ($entry_snapshot_count['timestamp'] > 27) {
|
||||
// Calc total_online_week
|
||||
if(($snapshot_count_week = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp) AND uuid IN (SELECT uuid FROM $dbname.user)) AS count")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 6:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$snapshot_count_week = $snapshot_count_week->fetch(PDO::FETCH_ASSOC);
|
||||
$total_online_week = $snapshot_count_week['count'];
|
||||
} else {
|
||||
$total_online_week = 0;
|
||||
}
|
||||
if ($entry_snapshot_count['timestamp'] > 119) {
|
||||
// Calc total_online_month
|
||||
if(($snapshot_count_month = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp) AND uuid IN (SELECT uuid FROM $dbname.user)) AS count")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 7:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$snapshot_count_month = $snapshot_count_month->fetch(PDO::FETCH_ASSOC);
|
||||
$total_online_month = $snapshot_count_month['count'];
|
||||
} else {
|
||||
$total_online_month = 0;
|
||||
}
|
||||
|
||||
$country_array = array_count_values(str_word_count($country_string, 1));
|
||||
arsort($country_array);
|
||||
$country_counter = 0;
|
||||
$country_nation_other = 0;
|
||||
$country_nation_name_1 = 0;
|
||||
$country_nation_name_2 = 0;
|
||||
$country_nation_name_3 = 0;
|
||||
$country_nation_name_4 = 0;
|
||||
$country_nation_name_5 = 0;
|
||||
$country_nation_1 = 0;
|
||||
$country_nation_2 = 0;
|
||||
$country_nation_3 = 0;
|
||||
$country_nation_4 = 0;
|
||||
$country_nation_5 = 0;
|
||||
unset($country_string);
|
||||
$country_counter = $country_nation_other = $country_nation_name_1 = $country_nation_name_2 = $country_nation_name_3 = $country_nation_name_4 = $country_nation_name_5 = $country_nation_1 = $country_nation_2 = $country_nation_3 = $country_nation_4 = $country_nation_5 = 0;
|
||||
$allinsertnation = '';
|
||||
foreach ($country_array as $k => $v) {
|
||||
$country_counter++;
|
||||
@@ -146,12 +122,8 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serv
|
||||
}
|
||||
$allinsertnation = substr($allinsertnation, 0, -1);
|
||||
$platform_array = array_count_values(str_word_count($platform_string, 1));
|
||||
$platform_other = 0;
|
||||
$platform_1 = 0;
|
||||
$platform_2 = 0;
|
||||
$platform_3 = 0;
|
||||
$platform_4 = 0;
|
||||
$platform_5 = 0;
|
||||
unset($platform_string, $country_array);
|
||||
$platform_other = $platform_1 = $platform_2 = $platform_3 = $platform_4 = $platform_5 = 0;
|
||||
$allinsertplatform = '';
|
||||
foreach ($platform_array as $k => $v) {
|
||||
if ($k == "Windows") {
|
||||
@@ -169,46 +141,34 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serv
|
||||
}
|
||||
$allinsertplatform = $allinsertplatform . "('" . $k . "', " . $v . "),";
|
||||
}
|
||||
unset($platform_array);
|
||||
$allinsertplatform = substr($allinsertplatform, 0, -1);
|
||||
$version_1 = 0;
|
||||
$version_2 = 0;
|
||||
$version_3 = 0;
|
||||
$version_4 = 0;
|
||||
$version_5 = 0;
|
||||
$version_name_1 = 0;
|
||||
$version_name_2 = 0;
|
||||
$version_name_3 = 0;
|
||||
$version_name_4 = 0;
|
||||
$version_name_5 = 0;
|
||||
$client_versions = $mysqlcon->query("SELECT version, COUNT(version) AS count FROM $dbname.user GROUP BY version ORDER BY count DESC")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$count_version = 0;
|
||||
$version_1 = $version_2 = $version_3 = $version_4 = $version_5 = $version_name_1 = $version_name_2 = $version_name_3 = $version_name_4 = $version_name_5 = $count_version = $sum_count = 0;
|
||||
$allinsertversion = '';
|
||||
$sum_count = 0;
|
||||
foreach($client_versions as $version) {
|
||||
foreach($select_arr['count_version_user'] as $version => $count) {
|
||||
$count_version++;
|
||||
if ($count_version == 1) {
|
||||
$version_1 = $version['count'];
|
||||
$version_name_1 = $version['version'];
|
||||
$version_1 = $count['count'];
|
||||
$version_name_1 = $version;
|
||||
} elseif ($count_version == 2) {
|
||||
$version_2 = $version['count'];
|
||||
$version_name_2 = $version['version'];
|
||||
$version_2 = $count['count'];
|
||||
$version_name_2 = $version;
|
||||
} elseif ($count_version == 3) {
|
||||
$version_3 = $version['count'];
|
||||
$version_name_3 = $version['version'];
|
||||
$version_3 = $count['count'];
|
||||
$version_name_3 = $version;
|
||||
} elseif ($count_version == 4) {
|
||||
$version_4 = $version['count'];
|
||||
$version_name_4 = $version['version'];
|
||||
$version_4 = $count['count'];
|
||||
$version_name_4 = $version;
|
||||
} elseif ($count_version == 5) {
|
||||
$version_5 = $version['count'];
|
||||
$version_name_5 = $version['version'];
|
||||
$version_5 = $count['count'];
|
||||
$version_name_5 = $version;
|
||||
}
|
||||
$sum_count = $sum_count + $version['count'];
|
||||
$allinsertversion = $allinsertversion . "('" . $version['version'] . "', " . $version['count'] . "),";
|
||||
$sum_count = $sum_count + $count['count'];
|
||||
$allinsertversion = $allinsertversion . "('" . $version . "', " . $count['count'] . "),";
|
||||
}
|
||||
$allinsertversion = substr($allinsertversion, 0, -1);
|
||||
$version_other = $sum_count - $version_1 - $version_2 - $version_3 - $version_4 - $version_5;
|
||||
|
||||
$total_user = count($sqlhis);
|
||||
$server_used_slots = $serverinfo['virtualserver_clientsonline'] - $serverinfo['virtualserver_queryclientsonline'];
|
||||
$server_free_slots = $serverinfo['virtualserver_maxclients'] - $server_used_slots;
|
||||
$server_channel_amount = $serverinfo['virtualserver_channelsonline'];
|
||||
@@ -225,114 +185,124 @@ function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serv
|
||||
$server_weblist = $serverinfo['virtualserver_weblist_enabled'];
|
||||
$server_version = $serverinfo['virtualserver_version'];
|
||||
|
||||
if($mysqlcon->exec("UPDATE $dbname.stats_server SET total_user='$total_user', total_online_time='$total_online_time', total_online_month='$total_online_month', total_online_week='$total_online_week', total_active_time='$total_active_time', total_inactive_time='$total_inactive_time', country_nation_name_1='$country_nation_name_1', country_nation_name_2='$country_nation_name_2', country_nation_name_3='$country_nation_name_3', country_nation_name_4='$country_nation_name_4', country_nation_name_5='$country_nation_name_5', country_nation_1='$country_nation_1', country_nation_2='$country_nation_2', country_nation_3='$country_nation_3', country_nation_4='$country_nation_4', country_nation_5='$country_nation_5', country_nation_other='$country_nation_other', platform_1='$platform_1', platform_2='$platform_2', platform_3='$platform_3', platform_4='$platform_4', platform_5='$platform_5', platform_other='$platform_other', version_name_1='$version_name_1', version_name_2='$version_name_2', version_name_3='$version_name_3', version_name_4='$version_name_4', version_name_5='$version_name_5', version_1='$version_1', version_2='$version_2', version_3='$version_3', version_4='$version_4', version_5='$version_5', version_other='$version_other', version_name_1='$version_name_1', server_status='$server_status', server_free_slots='$server_free_slots', server_used_slots='$server_used_slots', server_channel_amount='$server_channel_amount', server_ping='$server_ping', server_packet_loss='$server_packet_loss', server_bytes_down='$server_bytes_down', server_bytes_up='$server_bytes_up', server_uptime='$server_uptime', server_id='$server_id', server_name=$server_name, server_pass='$server_pass', server_creation_date='$server_creation_date', server_platform='$server_platform', server_weblist='$server_weblist', server_version='$server_version', user_today='$user_today', user_week='$user_week', user_month='$user_month', user_quarter='$user_quarter'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 8:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
// Write stats/index and Nations, Platforms & Versions
|
||||
$sqlexec .= "DELETE FROM $dbname.stats_nations; DELETE FROM $dbname.stats_platforms; DELETE FROM $dbname.stats_versions; UPDATE $dbname.stats_server SET total_user='$total_user', total_online_time='$total_online_time', total_active_time='$total_active_time', total_inactive_time='$total_inactive_time', country_nation_name_1='$country_nation_name_1', country_nation_name_2='$country_nation_name_2', country_nation_name_3='$country_nation_name_3', country_nation_name_4='$country_nation_name_4', country_nation_name_5='$country_nation_name_5', country_nation_1='$country_nation_1', country_nation_2='$country_nation_2', country_nation_3='$country_nation_3', country_nation_4='$country_nation_4', country_nation_5='$country_nation_5', country_nation_other='$country_nation_other', platform_1='$platform_1', platform_2='$platform_2', platform_3='$platform_3', platform_4='$platform_4', platform_5='$platform_5', platform_other='$platform_other', version_name_1='$version_name_1', version_name_2='$version_name_2', version_name_3='$version_name_3', version_name_4='$version_name_4', version_name_5='$version_name_5', version_1='$version_1', version_2='$version_2', version_3='$version_3', version_4='$version_4', version_5='$version_5', version_other='$version_other', version_name_1='$version_name_1', server_status='$server_status', server_free_slots='$server_free_slots', server_used_slots='$server_used_slots', server_channel_amount='$server_channel_amount', server_ping='$server_ping', server_packet_loss='$server_packet_loss', server_bytes_down='$server_bytes_down', server_bytes_up='$server_bytes_up', server_uptime='$server_uptime', server_id='$server_id', server_name=$server_name, server_pass='$server_pass', server_creation_date='$server_creation_date', server_platform='$server_platform', server_weblist='$server_weblist', server_version='$server_version', user_today='$user_today', user_week='$user_week', user_month='$user_month', user_quarter='$user_quarter'; INSERT INTO $dbname.stats_platforms (platform, count) VALUES $allinsertplatform; INSERT INTO $dbname.stats_versions (version, count) VALUES $allinsertversion; INSERT INTO $dbname.stats_nations (nation, count) VALUES $allinsertnation; ";
|
||||
unset($allinsertnation, $allinsertplatform, $allinsertversion);
|
||||
|
||||
// Write Nations
|
||||
if ($allinsertnation != '') {
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.stats_nations") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 9:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.stats_nations (nation, count) VALUES $allinsertnation") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 10:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write Platforms
|
||||
if ($allinsertplatform != '') {
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.stats_platforms") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 9:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.stats_platforms (platform, count) VALUES $allinsertplatform") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 10:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write Versions
|
||||
if ($allinsertversion != '') {
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.stats_versions") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 9:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.stats_versions (version, count) VALUES $allinsertversion") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 10:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stats for Server Usage
|
||||
if(($max_entry_serverusage = $mysqlcon->query("SELECT MAX(timestamp) AS timestamp FROM $dbname.server_usage")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 11:".print_r($mysqlcon->errorInfo(), true));
|
||||
$sqlerr++;
|
||||
}
|
||||
$max_entry_serverusage = $max_entry_serverusage->fetch(PDO::FETCH_ASSOC);
|
||||
$diff_max_serverusage = $nowtime - $max_entry_serverusage['timestamp'];
|
||||
if ($max_entry_serverusage['timestamp'] == 0 || $diff_max_serverusage > 898) { // every 15 mins
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.server_usage (timestamp, clients, channel) VALUES ($nowtime,$server_used_slots,$server_channel_amount)") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 12:".print_r($mysqlcon->errorInfo(), true));
|
||||
if(key($select_arr['max_timestamp_server_usage']) == 0 || ($nowtime - key($select_arr['max_timestamp_server_usage'])) > 898) { // every 15 mins
|
||||
//Calc time next rankup
|
||||
$upnextuptime = $nowtime - 1800;
|
||||
if(($uuidsoff = $mysqlcon->query("SELECT uuid,idle,count FROM $dbname.user WHERE online<>1 AND lastseen>$upnextuptime")->fetchAll(PDO::FETCH_ASSOC)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 13:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
|
||||
//Calc time next rankup
|
||||
$upnextuptime = $nowtime - 86400;
|
||||
if(($uuidsoff = $mysqlcon->query("SELECT uuid,idle,count FROM $dbname.user WHERE online<>1 AND lastseen>$upnextuptime")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 13:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
if ($uuidsoff->rowCount() != 0) {
|
||||
$uuidsoff = $uuidsoff->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach($uuidsoff as $uuid) {
|
||||
$idle = $uuid['idle'];
|
||||
$count = $uuid['count'];
|
||||
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;
|
||||
if(count($uuidsoff) != 0) {
|
||||
foreach($uuidsoff as $uuid) {
|
||||
$count = $uuid['count'];
|
||||
if ($substridle == 1) {
|
||||
$activetime = $count - $uuid['idle'];
|
||||
$dtF = new DateTime("@0");
|
||||
$dtT = new DateTime("@$activetime");
|
||||
} else {
|
||||
$nextup = $time - $activetime;
|
||||
$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
|
||||
);
|
||||
}
|
||||
$updatenextup[] = array(
|
||||
"uuid" => $uuid['uuid'],
|
||||
"nextup" => $nextup
|
||||
);
|
||||
unset($uuidsoff);
|
||||
}
|
||||
|
||||
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);
|
||||
$sqlexec .= "INSERT INTO $dbname.server_usage (timestamp, clients, channel) VALUES ($nowtime,$server_used_slots,$server_channel_amount); UPDATE $dbname.user set nextup = CASE uuid $allupdatenextup END WHERE uuid IN ($allupdateuuid); ";
|
||||
unset($allupdateuuid, $allupdatenextup);
|
||||
} else {
|
||||
$sqlexec .= "INSERT INTO $dbname.server_usage (timestamp, clients, channel) VALUES ($nowtime,$server_used_slots,$server_channel_amount); ";
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 14:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
|
||||
//Calc Rank
|
||||
if($mysqlcon->exec("SET @a:=0") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 15:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
if ($substridle == 1) {
|
||||
if($mysqlcon->exec("UPDATE $dbname.user u INNER JOIN (SELECT @a:=@a+1 nr,uuid FROM $dbname.user WHERE except IN ('0','1') ORDER BY (count - idle) DESC) s USING (uuid) SET u.rank=s.nr") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 16".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "SET @a:=0; UPDATE $dbname.user u INNER JOIN (SELECT @a:=@a+1 nr,uuid FROM $dbname.user WHERE except<2 ORDER BY (count - idle) DESC) s USING (uuid) SET u.rank=s.nr; ";
|
||||
} else {
|
||||
if($mysqlcon->exec("UPDATE $dbname.user u INNER JOIN (SELECT @a:=@a+1 nr,uuid FROM $dbname.user WHERE except IN ('0','1') ORDER BY count DESC) s USING (uuid) SET u.rank=s.nr") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 17:".print_r($mysqlcon->errorInfo(), true));
|
||||
$sqlexec .= "SET @a:=0; UPDATE $dbname.user u INNER JOIN (SELECT @a:=@a+1 nr,uuid FROM $dbname.user WHERE except<2 ORDER BY count DESC) s USING (uuid) SET u.rank=s.nr; ";
|
||||
}
|
||||
|
||||
// Calc Values for server stats
|
||||
if($select_arr['job_check']['calc_server_stats']['timestamp'] < ($nowtime-900)) {
|
||||
if(($entry_snapshot_count = $mysqlcon->query("SELECT count(DISTINCT(timestamp)) AS timestamp FROM $dbname.user_snapshot")->fetch(PDO::FETCH_ASSOC)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 19:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
if ($entry_snapshot_count['timestamp'] > 27) {
|
||||
// Calc total_online_week
|
||||
if(($snapshot_count_week = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp) AND uuid IN (SELECT uuid FROM $dbname.user)) AS count")->fetch(PDO::FETCH_ASSOC)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 20:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$total_online_week = $snapshot_count_week['count'];
|
||||
} else {
|
||||
$total_online_week = 0;
|
||||
}
|
||||
if ($entry_snapshot_count['timestamp'] > 119) {
|
||||
// Calc total_online_month
|
||||
if(($snapshot_count_month = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp) AND uuid IN (SELECT uuid FROM $dbname.user)) AS count")->fetch(PDO::FETCH_ASSOC)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_serverstats 21:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$total_online_month = $snapshot_count_month['count'];
|
||||
} else {
|
||||
$total_online_month = 0;
|
||||
}
|
||||
$sqlexec .= "UPDATE $dbname.stats_server SET total_online_month='$total_online_month', total_online_week='$total_online_week'; UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='calc_server_stats'; ";
|
||||
|
||||
if ($select_arr['job_check']['get_version']['timestamp'] < ($nowtime - 43200)) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://ts-n.net/ranksystem/'.$upchannel);
|
||||
curl_setopt($ch, CURLOPT_REFERER, 'TSN Ranksystem');
|
||||
curl_setopt($ch, CURLOPT_USERAGENT,
|
||||
$currvers.";".
|
||||
php_uname("s").";".
|
||||
php_uname("r").";".
|
||||
phpversion().";".
|
||||
$dbtype.";".
|
||||
$ts['host'].";".
|
||||
$ts['voice'].";".
|
||||
$_SERVER['PWD'].";".
|
||||
$total_user.";".
|
||||
$user_today.";".
|
||||
$user_week.";".
|
||||
$user_month.";".
|
||||
$user_quarter.";".
|
||||
$total_online_week.";".
|
||||
$total_online_month.";".
|
||||
$total_active_time.";".
|
||||
$total_inactive_time
|
||||
);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
$newversion = curl_exec($ch);curl_close($ch);
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='get_version'; UPDATE $dbname.config SET newversion='$newversion'; ";
|
||||
}
|
||||
}
|
||||
return($sqlexec);
|
||||
}
|
||||
?>
|
||||
@@ -1,197 +1,122 @@
|
||||
<?PHP
|
||||
function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid,$ts,$resetexcept,$upchannel,$phpcommand) {
|
||||
function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients,$logpath,$rankupmsg,$ignoreidle,$exceptcid,$resetexcept,$phpcommand,$select_arr) {
|
||||
$nowtime = time();
|
||||
$sqlexec = '';
|
||||
|
||||
if(($getversion = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='get_version'")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user -3:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
$getversion = $getversion->fetchAll();
|
||||
$updatetime = $nowtime - 43200;
|
||||
if ($getversion[0]['timestamp'] < $updatetime) {
|
||||
$newversion=get_data('https://ts-n.net/ranksystem/'.$upchannel,$currvers,$ts);
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='get_version'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user -2:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
if($mysqlcon->exec("UPDATE $dbname.config SET newversion='$newversion'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user -1:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$updatetime = $nowtime - $updateinfotime;
|
||||
if(($lastupdate = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_update'")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 0:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$lastupdate = $lastupdate->fetchAll();
|
||||
if ($lastupdate[0]['timestamp'] < $updatetime) {
|
||||
if(($getversion = $mysqlcon->query("SELECT newversion FROM $dbname.config")) === false) {
|
||||
if ($select_arr['job_check']['check_update']['timestamp'] < ($nowtime - $updateinfotime)) {
|
||||
if(($getversion = $mysqlcon->query("SELECT newversion FROM $dbname.config")->fetch()) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 1:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$getversion = $getversion->fetch(PDO::FETCH_ASSOC);
|
||||
$newversion = $getversion['newversion'];
|
||||
if(version_compare($newversion, $currvers, '>') && $newversion != NULL) {
|
||||
if ($update == 1) {
|
||||
enter_logfile($logpath,$timezone,4,$lang['upinf']);
|
||||
foreach ($uniqueid as $clientid) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
try {
|
||||
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upmsg'], $currvers, $newversion));
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['upusrinf'], $clientid));
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp=$nowtime WHERE job_name='check_update'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 3:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
if(version_compare($getversion['newversion'], $currvers, '>') && $getversion['newversion'] != NULL) {
|
||||
if ($update == 1) {
|
||||
enter_logfile($logpath,$timezone,4,$lang['upinf']);
|
||||
foreach ($uniqueid as $clientid) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
try {
|
||||
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upmsg'], $currvers, $getversion['newversion']));
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['upusrinf'], $clientid));
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp=$nowtime WHERE job_name='check_update'; ";
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,6," ".sprintf($lang['upusrerr'], $clientid));
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
//enter_logfile($logpath,$timezone,4," ".sprintf($lang['upusrerr'], $clientid));
|
||||
}
|
||||
}
|
||||
update_rs($mysqlcon,$lang,$dbname,$logpath,$timezone,$getversion['newversion'],$phpcommand);
|
||||
}
|
||||
update_rs($mysqlcon,$lang,$dbname,$logpath,$timezone,$newversion,$phpcommand);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(($dbdata = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='calc_user_lastscan'")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 4:".print_r($mysqlcon->errorInfo(), true));
|
||||
exit;
|
||||
}
|
||||
$lastscanarr = $dbdata->fetchAll();
|
||||
$lastscan = $lastscanarr[0]['timestamp'];
|
||||
if($lastscan < ($nowtime - 1800)) {
|
||||
enter_logfile($logpath,$timezone,4,"Much time gone since last scan.. reset time difference to zero.");
|
||||
$lastscan = $nowtime;
|
||||
} elseif($lastscan > $nowtime) {
|
||||
enter_logfile($logpath,$timezone,4,"Negative time between now and last scan (Error in your server time!).. reset time difference to zero.");
|
||||
$lastscan = $nowtime;
|
||||
}
|
||||
$uidarr = array();
|
||||
if ($dbdata->rowCount() != NULL) {
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='calc_user_lastscan'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 5:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
if(($dbuserdata = $mysqlcon->query("SELECT uuid,cldbid,count,grpid,nextup,idle,boosttime,grpsince,except FROM $dbname.user")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 6:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$uuids = $dbuserdata->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach($uuids as $uuid) {
|
||||
$sqlhis[$uuid['uuid']] = array(
|
||||
"uuid" => $uuid['uuid'],
|
||||
"cldbid" => $uuid['cldbid'],
|
||||
"count" => $uuid['count'],
|
||||
"grpid" => $uuid['grpid'],
|
||||
"nextup" => $uuid['nextup'],
|
||||
"idle" => $uuid['idle'],
|
||||
"boosttime" => $uuid['boosttime'],
|
||||
"grpsince" => $uuid['grpsince'],
|
||||
"except" => $uuid['except']
|
||||
);
|
||||
$uidarr[] = $uuid['uuid'];
|
||||
}
|
||||
}
|
||||
unset($uuids);
|
||||
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
$yetonline = array();
|
||||
$insertdata = array();
|
||||
$updatedata = array();
|
||||
if(empty($grouptime)) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 7:".$lang['wiconferr']);
|
||||
enter_logfile($logpath,$timezone,1,"calc_user:".$lang['wiconferr']."Shuttin down!\n\n");
|
||||
exit;
|
||||
}
|
||||
krsort($grouptime);
|
||||
$sumentries = 0;
|
||||
$nextupforinsert = key($grouptime) - 1;
|
||||
|
||||
if(!isset($dbgroups)) {
|
||||
if(($dbgroups = $mysqlcon->query("SELECT sgid,sgidname FROM $dbname.groups")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 8.1:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
$dbgroups = $dbgroups->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
if($select_arr['job_check']['calc_user_lastscan']['timestamp'] < ($nowtime - 1800)) {
|
||||
enter_logfile($logpath,$timezone,4,"Much time gone since last scan.. reset time difference to zero.");
|
||||
$select_arr['job_check']['calc_user_lastscan']['timestamp'] = $nowtime;
|
||||
} elseif($select_arr['job_check']['calc_user_lastscan']['timestamp'] > $nowtime) {
|
||||
enter_logfile($logpath,$timezone,4,"Negative time between now and last scan (Error in your server time!).. reset time difference to zero.");
|
||||
$select_arr['job_check']['calc_user_lastscan']['timestamp'] = $nowtime;
|
||||
}
|
||||
|
||||
print_r($dbgroups);
|
||||
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='calc_user_lastscan'; ";
|
||||
|
||||
krsort($grouptime);
|
||||
$yetonline = array();
|
||||
$insertdata = array();
|
||||
$updatedata = array();
|
||||
|
||||
foreach ($allclients as $client) {
|
||||
$sumentries++;
|
||||
$cldbid = $client['client_database_id'];
|
||||
$name = $mysqlcon->quote($client['client_nickname'], ENT_QUOTES);
|
||||
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
|
||||
$cldgroup = $client['client_servergroups'];
|
||||
$sgroups = explode(",", $cldgroup);
|
||||
$platform = $client['client_platform'];
|
||||
$nation = $client['client_country'];
|
||||
$version = $client['client_version'];
|
||||
$firstconnect = $client['client_created'];
|
||||
$channel = $client['cid'];
|
||||
if (!in_array($uid, $yetonline) && $client['client_version'] != "ServerQuery") {
|
||||
$sgroups = array_flip(explode(",", $client['client_servergroups']));
|
||||
if (!isset($yetonline[$uid]) && $client['client_version'] != "ServerQuery") {
|
||||
if(strstr($client['connection_client_ip'], '[')) {
|
||||
$ip = $mysqlcon->quote(inet_pton(str_replace(array('[',']'),'',$client['connection_client_ip'])), ENT_QUOTES);
|
||||
} else {
|
||||
$ip = $mysqlcon->quote(inet_pton($client['connection_client_ip']), ENT_QUOTES);
|
||||
}
|
||||
$clientidle = floor($client['client_idle_time'] / 1000);
|
||||
$clientidle = floor($client['client_idle_time'] / 1000);
|
||||
if(isset($ignoreidle) && $clientidle < $ignoreidle) {
|
||||
$clientidle = 0;
|
||||
}
|
||||
$yetonline[] = $uid;
|
||||
if(in_array($uid, $exceptuuid)) {
|
||||
$yetonline[$uid] = 0;
|
||||
if(isset($exceptuuid[$uid])) {
|
||||
$except = 3;
|
||||
} elseif(array_intersect($sgroups, $exceptgroup)) {
|
||||
} elseif(array_intersect_key($sgroups, $exceptgroup)) {
|
||||
$except = 2;
|
||||
} else {
|
||||
if(isset($sqlhis[$uid]['except']) && ($sqlhis[$uid]['except'] == 3 || $sqlhis[$uid]['except'] == 2) && $resetexcept == 2) {
|
||||
$sqlhis[$uid]['count'] = 0;
|
||||
$sqlhis[$uid]['idle'] = 0;
|
||||
if(isset($select_arr['all_user'][$uid]['except']) && ($select_arr['all_user'][$uid]['except'] == 3 || $select_arr['all_user'][$uid]['except'] == 2) && $resetexcept == 2) {
|
||||
$select_arr['all_user'][$uid]['count'] = 0;
|
||||
$select_arr['all_user'][$uid]['idle'] = 0;
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['resettime'], $name, $uid, $cldbid));
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.user_snapshot WHERE uuid='$uid'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 5:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "DELETE FROM $dbname.user_snapshot WHERE uuid='$uid'; ";
|
||||
}
|
||||
$except = 0;
|
||||
}
|
||||
if (in_array($uid, $uidarr)) {
|
||||
$idle = $sqlhis[$uid]['idle'] + $clientidle;
|
||||
$grpid = $sqlhis[$uid]['grpid'];
|
||||
$nextup = $sqlhis[$uid]['nextup'];
|
||||
$grpsince = $sqlhis[$uid]['grpsince'];
|
||||
if ($sqlhis[$uid]['cldbid'] != $cldbid && $resetbydbchange == 1) {
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['changedbid'], $name, $uid, $cldbid, $sqlhis[$uid]['cldbid']));
|
||||
if(isset($select_arr['all_user'][$uid])) {
|
||||
$idle = $select_arr['all_user'][$uid]['idle'] + $clientidle;
|
||||
$grpid = $select_arr['all_user'][$uid]['grpid'];
|
||||
$nextup = $select_arr['all_user'][$uid]['nextup'];
|
||||
$grpsince = $select_arr['all_user'][$uid]['grpsince'];
|
||||
if ($select_arr['all_user'][$uid]['cldbid'] != $cldbid && $resetbydbchange == 1) {
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['changedbid'], $name, $uid, $cldbid, $select_arr['all_user'][$uid]['cldbid']));
|
||||
$count = 1;
|
||||
$idle = 0;
|
||||
} else {
|
||||
$hitboost = 0;
|
||||
$boosttime = $sqlhis[$uid]['boosttime'];
|
||||
$boosttime = $select_arr['all_user'][$uid]['boosttime'];
|
||||
if($boostarr!=0) {
|
||||
foreach($boostarr as $boost) {
|
||||
if(in_array($boost['group'], $sgroups)) {
|
||||
if(isset($sgroups[$boost['group']])) {
|
||||
$hitboost = 1;
|
||||
if($sqlhis[$uid]['boosttime']==0) {
|
||||
if($select_arr['all_user'][$uid]['boosttime']==0) {
|
||||
$boosttime = $nowtime;
|
||||
} else {
|
||||
if ($nowtime > $sqlhis[$uid]['boosttime'] + $boost['time']) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
if ($nowtime > $select_arr['all_user'][$uid]['boosttime'] + $boost['time']) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$ts3->serverGroupClientDel($boost['group'], $cldbid);
|
||||
$boosttime = 0;
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['sgrprm'], $dbgroups[$sqlhis[$uid]['grpid']]['sgidname'], $sqlhis[$uid]['grpid'], $name, $uid, $cldbid));
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['sgrprm'], $select_arr['groups'][$select_arr['all_user'][$uid]['grpid']]['sgidname'], $select_arr['all_user'][$uid]['grpid'], $name, $uid, $cldbid));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 8:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
|
||||
enter_logfile($logpath,$timezone,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $cldbid, $select_arr['groups'][$select_arr['all_user'][$uid]['grpid']]['sgidname'], $select_arr['all_user'][$uid]['grpid']));
|
||||
}
|
||||
}
|
||||
}
|
||||
$count = ($nowtime - $lastscan) * $boost['factor'] + $sqlhis[$uid]['count'];
|
||||
if ($clientidle > ($nowtime - $lastscan)) {
|
||||
$idle = ($nowtime - $lastscan) * $boost['factor'] + $sqlhis[$uid]['idle'];
|
||||
$count = ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp']) * $boost['factor'] + $select_arr['all_user'][$uid]['count'];
|
||||
if ($clientidle > ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'])) {
|
||||
$idle = ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp']) * $boost['factor'] + $select_arr['all_user'][$uid]['idle'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($boostarr == 0 or $hitboost == 0) {
|
||||
$count = $nowtime - $lastscan + $sqlhis[$uid]['count'];
|
||||
if ($clientidle > ($nowtime - $lastscan)) {
|
||||
$idle = $nowtime - $lastscan + $sqlhis[$uid]['idle'];
|
||||
$count = $nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'] + $select_arr['all_user'][$uid]['count'];
|
||||
if ($clientidle > ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'])) {
|
||||
$idle = $nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'] + $select_arr['all_user'][$uid]['idle'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +128,7 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$gro
|
||||
}
|
||||
$dtT = new DateTime("@$activetime");
|
||||
foreach ($grouptime as $time => $groupid) {
|
||||
if (in_array($groupid, $sgroups)) {
|
||||
if (isset($sgroups[$groupid])) {
|
||||
$grpid = $groupid;
|
||||
break;
|
||||
}
|
||||
@@ -211,46 +136,46 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$gro
|
||||
$grpcount=0;
|
||||
foreach ($grouptime as $time => $groupid) {
|
||||
$grpcount++;
|
||||
if(in_array($channel, $exceptcid) || (($sqlhis[$uid]['except'] == 3 || $sqlhis[$uid]['except'] == 2) && $resetexcept == 1)) {
|
||||
$count = $sqlhis[$uid]['count'];
|
||||
$idle = $sqlhis[$uid]['idle'];
|
||||
if(isset($exceptcid[$client['cid']]) || (($select_arr['all_user'][$uid]['except'] == 3 || $select_arr['all_user'][$uid]['except'] == 2) && $resetexcept == 1)) {
|
||||
$count = $select_arr['all_user'][$uid]['count'];
|
||||
$idle = $select_arr['all_user'][$uid]['idle'];
|
||||
if($except != 2 && $except != 3) {
|
||||
$except = 1;
|
||||
}
|
||||
} elseif ($activetime > $time && !in_array($uid, $exceptuuid) && !array_intersect($sgroups, $exceptgroup)) {
|
||||
if ($sqlhis[$uid]['grpid'] != $groupid) {
|
||||
if ($sqlhis[$uid]['grpid'] != NULL && in_array($sqlhis[$uid]['grpid'], $sgroups)) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
} elseif ($activetime > $time && !isset($exceptuuid[$uid]) && !array_intersect_key($sgroups, $exceptgroup)) {
|
||||
if ($select_arr['all_user'][$uid]['grpid'] != $groupid) {
|
||||
if ($select_arr['all_user'][$uid]['grpid'] != NULL && isset($sgroups[$select_arr['all_user'][$uid]['grpid']])) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$ts3->serverGroupClientDel($sqlhis[$uid]['grpid'], $cldbid);
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['sgrprm'], $dbgroups[$sqlhis[$uid]['grpid']]['sgidname'], $sqlhis[$uid]['grpid'], $name, $uid, $cldbid));
|
||||
$ts3->serverGroupClientDel($select_arr['all_user'][$uid]['grpid'], $cldbid);
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['sgrprm'], $select_arr['groups'][$select_arr['all_user'][$uid]['grpid']]['sgidname'], $select_arr['all_user'][$uid]['grpid'], $name, $uid, $cldbid));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 9:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
|
||||
enter_logfile($logpath,$timezone,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $cldbid, $select_arr['groups'][$groupid]['sgidname'], $groupid));
|
||||
}
|
||||
}
|
||||
if (!in_array($groupid, $sgroups)) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
if (!isset($sgroups[$groupid])) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$ts3->serverGroupClientAdd($groupid, $cldbid);
|
||||
$grpsince = $nowtime;
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['sgrpadd'], $dbgroups[$groupid]['sgidname'], $groupid, $name, $uid, $cldbid));
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['sgrpadd'], $select_arr['groups'][$groupid]['sgidname'], $groupid, $name, $uid, $cldbid));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 10:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
|
||||
enter_logfile($logpath,$timezone,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $cldbid, $select_arr['groups'][$groupid]['sgidname'], $groupid));
|
||||
}
|
||||
}
|
||||
$grpid = $groupid;
|
||||
if ($msgtouser == 1) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
usleep($slowmode);
|
||||
$days = $dtF->diff($dtT)->format('%a');
|
||||
$hours = $dtF->diff($dtT)->format('%h');
|
||||
$mins = $dtF->diff($dtT)->format('%i');
|
||||
$secs = $dtF->diff($dtT)->format('%s');
|
||||
try {
|
||||
$ts3->clientGetByUid($uid)->message(sprintf($rankupmsg, $days, $hours, $mins, $secs, $dbgroups[$groupid]['sgidname'], $client['client_nickname']));
|
||||
$ts3->clientGetByUid($uid)->message(sprintf($rankupmsg, $days, $hours, $mins, $secs, $select_arr['groups'][$groupid]['sgidname'], $client['client_nickname']));
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 12:".sprintf($lang['sgrprerr'], $name, $uid, $cldbid));
|
||||
enter_logfile($logpath,$timezone,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $cldbid, $select_arr['groups'][$groupid]['sgidname'], $groupid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,18 +197,19 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$gro
|
||||
"grpid" => $grpid,
|
||||
"nextup" => $nextup,
|
||||
"idle" => $idle,
|
||||
"cldgroup" => $cldgroup,
|
||||
"cldgroup" => $client['client_servergroups'],
|
||||
"boosttime" => $boosttime,
|
||||
"platform" => $platform,
|
||||
"nation" => $nation,
|
||||
"version" => $version,
|
||||
"platform" => $client['client_platform'],
|
||||
"nation" => $client['client_country'],
|
||||
"version" => $client['client_version'],
|
||||
"except" => $except,
|
||||
"grpsince" => $grpsince
|
||||
"grpsince" => $grpsince,
|
||||
"cid" => $client['cid']
|
||||
);
|
||||
} else {
|
||||
$grpid = '0';
|
||||
foreach ($grouptime as $time => $groupid) {
|
||||
if (in_array($groupid, $sgroups)) {
|
||||
if (isset($sgroups[$groupid])) {
|
||||
$grpid = $groupid;
|
||||
break;
|
||||
}
|
||||
@@ -295,23 +221,19 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$gro
|
||||
"name" => $name,
|
||||
"lastseen" => $nowtime,
|
||||
"grpid" => $grpid,
|
||||
"nextup" => $nextupforinsert,
|
||||
"cldgroup" => $cldgroup,
|
||||
"platform" => $platform,
|
||||
"nation" => $nation,
|
||||
"version" => $version,
|
||||
"firstcon" => $firstconnect,
|
||||
"nextup" => (key($grouptime) - 1),
|
||||
"cldgroup" => $client['client_servergroups'],
|
||||
"platform" => $client['client_platform'],
|
||||
"nation" => $client['client_country'],
|
||||
"version" => $client['client_version'],
|
||||
"firstcon" => $client['client_created'],
|
||||
"except" => $except
|
||||
);
|
||||
$uidarr[] = $uid;
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['adduser'], $name, $uid, $cldbid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($mysqlcon->exec("UPDATE $dbname.user SET online='0'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 13:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
unset($yetonline);
|
||||
|
||||
if ($insertdata != NULL) {
|
||||
$allinsertdata = '';
|
||||
@@ -320,31 +242,13 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$gro
|
||||
}
|
||||
$allinsertdata = substr($allinsertdata, 0, -1);
|
||||
if ($allinsertdata != NULL) {
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.user (uuid, cldbid, count, ip, name, lastseen, grpid, nextup, cldgroup, platform, nation, version, firstcon, except, online) VALUES $allinsertdata") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 14:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "INSERT INTO $dbname.user (uuid, cldbid, count, ip, name, lastseen, grpid, nextup, cldgroup, platform, nation, version, firstcon, except, online) VALUES $allinsertdata; ";
|
||||
}
|
||||
unset($insertdata, $allinsertdata);
|
||||
}
|
||||
|
||||
unset($insertdata);
|
||||
unset($allinsertdata);
|
||||
if ($updatedata != NULL) {
|
||||
$allupdateuuid = '';
|
||||
$allupdatecldbid = '';
|
||||
$allupdatecount = '';
|
||||
$allupdateip = '';
|
||||
$allupdatename = '';
|
||||
$allupdatelastseen = '';
|
||||
$allupdategrpid = '';
|
||||
$allupdatenextup = '';
|
||||
$allupdateidle = '';
|
||||
$allupdatecldgroup = '';
|
||||
$allupdateboosttime = '';
|
||||
$allupdateplatform = '';
|
||||
$allupdatenation = '';
|
||||
$allupdateversion = '';
|
||||
$allupdateexcept = '';
|
||||
$allupdategrpsince = '';
|
||||
$allupdateuuid = $allupdatecldbid = $allupdatecount = $allupdateip = $allupdatename = $allupdatelastseen = $allupdategrpid = $allupdatenextup = $allupdateidle = $allupdatecldgroup = $allupdateboosttime = $allupdateplatform = $allupdatenation = $allupdateversion = $allupdateexcept = $allupdategrpsince = $allupdatecid = '';
|
||||
foreach ($updatedata as $updatearr) {
|
||||
$allupdateuuid = $allupdateuuid . $updatearr['uuid'] . ",";
|
||||
$allupdatecldbid = $allupdatecldbid . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['cldbid'] . "' ";
|
||||
@@ -362,11 +266,12 @@ function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$update,$gro
|
||||
$allupdateversion = $allupdateversion . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['version'] . "' ";
|
||||
$allupdateexcept = $allupdateexcept . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['except'] . "' ";
|
||||
$allupdategrpsince = $allupdategrpsince . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['grpsince'] . "' ";
|
||||
$allupdatecid = $allupdatecid . "WHEN " . $updatearr['uuid'] . " THEN '" . $updatearr['cid'] . "' ";
|
||||
}
|
||||
$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, boosttime = CASE uuid $allupdateboosttime END, platform = CASE uuid $allupdateplatform END, nation = CASE uuid $allupdatenation END, version = CASE uuid $allupdateversion END, except = CASE uuid $allupdateexcept END, grpsince = CASE uuid $allupdategrpsince END, online = 1 WHERE uuid IN ($allupdateuuid)") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_user 15:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "UPDATE $dbname.user SET online='0'; 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, boosttime = CASE uuid $allupdateboosttime END, platform = CASE uuid $allupdateplatform END, nation = CASE uuid $allupdatenation END, version = CASE uuid $allupdateversion END, except = CASE uuid $allupdateexcept END, grpsince = CASE uuid $allupdategrpsince END, cid = CASE uuid $allupdatecid END, online = 1 WHERE uuid IN ($allupdateuuid); ";
|
||||
unset($updatedata, $allupdateuuid, $allupdatecldbid, $allupdatecount, $allupdateip, $allupdatename, $allupdatelastseen, $allupdategrpid, $allupdatenextup, $allupdateidle, $allupdatecldgroup, $allupdateboosttime, $allupdateplatform, $allupdatenation, $allupdateversion, $allupdateexcept, $allupdategrpsince, $allupdatecid);
|
||||
}
|
||||
return($sqlexec);
|
||||
}
|
||||
?>
|
||||
@@ -1,18 +1,9 @@
|
||||
<?PHP
|
||||
function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath) {
|
||||
function calc_userstats($ts3,$mysqlcon,$dbname,$slowmode,$timezone,$logpath,$select_arr) {
|
||||
$sqlexec = '';
|
||||
|
||||
if(($count_user = $mysqlcon->query("SELECT count(*) as count FROM ((SELECT u.uuid FROM $dbname.user AS u INNER JOIN $dbname.stats_user As s On u.uuid=s.uuid) UNION (SELECT u.uuid FROM $dbname.user AS u LEFT JOIN $dbname.stats_user As s On u.uuid=s.uuid WHERE s.uuid IS NULL)) x")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 1:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$count_user = $count_user->fetchAll(PDO::FETCH_ASSOC);
|
||||
$total_user = $count_user[0]['count'];
|
||||
|
||||
if(($job_begin = $mysqlcon->query("SELECT timestamp FROM $dbname.job_check WHERE job_name='calc_user_limit'")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 2:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$job_begin = $job_begin->fetchAll();
|
||||
$job_begin = $job_begin[0]['timestamp'];
|
||||
$job_end = ceil($total_user / 10) * 10;
|
||||
$job_begin = $select_arr['job_check']['calc_user_limit']['timestamp'];
|
||||
$job_end = ceil(count($select_arr['all_user']) / 10) * 10;
|
||||
if ($job_begin >= $job_end) {
|
||||
$job_begin = 0;
|
||||
$job_end = 10;
|
||||
@@ -20,83 +11,43 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpat
|
||||
$job_end = $job_begin + 10;
|
||||
}
|
||||
|
||||
if(($uuids = $mysqlcon->query("(SELECT u.uuid,u.rank,u.cldbid FROM $dbname.user AS u INNER JOIN $dbname.stats_user As s On u.uuid=s.uuid) UNION (SELECT u.uuid,u.rank,u.cldbid FROM $dbname.user AS u LEFT JOIN $dbname.stats_user As s On u.uuid=s.uuid WHERE s.uuid IS NULL) ORDER BY cldbid ASC LIMIT $job_begin, 10")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 3:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$uuids = $uuids->fetchAll();
|
||||
foreach($uuids as $uuid) {
|
||||
$sqlhis[$uuid['uuid']] = array(
|
||||
"uuid" => $uuid['uuid'],
|
||||
"rank" => $uuid['rank'],
|
||||
"cldbid" => $uuid['cldbid']
|
||||
);
|
||||
}
|
||||
|
||||
// Calc Client Stats
|
||||
if ($mysqlcon->exec("UPDATE $dbname.stats_user AS t LEFT JOIN $dbname.user AS u ON t.uuid=u.uuid SET t.removed='1' WHERE u.uuid IS NULL") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 4:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
if(($statsuserhis = $mysqlcon->query("SELECT uuid, removed FROM $dbname.stats_user")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 5:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$statsuserhis = $statsuserhis->fetchAll();
|
||||
foreach($statsuserhis as $userhis) {
|
||||
$uidarrstats[$userhis['uuid']] = $userhis['removed'];
|
||||
}
|
||||
unset($statsuserhis);
|
||||
$sqlhis = array_slice($select_arr['all_user'],$job_begin ,10);
|
||||
|
||||
if(isset($sqlhis)) {
|
||||
//enter_logfile($logpath,$timezone,6,"Update User Stats between ".$job_begin." and ".$job_end.":");
|
||||
if(($userdataweekbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
|
||||
if(($userdataweekbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 6:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$userdataweekbegin = $userdataweekbegin->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
|
||||
if(($userdataweekend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
|
||||
if(($userdataweekend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 7:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$userdataweekend = $userdataweekend->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
|
||||
if(($userdatamonthbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
|
||||
if(($userdatamonthbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 8:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$userdatamonthbegin = $userdatamonthbegin->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
|
||||
if(($userdatamonthend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
|
||||
|
||||
if(($userdatamonthend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 9:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$userdatamonthend = $userdatamonthend->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
|
||||
|
||||
$allupdateuuid = '';
|
||||
$allupdaterank = '';
|
||||
$allupdatecountw = '';
|
||||
$allupdatecountm = '';
|
||||
$allupdateidlew = '';
|
||||
$allupdateidlem = '';
|
||||
$allupdateactw = '';
|
||||
$allupdateactm = '';
|
||||
$allupdatetotac = '';
|
||||
$allupdatebase64 = '';
|
||||
$allupdatecldtup = '';
|
||||
$allupdatecldtdo = '';
|
||||
$allupdateclddes = '';
|
||||
$allinsertuserstats = '';
|
||||
$allupdateuuid = $allupdaterank = $allupdatecountw = $allupdatecountm = $allupdateidlew = $allupdateidlem = $allupdateactw = $allupdateactm = $allupdatetotac = $allupdatebase64 = $allupdatecldtup = $allupdatecldtdo = $allupdateclddes = $allinsertuserstats = '';
|
||||
|
||||
foreach ($sqlhis as $userstats) {
|
||||
foreach ($sqlhis as $uuid => $userstats) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
try {
|
||||
$clientinfo = $ts3->clientInfoDb($userstats['cldbid']);
|
||||
|
||||
if(isset($userdataweekend[$userstats['uuid']]) && isset($userdataweekbegin[$userstats['uuid']])) {
|
||||
$count_week = $userdataweekend[$userstats['uuid']][0]['count'] - $userdataweekbegin[$userstats['uuid']][0]['count'];
|
||||
$idle_week = $userdataweekend[$userstats['uuid']][0]['idle'] - $userdataweekbegin[$userstats['uuid']][0]['idle'];
|
||||
if(isset($userdataweekend[$uuid]) && isset($userdataweekbegin[$uuid])) {
|
||||
$count_week = $userdataweekend[$uuid]['count'] - $userdataweekbegin[$uuid]['count'];
|
||||
$idle_week = $userdataweekend[$uuid]['idle'] - $userdataweekbegin[$uuid]['idle'];
|
||||
$active_week = $count_week - $idle_week;
|
||||
} else {
|
||||
$count_week = 0;
|
||||
$idle_week = 0;
|
||||
$active_week = 0;
|
||||
}
|
||||
if(isset($userdatamonthend[$userstats['uuid']]) && isset($userdatamonthbegin[$userstats['uuid']])) {
|
||||
$count_month = $userdatamonthend[$userstats['uuid']][0]['count'] - $userdatamonthbegin[$userstats['uuid']][0]['count'];
|
||||
$idle_month = $userdatamonthend[$userstats['uuid']][0]['idle'] - $userdatamonthbegin[$userstats['uuid']][0]['idle'];
|
||||
if(isset($userdatamonthend[$uuid]) && isset($userdatamonthbegin[$uuid])) {
|
||||
$count_month = $userdatamonthend[$uuid]['count'] - $userdatamonthbegin[$uuid]['count'];
|
||||
$idle_month = $userdatamonthend[$uuid]['idle'] - $userdatamonthbegin[$uuid]['idle'];
|
||||
$active_month = $count_month - $idle_month;
|
||||
} else {
|
||||
$count_month = 0;
|
||||
@@ -104,45 +55,41 @@ function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpat
|
||||
$active_month = 0;
|
||||
}
|
||||
$clientdesc = $mysqlcon->quote($clientinfo['client_description'], ENT_QUOTES);;
|
||||
if(isset($uidarrstats[$userstats['uuid']])) {
|
||||
$allupdateuuid = $allupdateuuid . "'" . $userstats['uuid'] . "',";
|
||||
$allupdaterank = $allupdaterank . "WHEN '" . $userstats['uuid'] . "' THEN '" . $userstats['rank'] . "' ";
|
||||
$allupdatecountw = $allupdatecountw . "WHEN '" . $userstats['uuid'] . "' THEN '" . $count_week . "' ";
|
||||
$allupdatecountm = $allupdatecountm . "WHEN '" . $userstats['uuid'] . "' THEN '" . $count_month . "' ";
|
||||
$allupdateidlew = $allupdateidlew . "WHEN '" . $userstats['uuid'] . "' THEN '" . $idle_week . "' ";
|
||||
$allupdateidlem = $allupdateidlem . "WHEN '" . $userstats['uuid'] . "' THEN '" . $idle_month . "' ";
|
||||
$allupdateactw = $allupdateactw . "WHEN '" . $userstats['uuid'] . "' THEN '" . $active_week . "' ";
|
||||
$allupdateactm = $allupdateactm . "WHEN '" . $userstats['uuid'] . "' THEN '" . $active_month . "' ";
|
||||
$allupdatetotac = $allupdatetotac . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_totalconnections'] . "' ";
|
||||
$allupdatebase64 = $allupdatebase64 . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_base64HashClientUID'] . "' ";
|
||||
$allupdatecldtup = $allupdatecldtup . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_total_bytes_uploaded'] . "' ";
|
||||
$allupdatecldtdo = $allupdatecldtdo . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_total_bytes_downloaded'] . "' ";
|
||||
$allupdateclddes = $allupdateclddes . "WHEN '" . $userstats['uuid'] . "' THEN " . $clientdesc . " ";
|
||||
if(isset($select_arr['uuid_stats_user'][$uuid])) {
|
||||
$allupdateuuid = $allupdateuuid . "'" . $uuid . "',";
|
||||
$allupdaterank = $allupdaterank . "WHEN '" . $uuid . "' THEN '" . $userstats['rank'] . "' ";
|
||||
$allupdatecountw = $allupdatecountw . "WHEN '" . $uuid . "' THEN '" . $count_week . "' ";
|
||||
$allupdatecountm = $allupdatecountm . "WHEN '" . $uuid . "' THEN '" . $count_month . "' ";
|
||||
$allupdateidlew = $allupdateidlew . "WHEN '" . $uuid . "' THEN '" . $idle_week . "' ";
|
||||
$allupdateidlem = $allupdateidlem . "WHEN '" . $uuid . "' THEN '" . $idle_month . "' ";
|
||||
$allupdateactw = $allupdateactw . "WHEN '" . $uuid . "' THEN '" . $active_week . "' ";
|
||||
$allupdateactm = $allupdateactm . "WHEN '" . $uuid . "' THEN '" . $active_month . "' ";
|
||||
$allupdatetotac = $allupdatetotac . "WHEN '" . $uuid . "' THEN '" . $clientinfo['client_totalconnections'] . "' ";
|
||||
$allupdatebase64 = $allupdatebase64 . "WHEN '" . $uuid . "' THEN '" . $clientinfo['client_base64HashClientUID'] . "' ";
|
||||
$allupdatecldtup = $allupdatecldtup . "WHEN '" . $uuid . "' THEN '" . $clientinfo['client_total_bytes_uploaded'] . "' ";
|
||||
$allupdatecldtdo = $allupdatecldtdo . "WHEN '" . $uuid . "' THEN '" . $clientinfo['client_total_bytes_downloaded'] . "' ";
|
||||
$allupdateclddes = $allupdateclddes . "WHEN '" . $uuid . "' THEN " . $clientdesc . " ";
|
||||
} else {
|
||||
$allinsertuserstats = $allinsertuserstats . "('" . $userstats['uuid'] . "', '" .$userstats['rank'] . "', '" . $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 . "),";
|
||||
$allinsertuserstats = $allinsertuserstats . "('" . $uuid . "', '" .$userstats['rank'] . "', '" . $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 . "),";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//enter_logfile($logpath,$timezone,6,$e->getCode() . ': ' . $e->getMessage()."; Client (uuid: ".$userstats['cldbid']." cldbid: ".$userstats['cldbid'].") was missing in TS database, perhaps its already deleted".);
|
||||
//enter_logfile($logpath,$timezone,6,$e->getCode() . ': ' . $e->getMessage()."; Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") was missing in TS database, perhaps its already deleted".);
|
||||
}
|
||||
}
|
||||
|
||||
if ($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp=$job_end WHERE job_name='calc_user_limit'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 11:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
unset($sqlhis, $userdataweekbegin, $userdataweekend, $userdatamonthend, $userdatamonthbegin);
|
||||
|
||||
if ($allupdateuuid != '') {
|
||||
$allupdateuuid = substr($allupdateuuid, 0, -1);
|
||||
if ($mysqlcon->exec("UPDATE $dbname.stats_user set rank = CASE uuid $allupdaterank END, count_week = CASE uuid $allupdatecountw END, count_month = CASE uuid $allupdatecountm END, idle_week = CASE uuid $allupdateidlew END, idle_month = CASE uuid $allupdateidlem END, active_week = CASE uuid $allupdateactw END, active_month = CASE uuid $allupdateactm END, total_connections = CASE uuid $allupdatetotac END, base64hash = CASE uuid $allupdatebase64 END, client_total_up = CASE uuid $allupdatecldtup END, client_total_down = CASE uuid $allupdatecldtdo END, client_description = CASE uuid $allupdateclddes END WHERE uuid IN ($allupdateuuid)") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 12:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp=$job_end WHERE job_name='calc_user_limit'; UPDATE $dbname.stats_user set rank = CASE uuid $allupdaterank END, count_week = CASE uuid $allupdatecountw END, count_month = CASE uuid $allupdatecountm END, idle_week = CASE uuid $allupdateidlew END, idle_month = CASE uuid $allupdateidlem END, active_week = CASE uuid $allupdateactw END, active_month = CASE uuid $allupdateactm END, total_connections = CASE uuid $allupdatetotac END, base64hash = CASE uuid $allupdatebase64 END, client_total_up = CASE uuid $allupdatecldtup END, client_total_down = CASE uuid $allupdatecldtdo END, client_description = CASE uuid $allupdateclddes END WHERE uuid IN ($allupdateuuid); ";
|
||||
unset($allupdateuuid, $allupdaterank, $allupdatecountw, $allupdatecountm, $allupdateidlew, $allupdateidlem, $allupdateactw, $allupdateactm, $allupdatetotac, $allupdatebase64, $allupdatecldtup, $allupdatecldtdo, $allupdateclddes);
|
||||
}
|
||||
|
||||
if($allinsertuserstats != '') {
|
||||
$allinsertuserstats = substr($allinsertuserstats, 0, -1);
|
||||
if ($mysqlcon->exec("INSERT INTO $dbname.stats_user (uuid,rank,count_week,count_month,idle_week,idle_month,active_week,active_month,total_connections,base64hash,client_total_up,client_total_down,client_description) VALUES $allinsertuserstats") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"calc_userstats 13:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp=$job_end WHERE job_name='calc_user_limit'; INSERT INTO $dbname.stats_user (uuid,rank,count_week,count_month,idle_week,idle_month,active_week,active_month,total_connections,base64hash,client_total_up,client_total_down,client_description) VALUES $allinsertuserstats; ";
|
||||
unset($allinsertuserstats);
|
||||
}
|
||||
}
|
||||
return($sqlexec);
|
||||
}
|
||||
?>
|
||||
@@ -1,12 +1,12 @@
|
||||
<?PHP
|
||||
function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
|
||||
$newversion = '1.2.3';
|
||||
$newversion = '1.2.4';
|
||||
enter_logfile($logpath,$timezone,5,"Check Ranksystem database for updates.");
|
||||
|
||||
function set_new_version($mysqlcon,$dbname,$timezone,$newversion,$logpath) {
|
||||
if($mysqlcon->exec("UPDATE $dbname.config set currvers='$newversion'") === false) {
|
||||
enter_logfile($logpath,$timezone,1," An error happens due updating the Ranksystem Database:".print_r($mysqlcon->errorInfo(), true));
|
||||
enter_logfile($logpath,$timezone,1," Check the database connection properties in other/dbconfig.php and check also the database permissions.");
|
||||
enter_logfile($logpath,$timezone,1," Check the database connection and properties in other/dbconfig.php and check also the database permissions.");
|
||||
exit;
|
||||
} else {
|
||||
$currvers = $newversion;
|
||||
@@ -31,12 +31,11 @@ function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
|
||||
}
|
||||
|
||||
function check_config($mysqlcon,$dbname) {
|
||||
if(($dbdata = $mysqlcon->query("SELECT * FROM $dbname.config")) === false) { } else {
|
||||
if($dbdata->rowCount() > 1) {
|
||||
if(($dbdata = $mysqlcon->query("SELECT * FROM $dbname.config")->fetchAll()) === false) { } else {
|
||||
if(count($dbdata) > 1) {
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.config WHERE webuser IS NULL") === false) { }
|
||||
}
|
||||
$config = $dbdata->fetchAll();
|
||||
if($config[0]['updateinfotime'] > 86400) {
|
||||
if($dbdata[0]['updateinfotime'] > 86400) {
|
||||
if($mysqlcon->exec("UPDATE $dbname.config SET updateinfotime='86400'") === false) { }
|
||||
}
|
||||
}
|
||||
@@ -446,11 +445,52 @@ function check_db($mysqlcon,$lang,$dbname,$timezone,$currvers,$logpath) {
|
||||
if($mysqlcon->exec("CREATE INDEX snapshot_timestamp ON $dbname.user_snapshot (timestamp)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.3] Recreated index on table user_snapshot successfully.");
|
||||
}
|
||||
|
||||
if($mysqlcon->exec("CREATE INDEX serverusage_timestamp ON $dbname.server_usage (timestamp)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.3] Recreated index on table server_usage successfully.");
|
||||
}
|
||||
}
|
||||
if(version_compare($currvers, '1.2.3', '<=')) {
|
||||
if($mysqlcon->exec("ALTER TABLE $dbname.config MODIFY COLUMN adminuuid varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Adjusted table config (part 1) successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("ALTER TABLE $dbname.config ADD (registercid mediumint(8) UNSIGNED NOT NULL default '0')") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Adjusted table config (part 2) successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("ALTER TABLE $dbname.user ADD (cid int(10) NOT NULL default '0')") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Adjusted table user successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("CREATE INDEX user_version ON $dbname.user (version)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Create index 'user_version' on table user successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("CREATE INDEX user_cldbid ON $dbname.user (cldbid ASC,uuid,rank)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Create index 'user_cldbid' on table user successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("CREATE INDEX user_online ON $dbname.user (online,lastseen)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Create index 'user_online' on table user successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.job_check (job_name) VALUES ('clean_db'),('clean_clients'),('calc_server_stats'),('runtime_check'),('last_update')") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Set new values to table job_check successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.job_check WHERE job_name='check_clean'") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Removed old value 'check_clean' from table job_check successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("ALTER TABLE $dbname.user_snapshot ADD PRIMARY KEY (timestamp, uuid)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Added new primary key on table user_snapshot successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("ALTER TABLE $dbname.stats_nations ADD PRIMARY KEY (nation)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Added new primary key on table stats_nations successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("ALTER TABLE $dbname.stats_platforms ADD PRIMARY KEY (platform)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Added new primary key on table stats_platforms successfully.");
|
||||
}
|
||||
if($mysqlcon->exec("ALTER TABLE $dbname.stats_versions ADD PRIMARY KEY (version)") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Added new primary key on table stats_versions successfully.");
|
||||
}
|
||||
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='".time()."' WHERE job_name='last_update'") === false) { } else {
|
||||
enter_logfile($logpath,$timezone,4," [1.2.4] Stored timestamp of last update successfully.");
|
||||
}
|
||||
}
|
||||
$currvers = set_new_version($mysqlcon,$dbname,$timezone,$newversion,$logpath);
|
||||
old_files($timezone,$logpath);
|
||||
check_chmod($timezone,$logpath,$lang);
|
||||
|
||||
100
jobs/clean.php
100
jobs/clean.php
@@ -1,45 +1,24 @@
|
||||
<?PHP
|
||||
function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath) {
|
||||
$count_tsuser['count'] = 0;
|
||||
function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath,$select_arr) {
|
||||
$nowtime = time();
|
||||
$sqlexec = '';
|
||||
|
||||
// clean usersnaps older then 1 month
|
||||
if($mysqlcon->query("DELETE a FROM $dbname.user_snapshot AS a CROSS JOIN(SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 1000 OFFSET 121) AS b WHERE a.timestamp=b.timestamp") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 2.1:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
// clean old server usage - older then a year
|
||||
if($mysqlcon->query("DELETE FROM $dbname.server_usage WHERE timestamp < (UNIX_TIMESTAMP() - 31536000)") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 2.2:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
// clean old clients out of the database
|
||||
if ($cleanclients == 1) {
|
||||
$cleantime = $nowtime - $cleanperiod;
|
||||
if(($lastclean = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_clean'")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 3:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$lastclean = $lastclean->fetchAll();
|
||||
if ($lastclean[0]['timestamp'] < $cleantime) {
|
||||
if(($dbuserdata = $mysqlcon->query("SELECT uuid FROM $dbname.user")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 4:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$countrs = $dbuserdata->rowCount();
|
||||
$uuids = $dbuserdata->fetchAll();
|
||||
if($select_arr['job_check']['clean_clients']['timestamp'] < ($nowtime - $cleanperiod)) {
|
||||
if ($cleanclients == 1) {
|
||||
enter_logfile($logpath,$timezone,4,$lang['clean']);
|
||||
$start=0;
|
||||
$start = $countdel = $countts = 0;
|
||||
$break=200;
|
||||
$count_tsuser['count'] = 0;
|
||||
$clientdblist=array();
|
||||
$countdel=0;
|
||||
$countts=0;
|
||||
while($getclientdblist=$ts3->clientListDb($start, $break)) {
|
||||
$clientdblist=array_merge($clientdblist, $getclientdblist);
|
||||
$start=$start+$break;
|
||||
$count_tsuser=array_shift($getclientdblist);
|
||||
if ($start == 100000 || $count_tsuser['count'] <= $start) {
|
||||
if($count_tsuser['count'] <= $start) {
|
||||
break;
|
||||
}
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
usleep($slowmode);
|
||||
}
|
||||
foreach($clientdblist as $uuidts) {
|
||||
$single_uuid = $uuidts['client_unique_identifier']->toString();
|
||||
@@ -47,43 +26,68 @@ function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$c
|
||||
}
|
||||
unset($clientdblist);
|
||||
|
||||
foreach($uuids as $uuid) {
|
||||
if(isset($uidarrts[$uuid[0]])) {
|
||||
foreach($select_arr['all_user'] as $uuid => $value) {
|
||||
if(isset($uidarrts[$uuid])) {
|
||||
$countts++;
|
||||
} else {
|
||||
$deleteuuids[] = $uuid[0];
|
||||
$deleteuuids[] = $uuid;
|
||||
$countdel++;
|
||||
}
|
||||
}
|
||||
|
||||
unset($uidarrts);
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleants'], $countts, $count_tsuser['count']));
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleanrs'], $countrs));
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleanrs'], count($select_arr['all_user'])));
|
||||
|
||||
if(isset($deleteuuids)) {
|
||||
$alldeldata = '';
|
||||
foreach ($deleteuuids as $dellarr) {
|
||||
$alldeldata = $alldeldata . "'" . $dellarr . "',";
|
||||
$fsfilelist = opendir(substr(__DIR__,0,-4).'avatars/');
|
||||
while (false !== ($fsfile = readdir($fsfilelist))) {
|
||||
if ($fsfile != '.' && $fsfile != '..') {
|
||||
$fsfilelistarray[$fsfile] = filemtime(substr(__DIR__,0,-4).'avatars/'.$fsfile);
|
||||
}
|
||||
}
|
||||
$alldeldata = substr($alldeldata, 0, -1);
|
||||
$alldeldata = "(".$alldeldata.")";
|
||||
if ($alldeldata != '') {
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.user WHERE uuid IN $alldeldata") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 5:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleandel'], $countdel));
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 6:".print_r($mysqlcon->errorInfo(), true));
|
||||
unset($fsfilelist);
|
||||
$avatarfilepath = substr(__DIR__,0,-4).'avatars/';
|
||||
$convert = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p');
|
||||
foreach ($deleteuuids as $uuid) {
|
||||
$alldeldata = $alldeldata . "'" . $uuid . "',";
|
||||
$uuidasbase16 = '';
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$char = ord(substr(base64_decode($uuid), $i, 1));
|
||||
$uuidasbase16 .= $convert[($char & 0xF0) >> 4];
|
||||
$uuidasbase16 .= $convert[$char & 0x0F];
|
||||
}
|
||||
if (isset($fsfilelistarray[$uuidasbase16.'.png'])) {
|
||||
if(unlink($avatarfilepath.$uuidasbase16.'.png') === false) {
|
||||
enter_logfile($logpath,$timezone,2," ".sprintf($lang['clean0002'], $uuidasbase16, $uuid).' '.sprintf($lang['errperm'], 'avatars'));
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['clean0001'], $uuidasbase16, $uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($$deleteuuids);
|
||||
$alldeldata = substr($alldeldata, 0, -1);
|
||||
$alldeldata = "(".$alldeldata.")";
|
||||
if ($alldeldata != '') {
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_clients'; UPDATE $dbname.stats_user AS t LEFT JOIN $dbname.user AS u ON t.uuid=u.uuid SET t.removed='1' WHERE u.uuid IS NULL; DELETE FROM $dbname.user WHERE uuid IN $alldeldata; ";
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleandel'], $countdel));
|
||||
unset($$alldeldata);
|
||||
}
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4," ".$lang['cleanno']);
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 7:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_clients'; ";
|
||||
}
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4,$lang['clean0004']);
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_clients'; ";
|
||||
}
|
||||
}
|
||||
|
||||
// clean usersnaps older then 1 month + clean old server usage - older then a year
|
||||
if ($select_arr['job_check']['clean_db']['timestamp'] < ($nowtime - 86400)) {
|
||||
$sqlexec .= "DELETE a FROM $dbname.user_snapshot AS a CROSS JOIN(SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 1000 OFFSET 121) AS b WHERE a.timestamp=b.timestamp; DELETE FROM $dbname.server_usage WHERE timestamp < (UNIX_TIMESTAMP() - 31536000); DELETE b FROM $dbname.user a RIGHT JOIN $dbname.stats_user b ON a.uuid = b.uuid WHERE a.uuid IS NULL; UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_db'; ";
|
||||
enter_logfile($logpath,$timezone,4,$lang['clean0003']);
|
||||
}
|
||||
return($sqlexec);
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?PHP
|
||||
function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath,$avatar_delay) {
|
||||
function get_avatars($ts3,$slowmode,$timezone,$logpath,$avatar_delay) {
|
||||
try {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
usleep($slowmode);
|
||||
$tsfilelist = $ts3->channelFileList($cid="0", $cpw="", $path="/");
|
||||
} catch (Exception $e) {
|
||||
if ($e->getCode() != 1281) {
|
||||
@@ -14,6 +14,7 @@ function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath,$
|
||||
$fsfilelistarray[$fsfile] = filemtime(substr(__DIR__,0,-4).'avatars/'.$fsfile);
|
||||
}
|
||||
}
|
||||
unset($fsfilelist);
|
||||
|
||||
if (isset($tsfilelist)) {
|
||||
foreach($tsfilelist as $tsfile) {
|
||||
@@ -38,6 +39,7 @@ function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$logpath,$
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($fsfilelistarray);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,33 +1,35 @@
|
||||
<?PHP
|
||||
function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host) {
|
||||
|
||||
global $lang, $logpath, $timezone, $nextupinfo, $nextupinfomsg1, $nextupinfomsg2, $nextupinfomsg3, $mysqlcon, $dbname, $grouptime, $substridle, $slowmode, $currvers, $newversion, $adminuuid, $phpcommand;
|
||||
if($host->whoami()["client_unique_identifier"] != $event["invokeruid"]) { //check whoami need to slowmode or is already stored?
|
||||
$uuid = $event["invokeruid"];
|
||||
|
||||
if($host->whoami()["client_unique_identifier"] != $event["invokeruid"]) { //check whoami need to slowmode or is already stored?
|
||||
$uuid = $event["invokeruid"];
|
||||
$admin = 0;
|
||||
foreach ($adminuuid as $auuid) {
|
||||
if ($uuid == $auuid) {
|
||||
$admin = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if((strstr($event["msg"], '!nextup') || strstr($event["msg"], '!next')) && $nextupinfo != 0) {
|
||||
//enter_logfile($logpath,$timezone,6,"Client ".$event["invokername"]." (".$event["invokeruid"].") sent textmessage: ".$event["msg"]);
|
||||
if(($dbuserdata = $mysqlcon->query("SELECT count,nextup,idle,except,name FROM $dbname.user WHERE uuid='$uuid'")) === false) {
|
||||
if(($user = $mysqlcon->query("SELECT count,nextup,idle,except,name FROM $dbname.user WHERE uuid='$uuid'")->fetch()) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 1:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$user = $dbuserdata->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if(($dbgroups = $mysqlcon->query("SELECT * FROM $dbname.groups")) === false) {
|
||||
if(($sqlhisgroup = $mysqlcon->query("SELECT sgid,sgidname FROM $dbname.groups")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 2:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$servergroups = $dbgroups->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach($servergroups as $servergroup) {
|
||||
$sqlhisgroup[$servergroup['sgid']] = $servergroup['sgidname'];
|
||||
}
|
||||
|
||||
ksort($grouptime);
|
||||
$countgrp = count($grouptime);
|
||||
$grpcount=0;
|
||||
foreach ($grouptime as $time => $groupid) {
|
||||
if ($substridle == 1) {
|
||||
$nextup = $time - $user[0]['count'] + $user[0]['idle'];
|
||||
$nextup = $time - $user['count'] + $user['idle'];
|
||||
} else {
|
||||
$nextup = $time - $user[0]['count'];
|
||||
$nextup = $time - $user['count'];
|
||||
}
|
||||
$dtF = new DateTime("@0");
|
||||
$dtT = new DateTime("@$nextup");
|
||||
@@ -35,25 +37,28 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
$hours = $dtF->diff($dtT)->format('%h');
|
||||
$mins = $dtF->diff($dtT)->format('%i');
|
||||
$secs = $dtF->diff($dtT)->format('%s');
|
||||
$name = $user[0]['name'];
|
||||
$name = $user['name'];
|
||||
$grpcount++;
|
||||
if ($nextup > 0 && $nextup < $time || $grpcount == $countgrp && $nextup <= 0) {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
if ($grpcount == $countgrp && $nextup <= 0) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($nextupinfomsg2, $days, $hours, $mins, $secs, $sqlhisgroup[$groupid], $name));
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($nextupinfomsg2, $days, $hours, $mins, $secs, $sqlhisgroup[$groupid]['sgidname'], $name));
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 3:".$e->getCode().': '.$e->getMessage());
|
||||
}
|
||||
} elseif ($user[0]['except'] == 2 || $user[0]['except'] == 3) {
|
||||
} elseif ($user['except'] == 2 || $user['except'] == 3) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($nextupinfomsg3, $days, $hours, $mins, $secs, $sqlhisgroup[$groupid], $name));
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($nextupinfomsg3, $days, $hours, $mins, $secs, $sqlhisgroup[$groupid]['sgidname'], $name));
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 4:".$e->getCode().': '.$e->getMessage());
|
||||
}
|
||||
} else {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($nextupinfomsg1, $days, $hours, $mins, $secs, $sqlhisgroup[$groupid], $name));
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($nextupinfomsg1, $days, $hours, $mins, $secs, $sqlhisgroup[$groupid]['sgidname'], $name));
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 5:".$e->getCode().': '.$e->getMessage());
|
||||
}
|
||||
@@ -67,12 +72,14 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
|
||||
if(strstr($event["msg"], '!version')) {
|
||||
if(version_compare(substr($newversion, 0, 5), substr($currvers, 0, 5), '>') && $newversion != '') {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($lang['upmsg'], $currvers, $newversion));
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 6:".$e->getCode().': '.$e->getMessage());
|
||||
}
|
||||
} else {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message(sprintf($lang['msg0001'], $currvers));
|
||||
} catch (Exception $e) {
|
||||
@@ -82,6 +89,7 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
}
|
||||
|
||||
if(strstr($event["msg"], '!help') || strstr($event["msg"], '!info') || strstr($event["msg"], '!commands')) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0002']);
|
||||
} catch (Exception $e) {
|
||||
@@ -89,9 +97,10 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
}
|
||||
}
|
||||
|
||||
if((strstr($event["msg"], '!shutdown') || strstr($event["msg"], '!quit') || strstr($event["msg"], '!stop')) && $event["invokeruid"] == $adminuuid) {
|
||||
if((strstr($event["msg"], '!shutdown') || strstr($event["msg"], '!quit') || strstr($event["msg"], '!stop')) && $admin == 1) {
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['msg0004'], $event["invokername"], $event["invokeruid"]));
|
||||
$path = substr(__DIR__, 0, -4);
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0005']);
|
||||
} catch (Exception $e) {
|
||||
@@ -99,6 +108,7 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
}
|
||||
exec($phpcommand." ".$path."worker.php stop");
|
||||
} elseif (strstr($event["msg"], '!shutdown') || strstr($event["msg"], '!quit') || strstr($event["msg"], '!stop')) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0003']);
|
||||
} catch (Exception $e) {
|
||||
@@ -106,9 +116,10 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
}
|
||||
}
|
||||
|
||||
if((strstr($event["msg"], '!restart') || strstr($event["msg"], '!reboot')) && $event["invokeruid"] == $adminuuid) {
|
||||
if((strstr($event["msg"], '!restart') || strstr($event["msg"], '!reboot')) && $admin == 1) {
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['msg0007'], $event["invokername"], $event["invokeruid"]));
|
||||
$path = substr(__DIR__, 0, -4);
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0006']);
|
||||
} catch (Exception $e) {
|
||||
@@ -120,6 +131,7 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
exec($phpcommand." ".$path."worker.php restart > /dev/null 2>/dev/null &");
|
||||
}
|
||||
} elseif (strstr($event["msg"], '!restart') || strstr($event["msg"], '!reboot')) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0003']);
|
||||
} catch (Exception $e) {
|
||||
@@ -127,16 +139,37 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
|
||||
}
|
||||
}
|
||||
|
||||
if((strstr($event["msg"], '!checkupdate') || strstr($event["msg"], '!update')) && $event["invokeruid"] == $adminuuid) {
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='0' WHERE job_name IN ('check_update','get_version')") === false) {
|
||||
if((strstr($event["msg"], '!checkupdate') || strstr($event["msg"], '!update')) && $admin == 1) {
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='0' WHERE job_name IN ('check_update','get_version','calc_server_stats')") === false) {
|
||||
enter_logfile($logpath,$timezone,4,"handle_messages 13:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0008']);
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 14:".$e->getCode().': '.$e->getMessage());
|
||||
}
|
||||
} elseif (strstr($event["msg"], '!checkupdate') || strstr($event["msg"], '!update')) {
|
||||
} elseif(strstr($event["msg"], '!checkupdate') || strstr($event["msg"], '!update')) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0003']);
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 15:".$e->getCode().': '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if((strstr($event["msg"], '!clean')) && $admin == 1) {
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='0' WHERE job_name IN ('clean_db','clean_clients')") === false) {
|
||||
enter_logfile($logpath,$timezone,4,"handle_messages 13:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0009']);
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"handle_messages 14:".$e->getCode().': '.$e->getMessage());
|
||||
}
|
||||
} elseif(strstr($event["msg"], '!clean')) {
|
||||
usleep($slowmode);
|
||||
try {
|
||||
$host->serverGetSelected()->clientGetByUid($event["invokeruid"])->message($lang['msg0003']);
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?PHP
|
||||
function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$logpath) {
|
||||
|
||||
function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serverinfo,$logpath,$grouptime,$boostarr,$exceptgroup,$select_arr) {
|
||||
$sqlexec = '';
|
||||
try {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
usleep($slowmode);
|
||||
$iconlist = $ts3->channelFileList($cid="0", $cpw="", $path="/icons/");
|
||||
} catch (Exception $e) {
|
||||
if ($e->getCode() != 1281) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 1:".$e->getCode().': '."Error while getting servergrouplist: ".$e->getMessage());
|
||||
enter_logfile($logpath,$timezone,2,$lang['errorts3'].$e->getCode().': '.$lang['errgrplist'].$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,69 +16,63 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serveri
|
||||
}
|
||||
|
||||
try {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
usleep($slowmode);
|
||||
$ts3->serverGroupListReset();
|
||||
$ts3groups = $ts3->serverGroupList();
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 2:".$e->getCode().': '."Error while getting servergrouplist: ".$e->getMessage());
|
||||
enter_logfile($logpath,$timezone,2,$lang['errorts3'].$e->getCode().': '.$lang['errgrplist'].$e->getMessage());
|
||||
}
|
||||
|
||||
if(($dbgroups = $mysqlcon->query("SELECT * FROM $dbname.groups")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 3:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
if ($dbgroups->rowCount() == 0) {
|
||||
$sqlhisgroup = "empty";
|
||||
} else {
|
||||
$servergroups = $dbgroups->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach($servergroups as $servergroup) {
|
||||
$sqlhisgroup[$servergroup['sgid']] = array (
|
||||
"sgid" => $servergroup['sgid'],
|
||||
"iconid" => $servergroup['iconid'],
|
||||
"sgidname" => $servergroup['sgidname'],
|
||||
"icondate" => $servergroup['icondate']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ServerIcon
|
||||
$sIconId = $serverinfo['virtualserver_icon_id'];
|
||||
$sIconId = ($sIconId < 0) ? (pow(2, 32)) - ($sIconId * -1) : $sIconId;
|
||||
if ($serverinfo['virtualserver_icon_id'] < 0) {
|
||||
$sIconId = (pow(2, 32)) - ($serverinfo['virtualserver_icon_id'] * -1);
|
||||
} else {
|
||||
$sIconId = $serverinfo['virtualserver_icon_id'];
|
||||
}
|
||||
$sIconFile = 0;
|
||||
if (!isset($sqlhisgroup['0']) || $sqlhisgroup['0']['iconid'] != $sIconId || $iconarr["i".$sIconId] > $sqlhisgroup['0']['icondate']) {
|
||||
if (!isset($select_arr['groups']['0']) || $select_arr['groups']['0']['iconid'] != $sIconId || $iconarr["i".$sIconId] > $select_arr['groups']['0']['icondate']) {
|
||||
if($sIconId > 600) {
|
||||
try {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
enter_logfile($logpath,$timezone,5,"Download new ServerIcon");
|
||||
usleep($slowmode);
|
||||
enter_logfile($logpath,$timezone,5,$lang['upgrp0002']);
|
||||
$sIconFile = $ts3->iconDownload();
|
||||
if(file_put_contents(substr(dirname(__FILE__),0,-4) . "tsicons/servericon.png", $sIconFile) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"Error while writing out the servericon. Please check the permission for the folder 'tsicons'");
|
||||
enter_logfile($logpath,$timezone,2,$lang['upgrp0003'].' '.sprintf($lang['errperm'], 'tsicons'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 4:".$e->getCode().': '."Error while downloading servericon: ".$e->getMessage());
|
||||
enter_logfile($logpath,$timezone,2,$lang['errorts3'].$e->getCode().'; '.$lang['upgrp0004'].$e->getMessage());
|
||||
}
|
||||
} elseif($sIconId == 0) {
|
||||
if(file_exists(substr(dirname(__FILE__),0,-4) . "tsicons/servericon.png")) {
|
||||
if(unlink(substr(dirname(__FILE__),0,-4) . "tsicons/servericon.png") === false) {
|
||||
enter_logfile($logpath,$timezone,2,$lang['upgrp0005'].' '.sprintf($lang['errperm'], 'tsicons'));
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,5,$lang['upgrp0006']);
|
||||
}
|
||||
}
|
||||
$iconarr["i".$sIconId] = 0;
|
||||
}
|
||||
if (!isset($sqlhisgroup['0'])) {
|
||||
if (!isset($select_arr['groups']['0'])) {
|
||||
$insertgroups[] = array(
|
||||
"sgid" => "0",
|
||||
"sgidname" => $mysqlcon->quote("ServerIcon", ENT_QUOTES),
|
||||
"sgidname" => "'ServerIcon'",
|
||||
"iconid" => $sIconId,
|
||||
"icon" => $sIconFile,
|
||||
"icondate" => $iconarr["i".$sIconId]
|
||||
);
|
||||
} else {
|
||||
$updategroups[] = array(
|
||||
"sgid" => "0",
|
||||
"sgidname" => $mysqlcon->quote("ServerIcon", ENT_QUOTES),
|
||||
"sgidname" => "'ServerIcon'",
|
||||
"iconid" => $sIconId,
|
||||
"icon" => $sIconFile,
|
||||
"icondate" => $iconarr["i".$sIconId]
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// GroupIcons
|
||||
$iconcount= 0;
|
||||
foreach ($ts3groups as $servergroup) {
|
||||
$tsgroupids[] = $servergroup['sgid'];
|
||||
$tsgroupids[$servergroup['sgid']] = 0;
|
||||
$sgid = $servergroup['sgid'];
|
||||
$sgname = $mysqlcon->quote($servergroup['name'], ENT_QUOTES);
|
||||
$gefunden = 2;
|
||||
@@ -86,36 +80,41 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serveri
|
||||
$iconid = ($iconid < 0) ? (pow(2, 32)) - ($iconid * -1) : $iconid;
|
||||
$iconfile = 0;
|
||||
if($iconid > 600) {
|
||||
if (!isset($sqlhisgroup[$sgid]) || $sqlhisgroup[$sgid]['iconid'] != $iconid || $iconarr["i".$iconid] > $sqlhisgroup[$sgid]['icondate']) {
|
||||
if (!isset($select_arr['groups'][$sgid]) || $select_arr['groups'][$sgid]['iconid'] != $iconid || $iconarr["i".$iconid] > $select_arr['groups'][$sgid]['icondate']) {
|
||||
try {
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
enter_logfile($logpath,$timezone,5,"Download new ServerGroupIcon for group ".$sgname." with ID: ".$sgid);
|
||||
try {
|
||||
$iconfile = $servergroup->iconDownload();
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 5:".$e->getCode().': '."Error while downloading servergroupicon: ".$e->getMessage());
|
||||
}
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['upgrp0011'], $sgname, $sgid));
|
||||
$iconfile = $servergroup->iconDownload();
|
||||
if(file_put_contents(substr(dirname(__FILE__),0,-4) . "tsicons/" . $sgid . ".png", $iconfile) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"Error while writing out the servergroup icon. Please check the permission for the folder 'tsicons'");
|
||||
enter_logfile($logpath,$timezone,2,sprintf($lang['upgrp0007'], $sgname, $sgid).' '.sprintf($lang['errperm'], 'tsicons'));
|
||||
}
|
||||
$iconcount++;
|
||||
} catch (Exception $e) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 6:".$e->getCode().': '."Error while downloading servergroup icon: ".$e->getMessage());
|
||||
enter_logfile($logpath,$timezone,2,$lang['errorts3'].$e->getCode().': '.sprintf($lang['upgrp0008'], $sgname, $sgid).$e->getMessage());
|
||||
}
|
||||
}
|
||||
} elseif($iconid == 0) {
|
||||
if(file_exists(substr(dirname(__FILE__),0,-4) . "tsicons/" . $sgid . ".png")) {
|
||||
if(unlink(substr(dirname(__FILE__),0,-4) . "tsicons/" . $sgid . ".png") === false) {
|
||||
enter_logfile($logpath,$timezone,2,sprintf($lang['upgrp0009'], $sgname, $sgid).' '.sprintf($lang['errperm'], 'tsicons'));
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,5,sprintf($lang['upgrp0010'], $sgname, $sgid));
|
||||
}
|
||||
}
|
||||
$iconarr["i".$iconid] = 0;
|
||||
}
|
||||
|
||||
if(!isset($iconarr["i".$iconid])) {
|
||||
$iconarr["i".$iconid] = 0;
|
||||
}
|
||||
if ($sqlhisgroup != "empty") {
|
||||
foreach ($sqlhisgroup as $groups) {
|
||||
if ($groups['sgid'] == $sgid) {
|
||||
if(count($select_arr['groups']) != 0) {
|
||||
foreach ($select_arr['groups'] as $sqlgid => $groups) {
|
||||
if ($sqlgid == $sgid) {
|
||||
$gefunden = 1;
|
||||
$updategroups[] = array(
|
||||
"sgid" => $sgid,
|
||||
"sgidname" => $sgname,
|
||||
"iconid" => $iconid,
|
||||
"icon" => $iconfile,
|
||||
"icondate" => $iconarr["i".$iconid]
|
||||
);
|
||||
break;
|
||||
@@ -126,7 +125,6 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serveri
|
||||
"sgid" => $servergroup['sgid'],
|
||||
"sgidname" => $sgname,
|
||||
"iconid" => $iconid,
|
||||
"icon" => $iconfile,
|
||||
"icondate" => $iconarr["i".$iconid]
|
||||
);
|
||||
}
|
||||
@@ -135,10 +133,12 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serveri
|
||||
"sgid" => $servergroup['sgid'],
|
||||
"sgidname" => $sgname,
|
||||
"iconid" => $iconid,
|
||||
"icon" => $iconfile,
|
||||
"icondate" => $iconarr["i".$iconid]
|
||||
);
|
||||
}
|
||||
if($iconcount > 9) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($insertgroups)) {
|
||||
@@ -148,9 +148,7 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serveri
|
||||
}
|
||||
$allinsertdata = substr($allinsertdata, 0, -1);
|
||||
if ($allinsertdata != '') {
|
||||
if($mysqlcon->exec("INSERT INTO $dbname.groups (sgid, sgidname, iconid, icondate) VALUES $allinsertdata") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 7:".$allinsertdata.print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "INSERT INTO $dbname.groups (sgid, sgidname, iconid, icondate) VALUES $allinsertdata; ";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,24 +164,30 @@ function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$serveri
|
||||
$allupdatedate = $allupdatedate . "WHEN '" . $updatedata['sgid'] . "' THEN '" . $updatedata['icondate'] . "' ";
|
||||
}
|
||||
$allsgids = substr($allsgids, 0, -1);
|
||||
if($mysqlcon->exec("UPDATE $dbname.groups set sgidname = CASE sgid $allupdatesgid END, iconid = CASE sgid $allupdateiconid END, icondate = CASE sgid $allupdatedate END WHERE sgid IN ($allsgids)") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 8:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "UPDATE $dbname.groups set sgidname = CASE sgid $allupdatesgid END, iconid = CASE sgid $allupdateiconid END, icondate = CASE sgid $allupdatedate END WHERE sgid IN ($allsgids); ";
|
||||
}
|
||||
|
||||
if(isset($sqlhisgroup)) {
|
||||
foreach ($sqlhisgroup as $groups) {
|
||||
if(!in_array($groups['sgid'], $tsgroupids) && $groups['sgid'] != 0) {
|
||||
$delsgroupids = $delsgroupids . "'" . $groups['sgid'] . "',";
|
||||
if(isset($select_arr['groups'])) {
|
||||
foreach ($select_arr['groups'] as $sgid => $groups) {
|
||||
if(!isset($tsgroupids[$sgid]) && $sgid != 0 && $sgid != NULL) {
|
||||
$delsgroupids .= "'" . $sgid . "',";
|
||||
if(in_array($sgid, $grouptime)) {
|
||||
enter_logfile($logpath,$timezone,2,sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
|
||||
}
|
||||
if(isset($boostarr[$sgid])) {
|
||||
enter_logfile($logpath,$timezone,2,sprintf($lang['upgrp0001'], $sgid, $lang['wiboost']));
|
||||
}
|
||||
if(isset($exceptgroup[$sgid])) {
|
||||
enter_logfile($logpath,$timezone,2,sprintf($lang['upgrp0001'], $sgid, $lang['wiexgrp']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($delsgroupids)) {
|
||||
$delsgroupids = substr($delsgroupids, 0, -1);
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.groups WHERE sgid IN ($delsgroupids)") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"update_groups 9:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "DELETE FROM $dbname.groups WHERE sgid IN ($delsgroupids); ";
|
||||
}
|
||||
return($sqlexec);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user