aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/ObjectCaps/ObjectAdd.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/ObjectCaps/ObjectAdd.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/ObjectCaps/ObjectAdd.cs368
1 files changed, 368 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/ObjectCaps/ObjectAdd.cs b/OpenSim/Region/CoreModules/Avatar/ObjectCaps/ObjectAdd.cs
new file mode 100644
index 0000000..193307d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/ObjectCaps/ObjectAdd.cs
@@ -0,0 +1,368 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenMetaverse;
34using OpenMetaverse.StructuredData;
35using OpenSim.Framework;
36using OpenSim.Framework.Servers;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
40
41namespace OpenSim.Region.CoreModules.Avatar.ObjectCaps
42{
43 public class ObjectAdd : IRegionModule
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private Scene m_scene;
48 #region IRegionModule Members
49
50 public void Initialise(Scene pScene, IConfigSource pSource)
51 {
52 m_scene = pScene;
53 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
54 }
55
56 public void PostInitialise()
57 {
58
59 }
60
61 public void RegisterCaps(UUID agentID, Caps caps)
62 {
63 UUID capuuid = UUID.Random();
64
65 m_log.InfoFormat("[OBJECTADD]: {0}", "/CAPS/OA/" + capuuid + "/");
66
67 caps.RegisterHandler("ObjectAdd",
68 new RestHTTPHandler("POST", "/CAPS/OA/" + capuuid + "/",
69 delegate(Hashtable m_dhttpMethod)
70 {
71 return ProcessAdd(m_dhttpMethod, agentID, caps);
72 }));
73 }
74
75 public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap)
76 {
77 Hashtable responsedata = new Hashtable();
78 responsedata["int_response_code"] = 400; //501; //410; //404;
79 responsedata["content_type"] = "text/plain";
80 responsedata["keepalive"] = false;
81 responsedata["str_response_string"] = "Request wasn't what was expected";
82 ScenePresence avatar;
83
84 if (!m_scene.TryGetAvatar(AgentId, out avatar))
85 return responsedata;
86
87
88 OSD r = OSDParser.DeserializeLLSDXml((string)request["requestbody"]);
89 //UUID session_id = UUID.Zero;
90 bool bypass_raycast = false;
91 uint everyone_mask = 0;
92 uint group_mask = 0;
93 uint next_owner_mask = 0;
94 uint flags = 0;
95 UUID group_id = UUID.Zero;
96 int hollow = 0;
97 int material = 0;
98 int p_code = 0;
99 int path_begin = 0;
100 int path_curve = 0;
101 int path_end = 0;
102 int path_radius_offset = 0;
103 int path_revolutions = 0;
104 int path_scale_x = 0;
105 int path_scale_y = 0;
106 int path_shear_x = 0;
107 int path_shear_y = 0;
108 int path_skew = 0;
109 int path_taper_x = 0;
110 int path_taper_y = 0;
111 int path_twist = 0;
112 int path_twist_begin = 0;
113 int profile_begin = 0;
114 int profile_curve = 0;
115 int profile_end = 0;
116 Vector3 ray_end = Vector3.Zero;
117 bool ray_end_is_intersection = false;
118 Vector3 ray_start = Vector3.Zero;
119 UUID ray_target_id = UUID.Zero;
120 Quaternion rotation = Quaternion.Identity;
121 Vector3 scale = Vector3.Zero;
122 int state = 0;
123
124 if (r.Type != OSDType.Map) // not a proper req
125 return responsedata;
126
127 OSDMap rm = (OSDMap)r;
128
129 if (rm.ContainsKey("ObjectData")) //v2
130 {
131 if (rm["ObjectData"].Type != OSDType.Map)
132 {
133 responsedata["str_response_string"] = "Has ObjectData key, but data not in expected format";
134 return responsedata;
135 }
136
137 OSDMap ObjMap = (OSDMap) rm["ObjectData"];
138
139 bypass_raycast = ObjMap["BypassRaycast"].AsBoolean();
140 everyone_mask = readuintval(ObjMap["EveryoneMask"]);
141 flags = readuintval(ObjMap["Flags"]);
142 group_mask = readuintval(ObjMap["GroupMask"]);
143 material = ObjMap["Material"].AsInteger();
144 next_owner_mask = readuintval(ObjMap["NextOwnerMask"]);
145 p_code = ObjMap["PCode"].AsInteger();
146
147 if (ObjMap.ContainsKey("Path"))
148 {
149 if (ObjMap["Path"].Type != OSDType.Map)
150 {
151 responsedata["str_response_string"] = "Has Path key, but data not in expected format";
152 return responsedata;
153 }
154
155 OSDMap PathMap = (OSDMap)ObjMap["Path"];
156 path_begin = PathMap["Begin"].AsInteger();
157 path_curve = PathMap["Curve"].AsInteger();
158 path_end = PathMap["End"].AsInteger();
159 path_radius_offset = PathMap["RadiusOffset"].AsInteger();
160 path_revolutions = PathMap["Revolutions"].AsInteger();
161 path_scale_x = PathMap["ScaleX"].AsInteger();
162 path_scale_y = PathMap["ScaleY"].AsInteger();
163 path_shear_x = PathMap["ShearX"].AsInteger();
164 path_shear_y = PathMap["ShearY"].AsInteger();
165 path_skew = PathMap["Skew"].AsInteger();
166 path_taper_x = PathMap["TaperX"].AsInteger();
167 path_taper_y = PathMap["TaperY"].AsInteger();
168 path_twist = PathMap["Twist"].AsInteger();
169 path_twist_begin = PathMap["TwistBegin"].AsInteger();
170
171 }
172
173 if (ObjMap.ContainsKey("Profile"))
174 {
175 if (ObjMap["Profile"].Type != OSDType.Map)
176 {
177 responsedata["str_response_string"] = "Has Profile key, but data not in expected format";
178 return responsedata;
179 }
180
181 OSDMap ProfileMap = (OSDMap)ObjMap["Profile"];
182
183 profile_begin = ProfileMap["Begin"].AsInteger();
184 profile_curve = ProfileMap["Curve"].AsInteger();
185 profile_end = ProfileMap["End"].AsInteger();
186 hollow = ProfileMap["Hollow"].AsInteger();
187 }
188 ray_end_is_intersection = ObjMap["RayEndIsIntersection"].AsBoolean();
189
190 ray_target_id = ObjMap["RayTargetId"].AsUUID();
191 state = ObjMap["State"].AsInteger();
192 try
193 {
194 ray_end = ((OSDArray) ObjMap["RayEnd"]).AsVector3();
195 ray_start = ((OSDArray) ObjMap["RayStart"]).AsVector3();
196 scale = ((OSDArray) ObjMap["Scale"]).AsVector3();
197 rotation = ((OSDArray)ObjMap["Rotation"]).AsQuaternion();
198 }
199 catch (Exception)
200 {
201 responsedata["str_response_string"] = "RayEnd, RayStart, Scale or Rotation wasn't in the expected format";
202 return responsedata;
203 }
204
205 if (rm.ContainsKey("AgentData"))
206 {
207 if (rm["AgentData"].Type != OSDType.Map)
208 {
209 responsedata["str_response_string"] = "Has AgentData key, but data not in expected format";
210 return responsedata;
211 }
212
213 OSDMap AgentDataMap = (OSDMap) rm["AgentData"];
214
215 //session_id = AgentDataMap["SessionId"].AsUUID();
216 group_id = AgentDataMap["GroupId"].AsUUID();
217 }
218
219 }
220 else
221 { //v1
222 bypass_raycast = rm["bypass_raycast"].AsBoolean();
223
224 everyone_mask = readuintval(rm["everyone_mask"]);
225 flags = readuintval(rm["flags"]);
226 group_id = rm["group_id"].AsUUID();
227 group_mask = readuintval(rm["group_mask"]);
228 hollow = rm["hollow"].AsInteger();
229 material = rm["material"].AsInteger();
230 next_owner_mask = readuintval(rm["next_owner_mask"]);
231 hollow = rm["hollow"].AsInteger();
232 p_code = rm["p_code"].AsInteger();
233 path_begin = rm["path_begin"].AsInteger();
234 path_curve = rm["path_curve"].AsInteger();
235 path_end = rm["path_end"].AsInteger();
236 path_radius_offset = rm["path_radius_offset"].AsInteger();
237 path_revolutions = rm["path_revolutions"].AsInteger();
238 path_scale_x = rm["path_scale_x"].AsInteger();
239 path_scale_y = rm["path_scale_y"].AsInteger();
240 path_shear_x = rm["path_shear_x"].AsInteger();
241 path_shear_y = rm["path_shear_y"].AsInteger();
242 path_skew = rm["path_skew"].AsInteger();
243 path_taper_x = rm["path_taper_x"].AsInteger();
244 path_taper_y = rm["path_taper_y"].AsInteger();
245 path_twist = rm["path_twist"].AsInteger();
246 path_twist_begin = rm["path_twist_begin"].AsInteger();
247 profile_begin = rm["profile_begin"].AsInteger();
248 profile_curve = rm["profile_curve"].AsInteger();
249 profile_end = rm["profile_end"].AsInteger();
250
251 ray_end_is_intersection = rm["ray_end_is_intersection"].AsBoolean();
252
253 ray_target_id = rm["ray_target_id"].AsUUID();
254
255
256 //session_id = rm["session_id"].AsUUID();
257 state = rm["state"].AsInteger();
258 try
259 {
260 ray_end = ((OSDArray)rm["ray_end"]).AsVector3();
261 ray_start = ((OSDArray)rm["ray_start"]).AsVector3();
262 rotation = ((OSDArray)rm["rotation"]).AsQuaternion();
263 scale = ((OSDArray)rm["scale"]).AsVector3();
264 }
265 catch (Exception)
266 {
267 responsedata["str_response_string"] = "RayEnd, RayStart, Scale or Rotation wasn't in the expected format";
268 return responsedata;
269 }
270 }
271
272
273
274 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);
275
276 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();
277
278 pbs.PathBegin = (ushort)path_begin;
279 pbs.PathCurve = (byte)path_curve;
280 pbs.PathEnd = (ushort)path_end;
281 pbs.PathRadiusOffset = (sbyte)path_radius_offset;
282 pbs.PathRevolutions = (byte)path_revolutions;
283 pbs.PathScaleX = (byte)path_scale_x;
284 pbs.PathScaleY = (byte)path_scale_y;
285 pbs.PathShearX = (byte) path_shear_x;
286 pbs.PathShearY = (byte)path_shear_y;
287 pbs.PathSkew = (sbyte)path_skew;
288 pbs.PathTaperX = (sbyte)path_taper_x;
289 pbs.PathTaperY = (sbyte)path_taper_y;
290 pbs.PathTwist = (sbyte)path_twist;
291 pbs.PathTwistBegin = (sbyte)path_twist_begin;
292 pbs.HollowShape = (HollowShape) hollow;
293 pbs.PCode = (byte)p_code;
294 pbs.ProfileBegin = (ushort) profile_begin;
295 pbs.ProfileCurve = (byte) profile_curve;
296 pbs.ProfileEnd = (ushort)profile_end;
297 pbs.Scale = scale;
298 pbs.State = (byte)state;
299
300 SceneObjectGroup obj = null; ;
301
302 if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos))
303 {
304 // rez ON the ground, not IN the ground
305 pos.Z += 0.25F;
306
307 obj = m_scene.AddNewPrim(avatar.UUID, group_id, pos, rotation, pbs);
308 }
309
310
311 if (obj == null)
312 return responsedata;
313
314 SceneObjectPart rootpart = obj.RootPart;
315 rootpart.Shape = pbs;
316 rootpart.Flags |= (PrimFlags)flags;
317 rootpart.EveryoneMask = everyone_mask;
318 rootpart.GroupID = group_id;
319 rootpart.GroupMask = group_mask;
320 rootpart.NextOwnerMask = next_owner_mask;
321 rootpart.Material = (byte)material;
322
323
324
325 m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor);
326
327 responsedata["int_response_code"] = 200; //501; //410; //404;
328 responsedata["content_type"] = "text/plain";
329 responsedata["keepalive"] = false;
330 responsedata["str_response_string"] = String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>",ConvertUintToBytes(obj.LocalId));
331
332 return responsedata;
333 }
334
335 private uint readuintval(OSD obj)
336 {
337 byte[] tmp = obj.AsBinary();
338 if (BitConverter.IsLittleEndian)
339 Array.Reverse(tmp);
340 return Utils.BytesToUInt(tmp);
341
342 }
343 private string ConvertUintToBytes(uint val)
344 {
345 byte[] resultbytes = Utils.UIntToBytes(val);
346 if (BitConverter.IsLittleEndian)
347 Array.Reverse(resultbytes);
348 return String.Format("<binary encoding=\"base64\">{0}</binary>",Convert.ToBase64String(resultbytes));
349 }
350
351 public void Close()
352 {
353
354 }
355
356 public string Name
357 {
358 get { return "ObjectAddModule"; }
359 }
360
361 public bool IsSharedModule
362 {
363 get { return false; }
364 }
365
366 #endregion
367 }
368}