/// <summary>
        /// Gets the name of the region.
        /// </summary>
        /// <returns><c>true</c>, if region name was gotten, <c>false</c> otherwise.</returns>
        /// <param name="regInfo">Reg info.</param>
        bool GetRegionName (ref RegionInfo regInfo)
        {
            var updated = false;

            Utilities.MarkovNameGenerator rNames = new Utilities.MarkovNameGenerator ();
            string regionName = rNames.FirstName (m_regionNameSeed == null ? Utilities.RegionNames : m_regionNameSeed, 3, 7);

            regionName = regInfo.RegionName;
            var oldName = regionName;

            do {
                regInfo.RegionName = MainConsole.Instance.Prompt ("Region Name (? for suggestion)", regionName);
                if (regInfo.RegionName == "" || regInfo.RegionName == "?") {
                    regionName = rNames.NextName;
                    regInfo.RegionName = "";
                    continue;
                }
            } while (regInfo.RegionName == "");
            rNames.Reset ();
            if (regInfo.RegionName != oldName)
                updated = true;

            return updated;
        }
Exemplo n.º 2
0
        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
            OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
            ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object>();
            var settings = webInterface.GetWebUISettings();

            bool adminUser = Authenticator.CheckAdminAuthentication(httpRequest, Constants.USER_GOD_CUSTOMER_SERVICE);
            bool allowRegistration = settings.WebRegistration;
            bool anonymousLogins;

            // allow configuration to override the web settings
            IConfig config = webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs ["LoginService"];
            if (config != null)
            {
                anonymousLogins = config.GetBoolean ("AllowAnonymousLogin", allowRegistration);
                allowRegistration = (allowRegistration || anonymousLogins);
            }

            if (!adminUser && !allowRegistration)
            {
                vars.Add("ErrorMessage", "");
                vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
                vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
                vars.Add("Registrations", false);
                vars.Add("NoRegistrations", true);
                return vars;
             }

            if (requestParameters.ContainsKey("Submit"))
            {
                string AvatarName = requestParameters["AvatarName"].ToString();
                string AvatarPassword = requestParameters["AvatarPassword"].ToString();
                string AvatarPasswordCheck = requestParameters["AvatarPassword2"].ToString();
                string FirstName = requestParameters["FirstName"].ToString();
                string LastName = requestParameters["LastName"].ToString();
                //removed - greythane - deemed not used
                //string UserAddress = requestParameters["UserAddress"].ToString();
                //string UserZip = requestParameters["UserZip"].ToString();
                string UserCity = requestParameters["UserCity"].ToString();
                string UserEmail = requestParameters["UserEmail"].ToString();
                string UserHomeRegion = requestParameters["UserHomeRegion"].ToString();
                string UserDOBMonth = requestParameters["UserDOBMonth"].ToString();
                string UserDOBDay = requestParameters["UserDOBDay"].ToString();
                string UserDOBYear = requestParameters["UserDOBYear"].ToString();
                string AvatarArchive = requestParameters.ContainsKey("AvatarArchive")
                                           ? requestParameters["AvatarArchive"].ToString()
                                           : "";
                bool ToSAccept = requestParameters.ContainsKey("ToSAccept") &&
                                 requestParameters["ToSAccept"].ToString() == "Accepted";

                string UserType = requestParameters.ContainsKey("UserType")         // only admins can set membership
                    ? requestParameters ["UserType"].ToString ()
                    : "Resident";

                // revise UserDOBMonth to a number
                UserDOBMonth = ShortMonthToNumber(UserDOBMonth);

                // revise Type flags
                int UserFlags = webInterface.UserTypeToUserFlags (UserType);

                // a bit of idiot proofing
                if (AvatarName == "")  {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarNameError") + "</h3>";
                    return null;
                }
                if ( (AvatarPassword == "") || (AvatarPassword != AvatarPasswordCheck) )
                {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarPasswordError") + "</h3>";
                    return null;
                }
                if (UserEmail == "")
                {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarEmailError") + "</h3>";
                    return null;
                }

                // Thish -  Only one space is allowed in the name to seperate First and Last of the avatar name
                if (AvatarName.Split (' ').Length != 2)
                {
                    response = "<h3>" + translator.GetTranslatedString("AvatarNameSpacingError") + "</h3>";
                    return null;
                }

                // so far so good...
                if (ToSAccept)
                {
                    AvatarPassword = Util.Md5Hash(AvatarPassword);

                    IUserAccountService accountService =
                        webInterface.Registry.RequestModuleInterface<IUserAccountService>();
                    UUID userID = UUID.Random();
                    string error = accountService.CreateUser(userID, settings.DefaultScopeID, AvatarName, AvatarPassword,
                                                             UserEmail);
                    if (error == "")
                    {
                        // set the user account type
                        UserAccount account = accountService.GetUserAccount (null, userID);
                        account.UserFlags = UserFlags;
                        accountService.StoreUserAccount (account);

                        // create and save agent info
                        IAgentConnector con = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector> ();
                        con.CreateNewAgent (userID);
                        IAgentInfo agent = con.GetAgent (userID);
                        agent.OtherAgentInformation ["RLFirstName"] = FirstName;
                        agent.OtherAgentInformation ["RLLastName"] = LastName;
                        //agent.OtherAgentInformation ["RLAddress"] = UserAddress;
                        agent.OtherAgentInformation ["RLCity"] = UserCity;
                        //agent.OtherAgentInformation ["RLZip"] = UserZip;
                        agent.OtherAgentInformation ["UserDOBMonth"] = UserDOBMonth;
                        agent.OtherAgentInformation ["UserDOBDay"] = UserDOBDay;
                        agent.OtherAgentInformation ["UserDOBYear"] = UserDOBYear;
                        agent.OtherAgentInformation ["UserFlags"] = UserFlags;
                        /*if (activationRequired)
                        {
                            UUID activationToken = UUID.Random();
                            agent.OtherAgentInformation["WebUIActivationToken"] = Util.Md5Hash(activationToken.ToString() + ":" + PasswordHash);
                            resp["WebUIActivationToken"] = activationToken;
                        }*/
                        con.UpdateAgent (agent);

                        // create user profile details
                        IProfileConnector profileData =
                            Framework.Utilities.DataManager.RequestPlugin<IProfileConnector> ();
                        if (profileData != null)
                        {
                            IUserProfileInfo profile = profileData.GetUserProfile (userID);
                            if (profile == null)
                            {
                                profileData.CreateNewProfile (userID);
                                profile = profileData.GetUserProfile (userID);
                            }

                            if (AvatarArchive != "")
                            {
                                profile.AArchiveName = AvatarArchive;

                                List<AvatarArchive> avarchives = webInterface.Registry.RequestModuleInterface<IAvatarAppearanceArchiver>().GetAvatarArchives();
                                UUID snapshotUUID = UUID.Zero;
                                foreach (var archive in avarchives)
                                    if (archive.FolderName == AvatarArchive)
                                        snapshotUUID = archive.Snapshot;

                                if (snapshotUUID != UUID.Zero)
                                    profile.Image = snapshotUUID;
                            }
                            profile.MembershipGroup = webInterface.UserFlagToType (UserFlags, webInterface.EnglishTranslator);    // membership is english
                            profile.IsNewUser = true;
                            profileData.UpdateUserProfile (profile);
                        }

                        IAgentInfoService agentInfoService = webInterface.Registry.RequestModuleInterface<IAgentInfoService> ();
                        Vector3 position = new Vector3 (128, 128, 25);
                        Vector3 lookAt = new Vector3 (0, 0, 22);

                        if (agentInfoService != null)
                            agentInfoService.SetHomePosition (userID.ToString (), (UUID) UserHomeRegion, position, lookAt);

                        vars.Add ("ErrorMessage", "Successfully created account, redirecting to main page");
                        response = "<h3>Successfully created account, redirecting to main page</h3>" +
                        "<script language=\"javascript\">" +
                        "setTimeout(function() {window.location.href = \"index.html\";}, 3000);" +
                        "</script>";
                    } else
                    {
                        vars.Add ("ErrorMessage", "<h3>" + error + "</h3>");
                        response = "<h3>" + error + "</h3>";
                    }
                }
                else
                    response = "<h3>You did not accept the Terms of Service agreement.</h3>";
                return null;
            }

            List<Dictionary<string, object>> daysArgs = new List<Dictionary<string, object>>();
            for (int i = 1; i <= 31; i++)
                daysArgs.Add(new Dictionary<string, object> {{"Value", i}});

            List<Dictionary<string, object>> monthsArgs = new List<Dictionary<string, object>>();
            //for (int i = 1; i <= 12; i++)
            //    monthsArgs.Add(new Dictionary<string, object> {{"Value", i}});

            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jan_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Feb_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Mar_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Apr_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("May_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jun_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jul_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Aug_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Sep_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Oct_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Nov_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Dec_Short")}});

            List<Dictionary<string, object>> yearsArgs = new List<Dictionary<string, object>>();
            for (int i = 1940; i <= 2013; i++)
                yearsArgs.Add(new Dictionary<string, object> {{"Value", i}});

            vars.Add("Days", daysArgs);
            vars.Add("Months", monthsArgs);
            vars.Add("Years", yearsArgs);

            var sortBy = new Dictionary<string, bool>();
            sortBy.Add("RegionName", true);

            var RegionListVars = new List<Dictionary<string, object>>();
            var regions = Framework.Utilities.DataManager.RequestPlugin<IRegionData>().Get((RegionFlags) 0,
                RegionFlags.Hyperlink |
                RegionFlags.Foreign |
                RegionFlags.Hidden,
                null, null, sortBy);
            foreach (var region in regions)
            {

                RegionListVars.Add (new Dictionary<string, object> {
                    { "RegionName", region.RegionName },
                    { "RegionUUID", region.RegionID }
                });
            }

            vars.Add("RegionList", RegionListVars);
            vars.Add("UserHomeRegionText", translator.GetTranslatedString("UserHomeRegionText"));

            vars.Add("UserTypeText", translator.GetTranslatedString("UserTypeText"));
            vars.Add("UserType", webInterface.UserTypeArgs(translator)) ;

            List<AvatarArchive> archives = webInterface.Registry.RequestModuleInterface<IAvatarAppearanceArchiver>().GetAvatarArchives();

            List<Dictionary<string, object>> avatarArchives = new List<Dictionary<string, object>>();
            IWebHttpTextureService webTextureService = webInterface.Registry.
                                                                    RequestModuleInterface<IWebHttpTextureService>();
            foreach (var archive in archives)
                avatarArchives.Add(new Dictionary<string, object>
                                       {
                                           {"AvatarArchiveName", archive.FolderName },
                                           {"AvatarArchiveSnapshotID", archive.Snapshot},
                                           {
                                               "AvatarArchiveSnapshotURL",
                                               webTextureService.GetTextureURL(archive.Snapshot)
                                           }
                                       });

            vars.Add("AvatarArchive", avatarArchives);

            IConfig loginServerConfig =
                webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs["LoginService"];
            string tosLocation = "";
            if (loginServerConfig != null && loginServerConfig.GetBoolean("UseTermsOfServiceOnFirstLogin", false))
            {
                tosLocation = loginServerConfig.GetString("FileNameOfTOS", "");
                tosLocation = PathHelpers.VerifyReadFile (tosLocation,  ".txt", Constants.DEFAULT_DATA_DIR);
            }
            string ToS = "There are no Terms of Service currently. This may be changed at any point in the future.";

            if (tosLocation != "")
            {
                System.IO.StreamReader reader =
                    new System.IO.StreamReader(System.IO.Path.Combine(Environment.CurrentDirectory, tosLocation));
                ToS = reader.ReadToEnd();
                reader.Close();
            }

            // check for user name seed
            string[] m_userNameSeed = null;
            if (loginServerConfig != null)
            {
                string userNameSeed = loginServerConfig.GetString ("UserNameSeed", "");
                if (userNameSeed != "")
                    m_userNameSeed = userNameSeed.Split (',');
            }

            Utilities.MarkovNameGenerator ufNames = new Utilities.MarkovNameGenerator ();
            Utilities.MarkovNameGenerator ulNames = new Utilities.MarkovNameGenerator ();
            string[] nameSeed = m_userNameSeed == null ? Utilities.UserNames : m_userNameSeed;

            string firstName = ufNames.FirstName (nameSeed, 3, 4);
            string lastName = ulNames.FirstName (nameSeed, 5, 6);
            string enteredName = firstName + " " + lastName;

            vars.Add("AvatarName",enteredName);
            vars.Add("ToSMessage", ToS);
            vars.Add("TermsOfServiceAccept", translator.GetTranslatedString("TermsOfServiceAccept"));
            vars.Add("TermsOfServiceText", translator.GetTranslatedString("TermsOfServiceText"));
            vars.Add("RegistrationsDisabled", "");
            //vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
            vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
            vars.Add("AvatarNameText", translator.GetTranslatedString("AvatarNameText"));
            vars.Add("AvatarPasswordText", translator.GetTranslatedString("Password"));
            vars.Add("AvatarPasswordConfirmationText", translator.GetTranslatedString("PasswordConfirmation"));
            vars.Add("AvatarScopeText", translator.GetTranslatedString("AvatarScopeText"));
            vars.Add("FirstNameText", translator.GetTranslatedString("FirstNameText"));
            vars.Add("LastNameText", translator.GetTranslatedString("LastNameText"));
            vars.Add("UserAddressText", translator.GetTranslatedString("UserAddressText"));
            vars.Add("UserZipText", translator.GetTranslatedString("UserZipText"));
            vars.Add("UserCityText", translator.GetTranslatedString("UserCityText"));
            vars.Add("UserCountryText", translator.GetTranslatedString("UserCountryText"));
            vars.Add("UserDOBText", translator.GetTranslatedString("UserDOBText"));
            vars.Add("UserEmailText", translator.GetTranslatedString("UserEmailText"));
            vars.Add("Accept", translator.GetTranslatedString("Accept"));
            vars.Add("Submit", translator.GetTranslatedString("Submit"));
            vars.Add("SubmitURL", "register.html");
            vars.Add("ErrorMessage", "");
            vars.Add("Registrations", true);
            vars.Add("NoRegistrations", false);

            return vars;
        }
        /// <summary>
        ///     Handle the create (add) user command from the console.
        /// </summary>
        /// <param name="scene">Scene.</param>
        /// <param name="cmd">string array with parameters: firstname, lastname, password, email</param>
        protected void HandleCreateUser (IScene scene, string [] cmd)
        {
            string userName = "";
            string password, email, uuid, scopeID;
            bool sysFlag = false;
            bool uuidFlag = false;
            List<string> userTypes = new List<string> (new [] { "Guest", "Resident", "Member", "Contractor", "Charter_Member" });

            List<string> cmdparams = new List<string> (cmd);
            foreach (string param in cmd) {
                if (param.StartsWith ("--system", StringComparison.Ordinal)) {
                    sysFlag = true;
                    cmdparams.Remove (param);
                }
                if (param.StartsWith ("--uuid", StringComparison.Ordinal)) {
                    uuidFlag = true;
                    cmdparams.Remove (param);
                }
            }

            // check for provided user name
            if (cmdparams.Count >= 4) {
                userName = cmdparams [2] + " " + cmdparams [3];
            } else {
                var ufNames = new Utilities.MarkovNameGenerator ();
                var ulNames = new Utilities.MarkovNameGenerator ();
                string [] nameSeed = m_userNameSeed == null ? Utilities.UserNames : m_userNameSeed;

                string firstName = ufNames.FirstName (nameSeed, 3, 4);
                string lastName = ulNames.FirstName (nameSeed, 5, 6);
                string enteredName = firstName + " " + lastName;
                if (userName != "")
                    enteredName = userName;

                do {
                    userName = MainConsole.Instance.Prompt ("User Name (? for suggestion, 'quit' to abort)", enteredName);
                    if (userName.ToLower () == "quit")
                        return;
                    
                    if (userName == "" || userName == "?") {
                        enteredName = ufNames.NextName + " " + ulNames.NextName;
                        userName = "";
                        continue;
                    }
                    var fl = userName.Split (' ');
                    if (fl.Length < 2) {
                        MainConsole.Instance.CleanInfo ("    User name must be <firstname> <lastname>");
                        userName = "";
                    }
                } while (userName == "");
                ufNames.Reset ();
                ulNames.Reset ();
            }

            // we have the name so check to make sure it is allowed
            UserAccount ua = GetUserAccount (null, userName);
            if (ua != null) {
                MainConsole.Instance.WarnFormat ("[User account service]: This user, '{0}' already exists!", userName);
                return;
            }

            // password as well?
            if (cmdparams.Count < 5) {
                var pwmatch = false;
                do {
                    password = MainConsole.Instance.PasswordPrompt ("Password");
                    if (password == "") {
                        MainConsole.Instance.CleanInfo (" .... password must not be empty, please re-enter");
                        continue;
                    }
                    var passwordAgain = MainConsole.Instance.PasswordPrompt ("Re-enter Password");
                    pwmatch = (password == passwordAgain);
                    if (!pwmatch)
                        MainConsole.Instance.CleanInfo (" .... passwords did not match, please re-enter");
                } while (!pwmatch);
            } else
                password = cmdparams [4];

            // maybe even an email?
            if (cmdparams.Count < 6) {
                email = MainConsole.Instance.Prompt ("Email for password recovery. ('none' if unknown)", "none");
            } else
                email = cmdparams [5];

            if ((email.ToLower () != "none") && !Utilities.IsValidEmail (email)) {
                MainConsole.Instance.CleanInfo ("This does not look like a valid email address. ('none' if unknown)");
                email = MainConsole.Instance.Prompt ("Email", email);
            }

            // Get user type (for payments etc)
            var userType = MainConsole.Instance.Prompt ("User type", "Resident", userTypes);

            // Get available user avatar archives
            var userAvatarArchive = "";
            var avatarArchives = GetAvatarArchivesFiles ();
            if (avatarArchives.Count > 0) {
                avatarArchives.Add ("None");
                userAvatarArchive = MainConsole.Instance.Prompt ("Avatar archive to use", "None", avatarArchives);
                if (userAvatarArchive == "None")
                    userAvatarArchive = "";
            }

            // Allow the modification the UUID if required - for matching user UUID with other Grids etc like SL
            uuid = UUID.Random ().ToString ();
            if (uuidFlag)
                while (true) {
                    uuid = MainConsole.Instance.Prompt ("Required avatar UUID)", uuid);
                    UUID test;
                    if (UUID.TryParse (uuid, out test))
                        break;

                    MainConsole.Instance.Error ("There was a problem verifying this UUID. Please retry.");
                }

            // this really should not be altered so hide it normally
            scopeID = UUID.Zero.ToString ();
            if (sysFlag) {
                scopeID = MainConsole.Instance.Prompt ("Scope (Don't change unless you know what this is)", scopeID);
            }

            // we should be good to go
            CreateUser (UUID.Parse (uuid), UUID.Parse (scopeID), userName, Util.Md5Hash (password), email);
            // CreateUser will tell us success or problem
            //MainConsole.Instance.InfoFormat("[User account service]: User '{0}' created", name);

            // check for success
            UserAccount account = GetUserAccount (null, userName);
            if (account != null) {
                account.UserFlags = UserTypeToUserFlags (userType);
                StoreUserAccount (account);

                // update profile for the user as well
                if (m_profileConnector != null) {
                    IUserProfileInfo profile = m_profileConnector.GetUserProfile (account.PrincipalID);
                    if (profile == null) {
                        m_profileConnector.CreateNewProfile (account.PrincipalID);          // create a profile for the user
                        profile = m_profileConnector.GetUserProfile (account.PrincipalID);
                    }

                    if (userAvatarArchive != "")
                        profile.AArchiveName = userAvatarArchive + ".aa";

                    profile.MembershipGroup = UserFlagToType (account.UserFlags);
                    profile.IsNewUser = true;
                    m_profileConnector.UpdateUserProfile (profile);
                }
            } else
                MainConsole.Instance.WarnFormat ("[User account service]: There was a problem creating the account for '{0}'", userName);

        }
        /// <summary>
        /// Creates/updates a region from console.
        /// </summary>
        /// <returns>The region from console.</returns>
        /// <param name="info">Info.</param>
        /// <param name="prompt">If set to <c>true</c> prompt.</param>
        /// <param name="currentInfo">Current info.</param>
        RegionInfo CreateRegionFromConsole(RegionInfo info, Boolean prompt, Dictionary<string, int> currentInfo)
        {
            if (info == null || info.NewRegion)
            {
                if (info == null)
                    info = new RegionInfo();

                info.RegionID = UUID.Random();

                if (currentInfo != null)
                {
                    info.RegionLocX = currentInfo ["minX"] > 0 ? currentInfo ["minX"] : 1000 * Constants.RegionSize;
                    info.RegionLocY = currentInfo ["minY"] > 0 ? currentInfo ["minY"] : 1000 * Constants.RegionSize;
                    info.RegionPort = currentInfo ["port"] > 0 ? currentInfo ["port"] + 1 : 9000;
                } else
                {
                    info.RegionLocX = 1000 * Constants.RegionSize;
                    info.RegionLocY = 1000 * Constants.RegionSize;
                    info.RegionPort = 9000;

                }
                prompt = true;
            }

            // prompt for user input
            if (prompt)
            {
                Utilities.MarkovNameGenerator rNames = new Utilities.MarkovNameGenerator();
                string regionName = rNames.FirstName (m_regionNameSeed == null ? Utilities.RegionNames: m_regionNameSeed, 3,7);
                if (info.RegionName != "")
                    regionName = info.RegionName;

                do
                {
                    info.RegionName = MainConsole.Instance.Prompt ("Region Name (? for suggestion)", regionName);
                    if (info.RegionName == "" || info.RegionName == "?")
                    {
                        regionName = rNames.NextName;
                        info.RegionName = "";
                        continue;
                    }
                }
                while (info.RegionName == "");
                rNames.Reset();

                info.RegionLocX =
                    int.Parse (MainConsole.Instance.Prompt ("Region Location X",
                    ((info.RegionLocX == 0
                            ? 1000
                            : info.RegionLocX / Constants.RegionSize)).ToString ())) * Constants.RegionSize;

                info.RegionLocY =
                    int.Parse (MainConsole.Instance.Prompt ("Region location Y",
                    ((info.RegionLocY == 0
                            ? 1000
                            : info.RegionLocY / Constants.RegionSize)).ToString ())) * Constants.RegionSize;

                //info.RegionLocZ =
                //    int.Parse (MainConsole.Instance.Prompt ("Region location Z",
                //        ((info.RegionLocZ == 0
                //            ? 0
                //            : info.RegionLocZ / Constants.RegionSize)).ToString ())) * Constants.RegionSize;

                var haveSize = true;
                var sizeCheck = "";
                do
                {
                    info.RegionSizeX = int.Parse (MainConsole.Instance.Prompt ("Region size X", info.RegionSizeX.ToString ()));
                    if (info.RegionSizeX > Constants.MaxRegionSize)
                    {
                        MainConsole.Instance.CleanInfo ("    The currently recommended maximum size is " + Constants.MaxRegionSize);
                        sizeCheck =  MainConsole.Instance.Prompt ("Continue with the X size of " + info.RegionSizeX + "? (yes/no)", "no");
                        haveSize = sizeCheck.ToLower().StartsWith("y");
                    }
                } while (! haveSize);

                // assume square regions
                info.RegionSizeY = info.RegionSizeX;

                do
                {
                    info.RegionSizeY = int.Parse (MainConsole.Instance.Prompt ("Region size Y", info.RegionSizeY.ToString ()));
                    if ( (info.RegionSizeY > info.RegionSizeX) && (info.RegionSizeY > Constants.MaxRegionSize) )
                    {
                        MainConsole.Instance.CleanInfo ("    The currently recommended maximum size is " + Constants.MaxRegionSize);
                        sizeCheck =  MainConsole.Instance.Prompt ("Continue with the Y size of " + info.RegionSizeY + "? (yes/no)", "no");
                        haveSize = sizeCheck.ToLower().StartsWith("y");
                    }
                } while (! haveSize);

                bool bigRegion = ((info.RegionSizeX > Constants.MaxRegionSize) || (info.RegionSizeY > Constants.MaxRegionSize));

                // * Mainland / Full Region (Private)
                // * Mainland / Homestead
                // * Mainland / Openspace
                //
                // * Estate / Full Region   (Private)
                //
                info.RegionType = MainConsole.Instance.Prompt ("Region Type (Mainland/Estate)",
                    (info.RegionType == "" ? "Estate" : info.RegionType));

                // Region presets or advanced setup
                string setupMode;
                string terrainOpen = "Grassland";
                string terrainFull = "Grassland";
                var responses = new List<string>();
                if (info.RegionType.ToLower().StartsWith("m"))
                {
                    // Mainland regions
                    info.RegionType = "Mainland / ";
                    responses.Add("Full Region");
                    responses.Add("Homestead");
                    responses.Add ("Openspace");
                    responses.Add ("Whitecore");                            // TODO: remove?
                    responses.Add ("Custom");
                    setupMode = MainConsole.Instance.Prompt("Mainland region type?", "Full Region", responses).ToLower ();

                    // allow specifying terrain for Openspace
                    if (bigRegion)
                        terrainOpen = "flatland";
                    else if (setupMode.StartsWith("o"))
                        terrainOpen = MainConsole.Instance.Prompt("Openspace terrain ( Grassland, Swamp, Aquatic)?", terrainOpen).ToLower();

                } else
                {
                    // Estate regions
                    info.RegionType = "Estate / ";
                    responses.Add("Full Region");
                    responses.Add ("Whitecore");                            // TODO: WhiteCore 'standard' setup, rename??
                    responses.Add ("Custom");
                    setupMode = MainConsole.Instance.Prompt("Estate region type?","Full Region", responses).ToLower();
                }

                // terrain can be specified for Full or custom regions
                if (bigRegion)
                    terrainFull = "Flatland";
                else if (setupMode.StartsWith ("f") || setupMode.StartsWith ("c"))
                {
                    var tresp = new List<string>();
                    tresp.Add ("Flatland");
                    tresp.Add ("Grassland");
                    tresp.Add ("Hills");
                    tresp.Add ("Mountainous");
                    tresp.Add ("Island");
                    tresp.Add ("Swamp");
                    tresp.Add ("Aquatic");
                    string tscape = MainConsole.Instance.Prompt ("Terrain Type?", terrainFull,tresp);
                    terrainFull = tscape;
                    // TODO: This would be where we allow selection of preset terrain files
                }

                if (setupMode.StartsWith("c"))
                {
                    info.RegionType = info.RegionType + "Custom";
                    info.RegionTerrain = terrainFull;

                    // allow port selection
                    info.RegionPort = int.Parse (MainConsole.Instance.Prompt ("Region Port", info.RegionPort.ToString ()));

                    // Startup mode
                    string scriptStart = MainConsole.Instance.Prompt (
                        "Region Startup - Normal or Delayed startup (normal/delay) : ","normal").ToLower();
                    info.Startup = scriptStart.StartsWith ("n") ? StartupType.Normal : StartupType.Medium;

                    info.SeeIntoThisSimFromNeighbor =  MainConsole.Instance.Prompt (
                        "See into this sim from neighbors (yes/no)",
                        info.SeeIntoThisSimFromNeighbor ? "yes" : "no").ToLower() == "yes";

                    info.InfiniteRegion = MainConsole.Instance.Prompt (
                        "Make an infinite region (yes/no)",
                        info.InfiniteRegion ? "yes" : "no").ToLower () == "yes";

                    info.ObjectCapacity =
                        int.Parse (MainConsole.Instance.Prompt ("Object capacity",
                        info.ObjectCapacity == 0
                                               ? "50000"
                                               : info.ObjectCapacity.ToString ()));
                }

                if (setupMode.StartsWith("w"))
                {
                    // 'standard' setup
                    info.RegionType = info.RegionType + "Whitecore";
                    //info.RegionPort;            // use auto assigned port
                    info.RegionTerrain = "Flatland";
                    info.Startup = StartupType.Normal;
                    info.SeeIntoThisSimFromNeighbor = true;
                    info.InfiniteRegion = false;
                    info.ObjectCapacity = 50000;

                }
                if (setupMode.StartsWith("o"))
                {
                    // 'Openspace' setup
                    info.RegionType = info.RegionType + "Openspace";
                    //info.RegionPort;            // use auto assigned port

                    if (terrainOpen.StartsWith("a"))
                        info.RegionTerrain = "Aquatic";
                    else if (terrainOpen.StartsWith("s"))
                        info.RegionTerrain = "Swamp";
                    else if (terrainOpen.StartsWith("g"))
                        info.RegionTerrain = "Grassland";
                    else
                        info.RegionTerrain = "Flatland";

                    info.Startup = StartupType.Medium;
                    info.SeeIntoThisSimFromNeighbor = true;
                    info.InfiniteRegion = false;
                    info.ObjectCapacity = 750;
                    info.RegionSettings.AgentLimit = 10;
                    info.RegionSettings.AllowLandJoinDivide = false;
                    info.RegionSettings.AllowLandResell = false;
                                   }
                if (setupMode.StartsWith("h"))
                {
                    // 'Homestead' setup
                    info.RegionType = info.RegionType + "Homestead";
                    //info.RegionPort;            // use auto assigned port
                    if (bigRegion)
                        info.RegionTerrain = "Flatland";
                    else
                        info.RegionTerrain = "Homestead";

                    info.Startup = StartupType.Medium;
                    info.SeeIntoThisSimFromNeighbor = true;
                    info.InfiniteRegion = false;
                    info.ObjectCapacity = 3750;
                    info.RegionSettings.AgentLimit = 20;
                    info.RegionSettings.AllowLandJoinDivide = false;
                    info.RegionSettings.AllowLandResell = false;
                }

                if (setupMode.StartsWith("f"))
                {
                    // 'Full Region' setup
                    info.RegionType = info.RegionType + "Full Region";
                    //info.RegionPort;            // use auto assigned port
                    info.RegionTerrain = terrainFull;
                    info.Startup = StartupType.Normal;
                    info.SeeIntoThisSimFromNeighbor = true;
                    info.InfiniteRegion = false;
                    info.ObjectCapacity = 15000;
                    info.RegionSettings.AgentLimit = 100;
                    if (info.RegionType.StartsWith ("M"))                           // defaults are 'true'
                    {
                        info.RegionSettings.AllowLandJoinDivide = false;
                        info.RegionSettings.AllowLandResell = false;
                    }
                }

            }

            // are we updating or adding??
            if (m_scene != null)
            {
                IGridRegisterModule gridRegister = m_scene.RequestModuleInterface<IGridRegisterModule>();
                //Re-register so that if the position has changed, we get the new neighbors
                gridRegister.RegisterRegionWithGrid(m_scene, true, false, null);

                // Tell clients about changes
                IEstateModule es = m_scene.RequestModuleInterface<IEstateModule> ();
                if (es != null)
                    es.sendRegionHandshakeToAll ();

                // in case we have changed the name
                if (m_scene.SimulationDataService.BackupFile != info.RegionName)
                {
                    string oldFile = BuildSaveFileName (m_scene.SimulationDataService.BackupFile);
                    if (File.Exists (oldFile))
                        File.Delete (oldFile);
                    m_scene.SimulationDataService.BackupFile = info.RegionName;
                }

                m_scene.SimulationDataService.ForceBackup();

                MainConsole.Instance.InfoFormat("[FileBasedSimulationData]: Save of {0} completed.",info.RegionName);
            }

            return info;
        }
