Пример #1
0
        /// <summary>
        /// Creates or updates a sim via a REST Method Request
        /// BROKEN with SQL Update
        /// </summary>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="httpRequest">HTTP request header object</param>
        /// <param name="httpResponse">HTTP response header object</param>
        /// <returns>"OK" or an error</returns>
        public string RestSetSimMethod(string request, string path, string param,
                                       OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            m_log.Info("Processing region update via REST method");
            RegionProfileData theSim;

            theSim = m_gridDBService.GetRegion(new UUID(param));
            if (theSim == null)
            {
                theSim = new RegionProfileData();
                UUID UUID = new UUID(param);
                theSim.UUID          = UUID;
                theSim.regionRecvKey = m_config.SimRecvKey;
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(request);
            XmlNode rootnode    = doc.FirstChild;
            XmlNode authkeynode = rootnode.ChildNodes[0];

            if (authkeynode.Name != "authkey")
            {
                return("ERROR! bad XML - expected authkey tag");
            }

            XmlNode simnode = rootnode.ChildNodes[1];

            if (simnode.Name != "sim")
            {
                return("ERROR! bad XML - expected sim tag");
            }

            //theSim.regionSendKey = Cfg;
            theSim.regionRecvKey      = m_config.SimRecvKey;
            theSim.regionSendKey      = m_config.SimSendKey;
            theSim.regionSecret       = m_config.SimRecvKey;
            theSim.regionDataURI      = String.Empty;
            theSim.regionAssetURI     = m_config.DefaultAssetServer;
            theSim.regionAssetRecvKey = m_config.AssetRecvKey;
            theSim.regionAssetSendKey = m_config.AssetSendKey;
            theSim.regionUserURI      = m_config.DefaultUserServer;
            theSim.regionUserSendKey  = m_config.UserSendKey;
            theSim.regionUserRecvKey  = m_config.UserRecvKey;

            for (int i = 0; i < simnode.ChildNodes.Count; i++)
            {
                switch (simnode.ChildNodes[i].Name)
                {
                case "regionname":
                    theSim.regionName = simnode.ChildNodes[i].InnerText;
                    break;

                case "sim_ip":
                    theSim.serverIP = simnode.ChildNodes[i].InnerText;
                    break;

                case "sim_port":
                    theSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
                    break;

                case "region_locx":
                    theSim.regionLocX   = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
                    theSim.regionHandle = Utils.UIntsToLong((theSim.regionLocX * Constants.RegionSize), (theSim.regionLocY * Constants.RegionSize));
                    break;

                case "region_locy":
                    theSim.regionLocY   = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
                    theSim.regionHandle = Utils.UIntsToLong((theSim.regionLocX * Constants.RegionSize), (theSim.regionLocY * Constants.RegionSize));
                    break;
                }
            }

            theSim.serverURI = "http://" + theSim.serverIP + ":" + theSim.serverPort + "/";
            bool requirePublic = false;
            bool requireValid  = true;

            if (requirePublic &&
                (theSim.serverIP.StartsWith("172.16") || theSim.serverIP.StartsWith("192.168") ||
                 theSim.serverIP.StartsWith("10.") || theSim.serverIP.StartsWith("0.") ||
                 theSim.serverIP.StartsWith("255.")))
            {
                return("ERROR! Servers must register with public addresses.");
            }

            if (requireValid && (theSim.serverIP.StartsWith("0.") || theSim.serverIP.StartsWith("255.")))
            {
                return("ERROR! 0.*.*.* / 255.*.*.* Addresses are invalid, please check your server config and try again");
            }

            try
            {
                m_log.Info("[DATA]: " +
                           "Updating / adding via " + m_gridDBService.GetNumberOfPlugins() + " storage provider(s) registered.");

                return(m_gridDBService.CheckReservations(theSim, authkeynode));
            }
            catch (Exception e)
            {
                return("ERROR! Could not save to database! (" + e.ToString() + ")");
            }
        }