function drpap_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if ($session['user']['location'] == get_module_setting("paploc") && $session['user']['dragonkills'] >= get_module_setting("dk")) {
                tlschema($args['schemas']['marketnav']);
                addnav($args['marketnav']);
                tlschema();
                addnav("Dr Paprika's Office", "runmodule.php?module=drpap&op=enter");
            }
            break;
        case "changesetting":
            if ($args['setting'] == "villagename") {
                if ($args['old'] == get_module_setting("paploc")) {
                    set_module_setting("paploc", $args['new']);
                }
            }
            break;
        case "dragonkilltext":
            if (get_module_setting("reset") == 1) {
                set_module_pref("count", 0);
            }
            break;
        case "moderate":
            $args['drpap'] = "Dr Paprika's Waiting Room";
            break;
    }
    return $args;
}
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 improbablehousing_furnitureshop_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            tlschema($args['schemas']['marketnav']);
            addnav($args['marketnav']);
            tlschema();
            addnav("Cadfael's Furniture", "runmodule.php?module=improbablehousing_furnitureshop&op=start");
            break;
        case "improbablehousing_sleepslot":
            $hid = $args['hid'];
            $house = $args['house'];
            $rid = $args['rid'];
            $slot = $args['slot'];
            // debug($rid);
            // debug($house);
            if (improbablehousing_getkeytype($house, $rid) >= 100) {
                //player has a master key, or owns the Dwelling
                $furniture = get_items_with_prefs("furniture");
                // debug($furniture);
                if (is_array($furniture)) {
                    addnav("Put down Furniture");
                    foreach ($furniture as $key => $vals) {
                        //debug($vals);
                        addnav("Install Furniture");
                        addnav(array("Put down %s", $vals['verbosename']), "runmodule.php?module=improbablehousing_furnitureshop&op=drop&item=" . $key . "&hid=" . $args['house']['id'] . "&rid=" . $args['rid'] . "&slot=" . $args['slot']);
                    }
                }
            }
            break;
    }
    return $args;
}
function iitems_hunterslodge_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "superuser":
            if ($session['user']['superuser'] & SU_EDIT_USERS) {
                addnav("Hunter's Lodge Purchase Log", "runmodule.php?module=iitems_hunterslodge&op=superuser");
            }
            break;
        case "village":
            tlschema($args['schemas']['fightnav']);
            addnav($args['fightnav']);
            tlschema();
            blocknav("lodge.php");
            addnav("L?The Hunter's Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
        case "newday":
            if ($session['user']['referer'] > 0) {
                $sql = "SELECT lastip, uniqueid FROM " . db_prefix("accounts") . " WHERE acctid={$session['user']['referer']}";
                $result = db_query($sql);
                $row = db_fetch_assoc($result);
                if ($row['lastip'] != $session['lastip'] && $row['uniqueid'] != $session['uniqueid']) {
                    $sql = "UPDATE " . db_prefix("accounts") . " SET donation=donation+1 WHERE acctid={$session['user']['referer']}";
                    $result = db_query($sql);
                }
            }
            break;
        case "items-returnlinks":
            $args['lodge'] = "runmodule.php?module=iitems_hunterslodge&op=start";
            break;
    }
    return $args;
}
function gauntlet_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "hprecalc":
            $args['total'] -= get_module_pref("extrahps");
            if (!get_module_setting("carrydk")) {
                $args['extra'] -= get_module_pref("extrahps");
                set_module_pref("extrahps", 0);
            }
            break;
        case "dragonkill":
            set_module_pref("seendk", 0);
            break;
        case "newday":
            set_module_pref("seen", 0);
            break;
        case "village":
            tlschema($args['schemas']['fightnav']);
            addnav($args["fightnav"]);
            tlschema();
            addnav("The Gauntlet", "runmodule.php?module=gauntlet");
            break;
    }
    return $args;
}
function relativedate(string $indate) : string
{
    $lastOn = round((strtotime('now') - strtotime($indate)) / 86400, 0) . 'days';
    tlschema('datetime');
    if (substr($lastOn, 0, 2) == '1 ') {
        $lastOn = translate_inline('1 day');
    } else {
        if (date('Y-m-d', strtotime($lastOn)) == date('Y-m-d')) {
            $lastOn = translate_inline('Today');
        } else {
            if (date('Y-m-d', strtotime($lastOn)) == date('Y-m-d', strtotime('-1 day'))) {
                $lastOn = translate_inline('Yesterday');
            } else {
                if (strpos($indate, '0000-00-00') !== false) {
                    $lastOn = translate_inline('Never');
                } else {
                    $lastOn = sprintf_translate('%s days', round((strtotime('now') - strtotime($indate)) / 86400, 0));
                    rawoutput(tlbutton_clear());
                }
            }
        }
    }
    tlschema();
    return $lastOn;
}
function maikopan_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if (get_module_pref("plotpoint3a", "watcher_quests") && !get_module_pref("plotpoint1") && $session['user']['location'] == "Kittania") {
                output("`0You hear quite a commotion coming from Maiko's cookery school.  A clattering of pots and pans, and a hoarse, screeching voice: \"`i`%Where is it?  WHERE IS IT?!`i`0\"`n`nYou might want to check that out.`n`n");
                addnav($args['fightnav']);
                tlschema();
                blocknav("runmodule.php?module=meatschool&op=start");
                addnav("Maiko's Cookery Academy", "runmodule.php?module=maikopan&step=1");
            } else {
                if (get_module_pref("plotpoint1") && !get_module_pref("plotpoint2")) {
                    blocknav("runmodule.php?module=meatschool&op=start");
                }
            }
            break;
        case "pub_kittania":
            if (get_module_pref("plotpoint1") && !get_module_pref("plotpoint2")) {
                redirect("runmodule.php?module=maikopan&step=2");
            }
            break;
    }
    return $args;
}
function checkban(string $login, bool $connect = false) : bool
{
    global $session;
    $accounts = db_prefix('accounts');
    $bans = db_prefix('accounts');
    $today = date('Y-m-d');
    $sql = db_query("SELECT lastip, uniquid, banoverride, superuser FROM {$accounts}\n        WHERE login = '******'");
    $row = db_fetch_assoc($sql);
    if ($row['banoverride'] || $row['superuser'] & ~SU_DOESNT_GIVE_GROTTO) {
        return false;
    }
    db_free_result($sql);
    $sql = db_query("SELECT * FROM {$bans}\n        WHERE (\n            (ipfilter = '{$row['lastip']}' OR ipfilter = '{$_SERVER['REMOTE_ADDR']}')\n            OR (uniqueid = '{$row['uniqueid']}' OR uniqueid = '{$_COOKIE['lgi']}')\n        )\n        AND (banexpire = '000-00-00' OR banexpire >= '{$today}')");
    if (db_num_rows($sql) > 0) {
        if ($connect) {
            $session = [];
            tlschema('ban');
            $session['message'] .= translate_inline('`n`4You fall under a ban currently in place on this website:');
            while ($row = db_fetch_assoc($sql)) {
                $session['message'] .= "`n{$row['banreason']}`n";
                if ($row['banexpire'] == '0000-00-00') {
                    $session['message'] .= translate_inline("`\$This ban is permanent!`0");
                } else {
                    $session['message'] .= sprintf_translate("`^This ban will be removed `\$after`^ %s.`0", date("M d, Y", strtotime($row['banexpire'])));
                }
                db_query("UPDATE {$bans}\n                    SET lasthit = '{$today} 00:00:00'\n                    WHERE ipfilter = '{$row['ipfilter']}'\n                    AND uniqueid = '{$row['uniqueid']}'\n                    ");
            }
            $session['message'] .= translate_inline("`n`4If you wish, you may appeal your ban with the petition link.");
            tlschema();
            header('Location: home.php');
        }
        return true;
    }
    return false;
}
function oldhouse_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "newday":
            set_module_pref("scaretoday", 0);
            break;
        case "changesetting":
            if ($args['setting'] == "villagename") {
                if ($args['old'] == get_module_setting("oldhouseloc")) {
                    set_module_setting("oldhouseloc", $args['new']);
                }
            }
            break;
        case "village":
            if ($session['user']['location'] == get_module_setting("oldhouseloc")) {
                tlschema($args['schemas']['tavernnav']);
                addnav($args['tavernnav']);
                tlschema();
                addnav("O?The Old House", "runmodule.php?module=oldhouse");
            }
            break;
    }
    return $args;
}
function fightnav($allowspecial = true, $allowflee = true, $script = false)
{
    global $PHP_SELF, $session, $newenemies, $companions;
    tlschema("fightnav");
    if ($script === false) {
        $script = substr($PHP_SELF, strrpos($PHP_SELF, "/") + 1) . "?";
    } else {
        if (!strpos($script, "?")) {
            $script .= "?";
            //		}elseif (substr($script,strlen($script)-1)!="&" && !substr($script,strlen($script)-1)=="?"){
        } elseif (substr($script, strlen($script) - 1) != "&") {
            $script .= "&";
        }
    }
    $fight = "Fight";
    $run = "Run";
    if (!$session['user']['alive']) {
        $fight = "F?Torment";
        $run = "R?Flee";
    }
    addnav($fight, $script . "op=fight");
    if ($allowflee) {
        addnav($run, $script . "op=run");
    }
    if ($session['user']['superuser'] & SU_DEVELOPER) {
        addnav("Abort", $script);
    }
    if (getsetting("autofight", 0)) {
        addnav("Automatic Fighting");
        addnav("5?For 5 Rounds", $script . "op=fight&auto=five");
        addnav("1?For 10 Rounds", $script . "op=fight&auto=ten");
        $auto = getsetting("autofightfull", 0);
        if (($auto == 1 || $auto == 2 && !$allowflee) && count($newenemies) == 1) {
            addnav("U?Until End", $script . "op=fight&auto=full");
        } elseif ($auto == 1 || $auto == 2 && !$allowflee) {
            addnav("U?Until current enemy dies", $script . "op=fight&auto=full");
        }
    }
    if ($allowspecial) {
        addnav("Special Abilities");
        modulehook("fightnav-specialties", array("script" => $script));
        if ($session['user']['superuser'] & SU_DEVELOPER) {
            addnav("`&Super user`0", "");
            addnav("!?`&&#149; __GOD MODE", $script . "op=fight&skill=godmode", true);
        }
        modulehook("fightnav", array("script" => $script));
    }
    if (count($newenemies) > 1) {
        addnav("Targets");
        foreach ($newenemies as $index => $badguy) {
            if ($badguy['creaturehealth'] <= 0 || isset($badguy['dead']) && $badguy['dead'] == true) {
                continue;
            }
            addnav(array("%s%s`0", isset($badguy['istarget']) && $badguy['istarget'] ? "`#*`0" : "", $badguy['creaturename']), $script . "op=fight&newtarget={$index}");
        }
    }
    tlschema();
}
function eboy_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            tlschema($args['schemas']['marketnav']);
            addnav($args['marketnav']);
            tlschema();
            addnav("eBoy's Trading Station", "runmodule.php?module=eboy&op=start");
            break;
        case "newday-runonce":
            $eboyitems = get_items_with_settings("eboy");
            //get number of players
            $sql = "SELECT count(acctid) AS c FROM " . db_prefix("accounts") . " WHERE locked=0";
            $result = db_query_cached($sql, "numplayers", 600);
            $row = db_fetch_assoc($result);
            $numplayers = $row['c'];
            $sql = "SELECT * from " . db_prefix("cityprefs");
            $result = db_query($sql);
            $numrows = db_num_rows($result);
            for ($i = 0; $i < $numrows; $i++) {
                $row = db_fetch_assoc($result);
                $cid = $row['cityid'];
                foreach ($eboyitems as $item => $settings) {
                    //Advance Multiplier
                    if ($settings['eboy_multiplier_' . $cid]) {
                        if ($settings['eboy_stock_' . $cid] < $numplayers / 10) {
                            increment_item_setting("eboy_multiplier_" . $cid, 0.1, $item);
                        } else {
                            if ($settings['stock_' . $cid] > $numplayers / 5) {
                                increment_item_setting("eboy_multiplier_" . $cid, -0.1, $item);
                            }
                        }
                        //stop prices staying ridiculously low
                        if (get_item_setting("eboy_multiplier_" . $cid, $item) < 0.1) {
                            set_item_setting("eboy_multiplier_" . $cid, 0.1, $item);
                        }
                        //or going ridiculously high
                        if (get_item_setting("eboy_multiplier_" . $cid, $item) > 50) {
                            set_item_setting("eboy_multiplier_" . $cid, 50, $item);
                        }
                    } else {
                        set_item_setting("eboy_multiplier_" . $cid, 1, $item);
                    }
                    if (!isset($settings['eboy_stock_' . $cid])) {
                        set_item_setting("eboy_stock_" . $cid, 1, $item);
                    }
                    increment_item_setting("eboy_stock_" . $cid, $settings['eboy_dailyadd'], $item);
                }
            }
            break;
        case "items-returnlinks":
            $args['eboy'] = "runmodule.php?module=eboy&op=start";
            break;
    }
    return $args;
}
function logd_error_handler($errno, $errstr, $errfile, $errline)
{
    global $session;
    static $in_error_handler = 0;
    // If we have used the @ operator, just don't report anything!
    if (!error_reporting()) {
        return;
    }
    $in_error_handler++;
    if ($in_error_handler > 1) {
        //prevents the error handler from being re-called when we're already within a call of it.
        if ($errno & (E_USER_WARNING | E_WARNING)) {
            echo "PHP Warning: \"{$errstr}\"<br>in <b>{$errfile}</b> at <b>{$errline}</b>.  Additionally this occurred while within logd_error_handler().<br>";
        } elseif ($errno & (E_USER_ERROR | E_ERROR)) {
            echo "PHP ERROR: \"{$errstr}\"<br>in <b>{$errfile}</b> at <b>{$errline}</b>.  Additionally this occurred while within logd_error_handler().<br>";
        }
        $in_error_handler--;
        return;
    }
    switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
            if (getsetting('show_notices', 0) && $session['user']['superuser'] & SU_SHOW_PHPNOTICE) {
                debug("PHP Notice: \"{$errstr}\"<br>in <b>{$errfile}</b> at <b>{$errline}</b>.");
            }
            break;
        case E_WARNING:
        case E_USER_WARNING:
            require_once "show_backtrace.php";
            tlschema("errorhandler");
            output("PHP Warning: \"%s\"`nin `b%s`b at `b%s`b.`n", $errstr, $errfile, $errline, true);
            tlschema();
            $backtrace = show_backtrace();
            rawoutput($backtrace);
            if (getsetting("notify_on_warn", 0) > "") {
                //$args = func_get_args();
                //call_user_func_array("logd_error_notify",$args);
                logd_error_notify($errno, $errstr, $errfile, $errline, $backtrace);
            }
            break;
        case E_ERROR:
        case E_USER_ERROR:
            require_once "lib/show_backtrace.php";
            echo sprintf("PHP ERROR: \"%s\"<br>in <b>%s</b> at <b>%s</b>.<br>", $errstr, $errfile, $errline);
            $backtrace = show_backtrace();
            echo $backtrace;
            if (getsetting("notify_on_error", 0) > "") {
                //$args = func_get_args();
                //call_user_func_array("logd_error_notify",$args);
                logd_error_notify($errno, $errstr, $errfile, $errline, $backtrace);
            }
            die;
            break;
    }
    $in_error_handler--;
}
function dwellingseditor_run()
{
    global $session;
    tlschema("dwellingseditor");
    $op = httpget('op');
    if ($op != "lookup") {
        page_header("Dwellings Editor");
    }
    addnav("Navigation");
    addnav("Back to the Grotto", "superuser.php");
    if ($op != "") {
        addnav("Dwelling List", "runmodule.php?module=dwellingseditor");
    }
    addnav("Find Dwellings by User", "runmodule.php?module=dwellingseditor&op=usersearch");
    addnav("Operations");
    if ($op != "typsu") {
        addnav("Type Pref Editor", "runmodule.php?module=dwellingseditor&op=typesu");
    }
    modulehook("dwellingseditor-main");
    $typeid = httpget("typeid");
    $dwid = httpget('dwid');
    $type = httpget("type");
    if ($type == "" && $dwid > 0) {
        $sql = "SELECT type FROM " . db_prefix("dwellings") . " WHERE dwid={$dwid}";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        $type = $row['type'];
    }
    if ($dwid > 0) {
        addnav("Operations");
        if ($op != "edit") {
            addnav("Edit Dwelling Details", "runmodule.php?module=dwellingseditor&op=edit&dwid={$dwid}");
        }
        if ($op != "keys") {
            addnav("Manage Keys", "runmodule.php?module=dwellingseditor&op=keys&dwid={$dwid}");
        }
        if ($session['user']['superuser'] & SU_EDIT_COMMENTS) {
            addnav("Moderate Commentary", "moderate.php?area=dwellings-{$dwid}&dwid={$dwid}");
        }
        if ($op != "delete") {
            addnav("Delete this Dwelling", "runmodule.php?module=dwellingseditor&op=delete&dwid={$dwid}");
        }
        modulehook("dwellingseditor", array("dwid" => $dwid));
        addnav("Navigation");
        if ($op != "coffers") {
            addnav("Coffer Log", "runmodule.php?module=dwellingseditor&op=coffers&dwid={$dwid}");
        }
        if ($op != "dwsu") {
            addnav("Dwelling  Viewer", "runmodule.php?module=dwellingseditor&op=dwsu&dwid={$dwid}");
        }
    }
    require_once "modules/dwellingseditor/case_{$op}.php";
    page_footer();
}
function meatschool_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            addnav($args['fightnav']);
            tlschema();
            addnav("Maiko's Cookery Academy", "runmodule.php?module=meatschool&op=start");
            break;
    }
    return $args;
}
function insultschool_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            addnav($args['fightnav']);
            tlschema();
            addnav("Cuthbert's Academy of Lingual Defence", "runmodule.php?module=insultschool&op=start");
            break;
    }
    return $args;
}
function handle_event($location, $baseLink = false, $needHeader = false)
{
    if ($baseLink === false) {
        global $PHP_SELF;
        $baseLink = substr($PHP_SELF, strrpos($PHP_SELF, "/") + 1) . "?";
    } else {
        //debug("Base link was specified as $baseLink");
        //debug(debug_backtrace());
    }
    global $session, $playermount, $badguy;
    $skipdesc = false;
    tlschema("events");
    $allowinactive = false;
    $eventhandler = httpget('eventhandler');
    if ($session['user']['superuser'] & SU_DEVELOPER && $eventhandler != "") {
        $allowinactive = true;
        $array = preg_split("/[:-]/", $eventhandler);
        if ($array[0] == "module") {
            $session['user']['specialinc'] = "module:" . $array[1];
        } else {
            $session['user']['specialinc'] = "";
        }
    }
    $_POST['i_am_a_hack'] = 'true';
    if ($session['user']['specialinc'] != "") {
        $specialinc = $session['user']['specialinc'];
        $session['user']['specialinc'] = "";
        if ($needHeader !== false) {
            page_header($needHeader);
        }
        output("`^`c`bSomething Special!`c`b`0");
        if (strchr($specialinc, ":")) {
            $array = split(":", $specialinc);
            $starttime = getmicrotime();
            module_do_event($location, $array[1], $allowinactive, $baseLink);
            $endtime = getmicrotime();
            if ($endtime - $starttime >= 1.0 && $session['user']['superuser'] & SU_DEBUG_OUTPUT) {
                debug("Slow Event (" . round($endtime - $starttime, 2) . "s): {$hookname} - {$row['modulename']}`n");
            }
        }
        if (checknavs()) {
            // The page rendered some linkage, so we just want to exit.
            page_footer();
        } else {
            $skipdesc = true;
            $session['user']['specialinc'] = "";
            $session['user']['specialmisc'] = "";
            httpset("op", "");
        }
    }
    tlschema();
    return $skipdesc;
}
function uniqueforests_dohook($hookname, $args)
{
    global $session;
    require_once "modules/cityprefs/lib.php";
    $cityid = get_cityprefs_cityid("location", $session['user']['location']);
    switch ($hookname) {
        case "collect-events":
            if (get_module_objpref("city", $cityid, "use")) {
                foreach ($args as $index => $event) {
                    $event['rawchance'] = 0;
                    $events[$index] = $event;
                }
                $args = $events;
            }
            break;
        case "village":
            if (get_module_objpref("city", $cityid, "use")) {
                addnav($args['gatenav']);
                $name = get_module_objpref("city", $cityid, "name");
                blocknav("forest.php");
                addnav(array("%s", $name), "forest.php?location=uniqueforests");
            }
            break;
        case "header-forest":
            if (httpget('location') == "uniqueforests" || get_module_objpref("city", $cityid, "use")) {
                if (httpget('op') == "") {
                    global $block_new_output;
                    $block_new_output = true;
                }
                blocknav("runmodule.php", true);
                blocknav("healer.php", true);
                tlschema("module-uniqueforests");
            }
            break;
        case "footer-forest":
            if (httpget('location') == "uniqueforests" || get_module_objpref("city", $cityid, "use")) {
                $name = get_module_objpref("city", $cityid, "name");
                page_header(color_sanitize($name));
            }
            break;
        case "forest-desc":
            if (httpget('location') == "uniqueforests" || get_module_objpref("city", $cityid, "use")) {
                page_header(color_sanitize($name));
                global $block_new_output;
                $block_new_output = false;
                output(get_module_objpref("city", $cityid, "desc"));
                $block_new_output = true;
            }
            break;
    }
    return $args;
}
function forest($noshowmessage = false)
{
    global $session, $playermount;
    tlschema("forest");
    //	mass_module_prepare(array("forest", "validforestloc"));
    addnav("Heal");
    addnav("H?Hospital Tent", "healer.php");
    addnav("Fight");
    addnav("L?Look for Something to Kill", "forest.php?op=search");
    if ($session['user']['level'] > 1) {
        addnav("S?Go Slumming", "forest.php?op=search&type=slum");
    }
    addnav("T?Go Thrillseeking", "forest.php?op=search&type=thrill");
    if (getsetting("suicide", 0)) {
        if (getsetting("suicidedk", 10) <= $session['user']['dragonkills']) {
            addnav("*?Search `\$Suicidally`0", "forest.php?op=search&type=suicide");
        }
    }
    if ($session['user']['level'] >= 15 && $session['user']['seendragon'] == 0) {
        // Only put the green dragon link if we are a location which
        // should have a forest.   Don't even ask how we got into a forest()
        // call if we shouldn't have one.   There is at least one way via
        // a superuser link, but it shouldn't happen otherwise.. We just
        // want to make sure however.
        $isforest = 0;
        $vloc = modulehook('validforestloc', array());
        foreach ($vloc as $i => $l) {
            if ($session['user']['location'] == $i) {
                $isforest = 1;
                break;
            }
        }
        if ($isforest || count($vloc) == 0) {
            addnav("G?`@Seek Out the Green Dragon", "forest.php?op=dragon");
        }
    }
    addnav("Other");
    villagenav();
    if ($noshowmessage != true) {
        output("`c`7`bThe Forest`b`0`c");
        output("The Forest, home to evil creatures and evildoers of all sorts.`n`n");
        output("The thick foliage of the forest restricts your view to only a few yards in most places.");
        output("The paths would be imperceptible except for your trained eye.");
        output("You move as silently as a soft breeze across the thick moss covering the ground, wary to avoid stepping on a twig or any of the numerous pieces of bleached bone that populate the forest floor, lest you betray your presence to one of the vile beasts that wander the forest.`n");
        modulehook("forest-desc");
    }
    modulehook("forest", array());
    module_display_events("forest", "forest.php");
    addnav("Inventory");
    addnav("View your Inventory", "inventory.php?items_context=forest");
    tlschema();
}
function counciloffices_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            tlschema($args['schemas']['fightnav']);
            addnav($args['fightnav']);
            tlschema();
            addnav("Council Offices", "runmodule.php?module=counciloffices&councilop=enter");
            break;
    }
    return $args;
}
function catapult_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            tlschema($args['schemas']['fightnav']);
            addnav($args['fightnav']);
            tlschema();
            addnav("Visit the Travel Agents", "runmodule.php?module=catapult&op=examine");
            break;
    }
    return $args;
}
function luggagehut_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            tlschema($args['schemas']['marketnav']);
            addnav($args['marketnav']);
            tlschema();
            addnav("The Luggage Hut", "runmodule.php?module=luggagehut&op=start");
            break;
    }
    return $args;
}
function heidi_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            $allowgift = get_module_setting("allowgift");
            $allowdp = get_module_setting("allowdp");
            $changeallowed = get_module_setting("changeallowed");
            // disable for farmies lower than level 10
            if (($allowgift || $allowdp || $changeallowed > 0) && ($session['user']['dragonkills'] > 0 || $session['user']['level'] >= 10)) {
                tlschema($args['schemas']['marketnav']);
                addnav($args['marketnav']);
                tlschema();
                addnav("H?Heidi's Place", "runmodule.php?module=heidi");
            }
            break;
        case "newday":
            if ($args['resurrection'] != 'true') {
                set_module_pref("pvpchange", 0);
            }
            set_module_pref("pendingdp", 0);
            $turns = getsetting("turns", 10) + $session['user']['spirits'];
            reset($session['user']['dragonpoints']);
            while (list($key, $val) = each($session['user']['dragonpoints'])) {
                if ($val == "ff") {
                    $turns++;
                }
            }
            set_module_pref("newdayturns", $turns);
            $echance = e_rand(0, 100);
            $mult = e_rand(200, 400);
            $addgold = round($mult * ($session['user']['level'] / max(10, $session['user']['dragonkills'])));
            if ($session['user']['dragonkills'] < 6) {
                $addgold * 1.5;
            }
            if ($echance >= get_module_setting("findperc")) {
                $addgold = 0;
            }
            set_module_pref("addgold", $addgold);
            if ($addgold > 1) {
                // they are a recipient
                $session['user']['gold'] += $addgold;
                output("`n`5Beside your pillow is a small leather bag containing %s gold, and a note: `^Blessings to ye, child, for someone cared enough to send ye a gift.", $addgold);
                output("`5Wondering who it is from, you add it to your purse.`n");
                debuglog("gained {$addgold} gold from an anonymous gift.");
            }
            break;
    }
    return $args;
}
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 haberdasher_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if ($session['user']['location'] == getsetting("villagename", LOCATION_FIELDS)) {
                tlschema($args['schemas']['marketnav']);
                addnav($args["marketnav"]);
                tlschema();
                addnav("D?Deimos' Haberdashery", "runmodule.php?module=haberdasher");
            }
            break;
        case "biostat":
            if (get_module_pref("hatsize", false, $args['acctid'])) {
                output("`^Hat Size: `@%s`n", get_module_pref("hatsize", false, $args['acctid']));
            }
            break;
        case "dragonkilltext":
            $losepercent = get_module_setting("losepercent");
            $hatgold = get_module_pref("hatgold");
            if ($losepercent > 0 && $hatgold > 0) {
                $losepercent /= 100;
                $loseamount = floor($hatgold * $losepercent);
                $hatgold -= $loseamount;
                if ($hatgold <= get_module_setting("lowesthat")) {
                    output("`n`nYou find a hat nearby, but it's too badly burnt to be worth wearing.");
                    $hatgold = 0;
                } else {
                    output("`n`nYou find a hat nearby, somewhat burnt, but still wearable.");
                }
                set_module_pref("hatgold", $hatgold);
                $hatsize = haberdasher_sizecalc($session['user']['acctid']);
            }
            break;
        case "validateprefs":
            if (isset($args['hatsize'])) {
                if (is_numeric($args['hatsize'])) {
                    if (isset($args['hatgold'])) {
                        $hatsize = haberdasher_rawsizecalc($args['hatgold']);
                        if ($hatsize == 0) {
                            $args['hatgold'] = 0;
                        }
                        $args['hatsize'] = $hatsize;
                    }
                }
            }
            break;
    }
    return $args;
}
function allhof_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if ($session['user']['location'] != getsetting("villagename", LOCATION_FIELDS)) {
                tlschema($args['schemas']['infonav']);
                addnav($args['infonav']);
                tlschema();
                addnav("Hall o' Fame", "hof.php?hof=1");
            }
            break;
    }
    return $args;
}
function cakeordeath_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            // if ($session['user']['location'] == get_module_setting("location")) {
            tlschema($args['schemas']['fightnav']);
            addnav($args['fightnav']);
            tlschema();
            addnav("Cake Or Death", "runmodule.php?module=cakeordeath&op=examine");
            // }
            break;
    }
    return $args;
}
function pub_newpittsburgh_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if ($session['user']['location'] == "New Pittsburgh") {
                tlschema($args['schemas']['tavernnav']);
                addnav($args['tavernnav']);
                tlschema();
                addnav("Vigour Mortis", "runmodule.php?module=pub_newpittsburgh&op=start");
            }
            break;
    }
    return $args;
}
function pub_squathole_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if ($session['user']['location'] == "Squat Hole") {
                tlschema($args['schemas']['tavernnav']);
                addnav($args['tavernnav']);
                tlschema();
                addnav("Booz", "runmodule.php?module=pub_squathole&op=start");
            }
            break;
    }
    return $args;
}
function strategyhut_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if (!$session['user']['dragonkills'] || $session['user']['superuser']) {
                tlschema($args['schemas']['marketnav']);
                addnav($args['marketnav']);
                tlschema();
                addnav(" ?The Strategy Hut", "runmodule.php?module=strategyhut");
            }
            break;
    }
    return $args;
}
function pub_kittania_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            if ($session['user']['location'] == "Kittania") {
                tlschema($args['schemas']['tavernnav']);
                addnav($args['tavernnav']);
                tlschema();
                addnav("The Sunny Spot", "runmodule.php?module=pub_kittania&op=start");
            }
            break;
    }
    return $args;
}