Her er den hele! det jeg har lavet er inde i en
// min ting
//mine ting slut
class QPlug {
var $addr;
var $port;
var $url;
var $buffer;
var $fp;
var $errno;
var $errstr;
var $player_info;
var $configs;
var $status_array;
var $vars;
var $width;
var $height;
var $BGCOLOR;
var $FIELD_COLOR;
var $ALERT_COLOR;
var $font_size;
var $font_color;
var $font_type;
// mine var
// mine var slut
function QPlug($addr, $port, $url) {
$this->addr = $addr;
$this->port = $port;
$this->url = $url;
$this->configs = array();
$this->player_info = array();
$this->width = 500;
$this->height = 200;
$this->BGCOLOR = "#000000";
$this->FIELD_COLOR = "#FFFFFF";
$this->ALERT_COLOR = "red";
$this->font_size = 2;
$this->font_color = "#FFFFFF";
$this->font_type = "tahoma,verdana,helvetica,arial,sans-serif";
}
function Connect() {
$this->fp = fsockopen("udp://"
.$this->addr, $this->port,
$this->errno, $this->errstr);
if ($this->fp) {
fwrite($this->fp,$this->buffer);
/* Wait 2 seconds Max */
socket_set_timeout($this->fp,2);
$crap = fgets($this->fp,20);
return true;
}
return false;
}
function Disconnect() {
fclose($this->fp);
}
function SetHeight($height) {
$this->height = $height;
}
function SetWidth($width) {
$this->width = $width;
}
function SetColors($bgcolor, $field_color, $alert_color) {
if ($bgcolor)
$this->BGCOLOR = $bgcolor;
if ($field_color)
$this->FIELD_COLOR = $field_color;
if ($alert_color)
$this->ALERT_COLOR = $alert_color;
}
function SetFont($size, $color, $type) {
if ($size)
$this->font_size = $size;
if ($color)
$this->font_color = $color;
if ($type)
$this->font_type = $type;
}
function GetFont() {
?><font face="<?echo $this->font_type;?>" size="<?echo $this->font_size;?>" color="<?echo $this->font_color;?>"><?
}
function SetVars($vars) {
$this->vars = $vars;
}
// mine ting
function DrawBotTable() {
//Tager server infoen ud
// udtagelse slut
echo "mark: ";
echo $this->hostname."=> ";
echo " Map: ".$this->mapname;
echo " Players: ".$this->numplayers."/12";
}
function players() {
$i="0";
while(list($key,$val) = each($this->player_info)) {
$i=$i+1;
}
$this->numplayer=$i;
global $this->numplayers;
}
function serverinfo() {
$bit=0;
while(list(,$item) = each($this->configs)) {
if (!$bit) {
$myitem = $item;
}else {
IF($myitem == "gamename"){ $gamename = $item; }
IF($myitem == "capturelimit"){ $capturelimit = $item; }
IF($myitem == "maxclients"){ $maxclients = $item; }
IF($myitem == "timelimit"){ $timelimit = $item; }
IF($myitem == "dmflags"){ $dmflags = $item; }
IF($myitem == "version"){ $version = $item; }
}
$bit=abs($bit-1);
}
}
// mine ting slute
function DrawTable() {
?><table border="0" cellpadding="0" cellspacing="0" width="<?echo $this->width;?>" height="<?echo $this->height;?>">
<tr bgcolor="<?echo $this->BGCOLOR;?>" valign="center">
<td nowrap align="left">
<?
$this->SetFont("3",$this->ALERT_COLOR,"");
echo $this->GetFont();
echo $this->addr.":".$this->port;
?> <?
$this->SetFont("2",$this->FIELD_COLOR,"");
echo $this->GetFont();
if ($this->mapname) echo "(".$this->mapname.")";
?></font></td>
<td align="right" nowrap>
<?
$this->SetFont("2",$this->FIELD_COLOR,"");
echo $this->GetFont();
if ($this->hostname) echo "<".$this->hostname.">";
else echo "<No response>";
?> </font></td>
<tr bgcolor="<?echo $this->BGCOLOR;?>" valign="top">
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="<?echo $this->BGCOLOR;?>" valign="top">
<td width="1" bgcolor="<?echo $this->BGCOLOR;?>"> </td>
<td nowrap width="55%">
<table border="0" cellpadding="1" cellspacing="2" width="100%">
<tr>
<td><?
$this->SetFont("2",$this->FIELD_COLOR,"");
echo $this->GetFont();
?><b>Player</b></font></td>
<td><?
$this->SetFont("2",$this->FIELD_COLOR,"");
echo $this->GetFont();
?><b>Frags</b></font></td>
<td><?
$this->SetFont("2",$this->FIELD_COLOR,"");
echo $this->GetFont();
?><b>Ping</b></font></td>
<?
while(list($key,$val) = each($this->player_info)) {
?><tr bgcolor="<?echo $this->FIELD_COLOR;?>">
<?if ($val["score"] && $val["ping"]) {?>
<td>
<?
$this->SetFont("2",$this->BGCOLOR,"");
echo $this->GetFont();
echo $val["name"]." ";
?></font></td>
<?}?>
<td>
<?
$this->SetFont("2",$this->BGCOLOR,"");
echo $this->GetFont();
echo $val["score"];
?></font></td>
<td>
<?
$this->SetFont("2",$this->BGCOLOR,"");
echo $this->GetFont();
echo $val["ping"];
?></font></td><?
}
?>
</tr>
</table></td>
<td width="44%">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<table border="0" cellpadding="1" cellspacing="2" width"100%">
<tr>
<td><?
$this->SetFont("2",$this->FIELD_COLOR,"");
echo $this->GetFont();
?><b>Server config</b></font></td>
<tr bgcolor="<?echo $this->FIELD_COLOR;?>">
<td>
<table border="0" cellpadding="1" cellspacing="0" width="100%"><?
$bit=0;
while(list(,$item) = each($this->configs)) {
if (!$bit) {
?><tr bgcolor="<?echo $this->BGCOLOR;?>">
<td nowrap><?
$this->SetFont("2",$this->FIELD_COLOR,"");
echo $this->GetFont();
echo "$item => ";
} else {
echo substr($item,0,30);
?></font></td><?
}
$bit=abs($bit-1);
}
?>
</tr>
</table></td>
</tr>
</table></td>
<td width="1" bgcolor="<?echo $this->BGCOLOR;?>"> </td>
</tr>
</table></td>
</tr>
</table></td>
<tr bgcolor="<?echo $this->BGCOLOR;?>">
<td colspan="2"><br></td>
</tr>
</table><?
}
}
class Q2Plug extends QPlug {
var $mapname;
var $hostname;
function Q2Plug($addr, $port, $url) {
$this->QPlug($addr, $port, $url);
$this->buffer ="xxxxstatus";
$this->buffer[0] = pack("v",0xFF);
$this->buffer[1] = pack("v",0xFF);
$this->buffer[2] = pack("v",0xFF);
$this->buffer[3] = pack("v",0xFF);
$this->scores = array();
$this->pings = array();
}
function GetAddr() {
return $this->addr;
}
function GetData() {
/* Grab the set options */
$string = fgets($this->fp, 2500);
/*
Set blocking mode to FALSE to
prevent waiting on empty socket
*/
socket_set_blocking($this->fp,0);
/*
Just loop 100 times. Increase for
servers with more players. Possible? (q2)
*/
for ($i=0;$i<100;$i++)
$string.= fgets($this->fp,5000);
$this->status_array = explode("\\\\",$string);
}
function ParseData() {
$game = 0;
$map = 0;
$host = 0;
$players = "";
while(list(,$val) = each($this->status_array)) {
if ($i > 0) {
if ($map == 1) {
$this->mapname = $val;
$map=0;
} else if ($host == 1) {
$this->hostname = $val;
$host=0;
}
if ($game == 1) {
$players = $val;
$game=0;
$val = explode(" ",$val);
$this->configs[] = $val[0];
} else $this->configs[] = $val;
if ($val == "game")
$game=1;
else if ($val == "mapname")
$map=1;
else if ($val == "hostname")
$host=1;
}
$i++;
}
$players = explode("\\"", $players);
$i=0;
$which = true;
foreach($players as $val) {
if ($i==0)
$val = eregi_replace("([a-zA-Z+])","",$val);
if ($which) {
$info = explode(" ",$val);
$this->player_info[$i] = array("score" => $info[0], "ping" => $info[1], "name" => "");
$this->scores[] = $info[0];
$this->pings[] = $info[1];
$which = false;
} else {
$this->player_info[$i-1]["name"] = $val;
$which = true;
}
$i++;
}
arsort($this->player_info);
reset($this->player_info);
if ($this->vars) {
$bit=0;
$newconfig = array();
while(list(,$item) = each($this->configs)) {
if ($bit) {
$newconfig[] = $item;
$bit=0;
} else {
foreach ($this->vars as $var) {
if (!strcmp($item,$var)) {
$bit=1;
$newconfig[] = $item;
}
}
}
}
$this->configs = $newconfig;
}
}
function PrintPlayers() {
foreach ($this->player_info as $player_info) {
echo $player_info["name"]."<BR>";
}
}
}
----------------------
DoomStone
DoomStone@DoomStone.dk