protected void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID)
        {
            OSDMap args = Utils.GetOSDMap((string)request["body"]);

            if (args == null)
            {
                responsedata["int_response_code"]   = 400;
                responsedata["str_response_string"] = "false";
                return;
            }
            // retrieve the input arguments
            int     x = 0, y = 0;
            UUID    uuid        = UUID.Zero;
            string  regionname  = string.Empty;
            Vector3 newPosition = Vector3.Zero;

            if (args.ContainsKey("destination_x") && args["destination_x"] != null)
            {
                Int32.TryParse(args["destination_x"].AsString(), out x);
            }
            if (args.ContainsKey("destination_y") && args["destination_y"] != null)
            {
                Int32.TryParse(args["destination_y"].AsString(), out y);
            }
            if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
            {
                UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
            }
            if (args.ContainsKey("destination_name") && args["destination_name"] != null)
            {
                regionname = args["destination_name"].ToString();
            }
            if (args.ContainsKey("new_position") && args["new_position"] != null)
            {
                Vector3.TryParse(args["new_position"], out newPosition);
            }

            GridRegion destination = new GridRegion();

            destination.RegionID   = uuid;
            destination.RegionLocX = x;
            destination.RegionLocY = y;
            destination.RegionName = regionname;

            string sogXmlStr = "", extraStr = "", stateXmlStr = "";

            if (args.ContainsKey("sog") && args["sog"] != null)
            {
                sogXmlStr = args["sog"].AsString();
            }
            if (args.ContainsKey("extra") && args["extra"] != null)
            {
                extraStr = args["extra"].AsString();
            }

            IScene       s   = m_SimulationService.GetScene(destination.RegionID);
            ISceneObject sog = null;

            try
            {
                //m_log.DebugFormat("[OBJECT HANDLER]: received {0}", sogXmlStr);
                sog = s.DeserializeObject(sogXmlStr);
                sog.ExtraFromXmlString(extraStr);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[OBJECT HANDLER]: exception on deserializing scene object {0}", ex.Message);
                responsedata["int_response_code"]   = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            if (args.ContainsKey("modified"))
            {
                sog.HasGroupChanged = args["modified"].AsBoolean();
            }
            else
            {
                sog.HasGroupChanged = false;
            }

            if ((args["state"] != null) && s.AllowScriptCrossings)
            {
                stateXmlStr = args["state"].AsString();
                if (stateXmlStr != "")
                {
                    try
                    {
                        sog.SetState(stateXmlStr, s);
                    }
                    catch (Exception ex)
                    {
                        m_log.InfoFormat("[OBJECT HANDLER]: exception on setting state for scene object {0}", ex.Message);
                        // ignore and continue
                    }
                }
            }

            bool result = false;

            try
            {
                // This is the meaning of POST object
                result = CreateObject(destination, newPosition, sog);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[OBJECT HANDLER]: Exception in CreateObject: {0}", e.StackTrace);
            }

            responsedata["int_response_code"]   = HttpStatusCode.OK;
            responsedata["str_response_string"] = result.ToString();
        }
Beispiel #2
0
        protected void DoAgentPut(OSDMap args, IOSHttpResponse httpResponse)
        {
            // retrieve the input arguments
            OSD tmpOSD;
            EntityTransferContext ctx = new EntityTransferContext();
            int    x = 0, y = 0;
            UUID   uuid = UUID.Zero;
            string regionname = string.Empty;

            if (args.TryGetValue("destination_x", out tmpOSD) && tmpOSD != null)
            {
                Int32.TryParse(tmpOSD.AsString(), out x);
            }
            if (args.TryGetValue("destination_y", out tmpOSD) && tmpOSD != null)
            {
                Int32.TryParse(tmpOSD.AsString(), out y);
            }
            if (args.TryGetValue("destination_uuid", out tmpOSD) && tmpOSD != null)
            {
                UUID.TryParse(tmpOSD.AsString(), out uuid);
            }
            if (args.TryGetValue("destination_name", out tmpOSD) && tmpOSD != null)
            {
                regionname = tmpOSD.ToString();
            }
            if (args.TryGetValue("context", out tmpOSD) && tmpOSD is OSDMap)
            {
                ctx.Unpack((OSDMap)tmpOSD);
            }

            GridRegion destination = new GridRegion();

            destination.RegionID   = uuid;
            destination.RegionLocX = x;
            destination.RegionLocY = y;
            destination.RegionName = regionname;

            string messageType;

            if (args["message_type"] != null)
            {
                messageType = args["message_type"].AsString();
            }
            else
            {
                m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
                messageType = "AgentData";
            }

            bool result = true;

            if ("AgentData".Equals(messageType))
            {
                AgentData agent = new AgentData();
                try
                {
                    agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID), ctx);
                }
                catch (Exception ex)
                {
                    m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
                    httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                    httpResponse.RawBuffer  = Util.UTF8.GetBytes("false");
                    return;
                }

                //agent.Dump();
                // This is one of the meanings of PUT agent
                result = UpdateAgent(destination, agent);
            }
            else if ("AgentPosition".Equals(messageType))
            {
                AgentPosition agent = new AgentPosition();
                try
                {
                    agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID), ctx);
                }
                catch (Exception ex)
                {
                    m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
                    httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                    httpResponse.RawBuffer  = Util.UTF8.GetBytes("false");
                    return;
                }
                //agent.Dump();
                // This is one of the meanings of PUT agent
                result = m_SimulationService.UpdateAgent(destination, agent);
            }

            httpResponse.StatusCode = (int)HttpStatusCode.OK;
            httpResponse.RawBuffer  = Util.UTF8.GetBytes(result.ToString());
            //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
        }
        protected void DoAgentPut(Hashtable request, Hashtable responsedata)
        {
            OSDMap args = Utils.GetOSDMap((string)request["body"]);

            if (args == null)
            {
                responsedata["int_response_code"]   = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            // retrieve the input arguments
            int    x = 0, y = 0;
            UUID   uuid       = UUID.Zero;
            string regionname = string.Empty;

            if (args.ContainsKey("destination_x") && args["destination_x"] != null)
            {
                Int32.TryParse(args["destination_x"].AsString(), out x);
            }
            if (args.ContainsKey("destination_y") && args["destination_y"] != null)
            {
                Int32.TryParse(args["destination_y"].AsString(), out y);
            }
            if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
            {
                UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
            }
            if (args.ContainsKey("destination_name") && args["destination_name"] != null)
            {
                regionname = args["destination_name"].ToString();
            }

            GridRegion destination = new GridRegion();

            destination.RegionID   = uuid;
            destination.RegionLocX = x;
            destination.RegionLocY = y;
            destination.RegionName = regionname;

            string messageType;

            if (args["message_type"] != null)
            {
                messageType = args["message_type"].AsString();
            }
            else
            {
                m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
                messageType = "AgentData";
            }

            bool result = true;

            if ("AgentData".Equals(messageType))
            {
                AgentData agent = new AgentData();
                try
                {
                    agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID));
                }
                catch (Exception ex)
                {
                    m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
                    responsedata["int_response_code"]   = HttpStatusCode.BadRequest;
                    responsedata["str_response_string"] = "Bad request";
                    return;
                }

                //agent.Dump();
                // This is one of the meanings of PUT agent
                result = UpdateAgent(destination, agent);
            }
            else if ("AgentPosition".Equals(messageType))
            {
                AgentPosition agent = new AgentPosition();
                try
                {
                    agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID));
                }
                catch (Exception ex)
                {
                    m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
                    return;
                }
                //agent.Dump();
                // This is one of the meanings of PUT agent
                result = m_SimulationService.UpdateAgent(destination, agent);
            }

            responsedata["int_response_code"]   = HttpStatusCode.OK;
            responsedata["str_response_string"] = result.ToString();
            //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
        }
Beispiel #4
0
        protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID)
        {
            OSDMap args = WebUtils.GetOSDMap((string)request["body"]);

            if (args == null)
            {
                responsedata["int_response_code"]   = 400;
                responsedata["str_response_string"] = "false";
                return;
            }
            // retrieve the input arguments
            int    x = 0, y = 0;
            UUID   uuid       = UUID.Zero;
            string regionname = string.Empty;

            if (args.ContainsKey("destination_x") && args["destination_x"] != null)
            {
                Int32.TryParse(args["destination_x"].AsString(), out x);
            }
            if (args.ContainsKey("destination_y") && args["destination_y"] != null)
            {
                Int32.TryParse(args["destination_y"].AsString(), out y);
            }
            if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
            {
                UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
            }
            if (args.ContainsKey("destination_name") && args["destination_name"] != null)
            {
                regionname = args["destination_name"].ToString();
            }

            GridRegion destination = new GridRegion();

            destination.RegionID   = uuid;
            destination.RegionLocX = x;
            destination.RegionLocY = y;
            destination.RegionName = regionname;

            string sogXmlStr = "", extraStr = "";

            if (args.ContainsKey("sog") && args["sog"] != null)
            {
                sogXmlStr = args["sog"].AsString();
            }

            IScene       s   = m_SimulationService.GetScene(destination.RegionHandle);
            ISceneObject sog = null;

            try
            {
                //m_log.DebugFormat("[OBJECT HANDLER]: received {0}", sogXmlStr);
                IRegionSerialiserModule mod = s.RequestModuleInterface <IRegionSerialiserModule>();
                if (mod != null)
                {
                    sog = mod.DeserializeGroupFromXml2(sogXmlStr, s);
                    if (sog != null)
                    {
                        sog.ExtraFromXmlString(extraStr);
                    }
                }
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[OBJECT HANDLER]: exception on deserializing scene object {0}", ex.ToString());
                responsedata["int_response_code"]   = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            bool result = false;

            if (sog == null)
            {
                m_log.ErrorFormat("[OBJECT HANDLER]: error on deserializing scene object as the object was null!");

                responsedata["int_response_code"]   = HttpStatusCode.OK;
                responsedata["str_response_string"] = result.ToString();
            }

            try
            {
                // This is the meaning of POST object
                result = m_SimulationService.CreateObject(destination, sog);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[OBJECT HANDLER]: Exception in CreateObject: {0}", e.StackTrace);
            }

            responsedata["int_response_code"]   = HttpStatusCode.OK;
            responsedata["str_response_string"] = result.ToString();
        }