ID:274919
 
Just thought I'd share this with everyone. This is a copy of the scripts I'm using on my page for Scream of the Stickster, and eventually for an Incursion page, that will show if any games are online and send the visitor a .dms file to join if they click on it.


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>";
}
?>
wow that could come in handy for loadsa stuff
Yay
Maz
Very Cool, LummuxJR! This is what I've been looking for to show status of games on my hosting server! Good work!
when ever i create anything with php, i get this page on my site http://www.scooberthosting.com/test1.php Can you tell my why?
In response to Scoobert
The PHP that comes with OmniHTTPd doesn't work too well, go to http://www.php.net, and download the windows binaries. Then when that's done read install.txt.
In response to Nadrew
i did, thats the odd thing.
In response to Nadrew
ill try reinstalling it, should i do manual?
In response to Scoobert
Did you edit php.ini right? You need to turn off cgi.force_redirect and set up all the directories.
In response to Nadrew
is that in the omnihttpd php dir or the php dir, because i dont see it in the php dir
[edit]
never mind i see that you are supposta rename it.
In response to Nadrew
ok nad, i tryed it all and something confusses me, this right here,
Step 1: Install OmniHTTPd server.
Step 2: Right click on the blue OmniHTTPd icon in the system
tray and select 'Properties'
Step 3: Click on 'Web Server Global Settings'
Step 4: On the 'External' tab, enter:
virtual = .php | actual = c:\php\sapi\php.exe
and use the Add button.
Step 5: On the Mime tab, enter:
virtual = wwwserver/stdcgi | actual = .php
and use the Add button.
Step 6: Click 'OK'

there is no php.exe in /sapi/, so why would i want to redirect it there?
In response to Scoobert
You need to direct it to where you installed PHP (they changed the directory right before the release, find php.exe and direct it there), as for the rest that's only part of it, install.txt also contains instructions on editing php.ini.
In response to Nadrew
i followed it by the install.txt file just how it asked, and it still aint working, is the php.ini supposta be in my php file or my windows file, that stuff is confusing. I am slighly dislexic so its hard for me to fully understand some stuff.
In response to Nadrew
ahh ha, i got it!!!! YAY!!!!!!!!!
i tryed this, and i seem to get this page to show up:
Warning: file("http://www.byond.com/hub/ hub.cgi?qd=hub;hub=Scoobert.DaysofPast ;format=text;content=|worlds|users|") - No error in C:\httpd\HTDOCS\test1.php on line 3

Warning: Variable passed to each() is not an array or object in C:\httpd\HTDOCS\test1.php on line 6
In response to Scoobert
Scoobert wrote:
i tryed this, and i seem to get this page to show up:
Warning: file("http://www.byond.com/hub/ hub.cgi?qd=hub;hub=Scoobert.DaysofPast ;format=text;content=|worlds|users|") - No error in C:\httpd\HTDOCS\test1.php on line 3

Warning: Variable passed to each() is not an array or object in C:\httpd\HTDOCS\test1.php on line 6

You have a line break in your URL; did you put that in on the forum or is it in your code? That needs to be one solid line.
I recommend leaving it my way and putting in the $game substitution, just redefining $game to your world.hub value.

Lummox JR
In response to Lummox JR
i did it your way.
[edit]
ok i see in the $game="..." i added a space to the end so it was like $game="... "
In response to Lummox JR
I got it working and that is sweet. And useful.
In response to Scoobert
Neat, eh, Scoobert? A quite useful tool, LummoxJR! Thanks!
sorry to be a pain but, is there any way to show how meany games are being hosted?
In response to Andy017
Woah, three-year bump! Eek.

As to your question... display the value of count($worlds)
Page: 1 2