Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('libraries/TeamSpeak3/TeamSpeak3.php');
- $ts3 = TeamSpeak3::factory('serverquery://dave:<passwort>@10.10.12.100:10011?server_port=9987');
- $mainChannel = 5;
- $reserve_channels = 2;
- $empty = 0;
- foreach ($ts3->channelList(['pid' => $mainChannel]) as $channel) {
- if ($channel->total_clients === 0) {
- $empty++;
- $empty_channels[$channel->channel_order] = $channel->cid;
- }
- $channels[] = $channel;
- }
- if ($empty > $reserve_channels) {
- $i = 0;
- foreach ($empty_channels as $order => $cid) {
- if ($i > 1) {
- $ts3->channelDelete($cid, true);
- } else {
- $i++;
- }
- }
- $ts3->channelListReset();
- $i = 1;
- foreach ($ts3->channelList(['pid' => $mainChannel]) as $channel) {
- try {
- $channel->modify([
- 'channel_name' => 'Talk #'.$i
- ]);
- } catch (Exception $e) {
- $i++;
- echo $e->getMessage().' - '.$i.'<br/>';
- }
- }
- } else if ($empty < $reserve_channels) {
- $i = 1;
- while (true) {
- try {
- if ($i > 10) break;
- $cid = $ts3->channelCreate([
- 'channel_name' => 'Talk #'.$i,
- 'cpid' => $mainChannel
- ]);
- $empty++;
- if ($empty >= $reserve_channels) break;
- } catch (Exception $e) {
- $i++;
- echo $e->getMessage().' - '.$i.'<br/>';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement