Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ts3server {
- private $teamspeakhandle;
- function __construct($ip, $port, $name, $pass, $virtualServer) {
- $this->teamspeakhandle=fsockopen($ip,$port);
- stream_set_timeout($this->teamspeakhandle,0,100000);
- if ($this->teamspeakhandle) {
- $this->_login($name, $pass, $virtualServer);
- //echo $this->_tsread(256); //Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help " for information on a specific command. error id=0 msg=ok
- }else {
- echo "Socket connection failed!";
- }
- }
- private function _login($name, $pass, $virtualServer) {
- fputs($this->teamspeakhandle,"login ".$name." ".$pass."\n");
- $return = $this->_tsread(256);
- if(strpos($return, 'msg=ok') !== FALSE) {
- $this->_command('use', array($virtualServer));
- //echo "Login successful\n";
- }
- }
- private function _command($command, $params = array()) {
- $command .= " ";
- if($params) {
- foreach($params as $param) {
- $command .= $param." ";
- }
- }
- fputs($this->teamspeakhandle,$command."\n");
- return $this->_tsread(256);
- }
- public function clientList() {
- $return = $this->_command('clientlist -ip');
- $return = explode("|", $return);
- foreach($return as $key => $ret) {
- foreach(explode(" ", $ret) as $value) {
- $tmp = explode("=", $value);
- if (!isset($tmp[1])) $tmp[1] = NULL;
- $clients[$key][$tmp[0]] = str_replace("\s", " ",$tmp[1]);
- if(isset($clients[$key]["client_type"]) && $clients[$key]["client_type"] == 1) {
- unset($clients[$key]);
- }
- }
- }
- return $clients;
- }
- private function _tsread($size,$timeout=1){
- $start=microtime(true);
- do{
- usleep($size*100);
- $data=fread($this->teamspeakhandle,1);
- $info=stream_get_meta_data($this->teamspeakhandle);
- }
- while ((microtime(true)-$start)<$timeout and $info['timed_out']);
- do{
- usleep($size*10);
- if ($info['unread_bytes']>$size){
- $data.=fread($this->teamspeakhandle,$size);
- }
- else {
- $data.=fread($this->teamspeakhandle,$info['unread_bytes']);
- }
- $info=stream_get_meta_data($this->teamspeakhandle);
- }
- while ($info['unread_bytes']>0);
- return $data;
- }
- };
- $ts3 = new ts3server('127.0.0.1', 10011, "serveradmin","xxx","4");
- while(1)
- {
- sleep(1);
- foreach($ts3->clientList() as $client) {
- //echo "|".$client['connection_client_ip']."|\n";
- //include("mysql.php");
- //print_r($client);
- if (!isset($client['connection_client_ip'])) $client['connection_client_ip'] = NULL;
- $client['connection_client_ip'] = explode("error", $client['connection_client_ip']);
- foreach($client['connection_client_ip'] as $clientip) {
- if ($clientip != NULL)
- if ($clientip != "")
- {
- echo "</br>IP: ".$client['connection_client_ip'][0];
- echo "</br>ID: ".$client['clid'];
- echo "</br>DBID: ".$client['client_database_id'];
- echo "</br>NickName: ".$client['client_nickname'];
- echo "</br>Type: ".$client['client_type'];
- echo "</br>";
- /*
- xZ6mER4fGuAq8ufY
- nowybot
- */
- $servername = "localhost";
- $username = "newbot";
- $password = "xZ6mER4fGuAq8ufY";
- $dbname = "newbot";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO online_users (DBID, ID, IP, NickName, Type)
- VALUES ('John', 'Doe', 'john@example.com')";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- }
- /*
- Array
- (
- [clid] => 4
- [cid] => 236
- [client_database_id] => 7943
- [client_nickname] => bocik
- [client_type] => 0
- )
- */
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement