release 1.3.12

This commit is contained in:
Newcomer1989
2020-09-22 18:56:47 +02:00
parent 3ab200784d
commit 3a333716a2
54 changed files with 845 additions and 1195 deletions

View File

@@ -133,32 +133,51 @@ if($addons_config['assign_groups_active']['value'] == '1') {
}
enter_logfile($cfg,4,"Loading addons [done]");
function sendmessage($ts3, $cfg, $uuid, $msg, $erromsg=NULL, $errcode=NULL, $successmsg=NULL, $nolog=NULL) {
function sendmessage($ts3, $cfg, $uuid, $targetmode, $targetid=NULL, $msg, $erromsg=NULL, $loglevel=NULL, $successmsg=NULL, $nolog=NULL) {
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);
if ($targetmode==2 && $targetid!=NULL) {
$ts3->serverGetSelected()->channelGetById($targetid)->message("\n".$frag);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage fragment to channel (ID: $targetid): ".$frag);
} elseif ($targetmode==3) {
$ts3->serverGetSelected()->message("\n".$frag);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage fragment to server: ".$frag);
} elseif ($targetmode==1 && $targetid!=NULL) {
$ts3->serverGetSelected()->clientGetById($targetid)->message("\n".$frag);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage fragment to connectionID $targetid (uuid $uuid): ".$frag);
} else {
$ts3->serverGetSelected()->clientGetByUid($uuid)->message("\n".$frag);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage fragment to uuid $uuid (connectionID $targetid): ".$frag);
}
}
} 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 ($targetmode==2 && $targetid!=NULL) {
$ts3->serverGetSelected()->channelGetById($targetid)->message($msg);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage to channel (ID: $targetid): ".$msg);
} elseif ($targetmode==3) {
$ts3->serverGetSelected()->message($msg);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage to server: ".$msg);
} elseif ($targetmode==1 && $targetid!=NULL) {
$ts3->serverGetSelected()->clientGetById($targetid)->message($msg);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage to connectionID $targetid (uuid $uuid): ".$msg);
} else {
$ts3->serverGetSelected()->clientGetByUid($uuid)->message($msg);
if($nolog==NULL) enter_logfile($cfg,6,"sendmessage to uuid $uuid (connectionID $targetid): ".$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());
if($loglevel!=NULL) {
enter_logfile($cfg,$loglevel,$erromsg." TS3: ".$e->getCode().': '.$e->getMessage());
} else {
enter_logfile($cfg,3,"sendmessage: ".$e->getCode().': '.$e->getMessage());
enter_logfile($cfg,3,"sendmessage: ".$e->getCode().': '.$e->getMessage().", targetmode: $targetmode, targetid: $targetid");
}
}
}
@@ -297,7 +316,6 @@ function run_bot() {
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) {
@@ -307,8 +325,8 @@ function run_bot() {
$checkgroups = 0;
if(isset($groupslist) && $groupslist != NULL) {
if(isset($cfg['rankup_definition']) && $cfg['rankup_definition'] != NULL) {
foreach($cfg['rankup_definition'] as $time => $groupid) {
if(!isset($groupslist[$groupid]) && $groupid != NULL) {
foreach($cfg['rankup_definition'] as $rank) {
if(!isset($groupslist[$rank['group']]) && $rank['group'] != NULL) {
$checkgroups++;
}
}
@@ -351,9 +369,9 @@ function run_bot() {
if(isset($groupslist) && $groupslist != NULL) {
if(isset($cfg['rankup_definition']) && $cfg['rankup_definition'] != NULL) {
foreach($cfg['rankup_definition'] as $time => $groupid) {
if(!isset($groupslist[$groupid]) && $groupid != NULL) {
enter_logfile($cfg,1,' '.sprintf($lang['upgrp0001'], $groupid, $lang['wigrptime']));
foreach($cfg['rankup_definition'] as $rank) {
if(!isset($groupslist[$rank['group']]) && $rank['group'] != NULL) {
enter_logfile($cfg,1,' '.sprintf($lang['upgrp0001'], $rank['group'], $lang['wigrptime']));
$errcnf++;
}
}
@@ -385,8 +403,8 @@ function run_bot() {
} else {
if($lastupdate['timestamp'] != 0 && ($lastupdate['timestamp'] + 10) > time()) {
if(isset($cfg['webinterface_admin_client_unique_id_list']) && $cfg['webinterface_admin_client_unique_id_list'] != NULL) {
foreach(array_flip($cfg['webinterface_admin_client_unique_id_list']) as $clientid) {
sendmessage($ts3server, $cfg, $clientid, sprintf($lang['upmsg2'], $cfg['version_current_using'], 'https://ts-ranksystem.com/#changelog'), sprintf($lang['upusrerr'], $clientid), 6, sprintf($lang['upusrinf'], $clientid));
foreach(array_flip($cfg['webinterface_admin_client_unique_id_list']) as $clientuuid) {
sendmessage($ts3server, $cfg, $clientuuid, NULL, sprintf($lang['upmsg2'], $cfg['version_current_using'], 'https://ts-ranksystem.com/#changelog'), sprintf($lang['upusrerr'], $clientuuid), 6, sprintf($lang['upusrinf'], $clientuuid));
}
}
}
@@ -541,8 +559,8 @@ function run_bot() {
if($looptime < 1) {
$loopsleep = (1 - $looptime);
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
if($cfg['teamspeak_query_encrypt_switch'] == 1 || version_compare($ts3version['version'],'1.4.0','>=') && version_compare($ts3version['version'],'2.9.9','<=')) {
// no wait for data to become available on the stream on SSH due issues with non-blocking mode or TeaSpeak
usleep(round($loopsleep * 1000000));
} else {
$ts3server->getAdapter()->waittsn($loopsleep, 50000); // 50ms delay for CPU reason

View File

@@ -377,6 +377,7 @@ function calc_serverstats($ts3,$mysqlcon,&$cfg,$dbname,$dbtype,$serverinfo,&$db_
if ($db_cache['job_check']['get_version']['timestamp'] < ($nowtime - 43199)) {
$db_cache['job_check']['get_version']['timestamp'] = $nowtime;
enter_logfile($cfg,6,"Get the latest Ranksystem Version.");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ts-n.net/ranksystem/'.$cfg['version_update_channel']);
curl_setopt($ch, CURLOPT_REFERER, 'TSN Ranksystem');

View File

@@ -172,13 +172,15 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
$dtT = new DateTime("@".round($activetime));
foreach($sgroups as $clientgroup => $dummy) {
if(isset($cfg['rankup_definition_flipped'][$clientgroup])) {
$client_groups_rankup[$clientgroup] = 0;
foreach($cfg['rankup_definition'] as $rank) {
if($rank['group'] == $clientgroup && $rank['keep'] == 0) {
$client_groups_rankup[$clientgroup] = 0;
}
}
}
$grpcount=0;
foreach ($cfg['rankup_definition'] as $time => $groupid) {
foreach ($cfg['rankup_definition'] as $rank) {
$grpcount++;
if(isset($cfg['rankup_excepted_channel_id_list'][$client['cid']]) || (($db_cache['all_user'][$uid]['except'] == 3 || $db_cache['all_user'][$uid]['except'] == 2) && $cfg['rankup_excepted_mode'] == 1)) {
$count = $db_cache['all_user'][$uid]['count'];
@@ -186,41 +188,49 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
if($except != 2 && $except != 3) {
$except = 1;
}
} 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])) {
} elseif ($activetime > $rank['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[$rank['group']])) {
if ($db_cache['all_user'][$uid]['grpid'] != NULL && $db_cache['all_user'][$uid]['grpid'] != 0 && isset($sgroups[$db_cache['all_user'][$uid]['grpid']])) {
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']));
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']));
$donotremove = 0;
foreach($cfg['rankup_definition'] as $rank2) {
if($rank2['group'] == $db_cache['all_user'][$uid]['grpid'] && $rank2['keep'] == 1 && $activetime > $rank2['time']) {
$donotremove = 1; break;
}
}
if($donotremove == 0) {
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']));
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']));
}
}
}
usleep($cfg['teamspeak_query_command_delay']);
try {
$ts3->serverGroupClientAdd($groupid, $client['client_database_id']);
$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'][$groupid]['sgidname'], $groupid, $name, $uid, $client['client_database_id']));
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'][$groupid]['sgidname'],$client['client_nickname']), sprintf($lang['sgrprerr'], $name, $uid, $client['client_database_id'], $db_cache['groups'][$groupid]['sgidname'],$groupid), 2);
sendmessage($ts3, $cfg, $uid, 1, NULL, sprintf($cfg['rankup_message_to_user'],$days,$hours,$mins,$secs,$db_cache['groups'][$rank['group']]['sgidname'],$client['client_nickname']), 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'], $name, $uid, $client['client_database_id'], $db_cache['groups'][$groupid]['sgidname'], $groupid));
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']));
}
$db_cache['all_user'][$uid]['grpid'] = $groupid;
}
if($grpcount == 1) {
$db_cache['all_user'][$uid]['nextup'] = 0;
}
$db_cache['all_user'][$uid]['grpid'] = $rank['group'];
break;
} else {
$db_cache['all_user'][$uid]['nextup'] = $time - $activetime;
$db_cache['all_user'][$uid]['nextup'] = $rank['time'] - $activetime;
}
}
@@ -260,20 +270,20 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
$db_cache['all_user'][$uid]['except'] = $except;
} else {
$db_cache['all_user'][$uid]['grpid'] = 0;
foreach ($cfg['rankup_definition'] as $time => $groupid) {
if (isset($sgroups[$groupid])) {
$db_cache['all_user'][$uid]['grpid'] = $groupid;
foreach ($cfg['rankup_definition'] as $rank) {
if (isset($sgroups[$rank['group']])) {
$db_cache['all_user'][$uid]['grpid'] = $rank['group'];
break;
}
}
$insertdata[] = array(
"uuid" => $mysqlcon->quote($client['client_unique_identifier'], ENT_QUOTES),
"cldbid" => $client['client_database_id'],
"count" => 0,
"count" => $addtime,
"name" => $name,
"lastseen" => $nowtime,
"grpid" => $db_cache['all_user'][$uid]['grpid'],
"nextup" => (key($cfg['rankup_definition']) - 1),
"nextup" => (key($cfg['rankup_definition']) - $addtime),
"idle" => 0,
"cldgroup" => $client['client_servergroups'],
"boosttime" => 0,
@@ -286,9 +296,9 @@ function calc_user($ts3,$mysqlcon,$lang,$cfg,$dbname,$allclients,$phpcommand,&$d
"cid" => $client['cid']
);
$db_cache['all_user'][$uid]['cldbid'] = $client['client_database_id'];
$db_cache['all_user'][$uid]['count'] = 0;
$db_cache['all_user'][$uid]['count'] = $addtime;
$db_cache['all_user'][$uid]['idle'] = 0;
$db_cache['all_user'][$uid]['nextup'] = (key($cfg['rankup_definition']) - 1);
$db_cache['all_user'][$uid]['nextup'] = (key($cfg['rankup_definition']) - $addtime);
$db_cache['all_user'][$uid]['firstcon'] = $nowtime;
$db_cache['all_user'][$uid]['boosttime'] = 0;
$db_cache['all_user'][$uid]['grpsince'] = 0;

View File

@@ -79,11 +79,11 @@ function calc_userstats($ts3,$mysqlcon,$cfg,$dbname,&$db_cache) {
$sqlexec .= "UPDATE `$dbname`.`user` SET `cldbid`={$getcldbid[0]} WHERE `uuid`='$uuid';\n";
// select current user_snapshot entries and insert this with the new database-ID
foreach($userdata[$userstats['cldbid']] as $id => $data) {
$allinsert .= "('{$getcldbid[0]}',$id,{$data['count']},{$data['idle']}),";
$allinsert .= "($id,'{$getcldbid[0]}',{$data['count']},{$data['idle']}),";
}
if ($allinsert != '') {
$allinsert = substr($allinsert, 0, -1);
$sqlexec .= "INSERT INTO `$dbname`.`user_snapshot` (`cldbid`,`id`,`count`,`idle`) VALUES $allinsert ON DUPLICATE KEY UPDATE `count_week`=VALUES(`count_week`),`count_month`=VALUES(`count_month`),`idle_week`=VALUES(`idle_week`);\nDELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$userstats['cldbid']}';\n";
$sqlexec .= "INSERT INTO `$dbname`.`user_snapshot` (`id`,`cldbid`,`count`,`idle`) VALUES $allinsert ON DUPLICATE KEY UPDATE `count`=VALUES(`count`),`idle`=VALUES(`idle`);\nDELETE FROM `$dbname`.`user_snapshot` WHERE `cldbid`='{$userstats['cldbid']}';\n";
}
unset($allinsert);
enter_logfile($cfg,4," Store new cldbid ".$getcldbid[0]." for client (uuid: ".$uuid." old cldbid: ".$userstats['cldbid'].")");

View File

@@ -1,6 +1,6 @@
<?PHP
function check_db($mysqlcon,$lang,$cfg,$dbname) {
$cfg['version_latest_available'] = '1.3.11';
$cfg['version_latest_available'] = '1.3.12';
enter_logfile($cfg,5,"Check Ranksystem database for updates...");
function check_double_cldbid($mysqlcon,$cfg,$dbname) {
@@ -40,7 +40,7 @@ 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','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','webinterface/nav.php');
$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','webinterface/nav.php','stats/nav.php');
function rmdir_recursive($folder,$cfg) {
foreach(scandir($folder) as $file) {
if ('.' === $file || '..' === $file) continue;
@@ -345,9 +345,6 @@ function check_db($mysqlcon,$lang,$cfg,$dbname) {
}
if(version_compare($cfg['version_current_using'], '1.3.11', '<')) {
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`.`addons_config` (`param`,`value`) VALUES ('assign_groups_excepted_groupids','');") === false) { } else {
enter_logfile($cfg,4," [1.3.11] Adjusted table addons_config successfully.");
}
@@ -360,10 +357,20 @@ function check_db($mysqlcon,$lang,$cfg,$dbname) {
if($mysqlcon->exec("CREATE INDEX `user_online` ON `$dbname`.`user` (`online`,`lastseen`)") === false) { }
}
if(version_compare($cfg['version_current_using'], '1.3.11', '<')) {
if($mysqlcon->exec("INSERT INTO `$dbname`.`cfg_params` (`param`,`value`) VALUES ('imprint_enabled', '0'),('imprint_address', 'Max Mustermann<br>Musterstraße 13<br>05172 Musterhausen<br>Germany'),('imprint_email', 'info@example.com'),('imprint_phone', '+49 171 1234567'),('imprint_notes', NULL),('imprint_privacy-policy', 'Add your own privacy policy here. (editable in the webinterface)');") === false) { } else {
enter_logfile($cfg,4," [1.3.11] Added new imprint values.");
if(version_compare($cfg['version_current_using'], '1.3.12', '<')) {
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`.`cfg_params` (`param`,`value`) VALUES ('stats_imprint_switch', '0'),('stats_imprint_address', 'Max Mustermann<br>Musterstraße 13<br>05172 Musterhausen<br>Germany'),('stats_imprint_address_url', 'https://site.url/imprint/'), ('stats_imprint_email', 'info@example.com'),('stats_imprint_phone', '+49 171 1234567'),('stats_imprint_notes', NULL),('stats_imprint_privacypolicy', 'Add your own privacy policy here. (editable in the webinterface)'),('stats_imprint_privacypolicy_url', 'https://site.url/privacy/');") === false) { } else {
enter_logfile($cfg,4," [1.3.12] Added new imprint values.");
}
if($mysqlcon->exec("CREATE INDEX `snapshot_id` ON `$dbname`.`user_snapshot` (`id`)") === false) { }
if($mysqlcon->exec("CREATE INDEX `snapshot_cldbid` ON `$dbname`.`user_snapshot` (`cldbid`)") === 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) { }
}
$cfg = set_new_version($mysqlcon,$cfg,$dbname);
}

View File

@@ -2,8 +2,18 @@
function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host) {
global $lang,$cfg,$mysqlcon,$dbname,$phpcommand,$ts3,$whoami;
enter_logfile($cfg,6,"whoami: ".print_r($host->whoami(),true));
if($event["targetmode"] == 1) {
$targetid = $event["invokerid"];
} elseif($event["targetmode"] == 2) {
$targetid = $host->whoami()["client_channel_id"];
} else {
$targetid = NULL;
}
if($host->whoami()["client_unique_identifier"] != $event["invokeruid"] && substr($event["msg"],0,1) === "!") {
enter_logfile($cfg,6,"event: ".print_r($event,true));
if($host->whoami()["client_id"] != $event["invokerid"] && substr($event["msg"],0,1) === "!") {
$uuid = $event["invokeruid"];
$admin = 0;
foreach(array_flip($cfg['webinterface_admin_client_unique_id_list']) as $auuid) {
@@ -11,9 +21,9 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
$admin = 1;
}
}
enter_logfile($cfg,6,"Client ".$event["invokername"]." (".$event["invokeruid"].") sent textmessage: ".$event["msg"]);
if((strstr($event["msg"], '!nextup') || strstr($event["msg"], '!next')) && $cfg['rankup_next_message_mode'] != 0) {
if(($user = $mysqlcon->query("SELECT `count`,`nextup`,`idle`,`except`,`name`,`rank`,`grpsince`,`grpid` FROM `$dbname`.`user` WHERE `uuid`='$uuid'")->fetch()) === false) {
enter_logfile($cfg,2,"handle_messages 1:".print_r($mysqlcon->errorInfo(), true));
@@ -26,11 +36,12 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
ksort($cfg['rankup_definition']);
$countgrp = count($cfg['rankup_definition']);
$grpcount = 0;
foreach ($cfg['rankup_definition'] as $time => $groupid) {
foreach ($cfg['rankup_definition'] as $rank) {
if ($cfg['rankup_time_assess_mode'] == 1) {
$nextup = $time - $user['count'] + $user['idle'];
$nextup = $rank['time'] - $user['count'] + $user['idle'];
} else {
$nextup = $time - $user['count'];
$nextup = $rank['time'] - $user['count'];
}
$dtF = new DateTime("@0");
$dtT = new DateTime("@".round($nextup));
@@ -40,15 +51,16 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
$secs = $dtF->diff($dtT)->format('%s');
$name = $user['name'];
$grpcount++;
if ($nextup > 0 && $nextup < $time || $grpcount == $countgrp && $nextup <= 0) {
if ($nextup > 0 && $nextup < $rank['time'] || $grpcount == $countgrp && $nextup <= 0) {
if ($grpcount == $countgrp && $nextup <= 0) {
$msg = sprintf($cfg['rankup_next_message_2'], $days, $hours, $mins, $secs, $sqlhisgroup[$groupid]['sgidname'], $name, $user['rank'], $sqlhisgroup[$user['grpid']]['sgidname'], date('Y-m-d H:i:s', $user['grpsince']));
$msg = sprintf($cfg['rankup_next_message_2'], $days, $hours, $mins, $secs, $sqlhisgroup[$rank['group']]['sgidname'], $name, $user['rank'], $sqlhisgroup[$user['grpid']]['sgidname'], date('Y-m-d H:i:s', $user['grpsince']));
} elseif ($user['except'] == 2 || $user['except'] == 3) {
$msg = sprintf($cfg['rankup_next_message_3'], $days, $hours, $mins, $secs, $sqlhisgroup[$groupid]['sgidname'], $name, $user['rank'], $sqlhisgroup[$user['grpid']]['sgidname'], date('Y-m-d H:i:s', $user['grpsince']));
$msg = sprintf($cfg['rankup_next_message_3'], $days, $hours, $mins, $secs, $sqlhisgroup[$rank['group']]['sgidname'], $name, $user['rank'], $sqlhisgroup[$user['grpid']]['sgidname'], date('Y-m-d H:i:s', $user['grpsince']));
} else {
$msg = sprintf($cfg['rankup_next_message_1'], $days, $hours, $mins, $secs, $sqlhisgroup[$groupid]['sgidname'], $name, $user['rank'], $sqlhisgroup[$user['grpid']]['sgidname'], date('Y-m-d H:i:s', $user['grpsince']));
$msg = sprintf($cfg['rankup_next_message_1'], $days, $hours, $mins, $secs, $sqlhisgroup[$rank['group']]['sgidname'], $name, $user['rank'], $sqlhisgroup[$user['grpid']]['sgidname'], date('Y-m-d H:i:s', $user['grpsince']));
}
sendmessage($host,$cfg,$event["invokeruid"],$msg);
$targetid = $event["invokerid"];
sendmessage($host, $cfg, $event["invokeruid"], 1, $targetid, $msg);
if($cfg['rankup_next_message_mode'] == 1) {
break;
}
@@ -60,22 +72,22 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
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'));
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, 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']));
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, 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']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $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']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0005']);
if (substr(php_uname(), 0, 7) == "Windows") {
exec("start ".$phpcommand." ".$path."worker.php stop");
file_put_contents(substr(__DIR__,0,-4).'logs\autostart_deactivated',"");
@@ -85,14 +97,14 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
}
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']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $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"], "restart"));
$path = substr(__DIR__, 0, -4);
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0006']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0006']);
if (substr(php_uname(), 0, 7) == "Windows") {
exec("start ".$phpcommand." ".$path."worker.php restart");
} else {
@@ -100,7 +112,7 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
}
return;
} elseif (strstr($event["msg"], '!restart') || strstr($event["msg"], '!reboot')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0003']);
return;
}
@@ -108,10 +120,10 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
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']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0008']);
return;
} elseif(strstr($event["msg"], '!checkupdate') || strstr($event["msg"], '!update')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0003']);
return;
}
@@ -120,10 +132,10 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
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']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0009'] ." ". $lang['msg0010']);
return;
} elseif(strstr($event["msg"], '!clean')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0003']);
return;
}
@@ -135,25 +147,25 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
enter_logfile($cfg,4,"handle_messages 15:".print_r($mysqlcon->errorInfo(), true));
}
}
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0011'] ." ". $lang['msg0010']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0011'] ." ". $lang['msg0010']);
return;
} elseif(strstr($event["msg"], '!reloadgroups')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $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.", (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'])));
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, 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\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']));
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, 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)));
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, 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;
}
@@ -199,7 +211,7 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
}
}
} else {
$lines[] = "Perhaps the logfile got rotated or something goes wrong due opening file!\n";
$lines[] = "Perhaps the logfile got rotated or something goes wrong due opening the file!\n";
$lines[] = "No log entry found...\n";
}
$lines = array_reverse($lines);
@@ -207,12 +219,13 @@ function handle_messages(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3
foreach ($lines as $line) {
$message .= $line;
}
sendmessage($host, $cfg, $event["invokeruid"], $message, NULL, NULL, NULL, $nolog=1);
$targetid = $event["invokerid"];
sendmessage($host, $cfg, $event["invokeruid"], 1, $targetid, $message, NULL, NULL, NULL, $nolog=1);
} elseif(strstr($event["msg"], '!logs') || strstr($event["msg"], '!log')) {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0003']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0003']);
}
} elseif($host->whoami()["client_unique_identifier"] != $event["invokeruid"] && $event["targetmode"] == "1") {
sendmessage($host, $cfg, $event["invokeruid"], $lang['msg0002']);
sendmessage($host, $cfg, $event["invokeruid"], $event["targetmode"], $targetid, $lang['msg0002']);
}
}
?>

View File

@@ -22,20 +22,20 @@ function reset_rs($ts3,$mysqlcon,$lang,$cfg,$dbname,&$db_cache) {
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 ".$db_cache['groups'][$groupid]['sgidname']." (ID: ".$groupid.")");
foreach ($cfg['rankup_definition'] as $rank) {
enter_logfile($cfg,5," Getting TS3 servergrouplist for ".$db_cache['groups'][$rank['group']]['sgidname']." (ID: ".$rank['group'].")");
try {
usleep($cfg['teamspeak_query_command_delay']);
$tsclientlist = $ts3->servergroupclientlist($groupid);
$tsclientlist = $ts3->servergroupclientlist($rank['group']);
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'], $db_cache['groups'][$groupid]['sgidname'], $groupid, $all_clients[$tsclient['cldbid']]['name'], $all_clients[$tsclient['cldbid']]['uuid'], $tsclient['cldbid']));
$ts3->serverGroupClientDel($rank['group'], $tsclient['cldbid']);
enter_logfile($cfg,5," ".sprintf($lang['sgrprm'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group'], $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'], $db_cache['groups'][$groupid]['sgidname'], $groupid));
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'], $db_cache['groups'][$rank['group']]['sgidname'], $rank['group']));
$err_cnt++;
}
}

View File

@@ -29,7 +29,7 @@ function server_usage($mysqlcon,$cfg,$dbname,$serverinfo,&$db_cache) {
$dtT = new DateTime("@".round($count));
}
$grpcount=0;
foreach ($cfg['rankup_definition'] as $time => $groupid) {
foreach ($cfg['rankup_definition'] as $time => $dummy) {
$grpcount++;
if ($activetime > $time) {
if($grpcount == 1) {

View File

@@ -170,15 +170,19 @@ function update_groups($ts3,$mysqlcon,$lang,$cfg,$dbname,$serverinfo,&$db_cache,
if(!isset($tsgroupids[$sgid]) && $sgid != 0 && $sgid != NULL) {
$delsgroupids .= $sgid . ",";
unset($db_cache['groups'][$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));
foreach($cfg['rankup_definition'] as $rank) {
if(in_array($sgid, $rank)) {
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));
}
}
}
}
}