}
         debuglog($session['user']['name'] . "`0 changed superuser to " . show_bitfield($value), $userid);
         debug("superuser has changed to {$value}");
     }
 } elseif ($key == "name" && stripslashes($val) != $oldvalues[$key]) {
     $updates++;
     $tmp = sanitize_colorname(getsetting("spaceinname", 0), stripslashes($val), true);
     $tmp = preg_replace("/[`][cHw]/", "", $tmp);
     $tmp = sanitize_html($tmp);
     if ($tmp != stripslashes($val)) {
         output("`\$Illegal characters removed from player name!`0`n");
     }
     if (soap($tmp) != $tmp) {
         output("`^The new name doesn't pass the bad word filter!`0");
     }
     $newname = change_player_name($tmp, $oldvalues);
     $sql .= "{$key} = \"" . addslashes($newname) . "\",";
     output("Changed player name to %s`0`n", $newname);
     debuglog($session['user']['name'] . "`0 changed player name to {$newname}`0", $userid);
     $oldvalues['name'] = $newname;
     if ($session['user']['acctid'] == $userid) {
         $session['user']['name'] = $newname;
     }
 } elseif ($key == "title" && stripslashes($val) != $oldvalues[$key]) {
     $updates++;
     $tmp = sanitize_colorname(true, stripslashes($val), true);
     $tmp = preg_replace("/[`][cHw]/", "", $tmp);
     $tmp = sanitize_html($tmp);
     if ($tmp != stripslashes($val)) {
         output("`\$Illegal characters removed from player title!`0`n");
     }
function hunterslodge_customcolours_run()
{
    require_once "lib/sanitize.php";
    require_once "lib/names.php";
    global $session;
    $op = httpget("op");
    $free = httpget("free");
    $context = httpget("context");
    switch ($context) {
        case "village":
            $backlink = "village.php";
            break;
        case "forest":
            $backlink = "forest.php";
            break;
        case "worldmap":
            $backlink = "runmodule.php?module=worldmapen&op=continue";
            break;
        case "lodge":
            $backlink = "runmodule.php?module=iitems_hunterslodge&op=start";
            break;
    }
    page_header("Choose your Custom Colours");
    switch ($op) {
        case "change":
            output("Want to change your name colours?  No problem.  Enter your desired name, using colour codes, in the box below.  You've got 30 characters to play around with, including colour codes.`n`n");
            namecolour_form();
            addnav("Cancel");
            addnav("Don't change colours, just go back to where I came from", $backlink);
            break;
        case "confirm":
            $newname = httppost("newname");
            $newname = str_replace("`0", "", httppost("newname"));
            $newname = str_replace("`b", "", $newname);
            $newname = str_replace("`i", "", $newname);
            $newname = str_replace("`n", "", $newname);
            $newname = preg_replace("/[`][cHw]/", "", $newname);
            $regname = get_player_basename();
            $comp1 = strtolower(sanitize($regname));
            $comp2 = strtolower(sanitize($newname));
            $err = 0;
            if ($comp1 != $comp2) {
                if (!$err) {
                    output("`4`bInvalid name`b`0`n");
                }
                $err = 1;
                output("Your new name must contain only the same characters as your current name; you can add or remove colors, and you can change the capitalization, but you may not add or remove anything else. You chose %s.`0`n`n", $newname);
            }
            if (strlen($newname) > 30) {
                if (!$err) {
                    output("`4`bInvalid name`b`0`n");
                }
                $err = 1;
                output("Your new name is too long.  Including the color markups, you are not allowed to exceed 30 characters in length.`n`n");
            }
            if (!$err) {
                output("`0Your name will look this this: %s`n`n`0Do you want to set your new name colours now?`n`n", $newname);
                addnav("Confirm");
                addnav("Set the new name colours", "runmodule.php?module=hunterslodge_customcolours&op=set&free={$free}&context={$context}&newname=" . rawurlencode($newname));
                addnav("Cancel");
                addnav("Don't change colours, just go back to where I came from", $backlink);
            } else {
                addnav("Cancel");
                addnav("Don't change colours, just go back to where I came from", $backlink);
            }
            output("`0Change your name again below, if you like.`n`n");
            namecolour_form();
            break;
        case "set":
            $fromname = $session['user']['name'];
            $newname = change_player_name(rawurldecode(httpget('newname')));
            $session['user']['name'] = $newname;
            output("You are now known as %s!`0`n`n", $session['user']['name']);
            if (!$free) {
                $id = has_item("hunterslodge_customcolours");
                delete_item($id);
            }
            addnav("Return");
            addnav("Go back to where I came from", $backlink);
            break;
    }
    page_footer();
}
function namecolor_run()
{
    require_once "lib/sanitize.php";
    require_once "lib/names.php";
    global $session;
    $rebuy = get_module_pref("boughtbefore");
    $cost = get_module_setting($rebuy ? "extrapoints" : "initialpoints");
    $hasperm = get_module_pref("permanent");
    if ($hasperm) {
        $cost = 0;
    }
    $op = httpget("op");
    page_header("Hunter's Lodge");
    $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
    $permcost = get_module_setting("permanent");
    if ($op == "permanent") {
        page_header("Unlimited Name Colour Changes");
        output("For %s Donator Points, you can change your colours as often as you like without paying again.`n`n", $permcost);
        addnav("Unlimited Changes");
        if ($pointsavailable >= $permcost) {
            addnav(array("Get permanent free Name Colour changes (%s Points)", $permcost), "runmodule.php?module=namecolor&op=permanentconfirm");
        } else {
            addnav(array("Sorry, but you need %s more Donator Points for this option.", $permcost - $pointsavailable), "");
        }
        addnav("Cancel", "lodge.php");
        page_footer();
    }
    if ($op == "permanentconfirm") {
        page_header("Unlimited Name Colour Changes");
        output("You've got unlimited Name Colour Changes!");
        addnav("Back to the Lodge", "lodge.php");
        set_module_pref("permanent", 1);
        $session['user']['donationspent'] += $permcost;
        page_footer();
    }
    if ($op == "namechange") {
        output("`3`bName Color Change`b`0`n`n");
        output("`7J. C. Petersen smiles at you,");
        if ($hasperm) {
            output("\"`&I see you have unlimited changes.  Well, go right ahead.`7\"");
        } else {
            if ($rebuy) {
                output("\"`&Because you have previously spent points on a name color change, subsequent color changes only cost you %s points.`7\"", $cost);
            } else {
                output("\"`&Because this will be your first name color change, it will cost you %s points.  Future name changes will only cost %s points.`7\"", $cost, get_module_setting('extrapoints'));
            }
        }
        $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
        if ($pointsavailable < $cost) {
            output("`n`nHe consults his book silently for a moment and then turns to you. \"`&I'm terribly sorry, but you only have %s points available and a name color change would cost you %s.`7\"", $pointsavailable, $cost);
        } else {
            output("`n`nHe looks you up and down slowly, \"`&Your colorized name *must* contain the same characters as your current name in the same order.  This means that it has to be the same display name, though you may add in or remove colors, or change the capitalization of letters.`7\"`n`n");
            namecolor_form();
        }
        addnav("L?Return to the Lodge", "lodge.php");
    } elseif ($op == "namepreview") {
        $regname = get_player_basename();
        $newname = str_replace("`0", "", httppost("newname"));
        if (!get_module_setting("bold")) {
            $newname = str_replace("`b", "", $newname);
        }
        if (!get_module_setting("italics")) {
            $newname = str_replace("`i", "", $newname);
        }
        $newname = preg_replace("/[`][cHw]/", "", $newname);
        $comp1 = strtolower(sanitize($regname));
        $comp2 = strtolower(sanitize($newname));
        $err = 0;
        if ($comp1 != $comp2) {
            if (!$err) {
                output("`3`bInvalid name`b`0`n");
            }
            $err = 1;
            output("Your new name must contain only the same characters as your current name; you can add or remove colors, and you can change the capitalization, but you may not add or remove anything else. You chose %s.`n", $newname);
        }
        if (strlen($newname) > 30) {
            if (!$err) {
                output("`3`bInvalid name`b`0`n");
            }
            $err = 1;
            output("Your new name is too long.  Including the color markups, you are not allowed to exceed 30 characters in length.`n");
        }
        $colorcount = 0;
        for ($x = 0; $x < strlen($newname); $x++) {
            if (substr($newname, $x, 1) == "`") {
                $x++;
                $colorcount++;
            }
        }
        $max = get_module_setting("maxcolors");
        if ($colorcount > $max) {
            if (!$err) {
                output("`3`bInvalid name`b`0`n");
            }
            $err = 1;
            output("You have used too many colors in your name.  You may not exceed %s colors total.`n", $max);
        }
        if (!$err) {
            output("`7Your name will look this this: %s`n`n`7Is this what you wish?`n`n`0", $newname);
            addnav("Confirm Name Change");
            addnav("Yes", "runmodule.php?module=namecolor&op=changename&name=" . rawurlencode($newname));
            addnav("No", "runmodule.php?module=namecolor&op=namechange");
        } else {
            output("`n");
            namecolor_form();
            addnav("L?Return to the Lodge", "lodge.php");
        }
    } elseif ($op == "changename") {
        $session['user']['donationspent'] += $cost;
        set_module_pref("boughtbefore", 1);
        $fromname = $session['user']['name'];
        $newname = change_player_name(rawurldecode(httpget('name')));
        $session['user']['name'] = $newname;
        addnews("%s`^ has become known as %s.", $fromname, $session['user']['name']);
        output("`7Congratulations, your name is now {$session['user']['name']}`7!`n`n");
        modulehook("namechange", array());
        addnav("L?Return to the Lodge", "lodge.php");
    }
    page_footer();
}