Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2.  
  3.     require_once('libraries/TeamSpeak3/TeamSpeak3.php');
  4.    
  5.     $ts3 = TeamSpeak3::factory('serverquery://dave:<passwort>@10.10.12.100:10011?server_port=9987');
  6.    
  7.     $mainChannel = 5;
  8.     $reserve_channels = 2;
  9.  
  10.     $empty = 0;
  11.    
  12.     foreach ($ts3->channelList(['pid' => $mainChannel]) as $channel) {
  13.         if ($channel->total_clients === 0) {
  14.             $empty++;
  15.             $empty_channels[$channel->channel_order] = $channel->cid;
  16.         }
  17.         $channels[] = $channel;
  18.     }
  19.    
  20.  
  21.     if ($empty > $reserve_channels) {
  22.         $i = 0;
  23.         foreach ($empty_channels as $order => $cid) {
  24.             if ($i > 1) {
  25.                 $ts3->channelDelete($cid, true);
  26.             } else {
  27.                 $i++;
  28.             }
  29.         }
  30.         $ts3->channelListReset();
  31.         $i = 1;
  32.         foreach ($ts3->channelList(['pid' => $mainChannel]) as $channel) {
  33.             try {
  34.                 $channel->modify([
  35.                     'channel_name' => 'Talk #'.$i
  36.                 ]);
  37.             } catch (Exception $e) {
  38.                 $i++;
  39.                 echo $e->getMessage().' - '.$i.'<br/>';
  40.             }
  41.         }
  42.     } else if ($empty < $reserve_channels) {
  43.         $i = 1;
  44.         while (true) {
  45.             try {
  46.                 if ($i > 10) break;
  47.                 $cid = $ts3->channelCreate([
  48.                     'channel_name' => 'Talk #'.$i,
  49.                     'cpid' => $mainChannel
  50.                 ]);
  51.                 $empty++;
  52.                 if ($empty >= $reserve_channels) break;
  53.             } catch (Exception $e) {
  54.                 $i++;
  55.                 echo $e->getMessage().' - '.$i.'<br/>';
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement