Skip to content

Commit

Permalink
release 1.3.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Newcomer1989 committed Dec 18, 2022
1 parent d2cb86e commit b96e32b
Show file tree
Hide file tree
Showing 35 changed files with 359 additions and 122 deletions.
2 changes: 1 addition & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if (isset($_GET['apikey'])) {
$matchkey = 0;
foreach($cfg['stats_api_keys'] as $apikey => $desc) {
if ($apikey == $_GET['apikey']) $matchkey = 1;
if (hash_equals($apikey, $_GET['apikey'])) $matchkey = 1;
}
if ($matchkey == 0) {
$json = array(
Expand Down
15 changes: 12 additions & 3 deletions install.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?PHP
$rsversion = '1.3.19';
$rsversion = '1.3.21';

require_once('other/_functions.php');
require_once('other/config.php');
Expand Down Expand Up @@ -79,7 +79,16 @@ function install($type, $host, $user, $pass, $dbname, $lang, $mysqlcon, &$err_ms
$err_lvl = 2;
} else {
$count = 1;
if(($mysqlcon->exec("DROP DATABASE `$dbname`")) === false) { }
$stmt = $mysqlcon->query('SHOW DATABASES');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row['Database'] == $dbname) {
$dbExists = true;
break;
}
}
if ($dbExists) {
if(($mysqlcon->exec("DROP DATABASE `$dbname`")) === false) { }
}

if($mysqlcon->exec("CREATE DATABASE `$dbname`") === false) {
$err_msg .= $lang['isntwidbmsg'].$mysqlcon->errorCode()." ".print_r($mysqlcon->errorInfo(), true).'<br>'; $err_lvl = 2;
Expand Down Expand Up @@ -168,7 +177,7 @@ function install($type, $host, $user, $pass, $dbname, $lang, $mysqlcon, &$err_ms
$count++;
}

if($mysqlcon->exec("INSERT INTO `$dbname`.`job_check` (`job_name`) VALUES ('calc_user_limit'),('calc_user_lastscan'),('calc_user_removed'),('check_update'),('database_export'),('get_version'),('clean_db'),('clean_clients'),('calc_donut_chars'),('calc_server_stats'),('get_avatars'),('last_snapshot_id'),('last_snapshot_time'),('last_update'),('reload_trigger'),('reset_user_time'),('reset_user_delete'),('reset_group_withdraw'),('reset_webspace_cache'),('reset_usage_graph'),('reset_stop_after'),('runtime_check'),('update_channel'),('update_groups')") === false) {
if($mysqlcon->exec("INSERT INTO `$dbname`.`job_check` (`job_name`) VALUES ('calc_user_limit'),('calc_user_lastscan'),('calc_user_removed'),('check_update'),('clean_user_iphash'),('database_export'),('get_version'),('clean_db'),('clean_clients'),('calc_donut_chars'),('calc_server_stats'),('get_avatars'),('last_snapshot_id'),('last_snapshot_time'),('last_update'),('reload_trigger'),('reset_user_time'),('reset_user_delete'),('reset_group_withdraw'),('reset_webspace_cache'),('reset_usage_graph'),('reset_stop_after'),('runtime_check'),('update_channel'),('update_groups')") === false) {
$err_msg .= $lang['isntwidbmsg'].$mysqlcon->errorCode()." ".print_r($mysqlcon->errorInfo(), true).'<br>'; $err_lvl = 2;
$count++;
}
Expand Down
4 changes: 2 additions & 2 deletions jobs/addon_channelinfo_toplist.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ function addon_channelinfo_toplist(&$addons_config,$ts3,$mysqlcon,$cfg,$dbname,$
$smarty->assign('CLIENT_NEXT_RANKUP_TIME_'.($nr + 1),$userdata[$nr]['nextup']);

$smarty->assign('CLIENT_CURRENT_RANK_GROUP_ID_'.($nr + 1),$userdata[$nr]['grpid']);
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['sgidname'])) {
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['sgidname']) && $userdata[$nr]['grpid'] != 0) {
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_NAME_'.($nr + 1),substr($db_cache['groups'][$userdata[$nr]['grpid']]['sgidname'],1,-1));
} else {
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_NAME_'.($nr + 1),'unknown_group');
}
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['iconid']) && isset($db_cache['groups'][$userdata[$nr]['grpid']]['ext'])) {
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['iconid']) && isset($db_cache['groups'][$userdata[$nr]['grpid']]['ext']) && $userdata[$nr]['grpid'] != 0) {
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_ICON_URL_'.($nr + 1),'tsicons/'.$db_cache['groups'][$userdata[$nr]['grpid']]['iconid'].'.'.$db_cache['groups'][$userdata[$nr]['grpid']]['ext']);
} else {
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_ICON_URL_'.($nr + 1),'file_not_found');
Expand Down
2 changes: 1 addition & 1 deletion jobs/bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function run_bot(&$cfg) {

enter_logfile($cfg,9," Select virtual server...");
try {
if(version_compare($ts3version['version'],'3.4.0','>=')) {
if(version_compare($ts3version['version'],'3.4.0','>=') || version_compare($ts3version['version'],'3.0.0','<=')) {
usleep($cfg['teamspeak_query_command_delay']);
$ts3server = $ts3host->serverGetByPort($cfg['teamspeak_voice_port'], $cfg['teamspeak_query_nickname']);
} else {
Expand Down
20 changes: 12 additions & 8 deletions jobs/calc_serverstats.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ function calc_serverstats($ts3,$mysqlcon,&$cfg,$dbname,$dbtype,$serverinfo,&$db_
$cfg['temp_db_version']
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
Expand All @@ -435,14 +433,20 @@ function calc_serverstats($ts3,$mysqlcon,&$cfg,$dbname,$dbtype,$serverinfo,&$db_
}

//Calc Rank
$dbversion = $mysqlcon->getAttribute(PDO::ATTR_SERVER_VERSION);
preg_match("/^[0-9\.-]+/", $dbversion, $version_number);
if ($cfg['rankup_time_assess_mode'] == 1) {
$sqlexec .= "SET @a:=0;\nUPDATE `$dbname`.`user` AS `u` INNER JOIN (SELECT @a:=@a+1 `nr`,`uuid` FROM `$dbname`.`user` WHERE `except`<2 ORDER BY (`count` - `idle`) DESC) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`nr`;\n";
//MySQL 8 or above
//UPDATE `user` AS `u` INNER JOIN (SELECT RANK() OVER (ORDER BY (`count` - `idle`) DESC) AS `rank`, `uuid` FROM `$dbname`.`user` WHERE `except`<2) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`rank`;
if(version_compare($version_number[0], '10.6', '>=') || version_compare($version_number[0], '5.5.5-10.6', '>=')) {
$sqlexec .= "UPDATE `$dbname`.`user` AS `u` INNER JOIN (SELECT RANK() OVER (ORDER BY (`count` - `idle`) DESC) AS `rank`, `uuid` FROM `$dbname`.`user` WHERE `except`<2) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`rank`;\n";
} else {
$sqlexec .= "SET @a:=0;\nUPDATE `$dbname`.`user` AS `u` INNER JOIN (SELECT @a:=@a+1 `nr`,`uuid` FROM `$dbname`.`user` WHERE `except`<2 ORDER BY (`count` - `idle`) DESC) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`nr`;\n";
}
} else {
$sqlexec .= "SET @a:=0;\nUPDATE `$dbname`.`user` AS `u` INNER JOIN (SELECT @a:=@a+1 `nr`,`uuid` FROM `$dbname`.`user` WHERE `except`<2 ORDER BY `count` DESC) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`nr`;\n";
//MySQL 8 or above
//UPDATE `user` AS `u` INNER JOIN (SELECT RANK() OVER (ORDER BY `count` DESC) AS `rank`, `uuid` FROM `$dbname`.`user` WHERE `except`<2) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`rank`;
if(version_compare($version_number[0], '10.6', '>=') || version_compare($version_number[0], '5.5.5-10.6', '>=')) {
$sqlexec .= "UPDATE `$dbname`.`user` AS `u` INNER JOIN (SELECT RANK() OVER (ORDER BY `count` DESC) AS `rank`, `uuid` FROM `$dbname`.`user` WHERE `except`<2) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`rank`;\n";
} else {
$sqlexec .= "SET @a:=0;\nUPDATE `$dbname`.`user` AS `u` INNER JOIN (SELECT @a:=@a+1 `nr`,`uuid` FROM `$dbname`.`user` WHERE `except`<2 ORDER BY `count` DESC) AS `s` USING (`uuid`) SET `u`.`rank`=`s`.`nr`;\n";
}
}
}

Expand Down
61 changes: 34 additions & 27 deletions jobs/calc_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
$name = $mysqlcon->quote((mb_substr(mb_convert_encoding($client['client_nickname'],'UTF-8','auto'),0,30)), ENT_QUOTES);
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
$sgroups = array_flip(explode(",", $client['client_servergroups']));
if(strlen($client['client_country']) > 2 || $client['client_country'] == '') $client['client_country'] = 'XX';
if($client['client_country'] !== NULL && strlen($client['client_country']) > 2 || $client['client_country'] === NULL) $client['client_country'] = 'XX';
$client['client_platform'] = mb_substr($client['client_platform'],0,32);
$client['client_version'] = mb_substr($client['client_version'],0,64);

Expand All @@ -108,17 +108,18 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
if(isset($db_cache['all_user'][$uid]['except']) && ($db_cache['all_user'][$uid]['except'] == 3 || $db_cache['all_user'][$uid]['except'] == 2) && $cfg['rankup_excepted_mode'] == 2) {
$db_cache['all_user'][$uid]['count'] = 0;
$db_cache['all_user'][$uid]['idle'] = 0;
enter_logfile($cfg,5,sprintf($lang['resettime'], $name, $uid, $client['client_database_id']));
$sqlexec .= "DELETE FROM `$dbname`.`user_snapshot` WHERE `uuid`='$uid';\n";
enter_logfile($cfg,5,sprintf($lang['resettime'], $client['client_nickname'], $uid, $client['client_database_id']));
$sqlexec .= "DELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$client['client_database_id']}';\n";
}
$except = 0;
}
if(isset($db_cache['all_user'][$uid])) {
$idle = $db_cache['all_user'][$uid]['idle'] + $clientidle;
if ($db_cache['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'], $db_cache['all_user'][$uid]['cldbid']));
enter_logfile($cfg,5,sprintf($lang['changedbid'], $client['client_nickname'], $uid, $client['client_database_id'], $db_cache['all_user'][$uid]['cldbid']));
$count = 1;
$idle = 0;
$boosttime = 0;
} else {
$hitboost = 0;
$boosttime = $db_cache['all_user'][$uid]['boosttime'];
Expand All @@ -129,14 +130,15 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
if($db_cache['all_user'][$uid]['boosttime']==0) {
$boosttime = $nowtime;
} else {
if ($nowtime > $db_cache['all_user'][$uid]['boosttime'] + $boost['time']) {
if ($nowtime > $db_cache['all_user'][$uid]['boosttime'] + $boost['time'] && (!isset($db_cache['all_user'][$uid]['grouperror']) || $db_cache['all_user'][$uid]['grouperror'] < ($nowtime - 300))) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientDel($boost['group'], $client['client_database_id']);
$boosttime = 0;
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $db_cache['groups'][$boost['group']]['sgidname'], $boost['group'], $name, $uid, $client['client_database_id']).' [Boost-Group]');
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $db_cache['groups'][$boost['group']]['sgidname'], $boost['group'], $client['client_nickname'], $uid, $client['client_database_id']).' [Boost-Group]');
} catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $db_cache['groups'][$db_cache['all_user'][$uid]['grpid']]['sgidname'], $db_cache['all_user'][$uid]['grpid']));
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $client['client_nickname'], $uid, $client['client_database_id'], $db_cache['groups'][$db_cache['all_user'][$uid]['grpid']]['sgidname'], $db_cache['all_user'][$uid]['grpid']));
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
}
}
}
Expand Down Expand Up @@ -189,31 +191,35 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
$donotremove = 1; break;
}
}
if($donotremove == 0) {
if($donotremove == 0 && (!isset($db_cache['all_user'][$uid]['grouperror']) || $db_cache['all_user'][$uid]['grouperror'] < ($nowtime - 300))) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientDel($db_cache['all_user'][$uid]['grpid'], $client['client_database_id']);
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $db_cache['groups'][$db_cache['all_user'][$uid]['grpid']]['sgidname'], $db_cache['all_user'][$uid]['grpid'], $name, $uid, $client['client_database_id']));
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $db_cache['groups'][$db_cache['all_user'][$uid]['grpid']]['sgidname'], $db_cache['all_user'][$uid]['grpid'], $client['client_nickname'], $uid, $client['client_database_id']));
if(isset($client_groups_rankup[$db_cache['all_user'][$uid]['grpid']])) unset($client_groups_rankup[$db_cache['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'], $db_cache['groups'][$db_cache['all_user'][$uid]['grpid']]['sgidname'], $db_cache['all_user'][$uid]['grpid']));
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $client['client_nickname'], $uid, $client['client_database_id'], $db_cache['groups'][$db_cache['all_user'][$uid]['grpid']]['sgidname'], $db_cache['all_user'][$uid]['grpid']));
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
}
}
}
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientAdd($rank['group'], $client['client_database_id']);
$db_cache['all_user'][$uid]['grpsince'] = $nowtime;
enter_logfile($cfg,5,sprintf($lang['sgrpadd'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group'], $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,$db_cache['groups'][$rank['group']]['sgidname'],$client['client_nickname']), 1, NULL, sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $db_cache['groups'][$rank['group']]['sgidname'],$rank['group']), 2);
if(!isset($db_cache['all_user'][$uid]['grouperror']) || $db_cache['all_user'][$uid]['grouperror'] < ($nowtime - 300)) {
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientAdd($rank['group'], $client['client_database_id']);
$db_cache['all_user'][$uid]['grpsince'] = $nowtime;
enter_logfile($cfg,5,sprintf($lang['sgrpadd'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group'], $client['client_nickname'], $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,$db_cache['groups'][$rank['group']]['sgidname'],$client['client_nickname']), 1, NULL, sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $db_cache['groups'][$rank['group']]['sgidname'],$rank['group']), 2);
}
} catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $client['client_nickname'], $uid, $client['client_database_id'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group']));
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
}
} catch (Exception $e) {
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group']));
}
}
if($grpcount == 1) {
Expand All @@ -227,13 +233,14 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
}

foreach($client_groups_rankup as $removegroup => $dummy) {
if($removegroup != NULL && $removegroup != 0 && $removegroup != $db_cache['all_user'][$uid]['grpid']){
if($removegroup != NULL && $removegroup != 0 && $removegroup != $db_cache['all_user'][$uid]['grpid'] && (!isset($db_cache['all_user'][$uid]['grouperror']) || $db_cache['all_user'][$uid]['grouperror'] < ($nowtime - 300))){
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).", $db_cache['groups'][$removegroup]['sgidname'], $removegroup, $name, $uid, $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).", $db_cache['groups'][$removegroup]['sgidname'], $removegroup, $client['client_nickname'], $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'], $db_cache['groups'][$removegroup]['sgidname'], $removegroup));
enter_logfile($cfg,2,"TS3 error: ".$e->getCode().': '.$e->getMessage()." ; ".sprintf($lang['sgrprerr'], $client['client_nickname'], $uid, $client['client_database_id'], $db_cache['groups'][$removegroup]['sgidname'], $removegroup));
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
}
}
}
Expand Down Expand Up @@ -295,7 +302,7 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
$db_cache['all_user'][$uid]['boosttime'] = 0;
$db_cache['all_user'][$uid]['grpsince'] = 0;
$db_cache['all_user'][$uid]['except'] = $except;
enter_logfile($cfg,5,sprintf($lang['adduser'], $name, $uid, $client['client_database_id']));
enter_logfile($cfg,5,sprintf($lang['adduser'], $client['client_nickname'], $uid, $client['client_database_id']));
}
$db_cache['all_user'][$uid]['name'] = $client['client_nickname'];
$db_cache['all_user'][$uid]['lastseen'] = $nowtime;
Expand Down
Loading

0 comments on commit b96e32b

Please sign in to comment.