Jump to content
GIGN Forum

Cs Servera Monitors...


Upaaa
 Share

Recommended Posts

Lieta tāda ka pc atradu pavecu cs monitoru nu cik nu vecs kādi 3/4 mēneši jau ir !

Bet laikam viņš bija nomests malā jo nestrādāja!

Tad nu tā kāds var palīdzēt apslīpēt šo skriptu!

<div style="color:#000000">
<?php
error_reporting(0);

//servera adrese
  $adrese = "nu te ķipa mans servera ip.. ar visu portu!";
//maps address
  $maps = "links uz bildi .."; 


function fragsort ($a, $b) {   
    if ($a["frags"] == $b["frags"]) return 0;
    if ($a["frags"] > $b["frags"]) {
        return -1;
    } else {
        return 1;
    }
}    

Class CounterStrike {
    var $m_playerinfo  = "";        // Info about players
    var $m_servervars  = "";        // Info about the server current map, players etc
    var $m_serverrules = "";        // Server rules
    var $m_challenge   = "";        // Server challenge number

    //
    // Get exact time, used for timeout counting
    //
    function timenow() {
        return doubleval(ereg_replace('^0\.([0-9]*) ([0-9]*)$','\\2.\\1',microtime()));
    }

    //
    // Read raw data from server
    //
    function getServerData($command,$serveraddress,$portnumber,$waittime) {
        $serverdata    = "";
        $serverdatalen = 0;

        if ($waittime< 500) $waittime= 500;
        if ($waittime>2000) $waittime=2000;
        $waittime=doubleval($waittime/1000.0);

        if (!$cssocket = @fsockopen("udp:".$serveraddress,$portnumber,$errnr)) {
            $this->errmsg="No connection";
            return "";
        }

        socket_set_blocking($cssocket,true);
        socket_set_timeout($cssocket,0,500000);
        fwrite($cssocket,$command,strlen($command));
        // Mark
        $starttime=$this->timenow();
        do {
            $serverdata.=fgetc($cssocket);
            $serverdatalen++;
            $socketstatus=socket_get_status($cssocket);
            if ($this->timenow()>($starttime+$waittime)) {
                $this->errmsg = "Connection timed out";
                fclose($cssocket);
                return "";
            }
        } while ($socketstatus["unread_bytes"] );
        fclose($cssocket);
        return $serverdata;        
    }

    function getnextstring(&$data) {
        $temp="";
        $counter=0;
        while (ord($data[$counter++])!=0) $temp.=$data[$counter-1];
        $data=substr($data,strlen($temp)+1);
        return $temp;
    }

    function getnextbytevalue(&$data) {
        $temp=ord($data[0]);
      $data=substr($data,1);
      return $temp;
    }

    function getnextfragvalue(&$data) {
        $frags=ord($data[0])+(ord($data[1])<<8)+(ord($data[2])<<16)+(ord($data[3])<<24);
        if ($frags>=4294967294) $frags-=4294967296;
        $data=substr($data,4);
        return $frags;
    }

    function getnextplaytime(&$data) {
        $decnumber=ord($data[0])+(ord($data[1])<<8)+(ord($data[2])<<16)+(ord($data[3])<<24);
        $binnumber=base_convert($decnumber,10,2);
        while (strlen($binnumber) < 32) $binnumber="0".$binnumber;
        $exp=abs(base_convert(substr($binnumber,1,8),2,10))-127;
        if (substr($binnumber,0,1)=="1") $exp=0-$exp;
        $man=1;$manadd=0.5;
        for ($counter=9;$counter<32;$counter++) {
            if (substr($binnumber,$counter,1)=="1") $man+=$manadd;
            $manadd=$manadd/2;
        }
        $time=round(pow(2,$exp)*$man);
        $playtime="";
        if ($time>3600) {
            $playtime=sprintf("%2d:",$time/3600);
        } 
        $time%=3600;
        $playtime=$playtime.sprintf("%2d:",$time/60);    
        $time%=60;
        $playtime=$playtime.sprintf("%2d",$time);
        $data=substr($data,5);
        return $playtime;
    }


    // **********************************************************************
    // getServerRules
    // Read rules/setup from the gameserver into m_serverrules
    // Return true if successful
    // **********************************************************************
    function getServerRules($serveraddress,$portnumber,$waittime) {
        // Get a challenge number
        if (!$this->getChallenge($serveraddress,$portnumber,$waittime)) return false;

        // Send a request for "rules" to the server
        $cmd        = "\xFF\xFF\xFF\xFFV" . $this->m_challenge;
        $serverdata = $this->getServerData($cmd,$serveraddress,$portnumber,$waittime);

        // Check length of returned data, if < 5 something went wrong
        if (strlen($serverdata)<5) return false;            
        // Figure out how many rules there are
        $rules=(ord($serverdata[5]))+(ord($serverdata[6])*256);
        if ($rules != 0) {
            // Strip OOB data                
            $serverdata = substr($serverdata,7);
            for ($i=1;$i<=$rules;$i++) {
                $rulename  = $this->getnextstring($serverdata);
                $rulevalue = $this->getnextstring($serverdata);
                $this->m_serverrules[$rulename]=$rulevalue;
            }
            return true;
        } else {
            return false;
        }
    }    


    // **********************************************************************
    // getServerinfo
    // Read information about the gameserver into m_servervars
    // Serveraddress,servername,current map etc etc
    // Return true if successful
    // **********************************************************************
    function getServerInfo($serveraddress,$portnumber,$waittime) {
        // Send a request for "info" to the server
        $cmd        = "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
        $serverdata = $this->getServerData($cmd,$serveraddress,$portnumber,$waittime);

        // Check length of returned data, if < 5 something went wrong
        if (strlen($serverdata)<5) return false;      
        // Strip OOB data                
        $serverdata=substr($serverdata,6);
        $this->m_servervars["serveraddress"]  = $this->getnextstring($serverdata);
        $this->m_servervars["servername"]     = $this->getnextstring($serverdata);
        $this->m_servervars["mapname"]        = $this->getnextstring($serverdata);
        $this->m_servervars["game"]           = $this->getnextstring($serverdata);
        $this->m_servervars["gamename"]       = $this->getnextstring($serverdata);
        $this->m_servervars["currentplayers"] = $this->getnextbytevalue($serverdata);
        $this->m_servervars["maxplayers"]     = $this->getnextbytevalue($serverdata);    

        // Get a challenge number
        if (!$this->getChallenge($serveraddress,$portnumber,$waittime)) return false;

        // Send a request for "rules" to the server
        $cmd        = "\xFF\xFF\xFF\xFFU" . $this->m_challenge;
        $serverdata = $this->getServerData($cmd,$serveraddress,$portnumber,$waittime);

        // Check length of returned data, if < 5 something went wrong
        if (strlen($serverdata)<5) return false;

        // Check number of players to read data for
        $players = ord($serverdata[5]);

         // Strip OOB data and other stuff
        $serverdata = substr($serverdata,7);

        for ($i=1;$i<=$players;$i++) {
            $playername             = htmlspecialchars($this->getnextstring($serverdata));
            $frags                  = $this->getnextfragvalue($serverdata);
            $playtime               = $this->getnextplaytime($serverdata);
            $this->m_playerinfo[$i] = array("name"=>$playername,"frags"=>$frags,"time"=>$playtime);
        }
        // Sort players in fragorder
        if ($players>1) usort($this->m_playerinfo,"fragsort");
        return true;
    }    

    // **********************************************************************
    // getChallenge
    // Read a challenge number from the gameserver into m_challenge
    // Return true if successful
    // **********************************************************************
    function getChallenge($serveraddress,$portnumber,$waittime) {
        $cmd        = "\xFF\xFF\xFF\xFFW";
        $serverdata = $this->getServerData($cmd,$serveraddress,$portnumber,$waittime);

        // Check length of returned data, if < 5 something went wrong
        if (strlen($serverdata)<5) return false;
        $this->m_challenge = substr($serverdata,5);
        return true;
    }
}

function applaunch($game) {
  $game = str_replace("cstrike", "10", $game);
  $game = str_replace("dod", "30", $game);
  $game = str_replace("valve", "70", $game);
  $game = str_replace("czero", "80", $game); 
  $game = str_replace("bshift", "130", $game);
  $game = str_replace("dmc", "40", $game);
  $game = str_replace("gearbox", "50", $game);
  $game = str_replace("ricochet", "60", $game);
  $game = str_replace("tfc", "20", $game);
  $game = str_replace("czeror", "100", $game);
  $game = str_replace("redorchestra", "1200", $game);  

  return $game;
}

function applaunch2($game) {
  $game = str_replace("cstrike", "240", $game);

  return $game;
}

function joinip($ip, $port, $game, $type) {
  if($type == "HL1") {
    $game = applaunch($game); 
  }
  elseif($type == "HL2") {
    $game = applaunch2($game); 
  }
  return "<a href='steam: \"-applaunch ".$game."\"  +connect ".$ip.":".$port."'>".$ip.":".$port."</a>";
}

function getMapImage($map) {
  if (!file_exists("csslmore/".$map.".gif"))
  {
      $map = "cstrike/cstrike_nopicture";
  }

  return "<img border=\"1\" src=\"csslmore/".$map.".gif\">";
}
          list($serverip, $serverport) = explode(":", $adrese);
          $csinfo=new CounterStrike;
          $status=$csinfo->getServerInfo($serverip,$serverport,1000);
          if($csinfo->m_servervars["gamename"] == "р") {
      $servers["servername"] = htmlentities($csinfo->m_servervars["serveraddress"]);
      $servers["gamename"] = $csinfo->m_servervars["game"];
      $servers["game"] = $csinfo->m_servervars["mapname"];
      $servers["mapname"] = $csinfo->m_servervars["servername"];
      $servers["currentplayers"] = $csinfo->m_servervars["currentplayers"];
      $servers["maxplayers"] = $csinfo->m_servervars["maxplayers"];
      $servers["type"] = "HL2";
       }
    //HL1
      else {
      $servers["servername"] = htmlentities($csinfo->m_servervars["servername"]);
      $servers["gamename"] = $csinfo->m_servervars["gamename"];
      $servers["game"] = $csinfo->m_servervars["game"];
      $servers["mapname"] = $csinfo->m_servervars["mapname"];
      $servers["currentplayers"] = $csinfo->m_servervars["currentplayers"];
      $servers["maxplayers"] = $csinfo->m_servervars["maxplayers"];
      $servers["type"] = "HL1";
      }
    $tag = $servers["currentplayers"];
    $max = $servers["maxplayers"];
    $nosaukums = $servers["servername"];
    $mape = $servers["mapname"];
    $statuss = $max-$tag;
    if ($statuss == "1") {
    $statuss = "Viens brīvs slots";
    } else if ($statuss == "0") {
    $statuss = "Nav brīvu slotu";
    } else {
    $statuss = "$statuss brīvi sloti";
    }
    $players = "<font color='green'>$tag</font>/<font color='red'>$max</font>";

