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(); }
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(); }
/// <summary> /// Deserialization of agent data. /// Avoiding reflection makes it painful to write, but that's the price! /// </summary> /// <param name="hash"></param> public virtual void Unpack(OSDMap args, IScene scene, EntityTransferContext ctx) { //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data"); if (args.ContainsKey("region_id")) { UUID.TryParse(args["region_id"].AsString(), out RegionID); } if (args["circuit_code"] != null) { UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode); } if (args["agent_uuid"] != null) { AgentID = args["agent_uuid"].AsUUID(); } if (args["session_uuid"] != null) { SessionID = args["session_uuid"].AsUUID(); } if (args["position"] != null) { Vector3.TryParse(args["position"].AsString(), out Position); } if (args["velocity"] != null) { Vector3.TryParse(args["velocity"].AsString(), out Velocity); } if (args["center"] != null) { Vector3.TryParse(args["center"].AsString(), out Center); } if (args["size"] != null) { Vector3.TryParse(args["size"].AsString(), out Size); } if (args["at_axis"] != null) { Vector3.TryParse(args["at_axis"].AsString(), out AtAxis); } if (args["left_axis"] != null) { Vector3.TryParse(args["left_axis"].AsString(), out AtAxis); } if (args["up_axis"] != null) { Vector3.TryParse(args["up_axis"].AsString(), out AtAxis); } if (args.ContainsKey("wait_for_root") && args["wait_for_root"] != null) { SenderWantsToWaitForRoot = args["wait_for_root"].AsBoolean(); } if (args["far"] != null) { Far = (float)(args["far"].AsReal()); } if (args["aspect"] != null) { Aspect = (float)args["aspect"].AsReal(); } if (args["throttles"] != null) { Throttles = args["throttles"].AsBinary(); } if (args["locomotion_state"] != null) { UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState); } if (args["head_rotation"] != null) { Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation); } if (args["body_rotation"] != null) { Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation); } if (args["control_flags"] != null) { UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags); } if (args["energy_level"] != null) { EnergyLevel = (float)(args["energy_level"].AsReal()); } if (args["god_level"] != null) { Byte.TryParse(args["god_level"].AsString(), out GodLevel); } if (args["always_run"] != null) { AlwaysRun = args["always_run"].AsBoolean(); } if (args["prey_agent"] != null) { PreyAgent = args["prey_agent"].AsUUID(); } if (args["agent_access"] != null) { Byte.TryParse(args["agent_access"].AsString(), out AgentAccess); } if (args["active_group_id"] != null) { ActiveGroupID = args["active_group_id"].AsUUID(); } if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array) { OSDArray groups = (OSDArray)(args["groups"]); Groups = new AgentGroupData[groups.Count]; int i = 0; foreach (OSD o in groups) { if (o.Type == OSDType.Map) { Groups[i++] = new AgentGroupData((OSDMap)o); } } } if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array)) { OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]); ChildrenCapSeeds = new Dictionary <ulong, string>(); foreach (OSD o in childrenSeeds) { if (o.Type == OSDType.Map) { ulong handle = 0; string seed = ""; OSDMap pair = (OSDMap)o; if (pair["handle"] != null) { if (!UInt64.TryParse(pair["handle"].AsString(), out handle)) { continue; } } if (pair["seed"] != null) { seed = pair["seed"].AsString(); } if (!ChildrenCapSeeds.ContainsKey(handle)) { ChildrenCapSeeds.Add(handle, seed); } } } } if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array) { OSDArray anims = (OSDArray)(args["animations"]); Anims = new Animation[anims.Count]; int i = 0; foreach (OSD o in anims) { if (o.Type == OSDType.Map) { Anims[i++] = new Animation((OSDMap)o); } } } if (args["default_animation"] != null) { try { DefaultAnim = new Animation((OSDMap)args["default_animation"]); } catch { DefaultAnim = null; } } if (args["animation_state"] != null) { try { AnimState = new Animation((OSDMap)args["animation_state"]); } catch { AnimState = null; } } MovementAnimationOverRides.Clear(); if (args["movementAO"] != null && args["movementAO"].Type == OSDType.Array) { OSDArray AOs = (OSDArray)(args["movementAO"]); int count = AOs.Count; for (int i = 0; i < count; i++) { OSDMap ao = (OSDMap)AOs[i]; if (ao["state"] != null && ao["uuid"] != null) { string state = ao["state"].AsString(); UUID id = ao["uuid"].AsUUID(); MovementAnimationOverRides[state] = id; } } } if (args.ContainsKey("motion_state")) { MotionState = (byte)args["motion_state"].AsInteger(); } //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array) //{ // OSDArray textures = (OSDArray)(args["agent_textures"]); // AgentTextures = new UUID[textures.Count]; // int i = 0; // foreach (OSD o in textures) // AgentTextures[i++] = o.AsUUID(); //} // packed_appearence should contain all appearance information if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map) { m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance"); Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]); } else { // if missing try the old pack method m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method"); Appearance = new AvatarAppearance(); // The code to unpack textures, visuals, wearables and attachments // should be removed; packed appearance contains the full appearance // This is retained for backward compatibility only if (args["texture_entry"] != null) { byte[] rawtextures = args["texture_entry"].AsBinary(); Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length); Appearance.SetTextureEntries(textures); } if (args["visual_params"] != null) { Appearance.SetVisualParams(args["visual_params"].AsBinary()); } if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array) { OSDArray wears = (OSDArray)(args["wearables"]); for (int i = 0; i < wears.Count / 2; i++) { AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]); Appearance.SetWearable(i, awear); } } if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(args["attachments"]); foreach (OSD o in attachs) { if (o.Type == OSDType.Map) { // We know all of these must end up as attachments so we // append rather than replace to ensure multiple attachments // per point continues to work // m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID); Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o)); } } } // end of code to remove } /* moved above * if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map) * Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]); * else * m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance"); */ if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) { OSDArray controls = (OSDArray)(args["controllers"]); Controllers = new ControllerData[controls.Count]; int i = 0; foreach (OSD o in controls) { if (o.Type == OSDType.Map) { Controllers[i++] = new ControllerData((OSDMap)o); } } } if (args["callback_uri"] != null) { CallbackURI = args["callback_uri"].AsString(); } // Attachment objects if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array) { OSDArray attObjs = (OSDArray)(args["attach_objects"]); AttachmentObjects = new List <ISceneObject>(); AttachmentObjectStates = new List <string>(); foreach (OSD o in attObjs) { if (o.Type == OSDType.Map) { OSDMap info = (OSDMap)o; ISceneObject so = scene.DeserializeObject(info["sog"].AsString()); so.ExtraFromXmlString(info["extra"].AsString()); so.HasGroupChanged = info["modified"].AsBoolean(); AttachmentObjects.Add(so); AttachmentObjectStates.Add(info["state"].AsString()); } } } if (args["parent_part"] != null) { ParentPart = args["parent_part"].AsUUID(); } if (args["sit_offset"] != null) { Vector3.TryParse(args["sit_offset"].AsString(), out SitOffset); } }
/// <summary> /// Deserialization of agent data. /// Avoiding reflection makes it painful to write, but that's the price! /// </summary> /// <param name="hash"></param> public virtual void Unpack(OSDMap args, IScene scene) { if (m_log.IsDebugEnabled) { m_log.DebugFormat("{0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); } if (args.ContainsKey("region_id")) { UUID.TryParse(args ["region_id"].AsString(), out RegionID); } if (args ["circuit_code"] != null) { UInt32.TryParse((string)args ["circuit_code"].AsString(), out CircuitCode); } if (args ["agent_uuid"] != null) { AgentID = args ["agent_uuid"].AsUUID(); } if (args ["session_uuid"] != null) { SessionID = args ["session_uuid"].AsUUID(); } if (args ["position"] != null) { Vector3.TryParse(args ["position"].AsString(), out Position); } if (args ["velocity"] != null) { Vector3.TryParse(args ["velocity"].AsString(), out Velocity); } if (args ["center"] != null) { Vector3.TryParse(args ["center"].AsString(), out Center); } if (args ["size"] != null) { Vector3.TryParse(args ["size"].AsString(), out Size); } if (args ["at_axis"] != null) { Vector3.TryParse(args ["at_axis"].AsString(), out AtAxis); } if (args ["left_axis"] != null) { Vector3.TryParse(args ["left_axis"].AsString(), out AtAxis); } if (args ["up_axis"] != null) { Vector3.TryParse(args ["up_axis"].AsString(), out AtAxis); } if (args.ContainsKey("wait_for_root") && args ["wait_for_root"] != null) { SenderWantsToWaitForRoot = args ["wait_for_root"].AsBoolean(); } if (args ["far"] != null) { Far = (float)(args ["far"].AsReal()); } if (args ["aspect"] != null) { Aspect = (float)args ["aspect"].AsReal(); } if (args ["throttles"] != null) { Throttles = args ["throttles"].AsBinary(); } if (args ["locomotion_state"] != null) { UInt32.TryParse(args ["locomotion_state"].AsString(), out LocomotionState); } if (args ["head_rotation"] != null) { Quaternion.TryParse(args ["head_rotation"].AsString(), out HeadRotation); } if (args ["body_rotation"] != null) { Quaternion.TryParse(args ["body_rotation"].AsString(), out BodyRotation); } if (args ["control_flags"] != null) { UInt32.TryParse(args ["control_flags"].AsString(), out ControlFlags); } if (args ["energy_level"] != null) { EnergyLevel = (float)(args ["energy_level"].AsReal()); } if (args ["god_level"] != null) { Byte.TryParse(args ["god_level"].AsString(), out GodLevel); } if (args ["always_run"] != null) { AlwaysRun = args ["always_run"].AsBoolean(); } if (args ["prey_agent"] != null) { PreyAgent = args ["prey_agent"].AsUUID(); } if (args ["agent_access"] != null) { Byte.TryParse(args ["agent_access"].AsString(), out AgentAccess); } if (args ["active_group_id"] != null) { ActiveGroupID = args ["active_group_id"].AsUUID(); } if ((args ["groups"] != null) && (args ["groups"]).Type == OSDType.Array) { OSDArray groups = (OSDArray)(args ["groups"]); Groups = new AgentGroupData[groups.Count]; int i = 0; foreach (OSD o in groups) { if (o.Type == OSDType.Map) { Groups [i++] = new AgentGroupData((OSDMap)o); } } } if ((args ["animations"] != null) && (args ["animations"]).Type == OSDType.Array) { OSDArray anims = (OSDArray)(args ["animations"]); Anims = new Animation[anims.Count]; int i = 0; foreach (OSD o in anims) { if (o.Type == OSDType.Map) { Anims [i++] = new Animation((OSDMap)o); } } } if (args ["default_animation"] != null) { try { DefaultAnim = new Animation((OSDMap)args ["default_animation"]); } catch { DefaultAnim = null; } } if (args ["animation_state"] != null) { try { AnimState = new Animation((OSDMap)args ["animation_state"]); } catch { AnimState = null; } } //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array) //{ // OSDArray textures = (OSDArray)(args["agent_textures"]); // AgentTextures = new UUID[textures.Count]; // int i = 0; // foreach (OSD o in textures) // AgentTextures[i++] = o.AsUUID(); //} Appearance = new AvatarAppearance(); // The code to unpack textures, visuals, wearables and attachments // should be removed; packed appearance contains the full appearance // This is retained for backward compatibility only if (args ["texture_entry"] != null) { byte[] rawtextures = args ["texture_entry"].AsBinary(); Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length); Appearance.SetTextureEntries(textures); } if (args ["visual_params"] != null) { Appearance.SetVisualParams(args ["visual_params"].AsBinary()); } if ((args ["wearables"] != null) && (args ["wearables"]).Type == OSDType.Array) { OSDArray wears = (OSDArray)(args ["wearables"]); for (int i = 0; i < wears.Count / 2; i++) { AvatarWearable awear = new AvatarWearable((OSDArray)wears [i]); Appearance.SetWearable(i, awear); } } if ((args ["attachments"] != null) && (args ["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(args ["attachments"]); foreach (OSD o in attachs) { if (o.Type == OSDType.Map) { // We know all of these must end up as attachments so we // append rather than replace to ensure multiple attachments // per point continues to work // m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID); Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o)); } } } // end of code to remove if (args.ContainsKey("packed_appearance") && (args ["packed_appearance"]).Type == OSDType.Map) { Appearance = new AvatarAppearance((OSDMap)args ["packed_appearance"]); } else { m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance"); } if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) { OSDArray controls = (OSDArray)(args["controllers"]); Controllers = new ControllerData[controls.Count]; int i = 0; foreach (OSD o in controls) { if (o.Type == OSDType.Map) { Controllers[i++] = new ControllerData((OSDMap)o); } } } if (args["callback_uri"] != null) { CallbackURI = args["callback_uri"].AsString(); } // Attachment objects if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array) { OSDArray attObjs = (OSDArray)(args["attach_objects"]); AttachmentObjects = new List <ISceneObject>(); AttachmentObjectStates = new List <string>(); foreach (OSD o in attObjs) { if (o.Type == OSDType.Map) { OSDMap info = (OSDMap)o; ISceneObject so = scene.DeserializeObject(info["sog"].AsString()); so.ExtraFromXmlString(info["extra"].AsString()); so.HasGroupChanged = info["modified"].AsBoolean(); AttachmentObjects.Add(so); AttachmentObjectStates.Add(info["state"].AsString()); } } } }