Exemplo n.º 5
0
        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                               OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
                                               ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object>();
            var gridService = webInterface.Registry.RequestModuleInterface<IGridService> ();


            if (requestParameters.ContainsKey("Submit"))
            {

                string RegionServerURL = requestParameters["RegionServerURL"].ToString();
                // required
                if (RegionServerURL == "")  {
                    response = "<h3>" + translator.GetTranslatedString ("RegionServerURLError") + "</h3>";   
                    return null;
                }

                string RegionName = requestParameters["RegionName"].ToString();
                //string OwnerUUID = requestParameters["OwnerUUID"].ToString();
                string RegionLocX = requestParameters["RegionLocX"].ToString();
                string RegionLocY = requestParameters["RegionLocY"].ToString();
                string RegionSizeX = requestParameters["RegionSizeX"].ToString();
                string RegionSizeY = requestParameters["RegionSizeY"].ToString();

                string RegionType = requestParameters["RegionType"].ToString();
                string RegionPresetType = requestParameters["RegionPresetType"].ToString();
                string RegionTerrain = requestParameters["RegionTerrain"].ToString();

                string RegionLoadTerrain = requestParameters.ContainsKey("RegionLoadTerrain")
                    ? requestParameters["RegionLoadTerrain"].ToString()
                    : "";
                //bool ToSAccept = requestParameters.ContainsKey("ToSAccept") &&
                //    requestParameters["ToSAccept"].ToString() == "Accepted";

               // string UserType = requestParameters.ContainsKey("UserType")         // only admins can set membership
               //     ? requestParameters ["UserType"].ToString ()
               //     : "Resident";


                // a bit of idiot proofing
                if (RegionName == "")  {
                    response = "<h3>" + translator.GetTranslatedString ("RegionNameError") + "</h3>";   
                    return null;
                }
                if ( (RegionLocX == "") || (RegionLocY == "") )
                {
                    response = "<h3>" + translator.GetTranslatedString ("RegionLocationError") + "</h3>";   
                    return null;
                } 

                // so far so good...
                // build the new region details
                int RegionPort = int.Parse (requestParameters ["RegionPort"].ToString ());

                var newRegion = new RegionInfo();

                newRegion.RegionName = RegionName;
                newRegion.RegionType = RegionType;
                newRegion.RegionLocX = int.Parse (RegionLocX);
                newRegion.RegionLocY = int.Parse (RegionLocY);
                newRegion.RegionSizeX = int.Parse (RegionSizeX);
                newRegion.RegionSizeY = int.Parse (RegionSizeY);

                newRegion.RegionPort = RegionPort;
                newRegion.SeeIntoThisSimFromNeighbor = true;
                newRegion.InfiniteRegion = false;
                newRegion.ObjectCapacity = 50000;
                newRegion.Startup = StartupType.Normal;

                var regionPreset = RegionPresetType.ToLower ();
                if (regionPreset.StartsWith ("c", System.StringComparison.Ordinal))
                {
                    newRegion.RegionPort = int.Parse( requestParameters["RegionPort"].ToString() );
                    newRegion.SeeIntoThisSimFromNeighbor = (requestParameters["RegionVisibility"].ToString().ToLower() == "yes");
                    newRegion.InfiniteRegion = (requestParameters["RegionInfinite"].ToString().ToLower() == "yes");
                    newRegion.ObjectCapacity = int.Parse( requestParameters["RegionCapacity"].ToString() );

                    string delayStartup = requestParameters["RegionDelayStartup"].ToString();
                    newRegion.Startup = delayStartup.StartsWith ("n", System.StringComparison.Ordinal) ? StartupType.Normal : StartupType.Medium;

                }

                if (regionPreset.StartsWith ("w", System.StringComparison.Ordinal))
                {
                    // 'standard' setup
                    newRegion.RegionType = newRegion.RegionType + "Whitecore";                   
                    //info.RegionPort;            // use auto assigned port
                    newRegion.RegionTerrain = "Flatland";
                    newRegion.Startup = StartupType.Normal;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = false;
                    newRegion.ObjectCapacity = 50000;
                    newRegion.RegionPort = RegionPort;
 

                }
                if (regionPreset.StartsWith ("o", System.StringComparison.Ordinal))       
                {
                    // 'Openspace' setup
                    newRegion.RegionType = newRegion.RegionType + "Openspace";                   
                    //newRegion.RegionPort;            // use auto assigned port
                    if (RegionTerrain.StartsWith ("a", System.StringComparison.Ordinal))
                        newRegion.RegionTerrain = "Aquatic";
                    else
                        newRegion.RegionTerrain = "Grassland";
                    newRegion.Startup = StartupType.Medium;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = false;
                    newRegion.ObjectCapacity = 750;
                    newRegion.RegionSettings.AgentLimit = 10;
                    newRegion.RegionSettings.AllowLandJoinDivide = false;
                    newRegion.RegionSettings.AllowLandResell = false;
                }
                if (regionPreset.StartsWith ("h", System.StringComparison.Ordinal))       
                {
                    // 'Homestead' setup
                    newRegion.RegionType = newRegion.RegionType + "Homestead";                   
                    //info.RegionPort;            // use auto assigned port
                    newRegion.RegionTerrain = "Homestead";
                    newRegion.Startup = StartupType.Medium;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = false;
                    newRegion.ObjectCapacity = 3750;
                    newRegion.RegionSettings.AgentLimit = 20;
                    newRegion.RegionSettings.AllowLandJoinDivide = false;
                    newRegion.RegionSettings.AllowLandResell = false;
                }

                if (regionPreset.StartsWith ("f", System.StringComparison.Ordinal))       
                {
                    // 'Full Region' setup
                    newRegion.RegionType = newRegion.RegionType + "Full Region";                   
                    //newRegion.RegionPort;            // use auto assigned port
                    newRegion.RegionTerrain = RegionTerrain;
                    newRegion.Startup = StartupType.Normal;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = false;
                    newRegion.ObjectCapacity = 15000;
                    newRegion.RegionSettings.AgentLimit = 100;
                    if (newRegion.RegionType.StartsWith ("M", System.StringComparison.Ordinal))                           // defaults are 'true'
                    {
                        newRegion.RegionSettings.AllowLandJoinDivide = false;
                        newRegion.RegionSettings.AllowLandResell = false;
                    }
                }

                if (RegionLoadTerrain.Length > 0)
                {
                    // we are loading terrain from a file... handled later
                    newRegion.RegionTerrain = "Custom";
                }

                // Disabled as this is a work in progress and will break with the current scenemanager (Dec 5 - greythane-
                // TODO: !!! Assumes everything is local for now !!!               
                ISceneManager scenemanager = webInterface.Registry.RequestModuleInterface<ISceneManager> ();
                if (scenemanager.CreateRegion(newRegion))
                {   
                    IGridRegisterModule gridRegister = webInterface.Registry.RequestModuleInterface<IGridRegisterModule>();
                    if (gridRegister != null) {
                        if (gridRegister.RegisterRegionWithGrid (null, true, false, null)) {

                            response = "<h3>Successfully created region, redirecting to main page</h3>" +
                                "<script language=\"javascript\">" +
                                "setTimeout(function() {window.location.href = \"index.html\";}, 3000);" +
                                "</script>";
                        }
                    } 

                    //                        response = "<h3>" + error + "</h3>";
                    response = "<h3> Error registering region with grid</h3>";
                } else
                    response = "<h3>Error creating this region.</h3>";
                return null;
            }

            // we have or need data
            if (httpRequest.Query.ContainsKey ("regionid"))
            {
                var region = gridService.GetRegionByUUID (null, UUID.Parse (httpRequest.Query ["regionid"].ToString ()));

                vars.Add ("RegionName", region.RegionName);

                UserAccount estateOwnerAccount = null; 
                var estateOwner = UUID.Zero;

                IEstateConnector estateConnector = Framework.Utilities.DataManager.RequestPlugin<IEstateConnector> ();
                if (estateConnector != null) {
                    EstateSettings estate = estateConnector.GetEstateSettings (region.RegionID);
                    if (estate != null)
                        estateOwner = estate.EstateOwner;

                    var accountService = webInterface.Registry.RequestModuleInterface<IUserAccountService> ();
                    if (accountService != null)
                        estateOwnerAccount = accountService.GetUserAccount (null, estate.EstateOwner);
                }
                vars.Add ("OwnerUUID", estateOwner);
                vars.Add ("OwnerName", estateOwnerAccount != null ? estateOwnerAccount.Name : "No account found");

                vars.Add ("RegionLocX", region.RegionLocX / Constants.RegionSize);
                vars.Add ("RegionLocY", region.RegionLocY / Constants.RegionSize);
                vars.Add ("RegionSizeX", region.RegionSizeX);
                vars.Add ("RegionSizeY", region.RegionSizeY);
                vars.Add ("RegionType", region.RegionType);
                vars.Add ("RegionTerrain", region.RegionTerrain);
                vars.Add ("RegionOnline",
                    (region.Flags & (int)RegionFlags.RegionOnline) == (int)RegionFlags.RegionOnline
                          ? translator.GetTranslatedString ("Online")
                          : translator.GetTranslatedString ("Offline"));

                IWebHttpTextureService webTextureService = webInterface.Registry.
                    RequestModuleInterface<IWebHttpTextureService> ();
                if (webTextureService != null && region.TerrainMapImage != UUID.Zero)
                    vars.Add ("RegionImageURL", webTextureService.GetTextureURL (region.TerrainMapImage));
                else
                    vars.Add ("RegionImageURL", "images/icons/no_picture.jpg");
            } 
            else
            {
                // default values

                // check for user region name  seed
                string[] m_regionNameSeed = null;
                IConfig regionConfig =
                    webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs["FileBasedSimulationData"];

                 if (regionConfig != null)
                {
                    string regionNameSeed = regionConfig.GetString ("RegionNameSeed", "");
                    if (regionNameSeed != "")
                        m_regionNameSeed = regionNameSeed.Split (',');
                }

                var rNames = new Utilities.MarkovNameGenerator();
                string regionName = rNames.FirstName (m_regionNameSeed == null ? Utilities.RegionNames: m_regionNameSeed, 3,7);
                vars.Add ("RegionName", regionName);

                var scenemanager = webInterface.Registry.RequestModuleInterface<ISceneManager> ();
                var gconnector = Framework.Utilities.DataManager.RequestPlugin<IGenericsConnector>();
                var settings = gconnector.GetGeneric<WebUISettings>(UUID.Zero, "WebUISettings", "Settings");
                if (settings == null)
                    settings = new WebUISettings ();
                
                // get some current details
                //List<GridRegion> regions = gridService.GetRegionsByName(null, "", null,null);

                var currentInfo = scenemanager.FindCurrentRegionInfo ();
                //Dictionary<string, int> currentInfo = null;
                if (currentInfo != null)
                {
                    vars.Add ("RegionLocX", currentInfo ["minX"] > 0 ? currentInfo ["minX"] : settings.MapCenter.X);
                    vars.Add ("RegionLocY", currentInfo ["minY"] > 0 ? currentInfo ["minY"] : settings.MapCenter.Y);
                    vars.Add("RegionPort", currentInfo ["port"] > 0 ? currentInfo ["port"] + 1 : 9000);
                } else
                {
                    vars.Add ("RegionLocX", settings.MapCenter.X);
                    vars.Add ("RegionLocY", settings.MapCenter.Y);
                    vars.Add("RegionPort", 9000);

                }

                   
                vars.Add ("RegionSizeX", Constants.RegionSize);
                vars.Add ("RegionSizeY", Constants.RegionSize);
                vars.Add ("RegionType", webInterface.RegionTypeArgs(translator));
                vars.Add ("RegionPresetType", webInterface.RegionPresetArgs(translator));
                vars.Add ("RegionTerrain", webInterface.RegionTerrainArgs(translator));
              
            }

                // Labels
                //vars.Add ("RegionInformationText", translator.GetTranslatedString ("RegionInformationText"));
            vars.Add ("RegionNameText", translator.GetTranslatedString ("RegionNameText"));
            vars.Add ("RegionLocationText", translator.GetTranslatedString ("RegionLocationText"));
            vars.Add ("RegionSizeText", translator.GetTranslatedString ("RegionSizeText"));
            vars.Add ("RegionTypeText", translator.GetTranslatedString ("RegionTypeText"));
            vars.Add ("RegionPresetText", translator.GetTranslatedString ("RegionPresetText"));
            vars.Add ("RegionTerrainText", translator.GetTranslatedString ("RegionTerrainText"));
            vars.Add ("OwnerNameText", translator.GetTranslatedString ("OwnerNameText"));
            vars.Add ("RegionPortText", translator.GetTranslatedString ("RegionPortText"));
            vars.Add ("RegionDelayStartupText", translator.GetTranslatedString ("RegionDelayStartupText"));
            vars.Add ("RegionVisibilityText", translator.GetTranslatedString ("RegionVisibilityText"));
            vars.Add ("RegionInfiniteText", translator.GetTranslatedString ("RegionInfiniteText"));
            vars.Add ("RegionCapacityText", translator.GetTranslatedString ("RegionCapacityText"));
            vars.Add ("Yes", translator.GetTranslatedString ("Yes"));
            vars.Add ("No", translator.GetTranslatedString ("No"));
            vars.Add("Accept", translator.GetTranslatedString("Accept"));
            vars.Add("Submit", translator.GetTranslatedString("Submit"));
            vars.Add("SubmitURL", "home.html");
            vars.Add("ErrorMessage", "");


         

            return vars;
        }
