Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
ciph3r
Worker
Worker



Joined: Jun 01, 2005
Posts: 178

PostPosted: Tue Jan 22, 2008 3:06 am Reply with quote

I currently am working on a CoD4 Server Viewer block.

This is what I have so far: [ Only registered users can see links on this board! Get registered or login! ]

The issue is the Server Name is hard coded into the block because I cannot figure out how to translate color codes.

Here is the source:
Code:


<SCRIPT LANGUAGE="javascript">var ie4 = false; if(document.all) { ie4 = true; } function getObject(id) { if (ie4) { return document.all[id]; } else { return document.getElementById(id); } } function toggle(link, divId) { var lText = link.innerHTML; var d = getObject(divId); if (lText == '+') { link.innerHTML = '−'; d.style.display = 'block'; } else { link.innerHTML = '+'; d.style.display = 'none'; } } </SCRIPT>
<?
// Modded AA Block for COD4

//////////////////////////////////////////////
// America's Army Server Info Block
// based on the PHP Nuke block designed by DivideByZero
//
// Redesigned and converted by Ken McNicholas for TinyPortal block
// Complete Computer Services
// August 20, 2006
//
// TinyPortal 0.86 with SMF 1.1 RC2
//
// The America's Army Server Info Block displays current players
// on a particular America's Army server.
// Set up the configuration info for the server you wish to query
//
//////////////////////////////////////////////

/*
****************************************
****************************************
*** !! User Configuration Section !! ***
****************************************
****************************************
*/

// Server IP you want to query

$aa_ip = '208.167.250.102';
$aa_port2 = ':28960';
// Server Name
$aa_server_name = '<span style="color:#FFFFFF">*</span><span style="color:#00B906">Ranked </span><span style="color:#E8FF19">S&D</span><span style="color:#FFFFFF">*</span><span style="color:#23C2C6">HardCore</span>';
$aa_server_url = 'http://cod4tracker.com/weblauncher/';
$aa_lookup_server = 'http://cod4tracker.com/weblauncher/' . $aa_ip . $aa_port2 . '/';
$aa_gtracker_url = 'http://www.gametracker.com/server_info/' . $aa_ip . $aa_port2 . '/';
$cod4_imageurl_full = '<img src="http://cache.www.gametracker.com/server_info/' . $aa_ip . $aa_port2 . '/b_160x400_T2_F-1-2-3.png" border="0" />';

// Server Port - 1717 = default
$aa_port = '28960';

// URL to where you put the folder containing the map pics (include a trailing slash!)
$aa_image_path = 'http://airdaleops.com/Themes/AONV2/server/cod4/';

// You should only need to change the map array if maps
// are added/deleted/changed, otherwise leave as is
$map = array("mp_citystreets" => "citystreets.png",
"mp_backlot" => "backlot.png",
"mp_bloc" => "bloc.png",
"mp_bog" => "bog.png",
"mp_cargoship" => "cargoship.png",
"mp_convoy" => "convoy.png",
"mp_countdown" => "countdown.png",
"mp_crash" => "crash.png",
"mp_crossfire" => "crossfire.png",
"mp_farm" => "farm.png",
"mp_overgrown" => "overgrown.png",
"mp_pipeline" => "pipeline.png",
"mp_shipment" => "shipment.png",
"mp_showdown" => "showdown.png",
"mp_strike" => "strike.png",
"mp_vacant" => "vacant.png",
"mp_crash_snow" => "crash_snow.png"
 );
                                   
/*
****************************************
****************************************
*/

//////////////////////////////////////////////
//
// The rest of this you should leave as is
// unless you are overly industrious :)
//
//////////////////////////////////////////////

// query server for game info
$aa_sock = fsockopen( "udp://" . $aa_ip, $aa_port);
if($aa_sock != false){

   

socket_set_timeout($aa_sock, 0, 500000);

   

fwrite($aa_sock, "ÿÿÿÿgetstatus\0");

   

$aa_info = @fread($aa_sock, 8192);

   

fclose($aa_sock);
}

$resarr = explode("\n", str_replace("\"", "" ,substr($aa_info, strpos($aa_info, "ui_maxclients"))));
$count = count($resarr) - 2;

// create array to hold game info
$aa_infoarr = explode("\\", $aa_info);
$aa_info = array();
$aa_infosize = count($aa_infoarr);
// since first element is unused (element 0) start at element 1
// and populate an associative array (nicer, and easier!)
for ($i = 1; $i < $aa_infosize; $i += 2){

   

$aa_info[$aa_infoarr[$i]] = $aa_infoarr[$i+1];
}

// get player list
//$players = "";
//$p = 1;
//for ($i = 0; $i < $aa_info['numplayers']; $i++){
//

   

$players .= $p . ' - ' . $aa_info['player_' . $i] . '<br />';
//

   

$p++;
//}

$players = "";
$p = 1;
for ($i = 1; $i < $count + 1; $i++)
{

   

$parr = explode(" ", $resarr[$i]);

   

$start = strlen($parr[0] . $parr[1]) + 2;

   

$players .= $p . " - " . substr($resarr[$i], $start) . '<br />';

   

$p++;
}

// display info
// Host name and link to detail from FO Online Server Browser
//echo '<a href="' . $aa_server_url . $aa_ip . '">' . $aa_info['hostname'] . "</a><br />";
/*
echo '<a href="' . $aa_server_url . $aa_ip . $aa_port2 . '/">' . $aa_info['sv_hostname'] . "</a><br />";
*/

// echo 'Server Name: <a href="' . $aa_server_url . $aa_ip . $aa_port2 . '/">' . Test . "</a><br />";

//echo 'Server Name: <a href="' . $aa_server_url . $aa_ip . $aa_port2 . '/">' . '<br><span style="color:#00B906">Ranked </span><span style="color:#E8FF19">S&D</span><span style="color:#FFFFFF">*</span><span style="color:#23C2C6">HardCore</span>' . "</a><br /><p>";


echo 'Server Name: <br>' . $aa_server_name .'<br>';

echo '<b>Advanced:</b><br>';
echo 'Pure Server: ' . $aa_info['sv_pure'] . '<br />';
echo 'Version: ' . $aa_info['shortversion'] . '<br />';
echo 'Punkbuster: ' .$aa_info['sv_punkbuster'] . '<br />';
//echo 'Max Ping: ' . $aa_info['sv_maxPing'] . '<br />';
//echo 'Max Rate: ' . $aa_info['sv_maxRate'] . '<br />';
echo '<br>';
//echo 'Test: ' . $aa_info['pam_mode'] . '<br />';
//IP:Port address
echo 'IP: <a href="' . $aa_server_url . $aa_ip . $aa_port2 . '/">' . $aa_ip . "</a><br />";
echo 'Port: ' . $aa_port . '<br />';
// Map Name
echo 'Map: ' . $aa_info['mapname'] . '<br />';
// Game Type
echo 'Game Type: ' . $aa_info['g_gametype'] . '<br />';
// Players / Max Players
echo 'Players: <b><font color=#00ff00>' . $count . '</b></font> / ' . $aa_info['sv_maxclients'] . '<br />';
echo '<hr';
// Round


$mappic = "";
if (array_key_exists($aa_info['mapname'], $map)){

   

echo '<img src="' . $aa_image_path . $map[$aa_info['mapname']] . '"><br />';
} else {

   

echo 'Map Unavailable!<br />';
}
echo '<a href="' . $aa_lookup_server . '">* Server Intel *</a><br />';
// display scrolling player list
echo '<marquee behavior="scroll" align="left" direction="up" height="50" width="90%" scrollamount="2" scrolldelay="150" bgcolor="000000"
loop="infinite" onmouseover="this.stop()" onmouseout="this.start()">';
echo '<a href="' . $aa_lookup_server . '">' . $players . '</a></marquee>';
?>
<hr />
Click (+) To Expand
<!-- <div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="cplayers_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'cplayers');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
  <td align="left"><b> <a onclick="toggle(getObject('cplayers_link'), 'cplayers');" href="javascript:%20void(0);" name="link">Current Players </a></b></td>
  </tr> </table> <div id="cplayers" style="border: 1px solid #0000CC; padding: 0px; position:relative; left:0px; width:140px"><? echo '<a href="' . $aa_lookup_server . '">' . $players . '</a>' ?>
 </CENTER></p></DIV>
<SCRIPT LANGUAGE="javascript">toggle(getObject('cplayers_link'), 'cplayers'); </SCRIPT> -->
 <div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="stools_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'stools');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
  <td align="left"><b> <a onclick="toggle(getObject('stools_link'), 'stools');" href="javascript:%20void(0);" name="link">Server Tools  </a></b></td>
  </tr> </table>
<div id="stools" style="border: 1px solid #FFFF00; padding: 0px; position:relative; left:0px; width:140px; height: 45%;"><a href="http://www.clangoat.com/pbssView/index.php" target="_blank">&raquo;&raquo;&raquo; PBSS Viewer</a><br />
  <a href="http://cod4tracker.com/index.php?form=PlayerSearch" target="_blank">&raquo;&raquo;&raquo; Player Search</a></DIV>
<SCRIPT LANGUAGE="javascript">toggle(getObject('stools_link'), 'stools'); </SCRIPT>
</DIV>
<div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="gtracker_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'gtracker');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
  <td align="left"><b><a onclick="toggle(getObject('gtracker_link'), 'gtracker');" href="javascript:%20void(0);" name="link"><img src="http://www.clangoat.com/images/custom/gtmenu.jpg" width="100%" border="0" /></a></b></td>
  </tr> </table>
<div id="gtracker" style="border: 1px solid #00FF00; padding: 0px; position:relative; left:0px; width:160px; height:441px"><? echo '<a href="' . $aa_gtracker_url . '">' . $cod4_imageurl_full . "</a><br />";?></CENTER></p></DIV> </FONT></DIV>
<SCRIPT LANGUAGE="javascript">toggle(getObject('gtracker_link'), 'gtracker'); </SCRIPT>

<div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="xfire_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'xfire');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
     <td align="left"><b><a onclick="toggle(getObject('xfire_link'), 'xfire')" href="javascript:%20void(0);" name="link"><img src="http://www.clangoat.com/images/custom/xfiremenu.jpg" width="100%" border="0"></a></b></td>
    </tr> </table> <div id="xfire" style="border: 1px solid #ffffff; padding: 0px; position:relative; left:0px; width:140px"><table width="100%" border="1">
  <tr>
    <th scope="row"><? echo '<a href="xfire:join?game=cod4mp&server=' . $aa_ip . $aa_port2 . '/">Join Server</a><br />';?> </th>
  </tr>
  <tr>
    <th scope="row"><? echo '<a href="
xfire:add_server?game=cod4mp&server=' . $aa_ip . $aa_port2 . '/">Add To Favorites</a><br />';?></th>
  </tr>
</table>
</div>
</div></div>
       </DIV>
<SCRIPT LANGUAGE="javascript">toggle(getObject('xfire_link'), 'xfire'); </SCRIPT>
     </FONT></DIV>


I found a CoD4Query script that I think holds the key to translating the color codes, but I cant figure it out on my own (ive spent 3 hours trying different things).

Here is the source:
Code:


<?
//
// CoDQuery 1.0
//
// Author:      Bell from the clan [WC-anka]
// Clanpage:      http://bunbun.milliways.st/
// PHP-stuff for CoD:   http://www.milliways.st/cod/
// Feedback:      codconfig@milliways.st
// License:      Use it, have fun and play on our servers... ;)
//

//
// CoDPlayer class
//
class CoDPlayer {
  var $score;
  var $ping;
  var $rawname;
  var $name;
  var $cname;
 
  function CoDPlayer($score, $ping, $rawname) {
    $this->score = $score;
    $this->ping = $ping;
    $name=trim(trim($rawname), "\"");
    $this->rawname=$name;
    $this->name=removecolorcodes($name);
    $this->cname=translatecolorcodes($name);
  }

}

//
// CoDQuery class
//
class CoDQuery {

  // Variables for normal use
  var $ip="208.167.250.102"; //IP adress
  var $port="28960";      //UDP port
  var $name="OFFLINE";      //Server name color codes removed
  var $cname="OFFLINE";      //Server name color coded html
  var $map="";         //Current map
  var $gametype;      //Gametype
  var $numplayers=0;      //Number of players
  var $maxplayers=0;      //Maximum players
  var $privateplayers=0;   //Private players
  var $password=0;      //Password needed to join?
  var $pure=0;         //Pure server?
  var $modified=0;      //Mod:ed server?
  var $friendlyfire=0;      //Friendly fire?
  var $killcam=0;      //Killcam?
  var $maxping=0;      //Max ping
  var $minping=0;      //Min ping
  var $maxrate=0;      //Max rate
  var $version=0;      //Version
  var $punkbuster=0;      //Punkbuster?

  var $players = array();   //Array with players

  // Variables for advanced users
  var $rawgetinfo;      //Raw information from the getinfo command            
  var $rawgetstatus;      //Raw information from the getstatus command

  var $info = array();      //Array with values from $rawgetinfo
  var $status = array();   //Array with values from $rawgetstatus
  var $rawplayers = array();   //Array with raw player information

  // Constructor
  function CoDQuery($ip,$port) {
    // Init some variables
    $this->ip = gethostbyname($ip);   //Resolv IP adress
    if($port)             //If $port is set to a value...
      $this->port = $port;      //...use it.
   
    // Open socket
    $fp = fsockopen("udp://" . $this->ip, $this->port, $errno, $errstr, 1);
 
    if (!$fp) {               // OK?
      $this->name=$this->cname="ERROR!!";   //If error, set servername to ERROR!!
    } else {

      // Set a low timeout to avoid longs waits if a player disconnects while we are still getting info
      stream_set_timeout($fp, 2);
      // Try one of the following instead of the line above if you use PHP prior to 4.3.0
      // socket_set_timeout($fp, 2);
      // set_socket_timeout($fp, 2);

      fputs($fp, "\xff\xff\xff\xffgetinfo\n");      // Send getinfo command
      usleep(100000);               // Wait 0.1 seconds between the commands.
      fputs($fp, "\xff\xff\xff\xffgetstatus\n");   // Send getstatus command 

      // Get response
      $dummy=fgets($fp);         //Skip first line

      // Get line with serverinfo
      $this->rawgetinfo = preg_replace("/\xff\xff\xff\xffstatusResponse/", "", fgets($fp));   //Save the raw server info

      // Split it into an array
      $arr=explode("\\",$this->rawgetinfo);

      // Skip first element which will be empty and then loop trough the rest
      for ($i=1;$i<count($arr);$i++) {
        $this->info[$arr[$i++]] = $arr[$i];   //Tidy up the data into a neat array
      }

      // Get line with serverstatus
      $this->rawgetstatus=fgets($fp);

      // Split it into an array
      $arr=explode("\\",$this->rawgetstatus);

      // Skip first element which will be empty and then loop trough the rest
      for ($i=1;$i<count($arr);$i++) {
        $this->status[$arr[$i++]]=$arr[$i];         //Tidy up the data into a neat array
      }

    }
 
    // Assign the variables that is normally used

    if(isset($this->info[hostname]))    $this->name      = removecolorcodes($this->info[hostname]);   
    if(isset($this->info[hostname]))    $this->cname      = translatecolorcodes($this->info[hostname]);   
    if(isset($this->info[mapname]))     $this->map      = $this->info[mapname];
    if(isset($this->info[gametype]))    $this->gametype      = $this->info[gametype];
    if(isset($this->info[clients]))     $this->numplayers   = $this->info[clients];
    if(isset($this->info[sv_maxclients])) $this->maxplayers   = $this->info[sv_maxclients];
    if(isset($this->status[sv_privateClients])) $this->privateplayers=$this->status[sv_privateClients];
    if(isset($this->status[pswrd]))   $this->password      = $this->status[pswrd];
    if(isset($this->info[pure]))   $this->pure      = $this->info[pure];
    if(isset($this->info[mod]))      $this->modified      = $this->info[mod];
    if(isset($this->info[ff]))      $this->friendlyfire   = $this->info[ff];
    if(isset($this->status[scr_killcam])) $this->killcam   = $this->status[scr_killcam];
    if(isset($this->info[maxPing]))   $this->maxping      = $this->info[maxPing];
    if(isset($this->status[sv_minPing])) $this->minping      = $this->status[sv_minPing];
    if(isset($this->status[sv_maxRate])) $this->maxrate      = $this->status[sv_maxRate];
    if(isset($this->status[shortversion])) $this->version   = $this->status[shortversion];
    if(isset($this->info[pb]))       $this->punkbuster   = $this->info[pb];

    // Loop through the players
    for ($i=0;$i<$this->numplayers;$i++) {
      // Exit if we get a timeout
      // This can happen if a player disconnects before we have recieved all the player data
      if (!($this->rawplayers[$i]=fgets($fp))) {
        $this->numplayers = $this->info[clients] = $i;      // Change to numplayers to actual value
        break;
      }
      // Split the raw data into an array
      $player=explode(" ",$this->rawplayers[$i],3);
      // Use the an array of instances of the CoDPlayer class (score, ping, name)
      $this->players[$i] = new CoDPlayer($player[0], $player[1], $player[2]);
    }
   
    // Close the socket
    fclose($fp);
  }
}

// Function to remove the color codes
function removecolorcodes($string) {
  return preg_replace("/\^[0-9]/", "", htmlspecialchars($string));
}

// Function to translate the color codes into html tags
function translatecolorcodes($string) {
  $pattern[0]="/\^0/";
  $pattern[1]="/\^1/";
  $pattern[2]="/\^2/";
  $pattern[3]="/\^3/";
  $pattern[4]="/\^4/";
  $pattern[5]="/\^5/";
  $pattern[6]="/\^6/";
  $pattern[7]="/\^7/";
  $pattern[8]="/\^8/";
  $pattern[9]="/\^9/";
  $replacement[0]="</font><font color=black>";
  $replacement[1]="</font><font color=red>";
  $replacement[2]="</font><font color=darkgreen>";
  $replacement[3]="</font><font color=yellow>";
  $replacement[4]="</font><font color=blue>";
  $replacement[5]="</font><font color=cyan>";
  $replacement[6]="</font><font color=magenta>";
  $replacement[7]="</font><font color=white>";
  $replacement[8]="</font><font color=purple>";
  $replacement[9]="</font><font color=gray>";
  $string = preg_replace($pattern, $replacement, htmlspecialchars($string));
  return "<font>" . $string . "</font>";
}
echo 'Server Name: <br>' . $name .'<br>';
?>


How could I use the translate function out of that in my block?
 
View user's profile Send private message Visit poster's website
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6432

PostPosted: Tue Jan 22, 2008 6:07 am Reply with quote

Add the class source on your server, instantiate the class in your block, then the function should be available.

Or, copy the functions into your block (if all you need are the removecolorcodes and translatecolorcodes functions).

_________________
I search, therefore I exist...
nukeSEO - nukeFEED - nukePIE - nukeSPAM - nukeWYSIWYG
 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Tue Jan 22, 2008 12:09 pm Reply with quote

LOL, I just wrote a COD4 server query thing this weekend. I can post how I handled the color codes later tonight (or just send you the code for the whole thing). It's not a block though, it was designed to be a page to show a bunch of servers for one clan. But you could probably make it a block with a bit of work. It also works for COD1 and COD:UO.

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
Gremmie







PostPosted: Tue Jan 22, 2008 12:17 pm Reply with quote

Okay, here is the function I used to convert player names to HTML while preserving the COD color scheme. It took me like a freaking hour to come up with the right regular expression for this. I'm quite proud of it. Smile

Code:


function toHtml($s)
   {
      static $colorTable = array('black', 'red', 'lime', 'yellow', 'blue', 'aqua', 'purple', 'white', 'navy', 'silver');
      $s = htmlspecialchars($s);
      $matches = array();
      while (preg_match('/(.*?)\^(\d)(.*?)((?:\^\d).*$|$)/', $s, $matches))
      {
         $s = $matches[1] . '<span style="color: ' . $colorTable[intval($matches[2])] . ';">' . $matches[3] .
            '</span>' . $matches[4];
      }
      return $s;
   }


So call that on your player names and it will turn them into HTML with colors.
 
ciph3r







PostPosted: Tue Jan 22, 2008 1:30 pm Reply with quote

Apologies, im not that experienced with PHP so as much as I appriciate your help. . . i still cant figure it out Sad

Which would be the better (easier) method?

And how would I implement it with the source i posted?

Sorry guys, im no pro.
 
