29 using System.Collections;
30 using System.Collections.Specialized;
31 using System.Reflection;
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;
49 using OpenSim.Framework.Capabilities;
52 namespace OpenSim.
Region.ClientStack.Linden
54 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"UploadObjectAssetModule")]
57 private static readonly ILog m_log =
58 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 private Scene m_scene;
61 #region Region Module interfaceBase Members
64 public Type ReplaceableInterface
82 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
89 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
95 #region Region Module interface
101 public string Name {
get {
return "UploadObjectAssetModuleModule"; } }
106 UUID capID = UUID.Random();
109 caps.RegisterHandler(
113 "/CAPS/OA/" + capID +
"/",
114 httpMethod => ProcessAdd(httpMethod, agentID, caps),
116 agentID.ToString()));
143 Hashtable responsedata =
new Hashtable();
144 responsedata[
"int_response_code"] = 400;
145 responsedata[
"content_type"] =
"text/plain";
146 responsedata[
"keepalive"] =
false;
147 responsedata[
"str_response_string"] =
"Request wasn't what was expected";
150 if (!m_scene.TryGetScenePresence(AgentId, out avatar))
153 OSDMap r = (
OSDMap)OSDParser.Deserialize((
string)request[
"requestbody"]);
154 UploadObjectAssetMessage message =
new UploadObjectAssetMessage();
157 message.Deserialize(r);
162 m_log.Error(
"[UPLOAD OBJECT ASSET MODULE]: Error deserializing message " + ex.ToString());
168 responsedata[
"int_response_code"] = 400;
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>";
177 Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation);
178 Quaternion rot = Quaternion.Identity;
179 Vector3 rootpos = Vector3.Zero;
184 for (
int i = 0; i < message.Objects.Length; i++)
186 UploadObjectAssetMessage.Object obj = message.Objects[i];
191 rootpos = obj.Position;
215 for (
int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
217 UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[extparams];
218 switch ((ushort)extraParam.Type)
220 case (ushort)ExtraParamType.Sculpt:
221 Primitive.SculptData sculpt =
new Primitive.SculptData(extraParam.ExtraParamData, 0);
223 pbs.SculptEntry =
true;
225 pbs.SculptTexture = obj.SculptID;
226 pbs.SculptType = (byte)sculpt.Type;
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;
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;
254 pbs.ReadProjectionData(extraParam.ExtraParamData, 0);
259 pbs.PathBegin = (ushort) obj.PathBegin;
261 pbs.PathEnd = (ushort) obj.PathEnd;
263 pbs.PathRevolutions = (byte) obj.Revolutions;
265 pbs.PathScaleY = (byte) obj.ScaleY;
267 pbs.PathShearY = (byte) obj.ShearY;
269 pbs.PathTaperX = (sbyte) obj.TaperX;
271 pbs.PathTwist = (sbyte) obj.Twist;
274 pbs.
PCode = (byte) PCode.Prim;
275 pbs.ProfileBegin = (ushort) obj.ProfileBegin;
277 pbs.ProfileEnd = (ushort) obj.ProfileEnd;
278 pbs.
Scale = obj.Scale;
279 pbs.
State = (byte) 0;
280 pbs.LastAttachPoint = (byte) 0;
282 prim.UUID = UUID.Random();
283 prim.CreatorID = AgentId;
284 prim.OwnerID = AgentId;
285 prim.GroupID = obj.GroupID;
286 prim.LastOwnerID = prim.OwnerID;
287 prim.CreationDate = Util.UnixTimeSinceEpoch();
288 prim.Name = obj.Name;
289 prim.Description =
"";
291 prim.PayPrice[0] = -2;
292 prim.PayPrice[1] = -2;
293 prim.PayPrice[2] = -2;
294 prim.PayPrice[3] = -2;
295 prim.PayPrice[4] = -2;
296 Primitive.TextureEntry tmp =
297 new Primitive.TextureEntry(UUID.Parse(
"89556747-24cb-43ed-920b-47caed15465f"));
299 for (
int j = 0; j < obj.Faces.Length; j++)
301 UploadObjectAssetMessage.Object.Face face = obj.Faces[j];
303 Primitive.TextureEntryFace primFace = tmp.CreateFace((uint) j);
305 primFace.Bump = face.Bump;
306 primFace.RGBA = face.Color;
307 primFace.Fullbright = face.Fullbright;
308 primFace.Glow = face.Glow;
309 primFace.TextureID = face.ImageID;
310 primFace.Rotation = face.ImageRot;
311 primFace.MediaFlags = ((face.MediaFlags & 1) != 0);
313 primFace.OffsetU = face.OffsetS;
314 primFace.OffsetV = face.OffsetT;
315 primFace.RepeatU = face.ScaleS;
316 primFace.RepeatV = face.ScaleT;
317 primFace.TexMapType = (MappingType) (face.MediaFlags & 6);
320 pbs.TextureEntry = tmp.GetBytes();
322 prim.Scale = obj.Scale;
326 grp.SetRootPart(prim);
333 grp.AttachToScene(m_scene);
334 grp.AbsolutePosition = obj.Position;
335 prim.RotationOffset = obj.Rotation;
338 grp.RootPart.ClearUpdateSchedule();
340 if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos))
342 m_scene.AddSceneObject(grp);
343 grp.AbsolutePosition = obj.Position;
349 for (
int j = 1; j < allparts.Length; j++)
352 rootGroup.RootPart.ClearUpdateSchedule();
353 allparts[j].RootPart.ClearUpdateSchedule();
354 rootGroup.LinkToGroup(allparts[j]);
357 rootGroup.ScheduleGroupForFullUpdate();
359 = m_scene.GetNewRezLocation(
360 Vector3.Zero, rootpos, UUID.Zero, rot, (byte)1, 1,
true, allparts[0].GroupScale,
false);
362 responsedata[
"int_response_code"] = 200;
363 responsedata[
"content_type"] =
"text/plain";
364 responsedata[
"keepalive"] =
false;
365 responsedata[
"str_response_string"] = String.Format(
"<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(allparts[0].LocalId));
370 private string ConvertUintToBytes(uint val)
372 byte[] resultbytes = Utils.UIntToBytes(val);
373 if (BitConverter.IsLittleEndian)
374 Array.Reverse(resultbytes);
375 return String.Format(
"<binary encoding=\"base64\">{0}</binary>", Convert.ToBase64String(resultbytes));
void RegisterCaps(UUID agentID, Caps caps)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap)
Parses add request
OpenMetaverse.StructuredData.OSDMap OSDMap
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
OpenMetaverse.StructuredData.OSD OSD
OpenMetaverse.ExtraParamType ExtraParamType
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
OpenSim.Framework.Capabilities.Caps Caps
void AddRegion(Scene pScene)
This is called whenever a Scene is added. For shared modules, this can happen several times...