From d0565ba96d63023b4c103f7e57821f90a09b7b35 Mon Sep 17 00:00:00 2001 From: lub Date: Tue, 27 Aug 2019 16:28:40 +0200 Subject: [PATCH] put foreach in a while(true) loop --- main.php | 75 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/main.php b/main.php index e84c3f4..13f30bd 100644 --- a/main.php +++ b/main.php @@ -7,40 +7,43 @@ $server = TeamSpeak3::factory('serverquery://'.$user.':'.$passwd.'@'.$host.':'.$ $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; - } +while(true) { + 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)); - } - } -} + $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)); + } + } + } + sleep(1); +} \ No newline at end of file