Example #1
0
        public override string RegisterRegion(UUID scopeID, GridRegion regionInfo)
        {
            string msg = m_LocalGridService.RegisterRegion(scopeID, regionInfo);

            if (msg == String.Empty)
            {
                return(base.RegisterRegion(scopeID, regionInfo));
            }

            return(msg);
        }
        public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
        {
            string msg = m_LocalGridService.RegisterRegion(scopeID, regionInfo);

            if (msg == string.Empty && m_RemoteGridService != null)
            {
                return(m_RemoteGridService.RegisterRegion(scopeID, regionInfo));
            }

            return(msg);
        }
Example #3
0
        public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
        {
            m_log.DebugFormat("[RemoteGridServiceConnector]: Register Region {0} Server {1} HTTP Port: {2} X:{3} Y:{4}",
                              regionInfo.RegionName, regionInfo.ServerURI, regionInfo.HttpPort,
                              regionInfo.RegionCoordX, regionInfo.RegionCoordY);

            string msg = m_LocalGridService.RegisterRegion(scopeID, regionInfo);

            if (msg == String.Empty)
            {
                return(m_RemoteGridService.RegisterRegion(scopeID, regionInfo));
            }

            return(msg);
        }
        /// <summary>
        /// Create secure Urls that only us and the sim that called us know of
        /// This Urls is used to add/remove agents and other information from the other sim
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public IWCCertificate BuildSecureUrlsForConnection(IWCCertificate c)
        {
            IGridRegistrationService gridRegistration = Registry.RequestModuleInterface <IGridRegistrationService>();

            if (gridRegistration != null)
            {
                IGridService gridService = Registry.RequestModuleInterface <IGridService>();
                if (gridService != null)
                {
                    GridRegion r = gridService.GetRegionByName(UUID.Zero, c.Connection.UserName + "_Link");
                    if (r == null)
                    {
                        uint  rX           = (uint)Util.RandomClass.Next(10000, 1000000);
                        uint  rY           = (uint)Util.RandomClass.Next(10000, 1000000);
                        ulong regionhandle = Utils.UIntsToLong(rX, rY);

                        r              = new GridRegion();
                        r.RegionID     = UUID.Random();
                        r.RegionHandle = regionhandle;
                        IHttpServer server = m_registry.RequestModuleInterface <ISimulationBase>().GetHttpServer(0);
                        r.ExternalHostName = server.HostName;
                        if (r.ExternalHostName.StartsWith("http://"))
                        {
                            r.ExternalHostName = r.ExternalHostName.Remove(0, 7);
                        }
                        else if (r.ExternalHostName.StartsWith("https://"))
                        {
                            r.ExternalHostName = r.ExternalHostName.Remove(0, 8);
                        }
                        r.InternalEndPoint = new IPEndPoint(IPAddress.Any, (int)server.Port);
                        r.Flags            = (int)Aurora.Framework.RegionFlags.Foreign;
                        r.RegionName       = c.Connection.UserName + "_Link";
                        r.RegionType       = "Link";

                        UUID SessionID;
                        gridService.RegisterRegion(r, UUID.Zero, out SessionID);
                    }
                    //Give the basic Urls that we have
                    c.Connection.SecureUrls = gridRegistration.GetUrlForRegisteringClient(c.Connection.UserName, r.RegionHandle);
                }
            }
            return(c);
        }
        /// <summary>
        ///   Register this region with the grid service
        /// </summary>
        /// <param name = "scene"></param>
        /// <param name = "returnResponseFirstTime">Should we try to walk the user through what went wrong?</param>
        /// <param name="continueTrying"> </param>
        /// <param name="password"> </param>
        public bool RegisterRegionWithGrid(IScene scene, bool returnResponseFirstTime, bool continueTrying, string password)
        {
            GridRegion region = BuildGridRegion(scene.RegionInfo);

            IGenericsConnector g           = DataManager.DataManager.RequestPlugin <IGenericsConnector>();
            GridSessionID      s           = null;
            IGridService       GridService = scene.RequestModuleInterface <IGridService>();

            if (g != null) //Get the sessionID from the database if possible
            {
                s = g.GetGeneric <GridSessionID>(scene.RegionInfo.RegionID, "GridSessionID", "GridSessionID");
            }

            if (s == null)
            {
                s = new GridSessionID {
                    SessionID = scene.RegionInfo.GridSecureSessionID
                };
                //Set it from the regionInfo if it knows anything
            }

            scene.RequestModuleInterface <ISimulationBase>().EventManager.FireGenericEventHandler("PreRegisterRegion", region);

            //Tell the grid service about us
            RegisterRegion error = GridService.RegisterRegion(region, s.SessionID, password);

            if (error.Error == String.Empty)
            {
                s.SessionID = error.SessionID;
                //If it registered ok, we save the sessionID to the database and tlel the neighbor service about it
                scene.RegionInfo.GridSecureSessionID = error.SessionID;
                //Update our local copy of what our region flags are
                scene.RegionInfo.RegionFlags = error.RegionFlags;
                scene.RegionInfo.ScopeID     = error.Region.ScopeID;
                scene.RegionInfo.AllScopeIDs = error.Region.AllScopeIDs;

                //Save the new SessionID to the database
                if (g != null)
                {
                    g.AddGeneric(scene.RegionInfo.RegionID, "GridSessionID", "GridSessionID", s.ToOSD());
                }

                m_knownNeighbors[scene.RegionInfo.RegionID] = error.Neighbors;
                return(true); //Success
            }
            if (returnResponseFirstTime && !continueTrying)
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region with grid failed again - " + error.Error);
                return(false);
            }

            //Parse the error and try to do something about it if at all possible
            if (error.Error == "Region location is reserved")
            {
                MainConsole.Instance.Error(
                    "[RegisterRegionWithGrid]: Registration of region with grid failed - The region location you specified is reserved. You must move your region.");
                int X = 0, Y = 0;
                int.TryParse(MainConsole.Instance.Prompt("New Region Location X", "1000"), out X);
                int.TryParse(MainConsole.Instance.Prompt("New Region Location Y", "1000"), out Y);

                scene.RegionInfo.RegionLocX = X * Constants.RegionSize;
                scene.RegionInfo.RegionLocY = Y * Constants.RegionSize;

                IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                foreach (IRegionLoader loader in loaders)
                {
                    loader.UpdateRegionInfo(scene.RegionInfo.RegionName, scene.RegionInfo);
                }
            }
            else if (error.Error == "Region overlaps another region")
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName +
                                           " with the grid failed - The region location you specified is already in use. You must move your region.");
                int X = 0, Y = 0;
                int.TryParse(
                    MainConsole.Instance.Prompt("New Region Location X",
                                                (scene.RegionInfo.RegionLocX / 256).ToString()), out X);
                int.TryParse(
                    MainConsole.Instance.Prompt("New Region Location Y",
                                                (scene.RegionInfo.RegionLocY / 256).ToString()), out Y);

                scene.RegionInfo.RegionLocX = X * Constants.RegionSize;
                scene.RegionInfo.RegionLocY = Y * Constants.RegionSize;

                IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                foreach (IRegionLoader loader in loaders)
                {
                    loader.UpdateRegionInfo(scene.RegionInfo.RegionName, scene.RegionInfo);
                }
            }
            else if (error.Error.Contains("Can't move this region"))
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName +
                                           " with the grid failed - You can not move this region. Moving it back to its original position.");
                //Opensim Grid Servers don't have this functionality.
                try
                {
                    string[] position = error.Error.Split(',');

                    scene.RegionInfo.RegionLocX = int.Parse(position[1]) * Constants.RegionSize;
                    scene.RegionInfo.RegionLocY = int.Parse(position[2]) * Constants.RegionSize;

                    IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                    foreach (IRegionLoader loader in loaders)
                    {
                        loader.UpdateRegionInfo(scene.RegionInfo.RegionName, scene.RegionInfo);
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Error(
                        "Unable to move the region back to its original position, is this an opensim server? Please manually move the region back.");
                    throw e;
                }
            }
            else if (error.Error == "Duplicate region name")
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName +
                                           " with the grid failed - The region name you specified is already in use. Please change the name.");
                string oldRegionName = scene.RegionInfo.RegionName;
                scene.RegionInfo.RegionName = MainConsole.Instance.Prompt("New Region Name", "");

                IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                foreach (IRegionLoader loader in loaders)
                {
                    loader.UpdateRegionInfo(oldRegionName, scene.RegionInfo);
                }
            }
            else if (error.Error == "Region locked out")
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName +
                                           " with the grid the failed - The region you are attempting to join has been blocked from connecting. Please connect another region.");
                MainConsole.Instance.Prompt("Press enter when you are ready to exit");
                Environment.Exit(0);
            }
            else if (error.Error == "Could not reach grid service")
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName +
                                           " with the grid failed - The grid service can not be found! Please make sure that you can connect to the grid server and that the grid server is on.");
                MainConsole.Instance.Error(
                    "You should also make sure you've provided the correct address and port of the grid service.");
                string input =
                    MainConsole.Instance.Prompt(
                        "Press enter when you are ready to proceed, or type cancel to exit");
                if (input == "cancel")
                {
                    Environment.Exit(0);
                }
            }
            else if (error.Error == "Wrong Session ID")
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName +
                                           " with the grid failed - Wrong Session ID for this region!");
                MainConsole.Instance.Error(
                    "This means that this region has failed to connect to the grid server and needs removed from it before it can connect again.");
                MainConsole.Instance.Error(
                    "If you are running the Aurora.Server instance this region is connecting to, type \"clear grid region <RegionName>\" and then press enter on this console and it will work");
                MainConsole.Instance.Error(
                    "If you are not running the Aurora.Server instance this region is connecting to, please contact your grid operator so that he can fix it");

                string input =
                    MainConsole.Instance.Prompt(
                        "Press enter when you are ready to proceed, or type cancel to exit");
                if (input == "cancel")
                {
                    Environment.Exit(0);
                }
            }
            else
            {
                MainConsole.Instance.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName +
                                           " with the grid failed - " + error.Error + "!");
                string input =
                    MainConsole.Instance.Prompt(
                        "Press enter when you are ready to proceed, or type cancel to exit");
                if (input == "cancel")
                {
                    Environment.Exit(0);
                }
            }
            return(RegisterRegionWithGrid(scene, true, continueTrying, password));
        }
        /// <summary>
        ///     Register this region with the grid service
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="returnResponseFirstTime">Should we try to walk the user through what went wrong?</param>
        /// <param name="continueTrying"> </param>
        /// <param name="password"> </param>
        public bool RegisterRegionWithGrid(IScene scene, bool returnResponseFirstTime, bool continueTrying,
                                           string password)
        {
            if (password == null)
            {
                password = m_RegisterRegionPassword;
            }

            GridRegion   region      = new GridRegion(scene.RegionInfo);
            IGridService GridService = scene.RequestModuleInterface <IGridService> ();

            scene.RequestModuleInterface <ISimulationBase> ()
            .EventManager.FireGenericEventHandler("PreRegisterRegion", region);

            // Tell the grid service about us
            RegisterRegion error = GridService.RegisterRegion(region, scene.RegionInfo.GridSecureSessionID, password,
                                                              ProtocolVersion.MAJOR_PROTOCOL_VERSION,
                                                              ProtocolVersion.MINOR_PROTOCOL_VERSION);

            if (error.Error == string.Empty)
            {
                // If it registered ok, we save the sessionID to the database and tell the neighbor service about it
                scene.RegionInfo.GridSecureSessionID = error.SessionID;
                // Update our local copy of what our region flags are
                scene.RegionInfo.RegionFlags = error.RegionFlags;
                scene.RegionInfo.ScopeID     = error.Region.ScopeID;
                scene.RegionInfo.AllScopeIDs = error.Region.AllScopeIDs;
                scene.RequestModuleInterface <IConfigurationService> ().SetURIs(error.URIs);
                m_knownNeighbors [scene.RegionInfo.RegionID] = error.Neighbors;

                return(true);    // Success
            }

            if (returnResponseFirstTime && !continueTrying)
            {
                MainConsole.Instance.Error(
                    "[RegisterRegionWithGrid]: Registration of region with grid failed again - " + error.Error);

                return(false);
            }

            // something failed...
            string errmsg = "[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid failed!";

            // Parse the error and try to do something about it if at all possible
            if (error.Error == "Region location is reserved")
            {
                var simbase = scene.RequestModuleInterface <ISimulationBase> ();

                MainConsole.Instance.Error(errmsg);
                MainConsole.Instance.Error("    The region location you specified is reserved. You must move your region.");
                int X;
                int Y;
                int.TryParse(MainConsole.Instance.Prompt("New Region Location X", simbase.MapCenterX.ToString()), out X);
                int.TryParse(MainConsole.Instance.Prompt("New Region Location Y", simbase.MapCenterY.ToString()), out Y);

                scene.RegionInfo.RegionLocX = X * Constants.RegionSize;
                scene.RegionInfo.RegionLocY = Y * Constants.RegionSize;
            }
            else if (error.Error == "Region overlaps another region")
            {
                MainConsole.Instance.Error(errmsg);
                MainConsole.Instance.Error("    The region location you specified is already in use. You must move your region.");
                int X;
                int Y;
                int.TryParse(
                    MainConsole.Instance.Prompt("New Region Location X",
                                                (scene.RegionInfo.RegionLocX / Constants.RegionSize).ToString()), out X);
                int.TryParse(
                    MainConsole.Instance.Prompt("New Region Location Y",
                                                (scene.RegionInfo.RegionLocY / Constants.RegionSize).ToString()), out Y);

                scene.RegionInfo.RegionLocX = X * Constants.RegionSize;
                scene.RegionInfo.RegionLocY = Y * Constants.RegionSize;
            }
            else if (error.Error.Contains("Can't move this region"))
            {
                MainConsole.Instance.Error(errmsg);
                MainConsole.Instance.Error("    You can not move this region. Moving it back to its original position.");
                // Opensim Grid Servers don't have this functionality.
                try {
                    string [] position = error.Error.Split(',');

                    scene.RegionInfo.RegionLocX = int.Parse(position [1]) * Constants.RegionSize;
                    scene.RegionInfo.RegionLocY = int.Parse(position [2]) * Constants.RegionSize;
                } catch (Exception) {
                    MainConsole.Instance.Error("Unable to move the region back to its original position, is this an Opensim server?");
                    MainConsole.Instance.Error("Please manually move the region back.");
                    throw;
                }
            }
            else if (error.Error == "Duplicate region name")
            {
                MainConsole.Instance.Error(errmsg);
                MainConsole.Instance.Error("    The region name you specified is already in use. Please change the name.");
                scene.RegionInfo.RegionName = MainConsole.Instance.Prompt("New Region Name", "");
            }
            else if (error.Error == "Region locked out")
            {
                MainConsole.Instance.Error(errmsg);
                MainConsole.Instance.Error("    The region you are attempting to join has been blocked from connecting.");
                MainConsole.Instance.Error("    Please connect another region.");
                MainConsole.Instance.Prompt("WhiteCore will exit. Press enter when you are ready to exit");
                Environment.Exit(0);
            }
            else if (error.Error == "Could not reach grid service")
            {
                MainConsole.Instance.Error(errmsg);
                MainConsole.Instance.Error("     The grid service can not be found!");
                MainConsole.Instance.Error("     Please make sure that you can connect to the grid server and that the grid server is on.");
                MainConsole.Instance.Error("     You should also make sure you've provided the correct address and port of the grid service.");
                string input =
                    MainConsole.Instance.Prompt("Press enter when you are ready to proceed, or type 'cancel' to exit");
                if (input == "cancel")
                {
                    Environment.Exit(0);
                }
            }
            else if (error.Error == "Wrong Session ID")
            {
                MainConsole.Instance.Error(errmsg);
                MainConsole.Instance.Error("    Wrong Session ID for this region!");
                MainConsole.Instance.Error("    This means that this region has failed to connect to the grid server");
                MainConsole.Instance.Error("    and needs removed from it before it can connect again.\n");
                MainConsole.Instance.Error("    If you are running the WhiteCore.Server instance this region is connecting to,");
                MainConsole.Instance.Error("    type \"grid clear region <RegionName>\" and then press enter on this console and it will work\n");
                MainConsole.Instance.Error("    If you are not running the WhiteCore.Server instance this region is connecting to,");
                MainConsole.Instance.Error("    please contact your grid operator so that the problem can be corrected");

                string input =
                    MainConsole.Instance.Prompt("Press enter when you are ready to proceed, or type cancel to exit");
                if (input == "cancel")
                {
                    Environment.Exit(0);
                }
            }
            else if (error.Error == "Grid is not fully ready yet, please try again shortly")
            {
                MainConsole.Instance.Error(errmsg + "- " + error.Error + ", retrying... ");
                System.Threading.Thread.Sleep(3000);    // Sleep for a bit and try again
            }
            else
            {
                MainConsole.Instance.Error(errmsg + " - " + error.Error + "!");
                string input =
                    MainConsole.Instance.Prompt("Press enter when you are ready to proceed, or type 'cancel' to exit");
                if (input == "cancel")
                {
                    Environment.Exit(0);
                }
            }

            return(RegisterRegionWithGrid(scene, true, continueTrying, password));
        }
 public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
 {
     return(m_GridService.RegisterRegion(scopeID, regionInfo));
 }
        byte[] Register(Dictionary <string, object> request)
        {
            UUID scopeID = UUID.Zero;

            if (request.ContainsKey("SCOPEID"))
            {
                UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
            }

            int versionNumberMin = 0, versionNumberMax = 0;

            if (request.ContainsKey("VERSIONMIN"))
            {
                Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
            }

            if (request.ContainsKey("VERSIONMAX"))
            {
                Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
            }

            // Check the protocol version
            // This is how it works:
            // Example 1:
            //   Client: [0 0]
            //   Server:       [1 1]
            //   ==> fail
            // Example 2:
            //   Client:       [1 1]
            //   Server: [0 0]
            //   ==> fail
            // Example 3:
            //   Client: [0 1]
            //   Server:   [1 1]
            //   ==> success
            // Example 4:
            //   Client:   [1 1]
            //   Server: [0 1]
            //   ==> success
            if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax || versionNumberMax < ProtocolVersions.ServerProtocolVersionMin))
            {
                // Can't do, there is no overlap in the acceptable ranges
                return(FailureResult());
            }

            Dictionary <string, object> rinfoData = new Dictionary <string, object>();
            GridRegion rinfo = null;

            try
            {
                foreach (KeyValuePair <string, object> kvp in request)
                {
                    rinfoData[kvp.Key] = kvp.Value.ToString();
                }
                rinfo = new GridRegion(rinfoData);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e);
            }

            string result = "Error communicating with grid service";

            if (rinfo != null)
            {
                result = m_GridService.RegisterRegion(scopeID, rinfo);
            }

            if (result == String.Empty)
            {
                return(SuccessResult());
            }
            else
            {
                return(FailureResult(result));
            }
        }
