2024-12-11 22:05:45 -06:00
< ? php
2017-02-05 10:49:37 -06:00
2024-12-11 22:05:45 -06:00
// index.php :: Primary program script, evil alien overlord, you decide.
if ( ! file_exists ( '../.installed' )) {
header ( 'Location: install.php' );
exit ;
}
require_once '../src/lib.php' ;
$controlrow = get_control_row ();
2017-02-05 10:49:37 -06:00
2017-02-05 10:58:20 -06:00
// Login (or verify) if not logged in.
2024-12-11 22:05:45 -06:00
if (( $userrow = checkcookies ()) === false ) {
if ( isset ( $_GET [ 'do' ]) && $_GET [ 'do' ] === 'verify' ) {
header ( " Location: users.php?do=verify " );
exit ;
2017-02-05 10:58:20 -06:00
}
2024-12-11 22:05:45 -06:00
header ( " Location: login.php?do=login " );
exit ;
2017-02-05 10:58:20 -06:00
}
2024-12-11 22:05:45 -06:00
2017-02-05 10:58:20 -06:00
// Close game.
2024-12-11 22:05:45 -06:00
if (( bool ) $controlrow [ " gameopen " ] === false ) {
display ( " The game is currently closed for maintanence. Please check back later. " , " Game Closed " );
exit ;
}
2017-02-05 10:58:20 -06:00
// Force verify if the user isn't verified yet.
2024-12-11 22:05:45 -06:00
if (( bool ) $controlrow [ " verifyemail " ] && ( bool ) $userrow [ " verify " ] === false ) {
header ( " Location: users.php?do=verify " );
exit ;
}
2017-02-05 10:58:20 -06:00
// Block user if he/she has been banned.
2024-12-11 22:05:45 -06:00
if ( $userrow [ " authlevel " ] === 2 ) {
exit ( " Your account has been blocked. " );
}
require_once '../src/towns.php' ;
require_once '../src/explore.php' ;
require_once '../src/fight.php' ;
require_once '../src/heal.php' ;
$do = explode ( ':' , $_GET [ 'do' ] ? ? '' );
match ( $do [ 0 ]) {
'inn' => inn (),
'buy' => buy (),
'buy2' => buy2 ( $do [ 1 ]),
'buy3' => buy3 ( $do [ 1 ]),
// 'sell' => sell(),
'maps' => maps (),
'maps2' => maps2 ( $do [ 1 ]),
'maps3' => maps3 ( $do [ 1 ]),
'gotown' => travelto ( $do [ 1 ]),
'move' => move (),
'fight' => fight (),
'victory' => victory (),
'drop' => drop (),
'dead' => dead (),
'verify' => header ( " Location: users.php?do=verify " ),
'spell' => healspells ( $do [ 1 ]),
'showchar' => showchar (),
'onlinechar' => onlinechar ( $do [ 1 ]),
'showmap' => showmap (),
'babblebox' => babblebox (),
'ninja' => ninja (),
default => donothing ()
};
function donothing ()
{
2017-02-05 10:49:37 -06:00
global $userrow ;
if ( $userrow [ " currentaction " ] == " In Town " ) {
$page = dotown ();
$title = " In Town " ;
} elseif ( $userrow [ " currentaction " ] == " Exploring " ) {
$page = doexplore ();
$title = " Exploring " ;
} elseif ( $userrow [ " currentaction " ] == " Fighting " ) {
$page = dofight ();
$title = " Fighting " ;
}
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
display ( $page , $title );
}
2024-12-11 22:05:45 -06:00
/**
* Spit out the main town page .
*/
function dotown ()
{
global $userrow , $controlrow ;
$townquery = db () -> query ( 'SELECT * FROM towns WHERE latitude = ? AND longitude = ? LIMIT 1;' , [ $userrow [ " latitude " ], $userrow [ " longitude " ]]);
if ( $townquery === false ) display ( " There is an error with your user account, or with the town data. Please try again. " , " Error " );
$townrow = $townquery -> fetchArray ( SQLITE3_ASSOC );
if ( $townrow === false ) display ( " There is an error with your user account, or with the town data. Please try again. " , " Error " );
2017-02-05 10:49:37 -06:00
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
2024-12-11 22:05:45 -06:00
if ( $controlrow [ " shownews " ] == 1 ) {
$newsrow = db () -> query ( 'SELECT * FROM news ORDER BY id DESC LIMIT 1;' ) -> fetchArray ( SQLITE3_ASSOC );
2017-02-05 10:58:20 -06:00
$townrow [ " news " ] = " <table width= \" 95% \" ><tr><td class= \" title \" >Latest News</td></tr><tr><td> \n " ;
$townrow [ " news " ] .= " <span class= \" light \" >[ " . prettydate ( $newsrow [ " postdate " ]) . " ]</span><br /> " . nl2br ( $newsrow [ " content " ]);
$townrow [ " news " ] .= " </td></tr></table> \n " ;
2024-12-11 22:05:45 -06:00
} else {
$townrow [ " news " ] = " " ;
}
2017-02-05 10:49:37 -06:00
// Who's Online. Currently just members. Guests maybe later.
2017-02-05 10:58:20 -06:00
if ( $controlrow [ " showonline " ] == 1 ) {
2024-12-11 22:05:45 -06:00
$onlinequery = db () -> query ( " SELECT * FROM news WHERE strftime('%s', onlinetime) >= strftime('%s', 'now') - 600 ORDER BY charname " );
$online_count = 0 ;
$online_rows = [];
foreach ( $onlinequery -> fetchArray ( SQLITE3_ASSOC ) as $onlinerow ) {
$online_count ++ ;
$online_rows [] = " <a href= \" index.php?do=onlinechar: " . $onlinerow [ " id " ] . " \" > " . $onlinerow [ " charname " ] . " </a> " . " , " ;
}
2017-02-05 10:58:20 -06:00
$townrow [ " whosonline " ] = " <table width= \" 95% \" ><tr><td class= \" title \" >Who's Online</td></tr><tr><td> \n " ;
2024-12-11 22:05:45 -06:00
$townrow [ " whosonline " ] .= " There are <b> $online_count </b> user(s) online within the last 10 minutes: " ;
$townrow [ " whosonline " ] .= rtrim ( implode ( ', ' , $online_rows ), ', ' );
2017-02-05 10:58:20 -06:00
$townrow [ " whosonline " ] .= " </td></tr></table> \n " ;
2024-12-11 22:05:45 -06:00
} else {
$townrow [ " whosonline " ] = " " ;
}
2017-02-05 10:58:20 -06:00
if ( $controlrow [ " showbabble " ] == 1 ) {
$townrow [ " babblebox " ] = " <table width= \" 95% \" ><tr><td class= \" title \" >Babble Box</td></tr><tr><td> \n " ;
$townrow [ " babblebox " ] .= " <iframe src= \" index.php?do=babblebox \" name= \" sbox \" width= \" 100% \" height= \" 250 \" frameborder= \" 0 \" id= \" bbox \" >Your browser does not support inline frames! The Babble Box will not be available until you upgrade to a newer <a href= \" http://www.mozilla.org \" target= \" _new \" >browser</a>.</iframe> " ;
$townrow [ " babblebox " ] .= " </td></tr></table> \n " ;
2024-12-11 22:05:45 -06:00
} else {
$townrow [ " babblebox " ] = " " ;
}
2017-02-05 10:49:37 -06:00
$page = gettemplate ( " towns " );
$page = parsetemplate ( $page , $townrow );
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
return $page ;
}
2024-12-11 22:05:45 -06:00
/**
* Just spit out a blank exploring page . Exploring without a GET string is normally when they first log in , or when
* they ' ve just finished fighting .
*/
function doexplore ()
{
return <<< HTML
< table width = " 100% " >
< tr >< td class = " title " >< img src = " images/title_exploring.gif " alt = " Exploring " /></ td ></ tr >
< tr >< td >
You are exploring the map , and nothing has happened . Continue exploring using the direction buttons or the Travel To menus .
</ td ></ tr >
</ table >
HTML ;
2017-02-05 10:49:37 -06:00
}
2024-12-11 22:05:45 -06:00
/**
* Redirect to fighting .
*/
function dofight ()
{
2017-02-05 10:49:37 -06:00
header ( " Location: index.php?do=fight " );
}
2024-12-11 22:05:45 -06:00
function showchar ()
{
2017-02-05 10:49:37 -06:00
global $userrow , $controlrow ;
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
// Format various userrow stuffs.
$userrow [ " experience " ] = number_format ( $userrow [ " experience " ]);
$userrow [ " gold " ] = number_format ( $userrow [ " gold " ]);
2024-12-11 22:05:45 -06:00
if ( $userrow [ " expbonus " ] > 0 ) {
$userrow [ " plusexp " ] = " <span class= \" light \" >(+ " . $userrow [ " expbonus " ] . " %)</span> " ;
2017-02-05 10:49:37 -06:00
} elseif ( $userrow [ " expbonus " ] < 0 ) {
$userrow [ " plusexp " ] = " <span class= \" light \" >( " . $userrow [ " expbonus " ] . " %)</span> " ;
} else { $userrow [ " plusexp " ] = " " ; }
2024-12-11 22:05:45 -06:00
if ( $userrow [ " goldbonus " ] > 0 ) {
$userrow [ " plusgold " ] = " <span class= \" light \" >(+ " . $userrow [ " goldbonus " ] . " %)</span> " ;
} elseif ( $userrow [ " goldbonus " ] < 0 ) {
2017-02-05 10:49:37 -06:00
$userrow [ " plusgold " ] = " <span class= \" light \" >( " . $userrow [ " goldbonus " ] . " %)</span> " ;
} else { $userrow [ " plusgold " ] = " " ; }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
$levelquery = doquery ( " SELECT " . $userrow [ " charclass " ] . " _exp FROM { { table}} WHERE id=' " . ( $userrow [ " level " ] + 1 ) . " ' LIMIT 1 " , " levels " );
$levelrow = mysql_fetch_array ( $levelquery );
2017-02-05 10:57:01 -06:00
if ( $userrow [ " level " ] < 99 ) { $userrow [ " nextlevel " ] = number_format ( $levelrow [ $userrow [ " charclass " ] . " _exp " ]); } else { $userrow [ " nextlevel " ] = " <span class= \" light \" >None</span> " ; }
2017-02-05 10:49:37 -06:00
if ( $userrow [ " charclass " ] == 1 ) { $userrow [ " charclass " ] = $controlrow [ " class1name " ]; }
elseif ( $userrow [ " charclass " ] == 2 ) { $userrow [ " charclass " ] = $controlrow [ " class2name " ]; }
elseif ( $userrow [ " charclass " ] == 3 ) { $userrow [ " charclass " ] = $controlrow [ " class3name " ]; }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " difficulty " ] == 1 ) { $userrow [ " difficulty " ] = $controlrow [ " diff1name " ]; }
elseif ( $userrow [ " difficulty " ] == 2 ) { $userrow [ " difficulty " ] = $controlrow [ " diff2name " ]; }
elseif ( $userrow [ " difficulty " ] == 3 ) { $userrow [ " difficulty " ] = $controlrow [ " diff3name " ]; }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
$spellquery = doquery ( " SELECT id,name FROM { { table}} " , " spells " );
$userspells = explode ( " , " , $userrow [ " spells " ]);
$userrow [ " magiclist " ] = " " ;
while ( $spellrow = mysql_fetch_array ( $spellquery )) {
2017-02-05 10:58:20 -06:00
$spell = false ;
foreach ( $userspells as $a => $b ) {
if ( $b == $spellrow [ " id " ]) { $spell = true ; }
}
if ( $spell == true ) {
$userrow [ " magiclist " ] .= $spellrow [ " name " ] . " <br /> " ;
2017-02-05 10:49:37 -06:00
}
}
if ( $userrow [ " magiclist " ] == " " ) { $userrow [ " magiclist " ] = " None " ; }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
// Make page tags for XHTML validation.
$xml = " <?xml version= \" 1.0 \" encoding= \" ISO-8859-1 \" ?> \n "
. " <!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" DTD/xhtml1-transitional.dtd \" > \n "
. " <html xmlns= \" http://www.w3.org/1999/xhtml \" xml:lang= \" en \" lang= \" en \" > \n " ;
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
$charsheet = gettemplate ( " showchar " );
$page = $xml . gettemplate ( " minimal " );
$array = array ( " content " => parsetemplate ( $charsheet , $userrow ), " title " => " Character Information " );
echo parsetemplate ( $page , $array );
die ();
}
function onlinechar ( $id ) {
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
global $controlrow ;
$userquery = doquery ( " SELECT * FROM { { table}} WHERE id=' $id ' LIMIT 1 " , " users " );
if ( mysql_num_rows ( $userquery ) == 1 ) { $userrow = mysql_fetch_array ( $userquery ); } else { display ( " No such user. " , " Error " ); }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
// Format various userrow stuffs.
$userrow [ " experience " ] = number_format ( $userrow [ " experience " ]);
$userrow [ " gold " ] = number_format ( $userrow [ " gold " ]);
2024-12-11 22:05:45 -06:00
if ( $userrow [ " expbonus " ] > 0 ) {
$userrow [ " plusexp " ] = " <span class= \" light \" >(+ " . $userrow [ " expbonus " ] . " %)</span> " ;
2017-02-05 10:49:37 -06:00
} elseif ( $userrow [ " expbonus " ] < 0 ) {
$userrow [ " plusexp " ] = " <span class= \" light \" >( " . $userrow [ " expbonus " ] . " %)</span> " ;
} else { $userrow [ " plusexp " ] = " " ; }
2024-12-11 22:05:45 -06:00
if ( $userrow [ " goldbonus " ] > 0 ) {
$userrow [ " plusgold " ] = " <span class= \" light \" >(+ " . $userrow [ " goldbonus " ] . " %)</span> " ;
} elseif ( $userrow [ " goldbonus " ] < 0 ) {
2017-02-05 10:49:37 -06:00
$userrow [ " plusgold " ] = " <span class= \" light \" >( " . $userrow [ " goldbonus " ] . " %)</span> " ;
} else { $userrow [ " plusgold " ] = " " ; }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
$levelquery = doquery ( " SELECT " . $userrow [ " charclass " ] . " _exp FROM { { table}} WHERE id=' " . ( $userrow [ " level " ] + 1 ) . " ' LIMIT 1 " , " levels " );
$levelrow = mysql_fetch_array ( $levelquery );
$userrow [ " nextlevel " ] = number_format ( $levelrow [ $userrow [ " charclass " ] . " _exp " ]);
if ( $userrow [ " charclass " ] == 1 ) { $userrow [ " charclass " ] = $controlrow [ " class1name " ]; }
elseif ( $userrow [ " charclass " ] == 2 ) { $userrow [ " charclass " ] = $controlrow [ " class2name " ]; }
elseif ( $userrow [ " charclass " ] == 3 ) { $userrow [ " charclass " ] = $controlrow [ " class3name " ]; }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " difficulty " ] == 1 ) { $userrow [ " difficulty " ] = $controlrow [ " diff1name " ]; }
elseif ( $userrow [ " difficulty " ] == 2 ) { $userrow [ " difficulty " ] = $controlrow [ " diff2name " ]; }
elseif ( $userrow [ " difficulty " ] == 3 ) { $userrow [ " difficulty " ] = $controlrow [ " diff3name " ]; }
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
$charsheet = gettemplate ( " onlinechar " );
$page = parsetemplate ( $charsheet , $userrow );
display ( $page , " Character Information " );
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
}
function showmap () {
2024-12-11 22:05:45 -06:00
global $userrow ;
2017-02-05 10:49:37 -06:00
// Make page tags for XHTML validation.
$xml = " <?xml version= \" 1.0 \" encoding= \" ISO-8859-1 \" ?> \n "
. " <!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" DTD/xhtml1-transitional.dtd \" > \n "
. " <html xmlns= \" http://www.w3.org/1999/xhtml \" xml:lang= \" en \" lang= \" en \" > \n " ;
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
$page = $xml . gettemplate ( " minimal " );
2017-02-05 10:51:23 -06:00
$array = array ( " content " => " <center><img src= \" images/map.gif \" alt= \" Map \" /></center> " , " title " => " Map " );
2017-02-05 10:49:37 -06:00
echo parsetemplate ( $page , $array );
die ();
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
}
function babblebox () {
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
global $userrow ;
2024-12-11 22:05:45 -06:00
2017-02-05 11:09:00 -06:00
if ( isset ( $_POST [ " babble " ])) {
2017-02-05 11:03:19 -06:00
$safecontent = makesafe ( $_POST [ " babble " ]);
2017-02-05 10:49:37 -06:00
if ( $safecontent == " " || $safecontent == " " ) { //blank post. do nothing.
} else { $insert = doquery ( " INSERT INTO { { table}} SET id='',posttime=NOW(),author=' " . $userrow [ " charname " ] . " ',babble=' $safecontent ' " , " babble " ); }
header ( " Location: index.php?do=babblebox " );
die ();
}
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
$babblebox = array ( " content " => " " );
$bg = 1 ;
2017-02-05 10:57:01 -06:00
$babblequery = doquery ( " SELECT * FROM { { table}} ORDER BY id DESC LIMIT 20 " , " babble " );
2017-02-05 10:49:37 -06:00
while ( $babblerow = mysql_fetch_array ( $babblequery )) {
2017-02-05 10:57:01 -06:00
if ( $bg == 1 ) { $new = " <div style= \" width:98%; background-color:#eeeeee; \" >[<b> " . $babblerow [ " author " ] . " </b>] " . $babblerow [ " babble " ] . " </div> \n " ; $bg = 2 ; }
2024-12-11 22:05:45 -06:00
else { $new = " <div style= \" width:98%; background-color:#ffffff; \" >[<b> " . $babblerow [ " author " ] . " </b>] " . stripslashes ( $babblerow [ " babble " ]) . " </div> \n " ; $bg = 1 ; }
2017-02-05 10:57:01 -06:00
$babblebox [ " content " ] = $new . $babblebox [ " content " ];
2017-02-05 10:49:37 -06:00
}
$babblebox [ " content " ] .= " <center><form action= \" index.php?do=babblebox \" method= \" post \" ><input type= \" text \" name= \" babble \" size= \" 15 \" maxlength= \" 120 \" /><br /><input type= \" submit \" name= \" submit \" value= \" Babble \" /> <input type= \" reset \" name= \" reset \" value= \" Clear \" /></form></center> " ;
2024-12-11 22:05:45 -06:00
2017-02-05 10:49:37 -06:00
// Make page tags for XHTML validation.
$xml = " <?xml version= \" 1.0 \" encoding= \" ISO-8859-1 \" ?> \n "
. " <!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" DTD/xhtml1-transitional.dtd \" > \n "
. " <html xmlns= \" http://www.w3.org/1999/xhtml \" xml:lang= \" en \" lang= \" en \" > \n " ;
$page = $xml . gettemplate ( " babblebox " );
echo parsetemplate ( $page , $babblebox );
die ();
}
2024-12-11 22:05:45 -06:00
/**
* NINJA ! 🥷
*/
function ninja () : void
{
exit ( 'NINJA! 🥷' );
2017-02-05 10:49:37 -06:00
}