ciph3r







PostPosted: Tue Jan 22, 2008 2:25 pm Reply with quote

Im actually having the same issue with an AA version that I have:

Source:
Code:
<SCRIPT LANGUAGE="javascript">var ie4 = false; if(document.all) { ie4 = true; } function getObject(id) { if (ie4) { return document.all[id]; } else { return document.getElementById(id); } } function toggle(link, divId) { var lText = link.innerHTML; var d = getObject(divId); if (lText == '+') { link.innerHTML = '−'; d.style.display = 'block'; } else { link.innerHTML = '+'; d.style.display = 'none'; } } </SCRIPT>

<?
//////////////////////////////////////////////
// America's Army Server Info Block
// based on the PHP Nuke block designed by DivideByZero
//
// Redesigned and converted by Ken McNicholas for TinyPortal block
// Complete Computer Services
// August 20, 2006
//
// TinyPortal 0.86 with SMF 1.1 RC2
//
// The America's Army Server Info Block displays current players
// on a particular America's Army server.
// Set up the configuration info for the server you wish to query
//
//////////////////////////////////////////////

/*
****************************************
****************************************
*** !! User Configuration Section !! ***
****************************************
****************************************
*/
 include("includes/colorednames.php");
// Server IP you want to query
$aa_ip = '66.55.131.213';
$aa_port2 = ':1716';
$aa_port_display = '1716';
// Server Name
$aa_server_name   = '<b><font color="#ffffff">-</font><font color="#7f7f7f">T</font><font color="#c0c0c0">h</font><font color="#efefef">e </font><font color="#ff0101">S</font><font color="#ff0180">e</font><font color="#b90101">x </font><font color="#010180">P</font><font color="#0101ff">e</font><font color="#8080ff">n</font><font color="#ffffff">- | </font><font color="#ffff01">Ho</font><font color="#bbbb01">n</font><font color="#828201">or</font></b>';
$aa_server_url = 'http://www.forwardobserver.us/browser/foserverlist.php?ServerIP=';
$aa_lookup_server = 'http://www.clangoat.com/ServerViewer/';
$aa_gtracker_url = 'http://www.gametracker.com/server_info/' . $aa_ip . $aa_port2 . '/';
$cod4_imageurl_full = '<img width="100%" height="100%" src="http://cache.www.gametracker.com/server_info/' . $aa_ip . $aa_port2 . '/b_160x400_T2_F-1-2-3.png" border="0" />';

// Server Port - 1717 = default
$aa_port = '1717';

// URL to where you put the folder containing the map pics (include a trailing slash!)
$aa_image_path = 'http://www.clangoat.com/armygame/';

// You should only need to change the map array if maps
// are added/deleted/changed, otherwise leave as is
$map   = array("Bridge Crossing" => "Bridge.jpg",
                     "Bridge SE" => "Bridge SE.jpg",
                     "Border" => "Border.jpg",
                     "Collapsed Tunnel" => "Tunnel-d.jpg",
                     "Dusk" => "Dusk.jpg",               
                     "FLS Assault" => "FLS-b.jpg",
                     "Headquarters Raid" => "HQ_Raid.jpg",
                     "Insurgent Camp" => "Insurgent_Camp-c.jpg",
                     "Interdiction" => "Interdiction.jpg",
                     "JRTC Farm Raid" => "JRTC_Farm.jpg",
                     "Mountain Ambush" => "Mountain_Ambush-b.jpg",
                     "Mountain Pass" => "Mountain_Pass.jpg",
                     "Mountain Pass SE" => "Mountain Pass SE.jpg",
                     "Mout McKenna" => "MOUT_McKenna.jpg",
                     "Pipeline" => "Pipeline-b.jpg",
                     "Pipeline SF" => "Pipeline.jpg",
                     "Radio Tower" => "Radio_Tower.jpg",
                     "Redemption" => "Redemption.jpg",
                     "River Basin" => "River_Basin-c.jpg",
                     "SF Oasis" => "sf_oasis.jpg",
                     "SF Taiga" => "sf_taiga.jpg",
                     "SF Blizzard" => "sf_blizzard.jpg",
                     "SF Courtyard" => "sf_courtyard.jpg",
                     "SF Dockside" => "SFdockside.jpg",
                     "SF Extraction" => "SFextraction.jpg",
                     "SF PCR" => "sf_pcr.jpg",
                     "SF Water Treatment" => "sf_water_treatment.jpg",
                     "SF Arctic" => "sfarctic.jpg",
                     "SF Village" => "sfvillage.jpg",
                     "SF CSAR" => "sf_csar.jpg",
                     "SF Hospital" => "sf_hospital.jpg",
                     "SF Recon" => "sf_recon.jpg",
                     "SF Sandstorm" => "sf_sandstorm.jpg",
                     "Rummage" => "rummage.jpg",
                     "SF Hospital SE" => "sfhospitalse.jpg",
                     "SF SnakePlain" => "snakeplain.jpg",
                     "Steamroller" => "steamroller.jpg",
                     "Swamp Raid" => "Swamp_Raid-a.jpg",
                     "SMU GH RiverVillage" => "RiverVillage.jpg",
                       "SMU GH SFFloodgate" => "Floodgate.jpg",
                     "SMU GH SFOldTown" => "OldTown.jpg",
                     "SMU GH SFRefinery" => "Refinery.jpg",
                     "Weapons Cache" => "Weapons_Cache-d.jpg",
                     "Weapons Cache SE" => "Weapons_Cache-a.jpg",
                     "Woodland Outpost" => "woodland_outpost.jpg",
                     "Urban Assault" => "urban_assault.jpg");
                                   
