function translationconvert_run()
{
    global $session;
    page_header("Translations Convertor Thing");
    output("Outputting all known translations, so that you can do a find-and-replace in the files themselves and we can stop doing this silly translate thing.`n`n");
    if (httpget('delete')) {
        $del = httpget('delete');
        $sql = "UPDATE " . db_prefix("translations") . " SET version='updated' WHERE tid={$del}";
        db_query($sql);
    }
    $sql = "SELECT * FROM " . db_prefix("translations") . " WHERE version='dragonbones' ORDER BY uri";
    $result = db_query($sql);
    $total = 0;
    while ($row = db_fetch_assoc($result)) {
        if ($row['intext'] != $row['outtext']) {
            $total++;
            rawoutput("<a href=\"runmodule.php?module=translationconvert&delete=" . $row['tid'] . "\">MARK</a>");
            addnav("", "runmodule.php?module=translationconvert&delete=" . $row['tid']);
            output_notl("`n`0`b%s`b:", $row['uri']);
            rawoutput("<table width=100%><tr><td width=50% border=1px solid #cccccc>" . $row['intext'] . "</td><td width=50%>" . $row['outtext'] . "</td></tr></table>");
            output_notl("`n`n");
        }
    }
    debug($total);
    addnav("Back to the Grotto", "superuser.php");
    page_footer();
}
function marriage_uninstall()
{
    require_once "modules/marriage/lovedrinks.php";
    marriage_lovedrinksrem();
    output_notl("`n`c`b`QMarriage Module - Uninstalled`0`b`c");
    return true;
}
function improbablehousing_mementos_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "improbablehousing_interior":
            $hid = $args['hid'];
            $rid = $args['rid'];
            $house = $args['house'];
            $items = get_items_with_prefs("memento_dwellingtrigger_" . $hid . "_" . $rid);
            //debug($items);
            //group the items together in case there's multiple ones
            $texts = array();
            if (is_array($items) && count($items)) {
                foreach ($items as $id => $prefs) {
                    $texts[serialize($prefs["memento_dwellingtrigger_" . $hid . "_" . $rid])] = $prefs["memento_dwellingtrigger_" . $hid . "_" . $rid];
                }
                foreach ($texts as $text) {
                    output_notl("`0%s`0`n`n", stripslashes($text));
                }
            }
            if (improbablehousing_getkeytype($house, $rid) >= 30) {
                addnav("Donator Features");
                addnav("Memento Effects", "runmodule.php?module=improbablehousing_mementos&op=start&hid={$hid}&rid={$rid}");
            }
            break;
    }
    return $args;
}
function friendlist_unignore()
{
    global $session;
    $ac = httpget('ac');
    $ignored = rexplode(get_module_pref('ignored', 'friendlist', $ac));
    $iveignored = rexplode(get_module_pref('iveignored'));
    if (in_array($ac, $iveignored)) {
        $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $row = db_fetch_assoc($result);
            $info = sprintf_translate("%s`Q has been removed from your list.", $row['name']);
            require_once "lib/systemmail.php";
            $t = array("`\$Ignore List Removal");
            $mailmessage = array("%s`0`@ has removed you from %s ignore list.", $session['user']['name'], $session['user']['sex'] ? translate_inline("her") : translate_inline("his"));
            systemmail($ac, $t, $mailmessage);
        } else {
            $info = translate_inline("That user no longer exists...");
        }
    }
    $ignored = array_diff($ignored, array($session['user']['acctid']));
    $ignored = rimplode($ignored);
    set_module_pref('ignored', $ignored, 'friendlist', $ac);
    if (in_array($ac, $iveignored)) {
        $iveignored = array_diff($iveignored, array($ac));
        $iveignored = rimplode($iveignored);
        set_module_pref('iveignored', $iveignored);
    }
    output_notl($info);
}
function sethsong_run()
{
    $op = httpget('op');
    $visits = get_module_setting("visits");
    $been = get_module_pref("been");
    $iname = getsetting("innname", LOCATION_INN);
    tlschema("inn");
    page_header($iname);
    rawoutput("<span style='color: #9900FF'>");
    output_notl("`c`b");
    output($iname);
    output_notl("`b`c");
    tlschema();
    // Short circuit out if we've heard enough
    if ($been >= $visits) {
        output("%s`0 clears his throat and drinks some water.", getsetting("bard", "`^Seth"));
        output("\"I'm sorry, my throat is just too dry.\"");
    } else {
        sethsong_sing();
    }
    addnav("Where to?");
    addnav("I?Return to the Inn", "inn.php");
    villagenav();
    rawoutput("</span>");
    page_footer();
}
function avatar_showimages($set)
{
    $races = modulehook("racenames");
    rawoutput("<table cellpadding='0' cellspacing='0' border='0' bgcolor='#999999'>");
    $r = translate_inline("Race");
    $m = translate_inline("Male Image");
    $f = translate_inline("Female Image");
    rawoutput("<tr class='trhead'><th>{$r}</th><th>{$m}</th><th>{$f}</th></tr>");
    $i = 0;
    foreach ($races as $key => $race) {
        $r = strtolower($race);
        $imm = avatar_getimage($r, "male", $set);
        $imf = avatar_getimage($r, "female", $set);
        rawoutput("<tr class='" . ($i % 2 ? "trlight" : "trdark") . "'>");
        rawoutput("<th>");
        output_notl('`^');
        output($race);
        output_notl("`0");
        rawoutput("</th><td>");
        rawoutput($imm);
        rawoutput("</td><td>");
        rawoutput($imf);
        rawoutput("</td>");
        rawoutput("</tr>");
        $i++;
    }
    rawoutput("</table>");
}
function monsterkills_run()
{
    page_header("Most Monster Kills");
    $acc = db_prefix("accounts");
    $mp = db_prefix("module_userprefs");
    $sql = "SELECT {$acc}.name AS name,\r\n\t\t{$acc}.acctid AS acctid,\r\n\t\t{$mp}.value AS kills,\r\n\t\t{$mp}.userid FROM {$mp} INNER JOIN {$acc}\r\n\t\tON {$acc}.acctid = {$mp}.userid \r\n\t\tWHERE {$mp}.modulename = 'monsterkills' \r\n\t\tAND {$mp}.setting = 'kills' \r\n\t\tAND {$mp}.value > 0 ORDER BY ({$mp}.value+0)\t\r\n\t\tDESC limit " . get_module_setting("list") . "";
    $result = db_query($sql);
    $rank = translate_inline("Kills");
    $name = translate_inline("Name");
    output("`n`b`c`@Most`\$ Monster `@Kills`n`n`c`b");
    rawoutput("<table border='0' cellpadding='2' cellspacing='1' align='center'>");
    rawoutput("<tr class='trhead'><td align=center>{$name}</td><td align=center>{$rank}</td></tr>");
    for ($i = 0; $i < db_num_rows($result); $i++) {
        $row = db_fetch_assoc($result);
        if ($row['name'] == $session['user']['name']) {
            rawoutput("<tr class='trhilight'><td>");
        } else {
            rawoutput("<tr class='" . ($i % 2 ? "trdark" : "trlight") . "'><td align=left>");
        }
        output_notl("%s", $row['name']);
        rawoutput("</td><td align=right>");
        output_notl("%s", $row['kills']);
        rawoutput("</td></tr>");
    }
    rawoutput("</table>");
    addnav("Back to HoF", "hof.php");
    villagenav();
    page_footer();
}
function friendlist_search()
{
    global $session;
    $n = httppost("n");
    rawoutput("<form action='runmodule.php?module=friendlist&op=search' method='POST'>");
    addnav("", "runmodule.php?module=friendlist&op=search");
    if ($n != "") {
        $string = "%";
        for ($x = 0; $x < strlen($n); $x++) {
            $string .= substr($n, $x, 1) . "%";
        }
        $sql = "SELECT name,dragonkills,acctid FROM " . db_prefix("accounts") . " WHERE name LIKE '%{$string}%' AND acctid<>" . $session['user']['acctid'] . " AND locked=0 ORDER BY level,dragonkills";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $ignored = rexplode(get_module_pref('ignored'));
            $friends = rexplode(get_module_pref('friends'));
            $request = rexplode(get_module_pref('request'));
            $iveignored = rexplode(get_module_pref('iveignored'));
            output("`@These users were found:`n");
            rawoutput("<table style='width:60%;text-align:center;' cellpadding='3' cellspacing='0' border='0'>");
            rawoutput("<tr class='trhead'><td>" . translate_inline("Name") . "</td><td>" . translate_inline("Operations") . "</td></tr>");
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                rawoutput("<tr class='" . ($i % 2 ? "trlight" : "trdark") . "'><td>");
                output_notl($row['name']);
                rawoutput("</td><td>");
                if (in_array($row['acctid'], $ignored)) {
                    $info = translate_inline("This user has ignored you.");
                    $info .= " [<a href='runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid'] . "' class='colDkGreen'>" . translate_inline("Ignore") . "</a>]";
                    addnav("", "runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid']);
                } elseif (in_array($row['acctid'], $friends)) {
                    $info = translate_inline("This user is already in your list.");
                } elseif (in_array($row['acctid'], $request)) {
                    $info = translate_inline("This user has already requested to you.");
                } else {
                    if (in_array($row['acctid'], $iveignored)) {
                        $info = "[<a href='runmodule.php?module=friendlist&op=unignore&ac=" . $row['acctid'] . "' class='colLtRed'>" . translate_inline("Unignore") . "</a>]";
                        addnav("", "runmodule.php?module=friendlist&op=unignore&ac=" . $row['acctid']);
                    } else {
                        $info = "[<a href='runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid'] . "' class='colDkGreen'>" . translate_inline("Ignore") . "</a>]";
                        addnav("", "runmodule.php?module=friendlist&op=ignore&ac=" . $row['acctid']);
                        $info .= " - [<a href='runmodule.php?module=friendlist&op=request&ac=" . $row['acctid'] . "' class='colDkGreen'>" . translate_inline("Request") . "</a>]";
                        addnav("", "runmodule.php?module=friendlist&op=request&ac=" . $row['acctid']);
                    }
                }
                rawoutput("{$info}</td></tr>");
            }
            rawoutput("</table>");
        } else {
            output("`c`@`bA user was not found with that name.`b`c");
        }
        output_notl("`n");
    }
    output("`^`b`cFriend Search...`c`b");
    output("`n`nWho do you want to search for?");
    output("`n`nName of user: "******"<input name='n' maxlength='50' value=\"" . htmlentities(stripslashes(httppost('n'))) . "\">");
    $apply = translate_inline("Search");
    rawoutput("<input type='submit' class='button' value='{$apply}'></form>");
}
function translationwizard_uninstall()
{
    output_notl("Performing Uninstall on Translation Wizard. Thank you for using!`n`n");
    if (db_table_exists(db_prefix("temp_translations"))) {
        db_query("DROP TABLE " . db_prefix("temp_translations"));
    }
    return true;
}
function improbablehousing_secretrooms_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "commentarycommand":
            if (!httpget("hid")) {
                break;
            } else {
                require_once "modules/improbablehousing/lib/lib.php";
                $hid = httpget("hid");
                $rid = httpget("rid");
                $house = improbablehousing_gethousedata(httpget("hid"));
                $secrets = array();
                foreach ($house['data']['rooms'] as $rkey => $rvals) {
                    if ($rkey != $rid) {
                        if ($rvals['enterfrom'] == $rid && $rvals['hidden']) {
                            $secrets[$rkey] = $rvals;
                        } else {
                            if ($rkey == $house['data']['rooms'][$rid]['enterfrom']) {
                                $secrets[$rkey] = $rvals;
                            }
                        }
                    }
                }
                if (count($secrets)) {
                    foreach ($secrets as $rkey => $rvals) {
                        if (count($rvals['triggers'])) {
                            foreach ($rvals['triggers'] as $trigger) {
                                if ($args['command'] == $trigger) {
                                    $args['processed'] = 1;
                                    if (improbablehousing_canenter_room($house, $rkey)) {
                                        redirect("runmodule.php?module=improbablehousing&op=interior&hid={$hid}&rid={$rkey}");
                                    } else {
                                        output_notl("%s`n`n", $rvals['lockreject']);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            break;
        case "improbablehousing_interior":
            $hid = $args['hid'];
            $rid = $args['rid'];
            $house = $args['house'];
            if (improbablehousing_getkeytype($house, $rid) == 100) {
                addnav("Donator Features");
                addnav("Build a Secret Room", "runmodule.php?module=improbablehousing_secretrooms&op=start&hid={$hid}&rid={$rid}");
                if ($house['data']['rooms'][$rid]['hidden']) {
                    addnav("Secret Room Features");
                    addnav("Manage this room's trigger phrases", "runmodule.php?module=improbablehousing_secretrooms&op=manage&hid={$hid}&rid={$rid}");
                }
            }
            break;
    }
    return $args;
}
function tip()
{
    global $tipid;
    $tip = translate_inline("Tip");
    output_notl("<div style='cursor: pointer; cursor: hand; display: inline;' onMouseOver=\"tip{$tipid}.style.visibility='visible'; tip{$tipid}.style.display='inline';\" onMouseOut=\"tip{$tipid}.style.visibility='hidden'; tip{$tipid}.style.display='none';\">`i[ `b{$tip}`b ]`i", true);
    rawoutput("<div class='debug' id='tip{$tipid}' style='position: absolute; width: 200px; max-width: 200px; float: right;'>");
    $args = func_get_args();
    call_user_func_array("output", $args);
    rawoutput("</div></div>");
    rawoutput("<script language='JavaScript'>var tip{$tipid} = document.getElementById('tip{$tipid}'); tip{$tipid}.style.visibility='hidden'; tip{$tipid}.style.display='none';</script>");
    $tipid++;
}
function clancommentaryoverview_run()
{
    page_header("Clan Commentary Overview");
    $numcomments = get_module_setting("numcomments");
    require_once "lib/superusernav.php";
    superusernav();
    addnav("C?Commentary Overview", "moderate.php");
    addnav("Clan Halls");
    $sql = "SELECT clanid, clanname, clanshort FROM " . db_prefix("clans") . " ORDER BY clanid";
    $res = db_query($sql);
    // since these are proper names, they shouldn't be translated
    tlschema("notranslate");
    while ($row = db_fetch_assoc($res)) {
        addnav(array("<%s> %s", $row['clanshort'], $row['clanname']), "moderate.php?area=clan-{$row['clanid']}");
    }
    tlschema();
    $sql = "SELECT clanid, clanname FROM " . db_prefix("clans") . " ORDER BY clanid";
    $res = db_query($sql);
    $firstclan = 1;
    while ($clan = db_fetch_assoc($res)) {
        $cid = $clan['clanid'];
        $csql = "SELECT * FROM " . db_prefix("commentary") . " WHERE section='clan-" . $cid . "' ORDER BY postdate DESC LIMIT " . $numcomments;
        $cres = db_query($csql);
        if (db_num_rows($cres) > 0) {
            if ($firstclan == 1) {
                $firstclan = 0;
                addnav("", "runmodule.php?module=clancommentaryoverview");
                $buttonrefresh = translate_inline("Refresh");
                rawoutput("<form action='runmodule.php?module=clancommentaryoverview' method='post'>");
                rawoutput("<input type='submit' class='button' value='{$buttonrefresh}'>");
                rawoutput("</form>");
            }
            rawoutput("<hr>");
            $cname = $clan['clanname'];
            addnav("", "moderate.php?area=clan-" . $cid);
            rawoutput("<a href='moderate.php?area=clan-" . $cid . "'>");
            output_notl("`b`^%s`b`0", $cname);
            rawoutput("</a>");
            output_notl("`n");
            $carray = array();
            while ($ccomment = db_fetch_assoc($cres)) {
                array_push($carray, $ccomment);
            }
            while ($ccomment = array_pop($carray)) {
                clancommentaryoverview_displaycomment($ccomment);
            }
        }
    }
    page_footer();
}
function medals_award_medal($sname, $vname, $desc, $icon, $awardtext = false, $acctid = false)
{
    global $session;
    if (!$acctid) {
        $acctid = $session['user']['acctid'];
    }
    $ach = array("name" => $vname, "desc" => $desc, "icon" => $icon);
    $info = unserialize(get_module_pref("medals", "medals"));
    if (!isset($info[$sname])) {
        $info[$sname] = $ach;
        if ($awardtext) {
            output_notl("`n%s`n`n", $awardtext);
        }
        set_module_pref("medals", serialize($info), "medals", $acctid);
    }
}
function colourtest_run()
{
    global $session;
    $teststring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890 !@#\$%%^&*()`n";
    $colours = array("1" => "colDkBlue", "2" => "colDkGreen", "3" => "colDkCyan", "4" => "colDkRed", "5" => "colDkMagenta", "6" => "colDkYellow", "7" => "colDkWhite", "~" => "colBlack", "!" => "colLtBlue", "@" => "colLtGreen", "#" => "colLtCyan", "\$" => "colLtRed", "%%" => "colLtMagenta", "^" => "colLtYellow", "&" => "colLtWhite", ")" => "colLtBlack", "e" => "colDkRust", "E" => "colLtRust", "g" => "colXLtGreen", "G" => "colXLtGreen", "j" => "colMdGrey", "J" => "colMdBlue", "k" => "colaquamarine", "K" => "coldarkseagreen", "l" => "colDkLinkBlue", "L" => "colLtLinkBlue", "m" => "colwheat", "M" => "coltan", "p" => "collightsalmon", "P" => "colsalmon", "q" => "colDkOrange", "Q" => "colLtOrange", "R" => "colRose", "T" => "colDkBrown", "t" => "colLtBrown", "V" => "colBlueViolet", "v" => "coliceviolet", "x" => "colburlywood", "X" => "colbeige", "y" => "colkhaki", "Y" => "coldarkkhaki");
    page_header("Colour Test");
    output("`b`cPlease ensure that your monitor is correctly calibrated before making any changes to your templates.`b  It also helps a lot to have a friend do this with you - people's eyes are very different.`c`n`n");
    rawoutput("An excellent resource for monitor calibration, including test images and tutorials, can be found <a href=\"http://www.normankoren.com/makingfineprints1A.html\"> here.</a>");
    output("`n`n`0We are now testing each colour, to see how it looks against the background for this template.`n`nMake sure that each colour is clear and easily-readable.  It's a good idea to test on a variety of monitors, both CRT and LCD, at different colour depths and resolutions, and in different ambient light.  The ColorZilla and FireBug extensions for FireFox are invaluable for determining appropriate colours.`n`n");
    foreach ($colours as $code => $colour) {
        output_notl("`0CCode " . $code . ", CSS code " . $colour . ": `" . $code . "" . $teststring);
    }
    addnav("Back to the Superuser grotto", "superuser.php");
    addnav("Reload this page", "runmodule.php?module=colourtest");
    page_footer();
}
function jeweler_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            tlschema($args['schemas']['marketnav']);
            addnav($args['marketnav']);
            tlschema();
            addnav("Oliver's Jewelry", "runmodule.php?module=jeweler");
            break;
        case "biostat":
            $choker = get_module_pref("chokerheld", false, $args['acctid']);
            $amulet = get_module_pref("amuletheld", false, $args['acctid']);
            $necklace = get_module_pref("necklaceheld", false, $args['acctid']);
            $bracelet = get_module_pref("braceletheld", false, $args['acctid']);
            $ring = get_module_pref("ringheld", false, $args['acctid']);
            if ($choker || $amulet || $necklace || $bracelet || $ring) {
                output("`^Jewelry: ");
                $displayed = 0;
                $displaystring = "";
                $chokertext = translate_inline("Choker");
                $amulettext = translate_inline("Amulet");
                $necklacetext = translate_inline("Necklace");
                $bracelettext = translate_inline("Bracelet");
                $ringtext = translate_inline("Ring");
                if ($choker) {
                    $displaystring = $chokertext;
                    $displayed++;
                }
                if ($amulet) {
                    $displaystring = sprintf("%s%s%s", $displaystring, $displayed++ ? ", " : "", $amulettext);
                }
                if ($necklace) {
                    $displaystring = sprintf("%s%s%s", $displaystring, $displayed++ ? ", " : "", $necklacetext);
                }
                if ($bracelet) {
                    $displaystring = sprintf("%s%s%s", $displaystring, $displayed++ ? ", " : "", $bracelettext);
                }
                if ($ring) {
                    $displaystring = sprintf("%s%s%s", $displaystring, $displayed++ ? ", " : "", $ringtext);
                }
                output_notl("`@%s`n", $displaystring);
            }
            break;
    }
    return $args;
}
function checkday(bool $force = true) : bool
{
    global $session, $revertsession, $REQUEST_URI;
    output_notl('<!--checkday()-->', true);
    if (is_new_day()) {
        if ($force && $session['user']['loggedin']) {
            $session = $revertsession;
            $session['user']['restorepage'] = $REQUEST_URI;
            $session['allowednavs'] = [];
            addnav('', 'newday.php');
            redirect('newday.php');
        }
        return true;
    } else {
        return false;
    }
}
function iitems_superuser_item_menu()
{
    output("Select an item to edit, or create a new item.`n");
    massinvalidate("iitems");
    $sql = "SELECT id,localname,data FROM " . db_prefix("iitems");
    $result = db_query($sql);
    $allitems = array();
    $allkeys = array();
    $colcount = 0;
    for ($i = 0; $i < db_num_rows($result); $i++) {
        $row = db_fetch_assoc($result);
        $item = unserialize($row['data']);
        $item['id'] = $row['id'];
        $allitems[$row['localname']] = $item;
        if (count($item) > $colcount) {
            $colcount = count($item);
        }
        foreach ($item as $key => $val) {
            $allkeys[$key] = 1;
        }
    }
    rawoutput("<table width=100% cellpadding=1 cellspacing=1 border=1><tr><td>Actions</td>");
    foreach ($allkeys as $key => $val) {
        rawoutput("<td>" . $key . "</td>");
    }
    rawoutput("</tr>");
    foreach ($allitems as $itemid => $vals) {
        rawoutput("<tr><td><a href=\"runmodule.php?module=iitems&op=superuser&superop=edit&id=" . $vals['id'] . "\">" . $vals['verbosename'] . " (" . $itemid . ")</a> (<a href=\"runmodule.php?module=iitems&op=superuser&superop=give&id=" . $itemid . "\">Give</a>) (<a href=\"runmodule.php?module=iitems&op=superuser&superop=delete&id=" . $vals['id'] . "\">Delete</a>) (<a href=\"runmodule.php?module=iitems&op=superuser&superop=copy&id=" . $vals['id'] . "\">Copy</a>)<br />");
        addnav("", "runmodule.php?module=iitems&op=superuser&superop=edit&id=" . $vals['id']);
        addnav("", "runmodule.php?module=iitems&op=superuser&superop=delete&id=" . $vals['id']);
        addnav("", "runmodule.php?module=iitems&op=superuser&superop=copy&id=" . $vals['id']);
        addnav("", "runmodule.php?module=iitems&op=superuser&superop=give&id=" . $itemid);
        foreach ($allkeys as $key => $val) {
            rawoutput("<td>");
            if ($key == "image") {
                rawoutput("<img src=\"images/iitems/" . $vals['image'] . "\">");
            } else {
                output_notl("%s", $allitems[$itemid][$key]);
            }
            rawoutput("</td>");
        }
        rawoutput("</tr>");
    }
    rawoutput("</table>");
}
function friendlist_faq()
{
    $c = translate_inline("Return to the Contents");
    output_notl("`#<strong><center><a href='petition.php?op=faq'>{$c}</a></center></strong>`0", true);
    addnav("", "petition.php?op=faq");
    rawoutput("<hr>");
    output("`c`&`bQuestions about Friend Lists`b`c`n");
    output("`^1. Where is it?`n");
    output("`@Just click the link at the top of the mail page.`n`n");
    output("`^2. What is it for?`n");
    output("`@You can send requests to add someone to both of your lists.`nIf the other user accepts, you will be able to see their status, location, and whether or not they are logged in.`n`n");
    output("`^3. Anything else?`n");
    output("`@You can ignore players that harass you, to prevent them from sending you mail.`nYou can ignore Admin, however their mails will still come through.`n`n");
    if (get_module_setting('allowStat')) {
        output("`^4. Sure that's it?`n");
        output("`@Oh, I forgot!;) You can turn on a preference to see how many of your friends are online.");
    }
    rawoutput("<hr>");
    output_notl("`#<strong><center><a href='petition.php?op=faq'>{$c}</a></center></strong>`0", true);
}
function friendlist_deny()
{
    global $session;
    $ignored = rexplode(get_module_pref('ignored'));
    $friends = rexplode(get_module_pref('friends'));
    $request = rexplode(get_module_pref('request'));
    $ac = httpget('ac');
    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
    $result = db_query($sql);
    if (in_array($ac, $friends)) {
        $info = translate_inline("That user has been removed.");
        require_once "lib/systemmail.php";
        $t = "`\$Friend List Removal";
        $mailmessage = array("%s`0`@ has deleted you from %s Friend List.", $session['user']['name'], $session['user']['sex'] ? translate_inline("her") : translate_inline("his"));
        $friends = array_diff($friends, array($ac));
        $friends = rimplode($friends);
        set_module_pref('friends', $friends);
        $act = $session['user']['acctid'];
        $friends = rexplode(get_module_pref('friends', 'friendlist', $ac));
        $friends = array_diff($friends, array($act));
        $friends = rimplode($friends);
        set_module_pref('friends', $friends, 'friendlist', $ac);
        invalidatedatacache("friendliststat-" . $session['user']['acctid']);
        invalidatedatacache("friendliststat-" . $ac);
    } else {
        $info = translate_inline("That user has been denied.");
        require_once "lib/systemmail.php";
        $t = "`\$Friend Request Denied";
        $mailmessage = array("%s`0`@ has denied you your Friend Request.", $session['user']['name']);
        $request = array_diff($request, array($ac));
        $request = rimplode($request);
        set_module_pref('request', $request);
    }
    if (db_num_rows($result) > 0) {
        systemmail($ac, $t, $mailmessage);
        $row = db_fetch_assoc($result);
        $info = sprintf_translate("%s has been removed", $row['name']);
    }
    output_notl($info);
}
function friendlist_accept()
{
    global $session;
    $ignored = rexplode(get_module_pref('ignored'));
    $request = rexplode(get_module_pref('request'));
    $friends = rexplode(get_module_pref('friends'));
    $ac = httpget('ac');
    if (in_array($ac, $ignored)) {
        $info = translate_inline("This user has ignored you.");
    } elseif (in_array($ac, $friends)) {
        $info = translate_inline("This user is already in your list.");
    } elseif (in_array($ac, $request)) {
        $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $row = db_fetch_assoc($result);
            invalidatedatacache("friendliststat-" . $session['user']['acctid']);
            invalidatedatacache("friendliststat-" . $ac);
            $friends[] = $ac;
            $info = sprintf_translate("%s`Q has been added to your list.", $row['name']);
            require_once "lib/systemmail.php";
            $t = "`\$Friend Request Accepted";
            $mailmessage = array("%s`0`@ has accepted your Friend Request.", $session['user']['name']);
            systemmail($ac, $t, $mailmessage);
            $friends = rimplode($friends);
            set_module_pref('friends', $friends);
            $friends = rexplode(get_module_pref('friends', 'friendlist', $ac));
            $friends[] = $session['user']['acctid'];
            $friends = rimplode($friends);
            set_module_pref('friends', $friends, 'friendlist', $ac);
            $request = array_diff($request, array($ac));
            $request = rimplode($request);
            set_module_pref('request', $request);
        } else {
            $info = translate_inline("That user no longer exists...");
        }
    }
    output_notl($info);
}
function strategyhut_run()
{
    global $session;
    $cost = get_module_setting("cost");
    $op = httpget("op");
    page_header("The Strategy Hut");
    output("`5`c`bThe Strategy Hut`b`c");
    if ($op == "") {
        addnav(array("Ask for Advice (`^%s gold`0)", $cost), "runmodule.php?module=strategyhut&op=ask");
        output("`&You enter the hut, to find `6Atrus `&busy at his desk.");
        output("\"`^Well, a young warrior in search of help!");
        output("For a small fee, I will offer advice to you.`3\"`n`n");
        output("`&Hesitantly, you approach the burly warrior.`n`n");
        output("`&You blink a few times before you realize he was actually talking to you.");
        output("`6Atrus `&doesn't seem very patient, so you'd better decide quickly if you want to hear his advice!`n");
    } elseif ($session['user']['gold'] < $cost) {
        output("`&You go through your pockets, searching for money, but you don't have enough.");
        output("After a moment of intense searching, `6Atrus `&starts to scowl, and you decide to leave before he gets annoyed.`n`n");
    } else {
        $session['user']['gold'] -= $cost;
        debuglog("spent {$cost} gold at the strategy hut");
        output("`&You give `6Atrus `^%s gold`7.", $cost);
        output("`&He nods, and thinks for a moment.`n`n");
        $phrases = array("\"`^Heal often, bank often.`3\"", "\"`^Think balance: weapons and armor must be close in level, not enough defense and your first attack will be your last.`3\"", "\"`^Don't be afraid to slum, in the lower DK levels, speed is NOT a priority. Later is different.`3\"", "\"`^That stat bar is your life, when it gets into the yellow zone, heal. When it goes red, pray.`3\"", "\"`^In PvP, pick your targets with care. If not sure, DON'T... or you'll be explaining to {deathoverlord}`^ what happened.`3\"", "\"`^You don't always need to resurrect. There will be times to save favor for emergencies.`3\"", "\"`^If it's a game bug, petition it. If it's a gameplay issue, petition it.`3\"", "\"`^A good offense is not always a good defense, even the strongest players die in the forest.`3\"", "\"`^Confidence is one thing: attacking a God is suicide. Check the bio first.`3\"", "\"`^Keep an open mind and think it through. Only a fool fights blindly.`3\"", "\"`^There is a dragon, and when you are ready, it will be too. Patience.`3\"", "\"`^Travelling between towns can be dangerous. Heal first.`3\"", "\"`^Talk to everyone in all the villages, visit the shops and stalls. Explore. Learn.`3\"", "\"`^Lower DK players die often in the beginning. It happens to all of us.`3\"", "\"`^When you face the dragon, be ready and fully healed... or it will eat you for lunch.`3\"", "\"`^Your mount or familiar is an asset... learn what it can do, and know its limits. *And* yours, as well.`3\"", "\"`^There is no shame in knowing when to run. Better a bruised ego than a visit to {deathoverlord}`^.`3\"", "\"`^Log in ONCE per game day only, or you will be killed repeatedly... and lose experience as a result. There is no safe place.`3\"", "\"`^If you can't resurrect, log off and wait for New Day. You are already dead.`3\"", "\"`^A good player treats his fellows with courtesy and respect. A wise player knows that new friends can help him succeed.`3\"", "\"`^Don't forget to feed your mount or familiar.`3\"");
        $question = e_rand(0, count($phrases) - 1);
        $phrases = translate_inline($phrases);
        $myphrase = $phrases[$question];
        $myphrase = str_replace('{deathoverlord}', getsetting('deathoverlord', '`$Ramius'), $myphrase);
        output_notl("%s`n`n", $myphrase);
        output("`&You ponder his advice for a moment, before thanking him and making your exit.`n`n");
        if (is_module_active("medals")) {
            require_once "modules/medals.php";
            medals_award_medal("strategyhut", "Strategy Seeker", "This player asked for help in the Strategy Hut.", "medal_strategy.png");
        }
    }
    villagenav();
    page_footer();
}
function friendlist_request()
{
    global $session;
    $ac = httpget('ac');
    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
    $result = db_query($sql);
    if (db_num_rows($result) > 0) {
        $row = db_fetch_assoc($result);
        $info = translate_inline("You have successfully sent your request to %s`Q.");
        $info = str_replace('%s', $row['name'], $info);
        require_once "lib/systemmail.php";
        $t = array("`\$Friend Request Sent");
        $mailmessage = array("%s`0`@ has sent you a Friend Request.`nIf this user has been spamming you with this, ignore them from your search function.", $session['user']['name']);
        systemmail($ac, $t, $mailmessage);
    } else {
        $info = translate_inline("That user no longer exists...");
    }
    $request = get_module_pref('request', 'friendlist', $ac);
    $request = rexplode($request);
    $request[] = $session['user']['acctid'];
    $request = rimplode($request);
    set_module_pref('request', $request, 'friendlist', $ac);
    output_notl($info);
}
function clannews_dohook($hookname, $args)
{
    switch ($hookname) {
        case "clanhall":
            global $session, $claninfo;
            $maxevents = get_module_setting("maxevents");
            $sql = "SELECT " . db_prefix("news") . ".* FROM " . db_prefix("news") . " INNER JOIN " . db_prefix("accounts") . " ON " . db_prefix("news") . ".accountid = " . db_prefix("accounts") . ".acctid" . " WHERE " . db_prefix("accounts") . ".clanid = " . $session['user']['clanid'] . " ORDER BY " . db_prefix("news") . ".newsid DESC LIMIT " . $maxevents;
            $res = db_query($sql);
            if (db_num_rows($res)) {
                output("`n`n`b`&Recent News for %s:`b`0`n", $claninfo['clanname']);
                rawoutput("<ul type='square'>");
                tlschema("news");
                for ($i = 0; $i < db_num_rows($res); $i++) {
                    $row = db_fetch_assoc($res);
                    tlschema($row['tlschema']);
                    if ($row['arguments'] != "") {
                        $args = unserialize($row['arguments']);
                        array_unshift($args, $row['newstext']);
                        $news = call_user_func_array("sprintf_translate", $args);
                    } else {
                        $news = translate_inline($row['newstext']);
                    }
                    tlschema();
                    if ($i != 0) {
                        clannews_outputseparator();
                    }
                    rawoutput("<li>");
                    output_notl("`@{$news}`0");
                }
                rawoutput("</ul>");
                tlschema();
            }
            break;
    }
    return $args;
}
function injectmodule($modulename, $force = false)
{
    global $mostrecentmodule, $injected_modules;
    //try to circumvent the array_key_exists() problem we've been having.
    if ($force) {
        $force = 1;
    } else {
        $force = 0;
    }
    //early escape if we already called injectmodule this hit with the
    //same args.
    if (isset($injected_modules[$force][$modulename])) {
        $mostrecentmodule = $modulename;
        return $injected_modules[$force][$modulename];
    }
    $modulename = modulename_sanitize($modulename);
    $modulefilename = "modules/{$modulename}.php";
    if (file_exists($modulefilename)) {
        tlschema("module-{$modulename}");
        $sql = "SELECT active,filemoddate,infokeys,version FROM " . db_prefix("modules") . " WHERE modulename='{$modulename}'";
        $result = db_query_cached($sql, "inject-{$modulename}", 3600);
        if (!$force) {
            //our chance to abort if this module isn't currently installed
            //or doesn't meet the prerequisites.
            if (db_num_rows($result) == 0) {
                tlschema();
                output_notl("`n`3Module `#%s`3 is not installed, but was attempted to be injected.`n", $modulename);
                $injected_modules[$force][$modulename] = false;
                return false;
            }
            $row = db_fetch_assoc($result);
            if ($row['active']) {
            } else {
                tlschema();
                output("`n`3Module `#%s`3 is not active, but was attempted to be injected.`n", $modulename);
                $injected_modules[$force][$modulename] = false;
                return false;
            }
        }
        require_once $modulefilename;
        $mostrecentmodule = $modulename;
        $info = "";
        if (!$force) {
            //avoid calling the function if we're forcing the module
            $fname = $modulename . "_getmoduleinfo";
            $info = $fname();
            if (!isset($info['requires'])) {
                $info['requires'] = array();
            }
            if (!is_array($info['requires'])) {
                $info['requires'] = array();
            }
            if (!isset($info['download'])) {
                $info['download'] = "";
            }
            if (!isset($info['description'])) {
                $info['description'] = "";
            }
            if (!module_check_requirements($info['requires'])) {
                $injected_modules[$force][$modulename] = false;
                tlschema();
                output("`n`3Module `#%s`3 does not meet its prerequisites.`n", $modulename);
                return false;
            }
        }
        //check to see if the module needs to be upgraded.
        if (db_num_rows($result) > 0) {
            if (!isset($row)) {
                $row = db_fetch_assoc($result);
            }
            $filemoddate = date("Y-m-d H:i:s", filemtime($modulefilename));
            if ($row['filemoddate'] != $filemoddate || $row['infokeys'] == "" || $row['infokeys'][0] != '|' || $row['version'] == '') {
                //The file has recently been modified, lock tables and
                //check again (knowing we're the only one who can do this
                //at one shot)
                $sql = "LOCK TABLES " . db_prefix("modules") . " WRITE";
                db_query($sql);
                //check again after the table has been locked.
                $sql = "SELECT filemoddate FROM " . db_prefix("modules") . " WHERE modulename='{$modulename}'";
                $result = db_query($sql);
                $row = db_fetch_assoc($result);
                if ($row['filemoddate'] != $filemoddate || !isset($row['infokeys']) || $row['infokeys'] == "" || $row['infokeys'][0] != '|' || $row['version'] == '') {
                    //the file mod time is still different from that
                    //recorded in the database, time to update the database
                    //and upgrade the module.
                    debug("The module {$modulename} was found to have updated, upgrading the module now.");
                    if (!is_array($info)) {
                        //we might have gotten this info above, if not,
                        //we need it now.
                        $fname = $modulename . "_getmoduleinfo";
                        $info = $fname();
                        if (!isset($info['download'])) {
                            $info['download'] = "";
                        }
                        if (!isset($info['version'])) {
                            $info['version'] = "0.0";
                        }
                        if (!isset($info['description'])) {
                            $info['description'] = '';
                        }
                    }
                    //Everyone else will block at the initial lock tables,
                    //we'll update, and on their second check, they'll fail.
                    //Only we will update the table.
                    $keys = "|" . join(array_keys($info), "|") . "|";
                    $sql = "UPDATE " . db_prefix("modules") . " SET moduleauthor='" . addslashes($info['author']) . "', category='" . addslashes($info['category']) . "', formalname='" . addslashes($info['name']) . "', description='" . addslashes($info['description']) . "', filemoddate='{$filemoddate}', infokeys='{$keys}',version='" . addslashes($info['version']) . "',download='" . addslashes($info['download']) . "' WHERE modulename='{$modulename}'";
                    db_query($sql);
                    debug($sql);
                    $sql = "UNLOCK TABLES";
                    db_query($sql);
                    // Remove any old hooks (install will reset them)
                    module_wipehooks();
                    $fname = $modulename . "_install";
                    if ($fname() === false) {
                        return false;
                    }
                    invalidatedatacache("inject-{$modulename}");
                } else {
                    $sql = "UNLOCK TABLES";
                    db_query($sql);
                }
            }
        }
        tlschema();
        $injected_modules[$force][$modulename] = true;
        return true;
    } else {
        output("`n`\$Module `^%s`\$ was not found in the modules directory.`n", $modulename);
        $injected_modules[$force][$modulename] = false;
        return false;
    }
}
function waterfall_runevent($type)
{
    global $session;
    // We assume this event only shows up in the forest currently.
    $from = "forest.php?";
    $session['user']['specialinc'] = "module:waterfall";
    $op = httpget('op');
    switch ($op) {
        case "search":
        case "":
            output("`n`2You see a small path that leads away from the main trail. The path is overgrown and you almost didn't see it as you crept by.`n`n");
            output("As you crouch down to study the trail, you notice footprints leading down the path but, oddly, none coming out. While studying the path you hear what sounds like running water.`n");
            addnav("T?Follow the Trail", $from . "op=trail");
            addnav("Continue in the forest", $from . "op=leave");
            break;
        case "trail":
            output("`2You take the path and begin exploring...`n`n");
            $rand = e_rand(1, 12);
            switch ($rand) {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    output("`2After a few hours of exploring you become lost.`n`n");
                    output("`&You `\$lose `&some Stamina finding your way back.`n`n");
                    if ($session['user']['turns'] > 0) {
                        $session['user']['turns']--;
                    }
                    $session['user']['specialinc'] = "";
                    break;
                case 6:
                case 7:
                case 8:
                    output("`^After a few minutes of exploring you find a waterfall!`n`n");
                    output("`2You also notice a small ledge along the rock face of the waterfall.`n");
                    output("Should you walk the ledge?");
                    addnav("Walk the ledge", $from . "op=ledge");
                    addnav("Return to the forest", $from . "op=leaveleave");
                    break;
                case 9:
                case 10:
                case 11:
                case 12:
                    output("`^After a few minutes exploring the area you find a waterfall!`n");
                    output("`2Thirsty from the walk to the falls you are trying to decide whether or not to take a drink.`n");
                    addnav("Take a drink", $from . "op=drink");
                    addnav("Return to the forest", $from . "op=leaveleave");
                    break;
            }
            break;
        case "ledge":
            $session['user']['specialinc'] = "";
            $fall = e_rand(1, 9);
            switch ($fall) {
                case 1:
                case 2:
                case 3:
                case 4:
                    $gems = e_rand(1, 2);
                    output("`&You carefully walk the ledge behind the waterfall and find... `%%s %s`n", $gems, translate_inline($gems == 1 ? "gem" : "gems"));
                    $session['user']['gems'] += $gems;
                    debuglog("found {$gems} gem(s) behind the waterfall.");
                    break;
                case 5:
                case 6:
                case 7:
                case 8:
                    $lhps = round($session['user']['hitpoints'] * 0.25);
                    $session['user']['hitpoints'] -= $lhps;
                    output("`&You carefully walk the ledge behind the waterfall but not carefully enough!`n");
                    output("You slip and fall, hurting yourself.`n`n");
                    output("`4You have lost `\$%s `4hitpoints during your fall.", $lhps);
                    if ($session['user']['gold'] > 0) {
                        $gold = round($session['user']['gold'] * 0.15);
                        output("`4You also notice that you lost `^%s gold `4during the ordeal.`n`n", $gold);
                        $session['user']['gold'] -= $gold;
                        debuglog("lost {$gold} gold when he fell in the water by the waterfall.");
                    }
                    break;
                case 9:
                    output("`7As you are walking the ledge you slip and fall,`n");
                    output("hitting the rocks and the water below!`n`n");
                    output("`4`nYou have died and lost all your gold!");
                    output("`nYou may continue playing tomorrow.`n");
                    $session['user']['turns'] = 0;
                    $session['user']['hitpoints'] = 0;
                    debuglog("lost {$session['user']['gold']} gold when he fell from the top of the waterfall.");
                    $session['user']['gold'] = 0;
                    $session['user']['alive'] = false;
                    addnews("`%The broken body of %s`% was found partially submerged by the rocks under a waterfall.", $session['user']['name']);
                    addnav("Daily News", "news.php");
                    break;
            }
            break;
        case "drink":
            $session['user']['specialinc'] = "";
            $cnt = e_rand(1, 6);
            switch ($cnt) {
                case 1:
                case 2:
                case 3:
                    output("`2You drink from the falls and feel refreshed!`n`n");
                    output("`^You have been restored to full health!");
                    if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                        $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
                    }
                    break;
                case 4:
                    output("`2You walk to the base of the waterfall and drink deeply of the pure water.`n");
                    output("As you drink, you feel a tingling sensation spread all over your body...`n");
                    output("You feel refreshed and healthier than ever!`n`n");
                    $hptype = "permanently";
                    if (!get_module_setting("carrydk") || is_module_active("globalhp") && !get_module_setting("carrydk", "globalhp")) {
                        $hptype = "temporarily";
                    }
                    $hptype = translate_inline($hptype);
                    output("`^Your hitpoints have been restored and your maximum hitpoints have been %s increased by 1.", $hptype);
                    $session['user']['maxhitpoints']++;
                    if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                        $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
                    }
                    set_module_pref("extrahps", get_module_pref("extrahps") + 1);
                    break;
                case 5:
                case 6:
                    output("`2You drink from the falls and you start feeling weird.  You sit down and become ill.`n");
                    output("`4You lose some Stamina while recovering!");
                    if ($session['user']['turns'] > 0) {
                        $session['user']['turns']--;
                    }
                    break;
            }
            break;
        case "leave":
            output("`^You stare at the path for a few more moments trying to get the courage to explore it. A piercing chill runs up your spine that makes you start trembling.  At this point you have decided to stay on the main trail.  You quickly move away from the mysterious trail.");
            $session['user']['specialinc'] = "";
            break;
        case "leaveleave":
            output("`^You decide that discretion is the better part of valor, or at least survival, and return to the forest.");
            $session['user']['specialinc'] = "";
            break;
    }
    output_notl("`0");
}
    output_notl("%s", $row['uniqueid']);
    rawoutput("</td><td>");
    // "43200" used so will basically round to nearest day rather than floor number of days
    $expire = sprintf_translate("%s days", round((strtotime($row['banexpire']) + 43200 - strtotime("now")) / 86400, 0));
    if (substr($expire, 0, 2) == "1 ") {
        $expire = translate_inline("1 day");
    }
    if (date("Y-m-d", strtotime($row['banexpire'])) == date("Y-m-d")) {
        $expire = translate_inline("Today");
    }
    if (date("Y-m-d", strtotime($row['banexpire'])) == date("Y-m-d", strtotime("1 day"))) {
        $expire = translate_inline("Tomorrow");
    }
    if ($row['banexpire'] == "0000-00-00") {
        $expire = translate_inline("Never");
    }
    output_notl("%s", $expire);
    rawoutput("</td><td>");
    output_notl("%s", $row['banreason']);
    rawoutput("</td><td>");
    $file = "user.php?op=removeban&subop=xml&ip={$row['ipfilter']}&id={$row['uniqueid']}";
    rawoutput("<div id='user{$i}'><a href='{$file}' target='_blank' onClick=\"getUserInfo('{$row['ipfilter']}','{$row['uniqueid']}',{$i}); return false;\">");
    output_notl("%s", $showuser, true);
    rawoutput("</a></div>");
    addnav("", $file);
    rawoutput("</td><td>");
    output_notl("%s", relativedate($row['lasthit']));
    rawoutput("</td></tr>");
    $i++;
}
rawoutput("</table>");
                                    $divide = true;
                                    rawoutput("<a href=\"inventory.php?items_transferitem={$itemid}&items_transferto={$carrier}&items_context={$context}&items_sort={$sort}\">Transfer to your {$cvname}</a>");
                                    addnav("", "inventory.php?items_transferitem={$itemid}&items_transferto={$carrier}&items_context={$context}&items_sort={$sort}");
                                }
                            }
                        }
                    }
                }
            }
            if (isset($prefs['inventoryactions'])) {
                rawoutput($prefs['inventoryactions']);
            }
            output_notl("`n`0%s`n", $prefs['description']);
            if (isset($prefs['inventorydisplay'])) {
                output_notl("`0%s`n", $prefs['inventorydisplay']);
            }
            if ($prefs['image']) {
                rawoutput("</td></tr></table>");
            }
            rawoutput("</td></tr>");
        }
        rawoutput("</table>");
    } else {
        output_notl("`bEmpty`b`n");
    }
    rawoutput("</td></tr></table><br />");
}
//handle return links
addnav("Return");
addnav("Back to where you came from", items_return_link($context));
page_footer();
 }
 //clear all standard buffs
 $tempbuf = unserialize($session['user']['bufflist']);
 $session['user']['bufflist'] = "";
 strip_all_buffs();
 tlschema("buffs");
 while (list($key, $val) = @each($tempbuf)) {
     if (array_key_exists('survivenewday', $val) && $val['survivenewday'] == 1) {
         //$session['bufflist'][$key]=$val;
         if (array_key_exists('schema', $val) && $val['schema']) {
             tlschema($val['schema']);
         }
         apply_buff($key, $val);
         if (array_key_exists('newdaymessage', $val) && $val['newdaymessage']) {
             output($val['newdaymessage']);
             output_notl("`n");
         }
         if (array_key_exists('schema', $val) && $val['schema']) {
             tlschema();
         }
     }
 }
 tlschema();
 output("`2Hitpoints have been restored to `^%s`2.`n", $session['user']['maxhitpoints']);
 reset($session['user']['dragonpoints']);
 $dkff = 0;
 while (list($key, $val) = each($session['user']['dragonpoints'])) {
     if ($val == "ff") {
         $dkff++;
     }
 }
