Auto Move AFK

codex

New Member
Jan 7, 2017
10
4
18
PHP:
<?php

require_once('libraries/TeamSpeak3/TeamSpeak3.php');

/*
* Config Server
*/
$cfg = array('address' => '127.0.0.1', //IP Address
             'serveradmin' => 'serveradmin', //Login Name ServerQuery
             'password' => 'qwerty', //Login Password Server Query
             'queryport' => '10011', //Login Port Server Query
             'port' => '9987', //Server Port
             'nickname' => 'AFK-BOT', //Nickname Query
             'channel_afk' => '2', // CID to move
             'idle_time' => '60*1'); //Idle time in seconds
try {
       
    /*
     * Connection TeamSpeak
    */
       
    $ts3_VirtualServer = TeamSpeak3::factory("serverquery://{$cfg['serveradmin']}:{$cfg['password']}@{$cfg['address']}:{$cfg['queryport']}/?server_port={$cfg['port']}&nickname={$cfg['nickname']}");
   
    /*
     * AFK Move
    */
   
    while(true) {  
        foreach ($ts3_VirtualServer->clientList() as $clientList) {
            if ($clientList['client_type'] == 0) {
                if ($clientList['client_idle_time']/1000 >= $cfg['idle_time']) {
                    foreach ($ts3_VirtualServer->channelList() as $channelList) {
                        if ($clientList['cid'] != $cfg['channel_afk']) {
                            if ($channelList['cid'] == $cfg['channel_afk']) {
                                $ts3_VirtualServer->clientMove($clientList['clid'], $cfg['channel_afk'], NULL );
                                $clientList->message("You have been automatically moved a [B]" . $channelList['channel_name'] . "[/B] for inactivity.");
                            }
                        }
                    }
                }
            }
        } sleep(30);
    }  
} catch(TeamSpeak3_Exception $e) {
    echo "Error: " . $e->getCode() . " " . $e->getMessage();
}
?>
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
Why wouldn't you check multiple stuff in one if statement?
PHP:
if ($clientList['client_type'] == 0 && $clientList['client_idle_time']/1000 >= $cfg['idle_time'])
instead of
PHP:
if ($clientList['client_type'] == 0) {
   if ($clientList['client_idle_time']/1000 >= $cfg['idle_time']) {
 
Top