move UploadObjectAsset to simpleh..

master
UbitUmarov 2020-04-29 23:17:36 +01:00
parent 88a81a9ca4
commit 52f50d2035
1 changed files with 160 additions and 219 deletions

View File

@ -27,7 +27,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Specialized; using System.Net;
using System.Reflection; using System.Reflection;
using System.IO; using System.IO;
using System.Web; using System.Web;
@ -54,13 +54,12 @@ namespace OpenSim.Region.ClientStack.Linden
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadObjectAssetModule")] [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadObjectAssetModule")]
public class UploadObjectAssetModule : INonSharedRegionModule public class UploadObjectAssetModule : INonSharedRegionModule
{ {
private static readonly ILog m_log = private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_scene; private Scene m_scene;
#region Region Module interfaceBase Members #region Region Module interfaceBase Members
public Type ReplaceableInterface public Type ReplaceableInterface
{ {
get { return null; } get { return null; }
@ -68,7 +67,6 @@ namespace OpenSim.Region.ClientStack.Linden
public void Initialise(IConfigSource source) public void Initialise(IConfigSource source)
{ {
} }
public void AddRegion(Scene pScene) public void AddRegion(Scene pScene)
@ -78,14 +76,12 @@ namespace OpenSim.Region.ClientStack.Linden
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
{ {
m_scene.EventManager.OnRegisterCaps -= RegisterCaps; m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
m_scene = null; m_scene = null;
} }
public void RegionLoaded(Scene scene) public void RegionLoaded(Scene scene)
{ {
m_scene.EventManager.OnRegisterCaps += RegisterCaps; m_scene.EventManager.OnRegisterCaps += RegisterCaps;
} }
@ -94,8 +90,6 @@ namespace OpenSim.Region.ClientStack.Linden
#region Region Module interface #region Region Module interface
public void Close() { } public void Close() { }
public string Name { get { return "UploadObjectAssetModuleModule"; } } public string Name { get { return "UploadObjectAssetModuleModule"; } }
@ -103,29 +97,12 @@ namespace OpenSim.Region.ClientStack.Linden
public void RegisterCaps(UUID agentID, Caps caps) public void RegisterCaps(UUID agentID, Caps caps)
{ {
string capUrl = "/CAPS/" + UUID.Random() + "/"; caps.RegisterSimpleHandler("UploadObjectAsset",
new SimpleOSDMapHandler("POST","/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
{
ProcessAdd(httpRequest, httpResponse, map, agentID, caps);
}));
// m_log.Debug("[UPLOAD OBJECT ASSET MODULE]: /CAPS/" + capID); // m_log.Debug("[UPLOAD OBJECT ASSET MODULE]: /CAPS/" + capID);
caps.RegisterHandler(
"UploadObjectAsset",
new RestHTTPHandler(
"POST",
capUrl,
httpMethod => ProcessAdd(httpMethod, agentID, caps),
"UploadObjectAsset",
agentID.ToString()));
/*
caps.RegisterHandler("NewFileAgentInventoryVariablePrice",
new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>("POST",
"/CAPS/" + capID.ToString(),
delegate(LLSDAssetUploadRequest req)
{
return NewAgentInventoryRequest(req,agentID);
}));
*/
} }
#endregion #endregion
@ -135,26 +112,23 @@ namespace OpenSim.Region.ClientStack.Linden
/// Parses add request /// Parses add request
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <param name="AgentId"></param> /// <param name="agentID"></param>
/// <param name="cap"></param> /// <param name="cap"></param>
/// <returns></returns> /// <returns></returns>
public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap) public void ProcessAdd(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map, UUID agentID, Caps cap)
{ {
Hashtable responsedata = new Hashtable(); httpResponse.KeepAlive = false;
responsedata["int_response_code"] = 400; //501; //410; //404;
responsedata["content_type"] = "text/plain";
responsedata["keepalive"] = false;
responsedata["str_response_string"] = "Request wasn't what was expected";
ScenePresence avatar;
if (!m_scene.TryGetScenePresence(AgentId, out avatar)) if (!m_scene.TryGetScenePresence(agentID, out ScenePresence avatar))
return responsedata; {
httpResponse.StatusCode = (int)HttpStatusCode.Gone;
return;
}
OSDMap r = (OSDMap)OSDParser.Deserialize((string)request["requestbody"]);
UploadObjectAssetMessage message = new UploadObjectAssetMessage(); UploadObjectAssetMessage message = new UploadObjectAssetMessage();
try try
{ {
message.Deserialize(r); message.Deserialize(map);
} }
catch (Exception ex) catch (Exception ex)
@ -165,208 +139,175 @@ namespace OpenSim.Region.ClientStack.Linden
if (message == null) if (message == null)
{ {
responsedata["int_response_code"] = 400; //501; //410; //404; httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
responsedata["content_type"] = "text/plain"; return;
responsedata["keepalive"] = false;
responsedata["str_response_string"] =
"<llsd><map><key>error</key><string>Error parsing Object</string></map></llsd>";
return responsedata;
} }
Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation); try
Quaternion rot = Quaternion.Identity;
Vector3 rootpos = Vector3.Zero;
// Quaternion rootrot = Quaternion.Identity;
SceneObjectGroup rootGroup = null;
SceneObjectGroup[] allparts = new SceneObjectGroup[message.Objects.Length];
for (int i = 0; i < message.Objects.Length; i++)
{ {
UploadObjectAssetMessage.Object obj = message.Objects[i]; Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation);
PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); Quaternion rot = Quaternion.Identity;
Vector3 rootpos = Vector3.Zero;
if (i == 0) SceneObjectGroup rootGroup = null;
SceneObjectGroup[] allparts = new SceneObjectGroup[message.Objects.Length];
for (int i = 0; i < message.Objects.Length; i++)
{ {
rootpos = obj.Position; UploadObjectAssetMessage.Object obj = message.Objects[i];
// rootrot = obj.Rotation; PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();
}
// Combine the extraparams data into it's ugly blob again.... if (i == 0)
//int bytelength = 0; rootpos = obj.Position;
//for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
//{ for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
// bytelength += obj.ExtraParams[extparams].ExtraParamData.Length;
//}
//byte[] extraparams = new byte[bytelength];
//int position = 0;
//for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
//{
// Buffer.BlockCopy(obj.ExtraParams[extparams].ExtraParamData, 0, extraparams, position,
// obj.ExtraParams[extparams].ExtraParamData.Length);
//
// position += obj.ExtraParams[extparams].ExtraParamData.Length;
// }
//pbs.ExtraParams = extraparams;
for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
{
UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[extparams];
switch ((ushort)extraParam.Type)
{ {
case (ushort)ExtraParamType.Sculpt: UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[extparams];
Primitive.SculptData sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0); switch ((ushort)extraParam.Type)
{
case (ushort)ExtraParamType.Sculpt:
Primitive.SculptData sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0);
pbs.SculptEntry = true; pbs.SculptEntry = true;
pbs.SculptTexture = obj.SculptID; pbs.SculptTexture = obj.SculptID;
pbs.SculptType = (byte)sculpt.Type; pbs.SculptType = (byte)sculpt.Type;
break; break;
case (ushort)ExtraParamType.Flexible: case (ushort)ExtraParamType.Flexible:
Primitive.FlexibleData flex = new Primitive.FlexibleData(extraParam.ExtraParamData, 0); Primitive.FlexibleData flex = new Primitive.FlexibleData(extraParam.ExtraParamData, 0);
pbs.FlexiEntry = true; pbs.FlexiEntry = true;
pbs.FlexiDrag = flex.Drag; pbs.FlexiDrag = flex.Drag;
pbs.FlexiForceX = flex.Force.X; pbs.FlexiForceX = flex.Force.X;
pbs.FlexiForceY = flex.Force.Y; pbs.FlexiForceY = flex.Force.Y;
pbs.FlexiForceZ = flex.Force.Z; pbs.FlexiForceZ = flex.Force.Z;
pbs.FlexiGravity = flex.Gravity; pbs.FlexiGravity = flex.Gravity;
pbs.FlexiSoftness = flex.Softness; pbs.FlexiSoftness = flex.Softness;
pbs.FlexiTension = flex.Tension; pbs.FlexiTension = flex.Tension;
pbs.FlexiWind = flex.Wind; pbs.FlexiWind = flex.Wind;
break; break;
case (ushort)ExtraParamType.Light: case (ushort)ExtraParamType.Light:
Primitive.LightData light = new Primitive.LightData(extraParam.ExtraParamData, 0); Primitive.LightData light = new Primitive.LightData(extraParam.ExtraParamData, 0);
pbs.LightColorA = light.Color.A; pbs.LightColorA = light.Color.A;
pbs.LightColorB = light.Color.B; pbs.LightColorB = light.Color.B;
pbs.LightColorG = light.Color.G; pbs.LightColorG = light.Color.G;
pbs.LightColorR = light.Color.R; pbs.LightColorR = light.Color.R;
pbs.LightCutoff = light.Cutoff; pbs.LightCutoff = light.Cutoff;
pbs.LightEntry = true; pbs.LightEntry = true;
pbs.LightFalloff = light.Falloff; pbs.LightFalloff = light.Falloff;
pbs.LightIntensity = light.Intensity; pbs.LightIntensity = light.Intensity;
pbs.LightRadius = light.Radius; pbs.LightRadius = light.Radius;
break; break;
case 0x40: case 0x40:
pbs.ReadProjectionData(extraParam.ExtraParamData, 0); pbs.ReadProjectionData(extraParam.ExtraParamData, 0);
break; break;
}
} }
}
pbs.PathBegin = (ushort) obj.PathBegin; pbs.PathBegin = (ushort) obj.PathBegin;
pbs.PathCurve = (byte) obj.PathCurve; pbs.PathCurve = (byte) obj.PathCurve;
pbs.PathEnd = (ushort) obj.PathEnd; pbs.PathEnd = (ushort) obj.PathEnd;
pbs.PathRadiusOffset = (sbyte) obj.RadiusOffset; pbs.PathRadiusOffset = (sbyte) obj.RadiusOffset;
pbs.PathRevolutions = (byte) obj.Revolutions; pbs.PathRevolutions = (byte) obj.Revolutions;
pbs.PathScaleX = (byte) obj.ScaleX; pbs.PathScaleX = (byte) obj.ScaleX;
pbs.PathScaleY = (byte) obj.ScaleY; pbs.PathScaleY = (byte) obj.ScaleY;
pbs.PathShearX = (byte) obj.ShearX; pbs.PathShearX = (byte) obj.ShearX;
pbs.PathShearY = (byte) obj.ShearY; pbs.PathShearY = (byte) obj.ShearY;
pbs.PathSkew = (sbyte) obj.Skew; pbs.PathSkew = (sbyte) obj.Skew;
pbs.PathTaperX = (sbyte) obj.TaperX; pbs.PathTaperX = (sbyte) obj.TaperX;
pbs.PathTaperY = (sbyte) obj.TaperY; pbs.PathTaperY = (sbyte) obj.TaperY;
pbs.PathTwist = (sbyte) obj.Twist; pbs.PathTwist = (sbyte) obj.Twist;
pbs.PathTwistBegin = (sbyte) obj.TwistBegin; pbs.PathTwistBegin = (sbyte) obj.TwistBegin;
pbs.HollowShape = (HollowShape) obj.ProfileHollow; pbs.HollowShape = (HollowShape) obj.ProfileHollow;
pbs.PCode = (byte) PCode.Prim; pbs.PCode = (byte) PCode.Prim;
pbs.ProfileBegin = (ushort) obj.ProfileBegin; pbs.ProfileBegin = (ushort) obj.ProfileBegin;
pbs.ProfileCurve = (byte) obj.ProfileCurve; pbs.ProfileCurve = (byte) obj.ProfileCurve;
pbs.ProfileEnd = (ushort) obj.ProfileEnd; pbs.ProfileEnd = (ushort) obj.ProfileEnd;
pbs.Scale = obj.Scale; pbs.Scale = obj.Scale;
pbs.State = (byte) 0; pbs.State = (byte) 0;
pbs.LastAttachPoint = (byte) 0; pbs.LastAttachPoint = (byte) 0;
SceneObjectPart prim = new SceneObjectPart(); SceneObjectPart prim = new SceneObjectPart();
prim.UUID = UUID.Random(); prim.UUID = UUID.Random();
prim.CreatorID = AgentId; prim.CreatorID = agentID;
prim.OwnerID = AgentId; prim.OwnerID = agentID;
prim.GroupID = obj.GroupID; prim.GroupID = obj.GroupID;
prim.LastOwnerID = prim.OwnerID; prim.LastOwnerID = prim.OwnerID;
prim.RezzerID = AgentId; prim.RezzerID = agentID;
prim.CreationDate = Util.UnixTimeSinceEpoch(); prim.CreationDate = Util.UnixTimeSinceEpoch();
prim.Name = obj.Name; prim.Name = obj.Name;
prim.Description = ""; prim.Description = "";
prim.PayPrice[0] = -2; prim.PayPrice[0] = -2;
prim.PayPrice[1] = -2; prim.PayPrice[1] = -2;
prim.PayPrice[2] = -2; prim.PayPrice[2] = -2;
prim.PayPrice[3] = -2; prim.PayPrice[3] = -2;
prim.PayPrice[4] = -2; prim.PayPrice[4] = -2;
Primitive.TextureEntry tmp = Primitive.TextureEntry tmp =
new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f")); new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f"));
for (int j = 0; j < obj.Faces.Length; j++) for (int j = 0; j < obj.Faces.Length; j++)
{ {
UploadObjectAssetMessage.Object.Face face = obj.Faces[j]; UploadObjectAssetMessage.Object.Face face = obj.Faces[j];
Primitive.TextureEntryFace primFace = tmp.CreateFace((uint) j);
Primitive.TextureEntryFace primFace = tmp.CreateFace((uint) j); primFace.Bump = face.Bump;
primFace.RGBA = face.Color;
primFace.Fullbright = face.Fullbright;
primFace.Glow = face.Glow;
primFace.TextureID = face.ImageID;
primFace.Rotation = face.ImageRot;
primFace.MediaFlags = ((face.MediaFlags & 1) != 0);
primFace.Bump = face.Bump; primFace.OffsetU = face.OffsetS;
primFace.RGBA = face.Color; primFace.OffsetV = face.OffsetT;
primFace.Fullbright = face.Fullbright; primFace.RepeatU = face.ScaleS;
primFace.Glow = face.Glow; primFace.RepeatV = face.ScaleT;
primFace.TextureID = face.ImageID; primFace.TexMapType = (MappingType) (face.MediaFlags & 6);
primFace.Rotation = face.ImageRot; }
primFace.MediaFlags = ((face.MediaFlags & 1) != 0);
primFace.OffsetU = face.OffsetS; pbs.TextureEntry = tmp.GetBytes();
primFace.OffsetV = face.OffsetT; prim.Shape = pbs;
primFace.RepeatU = face.ScaleS; prim.Scale = obj.Scale;
primFace.RepeatV = face.ScaleT;
primFace.TexMapType = (MappingType) (face.MediaFlags & 6);
}
pbs.TextureEntry = tmp.GetBytes(); SceneObjectGroup grp = new SceneObjectGroup();
prim.Shape = pbs;
prim.Scale = obj.Scale;
SceneObjectGroup grp = new SceneObjectGroup(); grp.SetRootPart(prim);
prim.ParentID = 0;
if (i == 0)
grp.SetRootPart(prim); rootGroup = grp;
prim.ParentID = 0;
if (i == 0)
{
rootGroup = grp;
} grp.AttachToScene(m_scene);
grp.AttachToScene(m_scene);
grp.AbsolutePosition = obj.Position;
prim.RotationOffset = obj.Rotation;
// Required for linking
grp.RootPart.ClearUpdateSchedule();
if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos))
{
m_scene.AddSceneObject(grp);
grp.AbsolutePosition = obj.Position; grp.AbsolutePosition = obj.Position;
prim.RotationOffset = obj.Rotation;
// Required for linking
grp.RootPart.ClearUpdateSchedule();
if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos))
{
m_scene.AddSceneObject(grp);
grp.AbsolutePosition = obj.Position;
}
allparts[i] = grp;
} }
allparts[i] = grp; for (int j = 1; j < allparts.Length; j++)
{
// Required for linking
rootGroup.RootPart.ClearUpdateSchedule();
allparts[j].RootPart.ClearUpdateSchedule();
rootGroup.LinkToGroup(allparts[j]);
}
rootGroup.ScheduleGroupForFullAnimUpdate();
httpResponse.StatusCode = (int)HttpStatusCode.OK;
httpResponse.RawBuffer = Util.UTF8NBGetbytes(String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(allparts[0].LocalId)));
} }
catch{ }
for (int j = 1; j < allparts.Length; j++) httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
{
// Required for linking
rootGroup.RootPart.ClearUpdateSchedule();
allparts[j].RootPart.ClearUpdateSchedule();
rootGroup.LinkToGroup(allparts[j]);
}
rootGroup.ScheduleGroupForFullAnimUpdate();
pos
= m_scene.GetNewRezLocation(
Vector3.Zero, rootpos, UUID.Zero, rot, (byte)1, 1, true, allparts[0].GroupScale, false);
responsedata["int_response_code"] = 200; //501; //410; //404;
responsedata["content_type"] = "text/plain";
responsedata["keepalive"] = false;
responsedata["str_response_string"] = String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(allparts[0].LocalId));
return responsedata;
} }
private string ConvertUintToBytes(uint val) private string ConvertUintToBytes(uint val)