Example #9
0
        private byte[] Register(Dictionary <string, object> request)
        {
            int versionNumberMin = 0, versionNumberMax = 0;

            if (request.ContainsKey("VERSIONMIN"))
            {
                Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
            }
            else
            {
                MainConsole.Instance.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
            }

            if (request.ContainsKey("VERSIONMAX"))
            {
                Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
            }
            else
            {
                MainConsole.Instance.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
            }

            UUID sessionIDIn = UUID.Zero;

            if (request.ContainsKey("SESSIONID"))
            {
                UUID.TryParse(request["SESSIONID"].ToString(), out sessionIDIn);
            }
            else
            {
                MainConsole.Instance.WarnFormat("[GRID HANDLER]: no sessionID in request to register region");
            }

            // Check the protocol version
            if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax &&
                 versionNumberMax < ProtocolVersions.ServerProtocolVersionMax))
            {
                // Can't do, there is no overlap in the acceptable ranges
                return(FailureResult());
            }

            Dictionary <string, object> rinfoData = new Dictionary <string, object>();
            GridRegion rinfo = null;

            try
            {
                foreach (KeyValuePair <string, object> kvp in request)
                {
                    rinfoData[kvp.Key] = kvp.Value.ToString();
                }
                rinfo = new GridRegion(rinfoData);
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e);
            }

            string result = "Error communicating with grid service";

            UUID SessionID = UUID.Zero;
            List <GridRegion> neighbors;

            if (rinfo != null)
            {
                result = m_GridService.RegisterRegion(rinfo, sessionIDIn, out SessionID, out neighbors);
            }

            if (result == String.Empty)
            {
                return(SuccessResult(SessionID.ToString()));
            }
            else
            {
                return(FailureResult(result));
            }
        }
 public RegisterRegion RegisterRegion(GridRegion regionInfos, UUID oldSessionID)
 {
     return(m_localService.RegisterRegion(regionInfos, oldSessionID));
 }
Example #11
0
 public string RegisterRegion(GridRegion regionInfos, UUID oldSessionID, out UUID SessionID,
                              out List <GridRegion> neighbors)
 {
     return(m_localService.RegisterRegion(regionInfos, oldSessionID, out SessionID, out neighbors));
 }
Example #12
0
        /// <summary>
        /// Register this region with the grid service
        /// </summary>
        /// <param name="scene"></param>
        public void RegisterRegionWithGrid(IScene scene)
        {
            GridRegion region = BuildGridRegion(scene.RegionInfo);

            IGenericsConnector g           = Aurora.DataManager.DataManager.RequestPlugin <IGenericsConnector>();
            GridSessionID      s           = null;
            IGridService       GridService = scene.RequestModuleInterface <IGridService>();

            if (g != null) //Get the sessionID from the database if possible
            {
                s = g.GetGeneric <GridSessionID>(scene.RegionInfo.RegionID, "GridSessionID", "GridSessionID", new GridSessionID());
            }

            if (s == null)
            {
                s = new GridSessionID();
                //Set it from the regionInfo if it knows anything
                s.SessionID = scene.RegionInfo.GridSecureSessionID;
            }

            scene.RequestModuleInterface <ISimulationBase>().EventManager.FireGenericEventHandler("PreRegisterRegion", region);

            //Tell the grid service about us
            string error = GridService.RegisterRegion(region, s.SessionID, out s.SessionID);

            if (error == String.Empty)
            {
                //If it registered ok, we save the sessionID to the database and tlel the neighbor service about it
                scene.RegionInfo.GridSecureSessionID = s.SessionID;

                //Save the new SessionID to the database
                g.AddGeneric(scene.RegionInfo.RegionID, "GridSessionID", "GridSessionID", s.ToOSD());
            }
            else
            {
                //Parse the error and try to do something about it if at all possible
                if (error == "Region location is reserved")
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region with grid failed - The region location you specified is reserved. You must move your region.");
                    int X = 0, Y = 0;
                    int.TryParse(MainConsole.Instance.CmdPrompt("New Region Location X", "1000"), out X);
                    int.TryParse(MainConsole.Instance.CmdPrompt("New Region Location Y", "1000"), out Y);

                    scene.RegionInfo.RegionLocX = X * Constants.RegionSize;
                    scene.RegionInfo.RegionLocY = Y * Constants.RegionSize;

                    IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                    foreach (IRegionLoader loader in loaders)
                    {
                        loader.UpdateRegionInfo(scene.RegionInfo.RegionName, scene.RegionInfo);
                    }
                }
                if (error == "Region overlaps another region")
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid failed - The region location you specified is already in use. You must move your region.");
                    int X = 0, Y = 0;
                    int.TryParse(MainConsole.Instance.CmdPrompt("New Region Location X", "1000"), out X);
                    int.TryParse(MainConsole.Instance.CmdPrompt("New Region Location Y", "1000"), out Y);

                    scene.RegionInfo.RegionLocX = X * Constants.RegionSize;
                    scene.RegionInfo.RegionLocY = Y * Constants.RegionSize;

                    IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                    foreach (IRegionLoader loader in loaders)
                    {
                        loader.UpdateRegionInfo(scene.RegionInfo.RegionName, scene.RegionInfo);
                    }
                }
                if (error.Contains("Can't move this region"))
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid failed - You can not move this region. Moving it back to its original position.");
                    //Opensim Grid Servers don't have this functionality.
                    try
                    {
                        string[] position = error.Split(',');

                        scene.RegionInfo.RegionLocX = int.Parse(position[1]) * Constants.RegionSize;
                        scene.RegionInfo.RegionLocY = int.Parse(position[2]) * Constants.RegionSize;

                        IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                        foreach (IRegionLoader loader in loaders)
                        {
                            loader.UpdateRegionInfo(scene.RegionInfo.RegionName, scene.RegionInfo);
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.Error("Unable to move the region back to its original position, is this an opensim server? Please manually move the region back.");
                        throw e;
                    }
                }
                if (error == "Duplicate region name")
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid failed - The region name you specified is already in use. Please change the name.");
                    string oldRegionName = scene.RegionInfo.RegionName;
                    scene.RegionInfo.RegionName = MainConsole.Instance.CmdPrompt("New Region Name", "");

                    IRegionLoader[] loaders = scene.RequestModuleInterfaces <IRegionLoader>();
                    foreach (IRegionLoader loader in loaders)
                    {
                        loader.UpdateRegionInfo(oldRegionName, scene.RegionInfo);
                    }
                }
                if (error == "Region locked out")
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid the failed - The region you are attempting to join has been blocked from connecting. Please connect another region.");
                    MainConsole.Instance.CmdPrompt("Press enter when you are ready to exit");
                    Environment.Exit(0);
                }
                if (error == "Error communicating with grid service")
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid failed - The grid service can not be found! Please make sure that you can connect to the grid server and that the grid server is on.");
                    string input = MainConsole.Instance.CmdPrompt("Press enter when you are ready to proceed, or type cancel to exit");
                    if (input == "cancel")
                    {
                        Environment.Exit(0);
                    }
                }
                if (error == "Wrong Session ID")
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid failed - Wrong Session ID for this region!");
                    string input = MainConsole.Instance.CmdPrompt("Press enter when you are ready to proceed, or type cancel to exit");
                    if (input == "cancel")
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    m_log.Error("[RegisterRegionWithGrid]: Registration of region " + scene.RegionInfo.RegionName + " with the grid failed - " + error + "!");
                    string input = MainConsole.Instance.CmdPrompt("Press enter when you are ready to proceed, or type cancel to exit");
                    if (input == "cancel")
                    {
                        Environment.Exit(0);
                    }
                }
                RegisterRegionWithGrid(scene);
            }
        }