Last active
September 27, 2021 20:02
-
-
Save Captnwalker1/76388fee574695d8c088 to your computer and use it in GitHub Desktop.
TS3 AFK Mover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
*TS3 AFK Mover (CLI+DB) by The-Killer | |
* 2014-06-12 initial release | |
* 2018-05-13 add channel statistics collecting | |
*/ | |
//Include php ts3 library http://addons.teamspeak.com/directory/addon/integration/TeamSpeak-3-PHP-Framework.html | |
require_once('lib/libraries/TeamSpeak3/TeamSpeak3.php'); | |
//Mysqli connection just stored in another file | |
require_once('mysql.inc.php'); | |
date_default_timezone_set('America/New_York'); | |
//Define vars | |
$afkTime = 60*60; //60 minutes | |
$afkChannelID = 250; //AFK channel | |
//Array of Client DBIDs to special channel IDs i.e. leaders and their channels | |
$specialCases = array(); | |
if($mysqli) { | |
$result = $mysqli->query('SELECT cldbid,chanid FROM ts3afk WHERE 1'); | |
if(!$result) die($mysqli->error); | |
while ($row = $result->fetch_assoc()) { | |
$specialCases[$row['cldbid']] = $row['chanid']; | |
} | |
//$mysqli->close(); | |
} | |
//die(print_r($specialCases,true)); | |
$afkMsg = "[color=red][b]NOTICE:[/size][/b][/color] You were moved for being idle ".($afkTime/60)." minutes"; | |
$afkWarnMsg = "[color=red][b]WARNING:[/size][/b][/color] You have been idle for ".(($afkTime/2)/60)." minutes. At ".($afkTime/60)." minutes you will be moved to the AFK Channel! To prevent this simply press your talk button."; | |
error_reporting(E_ALL); | |
echo date('c')."Start run\n"; | |
// connect to local server, authenticate and quickly spawn an object for the virtual server on port 9987 | |
$ts3_VirtualServer = TeamSpeak3::factory("serverquery://afkmover:[email protected]:10011/?server_port=9987&nickname=AFKMover"); | |
if(!$ts3_VirtualServer) | |
{ | |
die("connect failed"); | |
} | |
// query clientlist from virtual server | |
$arr_ClientList = $ts3_VirtualServer->clientList(); | |
foreach($arr_ClientList as $k => $v) | |
{ | |
try { | |
$info = $arr_ClientList[$k]->getInfo(); | |
//if($k == 5) print_r($info); | |
//echo $k." => ".$v." ".($info['client_idle_time']/1000)."\n"; | |
$cldbid = $info['client_database_id']; | |
$clAFK = $info['client_idle_time']/1000; | |
//print_r($v); | |
//print_r($info); | |
//echo "$cldbid".$info['client_nickname']." afk for $clAFK\n"; | |
//if($cldbid == 2) { | |
if($clAFK >= $afkTime){ | |
if(array_key_exists($cldbid,$specialCases)) | |
{ | |
$arr_ClientList[$k]->move($specialCases[$cldbid]); | |
} else { | |
$arr_ClientList[$k]->move($afkChannelID); | |
} | |
$arr_ClientList[$k]->message($afkMsg); | |
} else if ($clAFK >= (($afkTime/2)- 1) && $clAFK <= ($afkTime/2)+10 ) { | |
$arr_ClientList[$k]->message($afkWarnMsg); | |
} | |
} catch (Exception $e) { | |
//echo print_r($info); | |
echo $info['client_nickname']."\n"; | |
echo 'Caught exception: ', $e->getMessage(), "\n"; | |
} | |
} | |
$arr_ChannelList = $ts3_VirtualServer->channelList(); | |
$insert = $mysqli->prepare("INSERT INTO `ts3chanstats` (`cid`, `pid`, `chanpath`, `clientcount`) VALUES ( ?, ?, ?, ?)"); | |
foreach($arr_ChannelList as $k => $v) | |
{ | |
try { | |
$info = $v->getInfo(); | |
if($info["total_clients"] > 0) { | |
$name = $v->getPathway(); | |
$name = str_replace("[cspacer]-=www.RightToRule.com=-",'',$name); | |
$name = str_replace(array("-=","=-"),'',$name); | |
$name = preg_replace('/\[cspacer\d]/','',$name); | |
$ccount = $info["total_clients"]; | |
$cid = $info["cid"]; | |
$pid = $info["pid"]; | |
//echo $name." ".$ccount."\n"; | |
//print_r($info); | |
$insert->bind_param("iisi",$cid,$pid,$name,$ccount); | |
$insert->execute(); | |
} | |
//return; | |
} catch (Exception $e) { | |
echo $e->getMessage(); | |
} | |
} | |
$insert->close(); | |
$mysqli->close(); | |
echo date('c')."End run\n"; | |
?> |
very good
thank
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good