clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
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.Collections.Specialized;
31 using System.Reflection;
32 using System.IO;
33 using System.Web;
34 using Mono.Addins;
35 using log4net;
36 using Nini.Config;
37 using OpenMetaverse;
38 using OpenMetaverse.StructuredData;
39 using OpenMetaverse.Messages.Linden;
40 using OpenSim.Framework;
41 using OpenSim.Framework.Servers;
42 using OpenSim.Framework.Servers.HttpServer;
43 using OpenSim.Region.Framework.Interfaces;
44 using OpenSim.Region.Framework.Scenes;
45 using OpenSim.Services.Interfaces;
46 using Caps = OpenSim.Framework.Capabilities.Caps;
47 using OSD = OpenMetaverse.StructuredData.OSD;
48 using OSDMap = OpenMetaverse.StructuredData.OSDMap;
49 using OpenSim.Framework.Capabilities;
50 using ExtraParamType = OpenMetaverse.ExtraParamType;
51  
52 namespace OpenSim.Region.ClientStack.Linden
53 {
54 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadObjectAssetModule")]
55 public class UploadObjectAssetModule : INonSharedRegionModule
56 {
57 private static readonly ILog m_log =
58 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 private Scene m_scene;
60  
61 #region Region Module interfaceBase Members
62  
63  
64 public Type ReplaceableInterface
65 {
66 get { return null; }
67 }
68  
69 public void Initialise(IConfigSource source)
70 {
71  
72 }
73  
74 public void AddRegion(Scene pScene)
75 {
76 m_scene = pScene;
77 }
78  
79 public void RemoveRegion(Scene scene)
80 {
81  
82 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
83 m_scene = null;
84 }
85  
86 public void RegionLoaded(Scene scene)
87 {
88  
89 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
90 }
91  
92 #endregion
93  
94  
95 #region Region Module interface
96  
97  
98  
99 public void Close() { }
100  
101 public string Name { get { return "UploadObjectAssetModuleModule"; } }
102  
103  
104 public void RegisterCaps(UUID agentID, Caps caps)
105 {
106 UUID capID = UUID.Random();
107  
108 // m_log.Debug("[UPLOAD OBJECT ASSET MODULE]: /CAPS/" + capID);
109 caps.RegisterHandler(
110 "UploadObjectAsset",
111 new RestHTTPHandler(
112 "POST",
113 "/CAPS/OA/" + capID + "/",
114 httpMethod => ProcessAdd(httpMethod, agentID, caps),
115 "UploadObjectAsset",
116 agentID.ToString()));
117  
118 /*
119 caps.RegisterHandler("NewFileAgentInventoryVariablePrice",
120  
121 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>("POST",
122 "/CAPS/" + capID.ToString(),
123 delegate(LLSDAssetUploadRequest req)
124 {
125 return NewAgentInventoryRequest(req,agentID);
126 }));
127 */
128  
129 }
130  
131 #endregion
132  
133  
134 /// <summary>
135 /// Parses add request
136 /// </summary>
137 /// <param name="request"></param>
138 /// <param name="AgentId"></param>
139 /// <param name="cap"></param>
140 /// <returns></returns>
141 public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap)
142 {
143 Hashtable responsedata = new Hashtable();
144 responsedata["int_response_code"] = 400; //501; //410; //404;
145 responsedata["content_type"] = "text/plain";
146 responsedata["keepalive"] = false;
147 responsedata["str_response_string"] = "Request wasn't what was expected";
148 ScenePresence avatar;
149  
150 if (!m_scene.TryGetScenePresence(AgentId, out avatar))
151 return responsedata;
152  
153 OSDMap r = (OSDMap)OSDParser.Deserialize((string)request["requestbody"]);
154 UploadObjectAssetMessage message = new UploadObjectAssetMessage();
155 try
156 {
157 message.Deserialize(r);
158  
159 }
160 catch (Exception ex)
161 {
162 m_log.Error("[UPLOAD OBJECT ASSET MODULE]: Error deserializing message " + ex.ToString());
163 message = null;
164 }
165  
166 if (message == null)
167 {
168 responsedata["int_response_code"] = 400; //501; //410; //404;
169 responsedata["content_type"] = "text/plain";
170 responsedata["keepalive"] = false;
171 responsedata["str_response_string"] =
172 "<llsd><map><key>error</key><string>Error parsing Object</string></map></llsd>";
173  
174 return responsedata;
175 }
176  
177 Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation);
178 Quaternion rot = Quaternion.Identity;
179 Vector3 rootpos = Vector3.Zero;
180 // Quaternion rootrot = Quaternion.Identity;
181  
182 SceneObjectGroup rootGroup = null;
183 SceneObjectGroup[] allparts = new SceneObjectGroup[message.Objects.Length];
184 for (int i = 0; i < message.Objects.Length; i++)
185 {
186 UploadObjectAssetMessage.Object obj = message.Objects[i];
187 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();
188  
189 if (i == 0)
190 {
191 rootpos = obj.Position;
192 // rootrot = obj.Rotation;
193 }
194  
195 // Combine the extraparams data into it's ugly blob again....
196 //int bytelength = 0;
197 //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
198 //{
199 // bytelength += obj.ExtraParams[extparams].ExtraParamData.Length;
200 //}
201 //byte[] extraparams = new byte[bytelength];
202 //int position = 0;
203  
204  
205  
206 //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
207 //{
208 // Buffer.BlockCopy(obj.ExtraParams[extparams].ExtraParamData, 0, extraparams, position,
209 // obj.ExtraParams[extparams].ExtraParamData.Length);
210 //
211 // position += obj.ExtraParams[extparams].ExtraParamData.Length;
212 // }
213  
214 //pbs.ExtraParams = extraparams;
215 for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
216 {
217 UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[extparams];
218 switch ((ushort)extraParam.Type)
219 {
220 case (ushort)ExtraParamType.Sculpt:
221 Primitive.SculptData sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0);
222  
223 pbs.SculptEntry = true;
224  
225 pbs.SculptTexture = obj.SculptID;
226 pbs.SculptType = (byte)sculpt.Type;
227  
228 break;
229 case (ushort)ExtraParamType.Flexible:
230 Primitive.FlexibleData flex = new Primitive.FlexibleData(extraParam.ExtraParamData, 0);
231 pbs.FlexiEntry = true;
232 pbs.FlexiDrag = flex.Drag;
233 pbs.FlexiForceX = flex.Force.X;
234 pbs.FlexiForceY = flex.Force.Y;
235 pbs.FlexiForceZ = flex.Force.Z;
236 pbs.FlexiGravity = flex.Gravity;
237 pbs.FlexiSoftness = flex.Softness;
238 pbs.FlexiTension = flex.Tension;
239 pbs.FlexiWind = flex.Wind;
240 break;
241 case (ushort)ExtraParamType.Light:
242 Primitive.LightData light = new Primitive.LightData(extraParam.ExtraParamData, 0);
243 pbs.LightColorA = light.Color.A;
244 pbs.LightColorB = light.Color.B;
245 pbs.LightColorG = light.Color.G;
246 pbs.LightColorR = light.Color.R;
247 pbs.LightCutoff = light.Cutoff;
248 pbs.LightEntry = true;
249 pbs.LightFalloff = light.Falloff;
250 pbs.LightIntensity = light.Intensity;
251 pbs.LightRadius = light.Radius;
252 break;
253 case 0x40:
254 pbs.ReadProjectionData(extraParam.ExtraParamData, 0);
255 break;
256 }
257 }
258  
259 pbs.PathBegin = (ushort) obj.PathBegin;
260 pbs.PathCurve = (byte) obj.PathCurve;
261 pbs.PathEnd = (ushort) obj.PathEnd;
262 pbs.PathRadiusOffset = (sbyte) obj.RadiusOffset;
263 pbs.PathRevolutions = (byte) obj.Revolutions;
264 pbs.PathScaleX = (byte) obj.ScaleX;
265 pbs.PathScaleY = (byte) obj.ScaleY;
266 pbs.PathShearX = (byte) obj.ShearX;
267 pbs.PathShearY = (byte) obj.ShearY;
268 pbs.PathSkew = (sbyte) obj.Skew;
269 pbs.PathTaperX = (sbyte) obj.TaperX;
270 pbs.PathTaperY = (sbyte) obj.TaperY;
271 pbs.PathTwist = (sbyte) obj.Twist;
272 pbs.PathTwistBegin = (sbyte) obj.TwistBegin;
273 pbs.HollowShape = (HollowShape) obj.ProfileHollow;
274 pbs.PCode = (byte) PCode.Prim;
275 pbs.ProfileBegin = (ushort) obj.ProfileBegin;
276 pbs.ProfileCurve = (byte) obj.ProfileCurve;
277 pbs.ProfileEnd = (ushort) obj.ProfileEnd;
278 pbs.Scale = obj.Scale;
279 pbs.State = (byte) 0;
280 SceneObjectPart prim = new SceneObjectPart();
281 prim.UUID = UUID.Random();
282 prim.CreatorID = AgentId;
283 prim.OwnerID = AgentId;
284 prim.GroupID = obj.GroupID;
285 prim.LastOwnerID = prim.OwnerID;
286 prim.CreationDate = Util.UnixTimeSinceEpoch();
287 prim.Name = obj.Name;
288 prim.Description = "";
289  
290 prim.PayPrice[0] = -2;
291 prim.PayPrice[1] = -2;
292 prim.PayPrice[2] = -2;
293 prim.PayPrice[3] = -2;
294 prim.PayPrice[4] = -2;
295 Primitive.TextureEntry tmp =
296 new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f"));
297  
298 for (int j = 0; j < obj.Faces.Length; j++)
299 {
300 UploadObjectAssetMessage.Object.Face face = obj.Faces[j];
301  
302 Primitive.TextureEntryFace primFace = tmp.CreateFace((uint) j);
303  
304 primFace.Bump = face.Bump;
305 primFace.RGBA = face.Color;
306 primFace.Fullbright = face.Fullbright;
307 primFace.Glow = face.Glow;
308 primFace.TextureID = face.ImageID;
309 primFace.Rotation = face.ImageRot;
310 primFace.MediaFlags = ((face.MediaFlags & 1) != 0);
311  
312 primFace.OffsetU = face.OffsetS;
313 primFace.OffsetV = face.OffsetT;
314 primFace.RepeatU = face.ScaleS;
315 primFace.RepeatV = face.ScaleT;
316 primFace.TexMapType = (MappingType) (face.MediaFlags & 6);
317 }
318  
319 pbs.TextureEntry = tmp.GetBytes();
320 prim.Shape = pbs;
321 prim.Scale = obj.Scale;
322  
323 SceneObjectGroup grp = new SceneObjectGroup();
324  
325 grp.SetRootPart(prim);
326 prim.ParentID = 0;
327 if (i == 0)
328 {
329 rootGroup = grp;
330  
331 }
332 grp.AttachToScene(m_scene);
333 grp.AbsolutePosition = obj.Position;
334 prim.RotationOffset = obj.Rotation;
335  
336 // Required for linking
337 grp.RootPart.ClearUpdateSchedule();
338  
339 if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos))
340 {
341 m_scene.AddSceneObject(grp);
342 grp.AbsolutePosition = obj.Position;
343 }
344  
345 allparts[i] = grp;
346 }
347  
348 for (int j = 1; j < allparts.Length; j++)
349 {
350 // Required for linking
351 rootGroup.RootPart.ClearUpdateSchedule();
352 allparts[j].RootPart.ClearUpdateSchedule();
353 rootGroup.LinkToGroup(allparts[j]);
354 }
355  
356 rootGroup.ScheduleGroupForFullUpdate();
357 pos
358 = m_scene.GetNewRezLocation(
359 Vector3.Zero, rootpos, UUID.Zero, rot, (byte)1, 1, true, allparts[0].GroupScale, false);
360  
361 responsedata["int_response_code"] = 200; //501; //410; //404;
362 responsedata["content_type"] = "text/plain";
363 responsedata["keepalive"] = false;
364 responsedata["str_response_string"] = String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(allparts[0].LocalId));
365  
366 return responsedata;
367 }
368  
369 private string ConvertUintToBytes(uint val)
370 {
371 byte[] resultbytes = Utils.UIntToBytes(val);
372 if (BitConverter.IsLittleEndian)
373 Array.Reverse(resultbytes);
374 return String.Format("<binary encoding=\"base64\">{0}</binary>", Convert.ToBase64String(resultbytes));
375 }
376 }
377 }