<?php
/*
+---------------------------------------------------------------+
| e107 website system
|
| ©Steve Dunstan 2001-2002
| http://e107.org
| hide@address.com
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
+---------------------------------------------------------------+
*/
$TeamMembers = array($pref['Liveforspeed_player1'],$pref['Liveforspeed_player2'],$pref['Liveforspeed_player3'],$pref['Liveforspeed_player4'],$pref['Liveforspeed_player5']);
$TeamMembers2 = $pref['Liveforspeed_no'];
$InGameName = array($pref['Liveforspeed_player1_name'],$pref['Liveforspeed_player2_name'],$pref['Liveforspeed_player3_name'],$pref['Liveforspeed_player4_name'],$pref['Liveforspeed_player5_name']);
//**********************************
// function to safely trim null-terminated strings
// could just use trim () in this example though
function trim_c_string ($string) {
$new = "";
$len = strlen ($string);
for ($x=0; $x<$len; $x++) {
if ($string[$x] != "\0") $new .= $string[$x];
else break;
}
return $new;
}
// Function to remove the colour code data from a string
function remove_colour_codes($String){
$ColCodes = array("^0","^1","^2","^3","^4","^5","^6","^7","^8","^9");
$NewString = str_replace($ColCodes, "",$String);
return $NewString;
}
// Function used by format_host_colours function to display correct colour value in html format
function get_colour($ColourNum){
switch ($ColourNum) {
case "0";
$ColourName = "#000000"; //Black
break;
case "1";
$ColourName = "#FF0000"; //Red
break;
case "2";
$ColourName = "#00FF00"; //Pastel Green
break;
case "3";
$ColourName = "#FFFF00"; //Yellow
break;
case "4";
$ColourName = "#0000FF"; //Light Blue
break;
case "5";
$ColourName = "#FF0080"; //Light Purple
break;
case "6";
$ColourName = "#00FFFF"; //Turquoise
break;
case "7";
// Remove comment marks on next line if not a white background
//$ColourName = "#FFFFFF"; //White
// Add Comment marks to next line if not a white background
$ColourName = "#808080"; //Dark Grey
break;
case "8";
$ColourName = "#00FF00"; //Pastel Green
break;
}
return $ColourName;
}
// Function to replace the ^x codes in the Host name to show correct colours on the screen
function format_host_colours($HostName){
for($i = 0; $i < strlen($HostName); $i++){
if(substr($HostName, $i, 1) == "^"){
$CharPos = strpos($HostName, "^", $i);
$ColNum = substr($HostName, strpos($HostName, "^", $i) + 1,1);
$ColourString = get_colour(substr($HostName, strpos($HostName, "^", $i) + 1,1));
if($i == "0"){
// If ^ found at the start of the host string remove the ^[num]
$TmpString = substr($HostName,$i+2);
// Add the html font code to the start of the string and append the
// variable $TmpString with the ^[num] removed
$HostName = "<font color='$ColourString'>".$TmpString;
}
else{
// Get the left part of the string to the next ^[num]
$LTmpString = substr($HostName,0,$i);
// Get the right part of the string after the ^[num]
$RTmpString = substr($HostName,$i+2);
// Add the html close font and add the new html colour to the end of the
// Left part of the string then add the right part of the string
$HostName = $LTmpString."</font><font color='$ColourString'>".$RTmpString;
}
}
}
// Close any html font tag left open in the above
$HostName = $HostName."</font>";
Return $HostName;
}
function display_fixed_table($TeamMembers, $LfsUsers, $InGameName, $TeamMembers2){
$TotalMembers = $TeamMembers2;
echo "<tr bgcolor='#CCCCCC' align='center'><th>Team Racer</th><th>Status</th></tr>";
for($i = 0; $i < $TotalMembers; $i++){
echo "<tr>";
foreach ($LfsUsers as $LfsUser => $LfsHost) {
if(strtolower($LfsUser) == $TeamMembers[$i]){
$LfsHost = format_host_colours($LfsHost);
echo "<td><font color='#FFFFFF'>$InGameName[$i]</font></td>";
echo"<td><font color='#FFFFFF'>Online on server - $LfsHost</font></td></tr>";
$Found = "True";
break;
}
else{
$Found = "False";
}
}
if($Found == "False"){
echo "<td><font color='#FFFFFF'>$InGameName[$i]</font></td>";
echo "<td><font color='#FFFFFF'>Offline</font></td>";
echo"<td> </td></tr>";
}
}
}
$LfsUsers = array ();
$x = 0;
$LfsHostList = "";
// get the hostlist
$LfsHostList = file_get_contents ("http://www.lfsworld.net/pubstat/get_stat2.php?version=1.2&action=hosts");
$len = strlen ($LfsHostList);
// Thanks to Tristiancliffe for this line. It is a refresh link
if ($len < 52) exit ("<a href='javascript:document.location.reload();'>Couldn't get hostlist. Click to retry...</a>");
// parse the data
while ($x < $len) {
$LfsHostName = "";
$nr_racers = 0;
for ($y=0; $y<32; $y++) $LfsHostName .= $LfsHostList[$x++];
$LfsHostName = trim_c_string ($LfsHostName);
$x += 20; // skip some host-data
$nr_racers = ord ($LfsHostList[$x++]);
for ($w=0; $w<$nr_racers; $w++) {
$LfsUserName = "";
for ($y=0; $y<24; $y++) $LfsUserName .= $LfsHostList[$x++];
$LfsUsers[trim_c_string ($LfsUserName)] = $LfsHostName;
}
}
?>