SRCDS Steam group


What am I doing wrong? PHP Server info
#1
Sad 
/serverlist.php
PHP Code:
<?PHP include "lib/header.php"; include "lib/server_info/serverinfo.php"; ?> <div class="post"> <h2 class="title"><?PHP echo $_SITENAME ?> Servers</h2> <div class="story"> <p><?PHP print_all_server_info(); ?></p> </div> </div> <?PHP include "lib/footer.php" ?>

/lib/server_info/serverinfo.php
PHP Code:
<?PHP include "source_query.php"; include "format_source_query.php"; include "testonline.php"; function print_server_info($ip,$port){ $query = "SELECT * from `bluorb`.`servers` WHERE `IP`='" . $ip . "' AND `Port`='" . $port ."';"; $SQL_result=mysql_query($query); while($row = mysql_fetch_array($SQL_result, MYSQL_ASSOC)){ if(($ip==$row['IP']) && ($port==$row['Port'])){ if ($row['GameEngine'] == "sourceengine"){ if (Server_IsOnline(gethostbyname($row['IP']),$row['Port'])){ $server_query = source_query( gethostbyname($row['IP']),$row['Port']); // $ip MUST contain IP:PORT $q = format_source_query($server_query); echo "<tr><td bgcolor=\"#eeeeee\">".$q['hostname']."</td><td>".$row['IP'].":".$row['Port']."</td><td>"."&lt;Unknown&gt;"."</td><td>".$q['map']."</td></tr>"; if( ($q['game'] !== $row['Game']) && ($q['game'] !== "Unknown") ){ echo "Error! recorded game does not match with server!"; } }else{ echo "<tr><td bgcolor=\"#eeeeee\">"."&lt;Unknown&gt;"."</td><td>".$row['IP'].":".$row['Port']."</td><td>"."&lt;Unknown&gt;"."</td><td>"."&lt;Unknown&gt;"."</td></tr>"; } }else{ echo "<tr><td bgcolor=\"#eeeeee\">".$row['Name']."</td><td>".$row['IP'].":".$row['Port']."</td><td>&lt;Unknown&gt;</td><td>&lt;Unknown&gt;</td></tr>"; } } }//WHILE } function print_all_server_info(){ $query = "SELECT * from `bluorb`.`servers` ORDER BY `Game`;"; $SQL_result=mysql_query($query); $_lastgame=""; while($row = mysql_fetch_array($SQL_result, MYSQL_ASSOC)){ if (($row['Game'] !== $_lastgame) || ($_lastgame="")){ if($_lastgame !== ""){ printf("</table></div>"); } $_game=$row['Game']; echo '<div class="file_table"><table border="0" width="100%" cellspacing="0" cellpadding="0" class="files"><tr><td bgcolor="#eeeeee"><a href=/games/'.str_replace(' ','_',$_game).'><strong>'.$_game.'</strong></a></td> <td width="200" bgcolor="#eeeeee"><strong>Server Address</strong></td><td width="40" bgcolor="#eeeeee"><strong>Players</strong></td><td width="150" bgcolor="#eeeeee"><strong>Map</strong></td></tr>'; } print_server_info($row['IP'],$row['Port']); $_lastgame=$row['Game']; }//WHILE printf("</table></div>"); } ?>

/lib/server_info/source_query.php
PHP Code:
<?PHP /* SOURCE ENGINE QUERY FUNCTION, requires the server ip:port */ function source_query($ip,$port) { //$cut = explode(":", $ip); $HL2_address = $ip; //$cut[0]; $HL2_port = $port; //$cut[2]; echo "Server: " . $HL2_address . ":" . $HL2_port; $HL2_command = "\377\377\377\377TSource Engine Query\0"; $HL2_socket = fsockopen("udp://".$HL2_address, $HL2_port, $errno, $errstr,3); fwrite($HL2_socket, $HL2_command); $JunkHead = fread($HL2_socket,4); $CheckStatus = socket_get_status($HL2_socket); if($CheckStatus["unread_bytes"] == 0) { return 0; } $do = 1; $HL2_stats=""; while($do) { $str = fread($HL2_socket,1); $HL2_stats.= $str; $status = socket_get_status($HL2_socket); if($status["unread_bytes"] == 0) { $do = 0; } } fclose($HL2_socket); $x = 0; $result=""; while ($x <= strlen($HL2_stats)) { $x++; $result.= substr($HL2_stats, $x, 1); } $result = urlencode($result); // the output return $result; } ?>

/lib/server_info/format_source_query.php
PHP Code:
<?PHP /* FORMAT SOURCE ENGINE QUERY (assumes the query's results were urlencode()'ed!) */ function format_source_query($string) { $string = str_replace('%07','',$string); $string = str_replace("%00","|||",$string); $sinfo = urldecode($string); $sinfo = explode('|||',$sinfo); $info['hostname'] = $sinfo[0]; $info['map'] = $sinfo[1]; $info['game'] = $sinfo[2]; $info['gamemode'] = $sinfo[3]; if ($info['game'] == 'garrysmod') { $info['game'] = "Garry's Mod"; } elseif ($info['game'] == 'cstrike') { if ($info['gamemode']=="Counter-Strike"){ $info['game'] = "Counter-Strike 1.6"; }elseif ($info['gamemode']=="Counter-Strike: Source"){ $info['game'] = "Counter-Strike: Source"; } } elseif ($info['game'] == 'dod') { $info['game'] = "Day of Defeat: Source"; } elseif ($info['game'] == 'tf') { $info['game'] = "Team Fortress 2"; } elseif ($info['game'] == 'left4dead') { $info['game'] = "Left 4 Dead"; } elseif ($info['game'] == 'ageofchivalry') { $info['game'] = "Age of Chivalry"; } elseif ($info['game'] == 'diprip') { $info['game'] = "D.I.P.R.I.P."; } elseif ($info['game'] == 'zps') { $info['game'] = "Zombie Panic: Source"; } elseif ($info['game'] == 'insurgency') { $info['game'] = "Insurgency"; } elseif ($info['game'] == 'hl2mp') { $info['game'] = "Half-Life 2: Deathmatch"; } return $info; } ?>

/lib/testonline.php
PHP Code:
<?php define('PACKET_SIZE', '1400'); define('SERVERQUERY_GETCHALLENGE', "\xFF\xFF\xFF\xFF\x57"); define ('REPLY_GETCHALLENGE', "\x41"); function Server_IsOnline($_ip, $_port){ // quick script to check if the server is online or not\ // Open a connection with server try{ $socket = fsockopen('udp://'.$_ip, $_port, $errno, $errstr, 2); echo $errno; // Send command to server $cmd = SERVERQUERY_GETCHALLENGE; $length = strlen($cmd); fwrite($socket, $cmd, $length); // Get response from server $response = fread($socket, PACKET_SIZE); if (empty($response)) { return false; } else { return true; } }catch(Exception $e){ return false; } } ?>



When I launch /serverlist.php with php.exe it works fine, but when it is launched by IIS with php-cgi.exe I get a 500 error:
HTTP Error 500.0 - Internal Server Error
C:\Program Files (x86)\PHP\php-cgi.exe - The FastCGI process exceeded configured activity timeout


I'm trying to get it to list all servers in a database alphabetically and get extra info for Source Engine servers. The error only comes up as soon as I add sourceengine servers.
Reply
#2
please help me someone!
Reply
#3
nvm I fixed it... error in the database ><
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)