Exemplo n.º 6
0
        public Dictionary<string, object> Fill (WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                               OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
                                               ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object> ();
            var gridService = webInterface.Registry.RequestModuleInterface<IGridService> ();
            vars.Add ("RegionServerURL", webInterface.GridURL);  // This needs to be sorted out for grid regions

            #region EditRegion
            if (requestParameters.ContainsKey ("Submit")) {

                string RegionServerURL = requestParameters ["RegionServerURL"].ToString ();
                // required
                if (RegionServerURL == "") {
                    response = "<h3>" + translator.GetTranslatedString ("RegionServerURLError") + "</h3>";
                    return null;
                }

                var regionID = requestParameters ["RegionID"].ToString ();
                var regionName = requestParameters ["RegionName"].ToString ();
                //var OwnerUUID = requestParameters["OwnerUUID"].ToString();
                var regionLocX = requestParameters ["RegionLocX"].ToString ();
                var regionLocY = requestParameters ["RegionLocY"].ToString ();
                var regionSizeX = requestParameters ["RegionSizeX"].ToString ();
                var regionSizeY = requestParameters ["RegionSizeY"].ToString ();

                var regionType = requestParameters ["RegionType"].ToString ();
                var regionPresetType = requestParameters ["RegionPresetType"].ToString ();
                var regionTerrain = requestParameters ["RegionTerrain"].ToString ();

                var regionLoadTerrain = requestParameters.ContainsKey ("RegionLoadTerrain")
                    ? requestParameters ["RegionLoadTerrain"].ToString ()
                    : "";

                // a bit of idiot proofing
                if (regionName == "") {
                    response = "<h3>" + translator.GetTranslatedString ("RegionNameError") + "</h3>";
                    return null;
                }
                if ((regionLocX == "") || (regionLocY == "")) {
                    response = "<h3>" + translator.GetTranslatedString ("RegionLocationError") + "</h3>";
                    return null;
                }

                // so far so good...
                // build the new region details

                int RegionPort = int.Parse (requestParameters ["RegionPort"].ToString ());


                var newRegion = new RegionInfo ();
                if (regionID != "")
                    newRegion.RegionID = UUID.Parse (regionID);

                newRegion.RegionName = regionName;
                newRegion.RegionType = regionType;
                newRegion.RegionLocX = int.Parse (regionLocX);
                newRegion.RegionLocY = int.Parse (regionLocY);
                newRegion.RegionSizeX = int.Parse (regionSizeX);
                newRegion.RegionSizeY = int.Parse (regionSizeY);

                newRegion.RegionPort = RegionPort;
                newRegion.SeeIntoThisSimFromNeighbor = true;
                newRegion.InfiniteRegion = true;
                newRegion.ObjectCapacity = 50000;
                newRegion.Startup = StartupType.Normal;

                var regionPreset = regionPresetType.ToLower (); //SubString(0,1);
                if (regionPreset.StartsWith ("c", System.StringComparison.Ordinal)) {
                    newRegion.RegionPort = int.Parse (requestParameters ["RegionPort"].ToString ());
                    newRegion.SeeIntoThisSimFromNeighbor = (requestParameters ["RegionVisibility"].ToString ().ToLower () == "yes");
                    newRegion.InfiniteRegion = (requestParameters ["RegionInfinite"].ToString ().ToLower () == "yes");
                    newRegion.ObjectCapacity = int.Parse (requestParameters ["RegionCapacity"].ToString ());

                    string delayStartup = requestParameters ["RegionDelayStartup"].ToString ();
                    newRegion.Startup = delayStartup.StartsWith ("n", System.StringComparison.Ordinal) ? StartupType.Normal : StartupType.Medium;

                }

                if (regionPreset.StartsWith ("w", System.StringComparison.Ordinal)) {
                    // 'standard' setup
                    newRegion.RegionType = newRegion.RegionType + "Whitecore";
                    //info.RegionPort;            // use auto assigned port
                    newRegion.RegionTerrain = "Flatland";
                    newRegion.Startup = StartupType.Normal;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = true;
                    newRegion.ObjectCapacity = 50000;
                    newRegion.RegionPort = RegionPort;


                }
                if (regionPreset.StartsWith ("o", System.StringComparison.Ordinal)) {
                    // 'Openspace' setup
                    newRegion.RegionType = newRegion.RegionType + "Openspace";
                    //newRegion.RegionPort;            // use auto assigned port
                    if (regionTerrain.StartsWith ("a", System.StringComparison.Ordinal))
                        newRegion.RegionTerrain = "Aquatic";
                    else
                        newRegion.RegionTerrain = "Grassland";
                    newRegion.Startup = StartupType.Medium;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = true;
                    newRegion.ObjectCapacity = 750;
                    newRegion.RegionSettings.AgentLimit = 10;
                    newRegion.RegionSettings.AllowLandJoinDivide = false;
                    newRegion.RegionSettings.AllowLandResell = false;
                }
                if (regionPreset.StartsWith ("h", System.StringComparison.Ordinal)) {
                    // 'Homestead' setup
                    newRegion.RegionType = newRegion.RegionType + "Homestead";
                    //info.RegionPort;            // use auto assigned port
                    newRegion.RegionTerrain = "Homestead";
                    newRegion.Startup = StartupType.Medium;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = true;
                    newRegion.ObjectCapacity = 3750;
                    newRegion.RegionSettings.AgentLimit = 20;
                    newRegion.RegionSettings.AllowLandJoinDivide = false;
                    newRegion.RegionSettings.AllowLandResell = false;
                }

                if (regionPreset.StartsWith ("f", System.StringComparison.Ordinal)) {
                    // 'Full Region' setup
                    newRegion.RegionType = newRegion.RegionType + "Full Region";
                    //newRegion.RegionPort;            // use auto assigned port
                    newRegion.RegionTerrain = regionTerrain;
                    newRegion.Startup = StartupType.Normal;
                    newRegion.SeeIntoThisSimFromNeighbor = true;
                    newRegion.InfiniteRegion = true;
                    newRegion.ObjectCapacity = 15000;
                    newRegion.RegionSettings.AgentLimit = 100;
                    if (newRegion.RegionType.StartsWith ("M", System.StringComparison.Ordinal))                           // defaults are 'true'
                    {
                        newRegion.RegionSettings.AllowLandJoinDivide = false;
                        newRegion.RegionSettings.AllowLandResell = false;
                    }
                }

                if (regionLoadTerrain.Length > 0) {
                    // we are loading terrain from a file... handled later
                    newRegion.RegionTerrain = "Custom";
                }

                // TODO: !!! Assumes everything is local for now !!!  
                if (requestParameters.ContainsKey ("NewRegion")) {
                    ISceneManager scenemanager = webInterface.Registry.RequestModuleInterface<ISceneManager> ();
                    if (scenemanager.CreateRegion (newRegion)) {
                        response = "<h3>Successfully created region</h3>" +
                            "<script language=\"javascript\">" +
                            "setTimeout(function() {window.location.href = \"/?page=region_manager\";}, 2000);" +
                            "</script>";
                        return null;
                    }
                    response = "<h3>Error creating this region.</h3>";
                    return null;
                }
/* not necessary??
                     IGridRegisterModule gridRegister = webInterface.Registry.RequestModuleInterface<IGridRegisterModule> ();
                        if (gridRegister != null) {
                            if (gridRegister.RegisterRegionWithGrid (null, true, false, null)) {
                        
                            }
                        

                        //                        response = "<h3>" + error + "</h3>";
                        response = "<h3> Error registering region with grid</h3>";
                }
*/
                // update region details
                var infoConnector = Framework.Utilities.DataManager.RequestPlugin<IRegionInfoConnector> ();
                if (infoConnector != null) {
                    infoConnector.UpdateRegionInfo (newRegion);

                    response = "<h3>Region details updated.</h3>" +
                    "<script language=\"javascript\">" +
                    "setTimeout(function() {window.location.href = \"/?page=region_manager\";}, 2000);" +
                    "</script>";
                } else
                    response = "<h3>Unable to update Region details!</h3>" +
                    "<script language=\"javascript\">" +
                    "setTimeout(function() {window.location.href = \"/?page=region_manager\";}, 2000);" +
                    "</script>";
                return null;

            }
            #endregion 

            #region EditRegion
            // we have or need data
            if (httpRequest.Query.ContainsKey ("regionid")) {
                var region = gridService.GetRegionByUUID (null, UUID.Parse (httpRequest.Query ["regionid"].ToString ()));

                vars.Add ("RegionID", region.RegionID.ToString ());
                vars.Add ("RegionName", region.RegionName);

                UserAccount estateOwnerAccount = null;
                var estateOwner = UUID.Zero;
                var estateId = -1;

                IEstateConnector estateConnector = Framework.Utilities.DataManager.RequestPlugin<IEstateConnector> ();
                if (estateConnector != null) {
                    EstateSettings estate = estateConnector.GetEstateSettings (region.RegionID);
                    if (estate != null) {
                        estateId = (int)estate.EstateID;
                        estateOwner = estate.EstateOwner;
                    }
                    var accountService = webInterface.Registry.RequestModuleInterface<IUserAccountService> ();
                    if (accountService != null)
                        estateOwnerAccount = accountService.GetUserAccount (null, estate.EstateOwner);
                }

                vars.Add ("EstateList", WebHelpers.EstateSelections (webInterface.Registry, null, estateId));
                vars.Add ("OwnerUUID", region.EstateOwner);
                vars.Add ("OwnerName", estateOwnerAccount != null ? estateOwnerAccount.Name : "No account found");

                vars.Add ("RegionLocX", region.RegionLocX / Constants.RegionSize);
                vars.Add ("RegionLocY", region.RegionLocY / Constants.RegionSize);
                vars.Add ("RegionSizeX", region.RegionSizeX);
                vars.Add ("RegionSizeY", region.RegionSizeY);
                vars.Add ("RegionPort", region.InternalPort.ToString ());
                vars.Add ("RegionType", WebHelpers.RegionTypeArgs (translator, region.RegionType));
                vars.Add ("RegionPresetType", WebHelpers.RegionPresetArgs (translator, region.RegionType));
                vars.Add ("RegionTerrain", WebHelpers.RegionTerrainArgs (translator, region.RegionTerrain));

                // TODO:  This will not work yet  :)
                bool switches = false;
                var infoConnector = Framework.Utilities.DataManager.RequestPlugin<IRegionInfoConnector> ();
                if (infoConnector != null) {
                    var regionInfo = infoConnector.GetRegionInfo (region.RegionID);
                    if (regionInfo != null) {
                        vars.Add ("RegionCapacity", regionInfo.ObjectCapacity.ToString ());
                        vars.Add ("RegionVisibility", WebHelpers.YesNoSelection (translator, regionInfo.SeeIntoThisSimFromNeighbor));
                        vars.Add ("RegionInfinite", WebHelpers.YesNoSelection (translator, regionInfo.InfiniteRegion));
                        vars.Add ("RegionDelayStartup", WebHelpers.RegionStartupSelection (translator, regionInfo.Startup));
                    }
                }
                if (!switches) {
                    vars.Add ("RegionCapacity", "Unknown");
                    vars.Add ("RegionVisibility", WebHelpers.YesNoSelection (translator, true));
                    vars.Add ("RegionInfinite", WebHelpers.YesNoSelection (translator, true));
                    vars.Add ("RegionDelayStartup", WebHelpers.RegionStartupSelection (translator, StartupType.Normal));
                }


                //vars.Add ("RegionOnline",
                //    (region.Flags & (int)RegionFlags.RegionOnline) == (int)RegionFlags.RegionOnline
                //          ? translator.GetTranslatedString ("Online")
                //          : translator.GetTranslatedString ("Offline"));

                IWebHttpTextureService webTextureService = webInterface.Registry.
                    RequestModuleInterface<IWebHttpTextureService> ();
                if (webTextureService != null && region.TerrainMapImage != UUID.Zero)
                    vars.Add ("RegionImageURL", webTextureService.GetTextureURL (region.TerrainMapImage));
                else
                    vars.Add ("RegionImageURL", "images/icons/no_picture.jpg");

                vars.Add ("Submit", translator.GetTranslatedString ("SaveUpdates"));

            }
            #endregion
            else
            #region NewRegion    
            {
                // default values

                // check for user region name  seed
                string [] m_regionNameSeed = null;
                IConfig regionConfig =
                    webInterface.Registry.RequestModuleInterface<ISimulationBase> ().ConfigSource.Configs ["FileBasedSimulationData"];

                if (regionConfig != null) {
                    string regionNameSeed = regionConfig.GetString ("RegionNameSeed", "");
                    if (regionNameSeed != "")
                        m_regionNameSeed = regionNameSeed.Split (',');
                }

                var rNames = new Utilities.MarkovNameGenerator ();
                string regionName = rNames.FirstName (m_regionNameSeed == null ? Utilities.RegionNames : m_regionNameSeed, 3, 7);
                vars.Add ("RegionID", "");
                vars.Add ("RegionName", regionName);

                var scenemanager = webInterface.Registry.RequestModuleInterface<ISceneManager> ();
                var gconnector = Framework.Utilities.DataManager.RequestPlugin<IGenericsConnector> ();
                var settings = gconnector.GetGeneric<WebUISettings> (UUID.Zero, "WebUISettings", "Settings");
                if (settings == null)
                    settings = new WebUISettings ();

                // get some current details (This may be better than using scenemanager)
                //List<GridRegion> regions = gridService.GetRegionsByName(null, "", null,null);

                var currentInfo = scenemanager.FindCurrentRegionInfo ();
                //Dictionary<string, int> currentInfo = null;
                if (currentInfo != null) {
                    vars.Add ("RegionLocX", currentInfo ["minX"] > 0 ? currentInfo ["minX"] : settings.MapCenter.X);
                    vars.Add ("RegionLocY", currentInfo ["minY"] > 0 ? currentInfo ["minY"] : settings.MapCenter.Y);
                    vars.Add ("RegionPort", currentInfo ["port"] > 0 ? currentInfo ["port"] + 1 : 9000);
                } else {
                    vars.Add ("RegionLocX", settings.MapCenter.X);
                    vars.Add ("RegionLocY", settings.MapCenter.Y);
                    vars.Add ("RegionPort", 9000);

                }


                vars.Add ("RegionSizeX", Constants.RegionSize);
                vars.Add ("RegionSizeY", Constants.RegionSize);
                vars.Add ("RegionType", WebHelpers.RegionTypeArgs (translator, ""));
                vars.Add ("RegionPresetType", WebHelpers.RegionPresetArgs (translator, ""));
                vars.Add ("RegionTerrain", WebHelpers.RegionTerrainArgs (translator, ""));
                vars.Add ("EstateList", WebHelpers.EstateSelections (webInterface.Registry, null, -1));
                vars.Add ("RegionCapacity", "Unknown");
                vars.Add ("RegionVisibility", WebHelpers.YesNoSelection (translator, true));
                vars.Add ("RegionInfinite", WebHelpers.YesNoSelection (translator, true));
                vars.Add ("RegionDelayStartup", WebHelpers.RegionStartupSelection (translator, StartupType.Normal)); // normal startup
                vars.Add ("Submit", translator.GetTranslatedString ("Save"));

            }
            #endregion

            vars.Add ("RegionPresets", WebHelpers.RegionSelections (webInterface.Registry));

            // Labels
            vars.Add ("RegionManagerText", translator.GetTranslatedString ("MenuRegionManager"));
            vars.Add ("RegionNameText", translator.GetTranslatedString ("RegionNameText"));
            vars.Add ("RegionLocationText", translator.GetTranslatedString ("RegionLocationText"));
            vars.Add ("RegionSizeText", translator.GetTranslatedString ("RegionSizeText"));
            vars.Add ("RegionTypeText", translator.GetTranslatedString ("RegionTypeText"));
            vars.Add ("RegionPresetText", translator.GetTranslatedString ("RegionPresetText"));
            vars.Add ("RegionTerrainText", translator.GetTranslatedString ("RegionTerrainText"));
            vars.Add ("EstateText", translator.GetTranslatedString ("EstateText"));
            vars.Add ("OwnerNameText", translator.GetTranslatedString ("OwnerNameText"));
            vars.Add ("RegionPortText", translator.GetTranslatedString ("RegionPortText"));
            vars.Add ("RegionDelayStartupText", translator.GetTranslatedString ("RegionDelayStartupText"));
            vars.Add ("RegionVisibilityText", translator.GetTranslatedString ("RegionVisibilityText"));
            vars.Add ("RegionInfiniteText", translator.GetTranslatedString ("RegionInfiniteText"));
            vars.Add ("RegionCapacityText", translator.GetTranslatedString ("RegionCapacityText"));
            vars.Add ("Cancel", translator.GetTranslatedString ("Cancel"));
            vars.Add ("InfoMessage", "");




            return vars;
        }
        /// <summary>
        /// Creates the grid owner user on a clean startup.
        /// Sets user to 'Charter Meneber" and elevates to  "God" status
        /// </summary>
        void CreateGridOwnerUser ()
        {

            string userName = "";
            string password, email, uuid;

            // Get user name
            // check for user name seed
            IConfig loginConfig = m_config.Configs ["LoginService"];
            if (loginConfig != null) {
                string userNameSeed = loginConfig.GetString ("UserNameSeed", "");
                if (userNameSeed != "")
                    m_userNameSeed = userNameSeed.Split (',');
            }

            var ufNames = new Utilities.MarkovNameGenerator ();
            var ulNames = new Utilities.MarkovNameGenerator ();
            string [] nameSeed = m_userNameSeed == null ? Utilities.UserNames : m_userNameSeed;

            string firstName = ufNames.FirstName (nameSeed, 3, 4);
            string lastName = ulNames.FirstName (nameSeed, 5, 6);
            string enteredName = firstName + " " + lastName;
            if (userName != "")
                enteredName = userName;

            do {
                userName = MainConsole.Instance.Prompt ("Grid owner user name (? for suggestion)", enteredName);
                if (userName == "" || userName == "?") {
                    enteredName = ufNames.NextName + " " + ulNames.NextName;
                    userName = "";
                    continue;
                }
                var fl = userName.Split (' ');
                if (fl.Length < 2) {
                    MainConsole.Instance.CleanInfo ("    User name must be <firstname> <lastname>");
                    userName = "";
                }
            } while (userName == "");
            ufNames.Reset ();
            ulNames.Reset ();

            // password 
            var pwmatch = false;
            do {
                password = MainConsole.Instance.PasswordPrompt ("Password");
                if (password == "") {
                    MainConsole.Instance.CleanInfo (" .... password must not be empty, please re-enter");
                    continue;
                }
                var passwordAgain = MainConsole.Instance.PasswordPrompt ("Re-enter Password");
                pwmatch = (password == passwordAgain);
                if (!pwmatch)
                    MainConsole.Instance.CleanInfo (" .... passwords did not match, please re-enter");
            } while (!pwmatch);

            // email
            email = MainConsole.Instance.Prompt ("Email for password recovery. ('none' if unknown)", "none");

            if ((email.ToLower () != "none") && !Utilities.IsValidEmail (email)) {
                MainConsole.Instance.CleanInfo ("This does not look like a valid email address. ('none' if unknown)");
                email = MainConsole.Instance.Prompt ("Email", email);
            }

            // Get available user avatar archives
            var userAvatarArchive = "";
            IAvatarAppearanceArchiver avieArchiver = m_registry.RequestModuleInterface<IAvatarAppearanceArchiver> ();
            if (avieArchiver != null) {
                List<string> avatarArchives = avieArchiver.GetAvatarArchiveFilenames ();

                if (avatarArchives.Count > 0) {
                    avatarArchives.Add ("None");
                    userAvatarArchive = MainConsole.Instance.Prompt ("Avatar archive to use", "None", avatarArchives);
                    if (userAvatarArchive == "None")
                        userAvatarArchive = "";
                }
            }

            // Allow the modification of UUID if required - for matching user UUID with other Grids etc like SL
            uuid = UUID.Random ().ToString ();
            while (true) {
                uuid = MainConsole.Instance.Prompt ("Required avatar UUID (optional))", uuid);
                UUID test;
                if (UUID.TryParse (uuid, out test))
                    break;

                MainConsole.Instance.Error ("There was a problem verifying this UUID. Please retry.");
            }

            // this really should not normally be altered so hide it
            //scopeID = UUID.Zero.ToString ();
            //if (sysFlag) {
            //    scopeID = MainConsole.Instance.Prompt ("Scope (Don't change unless you know what this is)", scopeID);
            //}

            // we should be good to go
            //m_accountService.CreateUser (UUID.Parse (uuid), UUID.Parse (scopeID), userName, Util.Md5Hash (password), email);
            m_accountService.CreateUser (UUID.Parse (uuid), UUID.Zero, userName, Util.Md5Hash (password), email);
            // CreateUser will tell us success or problem
            //MainConsole.Instance.InfoFormat("[User account service]: User '{0}' created", name);

            // check for success
            UserAccount account = m_accountService.GetUserAccount (null, userName);
            if (account != null) {
                account.UserFlags = Constants.USER_FLAG_CHARTERMEMBER;
                account.UserLevel = 250;
                m_accountService.StoreUserAccount (account);

                // update profile for the user as well
                var profileConnector = Framework.Utilities.DataManager.RequestPlugin<IProfileConnector> ();
                if (profileConnector != null) {
                    var profile = profileConnector.GetUserProfile (account.PrincipalID);
                    if (profile == null) {
                        profileConnector.CreateNewProfile (account.PrincipalID);          // create a profile for the user
                        profile = profileConnector.GetUserProfile (account.PrincipalID);
                    }

                    if (userAvatarArchive != "")
                        profile.AArchiveName = userAvatarArchive + ".aa";
                    profile.MembershipGroup = "Charter_Member";
                    profile.IsNewUser = true;
                    profileConnector.UpdateUserProfile (profile);
                }
            } else
               MainConsole.Instance.WarnFormat ("[System User account service]: There was a problem creating the account for '{0}'", userName);
        }