/*
****************************************
****************************************
*/

//////////////////////////////////////////////
//
// The rest of this you should leave as is
// unless you are overly industrious :)
//
//////////////////////////////////////////////

// query server for game info
$aa_sock = fsockopen( "udp://" . $aa_ip, $aa_port);
if($aa_sock != false){
   socket_set_timeout($aa_sock, 0, 500000);
   fwrite($aa_sock, "\\info\\");
   $aa_info = @fread($aa_sock, 8192);
   fclose($aa_sock);
}   

// create array to hold game info
$aa_infoarr = explode("\\", $aa_info);
$aa_info = array();
$aa_infosize = count($aa_infoarr);
// since first element is unused (element 0) start at element 1
// and populate an associative array (nicer, and easier!)
for ($i = 1; $i < $aa_infosize; $i += 2){
   $aa_info[$aa_infoarr[$i]] = $aa_infoarr[$i+1];
}

// get player list
$players = "";
$p = 1;
for ($i = 0; $i < $aa_info['numplayers']; $i++){
   $players .= $p . ' - ' . $aa_info['player_' . $i] . '<br />';
   $p++;
}

// display info
// Host name and link to detail from FO Online Server Browser
//echo 'test: ' . $aa_info[hostname] . '<br />';
echo 'Server Name: <br><a href="' . $aa_lookup_server . $aa_ip . '">' . $aa_server_name . "</a><br />";
//IP:Port address
echo 'IP: <a href="' . $aa_lookup_server . '">' . $aa_ip . '</a><br />';
echo 'Port: ' . $aa_port_display . '<br />';
// Map Name
echo 'Map: ' . $aa_info['mapname'] . '<br />';
// Game Version
echo 'Version: ' . $aa_info['gamever'] . '<br />';
// Players / Max Players
echo 'Players: <b><font color=#00ff00>' . $aa_info['numplayers'] . '</b></font> / ' . $aa_info['maxplayers'] . '<br />';
// Round
echo 'Round: ' . $aa_info['current_round'] . '<br />';
//Mission Time
echo 'Time: ' . $aa_info['mission_time'] . '<br />';
echo '<hr>';
$mappic = "";
if (array_key_exists($aa_info['mapname'], $map)){
   echo '<img src="' . $aa_image_path . $map[$aa_info['mapname']] . '"><br />';
} else {
   echo 'Map Unavailable!<br />';
}
echo '<a href="' . $aa_lookup_server . '">* Server Intel *</a><br />';
//echo 'Current Players:<br />';
//echo '<a name="scrollingCode"></a>'

// display scrolling player list
echo '<marquee behavior="scroll" align="left" direction="up" height="50" width="90%" scrollamount="2" scrolldelay="100" bgcolor="000000"
         loop="infinite" onmouseover="this.stop()" onmouseout="this.start()">';
echo '<a href="' . $aa_lookup_server . '">' . $players . '</a></marquee>';
?><br />
<hr />
Click (+) To Expand
<!-- <div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="cplayers2_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'cplayers2');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
  <td align="left"><b> <a onclick="toggle(getObject('cplayers2_link'), 'cplayers2');" href="javascript:%20void(0);" name="link">Current Players </a></b></td>
  </tr> </table> <div id="cplayers2" style="border: 1px solid #0000CC; padding: 0px; position:relative; left:0px; width:140px"><? echo '<a href="' . $aa_lookup_server . '">' . $players . '</a>' ?>
 </CENTER></p></DIV> 
<SCRIPT LANGUAGE="javascript">toggle(getObject('cplayers2_link'), 'cplayers2'); </SCRIPT> -->
<div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="stools2_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'stools2');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
  <td align="left"><b> <a onclick="toggle(getObject('stools2_link'), 'stools2');" href="javascript:%20void(0);" name="link">Server Tools  </a></b></td>
  </tr> </table>
<div id="stools2" style="border: 1px solid #FFFF00; padding: 0px; position:relative; left:0px; width:140px; height: 45%;">
    <a href="http://www.clangoat.com/ServerViewer/">&raquo;&raquo;&raquo; Server Viewer <img src="http://www.clangoat.com/modules/Downloads/images/new_7.gif" border="0"></a><br /><a href="http://www.clangoat.com/pbssView/index.php" target="_blank">&raquo;&raquo;&raquo; PBSS Viewer</a><br /><a href="http://www.aa-mbs.com/search.php?indiv=1&force=1&attr=playerName&type=wildcard&value=-g2.&">&raquo;&raquo;&raquo; Player Search</a></DIV>
<SCRIPT LANGUAGE="javascript">toggle(getObject('stools2_link'), 'stools2'); </SCRIPT>
</DIV><div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="gtracker2_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'gtracker2');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
  <td align="left"><b><a onclick="toggle(getObject('gtracker2_link'), 'gtracker2');" href="javascript:%20void(0);" name="link"><img src="http://www.clangoat.com/images/custom/gtmenu.jpg" width="100%" border="0" /></a></b></td>
  </tr> </table>
