diff options
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/ObjectCaps/UploadObjectAssetModule.cs | 301 |
1 files changed, 301 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/ObjectCaps/UploadObjectAssetModule.cs b/OpenSim/Region/CoreModules/Avatar/ObjectCaps/UploadObjectAssetModule.cs new file mode 100644 index 0000000..f1f219b --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/ObjectCaps/UploadObjectAssetModule.cs | |||
@@ -0,0 +1,301 @@ | |||
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 | |||
51 | namespace OpenSim.Region.CoreModules.Avatar.ObjectCaps | ||
52 | { | ||
53 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | ||
54 | public class UploadObjectAssetModule : INonSharedRegionModule | ||
55 | { | ||
56 | private static readonly ILog m_log = | ||
57 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
58 | private Scene m_scene; | ||
59 | |||
60 | #region IRegionModuleBase Members | ||
61 | |||
62 | |||
63 | public Type ReplaceableInterface | ||
64 | { | ||
65 | get { return null; } | ||
66 | } | ||
67 | |||
68 | public void Initialise(IConfigSource source) | ||
69 | { | ||
70 | |||
71 | } | ||
72 | |||
73 | public void AddRegion(Scene pScene) | ||
74 | { | ||
75 | m_scene = pScene; | ||
76 | } | ||
77 | |||
78 | public void RemoveRegion(Scene scene) | ||
79 | { | ||
80 | |||
81 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
82 | m_scene = null; | ||
83 | } | ||
84 | |||
85 | public void RegionLoaded(Scene scene) | ||
86 | { | ||
87 | |||
88 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
89 | } | ||
90 | |||
91 | #endregion | ||
92 | |||
93 | |||
94 | #region IRegionModule Members | ||
95 | |||
96 | |||
97 | |||
98 | public void Close() { } | ||
99 | |||
100 | public string Name { get { return "UploadObjectAssetModuleModule"; } } | ||
101 | |||
102 | |||
103 | public void RegisterCaps(UUID agentID, Caps caps) | ||
104 | { | ||
105 | UUID capID = UUID.Random(); | ||
106 | |||
107 | m_log.Info("[UploadObjectAssetModule]: /CAPS/" + capID); | ||
108 | caps.RegisterHandler("UploadObjectAsset", | ||
109 | new RestHTTPHandler("POST", "/CAPS/OA/" + capID + "/", | ||
110 | delegate(Hashtable m_dhttpMethod) | ||
111 | { | ||
112 | return ProcessAdd(m_dhttpMethod, agentID, caps); | ||
113 | })); | ||
114 | /* | ||
115 | caps.RegisterHandler("NewFileAgentInventoryVariablePrice", | ||
116 | |||
117 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>("POST", | ||
118 | "/CAPS/" + capID.ToString(), | ||
119 | delegate(LLSDAssetUploadRequest req) | ||
120 | { | ||
121 | return NewAgentInventoryRequest(req,agentID); | ||
122 | })); | ||
123 | */ | ||
124 | |||
125 | } | ||
126 | |||
127 | #endregion | ||
128 | |||
129 | public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap) | ||
130 | { | ||
131 | Hashtable responsedata = new Hashtable(); | ||
132 | responsedata["int_response_code"] = 400; //501; //410; //404; | ||
133 | responsedata["content_type"] = "text/plain"; | ||
134 | responsedata["keepalive"] = false; | ||
135 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
136 | ScenePresence avatar; | ||
137 | |||
138 | if (!m_scene.TryGetScenePresence(AgentId, out avatar)) | ||
139 | return responsedata; | ||
140 | |||
141 | OSDMap r = (OSDMap)OSDParser.Deserialize((string)request["requestbody"]); | ||
142 | UploadObjectAssetMessage message = new UploadObjectAssetMessage(); | ||
143 | try | ||
144 | { | ||
145 | message.Deserialize(r); | ||
146 | |||
147 | } | ||
148 | catch (Exception ex) | ||
149 | { | ||
150 | m_log.Error("[UploadObjectAssetModule]: Error deserializing message"); | ||
151 | // TODO: Remove this ugly multiline-friendly debug! | ||
152 | Console.WriteLine(ex.ToString()); | ||
153 | message = null; | ||
154 | } | ||
155 | |||
156 | if (message == null) | ||
157 | { | ||
158 | responsedata["int_response_code"] = 400; //501; //410; //404; | ||
159 | responsedata["content_type"] = "text/plain"; | ||
160 | responsedata["keepalive"] = false; | ||
161 | responsedata["str_response_string"] = | ||
162 | "<llsd><map><key>error</key><string>Error parsing Object</string></map></llsd>"; | ||
163 | |||
164 | return responsedata; | ||
165 | } | ||
166 | |||
167 | Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation); | ||
168 | Quaternion rot = Quaternion.Identity; | ||
169 | |||
170 | |||
171 | |||
172 | SceneObjectGroup grp = new SceneObjectGroup(); | ||
173 | for (int i = 0; i < message.Objects.Length; i++) | ||
174 | { | ||
175 | UploadObjectAssetMessage.Object obj = message.Objects[i]; | ||
176 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); | ||
177 | |||
178 | // Combine the extraparams data into it's ugly blob again.... | ||
179 | int bytelength = 0; | ||
180 | for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) | ||
181 | { | ||
182 | bytelength += obj.ExtraParams[extparams].ExtraParamData.Length; | ||
183 | } | ||
184 | byte[] extraparams = new byte[bytelength]; | ||
185 | int position = 0; | ||
186 | |||
187 | for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) | ||
188 | { | ||
189 | Buffer.BlockCopy(obj.ExtraParams[extparams].ExtraParamData, 0, extraparams, position, obj.ExtraParams[extparams].ExtraParamData.Length); | ||
190 | |||
191 | position += obj.ExtraParams[extparams].ExtraParamData.Length; | ||
192 | } | ||
193 | |||
194 | pbs.ExtraParams = extraparams; | ||
195 | |||
196 | pbs.PathBegin = (ushort)obj.PathBegin; | ||
197 | pbs.PathCurve = (byte)obj.PathCurve; | ||
198 | pbs.PathEnd = (ushort)obj.PathEnd; | ||
199 | pbs.PathRadiusOffset = (sbyte)obj.RadiusOffset; | ||
200 | pbs.PathRevolutions = (byte)obj.Revolutions; | ||
201 | pbs.PathScaleX = (byte)obj.ScaleX; | ||
202 | pbs.PathScaleY = (byte)obj.ScaleY; | ||
203 | pbs.PathShearX = (byte)obj.ShearX; | ||
204 | pbs.PathShearY = (byte)obj.ShearY; | ||
205 | pbs.PathSkew = (sbyte)obj.Skew; | ||
206 | pbs.PathTaperX = (sbyte)obj.TaperX; | ||
207 | pbs.PathTaperY = (sbyte)obj.TaperY; | ||
208 | pbs.PathTwist = (sbyte)obj.Twist; | ||
209 | pbs.PathTwistBegin = (sbyte)obj.TwistBegin; | ||
210 | pbs.HollowShape = (HollowShape)obj.ProfileHollow; | ||
211 | pbs.PCode = (byte)PCode.Prim; | ||
212 | pbs.ProfileBegin = (ushort)obj.ProfileBegin; | ||
213 | pbs.ProfileCurve = (byte)obj.ProfileCurve; | ||
214 | pbs.ProfileEnd = (ushort)obj.ProfileEnd; | ||
215 | pbs.Scale = obj.Scale; | ||
216 | pbs.State = (byte)0; | ||
217 | SceneObjectPart prim = new SceneObjectPart(); | ||
218 | prim.UUID = UUID.Random(); | ||
219 | prim.CreatorID = AgentId; | ||
220 | prim.OwnerID = AgentId; | ||
221 | prim.GroupID = obj.GroupID; | ||
222 | prim.LastOwnerID = prim.OwnerID; | ||
223 | prim.CreationDate = Util.UnixTimeSinceEpoch(); | ||
224 | prim.Name = obj.Name; | ||
225 | prim.Description = ""; | ||
226 | |||
227 | prim.PayPrice[0] = -2; | ||
228 | prim.PayPrice[1] = -2; | ||
229 | prim.PayPrice[2] = -2; | ||
230 | prim.PayPrice[3] = -2; | ||
231 | prim.PayPrice[4] = -2; | ||
232 | Primitive.TextureEntry tmp = new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f")); | ||
233 | |||
234 | for (int j = 0; j < obj.Faces.Length; j++) | ||
235 | { | ||
236 | UploadObjectAssetMessage.Object.Face face = obj.Faces[j]; | ||
237 | |||
238 | Primitive.TextureEntryFace primFace = tmp.CreateFace((uint)j); | ||
239 | |||
240 | primFace.Bump = face.Bump; | ||
241 | primFace.RGBA = face.Color; | ||
242 | primFace.Fullbright = face.Fullbright; | ||
243 | primFace.Glow = face.Glow; | ||
244 | primFace.TextureID = face.ImageID; | ||
245 | primFace.Rotation = face.ImageRot; | ||
246 | primFace.MediaFlags = ((face.MediaFlags & 1) != 0); | ||
247 | |||
248 | primFace.OffsetU = face.OffsetS; | ||
249 | primFace.OffsetV = face.OffsetT; | ||
250 | primFace.RepeatU = face.ScaleS; | ||
251 | primFace.RepeatV = face.ScaleT; | ||
252 | primFace.TexMapType = (MappingType)(face.MediaFlags & 6); | ||
253 | } | ||
254 | pbs.TextureEntry = tmp.GetBytes(); | ||
255 | prim.Shape = pbs; | ||
256 | prim.Scale = obj.Scale; | ||
257 | prim.Shape.SculptEntry = true; | ||
258 | prim.Shape.SculptTexture = obj.SculptID; | ||
259 | prim.Shape.SculptType = (byte) SculptType.Mesh; | ||
260 | |||
261 | if (i == 0) | ||
262 | { | ||
263 | grp.SetRootPart(prim); | ||
264 | prim.ParentID = 0; | ||
265 | } | ||
266 | else | ||
267 | { | ||
268 | prim.SetParent(grp); | ||
269 | grp.AddPart(prim); | ||
270 | } | ||
271 | |||
272 | } | ||
273 | pos = m_scene.GetNewRezLocation(Vector3.Zero, pos, UUID.Zero, rot, (byte)1 , 1 , true, grp.GroupScale(), false); | ||
274 | grp.AttachToScene(m_scene); | ||
275 | grp.AbsolutePosition = pos; | ||
276 | grp.ClearPartAttachmentData(); | ||
277 | grp.RootPart.IsAttachment = false; | ||
278 | |||
279 | if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos)) | ||
280 | { | ||
281 | m_scene.AddSceneObject(grp); | ||
282 | } | ||
283 | grp.ScheduleGroupForFullUpdate(); | ||
284 | responsedata["int_response_code"] = 200; //501; //410; //404; | ||
285 | responsedata["content_type"] = "text/plain"; | ||
286 | responsedata["keepalive"] = false; | ||
287 | responsedata["str_response_string"] = String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(grp.LocalId)); | ||
288 | |||
289 | return responsedata; | ||
290 | |||
291 | |||
292 | } | ||
293 | private string ConvertUintToBytes(uint val) | ||
294 | { | ||
295 | byte[] resultbytes = Utils.UIntToBytes(val); | ||
296 | if (BitConverter.IsLittleEndian) | ||
297 | Array.Reverse(resultbytes); | ||
298 | return String.Format("<binary encoding=\"base64\">{0}</binary>", Convert.ToBase64String(resultbytes)); | ||
299 | } | ||
300 | } | ||
301 | } | ||