Skip to content

Commit b96e32b

Browse files
committed
release 1.3.21
1 parent d2cb86e commit b96e32b

35 files changed

Lines changed: 359 additions & 122 deletions

api/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if (isset($_GET['apikey'])) {
1515
$matchkey = 0;
1616
foreach($cfg['stats_api_keys'] as $apikey => $desc) {
17-
if ($apikey == $_GET['apikey']) $matchkey = 1;
17+
if (hash_equals($apikey, $_GET['apikey'])) $matchkey = 1;
1818
}
1919
if ($matchkey == 0) {
2020
$json = array(

install.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?PHP
2-
$rsversion = '1.3.19';
2+
$rsversion = '1.3.21';
33

44
require_once('other/_functions.php');
55
require_once('other/config.php');
@@ -79,7 +79,16 @@ function install($type, $host, $user, $pass, $dbname, $lang, $mysqlcon, &$err_ms
7979
$err_lvl = 2;
8080
} else {
8181
$count = 1;
82-
if(($mysqlcon->exec("DROP DATABASE `$dbname`")) === false) { }
82+
$stmt = $mysqlcon->query('SHOW DATABASES');
83+
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
84+
if ($row['Database'] == $dbname) {
85+
$dbExists = true;
86+
break;
87+
}
88+
}
89+
if ($dbExists) {
90+
if(($mysqlcon->exec("DROP DATABASE `$dbname`")) === false) { }
91+
}
8392

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

171-
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) {
180+
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) {
172181
$err_msg .= $lang['isntwidbmsg'].$mysqlcon->errorCode()." ".print_r($mysqlcon->errorInfo(), true).'<br>'; $err_lvl = 2;
173182
$count++;
174183
}

jobs/addon_channelinfo_toplist.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ function addon_channelinfo_toplist(&$addons_config,$ts3,$mysqlcon,$cfg,$dbname,$
9292
$smarty->assign('CLIENT_NEXT_RANKUP_TIME_'.($nr + 1),$userdata[$nr]['nextup']);
9393

9494
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_ID_'.($nr + 1),$userdata[$nr]['grpid']);
95-
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['sgidname'])) {
95+
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['sgidname']) && $userdata[$nr]['grpid'] != 0) {
9696
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_NAME_'.($nr + 1),substr($db_cache['groups'][$userdata[$nr]['grpid']]['sgidname'],1,-1));
9797
} else {
9898
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_NAME_'.($nr + 1),'unknown_group');
9999
}
100-
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['iconid']) && isset($db_cache['groups'][$userdata[$nr]['grpid']]['ext'])) {
100+
if(isset($db_cache['groups'][$userdata[$nr]['grpid']]['iconid']) && isset($db_cache['groups'][$userdata[$nr]['grpid']]['ext']) && $userdata[$nr]['grpid'] != 0) {
101101
$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']);
102102
} else {
103103
$smarty->assign('CLIENT_CURRENT_RANK_GROUP_ICON_URL_'.($nr + 1),'file_not_found');

jobs/bot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function run_bot(&$cfg) {
145145

146146
enter_logfile($cfg,9," Select virtual server...");
147147
try {
148-
if(version_compare($ts3version['version'],'3.4.0','>=')) {
148+
if(version_compare($ts3version['version'],'3.4.0','>=') || version_compare($ts3version['version'],'3.0.0','<=')) {
149149
usleep($cfg['teamspeak_query_command_delay']);
150150
$ts3server = $ts3host->serverGetByPort($cfg['teamspeak_voice_port'], $cfg['teamspeak_query_nickname']);
151151
} else {

jobs/calc_serverstats.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ function calc_serverstats($ts3,$mysqlcon,&$cfg,$dbname,$dbtype,$serverinfo,&$db_
408408
$cfg['temp_db_version']
409409
);
410410
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
411-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
412-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
413411
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
414412
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
415413
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
@@ -435,14 +433,20 @@ function calc_serverstats($ts3,$mysqlcon,&$cfg,$dbname,$dbtype,$serverinfo,&$db_
435433
}
436434

437435
//Calc Rank
436+
$dbversion = $mysqlcon->getAttribute(PDO::ATTR_SERVER_VERSION);
437+
preg_match("/^[0-9\.-]+/", $dbversion, $version_number);
438438
if ($cfg['rankup_time_assess_mode'] == 1) {
439-
$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";
440-
//MySQL 8 or above
441-
//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`;
439+
if(version_compare($version_number[0], '10.6', '>=') || version_compare($version_number[0], '5.5.5-10.6', '>=')) {
440+
$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";
441+
} else {
442+
$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";
443+
}
442444
} else {
443-
$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";
444-
//MySQL 8 or above
445-
//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`;
445+
if(version_compare($version_number[0], '10.6', '>=') || version_compare($version_number[0], '5.5.5-10.6', '>=')) {
446+
$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";
447+
} else {
448+
$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";
449+
}
446450
}
447451
}
448452

jobs/calc_user.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
9090
$name = $mysqlcon->quote((mb_substr(mb_convert_encoding($client['client_nickname'],'UTF-8','auto'),0,30)), ENT_QUOTES);
9191
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
9292
$sgroups = array_flip(explode(",", $client['client_servergroups']));
93-
if(strlen($client['client_country']) > 2 || $client['client_country'] == '') $client['client_country'] = 'XX';
93+
if($client['client_country'] !== NULL && strlen($client['client_country']) > 2 || $client['client_country'] === NULL) $client['client_country'] = 'XX';
9494
$client['client_platform'] = mb_substr($client['client_platform'],0,32);
9595
$client['client_version'] = mb_substr($client['client_version'],0,64);
9696

@@ -108,17 +108,18 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
108108
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) {
109109
$db_cache['all_user'][$uid]['count'] = 0;
110110
$db_cache['all_user'][$uid]['idle'] = 0;
111-
enter_logfile($cfg,5,sprintf($lang['resettime'], $name, $uid, $client['client_database_id']));
112-
$sqlexec .= "DELETE FROM `$dbname`.`user_snapshot` WHERE `uuid`='$uid';\n";
111+
enter_logfile($cfg,5,sprintf($lang['resettime'], $client['client_nickname'], $uid, $client['client_database_id']));
112+
$sqlexec .= "DELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$client['client_database_id']}';\n";
113113
}
114114
$except = 0;
115115
}
116116
if(isset($db_cache['all_user'][$uid])) {
117117
$idle = $db_cache['all_user'][$uid]['idle'] + $clientidle;
118118
if ($db_cache['all_user'][$uid]['cldbid'] != $client['client_database_id'] && $cfg['rankup_client_database_id_change_switch'] == 1) {
119-
enter_logfile($cfg,5,sprintf($lang['changedbid'], $name, $uid, $client['client_database_id'], $db_cache['all_user'][$uid]['cldbid']));
119+
enter_logfile($cfg,5,sprintf($lang['changedbid'], $client['client_nickname'], $uid, $client['client_database_id'], $db_cache['all_user'][$uid]['cldbid']));
120120
$count = 1;
121121
$idle = 0;
122+
$boosttime = 0;
122123
} else {
123124
$hitboost = 0;
124125
$boosttime = $db_cache['all_user'][$uid]['boosttime'];
@@ -129,14 +130,15 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
129130
if($db_cache['all_user'][$uid]['boosttime']==0) {
130131
$boosttime = $nowtime;
131132
} else {
132-
if ($nowtime > $db_cache['all_user'][$uid]['boosttime'] + $boost['time']) {
133+
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))) {
133134
usleep($cfg['teamspeak_query_command_delay']);
134135
try {
135136
$ts3->serverGroupClientDel($boost['group'], $client['client_database_id']);
136137
$boosttime = 0;
137-
enter_logfile($cfg,5,sprintf($lang['sgrprm'], $db_cache['groups'][$boost['group']]['sgidname'], $boost['group'], $name, $uid, $client['client_database_id']).' [Boost-Group]');
138+
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]');
138139
} catch (Exception $e) {
139-
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']));
140+
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']));
141+
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
140142
}
141143
}
142144
}
@@ -189,31 +191,35 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
189191
$donotremove = 1; break;
190192
}
191193
}
192-
if($donotremove == 0) {
194+
if($donotremove == 0 && (!isset($db_cache['all_user'][$uid]['grouperror']) || $db_cache['all_user'][$uid]['grouperror'] < ($nowtime - 300))) {
193195
usleep($cfg['teamspeak_query_command_delay']);
194196
try {
195197
$ts3->serverGroupClientDel($db_cache['all_user'][$uid]['grpid'], $client['client_database_id']);
196-
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']));
198+
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']));
197199
if(isset($client_groups_rankup[$db_cache['all_user'][$uid]['grpid']])) unset($client_groups_rankup[$db_cache['all_user'][$uid]['grpid']]);
198200
} catch (Exception $e) {
199-
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']));
201+
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']));
202+
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
200203
}
201204
}
202205
}
203-
usleep($cfg['teamspeak_query_command_delay']);
204-
try {
205-
$ts3->serverGroupClientAdd($rank['group'], $client['client_database_id']);
206-
$db_cache['all_user'][$uid]['grpsince'] = $nowtime;
207-
enter_logfile($cfg,5,sprintf($lang['sgrpadd'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group'], $name, $uid, $client['client_database_id']));
208-
if ($cfg['rankup_message_to_user_switch'] == 1) {
209-
$days = $dtF->diff($dtT)->format('%a');
210-
$hours = $dtF->diff($dtT)->format('%h');
211-
$mins = $dtF->diff($dtT)->format('%i');
212-
$secs = $dtF->diff($dtT)->format('%s');
213-
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);
206+
if(!isset($db_cache['all_user'][$uid]['grouperror']) || $db_cache['all_user'][$uid]['grouperror'] < ($nowtime - 300)) {
207+
usleep($cfg['teamspeak_query_command_delay']);
208+
try {
209+
$ts3->serverGroupClientAdd($rank['group'], $client['client_database_id']);
210+
$db_cache['all_user'][$uid]['grpsince'] = $nowtime;
211+
enter_logfile($cfg,5,sprintf($lang['sgrpadd'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group'], $client['client_nickname'], $uid, $client['client_database_id']));
212+
if ($cfg['rankup_message_to_user_switch'] == 1) {
213+
$days = $dtF->diff($dtT)->format('%a');
214+
$hours = $dtF->diff($dtT)->format('%h');
215+
$mins = $dtF->diff($dtT)->format('%i');
216+
$secs = $dtF->diff($dtT)->format('%s');
217+
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);
218+
}
219+
} catch (Exception $e) {
220+
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']));
221+
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
214222
}
215-
} catch (Exception $e) {
216-
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']));
217223
}
218224
}
219225
if($grpcount == 1) {
@@ -227,13 +233,14 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
227233
}
228234

229235
foreach($client_groups_rankup as $removegroup => $dummy) {
230-
if($removegroup != NULL && $removegroup != 0 && $removegroup != $db_cache['all_user'][$uid]['grpid']){
236+
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))){
231237
try {
232238
usleep($cfg['teamspeak_query_command_delay']);
233239
$ts3->serverGroupClientDel($removegroup, $client['client_database_id']);
234-
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']));
240+
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']));
235241
} catch (Exception $e) {
236-
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));
242+
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));
243+
$db_cache['all_user'][$uid]['grouperror'] = $nowtime;
237244
}
238245
}
239246
}
@@ -295,7 +302,7 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
295302
$db_cache['all_user'][$uid]['boosttime'] = 0;
296303
$db_cache['all_user'][$uid]['grpsince'] = 0;
297304
$db_cache['all_user'][$uid]['except'] = $except;
298-
enter_logfile($cfg,5,sprintf($lang['adduser'], $name, $uid, $client['client_database_id']));
305+
enter_logfile($cfg,5,sprintf($lang['adduser'], $client['client_nickname'], $uid, $client['client_database_id']));
299306
}
300307
$db_cache['all_user'][$uid]['name'] = $client['client_nickname'];
301308
$db_cache['all_user'][$uid]['lastseen'] = $nowtime;

0 commit comments

Comments
 (0)