<div id="gtracker2" style="border: 1px solid #00FF00; padding: 0px; position:relative; left:0px; width:160px; height:441px"><? echo '<a href="' . $aa_gtracker2_url . '">' . $cod4_imageurl_full . "</a><br />";?></CENTER></p></DIV> </FONT></DIV>
<SCRIPT LANGUAGE="javascript">toggle(getObject('gtracker2_link'), 'gtracker2'); </SCRIPT>

<div style="width: 145px; border: 0px solid #ffffff; padding: 0px; background: #000000"> <table style="color: #ffd142; background: #000000" cellSpacing="0" cellPadding="0" width="145" border="1">
  <tr> <td align="left" width="3%"><font color="#ffffff">(</font><a id="xfire2_link" title="show/hide" style="color: #ffffff; text-decoration: none" onclick="toggle(this, 'xfire2');" href="javascript:%20void(0);">−</a><font color="#ffffff">)&nbsp;</font></td>
     <td align="left"><b><a onclick="toggle(getObject('xfire2_link'), 'xfire2')" href="javascript:%20void(0);" name="link"><img src="http://www.clangoat.com/images/custom/xfiremenu.jpg" width="100%" border="0"></a></b></td>
    </tr> </table> <div id="xfire2" style="border: 1px solid #ffffff; padding: 0px; position:relative; left:0px; width:140px"><table width="100%" border="1">
  <tr>
    <th scope="row"><? echo '<a href="xfire:join?game=aao&server=' . $aa_ip . $aa_port2 . '/">Join Server</a><br />';?> </th>
  </tr>
  <tr>
    <th scope="row"><? echo '<a href="
xfire:add_server?game=aao&server=' . $aa_ip . $aa_port2 . '/">Add To Favorites</a><br />';?></th>
  </tr>
</table>
</div>
</div></div>
       </DIV>
<SCRIPT LANGUAGE="javascript">toggle(getObject('xfire2_link'), 'xfire2'); </SCRIPT>
     </FONT></DIV>


Source of colorednames.php:
Code:
<? function ut2004color($tempname,$docolor) {


  $colagain=1;
  $maxcols=0;
  $data1=$tempname;

  while($colagain==1 && $maxcols<=50) {
   if(preg_match("#(.+)(.+)#",$data1,$match)) {
    $data1=$match[1];
    $data2=$match[2];

    $maxcols++;

    $snamehex = bin2hex(substr($data2, 0, 1));
    $snamehex .= bin2hex(substr($data2, 1, 1));
    $snamehex .= bin2hex(substr($data2, 2, 1));
    $tempname = str_replace ("$shex1$shex2$shex3", "", substr($data2, 3, 250));

    if($docolor==1) $coloredname = "<font color=\"#$snamehex\">$tempname</font>$coloredname";
    else $coloredname = "$tempname$coloredname";

    $colagain=1;
   } else {
    $firstbyte = substr($data1, 0, 1);
    if($firstbyte=="") {
     $snamehex = bin2hex(substr($data1, 1, 1));
     $snamehex .=bin2hex(substr($data1, 2, 1));
     $snamehex .=bin2hex(substr($data1, 3, 1));
     $tempname = str_replace ("$shex1$shex2$shex3", "", substr($data1, 4, 250));

     if($docolor==1) $coloredname = "<font color=\"#$snamehex\">$tempname</font>$coloredname";
     else $coloredname = "$tempname$coloredname";
    } else {
     $tempname = substr($data1, 0, 250);
     $coloredname = "$tempname$coloredname";
    }

    $colagain=0;
   }
  }

 if($docolor==1) $coloredname = "<b>$coloredname</b>";

 return $coloredname;
}
?>
 
Gremmie







PostPosted: Tue Jan 22, 2008 9:16 pm Reply with quote

Sorry I don't have time to figure this out for you. But in a nutshell, add that function I posted to the block code. Then call it whenever it displays a players name. I might clean up and release my code sometime soon.
 
ciph3r







PostPosted: Tue Jan 22, 2008 11:43 pm Reply with quote

Gremmie wrote:
Sorry I don't have time to figure this out for you. But in a nutshell, add that function I posted to the block code. Then call it whenever it displays a players name. I might clean up and release my code sometime soon.


Understood. When I was using SQuery we had a topic on their forums about using the colorednames.php.

Ive been trying to work off of that, and cant seem to get it figured out.

If I remember correctly, it was included (like in my source), then used in this perspective:
Code:


$servername = $gameserver->htmlize($gameserver->servertitle);

if(strstr($servername,"")){
        echo ut2004color($servername,1);
}else{
        echo $servername;
}


This was supposed to display it if it was colored (in colors) and if not, in plain text.

Now, Ive tried everything I can think of, but cant figure out how to use it in just my aa block.
 
ciph3r







PostPosted: Wed Jan 23, 2008 1:49 am Reply with quote

Ok, this is as far as I got:

I moved the code from the colorednames.php into the actual file. . .

I then added this:
Code:


 if(strstr($aa_info['hostname'],"")) {
echo 'Server Name: <br>' . ut2004color($aa_info['hostname'],1) . '<br />';
} else echo 'test: <br>' . $aa_info['hostname'] . '<br />';


