public OSDMap GetUrlsForUser(GridRegion region, UUID userID)
        {
            if ((((RegionFlags)region.Flags) & RegionFlags.Foreign) != RegionFlags.Foreign)
            {
                MainConsole.Instance.Debug("[IWC]: Not a foreign region");
                return(null);
            }
            string host = userID.ToString();
            IGridRegistrationService module = Registry.RequestModuleInterface <IGridRegistrationService>();

            if (module != null)
            {
                module.RemoveUrlsForClient(host);
                module.RemoveUrlsForClient(host + "|" + region.RegionHandle);
                IsGettingUrlsForIWCConnection = true;
                OSDMap map = module.GetUrlForRegisteringClient(host + "|" + region.RegionHandle);
                IsGettingUrlsForIWCConnection = false;

                string url = region.GenericMap["URL"];
                if (url == "")
                {
                    MainConsole.Instance.Warn("[IWC]: Foreign region with no URL");
                    return(null); //What the hell? Its a foreign region, it better have a URL!
                }
                //Remove the /Grid.... stuff
                url = url.Remove(url.Length - 5 - 36);
                OutgoingPublicComms.InformOfURLs(url + "/iwcconnection", map, userID, region.RegionHandle);

                return(map);
            }

            return(null);
        }
        private byte[] ConnectionRequest(OSDMap args)
        {
            IGridRegistrationService module = IWC.Registry.RequestModuleInterface <IGridRegistrationService>();
            OSDMap result = new OSDMap();

            if (module != null)
            {
                //Add our URLs for them so that they can connect too
                string theirIdent = args["OurIdentifier"];
                ulong  handle;
                if (ulong.TryParse(theirIdent, out handle))
                {
                    //Fu**in hackers
                    //No making region handle sessionIDs!
                    result["Success"] = false;
                }
                else
                {
                    module.RemoveUrlsForClient(theirIdent);
                    IWC.IsGettingUrlsForIWCConnection = true;
                    result = module.GetUrlForRegisteringClient(theirIdent);
                    IWC.IsGettingUrlsForIWCConnection = false;
                    result["OurIdentifier"]           = Utilities.GetAddress();
                    MainConsole.Instance.Warn(theirIdent + " successfully connected to us");
                    IWC.AddNewConnectionFromRequest(theirIdent, args);
                    result["Success"] = true;
                }
            }

            string       json = OSDParser.SerializeJsonString(result);
            UTF8Encoding enc  = new UTF8Encoding();

            return(enc.GetBytes(json));
        }
        /// <summary>
        ///   Query the given host (by connection) and verify that we can connect to it.
        /// </summary>
        /// <param name = "connector">The host to connect to</param>
        /// <returns>The connection that has been recieved from the host</returns>
        public bool AttemptConnection(string host)
        {
            IGridRegistrationService module = IWC.Registry.RequestModuleInterface <IGridRegistrationService>();

            if (module != null)
            {
                module.RemoveUrlsForClient(host);
                IWC.IsGettingUrlsForIWCConnection = true;
                OSDMap callThem = module.GetUrlForRegisteringClient(host);
                IWC.IsGettingUrlsForIWCConnection = false;
                callThem["OurIdentifier"]         = Utilities.GetAddress();

                callThem["Method"] = "ConnectionRequest";
                OSDMap result = WebUtils.PostToService(host, callThem, true, false, true);
                if (result["Success"])
                {
                    //Add their URLs back again
                    MainConsole.Instance.Warn("Successfully Connected to " + host);
                    IWC.AddNewConnectionFromRequest(result["OurIdentifier"], result);
                    return(true);
                }
            }
            return(false);
        }