world.php (Generates a .dms file)
<?php
$query=$HTTP_SERVER_VARS["QUERY_STRING"];
if($query) {
$query=urldecode($query);
preg_match("/(\d+)$/",$query,$match);
$world=$match[1];
header("Content-type: text/vmd.dmclientscript");
header("Content-Disposition: attachment; filename=url$world.dms");
echo "/*\nThis game requires the BYOND engine to run.\n\n";
echo "This is a DM Script file. You need to install BYOND (for free!)\n";
echo "and possibly configure your browser to open this file with\n";
echo "Dream Seeker. For more information, go to: http://www.byond.com/script.\n";
echo "*/\n";
echo "#define URL \"$query\"\n";
echo "#include <byond.dms>\n";
exit;
}
$refer=header("Location: ".$HTTP_SERVER_VARS["HTTP_REFERER"]);
if($refer) header("Location: $refer");
else {
$path='http://'.$HTTP_SERVER_VARS['HTTP_HOST'].dirname($HTTP_SERVER_VARS['PHP_SELF']).'/';
header("Location: $path");
}
exit;
?>
And insert this into a .php page on your site:
<?php
$game="MyName.MyGame"; // this should match your world.hub setting
$fcontents=file("http://www.byond.com/hub/hub.cgi?qd=hub;hub=$game;format=text;content=|worlds|users|");
$worlds=array();
$whichworld=null;
while(list($n,$line)=each($fcontents)) {
if(preg_match("/worlds\/(\d+)/",$line,$n)) {$whichworld=$n[0]; $worlds[$whichworld]=array(); continue;}
if(preg_match("/^\s*url\s*=\s*\"(.+)\"/",$line,$n)) {$worlds[$whichworld]['url']=$n[1]; continue;}
if(preg_match("/^\s*status\s*=\s*\"(.+)\"/",$line,$n)) {$worlds[$whichworld]['status']=$n[1]; continue;}
if(preg_match("/^\s*users\s*=\s*list\((.*)\)/",$line,$n)) {
$names=preg_split("/\s*,\s*/",$n[1]);
while (list($n,$name) = each ($names)) {
preg_match("/\"(.*)\"/",$name,$unquote);
$names[$n]=stripslashes($unquote[1]);
}
$worlds[$whichworld]["users"]=$names;
}
}
if(count($worlds)) {
echo "<DIV STYLE=\"text-indent: 0\"><center><TABLE STYLE=\"border:0;margin:5px\"><TR>";
echo "<TD STYLE=\"padding-right:20px\"><H2>Games Online</h2></td>";
echo "<TD STYLE=\"padding:0\">";
while(list($n,$lst)=each($worlds)) {
$url='http://www.foo.com/world.php?'.urlencode($lst['url']);
if(!$lst['status']) $lst['status']='(No status info available)';
echo "<A HREF=\"".$url."\">".$lst['status']."</a><BR>";
echo join(" - ",$lst["users"])."<P>\n";
}
echo "</td></tr></table></center></div>";
}
?>
Yay
Maz