diff --git a/cronjob.php b/cronjob.php index c8904f3..fac2e22 100644 --- a/cronjob.php +++ b/cronjob.php @@ -2,47 +2,5 @@ require_once('config.inc.php'); require_once('functions.php'); require_once($framework); - -if(__FILE__ != get_included_files()[0]) { - $server = TeamSpeak3::factory('serverquery://'.$user.':'.$passwd.'@'.$host.':'.$queryport.'/?server_port='.$voiceport); -} - -$exceptions = array_unique(array_merge($exceptions, $roots)); - -foreach($roots as $root) { - $root = $server->channelGetByName($root); - $subs = $root->subChannelList(); - foreach($subs as $sub) { - if(catchExceptions($sub['channel_name'], $exceptions)) { - continue; - } - - $groups = $sub->subChannelList(); - $groupCount = count($groups); - - $delete = false; - $i = 0; - foreach($groups as $group) { - if(catchExceptions($group['channel_name'], $exceptions)) { - $groupCount--; - continue; - } - $i++; - if($delete == true AND $group['total_clients'] == 0) { - $group->delete(); - } - if($group['total_clients'] == 0) { - $delete = true; - } - if($i == $groupCount AND $delete == false) { - $regex = '#([0-9]{1,3})#e'; - $replacement = '("$1" + 1)'; - $newName = preg_replace($regex, $replacement, $group['channel_name']); - createChannel($server, $newName, $sub, $options); - } - } - if(empty($groups) OR $i == 0) { - createChannel($server, $default, $sub, $options, array('channel_flag_permanent' => TRUE)); - } - } -} +$server = TeamSpeak3::factory('serverquery://'.$user.':'.$passwd.'@'.$host.':'.$queryport.'/?server_port='.$voiceport); +require_once('main.php'); diff --git a/main.php b/main.php new file mode 100644 index 0000000..93b28f5 --- /dev/null +++ b/main.php @@ -0,0 +1,40 @@ +channelGetByName($root); + $subs = $root->subChannelList(); + foreach($subs as $sub) { + if(catchExceptions($sub['channel_name'], $exceptions)) { + continue; + } + + $groups = $sub->subChannelList(); + $groupCount = count($groups); + + $delete = false; + $i = 0; + foreach($groups as $group) { + if(catchExceptions($group['channel_name'], $exceptions)) { + $groupCount--; + continue; + } + $i++; + if($delete == true AND $group['total_clients'] == 0) { + $group->delete(); + } + if($group['total_clients'] == 0) { + $delete = true; + } + if($i == $groupCount AND $delete == false) { + $regex = '#([0-9]{1,3})#e'; + $replacement = '("$1" + 1)'; + $newName = preg_replace($regex, $replacement, $group['channel_name']); + createChannel($server, $newName, $sub, $options); + } + } + if(empty($groups) OR $i == 0) { + createChannel($server, $default, $sub, $options, array('channel_flag_permanent' => TRUE)); + } + } +} diff --git a/service.php b/service.php index f93f55e..bc7eaec 100644 --- a/service.php +++ b/service.php @@ -1,8 +1,10 @@