コード例 #1
0
        public CreateObject2Ret DoCreateObject2Call(RegionInfo region, UUID sogId, byte[] sogBytes, bool allowScriptCrossing,
                                                    Vector3 pos, bool isAttachment, long nonceID, List <UUID> avatars)
        {
            ulong  regionHandle = GetRegionHandle(region.RegionHandle);
            string uri          = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/object2/" + sogId + "/" + regionHandle.ToString() + "/";

            HttpWebRequest objectCreateRequest = (HttpWebRequest)WebRequest.Create(uri);

            objectCreateRequest.Method      = "POST";
            objectCreateRequest.ContentType = "application/octet-stream";
            objectCreateRequest.Timeout     = CREATE_OBJECT_TIMEOUT;

            objectCreateRequest.Headers["authorization"] = GenerateAuthorization();
            objectCreateRequest.Headers["x-nonce-id"]    = nonceID.ToString();

            Guid[] avatarsArray;
            if (avatars == null)
            {
                avatarsArray = null;
            }
            else
            {
                int count = 0;
                avatarsArray = new Guid[avatars.Count];
                foreach (UUID id in avatars)
                {
                    avatarsArray[count++] = id.Guid;
                }
            }

            ObjectPostMessage message = new ObjectPostMessage {
                NumAvatars = avatarsArray.Length, Pos = pos, Sog = sogBytes, Avatars = avatarsArray
            };

            try
            {
                // send the Post
                Stream os = objectCreateRequest.GetRequestStream();
                ProtoBuf.Serializer.Serialize(os, message);

                os.Flush();
                os.Close();

                m_log.InfoFormat("[REST COMMS]: Posted DoCreateObject2 request to remote sim {0}", uri);
            }
            catch (Exception e)
            {
                m_log.InfoFormat("[REST COMMS]: DoCreateObject2 call failed {0}", e);
                return(CreateObject2Ret.Error);
            }

            // Let's wait for the response
            //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
            try
            {
                HttpWebResponse webResponse = (HttpWebResponse)objectCreateRequest.GetResponse();
                if (webResponse == null)
                {
                    m_log.Info("[REST COMMS]: Null reply on DoCreateObject2 post");
                    return(CreateObject2Ret.Error);
                }

                StreamReader sr    = new StreamReader(webResponse.GetResponseStream());
                string       reply = sr.ReadToEnd().Trim();
                sr.Close();

                //this will happen during the initial rollout and tells us we need to fall back to the
                //old method
                if (webResponse.StatusCode == HttpStatusCode.Forbidden)
                {
                    m_log.InfoFormat("[REST COMMS]: Entry denied on reply of DoCreateObject2");
                    return(CreateObject2Ret.AccessDenied);
                }
                else if (webResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    m_log.InfoFormat("[REST COMMS]: NotFound on reply of DoCreateObject2");
                    return(CreateObject2Ret.NotFound);
                }
                else if (webResponse.StatusCode == HttpStatusCode.OK)
                {
                    return(CreateObject2Ret.Ok);
                }
                else
                {
                    m_log.WarnFormat("[REST COMMS]: Error on reply of DoCreateObject2 {0}", reply);
                    return(CreateObject2Ret.Error);
                }
            }
            catch (WebException ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObject2 {0} Sz {1}", ex, objectCreateRequest.ContentLength);
                HttpWebResponse response = (HttpWebResponse)ex.Response;
                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.Forbidden)
                    {
                        m_log.InfoFormat("[REST COMMS]: Entry denied on reply of DoCreateObject2");
                        return(CreateObject2Ret.AccessDenied);
                    }
                    else if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        m_log.InfoFormat("[REST COMMS]: NotFound on reply of DoCreateObject2");
                        return(CreateObject2Ret.NotFound);
                    }
                    else if (response.StatusCode == HttpStatusCode.OK)
                    {
                        return(CreateObject2Ret.Ok);
                    }
                    else
                    {
                        m_log.Error("[REST COMMS]: Error on reply of DoCreateObject2: " + ex.Message);
                        return(CreateObject2Ret.Error);
                    }
                }
            }

            return(CreateObject2Ret.Error);
        }
コード例 #2
0
        protected virtual string DoObject2Post(Stream request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            if (!Util.CheckHttpAuthorization(_gridSendKey, httpRequest.Headers))
            {
                m_log.WarnFormat("[REST COMMS]: /object2/ communication from untrusted peer {0}", httpRequest.RemoteIPEndPoint.Address.ToString());
                httpResponse.StatusCode = 401;
                return("Untrusted");
            }

            //m_log.Debug(" >> " + request["http-method"] + " " + request["content-type"] + " uri=" + request["uri"]);

            UUID   objectID;
            string action;
            ulong  regionHandle;

            if (!GetParams(path, out objectID, out regionHandle, out action))
            {
                m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", path);
                httpResponse.StatusCode = 400;
                return("Invalid Parameters");
            }

            ObjectPostMessage message = ProtoBuf.Serializer.Deserialize <ObjectPostMessage>(request);

            if (message == null)
            {
                httpResponse.StatusCode = 400;
                return("Invalid Request");
            }

            // System.Threading.Thread.Sleep(16000);

            //used for interpolation
            ulong            createTime = Util.GetLongTickCount();
            SceneObjectGroup sog        = null;
            long             nonceID    = GetNonceID(httpRequest.Headers);

            try
            {
                var engine = ProviderRegistry.Instance.Get <ISerializationEngine>();
                sog = engine.SceneObjectSerializer.DeserializeGroupFromBytes(message.Sog);
                sog.TimeReceived = createTime;
                sog.NonceID      = nonceID;
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex);
                httpResponse.StatusCode = 500;
                return(ex.Message);
            }

            if (CheckNonceID(nonceID))
            {
                // possibly would have succeeded but client side cancelled
                // m_log.WarnFormat("[REST COMMS]: Skipping object create for nonce ID nonce ID {0}", nonceID);
                httpResponse.StatusCode = 204;
                return("No Content");
            }
            // else m_log.WarnFormat("[REST COMMS]: Nonce ID {0} not found, allowing rez.", nonceID);

            if (message.Pos.HasValue)
            {
                sog.OriginalEnteringScenePosition = sog.AbsolutePosition;
                sog.AbsolutePosition = Util.GetValidRegionXYZ(message.Pos.Value);
            }

            List <UUID> avatarIDs = new List <UUID>();

            if (message.Avatars == null)
            {
                sog.AvatarsToExpect = message.NumAvatars;
            }
            else
            {
                sog.AvatarsToExpect = message.Avatars.Length;
                foreach (Guid id in message.Avatars)
                {
                    avatarIDs.Add(new UUID(id));
                }
            }

            // This is the meaning of POST object
            bool result = m_localBackend.SendCreateObject(regionHandle, sog, avatarIDs, false, message.Pos.HasValue ? message.Pos.Value : Vector3.Zero, message.Pos.HasValue);

            if (result)
            {
                httpResponse.StatusCode = 200;
            }
            else
            {
                httpResponse.StatusCode = 500;
            }

            return(result.ToString());
        }