It seems to work for colored server names. . . but if the server name is not colored it adds a "" to it it.

Any ideas?

Keep in mind, im learning lol.
 
Gremmie







PostPosted: Wed Jan 23, 2008 8:38 am Reply with quote

Well why not move the function I posted into the file and then call it like you are doing above.

I don't know if UT has the same color scheme system as COD.
 
ciph3r







PostPosted: Wed Jan 23, 2008 3:58 pm Reply with quote

I figured it out finally!!!

w00t

First, for AA:

Create a utcolorednames.php file with the following source:
Code:


<? function ut2004color($tempname,$docolor) {

  $colagain=1;
  $maxcols=0;
  $data1=$tempname;

  while($colagain==1 && $maxcols<=50) {
   if(preg_match("#(.+)(.+)#",$data1,$match)) {
    $data1=$match[1];
    $data2=$match[2];

    $maxcols++;

    $snamehex = bin2hex(substr($data2, 0, 1));
    $snamehex .= bin2hex(substr($data2, 1, 1));
    $snamehex .= bin2hex(substr($data2, 2, 1));
    $tempname = str_replace ("$shex1$shex2$shex3", "", substr($data2, 3, 250));

    if($docolor==1) $coloredname = "<font color=\"#$snamehex\">$tempname</font>$coloredname";
    else $coloredname = "$tempname$coloredname";

    $colagain=1;
   } else {
    $firstbyte = substr($data1, 0, 1);
    if($firstbyte=="") {
     $snamehex = bin2hex(substr($data1, 1, 1));
     $snamehex .=bin2hex(substr($data1, 2, 1));
     $snamehex .=bin2hex(substr($data1, 3, 1));
     $tempname = str_replace ("$shex1$shex2$shex3", "", substr($data1, 4, 250));

     if($docolor==1) $coloredname = "<font color=\"#$snamehex\">$tempname</font>$coloredname";
     else $coloredname = "$tempname$coloredname";
    } else {
     $tempname = substr($data1, 0, 250);
     $coloredname = "$tempname$coloredname";
    }

    $colagain=0;
   }
  }

 if($docolor==1) $coloredname = "<b>$coloredname</b>";

 return $coloredname;
}
?>


At the top of the AA Query file (aaquery.php in my previous examples) add the following:

Above
Code:


// Server IP you want to query


Add
Code:
 include("utcolorednames.php");


Find
Code:


// display info
// Host name and link to detail from FO Online Server Browser
echo '<a href="' . $aa_server_url . $aa_ip . '">' . $aa_info['hostname'] . "</a><br />";


Replace with
Code:


// Host name
$servername = $aa_info['hostname'];

if(strstr($servername,"")){
echo 'Server Name: <br><a href="' . $aa_lookup_server . '">' . ut2004color($servername,1) . "</a><br />";
}else{
        echo 'Server Name: <br><a href="' . $aa_lookup_server . '">' . ut2004color($servername,0) . "</a><br />";
}




Once you have made these changes if the servername has colours in it, they will be displayed. . . if not, it will display it in the default font/color.


Changing it for CoD4.

The exact same concept, except this time create a cod4colorednames.php with the following:
Code:


<?php
// Function to translate the color codes into html tags
function translatecolorcodes($string) {
  $pattern[0]="/\^0/";
  $pattern[1]="/\^1/";
  $pattern[2]="/\^2/";
  $pattern[3]="/\^3/";
  $pattern[4]="/\^4/";
  $pattern[5]="/\^5/";
  $pattern[6]="/\^6/";
  $pattern[7]="/\^7/";
  $pattern[8]="/\^8/";
  $pattern[9]="/\^9/";
  $replacement[0]="</font><font color=black>";
  $replacement[1]="</font><font color=red>";
  $replacement[2]="</font><font color=darkgreen>";
  $replacement[3]="</font><font color=yellow>";
  $replacement[4]="</font><font color=blue>";
  $replacement[5]="</font><font color=cyan>";
  $replacement[6]="</font><font color=magenta>";
  $replacement[7]="</font><font color=white>";
  $replacement[8]="</font><font color=purple>";
  $replacement[9]="</font><font color=gray>";
  $string = preg_replace($pattern, $replacement, htmlspecialchars($string));
  return "<font>" . $string . "</font>";
}
?>


inside the cod4query.php file Look for:
Code:


// Server IP you want to query


Above add
Code:


 include("cod4colorednames.php");


Find
Code:


// display info
// Host name and link to detail from FO Online Server Browser
//echo '<a href="' . $aa_server_url . $aa_ip . '">' . $aa_info['hostname'] . "</a><br />";


Replace With
Code:


// display info

// Host name
$servername = $aa_info['sv_hostname'];

if(strstr($servername,"^")){
echo 'Server Name: <br><a href="' . $aa_lookup_server . '">' . translatecolorcodes($servername,1) . "</a><br />";
}else{
        echo 'Server Name: <br><a href="' . $aa_lookup_server . '">' . translatecolorcodes($servername,0) . "</a><br />";
}


Hope this helps
 
Gremmie







PostPosted: Wed Jan 23, 2008 4:48 pm Reply with quote

Congrats!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©