release 1.3.7

This commit is contained in:
Newcomer1989
2020-02-15 18:55:28 +01:00
parent 49bf90fb18
commit f7dcb8faef
56 changed files with 2889 additions and 1479 deletions

View File

@@ -175,11 +175,9 @@ function sendmessage($ts3, $cfg, $uuid, $msg, $erromsg=NULL, $errcode=NULL, $suc
}
}
$sqlexec = '';
function run_bot() {
global $cfg, $mysqlcon, $dbname, $dbtype, $lang, $phpcommand, $addons_config, $sqlexec, $max_execution_time, $memory_limit;
global $cfg, $mysqlcon, $dbname, $dbtype, $lang, $phpcommand, $addons_config, $max_execution_time, $memory_limit;
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 {
@@ -380,6 +378,12 @@ function run_bot() {
}
}
if($cfg['webinterface_fresh_installation'] == 1) {
if($mysqlcon->exec("UPDATE `$dbname`.`cfg_params` SET `value`=0 WHERE `param`='webinterface_fresh_installation'") === false) {
enter_logfile($cfg,2,"Executing SQL commands failed: ".print_r($mysqlcon->errorInfo(), true));
}
}
unset($groupslist,$errcnf,$checkgroups,$lastupdate,$updcld,$loglevel,$whoami,$ts3host,$max_execution_time,$memory_limit,$memory_limit);
enter_logfile($cfg,9,"Config check [done]");
@@ -388,6 +392,7 @@ function run_bot() {
usleep(3000000);
while(1) {
$sqlexec = '';
$starttime = microtime(true);
$weekago = time() - 604800;
$monthago = time() - 2592000;
@@ -491,7 +496,6 @@ function run_bot() {
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;
@@ -512,8 +516,7 @@ function run_bot() {
}
} catch (Exception $e) {
enter_logfile($cfg,2,$lang['errorts3'].$e->getCode().': '.$e->getMessage());
$offline_status = array(110,257,258,1024,1026,1031,1032,1033,1034,1280,1793);
if(in_array($e->getCode(), $offline_status)) {
if(in_array($e->getCode(), array(110,257,258,1024,1026,1031,1032,1033,1034,1280,1793))) {
if($mysqlcon->exec("UPDATE $dbname.stats_server SET server_status='0'") === false) {
enter_logfile($cfg,2,$lang['error'].print_r($mysqlcon->errorInfo(), true));
}
@@ -546,7 +549,6 @@ function run_bot() {
} else {
shutdown($mysqlcon,$cfg,1,"Critical TS3 error on core function!");
}
unset($offline_status,$wait_reconnect,$z);
}
}

View File

@@ -7,12 +7,15 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
if(empty($cfg['rankup_definition'])) {
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,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;
$addtime = $nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'];
if($addtime > 1800) {
enter_logfile($cfg,4,"Much time gone since last scan.. set addtime to 1 second.");
$addtime = 1;
} elseif($addtime < 0) {
enter_logfile($cfg,3,"Negative time valie (now < last scan).. Error in your machine time!.. set addtime to 1 second.");
$addtime = 1;
}
$sqlexec .= "UPDATE `$dbname`.`job_check` SET `timestamp`=$nowtime WHERE `job_name`='calc_user_lastscan'; UPDATE `$dbname`.`user` SET `online`=0 WHERE `online`=1; ";
@@ -22,19 +25,66 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
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])) {
$sqlexec2 = '';
$isonline = 0;
foreach($allclients as $client) {
if($client['client_unique_identifier'] == $uuid) {
$isonline = 1;
$select_arr['all_user'][$uuid]['count'] += $value['timecount'];
if($value['timecount'] < 0) {
$select_arr['all_user'][$uuid]['count'] += $value['timecount'];
if($select_arr['all_user'][$uuid]['count'] < 0) {
$select_arr['all_user'][$uuid]['count'] = 0;
$select_arr['all_user'][$uuid]['idle'] = 0;
} elseif ($select_arr['all_user'][$uuid]['idle'] > $select_arr['all_user'][$uuid]['count']) {
$select_arr['all_user'][$uuid]['idle'] = $select_arr['all_user'][$uuid]['count'];
}
} else {
$select_arr['all_user'][$uuid]['count'] += $value['timecount'];
}
}
}
if($isonline != 1) {
$sqlexec .= "UPDATE `$dbname`.`user` SET `count`=`count` + ".$value['timecount']." WHERE `uuid`='$uuid'; ";
if(($user = $mysqlcon->query("SELECT `uuid`,`count`,`idle` FROM `$dbname`.`user` WHERE `uuid`='{$uuid}'")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
enter_logfile($cfg,2,"Database error on selecting user (admin function remove/add time): ".print_r($mysqlcon->errorInfo(), true));
} else {
if($value['timecount'] < 0) {
$user[$uuid]['count'] += $value['timecount'];
if($user[$uuid]['count'] < 0) {
$user[$uuid]['count'] = 0;
$user[$uuid]['idle'] = 0;
} elseif ($user[$uuid]['idle'] > $user[$uuid]['count']) {
$user[$uuid]['idle'] = $user[$uuid]['count'];
}
} else {
$user[$uuid]['count'] += $value['timecount'];
}
$sqlexec2 .= "UPDATE `$dbname`.`user` SET `count`='{$user[$uuid]['count']}', `idle`='{$user[$uuid]['idle']}' WHERE `uuid`='{$uuid}'; ";
}
}
$sqlexec2 .= "DELETE FROM `$dbname`.`admin_addtime` WHERE `timestamp`=".$value['timestamp']." AND `uuid`='$uuid'; ";
if(($usersnap = $mysqlcon->query("SELECT `timestamp`,`uuid`,`count`,`idle` FROM `$dbname`.`user_snapshot` WHERE `uuid`='{$uuid}'")->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE)) === false) {
enter_logfile($cfg,2,"Database error on selecting user (admin function remove/add time): ".print_r($mysqlcon->errorInfo(), true));
} else {
foreach($usersnap as $timestamp => $valuesnap) {
if($value['timecount'] < 0) {
$valuesnap[$timestamp]['count'] += $value['timecount'];
if($valuesnap[$timestamp]['count'] < 0) {
$valuesnap[$timestamp]['count'] = 0;
$valuesnap[$timestamp]['idle'] = 0;
} elseif ($valuesnap[$timestamp]['idle'] > $valuesnap[$timestamp]['count']) {
$valuesnap[$timestamp]['idle'] = $valuesnap[$timestamp]['count'];
}
} else {
$valuesnap[$timestamp]['count'] += $value['timecount'];
}
$sqlexec2 .= "UPDATE `$dbname`.`user_snapshot` SET `count`='{$valuesnap[$timestamp]['count']}', `idle`='{$valuesnap[$timestamp]['idle']}' WHERE `uuid`='{$uuid}' AND `timestamp`='{$timestamp}'; ";
}
}
if($mysqlcon->exec($sqlexec2) === false) {
enter_logfile($cfg,2,"Database error on updating user (admin function remove/add time): ".print_r($mysqlcon->errorInfo(), true));
}
$sqlexec .= "DELETE FROM `$dbname`.`admin_addtime` WHERE `timestamp`=".$value['timestamp']." AND `uuid`='$uuid'; ";
$sqlexec .= "UPDATE `$dbname`.`user_snapshot` SET `count`=`count` + ".$value['timecount']." WHERE `uuid`='$uuid'; ";
enter_logfile($cfg,4,sprintf($lang['sccupcount2'],$value['timecount'],$uuid));
unset($sqlexec2, $user, $usersnap);
}
}
}
@@ -52,7 +102,7 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
$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'])) {
} elseif($cfg['rankup_excepted_group_id_list'] != NULL && array_intersect_key($sgroups, $cfg['rankup_excepted_group_id_list'])) {
$except = 2;
} else {
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) {
@@ -90,17 +140,17 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
}
}
}
$count = ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp']) * $boost['factor'] + $select_arr['all_user'][$uid]['count'];
if ($clientidle > ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'])) {
$idle = ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp']) * $boost['factor'] + $select_arr['all_user'][$uid]['idle'];
$count = $addtime * $boost['factor'] + $select_arr['all_user'][$uid]['count'];
if ($clientidle > $addtime) {
$idle = $addtime * $boost['factor'] + $select_arr['all_user'][$uid]['idle'];
}
}
}
}
if($cfg['rankup_boost_definition'] == 0 or $hitboost == 0) {
$count = $nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'] + $select_arr['all_user'][$uid]['count'];
if ($clientidle > ($nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'])) {
$idle = $nowtime - $select_arr['job_check']['calc_user_lastscan']['timestamp'] + $select_arr['all_user'][$uid]['idle'];
$count = $addtime + $select_arr['all_user'][$uid]['count'];
if ($clientidle > $addtime) {
$idle = $addtime + $select_arr['all_user'][$uid]['idle'];
}
}
}
@@ -114,7 +164,6 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
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;
}
}
@@ -128,9 +177,8 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,$se
if($except != 2 && $except != 3) {
$except = 1;
}
} elseif ($activetime > $time && !isset($cfg['rankup_excepted_unique_client_id_list'][$uid]) && !array_intersect_key($sgroups, $cfg['rankup_excepted_group_id_list'])) {
} elseif ($activetime > $time && !isset($cfg['rankup_excepted_unique_client_id_list'][$uid]) && ($cfg['rankup_excepted_group_id_list'] == NULL || !array_intersect_key($sgroups, $cfg['rankup_excepted_group_id_list']))) {
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 {

View File

@@ -1,6 +1,6 @@
<?PHP
function check_db($mysqlcon,$lang,$cfg,$dbname) {
$cfg['version_latest_available'] = '1.3.4';
$cfg['version_latest_available'] = '1.3.7';
enter_logfile($cfg,5,"Check Ranksystem database for updates...");
function set_new_version($mysqlcon,$cfg,$dbname) {
@@ -345,14 +345,29 @@ function check_db($mysqlcon,$lang,$cfg,$dbname) {
if($mysqlcon->exec("UPDATE `$dbname`.`job_check` SET `timestamp`='".time()."' WHERE `job_name`='last_update';") === false) { } else {
enter_logfile($cfg,4," [1.3.4] Stored timestamp of last update successfully.");
}
}
if(version_compare($cfg['version_current_using'], '1.3.7', '<')) {
if($mysqlcon->exec("DELETE FROM `$dbname`.`admin_addtime`;") === false) { }
if($mysqlcon->exec("DELETE FROM `$dbname`.`addon_assign_groups`;") === false) { }
if($mysqlcon->exec("CREATE INDEX `snapshot_timestamp` ON `$dbname`.`user_snapshot` (`timestamp`)") === false) { }
if($mysqlcon->exec("CREATE INDEX `snapshot_uuid` ON `$dbname`.`user_snapshot` (`uuid`)") === false) { }
if($mysqlcon->exec("CREATE INDEX `serverusage_timestamp` ON `$dbname`.`server_usage` (`timestamp`)") === false) { }
if($mysqlcon->exec("CREATE INDEX `user_version` ON `$dbname`.`user` (`version`)") === false) { }
if($mysqlcon->exec("CREATE INDEX `user_cldbid` ON `$dbname`.`user` (`cldbid` ASC,`uuid`,`rank`)") === false) { }
if($mysqlcon->exec("CREATE INDEX `user_online` ON `$dbname`.`user` (`online`,`lastseen`)") === false) { }
if($mysqlcon->exec("INSERT INTO `$dbname`.`cfg_params` (`param`,`value`) VALUES ('webinterface_fresh_installation', '0'),('webinterface_advanced_mode', '1')") === false) { } else {
enter_logfile($cfg,4," [1.3.7] Added new config values.");
}
if($mysqlcon->exec("DELETE FROM `$dbname`.`groups`;") === false) { } else {
enter_logfile($cfg,4," [1.3.7] Empty table groups successfully.");
}
if($mysqlcon->exec("ALTER TABLE `$dbname`.`groups` ADD COLUMN `sortid` int(10) NOT NULL default '0', ADD COLUMN `type` tinyint(1) NOT NULL default '0';") === false) { } else {
enter_logfile($cfg,4," [1.3.7] Adjusted table groups successfully.");
}
}
$cfg = set_new_version($mysqlcon,$cfg,$dbname);
}

View File

@@ -15,178 +15,193 @@ function update_groups($ts3,$mysqlcon,$lang,$cfg,$dbname,$serverinfo,$select_arr
$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((mb_substr($servergroup['name'],0,30)), 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());
} else {
$iconarr["xxxxx"] = 0;
enter_logfile($cfg,6,$lang['errorts3'].$e->getCode().': '.$lang['errgrplist'].$e->getMessage());
}
}
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'];
}
enter_logfile($cfg,6,"Servericon TSiconid:".$serverinfo['virtualserver_icon_id']."; powed TSiconid:".$sIconId."; DBiconid:".$select_arr['groups']['0']['iconid']."; TSicondate:".$iconarr["i".$sIconId]."; DBicondate:".$select_arr['groups']['0']['icondate'].";");
$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;
}
if(isset($iconarr["i".$sIconId]) && $iconarr["i".$sIconId] > 0) {
$sicondate = $iconarr["i".$sIconId];
} else {
$sicondate = 0;
}
$updategroups[] = array(
"sgid" => "0",
"sgidname" => "'ServerIcon'",
"iconid" => $sIconId,
"icondate" => $sicondate,
"sortid" => "0",
"type" => "0",
);
}
unset($sIconFile,$sIconId);
// GroupIcons
$iconcount = 0;
foreach ($ts3groups as $servergroup) {
$tsgroupids[$servergroup['sgid']] = 0;
$sgid = $servergroup['sgid'];
$sgname = $mysqlcon->quote((mb_substr($servergroup['name'],0,30)), 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] && $select_arr['groups'][$servergroup['sgid']]['sortid'] == $servergroup['sortid']) {
enter_logfile($cfg,6,"Continue server group ".$sgname." (CID: ".$servergroup['sgid'].")");
continue;
} else {
if($servergroup['sgid'] == 5000) {
enter_logfile($cfg,6,print_r($select_arr['groups'],true));
}
enter_logfile($cfg,5,"Update/Insert server group ".$sgname." (CID: ".$servergroup['sgid'].")");
$updategroups[] = array(
"sgid" => $servergroup['sgid'],
"sgidname" => $sgname,
"iconid" => $iconid,
"icondate" => $iconarr["i".$iconid],
"sortid" => $servergroup['sortid'],
"type" => $servergroup['type']
);
}
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']},{$updatedata['sortid']},{$updatedata['type']}),";
}
$sqlinsertvalues = substr($sqlinsertvalues, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`groups` (`sgid`,`sgidname`,`iconid`,`icondate`,`sortid`,`type`) VALUES $sqlinsertvalues ON DUPLICATE KEY UPDATE `sgidname`=VALUES(`sgidname`),`iconid`=VALUES(`iconid`),`icondate`=VALUES(`icondate`),`sortid`=VALUES(`sortid`),`type`=VALUES(`type`); ";
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());
}
}
?>