function quester_run()
{
    global $session;
    page_header();
    $op = httpget('op');
    $act = httpget('act');
    addnav("Actions");
    switch ($op) {
        case "enter":
            if (get_module_pref("questlevel") == 0) {
                output("You decide to ask Cedrik if he has heard any rumors, but he gives you a very serious look. 'You want to know some Rumors?' he asks, and you start to feel sorry for asking.`n`n");
                output("Cedrik looks at you and says, 'I know of a few rumors for an adventurer like yourself, however you look like the kind of person who would run out to inspect these rumors and get yourself killed.' Are you sure you want to hear them?`n`n");
                addnav("Accept", "runmodule.php?module=quester&op=start");
                addnav("Decline", "inn.php?op=bartender");
            } else {
                if (get_module_pref("completed") == 0) {
                    output("You decide to ask Cedrik if he has heard any rumors. He looks at you as if you were nuts, and says, 'You want more rumors? Why? You already have a quest going from a rumor I told you, and you didn't event finish it. Haven't you gone to %s yet?`n`n", get_module_pref("levelloc"));
                    output("Just a little scared, you wonder if you should ask Cedrik if you can start another quest, or if you should leave him alone lest something bad happen.`n`n");
                    addnav("Abandon Quest", "runmodule.php?module=quester&op=abandon");
                    addnav("Leave", "inn.php?op=bartender");
                } else {
                    output("You tell Cedrik you've finished the quest. 'Oh yeah? Lets see your proof!' he responds. You don't know whether he's pleased with you or not, but you proceed to show him your proof.`n`n");
                    if (get_module_pref("questlevel") == get_module_pref("queststage")) {
                        if (get_module_setting("bossreward") > 0) {
                            output("You start to reach into your backpack, but then you stop and stare at Cedrik realizing that you have no proof, since you banished the %s to another dimension. After a few seconds, Cedrik laughs and says, 'Hahaha, just kidding. I could feel the evil lift from the world, so I know you did it. Good job. Your reward is %s gold, and you definitely deserve it.' `n`n", get_module_pref("levelname"), get_module_setting("bossreward"));
                        } else {
                            output("You start to reach into your backpack, but then you stop and stare at Cedrik realizing that you have no proof, since you banished the %s to another dimension. After a few seconds, Cedrik laughs and says, 'Hahaha, just kidding. I could feel the evil lift from the world, so I know you did it. Good job.' `n`n", get_module_pref("levelname"));
                        }
                        quester_finish();
                    } else {
                        if (get_module_pref("leveltype") == 0) {
                            if (get_module_setting("normreward") > 0) {
                                output("You show him the %s you got from your quest, and Cedrik smiles. 'You've done well, young adventurer. Your reward is %s gold.' `n`n", get_module_pref("levelname"), get_module_setting("normreward"));
                            } else {
                                output("You show him the %s you got from your quest, and Cedrik smiles. 'You've done well, young adventurer.' `n`n", get_module_pref("levelname"));
                            }
                        } else {
                            if (get_module_setting("normreward") > 0) {
                                output("You show him the head of the %s, and Cedrik smiles. 'You've done well, young adventurer. Your reward is %s gold.' `n`n", get_module_pref("levelname"), get_module_setting("normreward"));
                            } else {
                                output("You show him the head of the %s, and Cedrik smiles. 'You've done well, young adventurer.' `n`n", get_module_pref("levelname"));
                            }
                        }
                        quester_nextlvl();
                        if (get_module_pref("questlevel") == get_module_pref("queststage")) {
                            output("This time, Cedrik looks at you more serious than you have ever seen. You begin to tremble just from the way he's looking at you. He says in the most serious tone of voice you have ever heard a man speak in, 'This is it. The preparations are done. It is time to rid the world of this great evil once and for all.'`n`n");
                            output("'It's time I told you the name of this foe. It is known as the `b%s`b, and is very powerful. This foe is immortal, so you cannot defeat him. However, there is another way to rid the world of its evil. Once you beat it down to unconsciousness, you must seal it into another dimension. This will rid the world of it without killing it.'`n`n", get_module_pref("levelname"));
                            output("'You can find this last foe in the forests of `b%s`b. This will be your toughest foe yet, so be cautious. I hope I will see you again in one piece.' Then Cedrik turns back to his drinks, and you decide that you're not getting any younger, so you take a deep breath and head off to rid the world of this evil.`n`n", get_module_pref("levelloc"));
                        } else {
                            if (get_module_pref("leveltype") == 0) {
                                output("Cedrik turns to a scroll and says, 'This part of the quest should be rather easy. You need to go and find the `b%s`b, down in the forests of `b%s`b. This is a very rare and powerful item, and it will help you greatly in your quest, as it's powerful magic can be used to seal away the great foe you must face. Be careful, however, as you never know what dangers you will find with it.' He hands you the scroll and you go off to find and take this item.`n`n", get_module_pref("levelname"), get_module_pref("levelloc"));
                            } else {
                                output("Cedrik leans twards you and says softly, 'This part of the quest could be a little tricky. You need to seek out and kill the `b%s`b, down in the forests of `b%s`b. This is one of your great foe's most loyal underlings, and, if not killed, will come to his aid. This will, in turn, pose a great threat to you as you battle your foe. So go now and kill this evil being.' He leans back and you go off to find and kill this monster.`n`n", get_module_pref("levelname"), get_module_pref("levelloc"));
                            }
                        }
                    }
                    addnav("Continue", "inn.php?op=bartender");
                }
            }
            break;
        case "abandon":
            if ($act == "baby") {
                output("You explain to Cedrik that you are a little baby and you want your bottle. He laughs and says, 'Yeah, I thought so. Ok then, I'll be sure to get someone else to do this for me.'`n`n");
                quester_abandon();
                addnav("Continue", "inn.php?op=bartender");
            } else {
                if ($act == "not") {
                    output("You forget why you said you wanted to stop, and tell Cedrik that if you're a baby he must be a fetus. You start to laugh, but when you notice the look he's giving you, you quiet down. `n`n");
                    output("After about 6 seconds of silence, Cedrik laughs too and says, 'you are the funny one, but rememer not to confuse funny with stupid around me, got it?' You nod, and leave.`n`n");
                    addnav("Continue", "inn.php?op=bartender");
                } else {
                    output("After telling Cedrik you want to abandon the quest, he replies, 'What? Chickening out? I guess I should've expected as much. Fine, I'll go find soneone else to do this. That is, if you're absolutly sure you want to be a baby'`n`n");
                    addnav("I'm a baby.", "runmodule.php?module=quester&op=abandon&act=baby");
                    addnav("I'm not a baby!", "runmodule.php?module=quester&op=abandon&act=not");
                }
            }
            break;
        case "start":
            if (!isset($_GET['level'])) {
                if (get_module_pref("questpoints") == 0) {
                    if ($session['user']['dragonkills'] > 0) {
                        output("Cedrik smiles and says, 'Why, aren't you the brave one. Ok, I know a rumor. I have heard that there is a great monster terrorizing the world, perhaps even more powerful than the Green Dragon itself! I heard that his monster was spawned from all of the evil in this world, which has taken the form of this hideous beast. You look like you have slain the Green Dragon about %s times, so I think you may be just the one for this job.'`n`n", $session['user']['dragonkills']);
                    } else {
                        output("Cedrik smiles and says, 'Why, aren't you the brave one. Ok, I know a rumor. I have heard that there is a great monster terrorizing the world, perhaps even more powerful than the Green Dragon itself! I heard that his monster was spawned from all of the evil in this world, which has taken the form of this hideous beast. I will help you slay this monster, but I'm not sure if you can handel it. At least you seem to be brave enough.'`n`n");
                    }
                } else {
                    output("Cedrik smiles and says, 'You're as brave as ever I see. Ok, I know another rumor, but it won't please you. I have heard that a new being was spawned from the deep evil released from this world by the great monster you killed, perhaps even more powerful than the last one! This new evil being has come back from another world through a dimensional rift, and is once again terrorizing this world. I think you may be just the one for this job. So, do you think you can handle it?'`n`n");
                }
                if (get_module_setting("autolvls") == 0) {
                    if (get_module_setting("lvl2") == 1) {
                        addnav("Accept (lvl2)", "runmodule.php?module=quester&op=start&level=2");
                    }
                    if (get_module_setting("lvl3") == 1) {
                        addnav("Accept (lvl3)", "runmodule.php?module=quester&op=start&level=3");
                    }
                    if (get_module_setting("lvl4") == 1) {
                        addnav("Accept (lvl4)", "runmodule.php?module=quester&op=start&level=4");
                    }
                    if (get_module_setting("lvl5") == 1) {
                        addnav("Accept (lvl5)", "runmodule.php?module=quester&op=start&level=5");
                    }
                    if (get_module_setting("lvl6") == 1) {
                        addnav("Accept (lvl6)", "runmodule.php?module=quester&op=start&level=6");
                    }
                } else {
                    addnav("Accept", "runmodule.php?module=quester&op=start&level=rand");
                }
                addnav("Decline", "inn.php?op=bartender");
            } else {
                if (httpget('level') == "rand") {
                    $randlvl = e_rand(2, 6);
                    while (get_module_setting("lvl" . $randlvl) == 0) {
                        $randlvl = e_rand(2, 6);
                    }
                    quester_start($randlvl);
                } else {
                    quester_start(httpget('level'));
                }
                output("Great. Your courage is admirable, but be warned: you will need more than courage to complete this quest. Now, for your first task.`n`n");
                if (get_module_pref("leveltype") == 0) {
                    output("Cedrik turns to a scroll and says, 'The first part of the quest should be rather easy. You need to go and find the `b%s`b, down in the forests of `b%s`b. This is a very rare and powerful item, and it will help you greatly in your quest, as it's powerful magic can be used to seal away the great foe you must face. Be careful, however, as you never know what dangers you will find with it.' He hands you the scroll and you go off to find and take this item.`n`n", get_module_pref("levelname"), get_module_pref("levelloc"));
                } else {
                    output("Cedrik leans towards you and says softly, 'The first part of the quest could be a little tricky. You need to seek out and kill the `b%s`b, down in the forests of `b%s`b. This is one of your great foe's most loyal underlings, and, if not killed, will come to his aid. This will, in turn, pose a great threat to you as you battle your foe. So go now and kill this evil being.' He leans back and you go off to find and kill this monster.`n`n", get_module_pref("levelname"), get_module_pref("levelloc"));
                }
                addnav("Continue", "inn.php?op=bartender");
            }
            break;
        case "hof":
            page_header("Most Quester Points");
            $acc = db_prefix("accounts");
            $mp = db_prefix("module_userprefs");
            $sql = "SELECT {$acc}.name AS name,\r\n\t    \t\t{$acc}.acctid AS acctid,\r\n\t    \t\t{$mp}.value AS questpoints,\r\n\t    \t\t{$mp}.userid FROM {$mp} INNER JOIN {$acc}\r\n\t    \t\tON {$acc}.acctid = {$mp}.userid\r\n\t    \t\tWHERE {$mp}.modulename = 'quester'\r\n\t    \t\tAND {$mp}.setting = 'questpoints'\r\n\t    \t\tAND {$mp}.value > 1 ORDER BY ({$mp}.value+0)\r\n\t    \t\tDESC limit " . get_module_setting("hoflist") . "";
            $result = db_query($sql);
            $rank = translate_inline("Points");
            $name = translate_inline("Name");
            output("`n`b`c`@Most Quest Points`n`n`c`b");
            rawoutput("<table border='0' cellpadding='2' cellspacing='1' align='center'>");
            rawoutput("<tr class='trhead'><td align=center>{$name}</td><td align=center>{$rank}</td></tr>");
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                if ($row['name'] == $session['user']['name']) {
                    rawoutput("<tr class='trhilight'><td>");
                } else {
                    rawoutput("<tr class='" . ($i % 2 ? "trdark" : "trlight") . "'><td align=left>");
                }
                output_notl("%s", $row['name']);
                rawoutput("</td><td align=right>");
                output_notl("%s", $row['questpoints']);
                rawoutput("</td></tr>");
            }
            rawoutput("</table>");
            addnav("Back to HoF", "hof.php");
            break;
    }
    page_footer();
}
}
addnav("`bHeal Companions`b");
$compheal = false;
foreach ($companions as $name => $companion) {
    if (isset($companion['cannotbehealed']) && $companion['cannotbehealed'] == true) {
    } else {
        $points = $companion['maxhitpoints'] - $companion['hitpoints'];
        if ($points > 0) {
            $compcost = round(log($session['user']['level'] + 1) * ($points + 10) * 1.33);
            addnav(array("%s`0 (`^%s Gold`0)", $companion['name'], $compcost), "healer.php?op=companion&name=" . rawurlencode($name) . "&compcost={$compcost}{$returnline}");
            $compheal = true;
        }
    }
}
tlschema("nav");
addnav("`bReturn`b");
if ($return == "") {
    if ($playerheal || $compheal) {
        addnav("F?Back to the Forest", "forest.php");
        villagenav();
    } else {
        forest(true);
    }
} elseif ($return == "village.php") {
    villagenav();
} else {
    addnav("R?Return whence you came", $return);
}
tlschema();
output_notl("`0");
page_footer();