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 watcher_quests_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "village":
            require_once "lib/http.php";
            if ($session['user']['level'] > 2 && get_module_pref("plotpoint1") == 0) {
                addnav("", "runmodule.php?module=watcher_quests&plotpoint=1");
                redirect("runmodule.php?module=watcher_quests&plotpoint=1", "Watcher plot point 1");
            }
            if (get_module_pref("plotpoint3") && !get_module_pref("plotpoint3a")) {
                $body = "Thank you for talking to me.  It honestly meant a lot more than I let on.`n`nI would love to come and see you sometime soon, but I have to figure out when I can take the evening off.  It might be a while.`n`nMeanwhile, I hope you'll be okay with this, but I have to act around you the same way I would if we didn't know each other; I could get in a lot of trouble if I'm anything but my usual self while I'm on the Vessel.  I hope you understand.`n`nWith any luck, I'll talk to you properly again soon.`n`n-Watcher";
                require_once "lib/systemmail.php";
                systemmail($session['user']['acctid'], "Thank You", $body, 3517);
                set_module_pref("plotpoint3a", true);
            }
            if ($session['user']['dragonkills'] >= 3 && get_module_pref("plotpoint2") == 0 && $session['user']['gems'] > 1) {
                addnav("", "runmodule.php?module=watcher_quests&plotpoint=2");
                redirect("runmodule.php?module=watcher_quests&plotpoint=2", "Watcher plot point 2");
            }
            break;
        case "mausoleum":
            if ($session['user']['dragonkills'] >= 5 && get_module_pref("plotpoint2") == 1 && get_module_pref("plotpoint3") == 0) {
                output("`n`n`\$The Watcher`0's forehead looks rather shiny.  She tugs distractedly at the collar of her turtleneck.`n`n");
                addnav("That's a shiny, shiny Watcher.");
                addnav("Ask what the deal is with that turtleneck", "runmodule.php?module=watcher_quests&plotpoint=3");
            }
            break;
    }
    return $args;
}
function wcgpoints_supporterpoints_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "wcgpoints_increased":
            if (get_module_pref("gotfirst")) {
                $session['user']['donation'] += 5;
                output("`5`bYou have five extra Supporter Points!`b  Thank you for contributing to humanitarian research.`0`n`n");
            } else {
                if (get_module_pref("runtime", "wcgpoints") > get_module_setting("initialrequirement")) {
                    $session['user']['donation'] += get_module_setting("initialreward");
                    require_once "lib/systemmail.php";
                    $subj = "You've got Supporter Points!";
                    $body = "As a thank-you for helping us to support humanitarian research via grid computing, we've given you 500 Supporter Points completely free of charge.  Thank you so much!  Remember that you'll get five extra Supporter Points every time your World Community Grid points increase (which is usually every 24 hours, if you let the client run regularly).  Have fun!";
                    systemmail($session['user']['acctid'], $subj, $body);
                    set_module_pref("gotfirst", true);
                }
            }
            break;
        case "wcg-features-desc":
            output("`bFree Supporter Points`b: After you've run the World Community Grid client for at least 24 hours (it doesn't have to be all at once - an hour here and an hour there will soon add up), you'll get 500 Supporter Points completely free of charge.  After that, you'll get 5 Supporter Points every time World Community Grid reports that your Cobblestones have increased.`n`n");
            break;
    }
    return $args;
}
function marriage_modifyflirtpoints($who = 1, $amount = 0, $from = -1, $punish = true)
{
    //punish checks if flirting is with beloved one
    global $session;
    //now update the sent
    if ($from == -1) {
        $from = $session['user']['acctid'];
    }
    $list = get_module_pref('flirtssent', 'marriage', $from);
    $list = unserialize($list);
    if ($list == "") {
        $list = array();
    }
    if (array_key_exists("S" . $who, $list)) {
        $list["S" . $who] += $amount;
        //even when negative
    } else {
        $list = array_merge(array("S" . $who => $amount), $list);
    }
    //if ($list["S".$who]<1) $list=array_splice($list,"S".$who,1); //clean up, not working
    set_module_pref('flirtssent', serialize($list), 'marriage', $from);
    //now for the received ones
    $list = get_module_pref('flirtsreceived', 'marriage', $who);
    $list = unserialize($list);
    if ($list == "") {
        $list = array();
    }
    if (array_key_exists("S" . $from, $list)) {
        $list["S" . $from] += $amount;
        //even when negative
    } else {
        $list = array_merge(array("S" . $from => $amount), $list);
    }
    set_module_pref('flirtsreceived', serialize($list), 'marriage', $who);
    //if someone flirted not with the person married to
    if ($session['user']['marriedto'] != 0 && $session['user']['marriedto'] != 4294967295.0 && $who != $session['user']['marriedto'] && $from == $session['user']['acctid'] && $punish && $amount > 0) {
        $mailmessage = array("%s`0`@ has been unfaithful to you!", $session['user']['name']);
        $t = array("`%Uh oh!!");
        require_once "lib/systemmail.php";
        systemmail($session['user']['marriedto'], $t, $mailmessage);
        set_module_pref('flirtsfaith', get_module_pref('flirtsfaith') + 1);
        output("`n`@`c`bShame on you! Don't be unfaithful!`b`c");
        marriage_flirtdec();
    }
}
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_ignore()
{
    global $session;
    $iveignored = rexplode(get_module_pref('iveignored'));
    $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 (db_num_rows($result) > 0 && in_array($ac, $friends)) {
        $row = db_fetch_assoc($result);
        require_once "lib/systemmail.php";
        $t = "`\$Friend List Ignore";
        $mailmessage = array("%s`0`@ has added you to %s ignore list.", $session['user']['name'], $session['user']['sex'] ? translate_inline("her") : translate_inline("his"));
        systemmail($ac, $t, $mailmessage);
        $friends = array_diff($friends, array($ac));
        invalidatedatacache("friendliststat-" . $session['user']['acctid']);
        invalidatedatacache("friendliststat-" . $ac);
    }
    $friends = rimplode($friends);
    set_module_pref('friends', $friends);
    $ignored = rexplode(get_module_pref('ignored', 'friendlist', $ac));
    $ignored[] = $session['user']['acctid'];
    $ignored = rimplode($ignored);
    set_module_pref('ignored', $ignored, 'friendlist', $ac);
    $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);
    if (in_array($ac, $request)) {
        $request = array_diff($request, array($ac));
        $request = rimplode($request);
        set_module_pref('request', $request);
    }
    $iveignored[] = $ac;
    $iveignored = rimplode($iveignored);
    set_module_pref('iveignored', $iveignored);
    output("You have ignored that user, they can no longer YoM you");
}
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 timedcombat_teach_dohook($hookname, $args)
{
    global $session, $last_timestamp;
    switch ($hookname) {
        case "newday":
            set_module_pref("taughttoday", 0);
            break;
        case "biostat":
            if (httpget('op') == "teachtimedcombat") {
                set_module_pref("able", true, "timedcombat", $args['acctid']);
                debug(get_module_pref("able", "timedcombat", $args['acctid']));
                set_module_pref("taughttoday", 1);
                increment_module_pref("taught");
                output("`bYou have successfully taught this character how to do Timed Combat!`b`n");
                if (is_module_active("medals")) {
                    require_once "modules/medals.php";
                    medals_award_medal("timedcombat_teach", "Time Tutor", "This player taught another player how to do Timed Combat!", "medal_timeteacher.png");
                }
                require_once "lib/systemmail.php";
                $subj = $session['user']['name'] . " taught you a new skill!";
                $body = "You can now perform Timed Combat in fights!  If you time your fight commands correctly, you'll get a double-attack and double-defence bonus!  The bonus applies to everything you do in combat.  Try timing your five-round auto-fights - one correct hit wins you five rounds of extra power, and the same goes for ten-round auto-fighting too!  If you don't want to muck about with counting under your breath, you can ignore the new skill and carry on fighting as you've always done.  Get four perfect hits in a row and you can teach other players!  Have fun!";
                systemmail($args['acctid'], $subj, $body);
            }
            $ret = httpget('ret');
            if ($args['acctid'] != $session['user']['acctid'] && !get_module_pref("taughttoday") && get_module_pref("maxchain", "timedcombat") >= 4) {
                //get the players' chat locations from commentaryinfo.php - it's handy!
                $tloc = get_module_pref("loc", "commentaryinfo");
                $sloc = get_module_pref("loc", "commentaryinfo", $args['acctid']);
                if ($tloc == $sloc && !get_module_pref("able", "timedcombat", $args['acctid'])) {
                    output("This player doesn't know how to do Timed Combat.  You can teach one student per game day.`n`n");
                    addnav("Teach this player the Timed Combat skill", "bio.php?op=teachtimedcombat&char=" . $args['acctid'] . "&ret=" . urlencode($ret));
                }
            }
            break;
    }
    return $args;
}
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 hundredpointrally_startnextrally()
{
    $data = unserialize(get_module_setting("data", "hundredpointrally"));
    $data['last'] = $data['current'];
    $data['current'] = $data['next'];
    unset($data['next']);
    //set the current rally's points
    $xmax = get_module_setting("worldmapsizeX", "worldmapen");
    $ymax = get_module_setting("worldmapsizeY", "worldmapen");
    $pointstaken = array();
    //sequenced co-ordinates
    for ($i = 1; $i <= 50; $i++) {
        $proposedpoint = e_rand(1, $xmax) . "," . e_rand(1, $ymax) . ",1";
        //make sure we don't use the same point twice
        while ($pointstaken[$proposedpoint]) {
            debug("Point " . $proposedpoint . " already taken, choosing again");
            $proposedpoint = e_rand(1, $xmax) . "," . e_rand(1, $ymax) . ",1";
        }
        $pointstaken[$proposedpoint] = true;
        $data['current']['sequencedpoints'][$i] = $proposedpoint;
    }
    for ($i = 1; $i <= 50; $i++) {
        $proposedpoint = e_rand(1, $xmax) . "," . e_rand(1, $ymax) . ",1";
        //make sure we don't use the same point twice
        while ($pointstaken[$proposedpoint]) {
            debug("Point " . $proposedpoint . " already taken, choosing again");
            $proposedpoint = e_rand(1, $xmax) . "," . e_rand(1, $ymax) . ",1";
        }
        $pointstaken[$proposedpoint] = true;
        $data['current']['unorderedpoints'][$i] = $proposedpoint;
    }
    //unordered co-ordinates
    $data['current']['open'] = true;
    //notify the players lined up for the next rally that the rally has begun
    require_once "lib/systemmail.php";
    if (count($data['current']['competitors']) > 0) {
        foreach ($data['current']['competitors'] as $key => $vals) {
            $to = $key;
            $subj = "The next Hundred-Point Rally has begun!";
            $body = "This is just a quick message to let you know that the next Hundred-Point Rally has begun!  Head out into the wilderness to find the first Rally Point!";
            systemmail($to, $subj, $body);
            //set them up with the first point
            $player = array();
            $player['sequencedpoints'] = 1;
            $player['activecurrent'] = true;
            $player['activenext'] = false;
            set_module_pref("data", serialize($player), "hundredpointrally", $to);
        }
    }
    set_module_setting("data", serialize($data), "hundredpointrally");
}
                         if ($su) {
                             // send a system message to admins regarding this failed attempt if it includes superusers.
                             $sql = "SELECT acctid FROM accounts WHERE superuser>=3";
                             $result2 = db_query($sql);
                             $subj = "`#{$_SERVER['REMOTE_ADDR']} failed to log in too many times!";
                             for ($i = 0; $i < db_num_rows($result2); $i++) {
                                 $row2 = db_fetch_assoc($result2);
                                 //delete old messages that
                                 $sql = "DELETE FROM mail WHERE msgto={$row2['acctid']} AND msgfrom=0 AND subject = '{$subj}' AND seen=0";
                                 db_query($sql);
                                 if (db_affected_rows() > 0) {
                                     $noemail = true;
                                 } else {
                                     $noemail = false;
                                 }
                                 systemmail($row2['acctid'], "{$subj}", "This message is generated as a result of one or more of the accounts having been a superuser account.  Log Follows:`n`n{$alert}", 0, $noemail);
                             }
                             //end for
                         }
                         //end if($su)
                     }
                     //end if($c>=10)
                 }
                 //end while
             } else {
             }
             //end if (db_num_rows)
             redirect("index.php");
         }
     }
 }
function pointstransfer_run()
{
    global $session;
    require_once "lib/systemmail.php";
    page_header("Hunter's Lodge");
    $op = httpget("op");
    $mint = get_module_setting("mint");
    addnav("L?Return to the Lodge", "lodge.php");
    if ($op == "") {
        $allowed = pointstransfer_pointscheck();
        if ($allowed < $mint) {
            output("`7.J. C. Petersen smiles at your generosity, but leaves the forms where they are.");
            $sallowed = ($allowed > 0 ? "`@" : "`\$") . $allowed;
            if (is_module_active("titlechange")) {
                output("`n`n\"`&I'm sorry, but counting any points used towards title changes, you have %s`& points available, which isn't enough for a transfer.", $sallowed);
            } else {
                output("`n`n\"`&I'm sorry, but you have %s`& points available, which isn't enough for a transfer.", $sallowed);
            }
            if ($mint) {
                output("You need at least `@%s`& points available.`7\"", $mint);
            } else {
                output_notl("`7\"");
            }
        } else {
            output("`7J. C. Petersen smiles at your generosity, and pulls out a form.");
            if (is_module_active("titlechange")) {
                output("`n`n\"`&Including any points used towards title changes, you have `@%s`& points available.", $allowed);
            } else {
                output("`n`n\"`&You have `@%s`& points available.", $allowed);
            }
            if ($mint) {
                output("You have the `@%s`& points needed for a minimum transfer.", $mint);
            }
            output("How many points would you like to transfer, and to whom?`7\"");
            $amount = get_module_pref("amount");
            $target = get_module_pref("target");
            $anon = get_module_pref("anon");
            $note = get_module_pref("note");
            $target = color_sanitize($target);
            rawoutput("<form action='runmodule.php?module=pointstransfer&op=confirm' method='POST'>");
            addnav("", "runmodule.php?module=pointstransfer&op=confirm");
            output("`n`nPoints: ");
            rawoutput("<input name='amount' width='8' value={$amount}>");
            output("`n`nRecipient: ");
            rawoutput("<input name='target' value={$target}>");
            output("`n`nAnonymous Transfer: ");
            rawoutput("<select name='anon'>");
            $no = translate_inline("No");
            $yes = translate_inline("Yes");
            rawoutput("<option value='0'" . ($anon == 0 ? " selected" : "") . ">{$no}</option>");
            rawoutput("<option value='1'" . ($anon == 1 ? " selected" : "") . ">{$yes}</option>");
            rawoutput("</select>");
            output("`n`nOptional Note:");
            rawoutput("<input size='75' name='note' value={$note}>");
            output_notl("`n`n");
            $click = translate_inline("Confirm");
            rawoutput("<input type='submit' class='button' value='{$click}'>");
            rawoutput("</form>");
        }
    } elseif ($op == "confirm") {
        $amount = abs((int) httppost("amount"));
        $target = httppost("target");
        $anon = httppost("anon");
        $note = preg_replace("/[`][bic]/", "", stripslashes(httppost("note")));
        set_module_pref("amount", $amount);
        set_module_pref("target", $target);
        set_module_pref("anon", $anon);
        set_module_pref("note", $note);
        if (!$amount) {
            output("`7J. C. Petersen gives you an odd look.");
            output("`n`n\"`&Why would you give someone zero points?");
            output("Perhaps you should try again when you're thinking more clearly?`7\"");
            addnav("Try Again", "runmodule.php?module=pointstransfer");
        } elseif ($amount < $mint) {
            output("`7J. C. Petersen gives you an odd look.");
            output("`n`n\"`&I'm sorry, but you need to donate at least `@%s`& points.", $mint);
            output("Perhaps you should try again, giving more?`7\"");
            addnav("Try Again", "runmodule.php?module=pointstransfer");
        } elseif ($amount > pointstransfer_pointscheck()) {
            output("`7J. C. Petersen gives you an odd look.");
            output("`n`n\"`&I'm sorry, but you don't have `@%s`& points to give.", $amount);
            output("Perhaps you should try again with less, or donate more?`7\"");
            addnav("Try Again", "runmodule.php?module=pointstransfer");
        } else {
            $newtarget = "";
            for ($x = 0; $x < strlen($target); $x++) {
                $newtarget .= substr($target, $x, 1) . "%";
                //Eric rocks.
            }
            $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE name LIKE '%" . addslashes($newtarget) . "' AND locked=0";
            $result = db_query($sql);
            if (!db_num_rows($result)) {
                output("`7J. C. Petersen gives you an odd lock.");
                output("`n`n\"`&I'm sorry, but I don't know anyone by that name.");
                output("Perhaps you should try again?`7\"");
                addnav("Try Again", "runmodule.php?module=pointstransfer");
            } elseif (db_num_rows($result) > 50) {
                output("`7J. C. Petersen gives you an odd lock.");
                output("`n`n\"`&I'm sorry, but there's way too many people who might go by that name.");
                output("Perhaps you should narrow it down, next time?`7\"");
                addnav("Try Again", "runmodule.php?module=pointstransfer");
            } elseif (db_num_rows($result) > 1) {
                rawoutput("<form action='runmodule.php?module=pointstransfer&op=send' method='POST'>");
                addnav("", "runmodule.php?module=pointstransfer&op=send");
                addnav("Start Over", "runmodule.php?module=pointstransfer");
                output("`7J. C. Petersen looks at you.");
                output("`n`n\"`&There's a few people I know by that name.");
                output("Tell me which one you mean, and I'll send those points right off.`7\"");
                output("`n`nPoints: `@%s`7", $amount);
                output("`n`nRecipient: ");
                rawoutput("<select name='target'>");
                for ($i = 0; $i < db_num_rows($result); $i++) {
                    $row = db_fetch_assoc($result);
                    $name = $row['name'];
                    rawoutput("<option value='{$name}'>" . full_sanitize($name) . "</option>");
                }
                rawoutput("</select>");
                output("`n`nAnonymous Transfer: `&%s`7", $anon ? "Yes" : "No");
                output("`n`nOptional Note: `&%s`7", $note);
                output_notl("`n`n");
                $send = translate_inline("Send");
                rawoutput("<input type='submit' class='button' value='{$send}'>");
                rawoutput("</form>");
            } else {
                addnav("Start Over", "runmodule.php?module=pointstransfer");
                $row = db_fetch_assoc($result);
                $name = $row['name'];
                output("`7J. C. Petersen smiles at you.");
                output("`n`n\"`&This all looks to be in order to me.");
                output("This is what you meant, right?`7\"");
                output("`n`nPoints: `@%s`7", $amount);
                output("`n`nRecipient: `&%s`7", $name);
                output("`n`nAnonymous Transfer: `&%s`7", $anon ? "Yes" : "No");
                output("`n`nOptional Note: `&%s`7", $note ? $note : "`inone`i");
                output_notl("`n`n");
                rawoutput("<form action='runmodule.php?module=pointstransfer&op=send' method='POST'>");
                addnav("", "runmodule.php?module=pointstransfer&op=send");
                rawoutput("<input type='hidden' value='{$name}' name='target'>");
                $send = translate_inline("Send");
                rawoutput("<input type='submit' class='button' value='{$send}'>");
                rawoutput("</form>");
            }
        }
    } elseif ($op == "send") {
        addnav("Send To Someone Else", "runmodule.php?module=pointstransfer");
        $amount = get_module_pref("amount");
        $target = httppost("target");
        if ($target == $session['user']['name']) {
            output("`7J. C. Petersen gives you a weird look and puts down his pen.");
            output("`n`n\"`&Why would you ever want to transfer points to yourself?");
            output("Perhaps you should try again when you're thinking more clearly?`7\"");
        } else {
            $anon = get_module_pref("anon");
            $note = get_module_pref("note");
            $note = $note ? "`n`nThey also added this note:`n" . $note : "";
            $sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE name='{$target}'";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $targetid = $row['acctid'];
            $sql = "UPDATE " . db_prefix("accounts") . " SET donation=donation+{$amount} WHERE acctid={$targetid}";
            db_query($sql);
            $session['user']['donation'] -= $amount;
            if ($anon) {
                systemmail($targetid, array("`@Donator Points Transfer`0"), array("`2Someone has gifted you with `@%s`2 donator points. %s", $amount, $note));
            } else {
                systemmail($targetid, array("`@Donator Points Transfer`0"), array("`&%s`2 has gifted you with `@%s`2 donator points. %s", $session['user']['name'], $amount, $note));
            }
            debuglog($session['user']['name'] . " sent {$amount} donator points to {$target}" . ($anon ? " anonymously." : "."));
            debuglog($session['user']['name'] . " sent {$amount} donator points to {$target}" . ($anon ? " anonymously." : "."), false, $targetid);
            output("`7J. C. Petersen finishes recording the transfer.");
            output("`n`n\"`&Okay, the points have been sent.");
            output("Have a nice day.`7\"");
        }
    }
    page_footer();
}
     systemmail($user, array("Your avatar has been validated!"), array("`^As of now, your avatar will be visible.`n`nRegards`n%s`^`n `&Staff", $session['user']['name']));
     debuglog(sprintf("Avatar was validated by %s - mailed", sanitize($session['user']['name'])), $user, $user);
     $text = "/me`3 validated the avatar of `%{$username}`3 located at " . get_module_pref('avatar', 'avatar', $user);
     require_once "lib/commentary.php";
     injectrawcomment("AvatarVal", $session['user']['acctid'], $text);
 } elseif (httpget('deny') && $ok) {
     $sql = "SELECT name FROM " . db_prefix('accounts') . "  WHERE acctid=" . (int) $user;
     $result = db_query($sql);
     $row = db_fetch_assoc($result);
     $username = $row['name'];
     output("`lAvatar has been set to default picture and user notified to provide a new link!`0`n`n");
     $text = "/me`3 denied the avatar of `%{$username}`3 located at " . get_module_pref('avatar', 'avatar', $user);
     set_module_pref("validated", 1, "avatar", $user);
     set_module_pref("avatar", "modules/avatar/default.jpg", "avatar", $user);
     require_once "./lib/systemmail.php";
     systemmail($user, array("`xYour avatar has `\$NOT`x been validated!"), array("`^Your picture is not within the local policies/rules. Please choose a new one and petition/mail the appropriate link to us. If you want to upload a new one and need the points back, please also do so.`n`nRegards`n%s`^`n `&Staff", $session['user']['name']));
     debuglog(sprintf("Avatar was not found suitable by %s - reset and mailed", sanitize($session['user']['name'])), $user, $user);
     require_once "lib/commentary.php";
     injectrawcomment("AvatarVal", $session['user']['acctid'], $text);
 } else {
     output_notl("`n`n");
 }
 $sql = "SELECT count(u.userid) AS counter FROM " . db_prefix("module_userprefs") . " AS u INNER JOIN " . db_prefix("module_userprefs") . " AS t ON u.userid=t.userid AND u.modulename='avatar' AND u.setting='avatar' AND u.value!='' AND t.modulename='avatar' AND t.setting='validated' AND t.value!='1';";
 $result = db_query($sql);
 $num = db_fetch_assoc($result);
 output("Currently there are %s avatars waiting for validation.`n`n", $num['counter']);
 addnav("Actions");
 if ($num['counter'] > 0) {
     addnav("Random Validate Avatars", "runmodule.php?module=avatar&op=validate&mode=validate");
     $sql = "SELECT a.login as login, u.userid as acctid ,a.name as name,a.emailaddress as email FROM " . db_prefix("module_userprefs") . " AS u INNER JOIN " . db_prefix("module_userprefs") . " AS t RIGHT JOIN " . db_prefix("accounts") . " AS a ON u.userid=t.userid AND a.acctid=u.userid WHERE u.modulename='avatar' AND u.setting='avatar' AND u.value!='' AND t.modulename='avatar' AND t.setting='validated' AND t.value!='1' ORDER BY a.login LIMIT 20;";
     $result = db_query($sql);
 $i = "";
 foreach ($stuff as $val) {
     if ($val != "" && $val != $target && $val != $session['user']['acctid']) {
         $i .= "," . $val;
     }
 }
 set_module_pref('proposals', $i, 'marriage', $target);
 $mailmessage = array("%s`0`@ has rejected you as unfit for marriage! You lose some charm.", $session['user']['name']);
 $t = array("`@Rejection!");
 require_once "lib/systemmail.php";
 systemmail($target, $t, $mailmessage);
 if (get_module_setting('counsel') == 1) {
     $mailmessage = array(translate_inline("`@Hallo. I am Professor van Lipvig, and I haf been paid by.. benefactors, to counsel you due to your Mishap vith %s`@.`nPlease visit me in ze village."), $session['user']['name']);
     $t = array("`@Professor");
     require_once "lib/systemmail.php";
     systemmail($target, $t, $mailmessage);
     $allprefst = unserialize(get_module_pref('allprefs', 'marriage', $target));
     $allprefst['counsel'] = 1;
     set_module_pref('allprefs', serialize($allprefst), 'marriage', $target);
 }
 $sql = "SELECT name,sex,charm FROM " . db_prefix("accounts") . " WHERE acctid='{$target}' AND locked=0";
 $res = db_query($sql);
 $row = db_fetch_assoc($res);
 if (get_module_setting('flirtCharis') == 1 && $row['charm'] != 0) {
     $row['charm']--;
     $sql = "UPDATE " . db_prefix("accounts") . " SET charm=" . $row['charm'] . " WHERE acctid='{$target}'";
     db_query($sql);
 }
 addnews("`&%s`0`& got a marriage proposal from %s`0`&, which %s`0`& rejected, seeing %s`0`& as '`@Unfit for Marriage.`&'", $session['user']['name'], $row['name'], $session['user']['name'], $row['name']);
 addnews("`&%s`0`& is currently moping around the inn.", $row['name']);
 $x = $row['sex'] ? translate_inline("she's") : translate_inline("he's");
 $typeid = get_module_setting("typeid", $row['type']);
 $gold_cost = get_module_objpref("dwellingtypes", $typeid, "cost-gold", "dwellings_pvp");
 $gems_cost = get_module_objpref("dwellingtypes", $typeid, "cost-gems", "dwellings_pvp");
 $daysleft = get_module_objpref("dwellings", $dwid, "run-out", "dwellings_pvp");
 $isauto = get_module_objpref("dwellings", $dwid, "isauto", "dwellings_pvp");
 set_module_objpref("dwellings", $dwid, "run-out", $daysleft - 1, "dwellings_pvp");
 $subj = translate_inline("Concerning Dwellings Guard");
 if ($daysleft == 1) {
     if ($gold_coffer >= $gold_cost && $gems_coffer >= $gems_cost && (get_module_setting("whatif") && $isauto)) {
         $extra = translate_inline("However, you have enough gold and gems inside of your coffers to purchase another Guard. So, we will go ahead and place a guard order when they expire.");
     } else {
         $extra = "";
     }
     $body = sprintf("`@We are sorry to inform you, but your establishment, %s`@, in `^%s`@ will lose the usage of it's personal guard in `\$1 day`@. This is due to the rental time running out. %s`n`nDwellings Commission.", $row['name'], $row['location'], $extra);
     require_once "lib/systemmail.php";
     systemmail($row['ownerid'], $subj, $body);
 } elseif ($daysleft <= 0) {
     if ($gold_coffer >= $gold_cost && $gems_coffer >= $gems_cost && (get_module_setting("whatif") && $isauto)) {
         require_once "modules/dwellings/lib.php";
         dwellings_modify_coffers($dwid, "gold", "-" . $gold_cost);
         dwellings_modify_coffers($dwid, "gems", "-" . $gems_cost);
         $days = get_module_objpref("dwellingtypes", $typeid, "guard-length", "dwellings_pvp");
         invalidatedatacache("objpref-dwellings-{$dwid}-run-out-dwellings_pvp");
         invalidatedatacache("objpref-dwellings-{$dwid}-bought-dwellings_pvp");
         set_module_objpref("dwellings", $dwid, "run-out", $days, "dwellings_pvp");
         set_module_objpref("dwellings", $dwid, "bought", 1, "dwellings_pvp");
     } else {
         invalidatedatacache("objpref-dwellings-{$dwid}-bought-dwellings_pvp");
         set_module_objpref("dwellings", $dwid, "bought", 0, "dwellings_pvp");
     }
 }
            systemmail($row2['keyowner'], array("`2You own a %s`2", $row['type']), $mailmessage);
            $sql = "UPDATE " . db_prefix("dwellings") . " SET ownerid = " . $row2['keyowner'] . " WHERE dwid=" . $row['dwid'];
            db_query($sql);
        }
    }
} elseif (get_module_setting("delete", "dwellings") == 3) {
    //give to partner (with alternatives if null)
    $accounts = db_prefix("accounts");
    $dwellings = db_prefix("dwellings");
    $sql = "SELECT {$accounts}.marriedto AS marriedto,\r\n\t\t\t\t{$dwellings}.dwid AS dwid, \r\n\t\t\t\t{$dwellings}.type AS type, \r\n\t\t\t\t{$dwellings}.location AS location,\r\n\t\t\t\t{$dwellings}.name AS name\r\n\t\t\t\tFROM {$accounts} \r\n\t\t\t\tINNER JOIN {$dwellings} \r\n\t\t\t\tON {$dwellings}.ownerid = {$accounts}.acctid \r\n\t\t\t\tWHERE acctid={$oldacctid}";
    $result = db_query($sql) or die(db_error(LINK));
    while ($row = db_fetch_assoc($result)) {
        if ($row['marriedto'] != 0 && $row['marriedto'] != INT_MAX) {
            //give to partner
            $msg = "`2%s has left this realm, and you are listed as the beneficiary to their %s in %s.  You are now the owner of %s.";
            $mailmessage = array($msg, $oldowner, $row['type'], $row['location'], $row['name']);
            require_once "lib/systemmail.php";
            systemmail($row['marriedto'], array("`2You own a %s`2", $row['type']), $mailmessage);
            $sql = "UPDATE " . db_prefix("dwellings") . " SET ownerid = " . $row['marriedto'] . " WHERE dwid=" . $row['dwid'] . "";
            db_query($sql);
        } else {
            if (!get_module_setting("delete2")) {
                //delete it as a second option
                dwellings_deleteforowner($oldacctid, $row['dwid']);
            } else {
                //abandon as a second option
                dwellings_abandonforowner($oldacctid, $row['dwid']);
            }
        }
    }
}
function titans_award_req($titan)
{
    global $session;
    debug($titan);
    require_once "lib/systemmail.php";
    $treq = 100000;
    //adjust this up or down - this is the Req that will be distributed out to players accordingly
    $kbreq = 1000;
    //Bonus for scoring the killing blow against a Titan
    $players = $titan['battlelog']['combatants'];
    $reqperpoint = $treq / $titan['creature']['spawnhp'];
    //Use the hitpoints that the Titan originally spawned with
    foreach ($players as $key => $vals) {
        //figure out how much to pay them
        $pay = round($vals['dmg'] * $reqperpoint);
        if ($key == $titan['battlelog']['killingblow_acctid']) {
            $pay += $kbreq;
            $msg = "`0As thanks for your heroic efforts in bringing down the Titan, `4The Watcher`0 has awarded you with " . number_format($pay) . " Requisition tokens, deposited straight into your bank account.  This includes a bonus of 1,000 Requisition tokens for dealing the killing blow.  Have fun with those!";
            debug($key . " is the same as " . $titan['battlelog']['killingblow_acctid'] . ", adding extra Req");
        } else {
            //now mail them to let them know
            $msg = "`0As thanks for your heroic efforts in bringing down the Titan, `4The Watcher`0 has awarded you with " . number_format($pay) . " Requisition tokens, deposited straight into your bank account.  Have fun with those!  " . $titan['battlelog']['killingblow_name'] . "`0 scored the killing blow, and gets an additional 1,000 Requisition tokens.  Maybe next time it'll be you!";
        }
        $sql = "UPDATE " . db_prefix("accounts") . " SET goldinbank=goldinbank+{$pay} WHERE acctid={$key}";
        db_query($sql);
        debug("Adding " . $pay . " gold to acctid " . $key);
        systemmail($key, "Titan Rewards", $msg);
    }
    return $titan;
}
                                output("`@Elessa`6 glares at you, her eyes flashing dangerously, \"`@You may not transfer money to yourself!  That makes no sense!`6\"");
                            } else {
                                debuglog("transferred {$amt} gold to", $row['acctid']);
                                $session['user']['gold'] -= $amt;
                                if ($session['user']['gold'] < 0) {
                                    //withdraw in case they don't have enough on hand.
                                    $session['user']['goldinbank'] += $session['user']['gold'];
                                    $session['user']['gold'] = 0;
                                }
                                $session['user']['amountouttoday'] += $amt;
                                $sql = "UPDATE " . db_prefix("accounts") . " SET goldinbank=goldinbank+{$amt},transferredtoday=transferredtoday+1 WHERE acctid='{$row['acctid']}'";
                                db_query($sql);
                                output("`@Elessa`6 smiles, \"`@The transfer has been completed!`6\"");
                                $subj = array("`^You have received a money transfer!`0");
                                $body = array("`&%s`6 has transferred `^%s`6 gold to your bank account!", $session['user']['name'], $amt);
                                systemmail($row['acctid'], $subj, $body);
                            }
                        }
                    }
                }
            }
        } else {
            output("`@Elessa`6 looks up from her ledger with a bit of surprise on her face, \"`@I'm terribly sorry, but I seem to have run into an accounting error, would you please try telling me what you wish to transfer again?`6\"");
        }
    }
} elseif ($op == "deposit") {
    output("`0");
    rawoutput("<form action='bank.php?op=depositfinish' method='POST'>");
    $balance = translate_inline("`@Elessa`6 says, \"`@You have a balance of `^%s`@ gold in the bank.`6\"`n");
    $debt = translate_inline("`@Elessa`6 says, \"`@You have a `\$debt`@ of `^%s`@ gold to the bank.`6\"`n");
    output_notl($session['user']['goldinbank'] >= 0 ? $balance : $debt, abs($session['user']['goldinbank']));
                            $sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE (superuser&" . SU_EDIT_USERS . ")";
                            $result2 = db_query($sql);
                            $subj = translate_mail(array("`#%s failed to log in too many times!", $_SERVER['REMOTE_ADDR']), 0);
                            $number = db_num_rows($result2);
                            for ($i = 0; $i < $number; $i++) {
                                $row2 = db_fetch_assoc($result2);
                                //delete old messages that
                                $sql = "DELETE FROM " . db_prefix("mail") . " WHERE msgto={$row2['acctid']} AND msgfrom=0 AND subject = '" . serialize($subj) . "' AND seen=0";
                                db_query($sql);
                                if (db_affected_rows() > 0) {
                                    $noemail = true;
                                } else {
                                    $noemail = false;
                                }
                                $msg = translate_mail(array("This message is generated as a result of one or more of the accounts having been a superuser account.  Log Follows:`n`n%s", $alert), 0);
                                systemmail($row2['acctid'], $subj, $msg, 0, $noemail);
                            }
                            //end for
                        }
                        //end if($su)
                    }
                    //end if($c>=10)
                }
                //end while
            }
            //end if (db_num_rows)
            redirect("index.php");
        }
    }
} else {
    if ($op == "logout") {
function petitionfixnavs_run()
{
    global $session;
    page_header("Fixed Navs");
    $id = httpget('id');
    $op = httpget('op');
    switch ($op) {
        case "cnext":
            $nextid = httpget('nextid');
            $sql = "UPDATE " . db_prefix("petitions") . " SET status=2,closeuserid='{$session['user']['acctid']}',closedate='" . date("Y-m-d H:i:s") . "' WHERE petitionid='{$id}'";
            db_query($sql);
            pt_insert(translate_inline("/me has closed the petition"));
            invalidatedatacache("petition_counts");
            redirect("viewpetition.php?op=view&id={$nextid}");
            break;
        case "cfnext":
            $sql = "SELECT author FROM " . db_prefix("petitions") . " WHERE petitionid='{$id}'";
            $result = db_query($sql);
            $author = db_fetch_assoc($result);
            debug($author);
            if (!$author) {
                output_notl("Error! Please give a detailed error report to the Petition Fixnavs Module Author!");
                page_footer();
                return;
            }
            $author = $author['author'];
            $sql = "UPDATE " . db_prefix("accounts") . " SET allowednavs='',specialinc='' WHERE acctid={$author}";
            $result = db_query($sql);
            $sql = "UPDATE " . db_prefix("accounts_everypage") . " SET allowednavs='' WHERE acctid={$author}";
            $result = db_query($sql);
            invalidatedatacache("accounts/account_" . $author);
            $sql = "DELETE FROM " . db_prefix("accounts_output") . " WHERE acctid={$author}";
            $result = db_query($sql);
            $nextid = httpget('nextid');
            $sql = "UPDATE " . db_prefix("petitions") . " SET status=2,closeuserid='{$session['user']['acctid']}',closedate='" . date("Y-m-d H:i:s") . "' WHERE petitionid='{$id}'";
            db_query($sql);
            pt_insert(translate_inline("/me has fixed navs and closed the petition"));
            require_once "lib/systemmail.php";
            systemmail($author, array("Your petition"), array("Your navs have been fixed, you should be able to navigate from the stuck page now. If not, please petition again. (This is an automatic message).`n`nRegards %s", $session['user']['name']));
            invalidatedatacache("petition_counts");
            redirect("viewpetition.php?op=view&id={$nextid}");
            break;
        default:
            $sql = "SELECT author FROM " . db_prefix("petitions") . " WHERE petitionid='{$id}'";
            $result = db_query($sql);
            $author = db_fetch_assoc($result);
            debug($author);
            if (!$author) {
                output_notl("Error! Could not find that user!!");
                page_footer();
                return;
            }
            $author = $author['author'];
            $sql = "UPDATE " . db_prefix("accounts") . " SET allowednavs='',specialinc='' WHERE acctid={$author}";
            $result = db_query($sql);
            $sql = "UPDATE " . db_prefix("accounts_everypage") . " SET allowednavs='' WHERE acctid={$author}";
            $result = db_query($sql);
            invalidatedatacache("accounts/account_" . $author);
            pt_insert(translate_inline("/me has fixed this users navs"));
            require_once "lib/systemmail.php";
            systemmail($author, array("Your petition"), array("Your navs have been fixed, you should be able to navigate from the stuck page now. If not, please petition again. (This is an automatic message).`n`nRegards %s", $session['user']['name']));
            redirect("viewpetition.php?op=view&id={$id}");
            break;
    }
    page_footer();
}
        rawoutput("</table>");
    }
}
if ($subop == "givekey3") {
    $keyowner = httpget('keyowner');
    if ($keyid == "") {
        $sql = "SELECT keyid FROM " . db_prefix("dwellingkeys") . " WHERE keyowner = 0 AND dwid = {$dwid} LIMIT 1";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        $keyid = $row['keyid'];
    }
    if ($keyid == "") {
        $sql = "INSERT INTO " . db_prefix("dwellingkeys") . " (dwid,dwidowner,keyowner) VALUES ({$dwid}," . $session['user']['acctid'] . ",{$keyowner})";
    } else {
        $sql = "UPDATE " . db_prefix("dwellingkeys") . " SET keyowner = {$keyowner} WHERE keyid = {$keyid}";
    }
    db_query($sql);
    $sql2 = "SELECT location,type FROM " . db_prefix("dwellings") . " WHERE dwid = " . $dwid;
    $row2 = db_fetch_assoc(db_query($sql2));
    $cname = translate_inline(get_module_setting("dwname", $row2['type']));
    output("The key will be delivered to them right away!");
    require_once "lib/systemmail.php";
    systemmail($keyowner, "`^You Have a key!`0", array("`&%s`& has given you a key to their %s`& in %s", $session['user']['name'], $cname, $row2['location']));
}
if ($subop == "takekey") {
    $sql = "UPDATE " . db_prefix("dwellingkeys") . " SET keyowner = 0 WHERE keyid = {$keyid} AND dwid = " . $dwid;
    db_query($sql);
    output("Key successfully taken back.");
    require_once "lib/systemmail.php";
    systemmail($keyowner, "`^Key Taken!`0", array("%s has taken back one of their keys!", $session['user']['name']));
}
            addnav("Back to the Dwelling", "runmodule.php?module=improbablehousing&op=interior&hid={$hid}&rid={$rid}");
        }
        break;
    case "notify":
        $recipient = httpget('recipient');
        require_once "lib/systemmail.php";
        $subj = "You have a Key!";
        switch ($key) {
            case "frontdoor":
                $body = "`0You have a front door key for " . $house['data']['name'] . "!  You can now enter this Dwelling even when it's locked.  Have fun with that!";
                break;
            case "access":
                $body = "`0You have an Access Key for " . $house['data']['rooms'][$rid]['name'] . " at " . $house['data']['name'] . "!  You can now enter this room even when it's locked.  Have fun with that!";
                break;
            case "control":
                $body = "`0You have a Control Key for " . $house['data']['rooms'][$rid]['name'] . " at " . $house['data']['name'] . "!  You can now lock and unlock this room.  Have fun with that!";
                break;
            case "deadbolt":
                $body = "`0You have a Deadbolt Key for " . $house['data']['rooms'][$rid]['name'] . " at " . $house['data']['name'] . "!  You can now lock and unlock this room even when it's deadbolted.  Have fun with that!";
                break;
            case "master":
                $body = "`0You have a Master Key for " . $house['data']['name'] . "!  You can now control most of this Dwelling's operations!  Have fun with that!";
                break;
        }
        systemmail($recipient, $subj, $body);
        output("Okay, the player's been notified.  Have fun!");
        addnav("All done!");
        addnav("Back to the Dwelling", "runmodule.php?module=improbablehousing&op=interior&hid={$hid}&rid={$rid}");
        break;
}
page_footer();
<?php

addnav("Navigation");
addnav("Back to Dwelling", "runmodule.php?module=dwellings&op=enter&dwid={$dwid}");
addnav("Back to Management", "runmodule.php?module=dwellings&op=manage&dwid={$dwid}");
addnav("Log Off", "runmodule.php?module=dwellings&op=logout&dwid={$dwid}");
$who = httpget('who');
if ($who > 0) {
    set_module_pref("dwelling_saver", 0, "dwellings", $who);
    $sql = "UPDATE " . db_prefix("accounts") . " SET restorepage='village.php',location='" . get_module_pref("location_saver", "dwellings", $who) . "' WHERE acctid={$who}";
    db_query($sql);
    $msg = "`2%s`2 woke you up while you were sleeping in their %s`2 and sent you to the fields to sleep.";
    $mailmessage = array($msg, $session['user']['name'], translate_inline(get_module_setting("dwname", $type)));
    require_once "lib/systemmail.php";
    systemmail($who, array("`2You were kicked out by %s`2", $session['user']['name']), $mailmessage);
    output("You woke this person up and sent them to the fields to finish out their rest.");
} else {
    $ac = db_prefix("accounts");
    $mu = db_prefix("module_userprefs");
    $sql = "SELECT {$ac}.name AS name,\r\n\t\t\t{$ac}.acctid AS acctid,\r\n\t\t\t{$ac}.level AS level,\r\n\t\t\t{$ac}.login AS login,\r\n\t\t\t{$ac}.laston AS laston,\r\n\t\t\t{$ac}.dragonkills AS dragonkills,\r\n\t\t\t{$mu}.userid FROM {$mu} \r\n\t\t\tINNER JOIN {$ac} ON {$ac}.acctid = {$mu}.userid \r\n\t\t\tWHERE {$mu}.setting = 'dwelling_saver'\r\n\t\t\tand {$mu}.value = {$dwid} \r\n\t\t\tand {$ac}.loggedin = 0";
    // This consumes a lot of resources and is not really essential.
    //					ORDER BY $mu.userid DESC";
    $result = db_query($sql);
    $name = translate_inline("Name");
    $level = translate_inline("Level");
    $dks = translate_inline("Dragon kills");
    $laston = translate_inline("Last on");
    $writemail = translate_inline("Write mail");
    rawoutput("<table border=0 cellpadding=2 cellspacing=1 bgcolor='#999999'>");
    rawoutput("<tr class='trhead'><td>{$name}</td><td>{$level}</td><td>{$dks}</td><td>{$laston}</td></tr>");
    $i = 0;
function giftstation_run()
{
    global $session;
    page_header("The Gifting Station");
    $op = httpget('op');
    $points = $session['user']['donation'] - $session['user']['donationspent'];
    switch ($op) {
        case "start":
            if (httpget("subop") == "continue") {
                output("The KittyMorph shows you a big smile.  \"`1Okay, that'll be delivered first thing in the morning.  Should make for a nice surprise when they wake up.  Anyone else you'd like to send a gift to?`0\"`n`n");
                $player = httpget('player');
                $itemid = httpget('item');
                $box = httpget('box');
                $free = httpget('free');
                $anonymous = httpget('anonymous');
                $boxid = give_item($box, false, "giftstation_" . $player);
                //	debug($boxid);
                //	debug($itemid);
                change_item_owner($itemid, $boxid);
                set_item_pref("giftbox_contains", $itemid, $boxid);
                if (!$anonymous) {
                    $desc = get_item_pref("description", $boxid);
                    $desc .= "`nThere's a gift tag attached to the box, telling you that this present came from " . $session['user']['name'] . "`0.";
                    set_item_pref("description", $desc, $boxid);
                }
                //notify player that they've got something awesome waiting for them
                require_once "lib/systemmail.php";
                $body = "Someone has used the Gifting Station in Common Ground to send you something.  Whatever it is, it'll turn up on your next new Game Day.";
                systemmail($player, "Someone sent you something awesome!", $body);
                if (!$free) {
                    $session['user']['donationspent'] += 1;
                    //log purchase
                    $sql = "INSERT INTO " . db_prefix("purchaselog") . " (acctid,purchased,amount,data,giftwrap,timestamp) VALUES ('" . $session['user']['acctid'] . "','giftstation_giftwrap','1','none','0','" . date("Y-m-d H:i:s") . "')";
                    $points = $session['user']['donation'] - $session['user']['donationspent'];
                }
                addnav("No, I think that'll do, thanks.", "gardens.php");
            } else {
                if (httpget("subop") == "searchagain") {
                    output("The KittyMorph nods, scratching out the contestant's name on his clipboard.  \"`1No problem.  Let's take it from the top.`0\"`n`n");
                    addnav("Actually, forget the whole thing.", "gardens.php");
                } else {
                    output("`0You head into the Gift Exchange.  A black-furred KittyMorph stands behind a counter.`n`n\"`1Hey there!`0\" he says.  \"`1As part of our continued diplomatic efforts, we provide a gift-wrapping service for items you'd like to send to your fellow contestants.  Interested?`0\"`n`n");
                    output("It costs one Supporter Point to gift-wrap and transfer (nearly) any item to any player.  Some items can be transferred for free.  You currently have %s Supporter Points.`n`n", number_format($points));
                    addnav("No thanks.", "gardens.php");
                }
            }
            if ($points > 0) {
                output("Search below for a player to send a present to.");
                rawoutput("<form action='runmodule.php?module=giftstation&op=findplayer' method='post'>");
                rawoutput("<input name='name'>");
                rawoutput("<input type='submit' class='button' value='" . translate_inline("search") . "'>");
                rawoutput("</form>");
                addnav("", "runmodule.php?module=giftstation&op=findplayer");
            } else {
                output("You don't have any Supporter Points!`n`n");
            }
            break;
        case "findplayer":
            $search = "%";
            $n = httppost('name');
            for ($x = 0; $x < strlen($n); $x++) {
                $search .= substr($n, $x, 1) . "%";
            }
            $search = " AND name LIKE '" . addslashes($search) . "' ";
            $uid = $session['user']['uniqueid'];
            $lastip = $session['user']['lastip'];
            $sql = "SELECT uniqueid, acctid, name FROM " . db_prefix("accounts") . " WHERE locked=0 {$search} ORDER BY name DESC ";
            $result = db_query($sql);
            output("The KittyMorph nods.  \"`1Okay, let's have a look at who I've got written down here whose name sounds like that...`0\"`n`n");
            $matches = 0;
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                if ($row['uniqueid'] != $session['user']['uniqueid']) {
                    addnav("", "runmodule.php?module=giftstation&op=chooseitem&player=" . $row['acctid']);
                    output_notl("<a href='runmodule.php?module=giftstation&op=chooseitem&player=" . $row['acctid'] . "'>" . $row['name'] . "</a>", true);
                    output("`n");
                    $matches++;
                }
            }
            if ($matches == 0) {
                output("He looks down at his list.  \"`1Oh.  Actually, it doesn't look like there's `ianyone`i matching that description who you can send a present to.  Bummer.  Wanna try that again?`0\"");
            }
            addnav("Return to Common Ground", "gardens.php");
            addnav("Search Again", "runmodule.php?module=giftstation&op=start");
            break;
        case "chooseitem":
            $player = httpget('player');
            output("The KittyMorph reaches below his counter and brings up a clipboard on which he writes down the name of your nominated contestant.  \"`1Okay, I've got the name - now, what would you like to send?`0\"`n`n");
            $giftables = get_items_with_prefs("giftable");
            if ($giftables) {
                $giftables = group_items($giftables);
                foreach ($giftables as $sortid => $prefs) {
                    $itemid = $prefs['itemid'];
                    if ($prefs['freegift']) {
                        addnav("Send for free");
                        addnav(array("%s (%s available)", $prefs['verbosename'], $prefs['quantity']), "runmodule.php?module=giftstation&op=choosewrapping&item={$itemid}&player={$player}&free=1");
                    } else {
                        addnav("Send for one Supporter Point");
                        addnav(array("%s (%s available)", $prefs['verbosename'], $prefs['quantity']), "runmodule.php?module=giftstation&op=choosewrapping&item={$itemid}&player={$player}&free=0");
                    }
                }
                addnav("Cancel?");
                addnav("Wait, I've changed my mind.  Let's back up a step.", "runmodule.php?module=giftstation&op=start&subop=searchagain");
                addnav("Actually, forget the whole thing.", "gardens.php");
            } else {
                output("You realise that you have nothing that you can give away.  You shrug your shoulders and give the KittyMorph a big, silly grin.`n`n");
                addnav("This is awkward.");
                addnav("Run out of the shop.  Just run.", "gardens.php");
            }
            break;
        case "choosewrapping":
            $player = httpget('player');
            $itemid = httpget('item');
            $free = httpget('free');
            output("The KittyMorph nods, taking the item from you and beginning to wrap it in tissue paper.  \"`1They should be pleased with that.  Care to choose a box, while I wrap this up?`0\"`n`nClick on any box to confirm the gift.`n`n");
            $boxes = get_items_with_settings("giftwrap");
            foreach ($boxes as $boxid => $prefs) {
                $img = $prefs['image'];
                rawoutput("<a href='runmodule.php?module=giftstation&op=chooseanonymous&player={$player}&item={$itemid}&box={$boxid}&free={$free}'><img src='images/items/{$img}'></a>");
                addnav("", "runmodule.php?module=giftstation&op=chooseanonymous&player={$player}&item={$itemid}&box={$boxid}&free={$free}");
            }
            addnav("Cancel?");
            addnav("Wait, I've changed my mind.  Let's back up a step.", "runmodule.php?module=giftstation&op=start&subop=searchagain");
            addnav("Actually, forget the whole thing.", "gardens.php");
            break;
        case "chooseanonymous":
            $player = httpget('player');
            $itemid = httpget('item');
            $free = httpget('free');
            $box = httpget('box');
            output("The KittyMorph ties a ribbon around the box before reaching below the counter and bringing up a gift tag and a preposterously flamboyant quill pen.`n`n\"`1So, is this an anonymous gift, or would you like your name on it?`0\"`n`n");
            addnav("Anonymous or not?");
            addnav("Tell them who it's from", "runmodule.php?module=giftstation&op=start&subop=continue&player={$player}&item={$itemid}&box={$box}&free={$free}");
            addnav("Give anonymously", "runmodule.php?module=giftstation&op=start&subop=continue&player={$player}&item={$itemid}&box={$box}&free={$free}&anonymous=true");
            break;
    }
    page_footer();
    return true;
}
function massmail_run()
{
    global $session;
    $op = httpget('op');
    popup_header("Ye Olde Poste Office");
    rawoutput("<table width='50%' border='0' cellpadding='0' cellspacing='2'>");
    rawoutput("<tr><td>");
    $t = translate_inline("Back to the Ye Olde Poste Office");
    rawoutput("<a href='mail.php'>{$t}</a></td><td>");
    rawoutput("</td></tr></table>");
    output_notl("`n`n");
    $clanid = $session['user']['clanid'];
    $body = httppost('body');
    $subject = "`^Clan Mail";
    $time = date("Y-m-d H:i:s", strtotime("-" . getsetting("LOGINTIMEOUT", 900) . " sec"));
    $name = $session['user']['name'];
    require_once "lib/systemmail.php";
    switch ($op) {
        case "clanmail":
            //copied and modified from Chris Vorndrans Bulletin
            if ($body == "") {
                rawoutput("<form action='runmodule.php?module=massmail&op=clanmail' method='POST'>");
                output("`n`^Clan Mail:`n`n");
                rawoutput("<textarea name=\"body\" rows=\"10\" cols=\"60\" class=\"input\"></textarea>");
                rawoutput("<input type='submit' class='button' value='" . translate_inline("Send") . "'></form>");
                rawoutput("</form>");
            } else {
                $sql = "SELECT * FROM " . db_prefix("accounts") . " WHERE clanid = '{$clanid}'";
                $res = db_query($sql);
                for ($i = 0; $i < db_num_rows($res); $i++) {
                    $row = db_fetch_assoc($res);
                    systemmail($row['acctid'], $subject, $body);
                }
                output("`^Message has been sent.`0");
            }
            addnav("", "runmodule.php?module=massmail&op=clanmail");
            break;
        case "adminall":
            if ($body == "") {
                rawoutput("<form action='runmodule.php?module=massmail&op=adminall' method='POST'>");
                output("`n`^Send to All Players:`n`n");
                rawoutput("<textarea name=\"body\" rows=\"10\" cols=\"60\" class=\"input\"></textarea>");
                rawoutput("<input type='submit' class='button' value='" . translate_inline("Send") . "'></form>");
                rawoutput("</form>");
            } else {
                $sql = "SELECT * FROM " . db_prefix("accounts");
                $res = db_query($sql);
                for ($i = 0; $i < db_num_rows($res); $i++) {
                    $row = db_fetch_assoc($res);
                    systemmail($row['acctid'], "`^Server News from " . $name, $body);
                }
                output("Your mail was sent to all players");
            }
            addnav("", "runmodule.php?module=massmail&op=adminall");
            break;
        case "adminonline":
            if ($body == "") {
                rawoutput("<form action='runmodule.php?module=massmail&op=adminonline' method='POST'>");
                output("`n`^Send to all online:`n`n");
                rawoutput("<textarea name=\"body\" rows=\"10\" cols=\"60\" class=\"input\"></textarea>");
                rawoutput("<input type='submit' class='button' value='" . translate_inline("Send") . "'></form>");
                rawoutput("</form>");
            } else {
                $sql = "SELECT * FROM " . db_prefix("accounts") . " WHERE loggedin = 1 AND laston > '{$time}'";
                $res = db_query($sql);
                for ($i = 0; $i < db_num_rows($res); $i++) {
                    $row = db_fetch_assoc($res);
                    systemmail($row['acctid'], "`^Server News from " . $name, $body);
                }
                output("Your Mail was sent to all online");
            }
            addnav("", "runmodule.php?module=massmail&op=adminonline");
            break;
            //end of copied code
    }
    popup_footer();
}
			}else if($amt<(int)$session['user']['level']){
				output("`6You might want to send a worthwhile transfer, at least as much as your level.");
			}else if($row['acctid']==$session['user']['acctid']){
				output("`6You may not transfer money to yourself!  That makes no sense!");
			}else{
				debuglog("transferred $amt gold to", $row['acctid']);
				$session[user][gold]-=$amt;
				if ($session[user][gold]<0){ //withdraw in case they don't have enough on hand.
					$session[user][goldinbank]+=$session[user][gold];
					$session[user][gold]=0;
				}
				$session['user']['amountouttoday']+= $amt;
				$sql = "UPDATE accounts SET goldinbank=goldinbank+$amt,transferredtoday=transferredtoday+1 WHERE acctid='{$row['acctid']}'";
				db_query($sql);
				output("`6Transfer Completed!");
				systemmail($row['acctid'],"`^You have received a money transfer!`0","`&{$session['user']['name']}`6 has transferred `^$amt`6 gold to your bank account!");
			}
		}else{
			output("`6Transfer could not be completed, please try again!");
		}
	}
}else if($HTTP_GET_VARS[op]=="deposit"){
  output("<form action='bank.php?op=depositfinish' method='POST'>You have ".($session[user][goldinbank]>=0?"a balance of":"a debt of")." ".abs($session[user][goldinbank])." gold in the bank.`n",true);
	output("`^".($session[user][goldinbank]>=0?"Deposit":"Pay off")." <u>h</u>ow much? <input id='input' name='amount' width=5 accesskey='h'> <input type='submit' class='button' value='Deposit'>`n`iEnter 0 or nothing to deposit it all`i</form>",true);
	output("<script language='javascript'>document.getElementById('input').focus();</script>",true);
  addnav("","bank.php?op=depositfinish");
}else if($HTTP_GET_VARS[op]=="depositfinish"){
	$_POST[amount]=abs((int)$_POST[amount]);
	if ($_POST[amount]==0){
		$_POST[amount]=$session[user][gold];
	}
    $sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE login='******'";
    $result = db_query($sql);
    if (db_num_rows($result) > 0) {
        $row1 = db_fetch_assoc($result);
        $sql = "SELECT count(messageid) AS count FROM " . db_prefix("mail") . " WHERE msgto='" . $row1['acctid'] . "' AND seen=0";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        if ($row['count'] >= getsetting("inboxlimit", 50)) {
            output("`\$You cannot send that person mail, their mailbox is full!`0`n`n");
        } else {
            $subject = str_replace("`n", "", httppost('subject'));
            $body = str_replace("`n", "\n", httppost('body'));
            $body = str_replace("\r\n", "\n", $body);
            $body = str_replace("\r", "\n", $body);
            $body = addslashes(substr(stripslashes($body), 0, (int) getsetting("mailsizelimit", 1024)));
            systemmail($row1['acctid'], $subject, $body, $session['user']['acctid']);
            output("Your message was sent!`n");
        }
    } else {
        output("Could not find the recipient, please try again.`n");
    }
    if (httppost("returnto") > "") {
        $op = "read";
        httpset('op', 'read');
        $id = httppost('returnto');
        httpset('id', $id);
    } else {
        $op = "";
        httpset('op', "");
    }
}
function settings_run()
{
    global $session;
    $op = httpget('op');
    $category = stripslashes(rawurldecode(httpget('cat'))) ?: 'Account';
    page_header("Settings - {$category}");
    switch ($op) {
        case 'save':
            $accounts = db_prefix('accounts');
            $post = httpallpost();
            unset($post['showFormTabIndex']);
            foreach ($post as $key => $val) {
                $post[$key] = stripcslashes($val);
            }
            $post['oldvalues'] = json_decode($post['oldvalues'], true);
            foreach ($post['oldvalues'] as $key => $val) {
                $post['oldvalues'][$key] = stripslashes($val);
            }
            $post = modulehook('prefs-change', $post);
            if ($post['return'] != '') {
                $return = $post['return'];
                unset($post['return']);
            }
            //Fix template changes.
            if (md5(md5($post['oldpass'])) == $session['user']['password'] && $post['newpass'] != '') {
                require_once 'lib/systemmail.php';
                $newPass = md5(md5($post['newpass']));
                db_query("UPDATE {$accounts}\n                    SET password = '******'\n                    WHERE acctid = '{$session['user']['acctid']}'");
                systemmail($session['user']['acctid'], 'Account Settings', "`@Your password was changed successfully!");
            }
            unset($post['newpass']);
            unset($post['oldpass']);
            foreach ($post as $key => $val) {
                if ($key == 'bio' && $val != $post['oldvalues']['bio']) {
                    $session['user']['bio'] = $val;
                } else {
                    if (!is_array($val) && $val != $post['oldvalues'][$key]) {
                        if (strpos($key, '__user') || strpos($key, '__check')) {
                            $moduleKey = explode('__', $key);
                            set_module_pref($moduleKey[1], $val, $moduleKey[0]);
                            unset($moduleKey);
                        } else {
                            $session['user']['prefs'][$key] = $val;
                        }
                    }
                }
            }
            $prefs = @serialize($session['user']['prefs']);
            db_query("UPDATE {$accounts} SET prefs = '{$prefs}'\n                WHERE acctid = '{$session['user']['acctid']}'");
            redirect("runmodule.php?module=settings&cat={$return}&save=true");
            addnav('Go back', 'runmodule.php?module=settings');
            break;
        default:
            $modules = db_prefix('modules');
            $userprefs = db_prefix('module_userprefs');
            $rewrite = trim(get_module_setting('rewrite'));
            $rewrite = json_decode($rewrite, true);
            $languages = getsetting('serverlanguages', 'en, English');
            $prefs = $session['user']['prefs'];
            $prefs['bio'] = $session['user']['bio'];
            $prefs['template'] = $_COOKIE['template'] ?: getsetting('defaultskin', 'jade.htm');
            $prefs['email'] = $session['user']['emailaddress'];
            $prefsFormat = ['Account' => ['bio' => 'Short biography, textarea', 'newpass' => 'New password, password', 'oldpass' => 'If you are changing your password&comma; type your old one, password', 'email' => 'Email, text'], 'Display' => ['template' => 'Skin, theme', 'language' => 'Which language do you prefer?, enum, ' . $languages, 'timestamp' => 'Show timestamps in commentary?, enum, 0, None, 1, Real Time, 2, Relative Time'], 'Game Behavior' => ['emailonmail' => 'Receive emails when you receive a mail?, bool', 'systemmail' => 'Receive emails for system messages?, bool', 'Be sure to check your email\'s spam folder and add our email as a trusted sender!, note', 'dirtyemail' => 'Allow profanity in mail?, bool', 'timeoffset' => sprintf_translate('Hours to offset time (currently %s)?, int', date($prefs['timeformat'], strtotime('now') + $prefs['timeoffset'] * 3600)), 'ihavenocheer' => 'Disable holiday text?, bool', 'nojump' => 'Disable jumping to the commentary when posting or refreshing?, bool']];
            if (count(explode(',', $languages)) < 3) {
                unset($prefs['Display']['language']);
            }
            $prefsFormat = modulehook('prefs-format', $prefsFormat);
            $prefsTemp = [];
            $modulesFound = [];
            $sql = db_query("SELECT modulename, formalname FROM {$modules}\n                WHERE infokeys LIKE '%|prefs|%'\n                AND active = 1\n                ORDER BY modulename");
            while ($row = db_fetch_assoc($sql)) {
                $formal = $row['formalname'];
                $modulesFound[$row['modulename']] = true;
                if (module_status($row['modulename']) == MODULE_FILE_NOT_PRESENT) {
                    foreach ($rewrite as $key => $moduleName) {
                        if ($moduleName == $formal || strpos($key, $row['modulename']) !== false) {
                            unset($rewrite[$key]);
                        }
                    }
                    set_module_setting('rewrite', json_encode($rewrite));
                } else {
                    $prefsTemp[$formal] = get_module_info($row['modulename'])['prefs'];
                }
                unset($prefsTemp[$formal][0]);
                foreach ($prefsTemp[$formal] as $setting => $description) {
                    $description = explode('|', $description)[0];
                    if (strpos($setting, 'user_') === false) {
                        unset($prefsTemp[$formal][$setting]);
                    } else {
                        $structuredKey = "{$row['modulename']}__{$setting}";
                        if ($rewrite[$structuredKey] != $formal) {
                            $prefsTemp[$rewrite[$structuredKey]][$structuredKey] = $description;
                        } else {
                            $prefsTemp[$formal][$structuredKey] = $description;
                        }
                        unset($prefsTemp[$formal][$setting]);
                    }
                }
                if (count($prefsTemp[$formal]) == 0) {
                    unset($prefsTemp[$formal]);
                    unset($modulesFound[$row['modulename']]);
                }
            }
            foreach ($modulesFound as $name => $true) {
                $sql = db_query("SELECT modulename, setting, value FROM {$userprefs}\n                    WHERE modulename = '{$name}'\n                    AND (setting LIKE 'user_%' OR setting LIKE 'check_%')\n                    AND userid = '{$session['user']['acctid']}'\n                    ");
                while ($row = db_fetch_assoc($sql)) {
                    $prefs["{$row['modulename']}__{$row['setting']}"] = $row['value'];
                }
            }
            $prefsFormat = array_merge_recursive($prefsFormat, $prefsTemp);
            $prefsFormat = modulehook('prefs-format', $prefsFormat);
            require_once 'lib/villagenav.php';
            villagenav();
            addnav('Refresh', 'runmodule.php?module=settings');
            addnav('Categories');
            foreach (array_keys($prefsFormat) as $int => $name) {
                addnav($name, "runmodule.php?module=settings&cat=" . rawurlencode($name));
            }
            output("`c`b`i`Q{$category} Settings`b`i`c");
            if (httpget('save')) {
                output("`@`iYour Settings have been saved!`i`n");
            }
            rawoutput("<form action='runmodule.php?module=settings&op=save' method = 'POST'>");
            require_once 'lib/showform.php';
            showform($prefsFormat[$category], $prefs);
            rawoutput(sprintf("<input type='hidden' name='oldvalues' value='%s' />", json_encode($prefs)));
            rawoutput("<input type='hidden' name='return' value='{$category}' />");
            rawoutput("</form>");
            rawoutput("<script type='text/javascript'>\n                document.getElementsByName('template')[0].onchange = function () {\n                    var index = this.selectedIndex;\n                    var selection = this.children[index].value;\n                    document.cookie = 'template=' + selection + ';expires=86400';\n                }\n\n                </script>");
            addnav('', 'runmodule.php?module=settings&op=save');
            break;
    }
    page_footer();
}
 rawoutput("<font size='+1'>");
 output("`c`b`3It is a New Day!`0`b`c");
 rawoutput("</font>");
 $resurrection = httpget('resurrection');
 if ($session['user']['alive'] != true) {
     $session['user']['resurrections']++;
     output("`@You are resurrected!  This is resurrection number %s.`0`n", $session['user']['resurrections']);
     $session['user']['alive'] = true;
     invalidatedatacache("list.php-warsonline");
 }
 $session['user']['age']++;
 if ($session['user']['age'] == 1 && !$session['user']['dragonkills']) {
     $subj = "Welcome to the Island!";
     $body = "If you have any questions that aren't answered in Basic Training, feel free to ask folks in the Banter channel for help - everybody's really friendly here.`n`nTo keep the Island running fast, characters are deleted automatically if they're left to gather dust - so please, remember to sign into your character every now and then.`n`nCharacters who have never earned any experience points will be erased if they haven't logged in for seven days.`nCharacters who have not reached level two will be erased if they don't log in for thirty days.`nCharacters who have reached level two at least once will expire after ninety days of inactivity.`n`nIf you anticipate not being around a computer for three months (it happens - extended holidays, military service, and so on), have a look in the Hunter's Lodge for a permanent account option.`n`nThanks for reading, and good luck!";
     require_once "lib/systemmail.php";
     systemmail($session['user']['acctid'], $subj, $body);
 }
 $session['user']['seenmaster'] = 0;
 output("You open your eyes to discover that a new day has been bestowed upon you. It is day number `^%s.`0", $session['user']['age']);
 output("You feel refreshed enough to take on the world!`n");
 // output("`2Turns for today set to `^%s`2.`n",$turnsperday);
 $turnstoday = "Base: {$turnsperday}";
 $args = modulehook("pre-newday", array("resurrection" => $resurrection, "turnstoday" => $turnstoday));
 $turnstoday = $args['turnstoday'];
 $interestrate = e_rand($mininterest * 100, $maxinterest * 100) / (double) 100;
 if ($session['user']['turns'] > getsetting("fightsforinterest", 4) && $session['user']['goldinbank'] >= 0) {
     $interestrate = 1;
     output("`2Today's interest rate: `^0% (Bankers in this village only give interest to those who work for it)`2.`n");
 } elseif (getsetting("maxgoldforinterest", 100000) && $session['user']['goldinbank'] >= getsetting("maxgoldforinterest", 100000)) {
     $interestrate = 1;
     output("`2Today's interest rate: `^0%% (The bank will not pay interest on accounts equal or greater than %s to retain solvency)`2.`n", getsetting("maxgoldforinterest", 100000));
function maikopan_run()
{
    global $session;
    switch (httpget('step')) {
        case 1:
            page_header("What's going on at Maiko's Cookery Academy?");
            output("You open the door to Maiko's cookery school, catch a flash of silver metal screaming towards you, and step smartly to your left.  The boning knife embeds itself in the door with a heavy wooden `ithunk`i and vibrates, merrily wibbling back and forth in its new home.  You tear your eyes away from it and towards Maiko, who now stands in the centre of a storm of cookery equipment, her chest heaving, her hair frowzled, her irises tiny green rings around pitch black pits.  Each inhalation snarls through her sinuses, her exhalations expelling little spots of hot saliva.`n`nYou speak very quietly, and very carefully.  \"`#Maiko, what's wrong?`0\"`n`nShe snarls, and begins to stride towards you.  She barely comes up to your shoulders, but you feel a very urgent, very pressing need to get the hell out of her way.  You step again, this time to the right, and she yanks the boning knife out of the door and turns to you.`n`n\"`%Someone stole my frying pan,`0\" she says almost conversationally.`n`nYou look at her carefully.  \"`#Someone stole your frying pan?  That's what this is...`0\"`n`n\"`%IT'S A REALLY.  GOOD.  FRYING.  PAN.`0\"  You're not sure whether Maiko even realises that she's punctuating her words with little stabbing motions.  \"`%MY.  FAVOURITE.  ONE.`0\"`n`n\"`#Okay!`0\" you say, hands upraised palm-out, not noticing that you're backing up.  \"`#Okay, I can help you look for it, I can go out and...`0\"`n`n\"`%And WHAT?  You want to go `ifind`i it for me?!  What the hell do you think this is, a `ifetch quest?`i`0\"  Droplets of hot, mad saliva spatter on your face.  \"`%You, you, you big `istrong`i %s`%, you gonna stride off into the Jungle and find the treasured trinket for the poor helpless lady who `ican't do a damned thing for herself?  WELL BLOODY SOD THAT!`i`0\"  She slips the knife into a holster on her ankle, turns, picks up a meat cleaver as long as your arm, and heads for the door.  \"`%I'm perfectly capable of finding my `iown`i damn pan, THANK YOU `iVERY`i MUCH!`0\"`n`nThe door slams shut, the glass rattling in the windows.`n`nYou stand for a second in the sudden silence, surveying the strewn-about silverware.  It seems impossible that all of these things were in their places, as recently as this morning.`n`nSomewhere in the room, a radio crackles into life with a `\$familiar`0 voice.  \"`&%s`&, it's `\$me`&.  Pick this up if you can.`0\"`n`nYou gingerly tiptoe towards where the sound probably came from, stepping between knives and over pans.  \"`&%s`&, come in, over here.  Just follow the sound of my voice.  God I hope this radio is working...`0\"`n`nYou find the radio on the floor underneath a large black wok.  You kneel down to reach the mic.  \"`#I'm here.`0\"`n`n\"`&Right, then.  I only tuned in a few minutes ago, and this camera's a bit f****d-up.  Am I to understand that Maiko's favourite frying pan has gone walkies?`0\"`n`n\"`#That's the situation, yeah.`0\"  You look around at the chaos.  \"`#She's a bit upset about it.`0\"`n`n\"`&So I gather.  Mate, I need you to go and get that frying pan for her.`0\"`n`nYou shake your head.  \"`#That's a bad idea.  Did you hear what she said?`0\"`n`nThe Watcher speaks slowly.  \"`&Ye-es, and in fact I agree with her.  Maiko `iis`i a strong, independent woman, and `ivery much`i capable of finding her own pan, just like she said.`0\"`n`n\"`#So, should I stay here and try to clean the place up a bit?`0\"`n`n\"`&No, you should go and find whoever took the pan `ibefore Maiko does,`i or at the very least, bloody `iwarn`i them that she's coming, because Maiko is...`0\"  `\$The Watcher`0 thinks for a second.  \"`&I like Maiko, love her to bits, and that's why I'm choosing my words `ivery, very politely indeed...`i  Maiko is a strong, independent woman who is very much capable of finding her own pan.  Finding her own pan `iwith extreme prejudice.`i  Sudden character changes don't make for good television.  I've been trying to show her cute side to the cameras, because... well, you know what television viewers are like, they're not fans of change.  They won't want to see her slicing some poor Midget's bollocks off and wearing them as a hat.`0\"`n`nYou sigh.  \"`#Understood.`0\"`n`n\"`&Try to get it back without bloodshed.  No harm, no foul.`0\"`n`n\"`#Hey, `\$Watcher?`0\" you say.  \"`#What's your name?  I can't really keep going on calling you `\$Watcher`#, it doesn't feel right.`0\"`n`n\"`&Yeah, it's...`0\"`n`nThere's a very, very long pause.`n`n\"`&We don't have time for this right now.  Maiko's on the warpath.  Get out there and stop her from really, `ireally`i hurting someone.`0\"`n`nThe radio crackle dies to silence in your hand.`n`nYou stand up.  Over and out.`n`nLooks like you've got a pan to find.`n", $session['user']['name'], $session['user']['name'], $session['user']['name']);
            set_module_pref("plotpoint1", 1);
            addnav("Continue");
            addnav("Exit to Kittania", "village.php");
            break;
        case 2:
            page_header("Something Improbable!");
            output("As you head into The Sunny Spot, you pass a young KittyMorph on his way out.  As hard as it is to tell the age of KittyMorphs, you peg him at about nineteen, twenty - he's wearing a backpack and what looks like a revolver of some kind stuck into his bandolier, and he seems familiar.  The grey fur over his hands is marred by what looks very, very much like burnt-black grease.  Like you might find on, say, an old and much-loved frying pan.`n`nHe seems familiar because he's been showing up to Maiko's cookery class for the past couple of weeks.`n`nYou collar the KittyMorph and spin him around to face you.  Confused, bright red eyes look up into yours.`n`n\"`#Know anything about a frying pan?`0\"`n`nThe young man stares up at you, opens and closes his mouth once or twice.  \"`4Well... yeah, I do.`0\"`n`n\"`#Well, you're bloody lucky I found you first, 'cause Maiko's frothing at the mouth.`0\"`n`nHis eyes, impossibly, widen even further.  \"`4Really?`0\"`n`n\"`#Carrying a meat cleaver as big as my arm,`0\" you say conversationally.  \"`#In a real black mood.`0\"`n`n\"`4Oh, Jesus!`0\"  The young man's eyes start to water.  \"`4That wasn't supposed to happen!`0\"`n`n\"`#Look,`0\" you say kindly, \"`#we all make mistakes.  Just...`0\"  You blink as a minor detail, casually stored away for evaluation at a later point when you're not so busy, bubbles up to the front of your mind.  You look down.`n`nYou look up again.  \"`#Frilly pink panties?  Seriously?`0\"  You shake your head at the young man.  \"`#Not been here long, have you?  Look, just give me the pan and we'll say no more about it, all right?`0\"`n`n\"`4I don't have it!`0\"`n`nYou sigh.  \"`#Of course you don't.  I know how this works.  You sold it, right?`0\"`n`n\"`4No!`0\"`n`n\"`#No?`0\"`n`n\"`4No, Sheila's got it!`0\"`n`nYou frown.  \"`#Sheila in Kittania?  As in, Sheila's Shack?  She knows Maiko.  She wouldn't put her pan up for sale as a weapon.`0\"`n`n\"`4Exactly!  I took it to Sheila and paid her to restore it!  Reseal the metal, polish it up like new, you know!  It was supposed to be a surprise!  I just came in here for a quick pint while she sorted it!`0\"`n`nYou grip the young man's shoulders, and bring him close to you.  \"`i`#What.`0`i\"`n`n\"`4Restoration job,`0\" whimpers the young KittyMorph, his eyes clearly brimming up now.  \"`4Sheila works with metal, she knows how to do it!  Take off all the years of grease.  New coating.  Good as new, she said!`0\"`n`n\"`#Oh, no...`0\" you whisper, letting go of the young man's shoulders and looking past him, into the middle distance.  You ponder for a moment Maiko's reaction to such a revelation.  It could be even worse than having the pan stolen.`n`n\"`#What's your name?`0\" you say quietly.`n`n\"`4Akira,`0\" sniffles the young man.`n`n\"`#It doesn't suit you.  You ever heard the expression, 'The blacker the wok, the better the cook?'`0\"`n`nYou didn't think Akira's eyes could widen further.  You were wrong.`n`n\"`#I don't think Sheila knows that one, either.  We've got to get it back,`0\" you say.  \"`#Fast.`0\"`n`nAkira nods vigorously.`n`nAs one, you break into a run.");
            addnav("Damn it.");
            addnav("Run back to Sheila's, quick!", "runmodule.php?module=maikopan&step=3");
            break;
        case 3:
            page_header("Sheila's Shack");
            output("You burst into Sheila's Shack, throw yourself onto the counter, and gasp up at her.`n`n\"`#Have you got Maiko's pan?`0\"`n`n\"`6And g'day to you too, mate,`0\" says Sheila.  She looks past you at Akira, standing sheepishly in the doorway.  \"`6'ere, what's going on?  Didn't young Akira here drop it off just recently?  Picked 'imself up something to cover up his nethers at last, too, if I recall.  Looking good, by the way.`0\"`n`n\"`4I made a mistake,`0\" says Akira.`n`n\"`6I couldn't disagree more,`0\" smiles Sheila, leaning over the counter and glancing down.  \"`6I think they suit you just right.  Go on, give us a twirl.`0\"`n`n\"`4No, it's about the pan.  You can keep the money, I just - I need it back, very urgently!`0\"`n`nSheila gives Akira an equally sheepish look.  \"`6You mean the one with the chrome handle, yeah?  With the little recessed heat-treated cherry wood accents?  Well, y'see, here's the thing...`0\"`n`nBoth you and Akira groan.`n`n\"`6The chrome was knackered, right!  All pitted with rust!  So I sent the handle off to me sister, Sheila, up in Cyber City, she was gonna give it a bath in oxalic acid - lovely stuff for chrome, takes the rust right off, the Robots love it...`0\"`n`n\"`#You `idismantled`i it?`0\" you moan.`n`n\"`6Right, and the screws holding the handle together were all rusty and the threads were pretty much gone, so I had a look through me selection for a good match, only I couldn't find one the right thread, yeah?  It's pretty old, an' all I've got is metric.  So I calls up me sister Sheila on the radio, and she might have some old feet-an'-inches ones, so I sent the screws off to 'er in Pleasantville, see if she could find a match for 'em...`0\"`n`n\"`4Oh, no!`0\" cries Akira.`n`n\"`6Well `istrewth`i, lad, it was that or re-thread the holes, an' you said you wanted it like new!  An' the wooden pieces, right, me sister Sheila was always the woodworker in our family, so they've gone back to her in NewHome for refinishin'...`0\"`n`n\"`4I can't believe it's in all these different places!`0\"`n`n\"`#`iI`i can't believe that all the other Sheilas are your `isisters.`i`0\"`n`n\"`6Why did you think we all looked the same?  You think I just follow you around the whole Island, setting up shop wherever you happen to be?  Anyway, the actual bowl part, well,`0\" says Sheila, grinning, \"`6It's here, attached to the 'andle with the screws.`0\"  She lifts up the frying pan.`n`nYou both stare.`n`n\"`6Had you goin', didn't I?`0\" she winks.  \"`6Chasin' all over the Island like that, pickin' up all the different little bits... would've just padded things out pretty pointlessly, don'tcha think?  Here.`0\"  She hands the pan over to you.  \"`6Good as new.  What d'you reckon?`0\"`n`nYou handle the pan carefully.  It's bright, and shiny, and lifeless.  \"`6I had to take me angle grinder to it to get the worst of it off,`0\" says Sheila.  You run your fingers gently over the inside of the bowl - it's as smooth as an unused soul.  \"`6Then I took some polishin' compound an' buffed out all the scratches.  You can see yer face in it, look.`0\"  The memories have been scoured from this pan, Maiko's love dissolved in a bath of oxalic acid.  \"`6I 'ad no idea the metal were that bright underneath.  It's a beaut!  And the stuff that came off it, `istrewth!`i`0\"  You contemplate the years of loving use, years of happy experimentation, the flavours of ten thousand carefully-prepared meals - the experience that took Maiko from an amateur cook to a professional chef.  Irreplacable memories.  \"`6Anyway, it's all gone now, an' it's good as new.`0\"`n`nYou force yourself to smile as convincingly as you can, and look from the dead pan up to Sheila.  \"`#It looks great.  Like it just came out of the factory.  You did great work.`0\"`n`nSheila grins back.  \"`6I try me hardest.`0\"");
            addnav("Now what?");
            addnav("Continue", "runmodule.php?module=maikopan&step=4");
            break;
        case 4:
            page_header("Outside Sheila's Shack");
            output("The pair of you trudge out of Sheila's Shack.  Akira is visibly trembling.  Still looking at the pan in your hand, he says in a voice so small the wind nearly blows it away:`n`n\"`4What are we going to do?`0\"`n`nYou sigh, looking down at the pan.  \"`#I don't think,`0\" you say slowly and quietly, turning the pan over to look at the other side, buffed to a mirror finish, \"`#that there's anything we `ican`i do.`0\"  There's not a single speck of Maiko left in that pan.`n`nAkira looks at the ground.  You look over towards him, then look away again, not sure whether he would want to be seen in that condition.`n`n\"`#Either way,`0\" you continue, more for something to say than anything else, \"`#Maiko's still out there, convinced that someone's stolen her pan.  We have to get to her before she starts cracking heads together.`0\"`n`nAkira mumbles something.`n`n\"`#Say again?`0\"`n`n\"`4Squat Hole,`0\" he says, glancing over to you but not meeting your eyes.  \"`4She'll have suspected the Midgets.  I don't think there's anyone in Kittania stupid enough to want to take her favourite pan.`0\"  He looks away again.  \"`4'cept me, of course.`0\"`n`n\"`#You had good intentions, Akira.`0\"`n`n\"`4I could make a comment about a certain road,`0\" says Akira, reaching into his backpack - \"`4but it's kind of redundant, and we're on a deadline.  I've got a one-shot teleporter.`0\"  He looks up at you.  The fur around his eyes is dark, and damp.  He holds out the teleporter.  \"`4Would you come wi... um.  No, I guess it's my responsi...`0\"`n`n\"`#Oh, for goodness' sake, kid,`0\" you sigh, grabbing his hand and smacking the button.  The teleporter, blackened and smoking, falls to the ground.");
            addnav("Continue");
            addnav("Into Squat Hole", "runmodule.php?module=maikopan&step=5");
            break;
        case 5:
            page_header("Squat Hole");
            output("You arrive with a flash of light and pain in Squat Hole.`n`nIt's surprisingly quiet.`n`n\"`%Now, boys, if we can all just sit quietly,`0\" says a sweet, quiet, but very teacher-like voice somewhere nearby, \"`%and you can tell me - and Mister Cleaver here too, of course -`0\" she giggles, low and dangerous - \"`%which one of you arse-scratching, nose-picking, knee-kicking, snot-swallowing, shit-gargling, goat-f*****g, BNP-voting little toerags -`0\" she pauses, and takes a breath - \"`%has my most precious frying pan?`0\"`n`n\"`#At least she didn't take much finding,`0\" you say to Akira, breaking into a run.`n`nAs you both round the corner, Maiko stands facing a dozen or so remarkably well-behaved Midgets, with her back to you.  A hair's-breadth of time passes between her facing away from you, and facing towards you, the cleaver inches from your face.  You both stop in your tracks.`n`n\"`%Hello Akira,`0\" says Maiko.  \"`%How goes the SpiderKitty leg stew?  And I can see your reflection in my cleaver, you know.`0\"  Behind her, the two Midgets who had stood up, sit back down again with a `isquelch`i.`n`n\"`4It goes pretty well, miss,`0\" says Akira.  \"`4But...`0\"`n`nMaiko sees the damp patches on Akira's cheeks, and her brow creases in an expression of concern.  \"`%What's wrong, Akira?`0\"`n`nWordlessly, Akira holds up the pan.`n`nMaiko's eyes flick down to it, back up to Akira's eyes with a puzzled, querying look, back into her cleaver to check on the Midgets - then, in sudden recognition, they widen, swivel back down to the pan, and stay there.`n`nMaiko's cleaver lowers very gently, as you watch something breaking inside her.  You find yourself wanting very badly to look away, but she's still full of adrenaline, and the cleaver is still in her hand, still sharp.`n`n\"`4I'm sorry, I -`0\" stutters Akira.  \"`4I didn't know, miss.  I took it and had it restored, I thought it'd be a nice surprise.  I didn't know it'd...`0\" he chokes on the words.  You can't blame him.  Saying `i`4I didn't know it would kill it`0`i seems at once both silly and far too true.`n`nThe tip of Maiko's cleaver touches the ground.  The Midgets behind her scatter and disappear so quickly you barely see them move.`n`nShe holds out the hand not holding the cleaver.  Grips the handle of the pan, takes it gently from Akira.`n`nHer eyes screw tightly shut, and she trembles, looking down at the ground.  She breathes out once, through her mouth, and then in, shuddery, through her nose.  She flicks her eyes open, looks Akira in the eye, and says \"`%Thank you.`0\"  A tear soaks into the sandy fur beneath her left eye.  \"`%Nobody else remembered my birthday.`0\"`n`nAkira winces.  So do you.`n`nMaiko notices, and winces herself.  `n`nThe world is very, very still, for a moment.`n`n\"`%You...  You didn't know either, did you?`0\" says Maiko.  \"`%You've only been coming to class a couple of weeks.  You can't have known.`0\"`n`nAkira's lips press tightly together.  Wordlessly, he shakes his head.`n`n\"`%You just did this because you thought it'd be something nice,`0\" says Maiko.  \"`%You didn't even do it for an occasion.`0\"  The tip of her gargantuan meat cleaver draws a razor-sharp line in the dirt as she takes a step towards Akira.  Still holding the cleaver in one hand and the pan in the other, she very slowly, very gently wraps her arms around Akira.`n`nAkira hugs back, carefully.  \"`4I'm sorry,`0\" he whispers.  \"`4I'm so, so sorry.`0\"`n`n\"`%Shush,`0\" mutters Maiko.  \"`%It's just a `ithing.`i`0\"`n`n\"`4It's not, though, is it?`0\" mumbles Akira.`n`nMaiko chuckles softly.  \"`%You're sweet.  I'm sure as I get to know you, you'll f**k up in other charming ways.`0\"  She pulls back, her smile disappearing.  \"`%You're right, it's `inot`i just a thing,`0\" she says quietly, looking down at the shiny, dead pan.  \"`%Well.  It is `inow`i, yes.`0\"  Her eyes brim with tears again.  \"`%I really don't know what to say, I...`0\"  She bites her bottom lip and blinks up at the sky, sniffing and visibly trying not to break down further.  \"`%I `iloved`i that thing, I didn't realise `ihow much`i I loved it, I didn't realise how much it was a `ipart`i of...  And you're so sweet, and so considerate, and so `ibloody stupid,`i you... `iyou`i...`0\" she exhales in a sob as Akira takes a quick step back.  \"`%I'm sorry, that was cruel, I'm just...  I think I'd better just put this cleaver `idown,`i for now, I think...`0\"`n`nThe cleaver clatters to the ground, and you exhale.`n`n\"`%You... `iyou...`i`0\"  She exhales, slowly, calms herself.  \"`%You,`0\" she whispers, eyes closed.  She smiles weakly, opens her eyes, looks at Akira.  \"`%I'd set you on dishwashing duty as punishment, but you might do it too well.`0\"`n`nAll three of you laugh, nervously - not because it was funny, but because it was an invitation to break the tension.`n`nMaiko steps towards Akira.  She puts the pan down on the ground, raises a hand and clips him roughly around the ear.  As he recoils, she raises her other hand and affectionately ruffles his hair.  She picks the pan up, and gently bops him on the back of the head.  The pan makes a hollow `ibong.`i  Then she stands on tiptoes and kisses him on the cheek, and says \"`%Let's go home.`0\"`n`nSniffling but clearly relieved, Akira picks up Maiko's cleaver, and the three of you start walking, in silence, back towards Kittania.");
            addnav("Continue");
            addnav("Begin the journey back", "runmodule.php?module=maikopan&step=6");
            break;
        case 6:
            page_header("The Road Home");
            output("It's a long time before anyone says anything.`n`n\"`%Quiet out, isn't it?`0\" Maiko says, quietly.`n`n\"`#Aye,`0\" you say.  \"`#Very quiet.`0\"`n`n\"`4Yes,`0\" says Akira.`n`nAnd then, silence again.  Your footsteps continue for a few minutes.`n`n\"`%I've been thinking,`0\" says Maiko.  And then stops talking.`n`n\"`#Oh?`0\" you say, after a few seconds.`n`n\"`%Yes.  I've been thinking about... things.  You know, material `ithings.`i  About the things you own owning you.  And about how strange it is that people say 'the road to Hell is paved with good intentions,' but they also say 'two wrongs don't make a right.'  And...`0\" she chews on her lip for a moment.  \"`%And about my pan.  Of course.`0\"  She looks down at it, in her hand, turning it this way and that.  \"`%I think us KittyMorphs probably feel differently about our things than other races do, humans in particular.  Mutants too, I'd imagine.`0\"  She looks over towards you.  \"`%Not to perpetuate stereotypes, but I think we tend to own fewer things, but love them more.`0\"`n`nYou mull it over for a moment.  \"`#Broadly speaking,`0\" you say, \"`#and going only from personal experience...  I think you might be right.`0\"`n`n\"`4I think so too,`0\" says Akira.`n`nMaiko nods, and the three of you carry on in silence for another minute or so.`n`n\"`%Of course,`0\" she says, breaking the silence, \"`%I suppose it's kind of silly to love things at all.`0\"`n`n\"`4I don't know,`0\" says Akira.  \"`4I don't think it's silly.  I mean, I've got some things that my friends gave to me, and I love those things.`0\"`n`n\"`%You love your `ifriends`i,`0\" says Maiko.  \"`%The things they give you just act as a...  I don't know, like a `iconductor`i for the memories.  And for the love.  Take away the thing, the love's still there.  The thing just... `igrounds`i it, I suppose.  Anchors it, in a place that you can see, and touch.  Keeps it all together.`0\"`n`n\"`4Gives it a home,`0\" says Akira.`n`nA bespectacled face appears from a nearby bush.  Maiko swings her pan.`n`n\"`5Hello, I'm a professional romance wri-`0\" `b`iSPANG`i`b \"`5`i-tuuuh...`i`0\"`n`nMaiko smiles.  \"`%Oh, you had the screws re-threaded!  That's `imuch`i better.  The handle's been a bit wobbly for a while, now.`0\"  `n`nAkira chuckles as the creature slowly crumples to the ground.  \"`4Well, `isome`i good came of my bone-headedness, then.`0\"`n`nMaiko looks down at the pan.  \"`%Yeah,`0\" she says, a small grin still lingering.`n`nSome more walking.  Some more silence.`n`nEventually, you have to ask.  \"`#Why didn't you let anyone know your birthday was coming up?`0\" `n`nMaiko shrugs.  \"`%Didn't really know whether or not I wanted to celebrate it.  Forty-nine is a weird one, like that.  It's, like, 'Okay, I'm `inot quite`i fifty, but I'm not quite used to the `iidea`i of being fifty yet.'  I don't know if that makes much sense.  I regret not telling people, anyway.  Usually I just go with celebrating everything that comes my way, because I always regret it afterwards if I don't.`0\"`n`nYou nod.  \"`#Sounds familiar.`0\"`n`nAkira looks confused, but doesn't say anything.  He looks over to you, wide-eyed, and mouths something silently.`n`n`4`iForty-nine?  Really?`i`0`n`nYou shrug, and nod back to him.  `3`iYeah, I know.`i`0`n`nIt's a long walk back to Kittania.");
            addnav("Continue");
            addnav("Enter Kittania", "runmodule.php?module=maikopan&step=7");
            break;
        case 7:
            page_header("The Road Home");
            output("After a long, quiet, somewhat awkward walk, the three of you are back in Kittania once again.`n`n\"`%Well,`0\" says Maiko.  \"`%Here we are.`0\"`n`nAkira snuffles his feet.  Maiko stands with her pan slightly raised.  The three of you look at each other for a second or so.`n`nYou get the feeling that Maiko doesn't want to be alone right now.  You also get the feeling that she doesn't want to draw attention to that.`n`n\"`#Does anyone fancy,`0\" you say, in a slow, musing fashion, slowly bringing your finger up as if to make a point - \"`#a pint?`0\"  You let your eyes drift upward along the line of your finger, towards the Sunny Spot, then drop them back down to your companions.`n`nThey glance at each other, then back to you.`n`n\"`%Yeah,`0\" says Maiko, beginning to walk in that direction.`n`n\"`4Yeah,`0\" says Akira, following her.`n`n\"`i`#Yeah,`0`i\" you grin.`n`n\"`%After you,`0\" says Maiko to Akira, at the base of ladder.  He sets his foot and begins to climb.`n`nMaiko looks up.  She notices you noticing her looking up, and blushes.  \"`%I don't know `ihow`i Sheila talked him into those,`0\" she says, quietly but with a smile, before gripping her pan in her teeth and heading upwards.`n`nYou chuckle to yourself, grip the ladder, and begin to ascend into the shade, then the warmth, then the familiar, heavy scents of beer and tobacco, and the sound of laughter.");
            addnav("Drink and be merry.");
            addnav("It is a new day.", "runmodule.php?module=maikopan&step=8");
            break;
        case 8:
            $body = "The audience loved what you did, there.  Next time, don't try to shoehorn a moral into the story, huh?  It didn't really work, and it left some viewers blinking owlishly at their televisions.  Also, if you're going to do a big dramatic buildup like that, you've got to get some violence going.  Or try to crowbar in a bit of nookie.  Personally I don't think Maiko and Akira will come to anything - they might flirt a bit just 'cause tension works in funny ways sometimes, but I don't think either of them will make a move.  Perhaps next time we'll get a romantic subplot going.  Viewers like that sort of thing.`n`nI dunno what to make of Akira, myself.  I don't know whether he's hot for teacher, or genuinely thoughtful, or just a wee bit simple.  Mind you, I can't honestly imagine Sheila of all people flirting with him quite `ithat`i outrageously if the third option were true.  Keep an eye on him for me, would you?`n`nBut, on the whole, great job!  You did wonderfully, and I thank you for it.`n`n-Wotcha`n`nPS: About what you asked me - I think it begins with an S.";
            require_once "lib/systemmail.php";
            systemmail($session['user']['acctid'], "Wow.", $body, 3517);
            set_module_pref("plotpoint2", 1);
            redirect("newday.php");
            break;
    }
    page_footer();
}