diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df84292 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +ts3 +config.inc.php diff --git a/README.md b/README.md index 65db261..caeb5fe 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,16 @@ TS3-Autochannel =============== -Keeps your TS3 group channel amount at a minimum +This little PHP script automatically creates Channels if all others are occupied and also deletes them after they aren't needed any more. + +There are some requirements to the channel structure: + +1. A root channel +2. sub channels (genres, games, modes...) +3. group channels <- these are for users + +The root channels can be nested of course and you can set exceptional channels which are ignored during the excecution. + +![reference tree](https://raw.githubusercontent.com/GameModeOn/TS3-Autochannel/master/images/reference.jpg) + +![live and in action](https://raw.githubusercontent.com/GameModeOn/TS3-Autochannel/master/images/live.jpg) diff --git a/config.inc.php.dist b/config.inc.php.dist new file mode 100644 index 0000000..6d298fa --- /dev/null +++ b/config.inc.php.dist @@ -0,0 +1,12 @@ +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)) { + 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); + } + } + if(empty($groups) OR $i == 0) { + createChannel($server, $default, $sub); + } + } +} + +function createChannel($server, $name, $parent) { + return $server->channelCreate( + array( + 'channel_name' => $name, + 'channel_flag_permanent' => TRUE, + 'cpid' => $parent->getId() + ) + ); +} +function catchExceptions($name, $excpetions) { + foreach($excpetions as $exception) { + if($name == $exception) { + return true; + } + } + return false; +} diff --git a/images/live.jpg b/images/live.jpg new file mode 100644 index 0000000..32496d8 Binary files /dev/null and b/images/live.jpg differ diff --git a/images/reference.jpg b/images/reference.jpg new file mode 100644 index 0000000..321a27d Binary files /dev/null and b/images/reference.jpg differ