aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs894
1 files changed, 748 insertions, 146 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
index a46c24a..59b9585 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Timers;
29using System.Collections; 30using System.Collections;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.IO; 32using System.IO;
@@ -54,14 +55,16 @@ using PermissionMask = OpenSim.Framework.PermissionMask;
54namespace OpenSim.Region.ClientStack.Linden 55namespace OpenSim.Region.ClientStack.Linden
55{ 56{
56 public delegate void UpLoadedAsset( 57 public delegate void UpLoadedAsset(
57 string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, 58 string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder,
58 byte[] data, string inventoryType, string assetType); 59 byte[] data, string inventoryType, string assetType,
60 int cost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
61 bool IsAtestUpload, ref string error);
59 62
60 public delegate UUID UpdateItem(UUID itemID, byte[] data); 63 public delegate UUID UpdateItem(UUID itemID, byte[] data);
61 64
62 public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); 65 public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors);
63 66
64 public delegate void NewInventoryItem(UUID userID, InventoryItemBase item); 67 public delegate void NewInventoryItem(UUID userID, InventoryItemBase item, uint cost);
65 68
66 public delegate void NewAsset(AssetBase asset); 69 public delegate void NewAsset(AssetBase asset);
67 70
@@ -87,6 +90,7 @@ namespace OpenSim.Region.ClientStack.Linden
87 90
88 private Scene m_Scene; 91 private Scene m_Scene;
89 private Caps m_HostCapsObj; 92 private Caps m_HostCapsObj;
93 private ModelCost m_ModelCost;
90 94
91 private static readonly string m_requestPath = "0000/"; 95 private static readonly string m_requestPath = "0000/";
92 // private static readonly string m_mapLayerPath = "0001/"; 96 // private static readonly string m_mapLayerPath = "0001/";
@@ -98,7 +102,8 @@ namespace OpenSim.Region.ClientStack.Linden
98 private static readonly string m_copyFromNotecardPath = "0007/"; 102 private static readonly string m_copyFromNotecardPath = "0007/";
99 // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule. 103 // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule.
100 private static readonly string m_getObjectPhysicsDataPath = "0101/"; 104 private static readonly string m_getObjectPhysicsDataPath = "0101/";
101 /* 0102 - 0103 RESERVED */ 105 private static readonly string m_getObjectCostPath = "0102/";
106 private static readonly string m_ResourceCostSelectedPath = "0103/";
102 private static readonly string m_UpdateAgentInformationPath = "0500/"; 107 private static readonly string m_UpdateAgentInformationPath = "0500/";
103 108
104 // These are callbacks which will be setup by the scene so that we can update scene data when we 109 // These are callbacks which will be setup by the scene so that we can update scene data when we
@@ -114,12 +119,50 @@ namespace OpenSim.Region.ClientStack.Linden
114 private IAssetService m_assetService; 119 private IAssetService m_assetService;
115 private bool m_dumpAssetsToFile = false; 120 private bool m_dumpAssetsToFile = false;
116 private string m_regionName; 121 private string m_regionName;
122
117 private int m_levelUpload = 0; 123 private int m_levelUpload = 0;
118 124
125 private bool m_enableFreeTestUpload = false; // allows "TEST-" prefix hack
126 private bool m_ForceFreeTestUpload = false; // forces all uploads to be test
127
128 private bool m_enableModelUploadTextureToInventory = false; // place uploaded textures also in inventory
129 // may not be visible till relog
130
131 private bool m_RestrictFreeTestUploadPerms = false; // reduces also the permitions. Needs a creator defined!!
132 private UUID m_testAssetsCreatorID = UUID.Zero;
133
134 private float m_PrimScaleMin = 0.001f;
135
136 private enum FileAgentInventoryState : int
137 {
138 idle = 0,
139 processRequest = 1,
140 waitUpload = 2,
141 processUpload = 3
142 }
143 private FileAgentInventoryState m_FileAgentInventoryState = FileAgentInventoryState.idle;
144
119 public BunchOfCaps(Scene scene, Caps caps) 145 public BunchOfCaps(Scene scene, Caps caps)
120 { 146 {
121 m_Scene = scene; 147 m_Scene = scene;
122 m_HostCapsObj = caps; 148 m_HostCapsObj = caps;
149
150 // create a model upload cost provider
151 m_ModelCost = new ModelCost();
152 // tell it about scene object limits
153 m_ModelCost.NonPhysicalPrimScaleMax = m_Scene.m_maxNonphys;
154 m_ModelCost.PhysicalPrimScaleMax = m_Scene.m_maxPhys;
155
156// m_ModelCost.ObjectLinkedPartsMax = ??
157// m_ModelCost.PrimScaleMin = ??
158
159 m_PrimScaleMin = m_ModelCost.PrimScaleMin;
160 float modelTextureUploadFactor = m_ModelCost.ModelTextureCostFactor;
161 float modelUploadFactor = m_ModelCost.ModelMeshCostFactor;
162 float modelMinUploadCostFactor = m_ModelCost.ModelMinCostFactor;
163 float modelPrimCreationCost = m_ModelCost.primCreationCost;
164 float modelMeshByteCost = m_ModelCost.bytecost;
165
123 IConfigSource config = m_Scene.Config; 166 IConfigSource config = m_Scene.Config;
124 if (config != null) 167 if (config != null)
125 { 168 {
@@ -134,6 +177,37 @@ namespace OpenSim.Region.ClientStack.Linden
134 { 177 {
135 m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); 178 m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures);
136 } 179 }
180 // economy for model upload
181 IConfig EconomyConfig = config.Configs["Economy"];
182 if (EconomyConfig != null)
183 {
184 modelUploadFactor = EconomyConfig.GetFloat("MeshModelUploadCostFactor", modelUploadFactor);
185 modelTextureUploadFactor = EconomyConfig.GetFloat("MeshModelUploadTextureCostFactor", modelTextureUploadFactor);
186 modelMinUploadCostFactor = EconomyConfig.GetFloat("MeshModelMinCostFactor", modelMinUploadCostFactor);
187 // next 2 are normalized so final cost is afected by modelUploadFactor above and normal cost
188 modelPrimCreationCost = EconomyConfig.GetFloat("ModelPrimCreationCost", modelPrimCreationCost);
189 modelMeshByteCost = EconomyConfig.GetFloat("ModelMeshByteCost", modelMeshByteCost);
190
191 m_enableModelUploadTextureToInventory = EconomyConfig.GetBoolean("MeshModelAllowTextureToInventory", m_enableModelUploadTextureToInventory);
192
193 m_RestrictFreeTestUploadPerms = EconomyConfig.GetBoolean("m_RestrictFreeTestUploadPerms", m_RestrictFreeTestUploadPerms);
194 m_enableFreeTestUpload = EconomyConfig.GetBoolean("AllowFreeTestUpload", m_enableFreeTestUpload);
195 m_ForceFreeTestUpload = EconomyConfig.GetBoolean("ForceFreeTestUpload", m_ForceFreeTestUpload);
196 string testcreator = EconomyConfig.GetString("TestAssetsCreatorID", "");
197 if (testcreator != "")
198 {
199 UUID id;
200 UUID.TryParse(testcreator, out id);
201 if (id != null)
202 m_testAssetsCreatorID = id;
203 }
204
205 m_ModelCost.ModelMeshCostFactor = modelUploadFactor;
206 m_ModelCost.ModelTextureCostFactor = modelTextureUploadFactor;
207 m_ModelCost.ModelMinCostFactor = modelMinUploadCostFactor;
208 m_ModelCost.primCreationCost = modelPrimCreationCost;
209 m_ModelCost.bytecost = modelMeshByteCost;
210 }
137 } 211 }
138 212
139 m_assetService = m_Scene.AssetService; 213 m_assetService = m_Scene.AssetService;
@@ -145,6 +219,8 @@ namespace OpenSim.Region.ClientStack.Linden
145 ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; 219 ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset;
146 TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; 220 TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset;
147 GetClient = m_Scene.SceneGraph.GetControllingClient; 221 GetClient = m_Scene.SceneGraph.GetControllingClient;
222
223 m_FileAgentInventoryState = FileAgentInventoryState.idle;
148 } 224 }
149 225
150 /// <summary> 226 /// <summary>
@@ -190,7 +266,6 @@ namespace OpenSim.Region.ClientStack.Linden
190 { 266 {
191 try 267 try
192 { 268 {
193 // I don't think this one works...
194 m_HostCapsObj.RegisterHandler( 269 m_HostCapsObj.RegisterHandler(
195 "NewFileAgentInventory", 270 "NewFileAgentInventory",
196 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( 271 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>(
@@ -209,6 +284,10 @@ namespace OpenSim.Region.ClientStack.Linden
209 m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); 284 m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req);
210 IRequestHandler getObjectPhysicsDataHandler = new RestStreamHandler("POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData); 285 IRequestHandler getObjectPhysicsDataHandler = new RestStreamHandler("POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData);
211 m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler); 286 m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler);
287 IRequestHandler getObjectCostHandler = new RestStreamHandler("POST", capsBase + m_getObjectCostPath, GetObjectCost);
288 m_HostCapsObj.RegisterHandler("GetObjectCost", getObjectCostHandler);
289 IRequestHandler ResourceCostSelectedHandler = new RestStreamHandler("POST", capsBase + m_ResourceCostSelectedPath, ResourceCostSelected);
290 m_HostCapsObj.RegisterHandler("ResourceCostSelected", ResourceCostSelectedHandler);
212 IRequestHandler UpdateAgentInformationHandler = new RestStreamHandler("POST", capsBase + m_UpdateAgentInformationPath, UpdateAgentInformation); 291 IRequestHandler UpdateAgentInformationHandler = new RestStreamHandler("POST", capsBase + m_UpdateAgentInformationPath, UpdateAgentInformation);
213 m_HostCapsObj.RegisterHandler("UpdateAgentInformation", UpdateAgentInformationHandler); 292 m_HostCapsObj.RegisterHandler("UpdateAgentInformation", UpdateAgentInformationHandler);
214 293
@@ -264,6 +343,9 @@ namespace OpenSim.Region.ClientStack.Linden
264 m_log.DebugFormat( 343 m_log.DebugFormat(
265 "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID); 344 "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID);
266 345
346 if (!m_HostCapsObj.WaitForActivation())
347 return string.Empty;
348
267 if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint)) 349 if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint))
268 { 350 {
269 m_log.WarnFormat( 351 m_log.WarnFormat(
@@ -404,62 +486,176 @@ namespace OpenSim.Region.ClientStack.Linden
404 //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); 486 //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString());
405 //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); 487 //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type);
406 488
489 // start by getting the client
490 IClientAPI client = null;
491 m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
492
493 // check current state so we only have one service at a time
494 lock (m_ModelCost)
495 {
496 switch (m_FileAgentInventoryState)
497 {
498 case FileAgentInventoryState.processRequest:
499 case FileAgentInventoryState.processUpload:
500 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
501 resperror.message = "Uploader busy processing previus request";
502 resperror.identifier = UUID.Zero;
503
504 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
505 errorResponse.uploader = "";
506 errorResponse.state = "error";
507 errorResponse.error = resperror;
508 return errorResponse;
509 break;
510 case FileAgentInventoryState.waitUpload:
511 // todo stop current uploader server
512 break;
513 case FileAgentInventoryState.idle:
514 default:
515 break;
516 }
517
518 m_FileAgentInventoryState = FileAgentInventoryState.processRequest;
519 }
520
521 int cost = 0;
522 int nreqtextures = 0;
523 int nreqmeshs= 0;
524 int nreqinstances = 0;
525 bool IsAtestUpload = false;
526
527 string assetName = llsdRequest.name;
528
529 LLSDAssetUploadResponseData meshcostdata = new LLSDAssetUploadResponseData();
530
407 if (llsdRequest.asset_type == "texture" || 531 if (llsdRequest.asset_type == "texture" ||
408 llsdRequest.asset_type == "animation" || 532 llsdRequest.asset_type == "animation" ||
533 llsdRequest.asset_type == "mesh" ||
409 llsdRequest.asset_type == "sound") 534 llsdRequest.asset_type == "sound")
410 { 535 {
411 ScenePresence avatar = null; 536 ScenePresence avatar = null;
412 IClientAPI client = null;
413 m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); 537 m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar);
414 538
415 // check user level 539 // check user level
416 if (avatar != null) 540 if (avatar != null)
417 { 541 {
418 client = avatar.ControllingClient;
419
420 if (avatar.UserLevel < m_levelUpload) 542 if (avatar.UserLevel < m_levelUpload)
421 { 543 {
422 if (client != null) 544 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
423 client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); 545 resperror.message = "Insufficient permissions to upload";
546 resperror.identifier = UUID.Zero;
424 547
425 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); 548 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
426 errorResponse.uploader = ""; 549 errorResponse.uploader = "";
427 errorResponse.state = "error"; 550 errorResponse.state = "error";
551 errorResponse.error = resperror;
552 lock (m_ModelCost)
553 m_FileAgentInventoryState = FileAgentInventoryState.idle;
428 return errorResponse; 554 return errorResponse;
429 } 555 }
430 } 556 }
431 557
432 // check funds 558 // check test upload and funds
433 if (client != null) 559 if (client != null)
434 { 560 {
435 IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); 561 IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>();
436 562
563 int baseCost = 0;
437 if (mm != null) 564 if (mm != null)
565 baseCost = mm.UploadCharge;
566
567 string warning = String.Empty;
568
569 if (llsdRequest.asset_type == "mesh")
438 { 570 {
439 if (!mm.UploadCovered(client.AgentId, mm.UploadCharge)) 571 string error;
572 int modelcost;
573
574 if (!m_ModelCost.MeshModelCost(llsdRequest.asset_resources, baseCost, out modelcost,
575 meshcostdata, out error, ref warning))
440 { 576 {
441 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); 577 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
578 resperror.message = error;
579 resperror.identifier = UUID.Zero;
442 580
443 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); 581 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
444 errorResponse.uploader = ""; 582 errorResponse.uploader = "";
445 errorResponse.state = "error"; 583 errorResponse.state = "error";
584 errorResponse.error = resperror;
585
586 lock (m_ModelCost)
587 m_FileAgentInventoryState = FileAgentInventoryState.idle;
446 return errorResponse; 588 return errorResponse;
447 } 589 }
590 cost = modelcost;
591 }
592 else
593 {
594 cost = baseCost;
595 }
596
597 if (cost > 0 && mm != null)
598 {
599 // check for test upload
600
601 if (m_ForceFreeTestUpload) // all are test
602 {
603 if (!(assetName.Length > 5 && assetName.StartsWith("TEST-"))) // has normal name lets change it
604 assetName = "TEST-" + assetName;
605
606 IsAtestUpload = true;
607 }
608
609 else if (m_enableFreeTestUpload) // only if prefixed with "TEST-"
610 {
611
612 IsAtestUpload = (assetName.Length > 5 && assetName.StartsWith("TEST-"));
613 }
614
615
616 if(IsAtestUpload) // let user know, still showing cost estimation
617 warning += "Upload will have no cost, for testing purposes only. Other uses are prohibited. Items will not work after 48 hours or on other regions";
618
619 // check funds
620 else
621 {
622 if (!mm.UploadCovered(client.AgentId, (int)cost))
623 {
624 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
625 resperror.message = "Insuficient funds";
626 resperror.identifier = UUID.Zero;
627
628 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
629 errorResponse.uploader = "";
630 errorResponse.state = "error";
631 errorResponse.error = resperror;
632 lock (m_ModelCost)
633 m_FileAgentInventoryState = FileAgentInventoryState.idle;
634 return errorResponse;
635 }
636 }
448 } 637 }
638
639 if (client != null && warning != String.Empty)
640 client.SendAgentAlertMessage(warning, true);
449 } 641 }
450 } 642 }
451 643
452 string assetName = llsdRequest.name;
453 string assetDes = llsdRequest.description; 644 string assetDes = llsdRequest.description;
454 string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; 645 string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
455 UUID newAsset = UUID.Random(); 646 UUID newAsset = UUID.Random();
456 UUID newInvItem = UUID.Random(); 647 UUID newInvItem = UUID.Random();
457 UUID parentFolder = llsdRequest.folder_id; 648 UUID parentFolder = llsdRequest.folder_id;
458 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); 649 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
650 UUID texturesFolder = UUID.Zero;
651
652 if(!IsAtestUpload && m_enableModelUploadTextureToInventory)
653 texturesFolder = llsdRequest.texture_folder_id;
459 654
460 AssetUploader uploader = 655 AssetUploader uploader =
461 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, 656 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
462 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); 657 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost,
658 texturesFolder, nreqtextures, nreqmeshs, nreqinstances, IsAtestUpload);
463 659
464 m_HostCapsObj.HttpListener.AddStreamHandler( 660 m_HostCapsObj.HttpListener.AddStreamHandler(
465 new BinaryStreamHandler( 661 new BinaryStreamHandler(
@@ -477,10 +673,22 @@ namespace OpenSim.Region.ClientStack.Linden
477 string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + 673 string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
478 uploaderPath; 674 uploaderPath;
479 675
676
480 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); 677 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
481 uploadResponse.uploader = uploaderURL; 678 uploadResponse.uploader = uploaderURL;
482 uploadResponse.state = "upload"; 679 uploadResponse.state = "upload";
680 uploadResponse.upload_price = (int)cost;
681
682 if (llsdRequest.asset_type == "mesh")
683 {
684 uploadResponse.data = meshcostdata;
685 }
686
483 uploader.OnUpLoad += UploadCompleteHandler; 687 uploader.OnUpLoad += UploadCompleteHandler;
688
689 lock (m_ModelCost)
690 m_FileAgentInventoryState = FileAgentInventoryState.waitUpload;
691
484 return uploadResponse; 692 return uploadResponse;
485 } 693 }
486 694
@@ -492,8 +700,14 @@ namespace OpenSim.Region.ClientStack.Linden
492 /// <param name="data"></param> 700 /// <param name="data"></param>
493 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, 701 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
494 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, 702 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
495 string assetType) 703 string assetType, int cost,
704 UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
705 bool IsAtestUpload, ref string error)
496 { 706 {
707
708 lock (m_ModelCost)
709 m_FileAgentInventoryState = FileAgentInventoryState.processUpload;
710
497 m_log.DebugFormat( 711 m_log.DebugFormat(
498 "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", 712 "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}",
499 assetID, inventoryItem, inventoryType, assetType); 713 assetID, inventoryItem, inventoryType, assetType);
@@ -501,117 +715,247 @@ namespace OpenSim.Region.ClientStack.Linden
501 sbyte assType = 0; 715 sbyte assType = 0;
502 sbyte inType = 0; 716 sbyte inType = 0;
503 717
718 IClientAPI client = null;
719
720 UUID owner_id = m_HostCapsObj.AgentID;
721 UUID creatorID;
722
723 bool istest = IsAtestUpload && m_enableFreeTestUpload && (cost > 0);
724
725 bool restrictPerms = m_RestrictFreeTestUploadPerms && istest;
726
727 if (istest && m_testAssetsCreatorID != UUID.Zero)
728 creatorID = m_testAssetsCreatorID;
729 else
730 creatorID = owner_id;
731
732 string creatorIDstr = creatorID.ToString();
733
734 IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>();
735 if (mm != null)
736 {
737 // make sure client still has enougth credit
738 if (!mm.UploadCovered(m_HostCapsObj.AgentID, (int)cost))
739 {
740 error = "Insufficient funds.";
741 return;
742 }
743 }
744
745 // strings to types
504 if (inventoryType == "sound") 746 if (inventoryType == "sound")
505 { 747 {
506 inType = 1; 748 inType = (sbyte)InventoryType.Sound;
507 assType = 1; 749 assType = (sbyte)AssetType.Sound;
508 } 750 }
509 else if (inventoryType == "animation") 751 else if (inventoryType == "animation")
510 { 752 {
511 inType = 19; 753 inType = (sbyte)InventoryType.Animation;
512 assType = 20; 754 assType = (sbyte)AssetType.Animation;
513 } 755 }
514 else if (inventoryType == "wearable") 756 else if (inventoryType == "wearable")
515 { 757 {
516 inType = 18; 758 inType = (sbyte)InventoryType.Wearable;
517 switch (assetType) 759 switch (assetType)
518 { 760 {
519 case "bodypart": 761 case "bodypart":
520 assType = 13; 762 assType = (sbyte)AssetType.Bodypart;
521 break; 763 break;
522 case "clothing": 764 case "clothing":
523 assType = 5; 765 assType = (sbyte)AssetType.Clothing;
524 break; 766 break;
525 } 767 }
526 } 768 }
527 else if (inventoryType == "object") 769 else if (inventoryType == "object")
528 { 770 {
529 inType = (sbyte)InventoryType.Object; 771 if (assetType == "mesh") // this code for now is for mesh models uploads only
530 assType = (sbyte)AssetType.Object;
531
532 List<Vector3> positions = new List<Vector3>();
533 List<Quaternion> rotations = new List<Quaternion>();
534 OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data);
535 OSDArray instance_list = (OSDArray)request["instance_list"];
536 OSDArray mesh_list = (OSDArray)request["mesh_list"];
537 OSDArray texture_list = (OSDArray)request["texture_list"];
538 SceneObjectGroup grp = null;
539
540 List<UUID> textures = new List<UUID>();
541 for (int i = 0; i < texture_list.Count; i++)
542 { 772 {
543 AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, ""); 773 inType = (sbyte)InventoryType.Object;
544 textureAsset.Data = texture_list[i].AsBinary(); 774 assType = (sbyte)AssetType.Object;
545 m_assetService.Store(textureAsset);
546 textures.Add(textureAsset.FullID);
547 }
548 775
549 for (int i = 0; i < mesh_list.Count; i++) 776 List<Vector3> positions = new List<Vector3>();
550 { 777 List<Quaternion> rotations = new List<Quaternion>();
551 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); 778 OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data);
779
780 // compare and get updated information
552 781
553 Primitive.TextureEntry textureEntry 782 bool mismatchError = true;
554 = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
555 OSDMap inner_instance_list = (OSDMap)instance_list[i];
556 783
557 OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; 784 while (mismatchError)
558 for (uint face = 0; face < face_list.Count; face++)
559 { 785 {
560 OSDMap faceMap = (OSDMap)face_list[(int)face]; 786 mismatchError = false;
561 Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face); 787 }
562 if(faceMap.ContainsKey("fullbright"))
563 f.Fullbright = faceMap["fullbright"].AsBoolean();
564 if (faceMap.ContainsKey ("diffuse_color"))
565 f.RGBA = faceMap["diffuse_color"].AsColor4();
566 788
567 int textureNum = faceMap["image"].AsInteger(); 789 if (mismatchError)
568 float imagerot = faceMap["imagerot"].AsInteger(); 790 {
569 float offsets = (float)faceMap["offsets"].AsReal(); 791 error = "Upload and fee estimation information don't match";
570 float offsett = (float)faceMap["offsett"].AsReal(); 792 lock (m_ModelCost)
571 float scales = (float)faceMap["scales"].AsReal(); 793 m_FileAgentInventoryState = FileAgentInventoryState.idle;
572 float scalet = (float)faceMap["scalet"].AsReal();
573 794
574 if(imagerot != 0) 795 return;
575 f.Rotation = imagerot; 796 }
576 797
577 if(offsets != 0) 798 OSDArray instance_list = (OSDArray)request["instance_list"];
578 f.OffsetU = offsets; 799 OSDArray mesh_list = (OSDArray)request["mesh_list"];
800 OSDArray texture_list = (OSDArray)request["texture_list"];
801 SceneObjectGroup grp = null;
579 802
580 if (offsett != 0) 803 // create and store texture assets
581 f.OffsetV = offsett; 804 bool doTextInv = (!istest && m_enableModelUploadTextureToInventory &&
805 texturesFolder != UUID.Zero);
582 806
583 if (scales != 0)
584 f.RepeatU = scales;
585 807
586 if (scalet != 0) 808 List<UUID> textures = new List<UUID>();
587 f.RepeatV = scalet;
588 809
589 if (textures.Count > textureNum) 810
590 f.TextureID = textures[textureNum]; 811 if (doTextInv)
591 else 812 m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
592 f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE; 813
814 if(client == null) // don't put textures in inventory if there is no client
815 doTextInv = false;
816
817 for (int i = 0; i < texture_list.Count; i++)
818 {
819 AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, creatorIDstr);
820 textureAsset.Data = texture_list[i].AsBinary();
821 if (istest)
822 textureAsset.Local = true;
823 m_assetService.Store(textureAsset);
824 textures.Add(textureAsset.FullID);
825
826 if (doTextInv)
827 {
828 string name = assetName;
829 if (name.Length > 25)
830 name = name.Substring(0, 24);
831 name += "_Texture#" + i.ToString();
832 InventoryItemBase texitem = new InventoryItemBase();
833 texitem.Owner = m_HostCapsObj.AgentID;
834 texitem.CreatorId = creatorIDstr;
835 texitem.CreatorData = String.Empty;
836 texitem.ID = UUID.Random();
837 texitem.AssetID = textureAsset.FullID;
838 texitem.Description = "mesh model texture";
839 texitem.Name = name;
840 texitem.AssetType = (int)AssetType.Texture;
841 texitem.InvType = (int)InventoryType.Texture;
842 texitem.Folder = texturesFolder;
843
844 texitem.CurrentPermissions
845 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export);
846
847 texitem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
848 texitem.EveryOnePermissions = 0;
849 texitem.NextPermissions = (uint)PermissionMask.All;
850 texitem.CreationDate = Util.UnixTimeSinceEpoch();
851
852 m_Scene.AddInventoryItem(client, texitem);
853 texitem = null;
854 }
855 }
593 856
594 textureEntry.FaceTextures[face] = f; 857 // create and store meshs assets
858 List<UUID> meshAssets = new List<UUID>();
859 for (int i = 0; i < mesh_list.Count; i++)
860 {
861 AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, creatorIDstr);
862 meshAsset.Data = mesh_list[i].AsBinary();
863 if (istest)
864 meshAsset.Local = true;
865 m_assetService.Store(meshAsset);
866 meshAssets.Add(meshAsset.FullID);
595 } 867 }
596 868
597 pbs.TextureEntry = textureEntry.GetBytes(); 869 int skipedMeshs = 0;
870 // build prims from instances
871 for (int i = 0; i < instance_list.Count; i++)
872 {
873 OSDMap inner_instance_list = (OSDMap)instance_list[i];
874
875 // skip prims that are 2 small
876 Vector3 scale = inner_instance_list["scale"].AsVector3();
877
878 if (scale.X < m_PrimScaleMin || scale.Y < m_PrimScaleMin || scale.Z < m_PrimScaleMin)
879 {
880 skipedMeshs++;
881 continue;
882 }
883
884 PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();
885
886 Primitive.TextureEntry textureEntry
887 = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
598 888
599 AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, "");
600 meshAsset.Data = mesh_list[i].AsBinary();
601 m_assetService.Store(meshAsset);
602 889
603 pbs.SculptEntry = true; 890 OSDArray face_list = (OSDArray)inner_instance_list["face_list"];
604 pbs.SculptTexture = meshAsset.FullID; 891 for (uint face = 0; face < face_list.Count; face++)
605 pbs.SculptType = (byte)SculptType.Mesh; 892 {
606 pbs.SculptData = meshAsset.Data; 893 OSDMap faceMap = (OSDMap)face_list[(int)face];
894 Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face);
895 if (faceMap.ContainsKey("fullbright"))
896 f.Fullbright = faceMap["fullbright"].AsBoolean();
897 if (faceMap.ContainsKey("diffuse_color"))
898 f.RGBA = faceMap["diffuse_color"].AsColor4();
899
900 int textureNum = faceMap["image"].AsInteger();
901 float imagerot = faceMap["imagerot"].AsInteger();
902 float offsets = (float)faceMap["offsets"].AsReal();
903 float offsett = (float)faceMap["offsett"].AsReal();
904 float scales = (float)faceMap["scales"].AsReal();
905 float scalet = (float)faceMap["scalet"].AsReal();
906
907 if (imagerot != 0)
908 f.Rotation = imagerot;
909
910 if (offsets != 0)
911 f.OffsetU = offsets;
912
913 if (offsett != 0)
914 f.OffsetV = offsett;
915
916 if (scales != 0)
917 f.RepeatU = scales;
918
919 if (scalet != 0)
920 f.RepeatV = scalet;
921
922 if (textures.Count > textureNum)
923 f.TextureID = textures[textureNum];
924 else
925 f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE;
926
927 textureEntry.FaceTextures[face] = f;
928 }
929
930 pbs.TextureEntry = textureEntry.GetBytes();
931
932 bool hasmesh = false;
933 if (inner_instance_list.ContainsKey("mesh")) // seems to happen always but ...
934 {
935 int meshindx = inner_instance_list["mesh"].AsInteger();
936 if (meshAssets.Count > meshindx)
937 {
938 pbs.SculptEntry = true;
939 pbs.SculptType = (byte)SculptType.Mesh;
940 pbs.SculptTexture = meshAssets[meshindx]; // actual asset UUID after meshs suport introduction
941 // data will be requested from asset on rez (i hope)
942 hasmesh = true;
943 }
944 }
945
946 Vector3 position = inner_instance_list["position"].AsVector3();
947 Quaternion rotation = inner_instance_list["rotation"].AsQuaternion();
607 948
608 Vector3 position = inner_instance_list["position"].AsVector3(); 949 // for now viwers do send fixed defaults
609 Vector3 scale = inner_instance_list["scale"].AsVector3(); 950 // but this may change
610 Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); 951// int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
952 byte physicsShapeType = (byte)PhysShapeType.prim; // default for mesh is simple convex
953 if(hasmesh)
954 physicsShapeType = (byte) PhysShapeType.convex; // default for mesh is simple convex
955// int material = inner_instance_list["material"].AsInteger();
956 byte material = (byte)Material.Wood;
611 957
612// no longer used - begin ------------------------ 958// no longer used - begin ------------------------
613// int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
614// int material = inner_instance_list["material"].AsInteger();
615// int mesh = inner_instance_list["mesh"].AsInteger(); 959// int mesh = inner_instance_list["mesh"].AsInteger();
616 960
617// OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; 961// OSDMap permissions = (OSDMap)inner_instance_list["permissions"];
@@ -626,24 +970,42 @@ namespace OpenSim.Region.ClientStack.Linden
626// UUID owner_id = permissions["owner_id"].AsUUID(); 970// UUID owner_id = permissions["owner_id"].AsUUID();
627// int owner_mask = permissions["owner_mask"].AsInteger(); 971// int owner_mask = permissions["owner_mask"].AsInteger();
628// no longer used - end ------------------------ 972// no longer used - end ------------------------
973
974
975 SceneObjectPart prim
976 = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero);
977
978 prim.Scale = scale;
979 rotations.Add(rotation);
980 positions.Add(position);
981 prim.UUID = UUID.Random();
982 prim.CreatorID = creatorID;
983 prim.OwnerID = owner_id;
984 prim.GroupID = UUID.Zero;
985 prim.LastOwnerID = creatorID;
986 prim.CreationDate = Util.UnixTimeSinceEpoch();
987
988 if (grp == null)
989 prim.Name = assetName;
990 else
991 prim.Name = assetName + "#" + i.ToString();
629 992
630 UUID owner_id = m_HostCapsObj.AgentID; 993 if (restrictPerms)
994 {
995 prim.BaseMask = (uint)(PermissionMask.Move | PermissionMask.Modify);
996 prim.EveryoneMask = 0;
997 prim.GroupMask = 0;
998 prim.NextOwnerMask = 0;
999 prim.OwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify);
1000 }
631 1001
632 SceneObjectPart prim 1002 if(istest)
633 = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero); 1003 prim.Description = "For testing only. Other uses are prohibited";
1004 else
1005 prim.Description = "";
634 1006
635 prim.Scale = scale; 1007 prim.Material = material;
636 //prim.OffsetPosition = position; 1008 prim.PhysicsShapeType = physicsShapeType;
637 rotations.Add(rotation);
638 positions.Add(position);
639 prim.UUID = UUID.Random();
640 prim.CreatorID = owner_id;
641 prim.OwnerID = owner_id;
642 prim.GroupID = UUID.Zero;
643 prim.LastOwnerID = prim.OwnerID;
644 prim.CreationDate = Util.UnixTimeSinceEpoch();
645 prim.Name = assetName;
646 prim.Description = "";
647 1009
648// prim.BaseMask = (uint)base_mask; 1010// prim.BaseMask = (uint)base_mask;
649// prim.EveryoneMask = (uint)everyone_mask; 1011// prim.EveryoneMask = (uint)everyone_mask;
@@ -651,52 +1013,64 @@ namespace OpenSim.Region.ClientStack.Linden
651// prim.NextOwnerMask = (uint)next_owner_mask; 1013// prim.NextOwnerMask = (uint)next_owner_mask;
652// prim.OwnerMask = (uint)owner_mask; 1014// prim.OwnerMask = (uint)owner_mask;
653 1015
654 if (grp == null) 1016 if (grp == null)
655 grp = new SceneObjectGroup(prim); 1017 {
656 else 1018 grp = new SceneObjectGroup(prim);
657 grp.AddPart(prim); 1019 grp.LastOwnerID = creatorID;
658 } 1020 }
1021 else
1022 grp.AddPart(prim);
1023 }
659 1024
660 Vector3 rootPos = positions[0]; 1025 Vector3 rootPos = positions[0];
661 1026
662 if (grp.Parts.Length > 1) 1027 if (grp.Parts.Length > 1)
663 { 1028 {
664 // Fix first link number 1029 // Fix first link number
665 grp.RootPart.LinkNum++; 1030 grp.RootPart.LinkNum++;
666 1031
667 Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); 1032 Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]);
668 Quaternion tmprot; 1033 Quaternion tmprot;
669 Vector3 offset; 1034 Vector3 offset;
670 1035
671 // fix children rotations and positions 1036 // fix children rotations and positions
672 for (int i = 1; i < rotations.Count; i++) 1037 for (int i = 1; i < rotations.Count; i++)
673 { 1038 {
674 tmprot = rotations[i]; 1039 tmprot = rotations[i];
675 tmprot = rootRotConj * tmprot; 1040 tmprot = rootRotConj * tmprot;
676 1041
677 grp.Parts[i].RotationOffset = tmprot; 1042 grp.Parts[i].RotationOffset = tmprot;
678 1043
679 offset = positions[i] - rootPos; 1044 offset = positions[i] - rootPos;
1045
1046 offset *= rootRotConj;
1047 grp.Parts[i].OffsetPosition = offset;
1048 }
680 1049
681 offset *= rootRotConj; 1050 grp.AbsolutePosition = rootPos;
682 grp.Parts[i].OffsetPosition = offset; 1051 grp.UpdateGroupRotationR(rotations[0]);
1052 }
1053 else
1054 {
1055 grp.AbsolutePosition = rootPos;
1056 grp.UpdateGroupRotationR(rotations[0]);
683 } 1057 }
684 1058
685 grp.AbsolutePosition = rootPos; 1059 data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
686 grp.UpdateGroupRotationR(rotations[0]);
687 } 1060 }
688 else 1061
1062 else // not a mesh model
689 { 1063 {
690 grp.AbsolutePosition = rootPos; 1064 m_log.ErrorFormat("[CAPS Asset Upload] got unsuported assetType for object upload");
691 grp.UpdateGroupRotationR(rotations[0]); 1065 return;
692 } 1066 }
693
694 data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
695 } 1067 }
696 1068
697 AssetBase asset; 1069 AssetBase asset;
698 asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString()); 1070 asset = new AssetBase(assetID, assetName, assType, creatorIDstr);
699 asset.Data = data; 1071 asset.Data = data;
1072 if (istest)
1073 asset.Local = true;
700 if (AddNewAsset != null) 1074 if (AddNewAsset != null)
701 AddNewAsset(asset); 1075 AddNewAsset(asset);
702 else if (m_assetService != null) 1076 else if (m_assetService != null)
@@ -704,11 +1078,17 @@ namespace OpenSim.Region.ClientStack.Linden
704 1078
705 InventoryItemBase item = new InventoryItemBase(); 1079 InventoryItemBase item = new InventoryItemBase();
706 item.Owner = m_HostCapsObj.AgentID; 1080 item.Owner = m_HostCapsObj.AgentID;
707 item.CreatorId = m_HostCapsObj.AgentID.ToString(); 1081 item.CreatorId = creatorIDstr;
708 item.CreatorData = String.Empty; 1082 item.CreatorData = String.Empty;
709 item.ID = inventoryItem; 1083 item.ID = inventoryItem;
710 item.AssetID = asset.FullID; 1084 item.AssetID = asset.FullID;
711 item.Description = assetDescription; 1085 if (istest)
1086 {
1087 item.Description = "For testing only. Other uses are prohibited";
1088 item.Flags = (uint) (InventoryItemFlags.SharedSingleReference);
1089 }
1090 else
1091 item.Description = assetDescription;
712 item.Name = assetName; 1092 item.Name = assetName;
713 item.AssetType = assType; 1093 item.AssetType = assType;
714 item.InvType = inType; 1094 item.InvType = inType;
@@ -716,18 +1096,60 @@ namespace OpenSim.Region.ClientStack.Linden
716 1096
717 // If we set PermissionMask.All then when we rez the item the next permissions will replace the current 1097 // If we set PermissionMask.All then when we rez the item the next permissions will replace the current
718 // (owner) permissions. This becomes a problem if next permissions are changed. 1098 // (owner) permissions. This becomes a problem if next permissions are changed.
719 item.CurrentPermissions
720 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export);
721 1099
722 item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; 1100 if (restrictPerms)
723 item.EveryOnePermissions = 0; 1101 {
724 item.NextPermissions = (uint)PermissionMask.All; 1102 item.CurrentPermissions
1103 = (uint)(PermissionMask.Move | PermissionMask.Modify);
1104
1105 item.BasePermissions = (uint)(PermissionMask.Move | PermissionMask.Modify);
1106 item.EveryOnePermissions = 0;
1107 item.NextPermissions = 0;
1108 }
1109 else
1110 {
1111 item.CurrentPermissions
1112 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export);
1113
1114 item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1115 item.EveryOnePermissions = 0;
1116 item.NextPermissions = (uint)PermissionMask.All;
1117 }
1118
725 item.CreationDate = Util.UnixTimeSinceEpoch(); 1119 item.CreationDate = Util.UnixTimeSinceEpoch();
726 1120
1121 m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
1122
727 if (AddNewInventoryItem != null) 1123 if (AddNewInventoryItem != null)
728 { 1124 {
729 AddNewInventoryItem(m_HostCapsObj.AgentID, item); 1125 if (istest)
1126 {
1127 m_Scene.AddInventoryItem(client, item);
1128/*
1129 AddNewInventoryItem(m_HostCapsObj.AgentID, item, 0);
1130 if (client != null)
1131 client.SendAgentAlertMessage("Upload will have no cost, for personal test purposes only. Other uses are forbiden. Items may not work on a another region" , true);
1132 */
1133 }
1134 else
1135 {
1136 AddNewInventoryItem(m_HostCapsObj.AgentID, item, (uint)cost);
1137// if (client != null)
1138// {
1139// // let users see anything.. i don't so far
1140// string str;
1141// if (cost > 0)
1142// // dont remember where is money unit name to put here
1143// str = "Upload complete. charged " + cost.ToString() + "$";
1144// else
1145// str = "Upload complete";
1146// client.SendAgentAlertMessage(str, true);
1147// }
1148 }
730 } 1149 }
1150
1151 lock (m_ModelCost)
1152 m_FileAgentInventoryState = FileAgentInventoryState.idle;
731 } 1153 }
732 1154
733 /// <summary> 1155 /// <summary>
@@ -920,6 +1342,120 @@ namespace OpenSim.Region.ClientStack.Linden
920 return response; 1342 return response;
921 } 1343 }
922 1344
1345 public string GetObjectCost(string request, string path,
1346 string param, IOSHttpRequest httpRequest,
1347 IOSHttpResponse httpResponse)
1348 {
1349 OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
1350 OSDMap resp = new OSDMap();
1351
1352 OSDArray object_ids = (OSDArray)req["object_ids"];
1353
1354 for (int i = 0; i < object_ids.Count; i++)
1355 {
1356 UUID uuid = object_ids[i].AsUUID();
1357
1358 SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid);
1359
1360 if (part != null)
1361 {
1362 SceneObjectGroup grp = part.ParentGroup;
1363 if (grp != null)
1364 {
1365 float linksetCost;
1366 float linksetPhysCost;
1367 float partCost;
1368 float partPhysCost;
1369
1370 grp.GetResourcesCosts(part, out linksetCost, out linksetPhysCost, out partCost, out partPhysCost);
1371
1372 OSDMap object_data = new OSDMap();
1373 object_data["linked_set_resource_cost"] = linksetCost;
1374 object_data["resource_cost"] = partCost;
1375 object_data["physics_cost"] = partPhysCost;
1376 object_data["linked_set_physics_cost"] = linksetPhysCost;
1377
1378 resp[uuid.ToString()] = object_data;
1379 }
1380 }
1381 }
1382
1383 string response = OSDParser.SerializeLLSDXmlString(resp);
1384 return response;
1385 }
1386
1387 public string ResourceCostSelected(string request, string path,
1388 string param, IOSHttpRequest httpRequest,
1389 IOSHttpResponse httpResponse)
1390 {
1391 OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
1392 OSDMap resp = new OSDMap();
1393
1394
1395 float phys=0;
1396 float stream=0;
1397 float simul=0;
1398
1399 if (req.ContainsKey("selected_roots"))
1400 {
1401 OSDArray object_ids = (OSDArray)req["selected_roots"];
1402
1403 // should go by SOG suming costs for all parts
1404 // ll v3 works ok with several objects select we get the list and adds ok
1405 // FS calls per object so results are wrong guess fs bug
1406 for (int i = 0; i < object_ids.Count; i++)
1407 {
1408 UUID uuid = object_ids[i].AsUUID();
1409 float Physc;
1410 float simulc;
1411 float streamc;
1412
1413 SceneObjectGroup grp = m_Scene.GetGroupByPrim(uuid);
1414 if (grp != null)
1415 {
1416 grp.GetSelectedCosts(out Physc, out streamc, out simulc);
1417 phys += Physc;
1418 stream += streamc;
1419 simul += simulc;
1420 }
1421 }
1422 }
1423 else if (req.ContainsKey("selected_prims"))
1424 {
1425 OSDArray object_ids = (OSDArray)req["selected_prims"];
1426
1427 // don't see in use in any of the 2 viewers
1428 // guess it should be for edit linked but... nothing
1429 // should go to SOP per part
1430 for (int i = 0; i < object_ids.Count; i++)
1431 {
1432 UUID uuid = object_ids[i].AsUUID();
1433
1434 SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid);
1435 if (part != null)
1436 {
1437 phys += part.PhysicsCost;
1438 stream += part.StreamingCost;
1439 simul += part.SimulationCost;
1440 }
1441 }
1442 }
1443
1444 if (simul != 0)
1445 {
1446 OSDMap object_data = new OSDMap();
1447
1448 object_data["physics"] = phys;
1449 object_data["streaming"] = stream;
1450 object_data["simulation"] = simul;
1451
1452 resp["selected"] = object_data;
1453 }
1454
1455 string response = OSDParser.SerializeLLSDXmlString(resp);
1456 return response;
1457 }
1458
923 public string UpdateAgentInformation(string request, string path, 1459 public string UpdateAgentInformation(string request, string path,
924 string param, IOSHttpRequest httpRequest, 1460 string param, IOSHttpRequest httpRequest,
925 IOSHttpResponse httpResponse) 1461 IOSHttpResponse httpResponse)
@@ -939,6 +1475,10 @@ namespace OpenSim.Region.ClientStack.Linden
939 1475
940 public class AssetUploader 1476 public class AssetUploader
941 { 1477 {
1478 private static readonly ILog m_log =
1479 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
1480
1481
942 public event UpLoadedAsset OnUpLoad; 1482 public event UpLoadedAsset OnUpLoad;
943 private UpLoadedAsset handlerUpLoad = null; 1483 private UpLoadedAsset handlerUpLoad = null;
944 1484
@@ -953,10 +1493,21 @@ namespace OpenSim.Region.ClientStack.Linden
953 1493
954 private string m_invType = String.Empty; 1494 private string m_invType = String.Empty;
955 private string m_assetType = String.Empty; 1495 private string m_assetType = String.Empty;
1496 private int m_cost;
1497 private string m_error = String.Empty;
1498
1499 private Timer m_timeoutTimer = new Timer();
1500 private UUID m_texturesFolder;
1501 private int m_nreqtextures;
1502 private int m_nreqmeshs;
1503 private int m_nreqinstances;
1504 private bool m_IsAtestUpload;
956 1505
957 public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, 1506 public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem,
958 UUID parentFolderID, string invType, string assetType, string path, 1507 UUID parentFolderID, string invType, string assetType, string path,
959 IHttpServer httpServer, bool dumpAssetsToFile) 1508 IHttpServer httpServer, bool dumpAssetsToFile,
1509 int totalCost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
1510 bool IsAtestUpload)
960 { 1511 {
961 m_assetName = assetName; 1512 m_assetName = assetName;
962 m_assetDes = description; 1513 m_assetDes = description;
@@ -968,6 +1519,18 @@ namespace OpenSim.Region.ClientStack.Linden
968 m_assetType = assetType; 1519 m_assetType = assetType;
969 m_invType = invType; 1520 m_invType = invType;
970 m_dumpAssetsToFile = dumpAssetsToFile; 1521 m_dumpAssetsToFile = dumpAssetsToFile;
1522 m_cost = totalCost;
1523
1524 m_texturesFolder = texturesFolder;
1525 m_nreqtextures = nreqtextures;
1526 m_nreqmeshs = nreqmeshs;
1527 m_nreqinstances = nreqinstances;
1528 m_IsAtestUpload = IsAtestUpload;
1529
1530 m_timeoutTimer.Elapsed += TimedOut;
1531 m_timeoutTimer.Interval = 120000;
1532 m_timeoutTimer.AutoReset = false;
1533 m_timeoutTimer.Start();
971 } 1534 }
972 1535
973 /// <summary> 1536 /// <summary>
@@ -982,12 +1545,14 @@ namespace OpenSim.Region.ClientStack.Linden
982 UUID inv = inventoryItemID; 1545 UUID inv = inventoryItemID;
983 string res = String.Empty; 1546 string res = String.Empty;
984 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); 1547 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
1548/*
985 uploadComplete.new_asset = newAssetID.ToString(); 1549 uploadComplete.new_asset = newAssetID.ToString();
986 uploadComplete.new_inventory_item = inv; 1550 uploadComplete.new_inventory_item = inv;
987 uploadComplete.state = "complete"; 1551 uploadComplete.state = "complete";
988 1552
989 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); 1553 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
990 1554*/
1555 m_timeoutTimer.Stop();
991 httpListener.RemoveStreamHandler("POST", uploaderPath); 1556 httpListener.RemoveStreamHandler("POST", uploaderPath);
992 1557
993 // TODO: probably make this a better set of extensions here 1558 // TODO: probably make this a better set of extensions here
@@ -1004,12 +1569,49 @@ namespace OpenSim.Region.ClientStack.Linden
1004 handlerUpLoad = OnUpLoad; 1569 handlerUpLoad = OnUpLoad;
1005 if (handlerUpLoad != null) 1570 if (handlerUpLoad != null)
1006 { 1571 {
1007 handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType); 1572 handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType,
1573 m_cost, m_texturesFolder, m_nreqtextures, m_nreqmeshs, m_nreqinstances, m_IsAtestUpload, ref m_error);
1574 }
1575 if (m_IsAtestUpload)
1576 {
1577 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
1578 resperror.message = "Upload SUCESSEFULL for testing purposes only. Other uses are prohibited. Item will not work after 48 hours or on other regions";
1579 resperror.identifier = inv;
1580
1581 uploadComplete.error = resperror;
1582 uploadComplete.state = "Upload4Testing";
1008 } 1583 }
1584 else
1585 {
1586 if (m_error == String.Empty)
1587 {
1588 uploadComplete.new_asset = newAssetID.ToString();
1589 uploadComplete.new_inventory_item = inv;
1590 // if (m_texturesFolder != UUID.Zero)
1591 // uploadComplete.new_texture_folder_id = m_texturesFolder;
1592 uploadComplete.state = "complete";
1593 }
1594 else
1595 {
1596 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
1597 resperror.message = m_error;
1598 resperror.identifier = inv;
1009 1599
1600 uploadComplete.error = resperror;
1601 uploadComplete.state = "failed";
1602 }
1603 }
1604
1605 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
1010 return res; 1606 return res;
1011 } 1607 }
1012 1608
1609 private void TimedOut(object sender, ElapsedEventArgs args)
1610 {
1611 m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out mesh upload");
1612 httpListener.RemoveStreamHandler("POST", uploaderPath);
1613 }
1614
1013 ///Left this in and commented in case there are unforseen issues 1615 ///Left this in and commented in case there are unforseen issues
1014 //private void SaveAssetToFile(string filename, byte[] data) 1616 //private void SaveAssetToFile(string filename, byte[] data)
1015 //{ 1617 //{