Public feed #889681

tss2info

public text v1 · immutable
Raw Edit
·published 2008-02-03 02:32 UTC
rendered paste body
<?php
class tss2info_ {
var $serverAddress   = "127.0.0.1"; // Ip du serveur
var $serverQueryPort = "51234"; // TeamSpeak QueryPort.. Schau in die server.ini von TeamSpeak (Standard 51234)
var $serverUDPPort   = "8767"; // UDP Port für Teamspeak der auch hinter der IP Adresse genutzt wird (Standard 8767)
var $serverPasswort  = "Ragnarok"; // Serverpasswort das bei Serversettings eingestellt wird (wenn kein Passwort erteilt, dann leer lassen)
var $socket;

// opens a connection to the teamspeak server
function getSocket($host, $port, $errno, $errstr, $timeout) {
  unset($socket);
  $attempts = 1;
  while($attempts <= 1 and !$socket) {
    $attempts++;
    $socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
    $this->errno = $errno;
    $this->errstr = $errstr;
    if($socket and fread($socket, 4) == "[TS]") {
      fgets($socket, 128);
      return $socket;
      }
  }// end while
  return false;
}// end function getSocket(...)

// sends a query to the teamspeak server
function sendQuery($socket, $query) {
  fputs($socket, $query."\n");
}// end function sendQuery(...)

// answer OK?
function getOK($socket) {
  $result = fread($socket, 2);
  fgets($socket, 128);
  return($result == "OK");
}// end function getOK(...)

// closes the connection to the teamspeak server
function closeSocket($socket) {
  fputs($socket, "quit");
  fclose($socket);
}// end function closeSocket(...)

function getInfo() {
// ---=== main program ===---

// establish connection to teamspeak server
$this->socket = $this->getSocket($this->serverAddress, $this->serverQueryPort, $errno, $errstr, 0.3);
if($this->socket == false) {
  if($this->TS_debug_modus == 1) {
    echo "Es wird kein Server gefunden.<br><b>Scriptabbruch:</b> Der folgende Query Port ist falsch oder gesperrt: ".$this->serverQueryPort.""; // No Server
    DIE;
  } else {
    return;
  }
} else {
  $this->serverStatus = "online";

  // select the one and only running server on port 8767
  $this->sendQuery($this->socket, "sel ".$this->serverUDPPort);

  // retrieve answer "OK"
  if(!$this->getOK($this->socket)) {
    if($this->TS_debug_modus == 1) {
      echo "Der Server antwortete nach der letzten Anfrage nicht mit OK.<br><b>Scriptabbruch:</b> Der folgende UPD Port ist falsch oder gesperrt: ".$this->serverUDPPort.""; // Server didn't answer \"OK\" after last command. Aborting.
      DIE;
    } else {
      return;
    }
  }// end if

$this->sendQuery($this->socket,"gi");
$this->serverinfo = array();
list($total_server_uptime, $total_server_version, $total_server_platform, $total_servers, $total_users_online, $total_users_maximal, $total_channels, $total_bytesreceived, $total_bytessend, $total_packetssend, $total_packetsreceived, $total_bwoutlastmin, $total_bwoutlastsec, $total_bwinlastmin, $total_bwinlastsec, $isp_ispname, $isp_linkurl, $isp_adminemail, $isp_countrynumber, $querstatus) = $serverinfovar;
$serverinfo = array(
"total_server_uptime" => $total_server_uptime,
"total_server_version" => $total_server_version,
"total_server_platform" => $total_server_platform,
"total_servers" => $total_servers,
"total_users_online" => $total_users_online,
"total_users_maximal" => $total_users_maximal,
"total_channels" => $total_channels,
"total_bytesreceived" => $total_bytesreceived,
"total_bytessend" => $total_bytessend,
"total_packetssend" => $total_packetssend,
"total_packetsreceived" => $total_packetsreceived,
"total_bwoutlastmin" => $total_bwoutlastmin,
"total_bwoutlastsec" => $total_bwoutlastsec,
"total_bwinlastmin" => $total_bwinlastmin,
"total_bwinlastsec" => $total_bwinlastsec,
"isp_ispname" => $isp_ispname,
"isp_linkurl" => $isp_linkurl,
"isp_adminemail" => $isp_adminemail,
"isp_countrynumber" => $isp_countrynumber,
"querstatus" => $querstatus);

  // close connection to teamspeak server
  $this->closeSocket($this->socket);

  }// end getInfo()
}// class tss2info
}
$tss2info_ = new tss2info_;
?>