Solved

I get a Parse error in line 29, WHY ?

Posted on 2002-03-21
4
164 Views
Last Modified: 2006-11-17
I get a Parse error in line 29, WHY ?

servers.php3

<? require("counterstrikeClass.php3"); ?>
<HTML>
<HEAD>
<TITLE>Servers</TITLE>
</HEAD>
<BODY>
<TABLE border=1>
      <tr>
            <TD>Servername</TD>
            <TD>Serveraddress</TD>
            <TD>Players</TD>
            <TD>Map</TD>
      </tr>
<?
      $fp = fopen("list.lst", "r");
      $line = file("list.lst");
      $server = array();

      for($i=0;$i<count($line);$i++){
            $server[$i] = new CounterStrike;
            $serveradr =substr($line[$i],0,strpos($line[$i],":"));
            $serverport=substr($line[$i],strpos($line[$i],":")+1);

            $status=$server[$i]->getServerInfo($serveradr,$serverport,1000);
            if ($status) {
?>
      <tr>
            <TD><a href="players.php3?serveradr=<?php echo $serveradr; ?>&serverport=<?php echo $serverport; ?>"><?php echo $server[$i]->m_servervars["servername"]; ?></a></TD>
            <TD><?=$server[$i]->m_servervars["serveraddress"]; ?></TD>
            <TD><?=$server[$i]->m_servervars["currentplayers"]; ?> / <?=$server[$i]->m_servervars["maxplayers"];?></TD>
            <TD><?=$server[$i]->m_servervars["mapname"];?></TD>
      </tr>
<?
            }
      }
?>
</TABLE>
</BODY>
</HTML>

the rest of the files :

players.php3 :

<? require("counterstrikeClass.php3");?>
<HTML>
<HEAD>
<TITLE>Players on <?=$HTTP_GET_VARS["serveradr"];?></TITLE>
</HEAD>
<?
  $server = new CounterStrike;
  $status=$server->getServerPlayers($HTTP_GET_VARS["serveradr"],$HTTP_GET_VARS["serverport"],1000);
  if ($status) {
?>
<TABLE border=1>
    <TR>
        <TD>Name</TD><TD>Frags</TD><TD>Time</TD>
    </TR>
    <?
      if (is_array($server->m_playerinfo)) {
            while (list(,$player) = each ($server->m_playerinfo)) { ?>
                  <TR>
                        <TD><?=$player["name"];?>&nbsp;</TD><TD>&nbsp;<?=$player["frags"];?></TD><TD><?=$player["time"];?></TD>
                  </TR>
    <?
            }
      }
      else {
      ?>
    <TR>
        <TD COLSPAN="3">No players on server right now</TD>
    </TR>
    <?
      }
      ?>    
</TABLE>
<?
}
else {
?>
<p>Error communicating with server</p>
<BR>
<?
}
?>    
</BODY>
</HTML>

counterstrikeClass.php3 :

<%
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  ="";            // Serverrules
      
      //
      // 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("%2dh",$time/3600);
            }
            $time%=3600;
            $playtime=$playtime.sprintf("%2dm",$time/60);    
            $time%=60;
            $playtime=$playtime.sprintf("%2ds",$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) {
            $cmd="\xFF\xFF\xFF\xFFrules\x00";            
            $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) {
            $cmd="\xFF\xFF\xFF\xFFinfo\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,5);
            $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);      
            return true;
}      


      // **********************************************************************
      // Get Playerinfo
      // Read information about the players into m_playerinfo
      // Name,frags,playtime
      // Return true if successful
      // **********************************************************************
      function getServerPlayers($serveraddress,$portnumber,$waittime) {
            // Servercommand
            $cmd="\xFF\xFF\xFF\xFFplayers\x00";
            $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;
      }
}
?>

Author : Henrik Schack Jensen
0
Comment
Question by:Capion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 50 total points
ID: 6885878
Shouldn't you use echo instead of "=" ?

ie: replace
<TD><?=$server[$i]->m_servervars["serveraddress"]; ?></TD>
with

<TD><? echo $server[$i]->m_servervars["serveraddress"]; ?></TD>
0
 
LVL 1

Author Comment

by:Capion
ID: 6885949
Thank You !
It "worked", the script ran error-free.
(next is.. I can´t run php4..which I found the script is progged for, so I just get an empty listing)
0
 

Expert Comment

by:mattsobo
ID: 6889712
    <tr>
          <TD><a href="players.php3?serveradr=<?php echo $serveradr; ?>&serverport=<?php echo $serverport; ?>"><?php
echo $server[$i]->m_servervars["servername"]; ?></a></TD>
          <TD><?=$server[$i]->m_servervars["serveraddress"]; ?></TD>
          <TD><?=$server[$i]->m_servervars["currentplayers"]; ?> / <?=$server[$i]->m_servervars["maxplayers"];?></TD>
          <TD><?=$server[$i]->m_servervars["mapname"];?></TD>
     </tr>

In this row you have several columns starting "<?="

What is that equal sign there for?

That's probably causing the error.
0
 
LVL 1

Author Comment

by:Capion
ID: 6889727
yes.. I changed them to Echo
and..read my previous comment *S*
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Find RGB colors from a screen. 2 42
Code not executing correctly. 3 44
SSL unsecure page mystery 17 47
Search result not displaying in grid 7 13
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question