View Single Post
Author Message
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 04-05-2006 , 09:05   PHP help please!
Reply With Quote #1

Hey all...need some PHP help...keep getting this error on http://owned.dajoob.com/forums/ :

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /usr/local/djcsites/dajoob.com/owned/forums/server_net.php on line 306


FULL SOURCE CODE TO THIS


My phpbb forums that im having the problem on.


It is producing the error on this line:

Code:
$result = fread($this->socket, $status["unread_bytes"]);
I think it is because it isnt storing the socket correctly or something.

Code:
<?php ############################################################## ## Mod Title: Counter-Strike Server Info ## Mod Version: 1.0.0 ## Author: Jay < <a href="mailto:[email protected]">[email protected]</a> > Jay - http:##<a href="http://www.dvdfuture.com" target="_blank" rel="nofollow noopener">www.dvdfuture.com</a> ## Description: ##   This mod will query your CS server and grab the info ##   about it and then put it onto your phpBB2 board! ## ##   Thanks to <a href="http://www.phprcon.net/" target="_blank" rel="nofollow noopener">http://www.phprcon.net/</a> PHPRcon for the use ##   of their code!! Make sure to go and CHECK IT OUT! ## ## Installation Level: (easy) ## Installation Time: 5-10 Minutes ## Files To Edit: ##   index.php, ## index_body.tpl, ## server_info.php ## ## Included Files: ##   server_info.php ##   server_net.php ############################################################## ## This MOD is released under the GPL License. ## Intellectual Property is retained by the MOD Author(s) listed above ############################################################## ## For Security Purposes, Please Check: http:##<a href="http://www.phpbb.com/mods/downloads/" target="_blank" rel="nofollow noopener">www.phpbb.com/mods/downloads/</a> for the ## latest version of this MOD. Downloading this MOD from other sites could cause malicious code ## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered ## in our MOD-Database, located at: http:##<a href="http://www.phpbb.com/mods/downloads/" target="_blank" rel="nofollow noopener">www.phpbb.com/mods/downloads/</a> ############################################################## ############################################################## ## Author Note: ## Make sure and edit the next three variables: $server_ip ## $server_port, and $server_password or this MOD will NOT ## work correctly! ############################################################## ############################################################## ## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD ############################################################## class rcon {    var $socket;    var $server_ip;    var $server_port;    var $server_password;    var $challenge_number = 0;    ##Constructor    function rcon()    {    }    ##Open socket to gameserver    function connect($server_ip, $server_port, $server_password = "")    {       ##store server data       $this->server_ip = gethostbyname($server_ip);       $this->server_port = $server_port;       $this->server_password = $server_password;       ##open connection to gameserver       $fp = fsockopen("udp://" . $this->server_ip, $this->server_port);       if(!$fp)        return false;       ##store socket       $this->socket = $fp;       ##return success       return true;    }    ##Close socket to gameserver    function disconnect()    {       ##close socket       fclose($this->socket);    } ##function disconnect()    ##Get detailed player info via rcon    function serverinfo()    {       ##get server information       $status = $this->rcon_command("status");       ##if there is bad rcon password       if(trim($status) == "Bad rcon_password.")       {          return $status;       }        ##format global server info        $line = explode("\n", $status);        $map = substr($line[3], strpos($line[3], ":") + 1);        $players = trim(substr($line[4], strpos($line[4], ":") + 1));        $active = explode(" ", $players);        $result["ip"] = trim(substr($line[2], strpos($line[2], ":") + 1));        $result["name"] = trim(substr($line[0], strpos($line[0], ":") + 1));        $result["map"] = trim(substr($map, 0, strpos($map, "at:")));        $result["mod"] = "Counterstrike";        $result["game"] = "Halflife";        $result["activeplayers"] = $active[0];        $result["maxplayers"] = substr($active[2], 1);        ##format player info        for($i = 1; $i <= $result["activeplayers"]; $i++)        {           ##get possible player line           $tmp = $line[$i + 6];           ##break if no more players are left           if(substr_count($tmp, "#") <= 0)           {              break;           }           ##name           $begin = strpos($tmp, "\"") + 1;           $end = strrpos($tmp, "\"");           $result[$i]["name"] = substr($tmp, $begin, $end - $begin);           $tmp = trim(substr($tmp, $end + 1));           ##Frag           $end = strpos($tmp, " ");           $result[$i]["frag"] = substr($tmp, 0, $end);           $tmp = trim(substr($tmp, $end));           ##Time           $end = strpos($tmp, " ");           $result[$i]["time"] = substr($tmp, 0, $end);           $tmp = trim(substr($tmp, $end));          ##Ping          $end = strpos($tmp, " ");          $result[$i]["ping"] = substr($tmp, 0, $end);          $tmp = trim(substr($tmp, $end));        }        ##return formatted result        return $result;    }    ##Get all maps in all directories    function servermaps()    {       ##get server information       $maps = $this->rcon_command("maps *");       ##if there is bad rcon password       if(trim($maps) == "Bad rcon_password.")        return $maps;       $line = explode("\n", $maps);       $count = sizeof($line) - 4;       ##format maps       for($i = 0; $i <= $count; $i++)       {          $text = $line[$i];          ##at directory output sorted map list          if(strstr($text, "Dir:"))          {             ##reset counter             $mapcount = 0;             ##parse directory name             $directory = strstr($text, " ");          } ##if(strstr($text, "Dir:"))          else if(strstr($text, "(fs)"))          {             ##parse mappath             $mappath = strstr($text, " ");             ##parse mapname             ##if no "/" is included in the "maps * " result             if(!($tmpmap = strrchr($mappath, "/")))              $tmpmap = $mappath;             ##parse mapname without suffix (.bsp)             $result[$i] = substr($tmpmap, 1, strpos($tmpmap, ".") - 1);          } ##else if(strstr($text, "(fs)"))       } ##for($i = 1; $i <= $count; $i++)       ##return formatted result       return $result;    } ##function servermaps()    ##Get server rules via info protocoll    function serverrules()    {       ##build info command       $buffer = "\xff\xff\xff\xffrules\x00";       $buffer = $this->communicate($buffer);       ##seperate rules       $buffer = substr($buffer, 7);       $buffer = explode("\x00", $buffer);       $buffer_count = sizeof($buffer) / 2;       ##build rules array       for($i = 1; $i < $buffer_count; $i++)       {          ##rule name          $result[$i]["name"] = $buffer[2 * $i];          ##rule value          $result[$i]["value"] = $buffer[2 * $i + 1];       }       ##return formatted result       return $result;    } ##function serverrules()    ##Execute rcon command on open socket $fp    function rcon_command($command, $pagenumber = 0)    {        ##get challenge number        if($this->challenge_number == "")        {            $challenge = "\xff\xff\xff\xffchallenge rcon\n";            $buffer = $this->communicate($challenge);            $buffer = explode(" ", $buffer);            $this->challenge_number = trim($buffer[2]);        }        ##build command        $buffer = "\xff\xff\xff\xffrcon $this->challenge_number \"$this->server_password\" $command\n";        ##get specified page        while($pagenumber-- >= 0)        {            ##send rcon command            $result = $this->communicate($buffer);            ##clear buffer for further pages            $buffer = "";            ##get more then one package            if(substr($result, 0, 4) == "\xfe\xff\xff\xff")            {               $result2 = $this->communicate("");               if(strlen($result2) < strlen($result2))               {                   $result = substr($result2, 9) . substr($result, 14);               }               else               {                   $result = substr($result, 14) . substr($result2, 9);               }            }            ##get only one package            else if(substr($result, 0, 4) == "\xff\xff\xff\xff")            {                $result = substr($result, 5);            }            ##whatever other case            else            {                echo(" \n");            }        } ##while($pagenumber >= 0)        ##return unformatted result        return trim($result);    } ##function rcon_command ($command)    ##Communication between PHPrcon and the Gameserver    function communicate($buffer)    {        ##write command on socket        if($buffer != "")        {            fputs($this->socket, $buffer, strlen($buffer));        }        ##get results from server        $result = fread ($this->socket, 1);        $status = socket_get_status($this->socket);        $result = fread($this->socket, $status["unread_bytes"]);        ##return unformatted result        return $result;    } ##function comunicate($buffer) } ?>
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana