function HandleCommand($socket, $cmd)
{
    global $TBS;
    global $pagetitle;
    global $result;
    $pagetitle = $cmd . " result";
    $username = !empty($_POST['username']) ? $_POST['username'] : null;
    $password = !empty($_POST['password']) ? $_POST['password'] : null;
    $confirmation = !empty($_POST['cmd_optn']) ? $_POST['cmd_optn'] : null;
    switch ($cmd) {
        case 'Add':
        case 'Update':
            if (modify_account($socket, $username, $password, 0, false)) {
                $result = $cmd . " succeed.";
            } else {
                $result = $cmd . " failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Ban':
            if (modify_account($socket, $username, "(hidden)", 0, true)) {
                $result = $cmd . " succeed.";
            } else {
                $result = $cmd . " failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Unban':
            if (modify_account($socket, $username, "(hidden)", 0, false)) {
                $result = $cmd . " succeed.";
            } else {
                $result = $cmd . " failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'AccessLevel':
            $access_level = intval($_POST['accesslevel']);
            if (modify_account($socket, $username, "(hidden)", $access_level, false)) {
                $result = "Set access level succeed.";
            } else {
                $result = "Set access level failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Disconnect':
            session_destroy();
            $result = "You have been disconnected.";
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Save':
            // Antony's enrichment.
            if ($confirmation == "yes") {
                $result = world_save($socket);
                $result = $cmd . " command sent.";
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Shutdown':
            // Antony's enrichment.
            if ($confirmation == "yes") {
                $result = shutdown($socket, false, false);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Restart':
            // Antony's enrichment.
            if ($confirmation == "yes") {
                $result = shutdown($socket, true, false);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'SaveShutdown':
            // Antony's enrichment.
            if ($confirmation == "yes") {
                $result = shutdown($socket, false, true);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'SaveRestart':
            // Antony's enrichment.
            if ($confirmation == "yes") {
                $result = shutdown($socket, true, true);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Broadcast':
            // Antony's enrichment.
            $message = $_POST['message'];
            $hue = (int) $_POST['hue'];
            $result = world_broadcast($socket, $message, $hue);
            if (!$result) {
                $result = $cmd . " command failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
    }
}
function HandleCommand($socket, $cmd)
{
    global $TBS;
    global $pagetitle;
    global $result;
    $pagetitle = $cmd . " result";
    $username = $_POST['username'];
    $password = $_POST['password'];
    $confirmation = $_POST['cmd_optn'];
    switch ($cmd) {
        case 'Add':
        case 'Update':
            if (modify_account($socket, $username, $password, 0, false)) {
                // assuming the access level is 0 [player]
                $result = $cmd . " succeed.";
            } else {
                $result = $cmd . " failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Ban':
            if (modify_account($socket, $username, "(hidden)", 0, true)) {
                $result = $cmd . " succeed.";
            } else {
                $result = $cmd . " failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Unban':
            if (modify_account($socket, $username, "(hidden)", 0, false)) {
                $result = $cmd . " succeed.";
            } else {
                $result = $cmd . " failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'AccessLevel':
            $access_level = intval($POST['accesslevel']);
            if (modify_account($socket, $username, "(hidden)", $access_level, false)) {
                $result = "Set access level succeed.";
            } else {
                $result = "Set access level failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Disconnect':
            //disconnect($socket);	// need not to disconnect, the socket has already closed on every page request ends.
            session_destroy();
            $result = "You have been disconnected.";
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
            /************************************************************************/
            /* Caution! Below features are added by Antony.
             * If you do not want to use my remote admin enrichment C# script on your shard. Remove below cases would be a safe way to avoid problem.
             */
        /************************************************************************/
        /* Caution! Below features are added by Antony.
         * If you do not want to use my remote admin enrichment C# script on your shard. Remove below cases would be a safe way to avoid problem.
         */
        case 'Save':
            if ($confirmation == "yes") {
                $result = world_save($socket);
                if (!$result) {
                    $result = $cmd . " failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Shutdown':
            if ($confirmation == "yes") {
                $result = shutdown($socket, false, false);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Restart':
            if ($confirmation == "yes") {
                $result = shutdown($socket, true, false);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'SaveShutdown':
            if ($confirmation == "yes") {
                $result = shutdown($socket, false, true);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'SaveRestart':
            if ($confirmation == "yes") {
                $result = shutdown($socket, true, true);
                if ($result) {
                    $result = $cmd . " command sent.";
                } else {
                    $result = $cmd . " command failed.";
                }
            } else {
                $result = $cmd . " command canceled.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
        case 'Broadcast':
            $message = $_POST['message'];
            $hue = (int) $_POST['hue'];
            $result = world_broadcast($socket, $message, $hue);
            if (!$result) {
                $result = $cmd . " command failed.";
            }
            $TBS->LoadTemplate('tpl/cmdresult.htm');
            break;
            /*** End of Antony's enrichment ***/
            /************************************************************************/
    }
}