PDA

View Full Version : MiniGIP


Sonyk
Mar 17, 2005, 02:53 AM
Out of curiousity, would we be allowed to use the MiniGIP script that's on the front page of J2O? I've noticed it's not available anywhere on the website, and I wouldn't want to take it without permission.

Link
Mar 17, 2005, 07:17 PM
If you want to use it on your site, that's fine, as long as you give credit to J2O. Internet Explorer displays it slightly incorrectly (gives it a border and does not transfer cell background colour). You could also use the image mini-GIP that seems to work now and appears correctly in all browsers.

Exempli gratia:

http://www.jazz2online.com/J2Ov2/panels/gip_stuff/gip_mini.php?bgc1=D0D0FE&bgc2=C2C2ED

Sonyk
Mar 18, 2005, 03:06 AM
Yes, I'm aware of the problem with embedded pages in IE, but my site looks better in Firebox regardless, so I urge users to view it in that. And that image version looks rather spiffy, if I do say so myself.
Also, would you prefer I have the script myself, instead of linking to the one on J2O?I would assume so...

blurredd
Mar 18, 2005, 09:30 AM
I don't think it would hurt to use .gif images instead of .png, but then again, I don't know what it would look like with the change.

Link
Mar 18, 2005, 10:29 AM
Here's the script for the one currently used on J2O. If you want to display the MOTD from the list server, uncomment the relevant portions, but this may be impractical as the MOTD is sometimes quite big. You'll also need to make a script to create a .j2i file (or link to the one on J2O) if you want to be able to join games from this. And finally you'll need to get the images (or create your own) and change the script to output the correct locations. They are in http://www.jazz2online.com/J2Ov2/panels/gip_stuff/.

If you link to the script with textColor, linkColor, and hoverColor in the query string (without a '#' preceding), they will be used instead of the default colours.

The preg_match function should all be on one line, with a single space between (.*?) and the final (.*).

If you want to completely customize the script, you can just take the portion up to (but not including) where it says "echo <<<END". At this point, all the server information is in the array $valid_servers, and you can loop through and display it how you want.


<?php

/* Mini Games in Progress Script for Jazz Jackrabbit 2
Copyright (c) 2004 Jazz2Online (http://www.jazz2online.com)

You are free to use and modify this script, but you must
keep the above copyright notice in place.
*/

$servers[0] = 'uk.jazzjackrabbit.net';
//$servers[1] = 'us.jazzjackrabbit.net';

if (!$textColor) $textColor = "000000";
if (!$linkColor) $linkColor = "000000";
if (!$hoverColor) $hoverColor = "B62700";

$num = 0;

WHILE ($servers[$num]) {
$sLink = @fsockopen($servers[$num], 10057, &$errorNum, &$errorString, 3);
if (!$sLink) {
$svrDown[$num] = $errorNum . ': ' . $errorString;
$svrError = TRUE;
} else {
$sRawData = "";
WHILE (!feof($sLink)) {
$sRawData .= fgets($sLink,1024);
}
fclose($sLink);
$svrError = FALSE;

// Get MOTD
/*$mLink = @fsockopen($servers[$num], 10058);
if ($mLink) {
while (!feof($mLink)) $motd .= fgets($mLink,256);
$servername = $servers[$num];
}*/

break;
}
$num++;
}


$sData = explode("\n",$sRawData);

FOR ($num = 0; $num < count($sData) - 1; $num++) {

// $server 1 2 3 4 5 6 7 8 9
preg_match('/(.*):(\d*) (local|mirror) (private|public) (.*) (1\..{0,4}) (\d*) (.*?) (.*)/',$sData[$num],$server);

$valid_servers[$num]['ip'] = $server[1];
$valid_servers[$num]['port'] = $server[2];
$valid_servers[$num]['list'] = $server[3];
$valid_servers[$num]['access'] = $server[4];
$valid_servers[$num]['type'] = $server[5];
$valid_servers[$num]['version'] = $server[6];
$valid_servers[$num]['uptime'] = $server[7];
$valid_servers[$num]['capacity'] = $server[8];
$valid_servers[$num]['name'] = str_replace('|','',trim($server[9]));

}

echo <<<END

<html>
<head>
<title>Games in Progress</title>
<style type="text/css">
ul { margin: 0; padding: 0; }
li { list-style-type: none; padding-left: 0; line-height: 1; }
span { font-family: Arial; }
.s { font-size: 11px; font-weight: bold; }
.i { font-size: 9px; color: #$textColor; }
.m { font-size: 10px; font-style: italic; }
body { margin: 4px; }
a { text-decoration: none; color: #$linkColor; }
a:hover { color: #$hoverColor; }
img { border: 0; }
</style>
</head>

<body>
<ul>

END;

if ($svrError == TRUE) {
echo "<li><span>Error connecting to list servers. Errors listed below.</span></li>";
foreach ($svrDown as $errorText) echo "<li><span>$errorText</span></li>";
} elseif ($num == 0) {
echo "<li><span>No servers currently listed.</span></li>";
} else {

foreach ($valid_servers as $Server) {
echo "<li>";
switch ($Server[type]) {
case 'battle':
$img = "gip_battle.png";
break;
case 'capture':
$img = "gip_ctf.png";
break;
case 'treasure':
$img = "gip_treasure.png";
break;
default:
$img = "gip_question.png";
}

$encodedIP = base64_encode($Server[ip].":".$Server[port]);

if ($Server[access] != "private") echo "<a href=\"gip_stuff/join.php?ip=$encodedIP\">";

echo "<img src=\"gip_stuff/$img\" />&nbsp;";

if ($Server[access] == "private") $Server[name] .= " (P)";

echo "<span class=\"s\">$Server[name]</span>";

if ($Server[access] != "private") echo "</a>";

echo "<br />";

$uptime = round($Server[uptime] / 60);

echo "<span class=\"i\">&nbsp;$Server[version] :: $Server[capacity] :: ".$uptime."min</span>";

echo "</li>";
}

/* if ($motd) {
echo "<li><br /></li>";
echo "<li><span class=\"m\" title=\"Message of the Day at $servername\">";
echo nl2br($motd);
echo "</span></li>";
} */

echo "</ul>";
echo "</body>";
echo "</html>";

}

?>

Sonyk
Mar 18, 2005, 02:46 PM
Ah, thank you. But, according to what you said, I am allowed to link to the ones on J2O?
Either way, it's nice to have the source, so I can change it if I ever find the need to.

Sonyk
Mar 19, 2005, 04:43 PM
Um... Just a question... I can tell the miniGIP times out a lot, but that's due to the PHP.ini's setting for maximum script execution, right?

Anyway, I've got it on my website, and it fit nicely. Thank you.