function creatureaddon_run()
{
    global $session, $args;
    $op = httpget('op');
    $header = $args['creaturename'] . " Description";
    popup_header($header);
    $description = get_module_objpref("creatures", $args['creatureid'], "description");
    output($description);
    popup_footer();
}
function friends_run()
{
    global $session;
    popup_header("Who's Online");
    //Output online characters list
    $sql = "SELECT name,laston,loggedin FROM " . db_prefix("accounts") . " WHERE locked=0 AND loggedin=1 AND laston>'" . date("Y-m-d H:i:s", strtotime("-" . getsetting("LOGINTIMEOUT", 900) . " seconds")) . "' ORDER BY laston DESC";
    $result = db_query($sql);
    rawoutput("<table>");
    while ($row = db_fetch_assoc($result)) {
        rawoutput("<tr><td>");
        output("%s", $row['name']);
        rawoutput("</td><td>");
        output("%s", $row['laston']);
        rawoutput("</td></tr>");
    }
    rawoutput("</table>");
    popup_footer();
}
<?php

// addnews ready
// translator ready
// mail ready
define("ALLOW_ANONYMOUS", true);
define("OVERRIDE_FORCED_NAV", true);
require_once "common.php";
require_once "lib/systemmail.php";
require_once "lib/output_array.php";
require_once "lib/http.php";
require_once "lib/stripslashes_deep.php";
$op = httpget('op');
switch ($op) {
    case "primer":
    case "faq":
    case "faq1":
    case "faq2":
    case "faq3":
        require "lib/petition/petition_{$op}.php";
        break;
    default:
        require "lib/petition/petition_default.php";
        break;
}
popup_footer();
function letteropener_run()
{
    global $session;
    page_header("Letter opener");
    require_once "common.php";
    require_once "lib/systemmail.php";
    require_once "lib/sanitize.php";
    require_once "lib/http.php";
    $maildb = "mail";
    if (get_module_setting("outbox")) {
        $maildb = "mailoutbox";
    }
    $op = httpget('op');
    $order = "acctid";
    if ($sort != "") {
        $order = "{$sort}";
    }
    $display = 0;
    $query = httppost('q');
    if ($query === false) {
        $query = httpget('q');
    }
    addnav("Back to the grotto", "superuser.php");
    addnav(array("Show last %s YOMs", get_module_setting("num")), "runmodule.php?module=letteropener&op=lastfew");
    if ($op == "read") {
        $id = httpget('id');
        $sql = "SELECT msgfrom,msgto from " . db_prefix($maildb) . " where messageid=\"" . $id . "\"";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        $acctid = $row['msgto'];
        $sqlz = "SELECT login from " . db_prefix("accounts") . " where acctid=\"" . $acctid . "\"";
        $result = db_query($sqlz);
        $rowz = db_fetch_assoc($result);
        $login = $rowz['login'];
        addnav("Read Someone else's mail", "runmodule.php?module=letteropener");
        //addnav("~");
        addnav(array("All YOMs to %s", $login), "runmodule.php?module=letteropener&op=to&to={$login}");
        addnav(array("All YOMs from %s", $login), "runmodule.php?module=letteropener&op=from&from={$login}");
        $sql = "SELECT " . db_prefix($maildb) . ".*," . db_prefix("accounts") . ".name,login FROM " . db_prefix($maildb) . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid=" . db_prefix($maildb) . ".msgfrom WHERE msgto=\"" . $acctid . "\" AND messageid=\"" . $id . "\"";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $row = db_fetch_assoc($result);
            tlschema("mail");
            if ((int) $row['msgfrom'] == 0) {
                $row['name'] = translate_inline("`i`^System`0`i");
                if (is_array(unserialize($row['subject']))) {
                    $row['subject'] = unserialize($row['subject']);
                    $row['subject'] = call_user_func_array("sprintf_translate", $row['subject']);
                }
                if (is_array(unserialize($row['body']))) {
                    $row['body'] = unserialize($row['body']);
                    $row['body'] = call_user_func_array("sprintf_translate", $row['body']);
                }
            }
            tlschema();
            if (!$row['seen']) {
                output("`b`#NEW`b`n");
            } else {
                output("`n");
            }
            if ((int) $row['msgfrom'] != 0) {
                addnav("Or");
                //$othername=$row['msgfrom'];
                //$sql="select login from ".db_prefix("accounts")." where acctid=$othername";
                //$result = db_query($sql);
                $othername = $row['login'];
                addnav(array("All YOMs to %s", $othername), "runmodule.php?module=letteropener&op=to&to={$othername}");
                addnav(array("All YOMs from %s", $othername), "runmodule.php?module=letteropener&op=from&from={$othername}");
            }
            output("`b`2From:`b `^%s`n", $row['name']);
            output("`b`2Subject:`b `^%s`n", $row['subject']);
            output("`b`2Sent:`b `^%s`n", $row['sent']);
            output_notl("<hr>`n", true);
            output_notl(str_replace("\n", "`n", $row['body']));
            output_notl("`n<hr>`n", true);
            rawoutput("<table width='50%' border='0' cellpadding='0' cellspacing='5'><tr>");
            rawoutput("<td align='right'>&nbsp;</td>");
            rawoutput("</tr><tr>");
            $sql = "SELECT messageid FROM " . db_prefix($maildb) . " WHERE msgto='{$acctid}' AND messageid < '{$id}' ORDER BY messageid DESC LIMIT 1";
            $result = db_query($sql);
            if (db_num_rows($result) > 0) {
                $row = db_fetch_assoc($result);
                $pid = $row['messageid'];
            } else {
                $pid = 0;
            }
            $sql = "SELECT messageid FROM " . db_prefix($maildb) . " WHERE msgto='{$acctid}' AND messageid > '{$id}' ORDER BY messageid  LIMIT 1";
            $result = db_query($sql);
            if (db_num_rows($result) > 0) {
                $row = db_fetch_assoc($result);
                $nid = $row['messageid'];
            } else {
                $nid = 0;
            }
            $prev = translate_inline("< Previous");
            $next = translate_inline("Next >");
            rawoutput("<td nowrap='true'>");
            if ($pid > 0) {
                rawoutput("<a href='runmodule.php?module=letteropener&op=read&id={$pid}' class='motd'>" . htmlentities($prev) . "</a>");
                addnav("", "runmodule.php?module=letteropener&op=read&id={$pid}");
            } else {
                rawoutput(htmlentities($prev));
            }
            rawoutput("</td><td nowrap='true'>");
            if ($nid > 0) {
                rawoutput("<a href='runmodule.php?module=letteropener&op=read&id={$nid}' class='motd'>" . htmlentities($next) . "</a>");
                addnav("", "runmodule.php?module=letteropener&op=read&id={$nid}");
            } else {
                rawoutput(htmlentities($next));
            }
            rawoutput("</td>");
            rawoutput("</tr></table>");
        }
    } elseif ($op == "lastfew") {
        output("Here are the last %s non-system YOMs", get_module_setting("num"));
        $sql = "select * from " . db_prefix($maildb) . " where msgfrom>0 ORDER BY messageid DESC limit " . get_module_setting("num") . "";
        $res = db_query($sql);
        $to = translate_inline("To");
        $from = translate_inline("From");
        require_once "lib/sanitize.php";
        for ($i = 0; $i < db_num_rows($res); $i++) {
            $row = db_fetch_assoc($res);
            $sql2 = "select name from " . db_prefix("accounts") . " where acctid=" . $row['msgto'] . "";
            $res2 = db_query($sql2);
            $row2 = db_fetch_assoc($res2);
            $toname = color_sanitize($row2['name']);
            $sql3 = "select name from " . db_prefix("accounts") . " where acctid=" . $row['msgfrom'] . "";
            $res3 = db_query($sql3);
            $row3 = db_fetch_assoc($res3);
            $fromname = color_sanitize($row3['name']);
            rawoutput("<table border=1 width=100%><tr><td>{$from} :{$fromname} - " . date("M d, h:i a", strtotime($row['sent'])) . " - {$to} : {$toname}</td></tr><tr><td>" . $row['body'] . "</td></tr></table><br>");
        }
    } elseif ($op == "") {
        output("Whose mail would you like to read?`n");
        rawoutput("<form action='runmodule.php?module=letteropener' method='POST'>");
        rawoutput("<input name='q' id='q'>");
        $se = translate_inline("Search");
        rawoutput("<input type='submit' class='button' value='{$se}'>");
        rawoutput("</form>");
        rawoutput("<script language='JavaScript'>document.getElementById('q').focus();</script>");
        addnav("", "runmodule.php?module=letteropener");
        $searchresult = false;
        $where = "";
        $op = "";
        $sql = "SELECT acctid,login,name FROM " . db_prefix("accounts");
        if ($query != "") {
            $where = "WHERE login='******' OR name='{$query}'";
            $searchresult = db_query($sql . " {$where}  ORDER BY '{$order}' LIMIT 2");
        }
        if ($query !== false || $searchresult) {
            if (db_num_rows($searchresult) != 1) {
                $where = "WHERE login LIKE '%{$query}%' OR acctid LIKE '%{$query}%' OR name LIKE '%{$query}%' OR emailaddress LIKE '%{$query}%' OR lastip LIKE '%{$query}%' OR uniqueid LIKE '%{$query}%' OR gentimecount LIKE '%{$query}%' OR level LIKE '%{$query}%'";
                $searchresult = db_query($sql . " {$where}  ORDER BY '{$order}' LIMIT 101");
            }
            if (db_num_rows($searchresult) <= 0) {
                output("`\$No results found`0");
                $where = "";
            } elseif (db_num_rows($searchresult) > 100) {
                output("`\$Too many results found, narrow your search please.`0");
                $op = "";
                $where = "";
            } else {
                $op = "";
                $display = 1;
            }
        }
        if ($display == 1) {
            $q = "";
            if ($query) {
                $q = "&q={$query}";
            }
            $acid = translate_inline("AcctID");
            $login = translate_inline("Login");
            $nm = translate_inline("Name");
            $rn = 0;
            $oorder = "";
            while ($row = db_fetch_assoc($searchresult)) {
                $laston = relativedate($row['laston']);
                $loggedin = date("U") - strtotime($row['laston']) < getsetting("LOGINTIMEOUT", 900) && $row['loggedin'];
                if ($loggedin) {
                    $laston = translate_inline("`#Online`0");
                }
                $row['laston'] = $laston;
                if ($row[$order] != $oorder) {
                    $rn++;
                }
                $oorder = $row[$order];
                rawoutput("<table align=center border=1 width=350>");
                rawoutput("<tr class='trhead'><td>{$acid}: ");
                output_notl("`&%s`0", $row['acctid'], true);
                rawoutput("</td><td>{$login}: ");
                output_notl("`&%s`0", $row['login'], true);
                rawoutput("</td>");
                rawoutput("<td rowspan=2 align=left nowrap>");
                addnav("", "runmodule.php?module=letteropener&op=to&to={$row['login']}");
                addnav("", "runmodule.php?module=letteropener&op=from&from={$row['login']}");
                $to = translate_inline("All messages `#to`& this person");
                $from = translate_inline("All messages `#from`& this person");
                output_notl("<a href='runmodule.php?module=letteropener&op=to&to={$row['login']}'>`&&#149;%s`7</a>", $to, true);
                rawoutput("<br>");
                output_notl("<a href='runmodule.php?module=letteropener&op=from&from={$row['login']}'>`&&#149;%s`7</a>", $from, true);
                rawoutput("</td></tr><tr><td colspan=2>");
                output_notl("`&%s`7", $row['name'], true);
                rawoutput("</td></tr></table><Br>");
            }
        }
    } elseif ($op == "to") {
        $subject = "";
        $body = "";
        $row = "";
        addnav("Read someone else's mail", "runmodule.php?module=letteropener");
        $to = httpget('to');
        $from = httpget('from');
        if ($to != "") {
            $sql = "SELECT acctid,login,name superuser FROM " . db_prefix("accounts") . " WHERE login=\"{$to}\"";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE login='******'login'] . "'";
            $result = db_query($sql);
            $row2 = db_fetch_assoc($result);
            $acctid = $row2['acctid'];
            rawoutput("<table>");
            $session['message'] = "";
            $sql = "SELECT subject,messageid," . db_prefix("accounts") . ".name,msgfrom,seen,sent FROM " . db_prefix($maildb) . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid=" . db_prefix($maildb) . ".msgfrom WHERE msgto=\"" . $acctid . "\" ORDER BY sent DESC";
            $result = db_query($sql);
            if (db_num_rows($result) > 0) {
                while ($row = db_fetch_assoc($result)) {
                    tlschema("mail");
                    if ((int) $row['msgfrom'] == 0) {
                        $row['name'] = translate_inline("`i`^System`0`i");
                        if (is_array(unserialize($row['subject']))) {
                            $row['subject'] = unserialize($row['subject']);
                            $row['subject'] = call_user_func_array("sprintf_translate", $row['subject']);
                        }
                    }
                    tlschema();
                    $id = $row['messageid'];
                    output_notl("<tr>", true);
                    output_notl("<td nowrap><img src='images/" . ($row['seen'] ? "old" : "new") . "scroll.GIF' width='16' height='16' alt='" . ($row['seen'] ? "Old" : "New") . "'></td>", true);
                    output_notl("<td><a href='runmodule.php?module=letteropener&op=read&id={$id}&login={$to}'>", true);
                    addnav("", "runmodule.php?module=letteropener&op=read&id={$id}&login={$to}");
                    if (trim($row['subject']) == "") {
                        output("`i(No Subject)`i");
                    } else {
                        output_notl($row['subject']);
                    }
                    output_notl("</a></td><td><a href='runmodule.php?module=letteropener&op=read&id={$id}&login={$to}'>", true);
                    addnav("", "runmodule.php?module=letteropener&op=read&id={$id}&login={$to}");
                    output("- from %s", $row['name']);
                    output_notl("</a></td><td><a href='runmodule.php?module=letteropener&op=read&id={$id}&login={$to}'>" . date("M d, h:i a", strtotime($row['sent'])) . "</a></td>", true);
                    addnav("", "runmodule.php?module=letteropener&op=read&id={$id}&login={$to}");
                    output_notl("</tr>", true);
                }
                //}
            } else {
                output("`iThey have no mail.`i");
            }
        } elseif (db_num_rows($result) == 0) {
            output("`@No one was found who matches \"%s\".  ", stripslashes($to));
            $try = translate_inline("Please try again");
            output_notl("<a href='runmodule.php?module=letteropener'>{$try}</a>.", true);
            popup_footer();
            exit;
        } else {
            output_notl("<select name='to' id='to' onChange='check_su_warning();'>", true);
            $superusers = array();
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                output_notl("<option value=\"" . HTMLEntities($row['login']) . "\">", true);
                output_notl("%s", full_sanitize($row['name']));
                if ($row['superuser'] & SU_GIVES_YOM_WARNING && !($row['superuser'] & SU_OVERRIDE_YOM_WARNING)) {
                    array_push($superusers, $row['login']);
                }
            }
            output_notl("</select>`n", true);
        }
        output_notl("</table>", true);
    } elseif ($op == "from") {
        $subject = "";
        $body = "";
        $row = "";
        addnav("Read someone else's mail", "runmodule.php?module=letteropener");
        $from = httpget('from');
        if ($from != "") {
            $sql = "SELECT acctid,login,name superuser FROM " . db_prefix("accounts") . " WHERE login=\"{$from}\"";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE login='******'login'] . "'";
            $result = db_query($sql);
            $row2 = db_fetch_assoc($result);
            $acctid = $row2['acctid'];
            output_notl("<table>", true);
            $session['message'] = "";
            $sql = "SELECT subject,messageid," . db_prefix("accounts") . ".name,msgto,seen,sent FROM " . db_prefix($maildb) . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid=" . db_prefix($maildb) . ".msgto WHERE msgfrom=\"" . $acctid . "\" ORDER BY sent DESC";
            $result = db_query($sql);
            if (db_num_rows($result) > 0) {
                for ($i = 0; $i < db_num_rows($result); $i++) {
                    $row = db_fetch_assoc($result);
                    $sql2 = "Select name from " . db_prefix("accounts") . " where acctid=" . $row['msgto'] . "";
                    $result2 = db_query($sql2);
                    $row2 = db_fetch_assoc($result2);
                    $toname = $row2['name'];
                    $id = $row['messageid'];
                    output_notl("<tr>", true);
                    output_notl("<td nowrap><img src='images/" . ($row['seen'] ? "old" : "new") . "scroll.GIF' width='16' height='16' alt='" . ($row['seen'] ? "Old" : "New") . "'></td>", true);
                    output_notl("<td><a href='runmodule.php?module=letteropener&op=read&id={$id}&login={$from}'>", true);
                    if (trim($row['subject']) == "") {
                        output("`i(No Subject)`i");
                    } else {
                        output_notl($row['subject']);
                    }
                    output_notl("</a></td><td><a href='runmodule.php?module=letteropener&op=read&id={$id}&login={$from}'>", true);
                    addnav("", "runmodule.php?module=letteropener&op=read&id={$id}&login={$from}");
                    output("- to %s", $toname);
                    output_notl("</a></td><td><a href='runmodule.php?module=letteropener&op=read&id={$id}&login={$from}'>" . date("M d, h:i a", strtotime($row['sent'])) . "</a></td>", true);
                    output_notl("</tr>", true);
                }
                //}
            } else {
                output("`iThey have not sent any mail.`i");
            }
        } elseif (db_num_rows($result) == 0) {
            output("`@No one was found who matches \"%s\".  ", stripslashes($from));
            $try = translate_inline("Please try again");
            output_notl("<a href='runmodule.php?module=letteropener'>{$try}</a>.", true);
            popup_footer();
            exit;
        } else {
            output_notl("<select name='to' id='to' onChange='check_su_warning();'>", true);
            $superusers = array();
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                output_notl("<option value=\"" . HTMLEntities($row['login']) . "\">", true);
                output_notl("%s", full_sanitize($row['name']));
                if ($row['superuser'] & SU_GIVES_YOM_WARNING && !($row['superuser'] & SU_OVERRIDE_YOM_WARNING)) {
                    array_push($superusers, $row['login']);
                }
            }
            output_notl("</select>`n", true);
        }
        output_notl("</table>", true);
    }
    page_footer();
}
function massmail_run()
{
    global $session;
    $op = httpget('op');
    popup_header("Ye Olde Poste Office");
    rawoutput("<table width='50%' border='0' cellpadding='0' cellspacing='2'>");
    rawoutput("<tr><td>");
    $t = translate_inline("Back to the Ye Olde Poste Office");
    rawoutput("<a href='mail.php'>{$t}</a></td><td>");
    rawoutput("</td></tr></table>");
    output_notl("`n`n");
    $clanid = $session['user']['clanid'];
    $body = httppost('body');
    $subject = "`^Clan Mail";
    $time = date("Y-m-d H:i:s", strtotime("-" . getsetting("LOGINTIMEOUT", 900) . " sec"));
    $name = $session['user']['name'];
    require_once "lib/systemmail.php";
    switch ($op) {
        case "clanmail":
            //copied and modified from Chris Vorndrans Bulletin
            if ($body == "") {
                rawoutput("<form action='runmodule.php?module=massmail&op=clanmail' method='POST'>");
                output("`n`^Clan Mail:`n`n");
                rawoutput("<textarea name=\"body\" rows=\"10\" cols=\"60\" class=\"input\"></textarea>");
                rawoutput("<input type='submit' class='button' value='" . translate_inline("Send") . "'></form>");
                rawoutput("</form>");
            } else {
                $sql = "SELECT * FROM " . db_prefix("accounts") . " WHERE clanid = '{$clanid}'";
                $res = db_query($sql);
                for ($i = 0; $i < db_num_rows($res); $i++) {
                    $row = db_fetch_assoc($res);
                    systemmail($row['acctid'], $subject, $body);
                }
                output("`^Message has been sent.`0");
            }
            addnav("", "runmodule.php?module=massmail&op=clanmail");
            break;
        case "adminall":
            if ($body == "") {
                rawoutput("<form action='runmodule.php?module=massmail&op=adminall' method='POST'>");
                output("`n`^Send to All Players:`n`n");
                rawoutput("<textarea name=\"body\" rows=\"10\" cols=\"60\" class=\"input\"></textarea>");
                rawoutput("<input type='submit' class='button' value='" . translate_inline("Send") . "'></form>");
                rawoutput("</form>");
            } else {
                $sql = "SELECT * FROM " . db_prefix("accounts");
                $res = db_query($sql);
                for ($i = 0; $i < db_num_rows($res); $i++) {
                    $row = db_fetch_assoc($res);
                    systemmail($row['acctid'], "`^Server News from " . $name, $body);
                }
                output("Your mail was sent to all players");
            }
            addnav("", "runmodule.php?module=massmail&op=adminall");
            break;
        case "adminonline":
            if ($body == "") {
                rawoutput("<form action='runmodule.php?module=massmail&op=adminonline' method='POST'>");
                output("`n`^Send to all online:`n`n");
                rawoutput("<textarea name=\"body\" rows=\"10\" cols=\"60\" class=\"input\"></textarea>");
                rawoutput("<input type='submit' class='button' value='" . translate_inline("Send") . "'></form>");
                rawoutput("</form>");
            } else {
                $sql = "SELECT * FROM " . db_prefix("accounts") . " WHERE loggedin = 1 AND laston > '{$time}'";
                $res = db_query($sql);
                for ($i = 0; $i < db_num_rows($res); $i++) {
                    $row = db_fetch_assoc($res);
                    systemmail($row['acctid'], "`^Server News from " . $name, $body);
                }
                output("Your Mail was sent to all online");
            }
            addnav("", "runmodule.php?module=massmail&op=adminonline");
            break;
            //end of copied code
    }
    popup_footer();
}
function hundredpointrally_run()
{
    global $session;
    page_header("Rally Headquarters");
    $op = httpget('op');
    //load settings
    $joincost = get_module_setting("joincost", "hundredpointrally");
    $data = @unserialize(get_module_setting("data", "hundredpointrally"));
    if (!is_array($data)) {
        $data = array();
        set_module_setting("data", serialize($data), "hundredpointrally");
    }
    //load pref
    $player = @unserialize(get_module_pref("data", "hundredpointrally"));
    if (!is_array($player)) {
        $player = array();
        set_module_pref("data", serialize($player), "hundredpointrally");
    }
    switch ($op) {
        case "start":
            do_forced_nav(false, false);
            require_once "lib/datetime.php";
            $nextstarttime = reltime($data['next']['starttime'], false);
            if (!$data['next']['starttime']) {
                $nextstarttime = "Undetermined amount of time";
            }
            $seed = get_module_setting("jackpotseed", "hundredpointrally");
            if (!isset($data['next']['jackpot']) || $data['next']['jackpot'] < $seed) {
                $data['next']['jackpot'] = $seed;
                set_module_setting("data", serialize($data), "hundredpointrally");
            }
            output("You head into a building decked out with chequered flags.  It smells of petrol and burning rubber, although there are no cars or motorbikes to be seen.  Noticing that the receptionist is a Robot, you surmise that she must be pumping the scent in artificially in order to create atmosphere.  Which figures, really.`n`n\"`7Hello!`0\" she says in a tinny, cheery warble.  \"`7Are you here to sign up for the Hundred-Point Rally?  The next one starts in -`0\" her voice becomes stilted and mechanical for a moment - \"`&%s TO RACE START JACKPOT VALUE OF %s CIGARETTES ENTRY FEE OF %s CIGARETTES`7.`0\"`n`n", strtoupper($nextstarttime), $data['next']['jackpot'], $joincost);
            if ($data['current']['open']) {
                $currentstarttime = reltime($data['current']['starttime'], false);
                output("\"`7Or, if you prefer, the current Rally is still open.  It started -`0\" the same mechanical, halting tone - \"`&%s AGO CURRENT JACKPOT %s CIGARETTES`7.  You'd have a better chance if you waited for the next one, but you can join this one if you're impatient.  It'll cost you the same either way.\"`n`n", strtoupper($currentstarttime), $data['current']['jackpot']);
            }
            addnav("Join a Rally");
            if ($session['user']['gems'] >= $joincost) {
                if (!$player['activenext']) {
                    addnav("Join the `bnext`b Hundred-Point Rally", "runmodule.php?module=hundredpointrally&op=joinnext");
                }
                if (!$player['activecurrent'] && $data['current']['open']) {
                    addnav("Join the `bcurrent`b Hundred-Point Rally", "runmodule.php?module=hundredpointrally&op=joincurrent");
                }
            }
            addnav("What?");
            addnav("Explain this Rally business to me.", "runmodule.php?module=hundredpointrally&op=explain");
            addnav("Exit");
            villagenav();
            break;
        case "explain":
            do_forced_nav(false, false);
            output("\"`7It's very simple,`0\" says the Robot.  \"`7The Hundred-Point Rally is a race around the World Map.  The winner takes the jackpot - the more people signed up for the Rally, the bigger the Jackpot.  You'll be given a series of fifty co-ordinates that you have to visit in sequence, and you'll also be given another fifty co-ordinates that can be visited in any order you like.  The challenge is not only in speed, but also in your ability to determine the most efficient path to hit all one hundred co-ordinates.  Because the race can be quite long, and because the co-ordinates are only revealed once the race has begun, it may or may not be a good idea to spend some time plotting out your route before heading to the first Rally Point.  Each new Rally starts exactly twenty-four hours `&WARNING SYSTEM CLOCK ERROR WHAT THE HELL WHY IS 24 HOURS THE SAME AS SIX DAYS`7 after the last one ends, and a Rally can last for up to 48 hours.`0\"`n`nYou nod.  \"`#Could you explain that part about the system clock error again?`0\"`n`n\"`&What part?`0\"`n`n\"`#Ah.`0\"`n`n`JTo ensure that players from different time zones have a fair shake every now and then, Rallies aren't tied to game time.  When the Robot says \"24 hours,\" she means 24 hours of your time, not game time (which runs six times faster).  If you're signing up for the next Rally and a start time isn't determined yet, you'll get a Distraction exactly 24 hours before the race begins, and another one at the drop of the chequered flag.  We highly recommend that you have Distractions sent to your E-mail if you're a Rally fan, and you can find the relevant option in your Preferences menu in any Outpost.`n`nRallies end as soon as someone hits all one hundred points - so, for example, if a Rally starts at midnight and ends at 2am, the next Rally will start at 2am the next day - and if `ithat`i Rally takes three hours to complete, then the Rally ends at 5am and the next Rally begins at 5am the next day.  This way, we eventually end up going all the way around the clock, giving players in different timezones a chance to compete in the Rally.`0");
            addnav("Okay, then.");
            addnav("Back to Reception", "runmodule.php?module=hundredpointrally&op=start");
            break;
        case "joinnext":
            do_forced_nav(false, false);
            output("You hand over your Cigarettes.  \"`7Very well.  Your entry has been accepted and you will be notified via Distraction when the race starts.  In the meantime, I suggest you buy a very, very fast Mount.`0\"  The Robot tries to smile.  It doesn't come out too well.");
            $data['next']['competitors'][$session['user']['acctid']]['points'] = 0;
            $data['next']['competitors'][$session['user']['acctid']]['name'] = $session['user']['name'];
            $player['activenext'] = true;
            $session['user']['gems'] -= $joincost;
            $data['next']['jackpot'] += floor($joincost * 0.75);
            set_module_pref("data", serialize($player), "hundredpointrally");
            set_module_setting("data", serialize($data), "hundredpointrally");
            addnav("Exit");
            villagenav();
            break;
        case "joincurrent":
            do_forced_nav(false, false);
            output("You hand over your Cigarettes.  \"`7Very well.  Your entry has been accepted.  Now you had better get out there and race!`0\"  The Robot tries to smile.  It doesn't come out too well.");
            $data['current']['competitors'][$session['user']['acctid']]['points'] = 0;
            $data['current']['competitors'][$session['user']['acctid']]['name'] = $session['user']['name'];
            $session['user']['gems'] -= $joincost;
            $data['current']['jackpot'] += floor($joincost * 0.75);
            $player['activecurrent'] = true;
            set_module_pref("data", serialize($player), "hundredpointrally");
            set_module_setting("data", serialize($data), "hundredpointrally");
            addnav("Exit");
            villagenav();
            break;
        case "showpoints":
            popup_header("Rally Points");
            rawoutput("<table cellpadding=5 cellspacing=5 border=0><tr><td valign='top'>");
            output("`0`bSequenced Points`b`nHit each of these World Map points in the prescribed order:`n");
            foreach ($data['current']['sequencedpoints'] as $order => $loc) {
                list($sx, $sy, $sz) = explode(",", $data['current']['sequencedpoints'][$order]);
                if ($player['sequencedpoints'] > $order) {
                    rawoutput("<del>");
                    output("Point %s: `@%s,%s`0`n", $order, $sx, $sy);
                    rawoutput("</del>");
                } else {
                    if ($player['sequencedpoints'] < $order) {
                        output("Point %s: `\$%s,%s`0`n", $order, $sx, $sy);
                    } else {
                        output(">> Point %s: `Q%s,%s`0`n", $order, $sx, $sy);
                    }
                }
            }
            rawoutput("</td><td valign='top'>");
            output("`0`bUnordered Points`b`nHit each of these World Map points in whatever order seems best to you:`n");
            foreach ($data['current']['unorderedpoints'] as $order => $loc) {
                list($ux, $uy, $uz) = explode(",", $loc);
                if (@in_array($loc, $player['unorderedpoints'])) {
                    rawoutput("<del>");
                    output("`@%s,%s`0`n", $ux, $uy);
                    rawoutput("</del>");
                } else {
                    output("`\$%s,%s`0`n", $ux, $uy);
                }
            }
            rawoutput("</td><td valign='top'>");
            $rankings = hundredpointrally_getrankings();
            output("`bCurrent Rankings`b`n");
            foreach ($rankings as $rank => $info) {
                if ($info['acctid'] == $session['user']['acctid']) {
                    output("`J`b>>`b ");
                }
                output("#%s: %s`0 (%s points)`n", $rank + 1, $info['name'], $info['points']);
            }
            rawoutput("</td></tr></table>");
            popup_footer();
            break;
    }
    page_footer();
}
function commentaryarchive_run()
{
    global $session;
    popup_header("Commentary Export");
    debug($args);
    if ($session['user']['donation'] >= 1000) {
        $sec = $session['user']['chatloc'];
        if ($sec) {
            output("This is a HTML output of the entire Commentary section you're currently viewing, complete with colour codes.  Use it for archiving memorable roleplaying sessions, outputting on forums or blogs, or what-have-you.`n`nTo use it, copy-paste the output in the textarea below into your favourite plain-text editor (notepad will do in a pinch) and save the results as somefilenameoranother.html.`n`nIf you need help archiving, feel free to ask around for assistance in the Enquirer or Location Four.`n`n`bImportant`b - when trying to copy-paste (or even output) a commentary area with hundreds of commentary pages, your computer may hang for a while.  If this happens, quit pressing buttons, go and have a cup of tea and let it get on with it.`n`nHave fun!`n`n");
            $sql = "SELECT " . db_prefix("commentary") . ".*, " . db_prefix("accounts") . ".name, " . db_prefix("accounts") . ".acctid, " . db_prefix("accounts") . ".clanrank, " . db_prefix("clans") . ".clanshort FROM " . db_prefix("commentary") . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid = " . db_prefix("commentary") . ".author LEFT JOIN " . db_prefix("clans") . " ON " . db_prefix("clans") . ".clanid=" . db_prefix("accounts") . ".clanid WHERE " . ($sec ? "section='{$sec}' AND " : '') . "( " . db_prefix("accounts") . ".locked=0 OR " . db_prefix("accounts") . ".locked is null ) " . "ORDER BY commentid ASC";
            $result = db_query($sql);
            rawoutput("<textarea>");
            rawoutput("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            rawoutput("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
            rawoutput("        \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
            rawoutput("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">");
            rawoutput("<head>");
            rawoutput("\t<title>Improbable Island Commentary Export from section " . $sec . "</title>");
            rawoutput("\t<meta http-equiv=\"content-type\" ");
            rawoutput("\t\tcontent=\"text/html;charset=utf-8\" />");
            rawoutput("\t<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />");
            rawoutput("\t<style type=\"text/css\">");
            rawoutput("\t\tbody {background-color: #C9B18B; font-family: georgia, serif; font-size:smaller; color:#111111;}");
            rawoutput("\t\t.colDkBlue    { color: #000040; }");
            rawoutput("\t\t.colDkGreen   { color: #004000; }");
            rawoutput("\t\t.colDkCyan    { color: #004040; }");
            rawoutput("\t\t.colDkRed     { color: #400000; }");
            rawoutput("\t\t.colDkMagenta { color: #400040; }");
            rawoutput("\t\t.colDkYellow  { color: #404000; }");
            rawoutput("\t\t.colDkWhite   { color: #303030; }");
            rawoutput("\t\t.colLtBlue    { color: #000060; }");
            rawoutput("\t\t.colLtGreen   { color: #006000; }");
            rawoutput("\t\t.colLtCyan    { color: #006060; }");
            rawoutput("\t\t.colLtRed     { color: #600000; }");
            rawoutput("\t\t.colLtMagenta { color: #600060; }");
            rawoutput("\t\t.colLtYellow  { color: #606000; }");
            rawoutput("\t\t.colLtWhite   { color: #505050; }");
            rawoutput("\t\t.colLtBlack   { color: #222222; }");
            rawoutput("\t\t.colDkOrange  { color: #4a2100; }");
            rawoutput("\t\t.colLtOrange  { color: #994400; }");
            rawoutput("\t\t.colBlue  \t{ color: #0070FF; }");
            rawoutput("\t\t.colLime  \t{ color: #DDFFBB; }");
            rawoutput("\t\t.colBlack  \t{ color: #000000; }");
            rawoutput("\t\t.colRose \t{ color: #9F819F; }");
            rawoutput("\t\t.colblueviolet \t{ color: #9A5BEE; }");
            rawoutput("\t\t.coliceviolet\t{ color: #6D7B9F; }");
            rawoutput("\t\t.colLtBrown \t{ color: #8F7D47; }");
            rawoutput("\t\t.colDkBrown \t{ color: #6b563f; }");
            rawoutput("\t\t.colXLtGreen\t{ color: #009900; }");
            rawoutput("\t\t.colAttention \t{ background-color: #00FF00; color: #FF0000; }");
            rawoutput("\t\t.colWhiteBlack \t{ background-color: #FFFFFF; color: #000000; }");
            rawoutput("\t\t.colbeige  { color: #F5F5DC; }");
            rawoutput("\t\t.colkhaki  { color: #F0E68C; }");
            rawoutput("\t\t.coldarkkhaki  { color: #5F5B35; }");
            rawoutput("\t\t.colaquamarine  { color: #7FFFD4; }");
            rawoutput("\t\t.coldarkseagreen  { color: #8FBC8F; }");
            rawoutput("\t\t.collightsalmon  { color: #8F6859; }");
            rawoutput("\t\t.colsalmon  { color: #7F5D4F; }");
            rawoutput("\t\t.colwheat  { color: #F5DEB3; }");
            rawoutput("\t\t.coltan  { color: #D2B48C; }");
            rawoutput("\t\t.colBack  \t{ background-color: #00FFFF; color: #000000; }");
            rawoutput("\t\t.colLtLinkBlue { color: #0069AF; }");
            rawoutput("\t\t.colDkLinkBlue { color: #004C7F; }");
            rawoutput("\t\t.colDkRust { color: #8D6060; }");
            rawoutput("\t\t.colLtRust { color: #B07878; }");
            rawoutput("\t\t.colMdBlue { color: #0000F0; }");
            rawoutput("\t\t.colMdGrey { color: #444444; }");
            rawoutput("\t\t.colburlywood { color: #DEB887; }");
            rawoutput("\t</style>");
            rawoutput("</head>");
            rawoutput("<body>");
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                $row['comment'] = comment_sanitize($row['comment']);
                output("`0" . $row['postdate'] . ": " . $row['name'] . ": `#" . $row['comment'] . "</span><br />");
            }
            rawoutput("</body>");
            rawoutput("</html>");
            rawoutput("</textarea>");
        } else {
            output("You're not in any commentary area right now.`n`n");
        }
    } else {
        output("Commentary Export is a pretty high-load deal - for that reason, we've restricted it to donators only.  Sorry about that.`n`n");
    }
    // array(9) {
    // 'commentid' = '103'
    // 'section' = 'village-Mutant'
    // 'author' = '1'
    // 'comment' = '1'
    // 'postdate' = '2009-09-24 10:52:29'
    // 'name' = 'Admin CavemanJoe'
    // 'acctid' = '1'
    // 'clanrank' = '0'
    // 'clanshort' = ''
    // }
    popup_footer();
}
function donationextend_run()
{
    popup_header("Extended Play");
    $ext1 = get_module_setting("extend1amt");
    $ext2 = $ext1 + get_module_setting("extend2amt");
    $ext1pct = $ext1 / 10000;
    $ext2pct = $ext2 / 10000;
    output("Improbable Island exists ad-free thanks to the generous donations of its players.  Because we don't have any advertisers or corporate sponsors, we can enjoy the sort of content that large businesses wouldn't like to be associated with - McDonald's would withdraw funding if they ever found out about our thousand-eyed Mutant Steaks, and Sony's PR department would faint if they came across the Saga of Budget Horse.`n`nWhen you donate money to Improbable Island, you get:`n`nPoints to spend on fabulous advantages in the Hunter's Lodge - including name colourization and custom titles, cigarettes, Requisition, extra New Days and more`nThe satisfaction of supporting indie game development`nBonus Supply Crates dropped on the World Map`nThe warm squishy feeling you get when you know that a few thousand players have some extra Stamina thanks to you!  Which brings us nicely to...`n`n`bExtended Play!`b`nThe Extended Play feature replaces the old Donations Status bar, which simply gave a readout of how much money the Island had taken in over the calendar month (expressed as a percentage of a fast-food checkout worker's wages, because quite frankly I was pretty skint at the time and kind of pessimistic that this crazy run-a-game-as-a-living thing was even gonna work, but that's a different story).  It had some problems.  Because it took into account only the current calendar month, it'd go from, say, 120%% to -20%% overnight when the month changed (starting off in the red because of the server bill), which was a bit jarring.  Also, nothing happened when the bar was full up!  You didn't get any reward!  Boo.`n`n`bThe new Extended Play readout works differently`b - it's always counting down, at a rate roughly equal to what the Island really needs to bring in so that we can pay the server costs, advertise for new players, and so that I can keep doing this as my day job.  It goes up whenever someone makes a donation, and declines smoothly rather than dropping to zero at the start of a new month.`n`n(yes, to program this I had to add up my rent and food bills and such and work out how much money I needed to live on per second - try it sometime, it's an eye-opener)`n`nWhenever the display says \"`bExtended Play Active`b,\" `bevery player on the Island`b gets an extra %s Stamina points (about %s%%) at each and every New Day (yes, even days triggered by Chronospheres and Instant New Days).  Should we ever do so well that we get the \"`bSpecial Extend`b\" message, `beveryone`b gets a %s-point Stamina bonus (about %s%%).  `bIt doesn't matter if you've never donated before`b - it doesn't matter if you ever do.  Every player gets the bonus, donator or not.`n`nHowever, if you've ever accumulated any Supporter Points at all, the Stamina bonus awarded by Extended Play will be `bdoubled.`b`n`n`bDoubled?`b`nFor the avoidance of doubt:`nYes, if you recruited even `ione`i new player who stuck around long enough to get you some referral points, you get the double bonus.  Even if this new player decided they weren't into text adventures after all.`nYes, if you had even one monster idea accepted, you get the double bonus.  Even if you also sent me twenty-odd terrible monster suggestions that made me want to reach through the screen and take away your keyboard so that you would stop.`nYes, if you've never given any money to the site but still did that monster rating thing, you get the bonus.  Even if you said \"screw it\" and just rated every monster at a 3 until you'd sorted out a hundred ratings.`nYes, if one gloomy day back in 2008 you let the moths out of your wallet and grudgingly donated `ione stinkin' dollar`i to support the server from which you sucked half a gigabyte of text every day for the past six months, you get the double bonus.  Even if you shed tears over that dollar while you spent all the points.`nThe double bonus is a permanent thing.  It doesn't go away, even if you've spent all your Supporter Points - you'll get double the benefit from Extended Play if you `iever had`i any Supporter Points.`n`n`bSo when's a good time to donate?`b`nAha, yes!  If the Extended Play readout is always counting down, but new game days happen at specific times, then some times might be better to donate than others!`n`nWell, sort of.  Maybe.  In very specific situations.  It depends on what the readout's at, and how much you plan to donate.  If it's at zero, and you plan to donate a fiver, then it really doesn't matter when the New Day arrives.  If it says we need nine dollars more for Extended Play, but the New Day just started, then donating a tenner will only really do any good for the people who activate their New Days shortly after you donate (for example, by using a Chronosphere or by logging in after the system-wide New Day has already started) - if no more donations come in before the next system-wide New Day, then the Extended Play will have expired by then.  But then, if the meter says we only need a few more dollars for an Extended Play, and the system-wide New Day is only minutes away, someone else will probably step up and put the extra couple of bucks in the hat - and the meter will have been close to Extended Play in part because of your donation.  So it's all swings and roundabouts, really!`n`n`bCan I opt-out of having my name shown as the last donation?  I'm shy.`b`nYes, check your Preferences.`n`nHave fun!", $ext1, $ext1pct, $ext2, $ext2pct);
    popup_footer();
}
function friendlist_run()
{
    global $session;
    $op = httpget('op');
    if ($op == 'faq') {
        popup_header("Frequently Asked Questions on Friend Lists");
    } else {
        popup_header("Ye Olde Poste Office");
        output_notl("`c`^[`@");
        $t = translate_inline("Friend List");
        rawoutput("<a href='runmodule.php?module=friendlist&op=list'>{$t}</a>");
        addnav('', 'runmodule.php?module=friendlist&op=list');
        output_notl("`^] - [`@");
        $t = translate_inline("Friend Search");
        rawoutput("<a href='runmodule.php?module=friendlist&op=search'>{$t}</a>");
        addnav('', 'runmodule.php?module=friendlist&op=search');
        output_notl("`^] - [`%");
        $t = translate_inline("Back to the Ye Olde Poste Office");
        rawoutput("<a href='mail.php'>{$t}</a>");
        output_notl("`^]`c`Q`n");
    }
    require_once "modules/friendlist/friendlist_{$op}.php";
    if ($op == 'deny') {
        friendlist_deny();
        $op = "list";
        require_once "modules/friendlist/friendlist_list.php";
    }
    $fname = "friendlist_" . $op;
    $fname();
    popup_footer();
}
function cities_faq()
{
    global $session;
    tlschema("faq");
    popup_header("Multi-Village Questions");
    $c = translate_inline("Return to Contents");
    rawoutput("<a href='petition.php?op=faq'>{$c}</a><hr>");
    output("`n`n`c`bQuestions about the multiple village system`b`c`n");
    output("`^1. Why, oh why did you activate such a (choose one [wondrous, horrible]) feature?`n");
    output("`@For kicks, of course. We like to mess with your head.`n");
    output("But seriously, have you looked at the user list?  On lotgd.net, we've got over 6,000 people cramming themselves into the Village Square and trying to get their voices heard! Too much! Too much!`n");
    output("In the interests of sanity, we've made more chat boards. And in the interests of game continuity, we've put them into separate villages with many cool new features.`n`n");
    output("If you are a smaller server, this might not be right for you, but we think it works okay there too.`n`n");
    output("`^2. How do I go to other villages?`n");
    output("`@Walk, skate, take the bus...`n");
    output("Or press the Travel link (in the City Gates or Village Gates category) in the navigation bar.`n`n");
    output("`^3. How does travelling work?`n");
    output("`@Pretty well, actually. Thanks for asking.`n");
    output("You get some number of  free travels per day (%s on this server) in which you can travel to any other village you want.", get_module_setting("allowance"));
    output("Also, it is possible for the admin to give additional free travels with some mounts.");
    output("After that, you use up one forest fight per travel.");
    output("After that...well, we hope you like where you end up.");
    output("Since all major economic transactions come through %s (the capital of the region), the roads to and from there have been fortified to protect against monsters from wandering onto them.", getsetting("villagename", LOCATION_FIELDS));
    output("That was a while back though, and the precautions are no longer perfect.`n");
    output("Travel between the other villages have no such precautions.`n");
    output("In either case, you might want to heal yourself before travelling.");
    output("You have been warned.`n`n");
    output("`^4. Where's (the Inn, the forest, my training master, etc.)?`n");
    output("`@Look around. Do you see it? No? Then it's not here.`n");
    output("The problem's usually:`n");
    output("a) It's actually there, you just missed it the first time around.`n");
    output("b) It's in another village, try travelling.`n");
    output("c) It's not on this server, check out the LoGD Net link on the login page.`n");
    output("d) Are you sure you didn't just see that feature in a dream?`n`n");
    output("`^5. I've used up my free travels and forest fights. How do I travel now?`n");
    output("`@We hope you like where you've ended up, because you're stuck there until the next new day.`n`n");
    output("`^6. Can I pay for more travels?`n");
    output("`@No, but you can just plain pay us.");
    if (file_exists("lodge.php")) {
        output("Check out the Hunter's Lodge.");
    } else {
        output("Speak to an admin about donating money.");
    }
    output("Actually, we are considering it.`n");
    if (is_module_active("newbieisland")) {
        $newbieisland = get_module_setting("villagename", "newbieisland");
        if ($session['user']['location'] == $newbieisland) {
            $newbieisland = translate_inline($newbieisland);
            output("`^7. I'm on %s.", $newbieisland);
            output("Why can't I see the Travel link or any of the other stuff this section talks about?`n");
            output("`@You need at least 5 levels in search, or a Ring of Finding +2 to see any of this stuff.`n");
            output("If you haven't figured it out by now, this second answer is always the real one.");
            output("You'll only be able to see Travel once you leave %s.", $newbieisland);
            output("Feel free to skip the rest of this section and come back to it later.`n`n");
        }
    }
    rawoutput("<hr><a href='petition.php?op=faq'>{$c}</a>");
    popup_footer();
}