clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 OpenSimulator 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 | |||
28 | using System; |
||
29 | using System.Collections; |
||
30 | using System.Reflection; |
||
31 | using log4net; |
||
32 | using Nini.Config; |
||
33 | using OpenMetaverse; |
||
34 | using OpenMetaverse.StructuredData; |
||
35 | using Mono.Addins; |
||
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; |
||
41 | using Caps=OpenSim.Framework.Capabilities.Caps; |
||
42 | |||
43 | namespace OpenSim.Region.ClientStack.Linden |
||
44 | { |
||
45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ObjectAdd")] |
||
46 | public class ObjectAdd : INonSharedRegionModule |
||
47 | { |
||
48 | // private static readonly ILog m_log = |
||
49 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
50 | |||
51 | private Scene m_scene; |
||
52 | |||
53 | #region INonSharedRegionModule Members |
||
54 | |||
55 | public void Initialise(IConfigSource pSource) |
||
56 | { |
||
57 | } |
||
58 | |||
59 | public void AddRegion(Scene scene) |
||
60 | { |
||
61 | m_scene = scene; |
||
62 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
||
63 | } |
||
64 | |||
65 | public void RemoveRegion(Scene scene) |
||
66 | { |
||
67 | if (m_scene == scene) |
||
68 | { |
||
69 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; |
||
70 | m_scene = null; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | public void RegionLoaded(Scene scene) |
||
75 | { |
||
76 | } |
||
77 | |||
78 | public void Close() |
||
79 | { |
||
80 | } |
||
81 | |||
82 | public string Name |
||
83 | { |
||
84 | get { return "ObjectAddModule"; } |
||
85 | } |
||
86 | |||
87 | public Type ReplaceableInterface |
||
88 | { |
||
89 | get { return null; } |
||
90 | } |
||
91 | |||
92 | #endregion |
||
93 | |||
94 | public void RegisterCaps(UUID agentID, Caps caps) |
||
95 | { |
||
96 | UUID capuuid = UUID.Random(); |
||
97 | |||
98 | // m_log.InfoFormat("[OBJECTADD]: {0}", "/CAPS/OA/" + capuuid + "/"); |
||
99 | |||
100 | caps.RegisterHandler( |
||
101 | "ObjectAdd", |
||
102 | new RestHTTPHandler( |
||
103 | "POST", |
||
104 | "/CAPS/OA/" + capuuid + "/", |
||
105 | httpMethod => ProcessAdd(httpMethod, agentID, caps), |
||
106 | "ObjectAdd", |
||
107 | agentID.ToString())); ; |
||
108 | } |
||
109 | |||
110 | public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap) |
||
111 | { |
||
112 | Hashtable responsedata = new Hashtable(); |
||
113 | responsedata["int_response_code"] = 400; //501; //410; //404; |
||
114 | responsedata["content_type"] = "text/plain"; |
||
115 | responsedata["keepalive"] = false; |
||
116 | responsedata["str_response_string"] = "Request wasn't what was expected"; |
||
117 | ScenePresence avatar; |
||
118 | |||
119 | if (!m_scene.TryGetScenePresence(AgentId, out avatar)) |
||
120 | return responsedata; |
||
121 | |||
122 | |||
123 | OSD r = OSDParser.DeserializeLLSDXml((string)request["requestbody"]); |
||
124 | //UUID session_id = UUID.Zero; |
||
125 | bool bypass_raycast = false; |
||
126 | uint everyone_mask = 0; |
||
127 | uint group_mask = 0; |
||
128 | uint next_owner_mask = 0; |
||
129 | uint flags = 0; |
||
130 | UUID group_id = UUID.Zero; |
||
131 | int hollow = 0; |
||
132 | int material = 0; |
||
133 | int p_code = 0; |
||
134 | int path_begin = 0; |
||
135 | int path_curve = 0; |
||
136 | int path_end = 0; |
||
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; |
||
143 | int path_skew = 0; |
||
144 | int path_taper_x = 0; |
||
145 | int path_taper_y = 0; |
||
146 | int path_twist = 0; |
||
147 | int path_twist_begin = 0; |
||
148 | int profile_begin = 0; |
||
149 | int profile_curve = 0; |
||
150 | int profile_end = 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; |
||
157 | int state = 0; |
||
158 | |||
159 | if (r.Type != OSDType.Map) // not a proper req |
||
160 | return responsedata; |
||
161 | |||
162 | OSDMap rm = (OSDMap)r; |
||
163 | |||
164 | if (rm.ContainsKey("ObjectData")) //v2 |
||
165 | { |
||
166 | if (rm["ObjectData"].Type != OSDType.Map) |
||
167 | { |
||
168 | responsedata["str_response_string"] = "Has ObjectData key, but data not in expected format"; |
||
169 | return responsedata; |
||
170 | } |
||
171 | |||
172 | OSDMap ObjMap = (OSDMap)rm["ObjectData"]; |
||
173 | |||
174 | bypass_raycast = ObjMap["BypassRaycast"].AsBoolean(); |
||
175 | everyone_mask = readuintval(ObjMap["EveryoneMask"]); |
||
176 | flags = readuintval(ObjMap["Flags"]); |
||
177 | group_mask = readuintval(ObjMap["GroupMask"]); |
||
178 | material = ObjMap["Material"].AsInteger(); |
||
179 | next_owner_mask = readuintval(ObjMap["NextOwnerMask"]); |
||
180 | p_code = ObjMap["PCode"].AsInteger(); |
||
181 | |||
182 | if (ObjMap.ContainsKey("Path")) |
||
183 | { |
||
184 | if (ObjMap["Path"].Type != OSDType.Map) |
||
185 | { |
||
186 | responsedata["str_response_string"] = "Has Path key, but data not in expected format"; |
||
187 | return responsedata; |
||
188 | } |
||
189 | |||
190 | OSDMap PathMap = (OSDMap)ObjMap["Path"]; |
||
191 | path_begin = PathMap["Begin"].AsInteger(); |
||
192 | path_curve = PathMap["Curve"].AsInteger(); |
||
193 | path_end = PathMap["End"].AsInteger(); |
||
194 | path_radius_offset = PathMap["RadiusOffset"].AsInteger(); |
||
195 | path_revolutions = PathMap["Revolutions"].AsInteger(); |
||
196 | path_scale_x = PathMap["ScaleX"].AsInteger(); |
||
197 | path_scale_y = PathMap["ScaleY"].AsInteger(); |
||
198 | path_shear_x = PathMap["ShearX"].AsInteger(); |
||
199 | path_shear_y = PathMap["ShearY"].AsInteger(); |
||
200 | path_skew = PathMap["Skew"].AsInteger(); |
||
201 | path_taper_x = PathMap["TaperX"].AsInteger(); |
||
202 | path_taper_y = PathMap["TaperY"].AsInteger(); |
||
203 | path_twist = PathMap["Twist"].AsInteger(); |
||
204 | path_twist_begin = PathMap["TwistBegin"].AsInteger(); |
||
205 | |||
206 | } |
||
207 | |||
208 | if (ObjMap.ContainsKey("Profile")) |
||
209 | { |
||
210 | if (ObjMap["Profile"].Type != OSDType.Map) |
||
211 | { |
||
212 | responsedata["str_response_string"] = "Has Profile key, but data not in expected format"; |
||
213 | return responsedata; |
||
214 | } |
||
215 | |||
216 | OSDMap ProfileMap = (OSDMap)ObjMap["Profile"]; |
||
217 | |||
218 | profile_begin = ProfileMap["Begin"].AsInteger(); |
||
219 | profile_curve = ProfileMap["Curve"].AsInteger(); |
||
220 | profile_end = ProfileMap["End"].AsInteger(); |
||
221 | hollow = ProfileMap["Hollow"].AsInteger(); |
||
222 | } |
||
223 | ray_end_is_intersection = ObjMap["RayEndIsIntersection"].AsBoolean(); |
||
224 | |||
225 | ray_target_id = ObjMap["RayTargetId"].AsUUID(); |
||
226 | state = ObjMap["State"].AsInteger(); |
||
227 | try |
||
228 | { |
||
229 | ray_end = ((OSDArray)ObjMap["RayEnd"]).AsVector3(); |
||
230 | ray_start = ((OSDArray)ObjMap["RayStart"]).AsVector3(); |
||
231 | scale = ((OSDArray)ObjMap["Scale"]).AsVector3(); |
||
232 | rotation = ((OSDArray)ObjMap["Rotation"]).AsQuaternion(); |
||
233 | } |
||
234 | catch (Exception) |
||
235 | { |
||
236 | responsedata["str_response_string"] = "RayEnd, RayStart, Scale or Rotation wasn't in the expected format"; |
||
237 | return responsedata; |
||
238 | } |
||
239 | |||
240 | if (rm.ContainsKey("AgentData")) |
||
241 | { |
||
242 | if (rm["AgentData"].Type != OSDType.Map) |
||
243 | { |
||
244 | responsedata["str_response_string"] = "Has AgentData key, but data not in expected format"; |
||
245 | return responsedata; |
||
246 | } |
||
247 | |||
248 | OSDMap AgentDataMap = (OSDMap)rm["AgentData"]; |
||
249 | |||
250 | //session_id = AgentDataMap["SessionId"].AsUUID(); |
||
251 | group_id = AgentDataMap["GroupId"].AsUUID(); |
||
252 | } |
||
253 | |||
254 | } |
||
255 | else |
||
256 | { //v1 |
||
257 | bypass_raycast = rm["bypass_raycast"].AsBoolean(); |
||
258 | |||
259 | everyone_mask = readuintval(rm["everyone_mask"]); |
||
260 | flags = readuintval(rm["flags"]); |
||
261 | group_id = rm["group_id"].AsUUID(); |
||
262 | group_mask = readuintval(rm["group_mask"]); |
||
263 | hollow = rm["hollow"].AsInteger(); |
||
264 | material = rm["material"].AsInteger(); |
||
265 | next_owner_mask = readuintval(rm["next_owner_mask"]); |
||
266 | hollow = rm["hollow"].AsInteger(); |
||
267 | p_code = rm["p_code"].AsInteger(); |
||
268 | path_begin = rm["path_begin"].AsInteger(); |
||
269 | path_curve = rm["path_curve"].AsInteger(); |
||
270 | path_end = rm["path_end"].AsInteger(); |
||
271 | path_radius_offset = rm["path_radius_offset"].AsInteger(); |
||
272 | path_revolutions = rm["path_revolutions"].AsInteger(); |
||
273 | path_scale_x = rm["path_scale_x"].AsInteger(); |
||
274 | path_scale_y = rm["path_scale_y"].AsInteger(); |
||
275 | path_shear_x = rm["path_shear_x"].AsInteger(); |
||
276 | path_shear_y = rm["path_shear_y"].AsInteger(); |
||
277 | path_skew = rm["path_skew"].AsInteger(); |
||
278 | path_taper_x = rm["path_taper_x"].AsInteger(); |
||
279 | path_taper_y = rm["path_taper_y"].AsInteger(); |
||
280 | path_twist = rm["path_twist"].AsInteger(); |
||
281 | path_twist_begin = rm["path_twist_begin"].AsInteger(); |
||
282 | profile_begin = rm["profile_begin"].AsInteger(); |
||
283 | profile_curve = rm["profile_curve"].AsInteger(); |
||
284 | profile_end = rm["profile_end"].AsInteger(); |
||
285 | |||
286 | ray_end_is_intersection = rm["ray_end_is_intersection"].AsBoolean(); |
||
287 | |||
288 | ray_target_id = rm["ray_target_id"].AsUUID(); |
||
289 | |||
290 | |||
291 | //session_id = rm["session_id"].AsUUID(); |
||
292 | state = rm["state"].AsInteger(); |
||
293 | try |
||
294 | { |
||
295 | ray_end = ((OSDArray)rm["ray_end"]).AsVector3(); |
||
296 | ray_start = ((OSDArray)rm["ray_start"]).AsVector3(); |
||
297 | rotation = ((OSDArray)rm["rotation"]).AsQuaternion(); |
||
298 | scale = ((OSDArray)rm["scale"]).AsVector3(); |
||
299 | } |
||
300 | catch (Exception) |
||
301 | { |
||
302 | responsedata["str_response_string"] = "RayEnd, RayStart, Scale or Rotation wasn't in the expected format"; |
||
303 | return responsedata; |
||
304 | } |
||
305 | } |
||
306 | |||
307 | |||
308 | |||
309 | 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); |
||
310 | |||
311 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); |
||
312 | |||
313 | pbs.PathBegin = (ushort)path_begin; |
||
314 | pbs.PathCurve = (byte)path_curve; |
||
315 | pbs.PathEnd = (ushort)path_end; |
||
316 | pbs.PathRadiusOffset = (sbyte)path_radius_offset; |
||
317 | pbs.PathRevolutions = (byte)path_revolutions; |
||
318 | pbs.PathScaleX = (byte)path_scale_x; |
||
319 | pbs.PathScaleY = (byte)path_scale_y; |
||
320 | pbs.PathShearX = (byte)path_shear_x; |
||
321 | pbs.PathShearY = (byte)path_shear_y; |
||
322 | pbs.PathSkew = (sbyte)path_skew; |
||
323 | pbs.PathTaperX = (sbyte)path_taper_x; |
||
324 | pbs.PathTaperY = (sbyte)path_taper_y; |
||
325 | pbs.PathTwist = (sbyte)path_twist; |
||
326 | pbs.PathTwistBegin = (sbyte)path_twist_begin; |
||
327 | pbs.HollowShape = (HollowShape)hollow; |
||
328 | pbs.PCode = (byte)p_code; |
||
329 | pbs.ProfileBegin = (ushort)profile_begin; |
||
330 | pbs.ProfileCurve = (byte)profile_curve; |
||
331 | pbs.ProfileEnd = (ushort)profile_end; |
||
332 | pbs.Scale = scale; |
||
333 | pbs.State = (byte)state; |
||
334 | |||
335 | SceneObjectGroup obj = null; ; |
||
336 | |||
337 | if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos)) |
||
338 | { |
||
339 | // rez ON the ground, not IN the ground |
||
340 | // pos.Z += 0.25F; |
||
341 | |||
342 | obj = m_scene.AddNewPrim(avatar.UUID, group_id, pos, rotation, pbs); |
||
343 | } |
||
344 | |||
345 | |||
346 | if (obj == null) |
||
347 | return responsedata; |
||
348 | |||
349 | SceneObjectPart rootpart = obj.RootPart; |
||
350 | rootpart.Shape = pbs; |
||
351 | rootpart.Flags |= (PrimFlags)flags; |
||
352 | rootpart.EveryoneMask = everyone_mask; |
||
353 | rootpart.GroupID = group_id; |
||
354 | rootpart.GroupMask = group_mask; |
||
355 | rootpart.NextOwnerMask = next_owner_mask; |
||
356 | rootpart.Material = (byte)material; |
||
357 | |||
358 | m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor); |
||
359 | |||
360 | responsedata["int_response_code"] = 200; //501; //410; //404; |
||
361 | responsedata["content_type"] = "text/plain"; |
||
362 | responsedata["keepalive"] = false; |
||
363 | responsedata["str_response_string"] = String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(obj.LocalId)); |
||
364 | |||
365 | return responsedata; |
||
366 | } |
||
367 | |||
368 | private uint readuintval(OSD obj) |
||
369 | { |
||
370 | byte[] tmp = obj.AsBinary(); |
||
371 | if (BitConverter.IsLittleEndian) |
||
372 | Array.Reverse(tmp); |
||
373 | return Utils.BytesToUInt(tmp); |
||
374 | |||
375 | } |
||
376 | private string ConvertUintToBytes(uint val) |
||
377 | { |
||
378 | byte[] resultbytes = Utils.UIntToBytes(val); |
||
379 | if (BitConverter.IsLittleEndian) |
||
380 | Array.Reverse(resultbytes); |
||
381 | return String.Format("<binary encoding=\"base64\">{0}</binary>", Convert.ToBase64String(resultbytes)); |
||
382 | } |
||
383 | |||
384 | } |
||
385 | } |