...

View Full Version : Online and Offline Icon



crazykilla
07-28-2007, 06:08 PM
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...
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.

_Aerospace_Eng_
07-28-2007, 06:13 PM
What you have might be a little overkill.
http://www.codingforums.com/showthread.php?t=116404

crazykilla
07-28-2007, 06:30 PM
Thanks, that works great.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum