29 using System.Collections;
30 using System.Reflection;
34 using OpenMetaverse.StructuredData;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Servers;
38 using OpenSim.Framework.Servers.HttpServer;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
43 namespace OpenSim.
Region.ClientStack.Linden
45 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"ObjectAdd")]
51 private Scene m_scene;
53 #region INonSharedRegionModule Members
62 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
69 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
84 get {
return "ObjectAddModule"; }
87 public Type ReplaceableInterface
96 UUID capuuid = UUID.Random();
100 caps.RegisterHandler(
104 "/CAPS/OA/" + capuuid +
"/",
105 httpMethod => ProcessAdd(httpMethod, agentID, caps),
107 agentID.ToString())); ;
112 Hashtable responsedata =
new Hashtable();
113 responsedata[
"int_response_code"] = 400;
114 responsedata[
"content_type"] =
"text/plain";
115 responsedata[
"keepalive"] =
false;
116 responsedata[
"str_response_string"] =
"Request wasn't what was expected";
119 if (!m_scene.TryGetScenePresence(AgentId, out avatar))
123 OSD r = OSDParser.DeserializeLLSDXml((string)request[
"requestbody"]);
125 bool bypass_raycast =
false;
126 uint everyone_mask = 0;
128 uint next_owner_mask = 0;
130 UUID group_id = UUID.Zero;
137 int path_radius_offset = 0;
138 int path_revolutions = 0;
139 int path_scale_x = 0;
140 int path_scale_y = 0;
141 int path_shear_x = 0;
142 int path_shear_y = 0;
144 int path_taper_x = 0;
145 int path_taper_y = 0;
147 int path_twist_begin = 0;
148 int profile_begin = 0;
149 int profile_curve = 0;
151 Vector3 ray_end = Vector3.Zero;
152 bool ray_end_is_intersection =
false;
153 Vector3 ray_start = Vector3.Zero;
154 UUID ray_target_id = UUID.Zero;
155 Quaternion
rotation = Quaternion.Identity;
156 Vector3 scale = Vector3.Zero;
160 if (r.Type != OSDType.Map)
165 if (rm.ContainsKey(
"ObjectData"))
167 if (rm[
"ObjectData"].
Type != OSDType.Map)
169 responsedata[
"str_response_string"] =
"Has ObjectData key, but data not in expected format";
175 bypass_raycast = ObjMap[
"BypassRaycast"].AsBoolean();
176 everyone_mask = readuintval(ObjMap[
"EveryoneMask"]);
177 flags = readuintval(ObjMap[
"Flags"]);
178 group_mask = readuintval(ObjMap[
"GroupMask"]);
179 material = ObjMap[
"Material"].AsInteger();
180 next_owner_mask = readuintval(ObjMap[
"NextOwnerMask"]);
181 p_code = ObjMap[
"PCode"].AsInteger();
183 if (ObjMap.ContainsKey(
"Path"))
185 if (ObjMap[
"Path"].
Type != OSDType.Map)
187 responsedata[
"str_response_string"] =
"Has Path key, but data not in expected format";
192 path_begin = PathMap[
"Begin"].AsInteger();
193 path_curve = PathMap[
"Curve"].AsInteger();
194 path_end = PathMap[
"End"].AsInteger();
195 path_radius_offset = PathMap[
"RadiusOffset"].AsInteger();
196 path_revolutions = PathMap[
"Revolutions"].AsInteger();
197 path_scale_x = PathMap[
"ScaleX"].AsInteger();
198 path_scale_y = PathMap[
"ScaleY"].AsInteger();
199 path_shear_x = PathMap[
"ShearX"].AsInteger();
200 path_shear_y = PathMap[
"ShearY"].AsInteger();
201 path_skew = PathMap[
"Skew"].AsInteger();
202 path_taper_x = PathMap[
"TaperX"].AsInteger();
203 path_taper_y = PathMap[
"TaperY"].AsInteger();
204 path_twist = PathMap[
"Twist"].AsInteger();
205 path_twist_begin = PathMap[
"TwistBegin"].AsInteger();
209 if (ObjMap.ContainsKey(
"Profile"))
211 if (ObjMap[
"Profile"].
Type != OSDType.Map)
213 responsedata[
"str_response_string"] =
"Has Profile key, but data not in expected format";
219 profile_begin = ProfileMap[
"Begin"].AsInteger();
220 profile_curve = ProfileMap[
"Curve"].AsInteger();
221 profile_end = ProfileMap[
"End"].AsInteger();
222 hollow = ProfileMap[
"Hollow"].AsInteger();
224 ray_end_is_intersection = ObjMap[
"RayEndIsIntersection"].AsBoolean();
226 ray_target_id = ObjMap[
"RayTargetId"].AsUUID();
227 state = ObjMap[
"State"].AsInteger();
228 lastattach = ObjMap[
"LastAttachPoint"].AsInteger();
231 ray_end = ((
OSDArray)ObjMap[
"RayEnd"]).AsVector3();
232 ray_start = ((
OSDArray)ObjMap[
"RayStart"]).AsVector3();
233 scale = ((
OSDArray)ObjMap[
"Scale"]).AsVector3();
234 rotation = ((
OSDArray)ObjMap[
"Rotation"]).AsQuaternion();
238 responsedata[
"str_response_string"] =
"RayEnd, RayStart, Scale or Rotation wasn't in the expected format";
242 if (rm.ContainsKey(
"AgentData"))
244 if (rm[
"AgentData"].
Type != OSDType.Map)
246 responsedata[
"str_response_string"] =
"Has AgentData key, but data not in expected format";
253 group_id = AgentDataMap[
"GroupId"].AsUUID();
259 bypass_raycast = rm[
"bypass_raycast"].AsBoolean();
261 everyone_mask = readuintval(rm[
"everyone_mask"]);
262 flags = readuintval(rm[
"flags"]);
263 group_id = rm[
"group_id"].AsUUID();
264 group_mask = readuintval(rm[
"group_mask"]);
265 hollow = rm[
"hollow"].AsInteger();
266 material = rm[
"material"].AsInteger();
267 next_owner_mask = readuintval(rm[
"next_owner_mask"]);
268 hollow = rm[
"hollow"].AsInteger();
269 p_code = rm[
"p_code"].AsInteger();
270 path_begin = rm[
"path_begin"].AsInteger();
271 path_curve = rm[
"path_curve"].AsInteger();
272 path_end = rm[
"path_end"].AsInteger();
273 path_radius_offset = rm[
"path_radius_offset"].AsInteger();
274 path_revolutions = rm[
"path_revolutions"].AsInteger();
275 path_scale_x = rm[
"path_scale_x"].AsInteger();
276 path_scale_y = rm[
"path_scale_y"].AsInteger();
277 path_shear_x = rm[
"path_shear_x"].AsInteger();
278 path_shear_y = rm[
"path_shear_y"].AsInteger();
279 path_skew = rm[
"path_skew"].AsInteger();
280 path_taper_x = rm[
"path_taper_x"].AsInteger();
281 path_taper_y = rm[
"path_taper_y"].AsInteger();
282 path_twist = rm[
"path_twist"].AsInteger();
283 path_twist_begin = rm[
"path_twist_begin"].AsInteger();
284 profile_begin = rm[
"profile_begin"].AsInteger();
285 profile_curve = rm[
"profile_curve"].AsInteger();
286 profile_end = rm[
"profile_end"].AsInteger();
288 ray_end_is_intersection = rm[
"ray_end_is_intersection"].AsBoolean();
290 ray_target_id = rm[
"ray_target_id"].AsUUID();
294 state = rm[
"state"].AsInteger();
295 lastattach = rm[
"last_attach_point"].AsInteger();
298 ray_end = ((
OSDArray)rm[
"ray_end"]).AsVector3();
299 ray_start = ((
OSDArray)rm[
"ray_start"]).AsVector3();
300 rotation = ((
OSDArray)rm[
"rotation"]).AsQuaternion();
301 scale = ((
OSDArray)rm[
"scale"]).AsVector3();
305 responsedata[
"str_response_string"] =
"RayEnd, RayStart, Scale or Rotation wasn't in the expected format";
312 Vector3 pos = m_scene.GetNewRezLocation(ray_start, ray_end, ray_target_id,
rotation, (bypass_raycast) ? (byte)1 : (byte)0, (ray_end_is_intersection) ? (byte)1 : (byte)0,
true, scale,
false);
316 pbs.PathBegin = (ushort)path_begin;
317 pbs.PathCurve = (byte)path_curve;
318 pbs.PathEnd = (ushort)path_end;
319 pbs.PathRadiusOffset = (sbyte)path_radius_offset;
320 pbs.PathRevolutions = (byte)path_revolutions;
321 pbs.PathScaleX = (byte)path_scale_x;
322 pbs.PathScaleY = (byte)path_scale_y;
323 pbs.PathShearX = (byte)path_shear_x;
324 pbs.PathShearY = (byte)path_shear_y;
325 pbs.PathSkew = (sbyte)path_skew;
326 pbs.PathTaperX = (sbyte)path_taper_x;
327 pbs.PathTaperY = (sbyte)path_taper_y;
328 pbs.PathTwist = (sbyte)path_twist;
329 pbs.PathTwistBegin = (sbyte)path_twist_begin;
331 pbs.PCode = (byte)p_code;
332 pbs.ProfileBegin = (ushort)profile_begin;
333 pbs.ProfileCurve = (byte)profile_curve;
334 pbs.ProfileEnd = (ushort)profile_end;
336 pbs.State = (byte)state;
337 pbs.LastAttachPoint = (byte)lastattach;
341 if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos))
346 obj = m_scene.AddNewPrim(avatar.UUID, group_id, pos,
rotation, pbs);
354 rootpart.Shape = pbs;
356 rootpart.EveryoneMask = everyone_mask;
357 rootpart.GroupID = group_id;
358 rootpart.GroupMask = group_mask;
359 rootpart.NextOwnerMask = next_owner_mask;
360 rootpart.Material = (byte)material;
362 m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
364 responsedata[
"int_response_code"] = 200;
365 responsedata[
"content_type"] =
"text/plain";
366 responsedata[
"keepalive"] =
false;
367 responsedata[
"str_response_string"] = String.Format(
"<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(obj.
LocalId));
372 private uint readuintval(
OSD obj)
374 byte[] tmp = obj.AsBinary();
375 if (BitConverter.IsLittleEndian)
377 return Utils.BytesToUInt(tmp);
380 private string ConvertUintToBytes(uint val)
382 byte[] resultbytes = Utils.UIntToBytes(val);
383 if (BitConverter.IsLittleEndian)
384 Array.Reverse(resultbytes);
385 return String.Format(
"<binary encoding=\"base64\">{0}</binary>", Convert.ToBase64String(resultbytes));
OpenMetaverse.StructuredData.OSDArray OSDArray
void RegisterCaps(UUID agentID, Caps caps)
OpenMetaverse.StructuredData.OSDMap OSDMap
Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
OpenSim.Framework.Capabilities.Caps Caps
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion rotation
OpenSim.Framework.Capabilities.Caps Caps
OpenMetaverse.StructuredData.OSD OSD
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void Initialise(IConfigSource pSource)
This is called to initialize the region module. For shared modules, this is called exactly once...