if (empty($mape)) {
echo "<style>
table {
    font-family:Tahoma, Geneva, sans-serif;
    font-size: 11px;
}
.img_border {
    width: 140px;
    height: 74px;
    font-size: 9px;
    padding: 0px;
    border: 2px solid #000000;
    background-color: #ffffff;
}
</style>

<table border='0'>
<tr>
<td>Statuss:</td>
<td>Serveris offline</td>
</tr>
<tr>
<td>Adrese:</td>
<td>".$adrese."</td>
</tr>
<tr>
<td>Spēlētāji:</td>
<td><font color='green'>0</font>/<font color='red'>0</font></td>
</tr>
<tr>
<td>Karte:</td>
<td>Offline</td>
</tr>
<tr>
<td colspan='2' align='left'>
<span align='left' style='padding: 3px;background-color: #000000; none repeat scroll 0% 0%;  -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(255, 255, 255);    -moz-border-radius-topleft: 3px;     -moz-border-radius-topright: 3px;'>Offline</span>
<br />
<img class='img_border' src='http://revenge.lv/images/maps/no_image.jpg' alt='' />
</td>
</tr>
</table>";
}
else{
    echo "
<style>
table {
    font-family:Tahoma, Geneva, sans-serif;
    font-size: 11px;
}
.img_border {
    width: 140px;
    height: 74px;
    font-size: 9px;
    padding: 0px;
    border: 2px solid #000000;
    background-color: #ffffff;
}
</style>

<table border='0'>
<tr>
<td>Statuss:</td>
<td>".$statuss."</td>
</tr>
<tr>
<td>Adrese:</td>
<td>".$adrese."</td>
</tr>
<tr>
<td>Spēlētāji:</td>
<td>".$players."</td>
</tr>
<tr>
<td>Karte:</td>
<td>".$mape."</td>
</tr>
<tr>
<td colspan='2' align='left'>
<span align='left' style='padding: 3px;background-color: #000000; none repeat scroll 0% 0%;  -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(255, 255, 255);    -moz-border-radius-topleft: 3px;     -moz-border-radius-topright: 3px;'>".$mape."</span>
<br />
<img class='img_border' src='$maps".$mape.".jpg' alt='' />
</td>
</tr>
</table>";
}
?>
</div>

Nu nav tā ka monitors met kādu erorru bet viņš negrib pieslēgties serverim ! Kāds var atrast kļūdu un pielabot lūdzu!?

Paldies jau iepriekš!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...