Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Online and Offline Icon

    Ok, not sure if this is the right section for this. But, my company hosts free TeamSpeak servers, and I wanted to know if there is any kind of code that could be made to show that if our servers are online or offline. We've made images that say online and offline. But, we havn't been able to come up with a code for it to test the server to see if it's online and for it to choose the appropriate image. I was thinking maybe using a code from a TeamSpeak server block but, I'm unsure of what to use out of it. Here's the code from the block...
    Code:
    var $socket;
    var $serverStatus = "offline";
    var $playerList = array();
    var $channelList = array();
    function getSocket($host, $port, $errno, $errstr, $timeout) {
      unset($socket);
     $socket=0;// added
      $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;
    	}
      }
      return false;
    }
    function sendQuery($socket, $query) {
      fputs($socket, $query."\n");
    }
    function getOK($socket) {
      $result = fread($socket, 2);
      fgets($socket, 128);
      return($result == "OK");
    }
    function closeSocket($socket) {
      fputs($socket, "quit");
      fclose($socket);
    }
    function getNext($evalString) {
      $pos = strpos($evalString, "\t");
      if(is_integer($pos)) {
        return substr($evalString, 0, $pos);
      } else {
        return $evalString;
      }
    }
    function chopNext($evalString) {
      $pos = strpos($evalString, "\t");
      if(is_integer($pos)) {
        return substr($evalString, $pos + 1);
      } else {
        return "";
      }
    }
    function stripQuotes($evalString) {
      if(strpos($evalString, '"') == 0) $evalString = substr($evalString, 1, strlen($evalString) - 1);
      if(strrpos($evalString, '"') == strlen($evalString) - 1) $evalString = substr($evalString, 0, strlen($evalString) - 1);
      return $evalString;
    }
    function getVerboseCodec($codec) {
      if($codec == 0) {
        $codec = "CELP 5.1 Kbit";
      } elseif($codec == 1) {
        $codec = "CELP 6.3 Kbit";
      } elseif($codec == 2) {
        $codec = "GSM 14.8 Kbit";
      } elseif($codec == 3) {
        $codec = "GSM 16.4 Kbit";
      } elseif($codec == 4) {
        $codec = "CELP Windows 5.2 Kbit";
      } elseif($codec == 5) {
        $codec = "Speex 3.4 Kbit";
      } elseif($codec == 6) {
        $codec = "Speex 5.2 Kbit";
      } elseif($codec == 7) {
        $codec = "Speex 7.2 Kbit";
      } elseif($codec == 8) {
        $codec = "Speex 9.3 Kbit";
      } elseif($codec == 9) {
        $codec = "Speex 12.3 Kbit";
      } elseif($codec == 10) {
        $codec = "Speex 16.3 Kbit";
      } elseif($codec == 11) {
        $codec = "Speex 19.5 Kbit";
      } elseif($codec == 12) {
        $codec = "Speex 25.9 Kbit";
      } else {
        $codec = "unknown (".$codec.")";
      }
      return $codec;
    }
    function getInfo() {
    $errno=0; // added 
    $errstr=0; // added 
    $isdefault=0; // added 
    $this->socket = $this->getSocket($this->serverAddress, $this->serverQueryPort, $errno, $errstr, 0.3);
    if($this->socket == false) {
      return;
      echo ("No Server");
    } else {
      $this->serverStatus = "online";
      $this->sendQuery($this->socket, "sel ".$this->serverUDPPort);
      if(!$this->getOK($this->socket)) {
        echo "Server didn't answer \"OK\" after last command. Aborting.";
    Any help with this would be appreciated.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What you have might be a little overkill.
    http://www.codingforums.com/showthread.php?t=116404
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that works great.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •