release 1.3.1

This commit is contained in:
Newcomer1989
2019-06-30 18:20:51 +02:00
parent a4327efd80
commit e56cace8c5
56 changed files with 2737 additions and 1398 deletions

View File

@@ -10,23 +10,26 @@ function addon_assign_groups($addons_config,$ts3,$cfg,$dbname,$allclients,$selec
if($client['client_unique_identifier'] == $uuid) {
$cldbid = $client['client_database_id'];
$nickname = htmlspecialchars($client['client_nickname'], ENT_QUOTES);
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
break;
}
}
if(isset($cldbid)) {
if(strstr($group, '-')) {
$group = str_replace('-','',$group);
usleep($cfg['teamspeak_query_command_delay']);
try {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGroupClientDel($group, $cldbid);
enter_logfile($cfg,6,"Removed servergroup $group from user $nickname (UID: $uid), requested by Add-on 'Assign Servergroups'");
}
catch (Exception $e) {
enter_logfile($cfg,2,"addon_assign_groups:".$e->getCode().': '."Error while removing group: ".$e->getMessage());
}
} else {
usleep($cfg['teamspeak_query_command_delay']);
try {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGroupClientAdd($group, $cldbid);
enter_logfile($cfg,6,"Added servergroup $group from user $nickname (UID: $uid), requested by Add-on 'Assign Servergroups'");
}
catch (Exception $e) {
enter_logfile($cfg,2,"addon_assign_groups:".$e->getCode().': '."Error while adding group: ".$e->getMessage());

View File

@@ -1,8 +1,18 @@
#!/usr/bin/php
<?PHP
set_time_limit(0);
ini_set('default_charset', 'UTF-8');
setlocale(LC_ALL, 'UTF-8');
if(ini_get('max_execution_time') !== NULL) {
$max_execution_time = ini_get('max_execution_time');
} else {
$max_execution_time = "{none set}";
}
if(ini_get('memory_limit') !== NULL) {
$memory_limit = ini_get('memory_limit');
} else {
$memory_limit = "{none set}";
}
set_time_limit(0);
error_reporting(0);
function shutdown($mysqlcon = NULL,$cfg,$loglevel,$reason,$nodestroypid = TRUE) {
@@ -12,7 +22,7 @@ function shutdown($mysqlcon = NULL,$cfg,$loglevel,$reason,$nodestroypid = TRUE)
}
}
enter_logfile($cfg,$loglevel,$reason." Shutting down!");
enter_logfile($cfg,4,"###################################################################");
enter_logfile($cfg,9,"###################################################################");
if(isset($mysqlcon)) {
$mysqlcon = null;
}
@@ -20,20 +30,29 @@ function shutdown($mysqlcon = NULL,$cfg,$loglevel,$reason,$nodestroypid = TRUE)
}
function enter_logfile($cfg,$loglevel,$logtext,$norotate = false) {
if($loglevel > $cfg['logs_debug_level']) return;
if($loglevel!=9 && $loglevel > $cfg['logs_debug_level']) return;
$file = $cfg['logs_path'].'ranksystem.log';
if ($loglevel == 1) {
$loglevel = " CRITICAL ";
} elseif ($loglevel == 2) {
$loglevel = " ERROR ";
} elseif ($loglevel == 3) {
$loglevel = " WARNING ";
} elseif ($loglevel == 4) {
$loglevel = " NOTICE ";
} elseif ($loglevel == 5) {
$loglevel = " INFO ";
} elseif ($loglevel == 6) {
$loglevel = " DEBUG ";
switch ($loglevel) {
case 1:
$loglevel = " CRITICAL ";
break;
case 2:
$loglevel = " ERROR ";
break;
case 3:
$loglevel = " WARNING ";
break;
case 4:
$loglevel = " NOTICE ";
break;
case 5:
$loglevel = " INFO ";
break;
case 6:
$loglevel = " DEBUG ";
break;
default:
$loglevel = " NONE ";
}
$loghandle = fopen($file, 'a');
fwrite($loghandle, DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($cfg['logs_timezone']))->format("Y-m-d H:i:s.u ").$loglevel.$logtext."\n");
@@ -73,9 +92,9 @@ if(!in_array('ssh2', get_loaded_extensions()) && $cfg['teamspeak_query_encrypt_s
shutdown($mysqlcon,$cfg,1,"PHP SSH2 is missed. Installation of PHP SSH2 is required, when using secured (SSH) connection to TeamSpeak! If you are not able to install PHP SSH2 (i.e. hosted webspace), you need to deactivate the TS3 Query encryption inside the Webinterface.");
}
enter_logfile($cfg,4,"");
enter_logfile($cfg,4,"###################################################################");
enter_logfile($cfg,4,"Initialize Bot...");
enter_logfile($cfg,9,"");
enter_logfile($cfg,9,"###################################################################");
enter_logfile($cfg,9,"Initialize Bot...");
require_once(substr(__DIR__,0,-4).'libs/ts3_lib/TeamSpeak3.php');
require_once(substr(__DIR__,0,-4).'jobs/calc_user.php');
require_once(substr(__DIR__,0,-4).'jobs/get_avatars.php');
@@ -87,20 +106,21 @@ 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/event_userenter.php');
require_once(substr(__DIR__,0,-4).'jobs/update_rs.php');
require_once(substr(__DIR__,0,-4).'jobs/reset_rs.php');
enter_logfile($cfg,5,"Running on OS: ".php_uname("s")." ".php_uname("r"));
enter_logfile($cfg,5,"Using PHP Version: ".phpversion());
enter_logfile($cfg,5,"Database Version: ".$mysqlcon->getAttribute(PDO::ATTR_SERVER_VERSION));
enter_logfile($cfg,9,"Running on OS: ".php_uname("s")." ".php_uname("r"));
enter_logfile($cfg,9,"Using PHP Version: ".phpversion());
enter_logfile($cfg,9,"Database Version: ".$mysqlcon->getAttribute(PDO::ATTR_SERVER_VERSION));
$cfg = check_db($mysqlcon,$lang,$cfg,$dbname);
$cfg['temp_db_version'] = $mysqlcon->getAttribute(PDO::ATTR_SERVER_VERSION);
$cfg['temp_last_botstart'] = time();
$cfg['temp_reconnect_attempts'] = 0;
enter_logfile($cfg,5,"Check Ranksystem files for updates...");
enter_logfile($cfg,4,"Check Ranksystem files for updates...");
if(isset($cfg['version_current_using']) && isset($cfg['version_latest_available']) && $cfg['version_latest_available'] != NULL && version_compare($cfg['version_latest_available'], $cfg['version_current_using'], '>')) {
update_rs($mysqlcon,$lang,$cfg,$dbname,$phpcommand);
}
enter_logfile($cfg,5,"Check Ranksystem files for updates [done]");
enter_logfile($cfg,4,"Check Ranksystem files for updates [done]");
function check_shutdown($cfg) {
if(!file_exists(substr(__DIR__,0,-4).'logs/pid')) {
@@ -108,56 +128,56 @@ function check_shutdown($cfg) {
}
}
enter_logfile($cfg,5,"Ranksystem Version: ".$cfg['version_current_using']);
enter_logfile($cfg,5,"Loading addons...");
enter_logfile($cfg,9,"Ranksystem Version: ".$cfg['version_current_using']." (on Update-Channel: ".$cfg['version_update_channel'].")");
enter_logfile($cfg,4,"Loading addons...");
require_once(substr(__DIR__,0,-4).'other/load_addons_config.php');
$addons_config = load_addons_config($mysqlcon,$lang,$cfg,$dbname);
if($addons_config['assign_groups_active']['value'] == '1') {
enter_logfile($cfg,5," Addon: 'assign_groups' [ON]");
enter_logfile($cfg,4," Addon: 'assign_groups' [ON]");
include(substr(__DIR__,0,-4).'jobs/addon_assign_groups.php');
$cfg['temp_addon_assign_groups'] = "enabled";
} else {
enter_logfile($cfg,5," Addon: 'assign_groups' [OFF]");
enter_logfile($cfg,4," Addon: 'assign_groups' [OFF]");
$cfg['temp_addon_assign_groups'] = "disabled";
}
enter_logfile($cfg,5,"Loading addons [done]");
enter_logfile($cfg,4,"Loading addons [done]");
function sendmessage($ts3, $cfg, $uuid, $msg, $erromsg=NULL, $errcode=NULL, $successmsg=NULL, $nolog=NULL) {
try {
if(strlen($msg) > 1024) {
$fragarr = explode("##*##", wordwrap($msg, 1022, "##*##", TRUE), 1022);
foreach($fragarr as $frag) {
try {
if(strlen($msg) > 1024) {
$fragarr = explode("##*##", wordwrap($msg, 1022, "##*##", TRUE), 1022);
foreach($fragarr as $frag) {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGetSelected()->clientGetByUid($uuid)->message("\n".$frag);
if($nolog==NULL) {
enter_logfile($cfg,6,"sendmessage to uuid $uuid (fragment): ".$frag);
}
}
} else {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGetSelected()->clientGetByUid($uuid)->message("\n".$frag);
$ts3->serverGetSelected()->clientGetByUid($uuid)->message($msg);
if($nolog==NULL) {
enter_logfile($cfg,6,"sendmessage to uuid $uuid (fragment): ".$frag);
enter_logfile($cfg,6,"sendmessage to uuid $uuid: ".$msg);
}
}
} else {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGetSelected()->clientGetByUid($uuid)->message($msg);
if($nolog==NULL) {
enter_logfile($cfg,6,"sendmessage to uuid $uuid: ".$msg);
if($successmsg!=NULL) {
enter_logfile($cfg,5,$successmsg);
}
} catch (Exception $e) {
if($errcode!=NULL) {
enter_logfile($cfg,$errcode,$erromsg." TS3: ".$e->getCode().': '.$e->getMessage());
} else {
enter_logfile($cfg,3,"sendmessage: ".$e->getCode().': '.$e->getMessage());
}
}
if($successmsg!=NULL) {
enter_logfile($cfg,5,$successmsg);
}
} catch (Exception $e) {
if($errcode!=NULL) {
enter_logfile($cfg,$errcode,$erromsg." TS3: ".$e->getCode().': '.$e->getMessage());
} else {
enter_logfile($cfg,2,"sendmessage: ".$e->getCode().': '.$e->getMessage());
}
}
}
$sqlexec = '';
function run_bot() {
global $cfg, $mysqlcon, $dbname, $dbtype, $lang, $phpcommand, $addons_config, $sqlexec;
global $cfg, $mysqlcon, $dbname, $dbtype, $lang, $phpcommand, $addons_config, $sqlexec, $max_execution_time, $memory_limit;
enter_logfile($cfg,4,"Connect to TS3 Server (Address: \"".$cfg['teamspeak_host_address']."\" Voice-Port: \"".$cfg['teamspeak_voice_port']."\" Query-Port: \"".$cfg['teamspeak_query_port']."\" SSH: \"".$cfg['teamspeak_query_encrypt_switch']."\").");
enter_logfile($cfg,9,"Connect to TS3 Server (Address: \"".$cfg['teamspeak_host_address']."\" Voice-Port: \"".$cfg['teamspeak_voice_port']."\" Query-Port: \"".$cfg['teamspeak_query_port']."\" SSH: \"".$cfg['teamspeak_query_encrypt_switch']."\" Query-Slowmode: \"".number_format(($cfg['teamspeak_query_command_delay']/1000000),1)."\").");
try {
if($cfg['teamspeak_query_encrypt_switch'] == 1) {
@@ -166,7 +186,7 @@ function run_bot() {
$ts3host = TeamSpeak3::factory("serverquery://".rawurlencode($cfg['teamspeak_query_user']).":".rawurlencode($cfg['teamspeak_query_pass'])."@".$cfg['teamspeak_host_address'].":".$cfg['teamspeak_query_port']."/?blocking=0");
}
enter_logfile($cfg,4,"Connection to TS3 Server established.");
enter_logfile($cfg,9,"Connection to TS3 Server established.");
try{
$ts3version = $ts3host->version();
enter_logfile($cfg,5," TS3 Server version: ".$ts3version['version']." on ".$ts3version['platform']." [Build: ".$ts3version['build']." from ".date("Y-m-d H:i:s",$ts3version['build'])."]");
@@ -179,7 +199,7 @@ function run_bot() {
enter_logfile($cfg,3," Your TS3 server is outdated, please update it.. also to be ready for TS5!");
}
enter_logfile($cfg,5," Select virtual server...");
enter_logfile($cfg,9," Select virtual server...");
try {
if(version_compare($ts3version['version'],'3.4.0','>=')) {
usleep($cfg['teamspeak_query_command_delay']);
@@ -202,7 +222,7 @@ function run_bot() {
}
}
}
enter_logfile($cfg,5," Select virtual server [done]");
enter_logfile($cfg,9," Select virtual server [done]");
$cfg['temp_reconnect_attempts'] = 0;
} catch (Exception $e) {
enter_logfile($cfg,2," Error due selecting virtual server - ".$e->getCode().': '.$e->getMessage());
@@ -237,8 +257,35 @@ function run_bot() {
enter_logfile($cfg,5," No channel defined where the Ranksystem Bot should be entered.");
}
enter_logfile($cfg,4,"Config check started...");
enter_logfile($cfg,9,"Config check started...");
switch ($cfg['logs_debug_level']) {
case 1:
$loglevel = "1 - CRITICAL";
break;
case 2:
$loglevel = "2 - ERROR";
break;
case 3:
$loglevel = "3 - WARNING";
break;
case 4:
$loglevel = "4 - NOTICE";
break;
case 5:
$loglevel = "5 - INFO";
break;
case 6:
$loglevel = "6 - DEBUG";
break;
default:
$loglevel = "UNKOWN";
}
enter_logfile($cfg,9," Log Level: ".$loglevel);
enter_logfile($cfg,6," Serverside config 'max_execution_time' (PHP.ini): ".$max_execution_time." sec.");
enter_logfile($cfg,6," Serverside config 'memory_limit' (PHP.ini): ".$memory_limit);
$cfg['rankup_definition_flipped'] = array_flip($cfg['rankup_definition']);
krsort($cfg['rankup_definition']);
if(($groupslist = $mysqlcon->query("SELECT * FROM `$dbname`.`groups`")->fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_ASSOC)) === false) {
enter_logfile($cfg,1," Select on DB failed for group check: ".print_r($mysqlcon->errorInfo(), true));
}
@@ -268,19 +315,18 @@ function run_bot() {
}
}
if($checkgroups > 0) {
enter_logfile($cfg,4," Found servergroups in config, which are unknown. Redownload all servergroups from TS3 server.");
if($mysqlcon->exec("DELETE FROM groups;") === false) {
enter_logfile($cfg,3," Found servergroups in config, which are unknown. Redownload all servergroups from TS3 server.");
if($mysqlcon->exec("DELETE FROM `$dbname`.`groups`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
$nobreak = 1;
$serverinfo = $ts3server->serverInfo();
$select_arr = array();
$sqlexec2 .= update_groups($ts3server,$mysqlcon,$lang,$cfg,$dbname,$serverinfo,$select_arr,$nobreak);
$sqlexec2 .= update_groups($ts3server,$mysqlcon,$lang,$cfg,$dbname,$serverinfo,$select_arr,1);
if($mysqlcon->exec($sqlexec2) === false) {
enter_logfile($cfg,2,"Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
unset($sqlexec2, $select_arr, $groupslist);
unset($sqlexec2,$select_arr,$groupslist,$serverinfo,$ts3version);
$errcnf = 0;
enter_logfile($cfg,4," Downloading of servergroups finished. Recheck the config.");
@@ -331,11 +377,11 @@ function run_bot() {
}
}
unset($groupslist,$errcnf,$checkgroups);
enter_logfile($cfg,4,"Config check [done]");
unset($groupslist,$errcnf,$checkgroups,$lastupdate,$updcld,$loglevel,$whoami,$ts3host,$max_execution_time,$memory_limit,$memory_limit);
enter_logfile($cfg,9,"Config check [done]");
enter_logfile($cfg,4,"Bot starts now his work!");
$looptime = 0; $cfg['temp_last_laptime'] = '';
enter_logfile($cfg,9,"Bot starts now his work!");
$looptime = $cfg['temp_count_laps'] = $cfg['temp_whole_laptime'] = $cfg['temp_count_laptime'] = 0; $cfg['temp_last_laptime'] = '';
usleep(3000000);
while(1) {
@@ -390,7 +436,8 @@ function run_bot() {
}
$get_db_data->nextRowset();
}
unset($get_db_data, $fetched_array, $single_select);
unset($get_db_data,$fetched_array,$single_select);
enter_logfile($cfg,6,"SQL select needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
check_shutdown($cfg);
$addons_config = load_addons_config($mysqlcon,$lang,$cfg,$dbname);
@@ -407,7 +454,7 @@ function run_bot() {
$sqlexec .= calc_serverstats($ts3server,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$select_arr,$phpcommand,$lang);
$sqlexec .= calc_userstats($ts3server,$mysqlcon,$cfg,$dbname,$select_arr);
$sqlexec .= update_groups($ts3server,$mysqlcon,$lang,$cfg,$dbname,$serverinfo,$select_arr);
if($addons_config['assign_groups_active']['value'] == '1') {
if($cfg['temp_addon_assign_groups'] == "disabled") {
enter_logfile($cfg,5,"Loading new addon...");
@@ -426,9 +473,11 @@ function run_bot() {
enter_logfile($cfg,5,"Disable addon [done]");
}
$startsql = microtime(true);
if($mysqlcon->exec($sqlexec) === false) {
enter_logfile($cfg,2,"Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
enter_logfile($cfg,6,"SQL exections needs: ".(number_format(round((microtime(true) - $startsql), 5),5)));
if($cfg['logs_debug_level'] > 5) {
$sqlfile = $cfg['logs_path'].'temp_sql_dump.sql';
$sqldump = fopen($sqlfile, 'wa+');
@@ -436,16 +485,26 @@ function run_bot() {
fclose($sqldump);
}
unset($sqlexec, $select_arr);
reset_rs($ts3server,$mysqlcon,$lang,$cfg,$dbname,$select_arr);
unset($sqlexec,$select_arr,$sqldump);
$sqlexec = '';
$looptime = microtime(true) - $starttime;
$cfg['temp_whole_laptime'] = $cfg['temp_whole_laptime'] + $looptime;
$cfg['temp_count_laptime']++;
$cfg['temp_last_laptime'] = substr((number_format(round($looptime, 5),5) . ';' . $cfg['temp_last_laptime']),0,79);
enter_logfile($cfg,6,"last loop: ".round($looptime, 5)." sec.");
if($looptime < 1) {
$loopsleep = (1 - $looptime);
$ts3server->getAdapter()->waittsn($loopsleep, 50000); // 50ms delay for CPU reason
if($cfg['teamspeak_query_encrypt_switch'] == 1) {
// no wait for data to become available on the stream on SSH due issues with non-blocking mode
usleep(round($loopsleep * 1000000));
} else {
$ts3server->getAdapter()->waittsn($loopsleep, 50000); // 50ms delay for CPU reason
}
}
}
} catch (Exception $e) {
@@ -484,6 +543,7 @@ function run_bot() {
} else {
shutdown($mysqlcon,$cfg,1,"Critical TS3 error on core function!");
}
unset($offline_status,$wait_reconnect,$z);
}
}

View File

@@ -1,5 +1,7 @@
<?PHP
function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$select_arr,$phpcommand,$lang) {
global $cfg;
$starttime = microtime(true);
$nowtime = time();
$sqlexec = '';
@@ -23,6 +25,8 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
$total_online_time = $total_online_time + $uuid['count'];
$total_inactive_time = $total_inactive_time + $uuid['idle'];
}
$total_online_time = round($total_online_time);
$total_inactive_time = round($total_inactive_time);
$total_active_time = $total_online_time - $total_inactive_time;
// Event Handling each 6 hours
@@ -90,102 +94,279 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
} else {
$server_status = 4;
}
$platform_array = array_count_values(str_word_count($platform_string, 1));
unset($platform_string);
$platform_other = $platform_1 = $platform_2 = $platform_3 = $platform_4 = $platform_5 = 0;
if(!isset($cfg['temp_cache_platforms'])) {
$allinsertplatform = '';
foreach ($platform_array as $platform => $count) {
switch ($platform) {
case "Windows":
$platform_1 = $count;
break;
case "iOS":
$platform_2 = $count;
break;
case "Linux":
$platform_3 = $count;
break;
case "Android":
$platform_4 = $count;
break;
case "OSX":
$platform_5 = $count;
break;
default:
$platform_other = $platform_other + $count;
}
$allinsertplatform .= "('{$platform}',{$count}),";
$cfg['temp_cache_platforms'][$platform] = $count;
}
if($allinsertplatform != '') {
$allinsertplatform = substr($allinsertplatform, 0, -1);
$sqlexec .= "DELETE FROM `$dbname`.`stats_platforms`; INSERT INTO `$dbname`.`stats_platforms` (`platform`,`count`) VALUES $allinsertplatform; ";
}
unset($platform_array,$allinsertplatform,$platform,$count);
} else {
$allupdateplatform = $updateplatform = $insertplatform = '';
if(isset($cfg['temp_cache_platforms'])) {
foreach ($platform_array as $platform => $count) {
switch ($platform) {
case "Windows":
$platform_1 = $count;
break;
case "iOS":
$platform_2 = $count;
break;
case "Linux":
$platform_3 = $count;
break;
case "Android":
$platform_4 = $count;
break;
case "OSX":
$platform_5 = $count;
break;
default:
$platform_other = $platform_other + $count;
}
if(isset($cfg['temp_cache_platforms'][$platform]) && $cfg['temp_cache_platforms'][$platform] == $count) {
continue;
} elseif(isset($cfg['temp_cache_platforms'][$platform])) {
$cfg['temp_cache_platforms'][$platform] = $count;
$allupdateplatform = "'{$platform}',";
$updateplatform .= "WHEN `platform`='{$platform}' THEN {$count} ";
} else {
$cfg['temp_cache_platforms'][$platform] = $count;
$insertplatform .= "('{$platform}',{$count}),";
}
}
}
if($updateplatform != '' && $allupdateplatform != '') {
$allupdateplatform = substr($allupdateplatform, 0, -1);
$sqlexec .= "UPDATE `$dbname`.`stats_platforms` SET `count`=CASE {$updateplatform}END WHERE `platform` IN ({$allupdateplatform}); ";
}
if($insertplatform != '') {
$insertplatform = substr($insertplatform, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`stats_platforms` (`platform`,`count`) VALUES $insertplatform; ";
}
unset($platform_array,$allupdateplatform,$updateplatform,$insertplatform,$platform,$count);
}
$country_array = array_count_values(str_word_count($country_string, 1));
arsort($country_array);
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++;
if ($country_counter == 1) {
$country_nation_name_1 = $k;
$country_nation_1 = $v;
} elseif ($country_counter == 2) {
$country_nation_name_2 = $k;
$country_nation_2 = $v;
} elseif ($country_counter == 3) {
$country_nation_name_3 = $k;
$country_nation_3 = $v;
} elseif ($country_counter == 4) {
$country_nation_name_4 = $k;
$country_nation_4 = $v;
} elseif ($country_counter == 5) {
$country_nation_name_5 = $k;
$country_nation_5 = $v;
} else {
$country_nation_other = $country_nation_other + $v;
if(!isset($cfg['temp_cache_nations'])) {
foreach ($country_array as $nation => $count) {
$country_counter++;
switch ($country_counter) {
case 1:
$country_nation_name_1 = $nation;
$country_nation_1 = $count;
break;
case 2:
$country_nation_name_2 = $nation;
$country_nation_2 = $count;
break;
case 3:
$country_nation_name_3 = $nation;
$country_nation_3 = $count;
break;
case 4:
$country_nation_name_4 = $nation;
$country_nation_4 = $count;
break;
case 5:
$country_nation_name_5 = $nation;
$country_nation_5 = $count;
break;
default:
$country_nation_other = $country_nation_other + $count;
}
$allinsertnation .= "('{$nation}',{$count}),";
$cfg['temp_cache_nations'][$nation] = $count;
}
$allinsertnation = $allinsertnation . "('" . $k . "', " . $v . "),";
}
$allinsertnation = substr($allinsertnation, 0, -1);
$platform_array = array_count_values(str_word_count($platform_string, 1));
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") {
$platform_1 = $v;
} elseif ($k == "iOS") {
$platform_2 = $v;
} elseif ($k == "Linux") {
$platform_3 = $v;
} elseif ($k == "Android") {
$platform_4 = $v;
} elseif ($k == "OSX") {
$platform_5 = $v;
} else {
$platform_other = $platform_other + $v;
if($allinsertnation != '') {
$allinsertnation = substr($allinsertnation, 0, -1);
$sqlexec .= "DELETE FROM `$dbname`.`stats_nations`; INSERT INTO `$dbname`.`stats_nations` (`nation`,`count`) VALUES $allinsertnation; ";
}
$allinsertplatform = $allinsertplatform . "('" . $k . "', " . $v . "),";
}
unset($platform_array);
$allinsertplatform = substr($allinsertplatform, 0, -1);
$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 = '';
foreach($select_arr['count_version_user'] as $version => $count) {
$count_version++;
if ($count_version == 1) {
$version_1 = $count['count'];
$version_name_1 = $version;
} elseif ($count_version == 2) {
$version_2 = $count['count'];
$version_name_2 = $version;
} elseif ($count_version == 3) {
$version_3 = $count['count'];
$version_name_3 = $version;
} elseif ($count_version == 4) {
$version_4 = $count['count'];
$version_name_4 = $version;
} elseif ($count_version == 5) {
$version_5 = $count['count'];
$version_name_5 = $version;
unset($country_array,$allinsertnation,$nation,$count);
} else {
$allupdatenation = $updatenation = $insertnation = '';
if(isset($cfg['temp_cache_nations'])) {
foreach ($country_array as $nation => $count) {
$country_counter++;
switch ($country_counter) {
case 1:
$country_nation_name_1 = $nation;
$country_nation_1 = $count;
break;
case 2:
$country_nation_name_2 = $nation;
$country_nation_2 = $count;
break;
case 3:
$country_nation_name_3 = $nation;
$country_nation_3 = $count;
break;
case 4:
$country_nation_name_4 = $nation;
$country_nation_4 = $count;
break;
case 5:
$country_nation_name_5 = $nation;
$country_nation_5 = $count;
break;
default:
$country_nation_other = $country_nation_other + $count;
}
if(isset($cfg['temp_cache_nations'][$nation]) && $cfg['temp_cache_nations'][$nation] == $count) {
continue;
} elseif(isset($cfg['temp_cache_nations'][$nation])) {
$cfg['temp_cache_nations'][$nation] = $count;
$allupdatenation = "'{$nation}',";
$updatenation .= "WHEN `nation`='{$nation}' THEN {$count} ";
} else {
$cfg['temp_cache_nations'][$nation] = $count;
$insertnation .= "('{$nation}',{$count}),";
}
}
}
$sum_count = $sum_count + $count['count'];
$allinsertversion = $allinsertversion . "('" . $version . "', " . $count['count'] . "),";
if($updatenation != '' && $allupdatenation != '') {
$allupdatenation = substr($allupdatenation, 0, -1);
$sqlexec .= "UPDATE `$dbname`.`stats_nations` SET `count`=CASE {$updatenation}END WHERE `nation` IN ({$allupdatenation}); ";
}
if($insertnation != '') {
$insertnation = substr($insertnation, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`stats_nations` (`nation`,`count`) VALUES $insertnation; ";
}
unset($country_array,$allupdatenation,$updatenation,$insertnation,$nation,$count);
}
$allinsertversion = substr($allinsertversion, 0, -1);
$version_other = $sum_count - $version_1 - $version_2 - $version_3 - $version_4 - $version_5;
$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 = $version_other = 0;
if(!isset($cfg['temp_cache_versions'])) {
$allinsertversion = '';
foreach($select_arr['count_version_user'] as $version => $count) {
$count_version++;
switch ($count_version) {
case 1:
$version_name_1 = $version;
$version_1 = $count['count'];
break;
case 2:
$version_name_2 = $version;
$version_2 = $count['count'];
break;
case 3:
$version_name_3 = $version;
$version_3 = $count['count'];
break;
case 4:
$version_name_4 = $version;
$version_4 = $count['count'];
break;
case 5:
$version_name_5 = $version;
$version_5 = $count['count'];
break;
default:
$version_other = $version_other + $count['count'];
}
$allinsertversion .= "('{$version}',{$count['count']}),";
$cfg['temp_cache_versions'][$version] = $count['count'];
}
if($allinsertversion != '') {
$allinsertversion = substr($allinsertversion, 0, -1);
$sqlexec .= "DELETE FROM `$dbname`.`stats_versions`; INSERT INTO `$dbname`.`stats_versions` (`version`,`count`) VALUES $allinsertversion; ";
}
unset($allinsertversion);
} else {
$allupdatenversion = $updateversion = $insertversion = '';
if(isset($cfg['temp_cache_versions'])) {
foreach($select_arr['count_version_user'] as $version => $count) {
$count_version++;
switch ($count_version) {
case 1:
$version_name_1 = $version;
$version_1 = $count['count'];
break;
case 2:
$version_name_2 = $version;
$version_2 = $count['count'];
break;
case 3:
$version_name_3 = $version;
$version_3 = $count['count'];
break;
case 4:
$version_name_4 = $version;
$version_4 = $count['count'];
break;
case 5:
$version_name_5 = $version;
$version_5 = $count['count'];
break;
default:
$version_other = $version_other + $count['count'];
}
if(isset($cfg['temp_cache_versions'][$version]) && $cfg['temp_cache_versions'][$version] == $count['count']) {
continue;
} elseif(isset($cfg['temp_cache_versions'][$version])) {
$cfg['temp_cache_versions'][$version] = $count['count'];
$allupdatenversion = "'{$version}',";
$updateversion .= "WHEN `version`='{$version}' THEN {$count['count']} ";
} else {
$cfg['temp_cache_versions'][$version] = $count['count'];
$insertversion .= "('{$version}',{$count['count']}),";
}
}
}
if($updateversion != '' && $allupdatenversion != '') {
$allupdatenversion = substr($allupdatenversion, 0, -1);
$sqlexec .= "UPDATE `$dbname`.`stats_versions` SET `count`=CASE {$updateversion}END WHERE `version` IN ({$allupdatenversion}); ";
}
if($insertversion != '') {
$insertversion = substr($insertversion, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`stats_versions` (`version`,`count`) VALUES $insertversion; ";
}
unset($allupdatenversion,$updateversion,$insertversion);
}
$server_used_slots = $serverinfo['virtualserver_clientsonline'] - $serverinfo['virtualserver_queryclientsonline'];
$server_free_slots = $serverinfo['virtualserver_maxclients'] - $server_used_slots;
$server_channel_amount = $serverinfo['virtualserver_channelsonline'];
$server_ping = $serverinfo['virtualserver_total_ping'];
$server_packet_loss = $serverinfo['virtualserver_total_packetloss_total'];
$server_bytes_down = $serverinfo['connection_bytes_received_total'];
$server_bytes_up = $serverinfo['connection_bytes_sent_total'];
$server_uptime = $serverinfo['virtualserver_uptime'];
$server_id = $serverinfo['virtualserver_id'];
$server_name = $mysqlcon->quote($serverinfo['virtualserver_name'], ENT_QUOTES);
$server_pass = $serverinfo['virtualserver_flag_password'];
$server_creation_date = $serverinfo['virtualserver_created'];
$server_platform = $serverinfo['virtualserver_platform'];
$server_weblist = $serverinfo['virtualserver_weblist_enabled'];
$server_version = $serverinfo['virtualserver_version'];
// 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);
$sqlexec .= "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,`server_status`=$server_status,`server_free_slots`=$server_free_slots,`server_used_slots`=$server_used_slots,`server_channel_amount`={$serverinfo['virtualserver_channelsonline']},`server_ping`={$serverinfo['virtualserver_total_ping']},`server_packet_loss`={$serverinfo['virtualserver_total_packetloss_total']},`server_bytes_down`={$serverinfo['connection_bytes_received_total']},`server_bytes_up`={$serverinfo['connection_bytes_sent_total']},`server_uptime`={$serverinfo['virtualserver_uptime']},`server_id`={$serverinfo['virtualserver_id']},`server_name`=$server_name,`server_pass`={$serverinfo['virtualserver_flag_password']},`server_creation_date`={$serverinfo['virtualserver_created']},`server_platform`='{$serverinfo['virtualserver_platform']}',`server_weblist`={$serverinfo['virtualserver_weblist_enabled']},`server_version`='{$serverinfo['virtualserver_version']}',`user_today`=$user_today,`user_week`=$user_week,`user_month`=$user_month,`user_quarter`=$user_quarter; ";
// Stats for Server Usage
if(key($select_arr['max_timestamp_server_usage']) == 0 || ($nowtime - key($select_arr['max_timestamp_server_usage'])) > 898) { // every 15 mins
@@ -196,7 +377,6 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
enter_logfile($cfg,2,"calc_serverstats 13:".print_r($mysqlcon->errorInfo(), true));
}
if(count($uuidsoff) != 0) {
krsort($cfg['rankup_definition']);
foreach($uuidsoff as $uuid) {
$count = $uuid['count'];
if ($cfg['rankup_time_assess_mode'] == 1) {
@@ -232,13 +412,13 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
$allupdateuuid = $allupdatenextup = '';
foreach ($updatenextup as $updatedata) {
$allupdateuuid = $allupdateuuid . "'" . $updatedata['uuid'] . "',";
$allupdatenextup = $allupdatenextup . "WHEN '" . $updatedata['uuid'] . "' THEN '" . $updatedata['nextup'] . "' ";
$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); ";
$sqlexec .= "INSERT INTO `$dbname`.`server_usage` (`timestamp`,`clients`,`channel`) VALUES ($nowtime,$server_used_slots,{$serverinfo['virtualserver_channelsonline']}); 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); ";
$sqlexec .= "INSERT INTO `$dbname`.`server_usage` (`timestamp`,`clients`,`channel`) VALUES ($nowtime,$server_used_slots,{$serverinfo['virtualserver_channelsonline']}); ";
}
enter_logfile($cfg,6,"Calc next rankup for offline user [DONE]");
}
@@ -250,7 +430,7 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
}
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) {
if(($snapshot_count_week = $mysqlcon->query("SELECT (SELECT SUM(`count`) FROM `$dbname`.`user_snapshot` WHERE `timestamp`=(SELECT MAX(`timestamp`) FROM `$dbname`.`user_snapshot`)) - (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($cfg,2,"calc_serverstats 20:".print_r($mysqlcon->errorInfo(), true));
}
if($snapshot_count_week['count'] == NULL) {
@@ -263,7 +443,7 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
}
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) {
if(($snapshot_count_month = $mysqlcon->query("SELECT (SELECT SUM(`count`) FROM `$dbname`.`user_snapshot` WHERE `timestamp`=(SELECT MAX(`timestamp`) FROM `$dbname`.`user_snapshot`)) - (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($cfg,2,"calc_serverstats 21:".print_r($mysqlcon->errorInfo(), true));
}
if($snapshot_count_month['count'] == NULL) {
@@ -274,7 +454,7 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
} 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'; ";
$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();
@@ -309,7 +489,7 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$cfg['version_latest_available'] = curl_exec($ch);
curl_close($ch);
if(version_compare($cfg['version_latest_available'], $cfg['version_current_using'], '>') && $cfg['version_latest_available'] != NULL) {
enter_logfile($cfg,4,$lang['upinf']);
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
@@ -325,7 +505,7 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
}
update_rs($mysqlcon,$lang,$cfg,$dbname,$phpcommand);
}
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`='$nowtime' WHERE `job_name`='get_version'; UPDATE `$dbname`.`cfg_params` SET `value`='{$cfg['version_latest_available']}' WHERE `param`='version_latest_available';";
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`=$nowtime WHERE `job_name`='get_version'; UPDATE `$dbname`.`cfg_params` SET `value`='{$cfg['version_latest_available']}' WHERE `param`='version_latest_available';";
}
//Calc Rank
@@ -339,6 +519,8 @@ function calc_serverstats($ts3,$mysqlcon,$cfg,$dbname,$dbtype,$serverinfo,$selec
//UPDATE `user` AS `u` INNER JOIN (SELECT RANK() OVER (ORDER BY `count` DESC) AS `rank`, `uuid` FROM `user` WHERE `except`<2) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`rank`;
}
}
enter_logfile($cfg,6,"calc_serverstats needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
return($sqlexec);
}
?>

View File

@@ -1,26 +1,24 @@
<?PHP
function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$select_arr) {
$starttime = microtime(true);
$nowtime = time();
$sqlexec = '';
if(empty($cfg['rankup_definition'])) {
enter_logfile($cfg,1,"calc_user:".$lang['wiconferr']."Shuttin down!\n\n");
exit;
shutdown($mysqlcon,$cfg,1,"calc_user:".$lang['wiconferr']);
}
if($select_arr['job_check']['calc_user_lastscan']['timestamp'] < ($nowtime - 1800)) {
enter_logfile($cfg,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($cfg,4,"Negative time between now and last scan (Error in your server time!).. reset time difference to zero.");
enter_logfile($cfg,3,"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;
}
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`='$nowtime' WHERE `job_name`='calc_user_lastscan'; ";
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`=$nowtime WHERE `job_name`='calc_user_lastscan'; UPDATE `$dbname`.`user` SET `online`=0 WHERE `online`=1; ";
$multipleonline = $updatedata = $insertdata = array();
krsort($cfg['rankup_definition']);
$yetonline = array();
$updatedata = array();
if(isset($select_arr['admin_addtime']) && count($select_arr['admin_addtime']) != 0) {
foreach($select_arr['admin_addtime'] as $uuid => $value) {
if(isset($select_arr['all_user'][$uuid])) {
@@ -42,16 +40,16 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
}
foreach ($allclients as $client) {
$cldbid = $client['client_database_id'];
$name = $mysqlcon->quote($client['client_nickname'], ENT_QUOTES);
$client_groups_rankup = array();
$name = substr($mysqlcon->quote($client['client_nickname'], ENT_QUOTES),0,30);
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
$sgroups = array_flip(explode(",", $client['client_servergroups']));
if (!isset($yetonline[$uid]) && $client['client_version'] != "ServerQuery" && $client['client_type']!="1") {
if (!isset($multipleonline[$uid]) && $client['client_version'] != "ServerQuery" && $client['client_type']!="1") {
$clientidle = floor($client['client_idle_time'] / 1000);
if(isset($cfg['rankup_ignore_idle_time']) && $clientidle < $cfg['rankup_ignore_idle_time']) {
$clientidle = 0;
}
$yetonline[$uid] = 0;
$multipleonline[$uid] = 0;
if(isset($cfg['rankup_excepted_unique_client_id_list'][$uid])) {
$except = 3;
} elseif(array_intersect_key($sgroups, $cfg['rankup_excepted_group_id_list'])) {
@@ -60,18 +58,15 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
if(isset($select_arr['all_user'][$uid]['except']) && ($select_arr['all_user'][$uid]['except'] == 3 || $select_arr['all_user'][$uid]['except'] == 2) && $cfg['rankup_excepted_mode'] == 2) {
$select_arr['all_user'][$uid]['count'] = 0;
$select_arr['all_user'][$uid]['idle'] = 0;
enter_logfile($cfg,5,sprintf($lang['resettime'], $name, $uid, $cldbid));
enter_logfile($cfg,5,sprintf($lang['resettime'], $name, $uid, $client['client_database_id']));
$sqlexec .= "DELETE FROM `$dbname`.`user_snapshot` WHERE `uuid`='$uid'; ";
}
$except = 0;
}
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 && $cfg['rankup_client_database_id_change_switch'] == 1) {
enter_logfile($cfg,5,sprintf($lang['changedbid'], $name, $uid, $cldbid, $select_arr['all_user'][$uid]['cldbid']));
$idle = $select_arr['all_user'][$uid]['idle'] + $clientidle;
if ($select_arr['all_user'][$uid]['cldbid'] != $client['client_database_id'] && $cfg['rankup_client_database_id_change_switch'] == 1) {
enter_logfile($cfg,5,sprintf($lang['changedbid'], $name, $uid, $client['client_database_id'], $select_arr['all_user'][$uid]['cldbid']));
$count = 1;
$idle = 0;
} else {
@@ -87,12 +82,11 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
if ($nowtime > $select_arr['all_user'][$uid]['boosttime'] + $boost['time']) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientDel($boost['group'], $cldbid);
$ts3->serverGroupClientDel($boost['group'], $client['client_database_id']);
$boosttime = 0;
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $select_arr['groups'][$boost['group']]['sgidname'], $boost['group'], $name, $uid, $cldbid));
}
catch (Exception $e) {
enter_logfile($cfg,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']));
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $select_arr['groups'][$boost['group']]['sgidname'], $boost['group'], $name, $uid, $client['client_database_id']));
} catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $select_arr['groups'][$select_arr['all_user'][$uid]['grpid']]['sgidname'], $select_arr['all_user'][$uid]['grpid']));
}
}
}
@@ -117,12 +111,14 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
$activetime = $count;
}
$dtT = new DateTime("@".round($activetime));
foreach ($cfg['rankup_definition'] as $time => $groupid) {
if (isset($sgroups[$groupid])) {
$grpid = $groupid;
break;
foreach($sgroups as $clientgroup => $dummy) {
if(isset($cfg['rankup_definition_flipped'][$clientgroup])) {
#enter_logfile($cfg,5,"Client ".$name." has group ".$clientgroup);
$client_groups_rankup[$clientgroup] = 0;
}
}
$grpcount=0;
foreach ($cfg['rankup_definition'] as $time => $groupid) {
$grpcount++;
@@ -133,53 +129,64 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
$except = 1;
}
} elseif ($activetime > $time && !isset($cfg['rankup_excepted_unique_client_id_list'][$uid]) && !array_intersect_key($sgroups, $cfg['rankup_excepted_group_id_list'])) {
if ($select_arr['all_user'][$uid]['grpid'] != $groupid) {
if ($select_arr['all_user'][$uid]['grpid'] != NULL && isset($sgroups[$select_arr['all_user'][$uid]['grpid']])) {
if (!isset($sgroups[$groupid])) {
#if ($select_arr['all_user'][$uid]['grpid'] != $groupid) {
if ($select_arr['all_user'][$uid]['grpid'] != NULL && $select_arr['all_user'][$uid]['grpid'] != 0 && isset($sgroups[$select_arr['all_user'][$uid]['grpid']])) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientDel($select_arr['all_user'][$uid]['grpid'], $cldbid);
enter_logfile($cfg,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($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $cldbid, $select_arr['groups'][$groupid]['sgidname'], $groupid));
$ts3->serverGroupClientDel($select_arr['all_user'][$uid]['grpid'], $client['client_database_id']);
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $select_arr['groups'][$select_arr['all_user'][$uid]['grpid']]['sgidname'], $select_arr['all_user'][$uid]['grpid'], $name, $uid, $client['client_database_id']));
if(isset($client_groups_rankup[$select_arr['all_user'][$uid]['grpid']])) unset($client_groups_rankup[$select_arr['all_user'][$uid]['grpid']]);
} catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $select_arr['groups'][$groupid]['sgidname'], $groupid));
}
}
if (!isset($sgroups[$groupid])) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientAdd($groupid, $cldbid);
$grpsince = $nowtime;
enter_logfile($cfg,5,sprintf($lang['sgrpadd'], $select_arr['groups'][$groupid]['sgidname'], $groupid, $name, $uid, $cldbid));
}
catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $cldbid, $select_arr['groups'][$groupid]['sgidname'], $groupid));
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientAdd($groupid, $client['client_database_id']);
$select_arr['all_user'][$uid]['grpsince'] = $nowtime;
enter_logfile($cfg,5,sprintf($lang['sgrpadd'], $select_arr['groups'][$groupid]['sgidname'], $groupid, $name, $uid, $client['client_database_id']));
if ($cfg['rankup_message_to_user_switch'] == 1) {
$days = $dtF->diff($dtT)->format('%a');
$hours = $dtF->diff($dtT)->format('%h');
$mins = $dtF->diff($dtT)->format('%i');
$secs = $dtF->diff($dtT)->format('%s');
sendmessage($ts3, $cfg, $uid, sprintf($cfg['rankup_message_to_user'],$days,$hours,$mins,$secs,$select_arr['groups'][$groupid]['sgidname'],$client['client_nickname']), sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $select_arr['groups'][$groupid]['sgidname'],$groupid), 2);
}
} catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $select_arr['groups'][$groupid]['sgidname'], $groupid));
}
$grpid = $groupid;
if ($cfg['rankup_message_to_user_switch'] == 1) {
$days = $dtF->diff($dtT)->format('%a');
$hours = $dtF->diff($dtT)->format('%h');
$mins = $dtF->diff($dtT)->format('%i');
$secs = $dtF->diff($dtT)->format('%s');
sendmessage($ts3, $cfg, $uid, sprintf($cfg['rankup_message_to_user'],$days,$hours,$mins,$secs,$select_arr['groups'][$groupid]['sgidname'],$client['client_nickname']), sprintf($lang['sgrprerr'], $name, $uid, $cldbid, $select_arr['groups'][$groupid]['sgidname'],$groupid), 2);
}
$select_arr['all_user'][$uid]['grpid'] = $groupid;
}
if($grpcount == 1) {
$nextup = 0;
$select_arr['all_user'][$uid]['nextup'] = 0;
}
break;
} else {
$nextup = $time - $activetime;
$select_arr['all_user'][$uid]['nextup'] = $time - $activetime;
}
}
foreach($client_groups_rankup as $removegroup => $dummy) {
if($removegroup != NULL && $removegroup != 0 && $removegroup != $select_arr['all_user'][$uid]['grpid']){
try {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGroupClientDel($removegroup, $client['client_database_id']);
enter_logfile($cfg,5,sprintf("Removed WRONG servergroup %s (ID: %s) from user %s (unique Client-ID: %s; Client-database-ID %s).", $select_arr['groups'][$removegroup]['sgidname'], $removegroup, $name, $uid, $client['client_database_id']));
} catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $select_arr['groups'][$groupid]['sgidname'], $groupid));
}
}
}
unset($client_groups_rankup);
$updatedata[] = array(
"uuid" => $mysqlcon->quote($client['client_unique_identifier'], ENT_QUOTES),
"cldbid" => $cldbid,
"cldbid" => $client['client_database_id'],
"count" => $count,
"name" => $name,
"lastseen" => $nowtime,
"grpid" => $grpid,
"nextup" => $nextup,
"grpid" => $select_arr['all_user'][$uid]['grpid'],
"nextup" => $select_arr['all_user'][$uid]['nextup'],
"idle" => $idle,
"cldgroup" => $client['client_servergroups'],
"boosttime" => $boosttime,
@@ -187,51 +194,63 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
"nation" => $client['client_country'],
"version" => $client['client_version'],
"except" => $except,
"grpsince" => $grpsince,
"grpsince" => $select_arr['all_user'][$uid]['grpsince'],
"cid" => $client['cid']
);
} else {
$grpid = '0';
$select_arr['all_user'][$uid]['grpid'] = '0';
foreach ($cfg['rankup_definition'] as $time => $groupid) {
if (isset($sgroups[$groupid])) {
$grpid = $groupid;
$select_arr['all_user'][$uid]['grpid'] = $groupid;
break;
}
}
$updatedata[] = array(
$insertdata[] = array(
"uuid" => $mysqlcon->quote($client['client_unique_identifier'], ENT_QUOTES),
"cldbid" => $cldbid,
"count" => "0",
"cldbid" => $client['client_database_id'],
"count" => 0,
"name" => $name,
"lastseen" => $nowtime,
"grpid" => $grpid,
"grpid" => $select_arr['all_user'][$uid]['grpid'],
"nextup" => (key($cfg['rankup_definition']) - 1),
"idle" => "0",
"idle" => 0,
"cldgroup" => $client['client_servergroups'],
"boosttime" => "0",
"boosttime" => 0,
"platform" => $client['client_platform'],
"nation" => $client['client_country'],
"version" => $client['client_version'],
"firstcon" => $client['client_created'],
"firstcon" => $nowtime,
"except" => $except,
"grpsince" => "0",
"grpsince" => 0,
"cid" => $client['cid']
);
enter_logfile($cfg,5,sprintf($lang['adduser'], $name, $uid, $cldbid));
enter_logfile($cfg,5,sprintf($lang['adduser'], $name, $uid, $client['client_database_id']));
}
}
}
unset($yetonline);
unset($multipleonline,$allclients,$client,$select_arr);
if ($updatedata != NULL) {
$sqlinsertvalues = '';
foreach ($updatedata as $updatearr) {
$sqlinsertvalues .= "(".$updatearr['uuid'].",'".$updatearr['cldbid']."','".$updatearr['count']."',".$updatearr['name'].",'".$updatearr['lastseen']."','".$updatearr['grpid']."','".$updatearr['nextup']."','".$updatearr['idle']."','".$updatearr['cldgroup']."','".$updatearr['boosttime']."','".$updatearr['platform']."','".$updatearr['nation']."','".$updatearr['version']."','".$updatearr['except']."','".$updatearr['grpsince']."','".$updatearr['cid']."',1),";
$sqlinsertvalues .= "(".$updatearr['uuid'].",".$updatearr['cldbid'].",".$updatearr['count'].",".$updatearr['name'].",".$updatearr['lastseen'].",".$updatearr['grpid'].",".$updatearr['nextup'].",".$updatearr['idle'].",'".$updatearr['cldgroup']."',".$updatearr['boosttime'].",'".$updatearr['platform']."','".$updatearr['nation']."','".$updatearr['version']."',".$updatearr['except'].",".$updatearr['grpsince'].",".$updatearr['cid'].",1),";
}
$sqlinsertvalues = substr($sqlinsertvalues, 0, -1);
$sqlexec .= "UPDATE `$dbname`.`user` SET `online`='0'; INSERT INTO `$dbname`.`user` (`uuid`,`cldbid`,`count`,`name`,`lastseen`,`grpid`,`nextup`,`idle`,`cldgroup`,`boosttime`,`platform`,`nation`,`version`,`except`,`grpsince`,`cid`,`online`) VALUES $sqlinsertvalues ON DUPLICATE KEY UPDATE `cldbid`=VALUES(`cldbid`),`count`=VALUES(`count`),`name`=VALUES(`name`),`lastseen`=VALUES(`lastseen`),`grpid`=VALUES(`grpid`),`nextup`=VALUES(`nextup`),`idle`=VALUES(`idle`),`cldgroup`=VALUES(`cldgroup`),`boosttime`=VALUES(`boosttime`),`platform`=VALUES(`platform`),`nation`=VALUES(`nation`),`version`=VALUES(`version`),`except`=VALUES(`except`),`grpsince`=VALUES(`grpsince`),`cid`=VALUES(`cid`),`online`=VALUES(`online`); ";
$sqlexec .= "INSERT INTO `$dbname`.`user` (`uuid`,`cldbid`,`count`,`name`,`lastseen`,`grpid`,`nextup`,`idle`,`cldgroup`,`boosttime`,`platform`,`nation`,`version`,`except`,`grpsince`,`cid`,`online`) VALUES $sqlinsertvalues ON DUPLICATE KEY UPDATE `cldbid`=VALUES(`cldbid`),`count`=VALUES(`count`),`name`=VALUES(`name`),`lastseen`=VALUES(`lastseen`),`grpid`=VALUES(`grpid`),`nextup`=VALUES(`nextup`),`idle`=VALUES(`idle`),`cldgroup`=VALUES(`cldgroup`),`boosttime`=VALUES(`boosttime`),`platform`=VALUES(`platform`),`nation`=VALUES(`nation`),`version`=VALUES(`version`),`except`=VALUES(`except`),`grpsince`=VALUES(`grpsince`),`cid`=VALUES(`cid`),`online`=VALUES(`online`); ";
unset($updatedata, $sqlinsertvalues);
}
if ($insertdata != NULL) {
$sqlinsertvalues = '';
foreach ($insertdata as $updatearr) {
$sqlinsertvalues .= "(".$updatearr['uuid'].",".$updatearr['cldbid'].",".$updatearr['count'].",".$updatearr['name'].",".$updatearr['lastseen'].",".$updatearr['grpid'].",".$updatearr['nextup'].",".$updatearr['idle'].",'".$updatearr['cldgroup']."',".$updatearr['boosttime'].",'".$updatearr['platform']."','".$updatearr['nation']."','".$updatearr['version']."',".$updatearr['except'].",".$updatearr['grpsince'].",".$updatearr['cid'].",1,".$updatearr['firstcon']."),";
}
$sqlinsertvalues = substr($sqlinsertvalues, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`user` (`uuid`,`cldbid`,`count`,`name`,`lastseen`,`grpid`,`nextup`,`idle`,`cldgroup`,`boosttime`,`platform`,`nation`,`version`,`except`,`grpsince`,`cid`,`online`,`firstcon`) VALUES $sqlinsertvalues ON DUPLICATE KEY UPDATE `cldbid`=VALUES(`cldbid`),`count`=VALUES(`count`),`name`=VALUES(`name`),`lastseen`=VALUES(`lastseen`),`grpid`=VALUES(`grpid`),`nextup`=VALUES(`nextup`),`idle`=VALUES(`idle`),`cldgroup`=VALUES(`cldgroup`),`boosttime`=VALUES(`boosttime`),`platform`=VALUES(`platform`),`nation`=VALUES(`nation`),`version`=VALUES(`version`),`except`=VALUES(`except`),`grpsince`=VALUES(`grpsince`),`cid`=VALUES(`cid`),`online`=VALUES(`online`),`firstcon`=VALUES(`firstcon`); ";
unset($insertdata, $sqlinsertvalues);
}
enter_logfile($cfg,6,"calc_user needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
return($sqlexec);
}
?>

View File

@@ -1,5 +1,6 @@
<?PHP
function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,$select_arr) {
$starttime = microtime(true);
$sqlexec = '';
$max_timestamp = key($select_arr['max_timestamp_user_snapshot']);
$min_timestamp_week = key($select_arr['usersnap_min_week']);
@@ -20,6 +21,7 @@ function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,$select_arr) {
foreach ($sqlhis as $uuid => $userstats) {
$uuids .= "'".$uuid."',";
}
unset($userstats,$uuid);
$uuids = substr($uuids, 0, -1);
if(isset($sqlhis) && $max_timestamp != NULL && $min_timestamp_week != NULL && $min_timestamp_month != NULL) {
@@ -34,6 +36,7 @@ function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,$select_arr) {
enter_logfile($cfg,2,"calc_userstats 7:".print_r($mysqlcon->errorInfo(), true));
}
unset($uuids,$job_begin,$max_timestamp,$min_timestamp_week,$min_timestamp_month);
$allupdateuuid = '';
foreach ($sqlhis as $uuid => $userstats) {
@@ -60,21 +63,48 @@ function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,$select_arr) {
$active_month = 0;
}
$clientdesc = $mysqlcon->quote($clientinfo['client_description'], ENT_QUOTES);;
$allupdateuuid .= "('" . $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 . "),";
$allupdateuuid .= "('$uuid',$count_week,$count_month,$idle_week,$idle_month,$active_week,$active_month,{$clientinfo['client_totalconnections']},'{$clientinfo['client_base64HashClientUID']}',{$clientinfo['client_total_bytes_uploaded']},{$clientinfo['client_total_bytes_downloaded']},$clientdesc),";
} catch (Exception $e) {
enter_logfile($cfg,6,$e->getCode() . ': ' . $e->getMessage()."; Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") was missing in TS database, perhaps its already deleted. Run !clean to correct this.");
if($e->getCode() == 512) {
enter_logfile($cfg,6,"Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") known by Ranksystem is missing in TS database, perhaps its already deleted or cldbid changed. Try to search for client by uuid.");
try {
$getcldbid = $ts3->clientFindDb($uuid, TRUE);
if($getcldbid[0] != $userstats['cldbid']) {
enter_logfile($cfg,4," Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") known by the Ranksystem changed its cldbid. New cldbid is ".$getcldbid[0].".");
if($cfg['rankup_client_database_id_change_switch'] == 1) {
$sqlexec .= "UPDATE `$dbname`.`user` SET `count`=0,`idle`=0 WHERE `uuid`='$uuid'; UPDATE `$dbname`.`stats_user` SET `count_week`=0,`count_month`=0,`idle_week`=0,`idle_month`=0,`achiev_time`=0,`achiev_time_perc`=0,`active_week`=0,`active_month`=0 WHERE `uuid`='$uuid'; DELETE FROM `$dbname`.`user_snapshot` WHERE `uuid`='$uuid'; ";
enter_logfile($cfg,4," ".sprintf($lang['changedbid'], $userstats['name'], $uuid, $userstats['cldbid'], $getcldbid[0]));
} else {
$sqlexec .= "UPDATE `$dbname`.`user` SET `cldbid`={$getcldbid[0]} WHERE `uuid`='$uuid'; ";
enter_logfile($cfg,4," Store new cldbid ".$getcldbid[0]." for client (uuid: ".$uuid." old cldbid: ".$userstats['cldbid'].")");
}
} else {
enter_logfile($cfg,3," Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") is missing in TS database, but TeamSpeak answers on question with the same cldbid (".$getcldbid[0].").. It's weird!");
}
} catch (Exception $e) {
if($e->getCode() == 2568) {
enter_logfile($cfg,4,$e->getCode() . ': ' . $e->getMessage()."; Error due command clientdbfind (permission: b_virtualserver_client_dbsearch needed).");
} else {
enter_logfile($cfg,6,$e->getCode() . ': ' . $e->getMessage()."; Client (uuid: ".$uuid." cldbid: ".$userstats['cldbid'].") is missing in TS database, it seems to be deleted. Run !clean to correct this.");
}
}
} else {
enter_logfile($cfg,2,$lang['errorts3'].$e->getCode().': '.$e->getMessage()."; Error due command clientdbinfo (permission: b_virtualserver_client_dbinfo needed).");
}
}
}
unset($sqlhis, $userdataweekbegin, $userdataend, $userdatamonthbegin);
unset($sqlhis,$userdataweekbegin,$userdataend,$userdatamonthbegin,$clientinfo,$count_week,$idle_week,$active_week,$count_month,$idle_month,$active_month,$clientdesc);
if ($allupdateuuid != '') {
$allupdateuuid = substr($allupdateuuid, 0, -1);
$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 $allupdateuuid ON DUPLICATE KEY UPDATE `rank`=VALUES(`rank`),`count_week`=VALUES(`count_week`),`count_month`=VALUES(`count_month`),`idle_week`=VALUES(`idle_week`),`idle_month`=VALUES(`idle_month`),`active_week`=VALUES(`active_week`),`active_month`=VALUES(`active_month`),`total_connections`=VALUES(`total_connections`),`base64hash`=VALUES(`base64hash`),`client_total_up`=VALUES(`client_total_up`),`client_total_down`=VALUES(`client_total_down`),`client_description`=VALUES(`client_description`); ";
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`=$job_end WHERE `job_name`='calc_user_limit'; INSERT INTO `$dbname`.`stats_user` (`uuid`,`count_week`,`count_month`,`idle_week`,`idle_month`,`active_week`,`active_month`,`total_connections`,`base64hash`,`client_total_up`,`client_total_down`,`client_description`) VALUES $allupdateuuid ON DUPLICATE KEY UPDATE `count_week`=VALUES(`count_week`),`count_month`=VALUES(`count_month`),`idle_week`=VALUES(`idle_week`),`idle_month`=VALUES(`idle_month`),`active_week`=VALUES(`active_week`),`active_month`=VALUES(`active_month`),`total_connections`=VALUES(`total_connections`),`base64hash`=VALUES(`base64hash`),`client_total_up`=VALUES(`client_total_up`),`client_total_down`=VALUES(`client_total_down`),`client_description`=VALUES(`client_description`); ";
unset($allupdateuuid);
} else {
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`=$job_end WHERE `job_name`='calc_user_limit'; ";
}
}
enter_logfile($cfg,6,"calc_userstats needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
return($sqlexec);
}
?>

View File

@@ -1,6 +1,6 @@
<?PHP
function check_db($mysqlcon,$lang,$cfg,$dbname) {
$cfg['version_latest_available'] = '1.3.0';
$cfg['version_latest_available'] = '1.3.1';
enter_logfile($cfg,5,"Check Ranksystem database for updates...");
function set_new_version($mysqlcon,$cfg,$dbname) {
@@ -16,15 +16,15 @@ function check_db($mysqlcon,$lang,$cfg,$dbname) {
function old_files($cfg) {
$del_folder = array('icons/','libs/ts3_lib/Adapter/Blacklist/','libs/ts3_lib/Adapter/TSDNS/','libs/ts3_lib/Adapter/Update/','libs/fonts/');
$del_files = array('install.php','libs/combined_stats.css','libs/combined_stats.js','webinterface/admin.php','libs/ts3_lib/Adapter/Blacklist/Exception.php','libs/ts3_lib/Adapter/TSDNS/Exception.php','libs/ts3_lib/Adapter/Update/Exception.php','libs/ts3_lib/Adapter/Blacklist.php','libs/ts3_lib/Adapter/TSDNS.php','libs/ts3_lib/Adapter/Update.php');
function rmdir_recursive($folder) {
$del_files = array('install.php','libs/combined_stats.css','libs/combined_stats.js','webinterface/admin.php','libs/ts3_lib/Adapter/Blacklist/Exception.php','libs/ts3_lib/Adapter/TSDNS/Exception.php','libs/ts3_lib/Adapter/Update/Exception.php','libs/ts3_lib/Adapter/Blacklist.php','libs/ts3_lib/Adapter/TSDNS.php','libs/ts3_lib/Adapter/Update.php','languages/core_ar.php','languages/core_cz.php','languages/core_de.php','languages/core_en.php','languages/core_es.php','languages/core_fr.php','languages/core_it.php','languages/core_nl.php','languages/core_pl.php','languages/core_pt.php','languages/core_ro.php','languages/core_ru.php');
function rmdir_recursive($folder,$cfg) {
foreach(scandir($folder) as $file) {
if ('.' === $file || '..' === $file) continue;
if (is_dir("$folder/$file")) {
rmdir_recursive("$folder/$file");
if (is_dir($folder.$file)) {
rmdir_recursive($folder.$file);
} else {
if(!unlink("$folder/$file")) {
enter_logfile($cfg,4,"Unnecessary file, please delete it from your webserver: ".$folder."/".$file);
if(!unlink($folder.$file)) {
enter_logfile($cfg,4,"Unnecessary file, please delete it from your webserver: ".$folder.$file);
}
}
}
@@ -35,12 +35,12 @@ function check_db($mysqlcon,$lang,$cfg,$dbname) {
foreach($del_folder as $folder) {
if(is_dir(substr(__DIR__,0,-4).$folder)) {
rmdir_recursive(substr(__DIR__,0,-4).$folder);
rmdir_recursive(substr(__DIR__,0,-4).$folder,$cfg);
}
}
foreach($del_files as $file) {
if(is_file(substr(__DIR__,0,-4).$file)) {
if(!unlink($file)) {
if(!unlink(substr(__DIR__,0,-4).$file)) {
enter_logfile($cfg,4,"Unnecessary file, please delete it from your webserver: ".$file);
}
}
@@ -281,12 +281,6 @@ function check_db($mysqlcon,$lang,$cfg,$dbname) {
}
}
if(version_compare($cfg['version_current_using'], '1.3.0', '<')) {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='".time()."' WHERE `job_name`='last_update';") === false) { } else {
enter_logfile($cfg,4," [1.3.0] Stored timestamp of last update successfully.");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`admin_addtime`;") === false) { }
if($mysqlcon->exec("DELETE FROM `$dbname`.`addon_assign_groups`;") === false) { }
if(empty($cfg['teamspeak_host_address']) || $cfg['teamspeak_host_address'] == '') {
enter_logfile($cfg,4," [1.3.0] Table cfg_params needs to be repaired.");
$oldconfigs = $mysqlcon->query("SELECT * FROM `$dbname`.`config`")->fetch();
@@ -329,6 +323,18 @@ function check_db($mysqlcon,$lang,$cfg,$dbname) {
if($mysqlcon->exec("DROP TABLE `$dbname`.`config`;") === false) { } else {
enter_logfile($cfg,4," [1.3.0] Dropped old table config.");
}
}
if(version_compare($cfg['version_current_using'], '1.3.1', '<')) {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='".time()."' WHERE `job_name`='last_update';") === false) { } else {
enter_logfile($cfg,4," [1.3.1] Stored timestamp of last update successfully.");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`admin_addtime`;") === false) { }
if($mysqlcon->exec("DELETE FROM `$dbname`.`addon_assign_groups`;") === false) { }
if($mysqlcon->exec("INSERT INTO `$dbname`.`job_check` (`job_name`,`timestamp`) VALUES ('reset_user_time', '0'),('reset_user_delete', '0'),('reset_group_withdraw', '0'),('reset_webspace_cache', '0'),('reset_usage_graph', '0'),('reset_stop_after', '0');") === false) { } else {
enter_logfile($cfg,4," [1.3.1] Added new job_check values.");
}
if($mysqlcon->exec("CREATE INDEX `snapshot_timestamp` ON `$dbname`.`user_snapshot` (`timestamp`)") === false) { }
if($mysqlcon->exec("CREATE INDEX `serverusage_timestamp` ON `$dbname`.`server_usage` (`timestamp`)") === false) { }

View File

@@ -1,5 +1,6 @@
<?PHP
function clean($ts3,$mysqlcon,$lang,$cfg,$dbname,$select_arr) {
$starttime = microtime(true);
$nowtime = time();
$sqlexec = '';
@@ -28,7 +29,7 @@ function clean($ts3,$mysqlcon,$lang,$cfg,$dbname,$select_arr) {
$single_uuid = $uuidts['client_unique_identifier']->toString();
$uidarrts[$single_uuid]= 1;
}
unset($clientdblist);
unset($clientdblist,$getclientdblist,$start,$break,$single_uuid);
foreach($select_arr['all_user'] as $uuid => $value) {
if(isset($uidarrts[$uuid])) {
@@ -38,10 +39,9 @@ function clean($ts3,$mysqlcon,$lang,$cfg,$dbname,$select_arr) {
$countdel++;
}
}
unset($uidarrts);
enter_logfile($cfg,4," ".sprintf($lang['cleants'], $countts, $count_tsuser['count']));
enter_logfile($cfg,4," ".sprintf($lang['cleanrs'], count($select_arr['all_user'])));
unset($uidarrts,$count_tsuser,$countts);
if(isset($deleteuuids)) {
$alldeldata = '';
$fsfilelist = opendir(substr(__DIR__,0,-4).'avatars/');
@@ -50,7 +50,7 @@ function clean($ts3,$mysqlcon,$lang,$cfg,$dbname,$select_arr) {
$fsfilelistarray[$fsfile] = filemtime(substr(__DIR__,0,-4).'avatars/'.$fsfile);
}
}
unset($fsfilelist);
unset($fsfilelist,$fsfile);
$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) {
@@ -69,7 +69,7 @@ function clean($ts3,$mysqlcon,$lang,$cfg,$dbname,$select_arr) {
}
}
}
unset($$deleteuuids);
unset($deleteuuids,$avatarfilepath,$convert,$uuidasbase16);
$alldeldata = substr($alldeldata, 0, -1);
$alldeldata = "(".$alldeldata.")";
if ($alldeldata != '') {
@@ -93,6 +93,7 @@ function clean($ts3,$mysqlcon,$lang,$cfg,$dbname,$select_arr) {
enter_logfile($cfg,4,$lang['clean0003']);
}
enter_logfile($cfg,6,"clean needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
return($sqlexec);
}
?>

View File

@@ -21,8 +21,9 @@ function event_userenter(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
break;
}
}
unset($clientlist,$host);
if(!isset($ip)) {
enter_logfile($cfg,6,"New user (".$event['client_nickname']." [".$event['client_database_id']."]) joined the server, but can't found a valid IP address.");
enter_logfile($cfg,6,"New user ({$event['client_nickname']} [{$event['client_database_id']}]) joined the server, but can't found a valid IP address.");
} else {
if($cfg['rankup_hash_ip_addresses_mode'] == 1) {
$hash = password_hash($ip, PASSWORD_DEFAULT);
@@ -42,11 +43,11 @@ function event_userenter(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
$uuid = htmlspecialchars($event['client_unique_identifier'], ENT_QUOTES);
if(isset($sqlhashs[$uuid])) {
$sqlexec3 .= "UPDATE `$dbname`.`user_iphash` SET `iphash`='".$hash."',`ip`='".$ip."' WHERE `uuid`='".$event['client_unique_identifier']."'; ";
enter_logfile($cfg,6,"Userenter: UPDATE `$dbname`.`user_iphash` SET `iphash`='".$hash."',`ip`='".$ip."' WHERE `uuid`='".$event['client_unique_identifier']."'; ");
$sqlexec3 .= "UPDATE `$dbname`.`user_iphash` SET `iphash`='$hash',`ip`='$ip' WHERE `uuid`='{$event['client_unique_identifier']}'; ";
enter_logfile($cfg,6,"Userenter: UPDATE `$dbname`.`user_iphash` SET `iphash`='$hash',`ip`='$ip' WHERE `uuid`='{$event['client_unique_identifier']}'; ");
} else {
$sqlexec3 .= "INSERT INTO `$dbname`.`user_iphash` (`uuid`,`iphash`,`ip`) VALUES ('".$event['client_unique_identifier']."','".$hash."','".$ip."'); ";
enter_logfile($cfg,6,"Userenter: INSERT INTO `$dbname`.`user_iphash` (`uuid`,`iphash`,`ip`) VALUES ('".$event['client_unique_identifier']."','".$hash."','".$ip."'); ");
$sqlexec3 .= "INSERT INTO `$dbname`.`user_iphash` (`uuid`,`iphash`,`ip`) VALUES ('{$event['client_unique_identifier']}','$hash','$ip'); ";
enter_logfile($cfg,6,"Userenter: INSERT INTO `$dbname`.`user_iphash` (`uuid`,`iphash`,`ip`) VALUES ('{$event['client_unique_identifier']}','$hash','$ip'); ");
}
if($mysqlcon->exec($sqlexec3) === false) {
enter_logfile($cfg,2,"event_userenter 3:".print_r($mysqlcon->errorInfo(), true));

View File

@@ -1,5 +1,6 @@
<?PHP
function get_avatars($ts3,$cfg) {
$starttime = microtime(true);
try {
usleep($cfg['teamspeak_query_command_delay']);
$tsfilelist = $ts3->channelFileList($cid="0", $cpw="", $path="/");
@@ -38,8 +39,14 @@ function get_avatars($ts3,$cfg) {
}
}
}
if((microtime(true) - $starttime) > 5) {
enter_logfile($cfg,6,"get_avatars needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
return;
}
}
unset($fsfilelistarray);
}
enter_logfile($cfg,6,"get_avatars needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
}
?>

View File

@@ -54,31 +54,43 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
}
}
}
krsort($cfg['rankup_definition']);
return;
}
if(strstr($event["msg"], '!version')) {
if(version_compare($cfg['version_latest_available'], $cfg['version_current_using'], '>') && $cfg['version_latest_available'] != '') {
sendmessage($host,$cfg,$event["invokeruid"],sprintf($lang['upmsg'], $cfg['version_current_using'], $cfg['version_latest_available'], 'https://ts-ranksystem.com/#changelog'));
} else {
sendmessage($host,$cfg,$event["invokeruid"],sprintf($lang['msg0001'], $cfg['version_current_using']));
}
return;
}
if(strstr($event["msg"], '!help') || strstr($event["msg"], '!info') || strstr($event["msg"], '!commands') || strstr($event["msg"], '!cmd')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0002']);
return;
}
if((strstr($event["msg"], '!shutdown') || strstr($event["msg"], '!quit') || strstr($event["msg"], '!stop')) && $admin == 1) {
enter_logfile($cfg,5,sprintf($lang['msg0004'], $event["invokername"], $event["invokeruid"]));
$path = substr(__DIR__, 0, -4);
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0005']);
exec($phpcommand." ".$path."worker.php stop");
if (substr(php_uname(), 0, 7) == "Windows") {
exec("start ".$phpcommand." ".$path."worker.php stop");
file_put_contents(substr(__DIR__,0,-4).'logs\autostart_deactivated',"");
} else {
exec($phpcommand." ".$path."worker.php stop > /dev/null &");
file_put_contents(substr(__DIR__,0,-4).'logs/autostart_deactivated',"");
}
shutdown($mysql,$cfg,4,"Stop command received!");
} elseif (strstr($event["msg"], '!shutdown') || strstr($event["msg"], '!quit') || strstr($event["msg"], '!stop')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
return;
}
if((strstr($event["msg"], '!restart') || strstr($event["msg"], '!reboot')) && $admin == 1) {
enter_logfile($cfg,5,sprintf($lang['msg0007'], $event["invokername"], $event["invokeruid"]));
enter_logfile($cfg,5,sprintf($lang['msg0007'], $event["invokername"], $event["invokeruid"], "restart"));
$path = substr(__DIR__, 0, -4);
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0006']);
if (substr(php_uname(), 0, 7) == "Windows") {
@@ -86,45 +98,61 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
} else {
exec($phpcommand." ".$path."worker.php restart > /dev/null 2>/dev/null &");
}
return;
} elseif (strstr($event["msg"], '!restart') || strstr($event["msg"], '!reboot')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
return;
}
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($cfg,4,"handle_messages 13:".print_r($mysqlcon->errorInfo(), true));
}
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0008']);
return;
} elseif(strstr($event["msg"], '!checkupdate') || strstr($event["msg"], '!update')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
return;
}
if((strstr($event["msg"], '!clean')) && $admin == 1) {
enter_logfile($cfg,5,sprintf($lang['msg0007'], $event["invokername"], $event["invokeruid"], "clean"));
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='0' WHERE `job_name` IN ('clean_db','clean_clients')") === false) {
enter_logfile($cfg,4,"handle_messages 13:".print_r($mysqlcon->errorInfo(), true));
}
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0009'] ." ". $lang['msg0010']);
return;
} elseif(strstr($event["msg"], '!clean')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
return;
}
if((strstr($event["msg"], '!reloadgroups') || strstr($event["msg"], '!reloadicons')) && $admin == 1) {
if($mysqlcon->exec("DELETE FROM `$dbname`.`groups`") === false) {
enter_logfile($cfg,4,"handle_messages 14:".print_r($mysqlcon->errorInfo(), true));
}
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0011'] ." ". $lang['msg0010']);
} elseif(strstr($event["msg"], '!clean')) {
return;
} elseif(strstr($event["msg"], '!reloadgroups')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
return;
}
if(strstr($event["msg"], '!online') || strstr($event["msg"], '!uptime')) {
sendmessage($host, $cfg, $event["invokeruid"], sprintf("Bot is online since %s, now %s.", date('Y-m-d H:i:s',$cfg['temp_last_botstart']), (new DateTime("@0"))->diff(new DateTime("@".(time()-$cfg['temp_last_botstart'])))->format($cfg['default_date_format'])));
sendmessage($host, $cfg, $event["invokeruid"], sprintf("Bot is online since %s, now %s.", (DateTime::createFromFormat('U', $cfg['temp_last_botstart'])->setTimeZone(new DateTimeZone($cfg['logs_timezone']))->format("Y-m-d H:i:s")), (new DateTime("@0"))->diff(new DateTime("@".(time()-$cfg['temp_last_botstart'])))->format($cfg['default_date_format'])));
return;
}
if(strstr($event["msg"], '!runtime') || strstr($event["msg"], '!runtimes')) {
sendmessage($host, $cfg, $event["invokeruid"], sprintf("Last 10 runtimes (in seconds):\n%s", str_replace(";","\n",$cfg['temp_last_laptime'])));
sendmessage($host, $cfg, $event["invokeruid"], sprintf("Last 10 runtimes (in seconds):\n%s\n\nØ %s sec. (Σ %s)", str_replace(";","\n",$cfg['temp_last_laptime']), round(($cfg['temp_whole_laptime'] / $cfg['temp_count_laptime']),5), $cfg['temp_count_laptime']));
return;
}
if(strstr($event["msg"], '!memory')) {
sendmessage($host, $cfg, $event["invokeruid"], sprintf("Allocated memory of PHP for the Ranksystem Bot..\ncurrent using: %s KiB\npeak using: %s KiB", round((memory_get_usage()/1024),2), round((memory_get_peak_usage()/1024),2)));
return;
}
if((strstr($event["msg"], '!logs') || strstr($event["msg"], '!log')) && $admin == 1) {
$parameter = explode(' ', $event["msg"]);
if(isset($parameter[1]) && $parameter[1] > 0 && $parameter[1] < 1000) {
@@ -132,7 +160,7 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
} else {
$number_lines = 5;
}
$filters = explode(',', 'CRITICAL,ERROR,WARNING,NOTICE,INFO,DEBUG');
$filters = explode(',', 'CRITICAL,ERROR,WARNING,NOTICE,INFO,DEBUG,NONE');
$filter2 = $lastfilter = '';
$lines=array();
if(file_exists($cfg['logs_path']."ranksystem.log")) {
@@ -162,6 +190,7 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
if (count($lines)>=$number_lines) {
break 2;
}
break;
}
}
}

270
jobs/reset_rs.php Normal file
View File

@@ -0,0 +1,270 @@
<?PHP
function reset_rs($ts3,$mysqlcon,$lang,$cfg,$dbname,$select_arr) {
$starttime = microtime(true);
if (in_array($select_arr['job_check']['reset_user_time']['timestamp'], ["1","2"], true) || in_array($select_arr['job_check']['reset_user_delete']['timestamp'], ["1","2"], true) || in_array($select_arr['job_check']['reset_group_withdraw']['timestamp'], ["1","2"], true) || in_array($select_arr['job_check']['reset_webspace_cache']['timestamp'], ["1","2"], true) || in_array($select_arr['job_check']['reset_usage_graph']['timestamp'], ["1","2"], true)) {
enter_logfile($cfg,4,"Reset job(s) started");
$err_cnt = 0;
if (in_array($select_arr['job_check']['reset_group_withdraw']['timestamp'], ["1","2"], true)) {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='2' WHERE `job_name`='reset_group_withdraw';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err_cnt++;
} else {
enter_logfile($cfg,4," Started job '".$lang['wihladm32']."'");
}
krsort($cfg['rankup_definition']);
if (($all_clients = $mysqlcon->query("SELECT cldbid,uuid,name FROM `$dbname`.`user`")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
shutdown($mysqlcon,$cfg,1,"Select on DB failed: ".print_r($mysqlcon->errorInfo(), true));
}
foreach ($cfg['rankup_definition'] as $time => $groupid) {
enter_logfile($cfg,5," Getting TS3 servergrouplist for ".$select_arr['groups'][$groupid]['sgidname']." (ID: ".$groupid.")");
try {
usleep($cfg['teamspeak_query_command_delay']);
$tsclientlist = $ts3->servergroupclientlist($groupid);
foreach ($tsclientlist as $tsclient) {
if (isset($all_clients[$tsclient['cldbid']])) {
try {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGroupClientDel($groupid, $tsclient['cldbid']);
enter_logfile($cfg,5," ".sprintf($lang['sgrprm'], $select_arr['groups'][$groupid]['sgidname'], $groupid, $all_clients[$tsclient['cldbid']]['name'], $all_clients[$tsclient['cldbid']]['uuid'], $tsclient['cldbid']));
} catch (Exception $e) {
enter_logfile($cfg,2," TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $all_clients[$tsclient['cldbid']]['name'], $all_clients[$tsclient['cldbid']]['uuid'], $tsclient['cldbid'], $select_arr['groups'][$groupid]['sgidname'], $groupid));
$err_cnt++;
}
}
}
} catch (Exception $e) {
enter_logfile($cfg,2," TS3 error: ".$e->getCode().': '.$e->getMessage()." due getting servergroupclientlist for group ".$groupid);
$err_cnt++;
}
}
if ($err_cnt == 0) {
if ($mysqlcon->exec("UPDATE `$dbname`.`user` SET `grpid`=0; UPDATE `$dbname`.`job_check` SET `timestamp`='4' WHERE `job_name`='reset_group_withdraw';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
} else {
enter_logfile($cfg,4," Finished job '".$lang['wihladm32']."'");
}
} else {
if ($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='3' WHERE `job_name`='reset_group_withdraw';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
}
}
if ($err_cnt == 0 && in_array($select_arr['job_check']['reset_user_time']['timestamp'], ["1","2"], true)) {
$err = 0;
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='2' WHERE `job_name`='reset_user_time';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Started job '".$lang['wihladm31']."' (".$lang['wisupidle'].": ".$lang['wihladm311'].")");
}
// zero times
if($mysqlcon->exec("UPDATE `$dbname`.`stats_server` SET `total_online_time`='0', `total_online_month`='0', `total_online_week`='0', `total_active_time`='0', `total_inactive_time`='0';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Reset Server statistics summary (table: stats_server)");
}
if($mysqlcon->exec("UPDATE `$dbname`.`stats_user` SET `rank`='0', `count_week`='0', `count_month`='0', `idle_week`='0', `idle_month`='0', `achiev_count`='0', `achiev_time`='0', `achiev_connects`='0', `achiev_time_perc`='0', `achiev_connects_perc`='0', `total_connections`='0', `active_week`='0', `active_month`='0';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Reset My statistics (table: stats_user)");
}
if($mysqlcon->exec("UPDATE `$dbname`.`user` SET `count`='0', `grpid`='0', `nextup`='0', `idle`='0', `boosttime`='0', `rank`='0', `grpsince`='0';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Reset List Rankup / user statistics (table: user)");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`user_snapshot`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned Top users / user statistic snapshots (table: user_snapshot)");
}
if ($err == 0) {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='4' WHERE `job_name`='reset_user_time';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
} else {
enter_logfile($cfg,4," Finished job '".$lang['wihladm31']."' (".$lang['wisupidle'].": ".$lang['wihladm311'].")");
}
} else {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='3' WHERE `job_name`='reset_user_time';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
}
}
if ($err_cnt == 0 && in_array($select_arr['job_check']['reset_user_delete']['timestamp'], ["1","2"], true)) {
$err = 0;
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='2' WHERE `job_name`='reset_user_delete';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Started job '".$lang['wihladm31']."' (".$lang['wisupidle'].": ".$lang['wihladm312'].")");
}
// remove clients
if($mysqlcon->exec("DELETE FROM `$dbname`.`stats_nations`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned donut chart nations (table: stats_nations)");
}
if($mysqlcon->exec("UPDATE `$dbname`.`stats_platforms` SET `count`=0;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned donut chart platforms (table: stats_platforms)");
}
if($mysqlcon->exec("UPDATE `$dbname`.`stats_server` SET `total_user`='0', `total_online_time`='0', `total_online_month`='0', `total_online_week`='0', `total_active_time`='0', `total_inactive_time`='0', `country_nation_name_1`='', `country_nation_name_2`='', `country_nation_name_3`='', `country_nation_name_4`='', `country_nation_name_5`='', `country_nation_1`='0', `country_nation_2`='0', `country_nation_3`='0', `country_nation_4`='0', `country_nation_5`='0', `country_nation_other`='0', `platform_1`='0', `platform_2`='0', `platform_3`='0', `platform_4`='0', `platform_5`='0', `platform_other`='0', `version_name_1`='', `version_name_2`='', `version_name_3`='', `version_name_4`='', `version_name_5`='', `version_1`='0', `version_2`='0', `version_3`='0', `version_4`='0', `version_5`='0', `version_other`='0';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Reset Server statistics summary (table: stats_server)");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`stats_user`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned My statistics (table: stats_user)");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`stats_versions`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned donut chart versions (table: stats_versions)");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`user`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned List Rankup / user statistics (table: user)");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`user_iphash`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned user ip-hash values (table: user_iphash)");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`user_snapshot`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
$err++;
} else {
enter_logfile($cfg,4," Cleaned Top users / user statistic snapshots (table: user_snapshot)");
}
if ($err == 0) {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='4' WHERE `job_name`='reset_user_delete';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
} else {
enter_logfile($cfg,4," Finished job '".$lang['wihladm31']."' (".$lang['wisupidle'].": ".$lang['wihladm312'].")");
}
} else {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='3' WHERE `job_name`='reset_user_delete';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
}
}
if (in_array($select_arr['job_check']['reset_webspace_cache']['timestamp'], ["1","2"], true)) {
if ($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='2' WHERE `job_name`='reset_webspace_cache';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
} else {
enter_logfile($cfg,4," Started job '".$lang['wihladm33']."'");
}
$del_folder = array('avatars/','tsicons/');
$err_cnt = 0;
if (!function_exists('rm_file_reset')) {
function rm_file_reset($folder,$cfg) {
foreach(scandir($folder) as $file) {
if ('.' === $file || '..' === $file || 'rs.png' === $file || is_dir($folder.$file)) {
continue;
} else {
if(unlink($folder.$file)) {
enter_logfile($cfg,4," File ".$folder.$file." successfully deleted.");
} else {
enter_logfile($cfg,2," File ".$folder.$file." couldn't be deleted. Please check the file permissions.");
$err_cnt++;
}
}
}
}
}
foreach ($del_folder as $folder) {
if(is_dir(substr(__DIR__,0,-4).$folder)) {
rm_file_reset(substr(__DIR__,0,-4).$folder,$cfg);
}
}
if ($err_cnt == 0) {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='4' WHERE `job_name`='reset_webspace_cache';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
} else {
enter_logfile($cfg,4," Finished job '".$lang['wihladm33']."'");
}
} else {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='3' WHERE `job_name`='reset_webspace_cache';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
}
}
if (in_array($select_arr['job_check']['reset_usage_graph']['timestamp'], ["1","2"], true)) {
if ($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='2' WHERE `job_name`='reset_usage_graph';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
} else {
enter_logfile($cfg,4," Started job '".$lang['wihladm34']."'");
}
if ($mysqlcon->exec("DELETE FROM `$dbname`.`server_usage`;") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='3' WHERE `job_name`='reset_usage_graph';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
} else {
enter_logfile($cfg,4," Cleaned server usage graph (table: server_usage)");
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='4' WHERE `job_name`='reset_usage_graph';") === false) {
enter_logfile($cfg,2," Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
} else {
enter_logfile($cfg,4," Finished job '".$lang['wihladm34']."'");
}
}
}
enter_logfile($cfg,4,"Reset job(s) finished");
if($select_arr['job_check']['reset_stop_after']['timestamp'] == "1") {
$path = substr(__DIR__, 0, -4);
if (substr(php_uname(), 0, 7) == "Windows") {
exec("start ".$phpcommand." ".$path."worker.php stop");
file_put_contents(substr(__DIR__,0,-4).'logs\autostart_deactivated',"");
} else {
exec($phpcommand." ".$path."worker.php stop > /dev/null &");
file_put_contents(substr(__DIR__,0,-4).'logs/autostart_deactivated',"");
}
shutdown($mysqlcon,$cfg,4,"Stop requested after Reset job. Wait for manually start.");
}
}
enter_logfile($cfg,6,"reset_rs needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
}
?>

View File

@@ -1,175 +1,192 @@
<?PHP
function update_groups($ts3,$mysqlcon,$lang,$cfg,$dbname,$serverinfo,$select_arr,$nobreak = 0) {
$starttime = microtime(true);
$sqlexec = '';
try {
usleep($cfg['teamspeak_query_command_delay']);
$iconlist = $ts3->channelFileList($cid="0", $cpw="", $path="/icons/");
if(isset($iconlist)) {
foreach($iconlist as $icon) {
$iconid = "i".substr($icon['name'], 5);
$iconarr[$iconid] = $icon['datetime'];
}
} else {
$iconarr["xxxxx"] = 0;
}
unset($iconlist);
try {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGroupListReset();
$ts3groups = $ts3->serverGroupList();
// ServerIcon
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($select_arr['groups']['0']) || $select_arr['groups']['0']['iconid'] != $sIconId || (isset($iconarr["i".$sIconId]) && $iconarr["i".$sIconId] > $select_arr['groups']['0']['icondate'])) {
if($sIconId > 600) {
try {
usleep($cfg['teamspeak_query_command_delay']);
enter_logfile($cfg,5,$lang['upgrp0002']);
$sIconFile = $ts3->iconDownload();
if(file_put_contents(substr(dirname(__FILE__),0,-4) . "tsicons/servericon.png", $sIconFile) === false) {
enter_logfile($cfg,2,$lang['upgrp0003'].' '.sprintf($lang['errperm'], 'tsicons'));
}
} catch (Exception $e) {
enter_logfile($cfg,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($cfg,2,$lang['upgrp0005'].' '.sprintf($lang['errperm'], 'tsicons'));
} else {
enter_logfile($cfg,5,$lang['upgrp0006']);
}
}
$iconarr["i".$sIconId] = 0;
}
$updategroups[] = array(
"sgid" => "0",
"sgidname" => "'ServerIcon'",
"iconid" => $sIconId,
"icondate" => $iconarr["i".$sIconId]
);
}
unset($sIconFile,$sIconId);
// GroupIcons
$iconcount = 0;
foreach ($ts3groups as $servergroup) {
$tsgroupids[$servergroup['sgid']] = 0;
$sgid = $servergroup['sgid'];
$sgname = $mysqlcon->quote($servergroup['name'], ENT_QUOTES);
$iconid = $servergroup['iconid'];
$iconid = ($iconid < 0) ? (pow(2, 32)) - ($iconid * -1) : $iconid;
$iconfile = 0;
if($iconid > 600) {
if (!isset($select_arr['groups'][$sgid]) || $select_arr['groups'][$sgid]['iconid'] != $iconid || $iconarr["i".$iconid] > $select_arr['groups'][$sgid]['icondate']) {
try {
check_shutdown($cfg); usleep($cfg['teamspeak_query_command_delay']);
enter_logfile($cfg,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($cfg,2,sprintf($lang['upgrp0007'], $sgname, $sgid).' '.sprintf($lang['errperm'], 'tsicons'));
}
$iconcount++;
} catch (Exception $e) {
enter_logfile($cfg,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($cfg,2,sprintf($lang['upgrp0009'], $sgname, $sgid).' '.sprintf($lang['errperm'], 'tsicons'));
} else {
enter_logfile($cfg,5,sprintf($lang['upgrp0010'], $sgname, $sgid));
}
}
$iconarr["i".$iconid] = 0;
}
if(!isset($iconarr["i".$iconid])) {
$iconarr["i".$iconid] = 0;
}
if(isset($select_arr['groups'][$servergroup['sgid']]) && $select_arr['groups'][$servergroup['sgid']]['sgidname'] == $servergroup['name'] && $select_arr['groups'][$servergroup['sgid']]['iconid'] == $iconid && $select_arr['groups'][$servergroup['sgid']]['icondate'] == $iconarr["i".$iconid]) {
continue;
} else {
if($servergroup['sgid'] == 5000) {
enter_logfile($cfg,6,print_r($select_arr['groups'],true));
}
enter_logfile($cfg,6,"Update/Insert server group ".$sgname." (CID: ".$servergroup['sgid'].")");
$updategroups[] = array(
"sgid" => $servergroup['sgid'],
"sgidname" => $sgname,
"iconid" => $iconid,
"icondate" => $iconarr["i".$iconid]
);
}
if($iconcount > 9 && $nobreak != 1) {
break;
}
}
unset($ts3groups,$sgname,$sgid,$iconid,$iconfile,$iconcount,$iconarr);
if (isset($updategroups)) {
$sqlinsertvalues = '';
foreach ($updategroups as $updatedata) {
$sqlinsertvalues .= "({$updatedata['sgid']},{$updatedata['sgidname']},{$updatedata['iconid']},{$updatedata['icondate']}),";
}
$sqlinsertvalues = substr($sqlinsertvalues, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`groups` (`sgid`,`sgidname`,`iconid`,`icondate`) VALUES $sqlinsertvalues ON DUPLICATE KEY UPDATE `sgidname`=VALUES(`sgidname`),`iconid`=VALUES(`iconid`),`icondate`=VALUES(`icondate`); ";
unset($updategroups, $sqlinsertvalues);
}
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, $cfg['rankup_definition'])) {
enter_logfile($cfg,2,sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
foreach ($cfg['webinterface_admin_client_unique_id_list'] as $clientid) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
} catch (Exception $e) {
enter_logfile($cfg,6," ".sprintf($lang['upusrerr'], $clientid));
}
}
}
}
if(isset($cfg['rankup_boost_definition'][$sgid])) {
enter_logfile($cfg,2,sprintf($lang['upgrp0001'], $sgid, $lang['wiboost']));
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
foreach ($cfg['webinterface_admin_client_unique_id_list'] as $clientid) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
} catch (Exception $e) {
enter_logfile($cfg,6," ".sprintf($lang['upusrerr'], $clientid));
}
}
}
}
if(isset($cfg['rankup_excepted_group_id_list'][$sgid])) {
enter_logfile($cfg,2,sprintf($lang['upgrp0001'], $sgid, $lang['wiexgrp']));
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
foreach ($cfg['webinterface_admin_client_unique_id_list'] as $clientid) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
} catch (Exception $e) {
enter_logfile($cfg,6," ".sprintf($lang['upusrerr'], $clientid));
}
}
}
}
}
}
}
if(isset($delsgroupids)) {
$delsgroupids = substr($delsgroupids, 0, -1);
$sqlexec .= "DELETE FROM `$dbname`.`groups` WHERE `sgid` IN ($delsgroupids); ";
}
enter_logfile($cfg,6,"update_groups needs: ".(number_format(round((microtime(true) - $starttime), 5),5)));
return($sqlexec);
} catch (Exception $e) {
enter_logfile($cfg,2,$lang['errorts3'].$e->getCode().': '.$lang['errgrplist'].$e->getMessage());
}
} catch (Exception $e) {
if ($e->getCode() != 1281) {
enter_logfile($cfg,2,$lang['errorts3'].$e->getCode().': '.$lang['errgrplist'].$e->getMessage());
}
}
foreach($iconlist as $icon) {
$iconid = "i".substr($icon['name'], 5);
$iconarr[$iconid] = $icon['datetime'];
}
try {
usleep($cfg['teamspeak_query_command_delay']);
$ts3->serverGroupListReset();
$ts3groups = $ts3->serverGroupList();
} catch (Exception $e) {
enter_logfile($cfg,2,$lang['errorts3'].$e->getCode().': '.$lang['errgrplist'].$e->getMessage());
}
// ServerIcon
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($select_arr['groups']['0']) || $select_arr['groups']['0']['iconid'] != $sIconId || $iconarr["i".$sIconId] > $select_arr['groups']['0']['icondate']) {
if($sIconId > 600) {
try {
usleep($cfg['teamspeak_query_command_delay']);
enter_logfile($cfg,5,$lang['upgrp0002']);
$sIconFile = $ts3->iconDownload();
if(file_put_contents(substr(dirname(__FILE__),0,-4) . "tsicons/servericon.png", $sIconFile) === false) {
enter_logfile($cfg,2,$lang['upgrp0003'].' '.sprintf($lang['errperm'], 'tsicons'));
}
} catch (Exception $e) {
enter_logfile($cfg,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($cfg,2,$lang['upgrp0005'].' '.sprintf($lang['errperm'], 'tsicons'));
} else {
enter_logfile($cfg,5,$lang['upgrp0006']);
}
}
$iconarr["i".$sIconId] = 0;
}
$updategroups[] = array(
"sgid" => "0",
"sgidname" => "'ServerIcon'",
"iconid" => $sIconId,
"icondate" => $iconarr["i".$sIconId]
);
}
// GroupIcons
$iconcount= 0;
foreach ($ts3groups as $servergroup) {
$tsgroupids[$servergroup['sgid']] = 0;
$sgid = $servergroup['sgid'];
$sgname = $mysqlcon->quote($servergroup['name'], ENT_QUOTES);
$gefunden = 2;
$iconid = $servergroup['iconid'];
$iconid = ($iconid < 0) ? (pow(2, 32)) - ($iconid * -1) : $iconid;
$iconfile = 0;
if($iconid > 600) {
if (!isset($select_arr['groups'][$sgid]) || $select_arr['groups'][$sgid]['iconid'] != $iconid || $iconarr["i".$iconid] > $select_arr['groups'][$sgid]['icondate']) {
try {
check_shutdown($cfg); usleep($cfg['teamspeak_query_command_delay']);
enter_logfile($cfg,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($cfg,2,sprintf($lang['upgrp0007'], $sgname, $sgid).' '.sprintf($lang['errperm'], 'tsicons'));
}
$iconcount++;
} catch (Exception $e) {
enter_logfile($cfg,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($cfg,2,sprintf($lang['upgrp0009'], $sgname, $sgid).' '.sprintf($lang['errperm'], 'tsicons'));
} else {
enter_logfile($cfg,5,sprintf($lang['upgrp0010'], $sgname, $sgid));
}
}
$iconarr["i".$iconid] = 0;
}
if(!isset($iconarr["i".$iconid])) {
$iconarr["i".$iconid] = 0;
}
$updategroups[] = array(
"sgid" => $servergroup['sgid'],
"sgidname" => $sgname,
"iconid" => $iconid,
"icondate" => $iconarr["i".$iconid]
);
if($iconcount > 9 && $nobreak != 1) {
break;
}
}
if (isset($updategroups)) {
$sqlinsertvalues = '';
foreach ($updategroups as $updatedata) {
$sqlinsertvalues .= "(".$updatedata['sgid'].",".$updatedata['sgidname'].",'".$updatedata['iconid']."','".$updatedata['icondate']."'),";
}
$sqlinsertvalues = substr($sqlinsertvalues, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`groups` (`sgid`,`sgidname`,`iconid`,`icondate`) VALUES $sqlinsertvalues ON DUPLICATE KEY UPDATE `sgidname`=VALUES(`sgidname`),`iconid`=VALUES(`iconid`),`icondate`=VALUES(`icondate`); ";
unset($updategroups, $sqlinsertvalues);
}
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, $cfg['rankup_definition'])) {
enter_logfile($cfg,2,sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
foreach ($cfg['webinterface_admin_client_unique_id_list'] as $clientid) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
} catch (Exception $e) {
enter_logfile($cfg,6," ".sprintf($lang['upusrerr'], $clientid));
}
}
}
}
if(isset($cfg['rankup_boost_definition'][$sgid])) {
enter_logfile($cfg,2,sprintf($lang['upgrp0001'], $sgid, $lang['wiboost']));
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
foreach ($cfg['webinterface_admin_client_unique_id_list'] as $clientid) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
} catch (Exception $e) {
enter_logfile($cfg,6," ".sprintf($lang['upusrerr'], $clientid));
}
}
}
}
if(isset($cfg['rankup_excepted_group_id_list'][$sgid])) {
enter_logfile($cfg,2,sprintf($lang['upgrp0001'], $sgid, $lang['wiexgrp']));
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
foreach ($cfg['webinterface_admin_client_unique_id_list'] as $clientid) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upgrp0001'], $sgid, $lang['wigrptime']));
} catch (Exception $e) {
enter_logfile($cfg,6," ".sprintf($lang['upusrerr'], $clientid));
}
}
}
}
}
}
}
if(isset($delsgroupids)) {
$delsgroupids = substr($delsgroupids, 0, -1);
$sqlexec .= "DELETE FROM `$dbname`.`groups` WHERE `sgid` IN ($delsgroupids); ";
}
return($sqlexec);
}
?>