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.cs897
1 files changed, 751 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..8241e07 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);
552 779
553 Primitive.TextureEntry textureEntry 780 // compare and get updated information
554 = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
555 OSDMap inner_instance_list = (OSDMap)instance_list[i];
556 781
557 OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; 782 bool mismatchError = true;
558 for (uint face = 0; face < face_list.Count; face++) 783
784 while (mismatchError)
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;
593 813
594 textureEntry.FaceTextures[face] = f; 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 }
595 } 855 }
596 856
597 pbs.TextureEntry = textureEntry.GetBytes(); 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);
867 }
868
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);
888
598 889
599 AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, ""); 890 OSDArray face_list = (OSDArray)inner_instance_list["face_list"];
600 meshAsset.Data = mesh_list[i].AsBinary(); 891 for (uint face = 0; face < face_list.Count; face++)
601 m_assetService.Store(meshAsset); 892 {
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;
602 912
603 pbs.SculptEntry = true; 913 if (offsett != 0)
604 pbs.SculptTexture = meshAsset.FullID; 914 f.OffsetV = offsett;
605 pbs.SculptType = (byte)SculptType.Mesh;
606 pbs.SculptData = meshAsset.Data;
607 915
608 Vector3 position = inner_instance_list["position"].AsVector3(); 916 if (scales != 0)
609 Vector3 scale = inner_instance_list["scale"].AsVector3(); 917 f.RepeatU = scales;
610 Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); 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();
948
949 // for now viwers do send fixed defaults
950 // but this may change
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,49 @@ 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 prim.EveryoneMask = 0;
994 prim.GroupMask = 0;
631 995
632 SceneObjectPart prim 996 if (restrictPerms)
633 = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero); 997 {
998 prim.BaseMask = (uint)(PermissionMask.Move | PermissionMask.Modify);
999 prim.OwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify);
1000 prim.NextOwnerMask = 0;
1001 }
1002 else
1003 {
1004 prim.BaseMask = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1005 prim.OwnerMask = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1006 prim.NextOwnerMask = (uint)PermissionMask.Transfer;
1007 }
1008
1009 if(istest)
1010 prim.Description = "For testing only. Other uses are prohibited";
1011 else
1012 prim.Description = "";
634 1013
635 prim.Scale = scale; 1014 prim.Material = material;
636 //prim.OffsetPosition = position; 1015 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 1016
648// prim.BaseMask = (uint)base_mask; 1017// prim.BaseMask = (uint)base_mask;
649// prim.EveryoneMask = (uint)everyone_mask; 1018// prim.EveryoneMask = (uint)everyone_mask;
@@ -651,52 +1020,64 @@ namespace OpenSim.Region.ClientStack.Linden
651// prim.NextOwnerMask = (uint)next_owner_mask; 1020// prim.NextOwnerMask = (uint)next_owner_mask;
652// prim.OwnerMask = (uint)owner_mask; 1021// prim.OwnerMask = (uint)owner_mask;
653 1022
654 if (grp == null) 1023 if (grp == null)
655 grp = new SceneObjectGroup(prim); 1024 {
656 else 1025 grp = new SceneObjectGroup(prim);
657 grp.AddPart(prim); 1026 grp.LastOwnerID = creatorID;
658 } 1027 }
1028 else
1029 grp.AddPart(prim);
1030 }
659 1031
660 Vector3 rootPos = positions[0]; 1032 Vector3 rootPos = positions[0];
661 1033
662 if (grp.Parts.Length > 1) 1034 if (grp.Parts.Length > 1)
663 { 1035 {
664 // Fix first link number 1036 // Fix first link number
665 grp.RootPart.LinkNum++; 1037 grp.RootPart.LinkNum++;
666 1038
667 Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); 1039 Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]);
668 Quaternion tmprot; 1040 Quaternion tmprot;
669 Vector3 offset; 1041 Vector3 offset;
670 1042
671 // fix children rotations and positions 1043 // fix children rotations and positions
672 for (int i = 1; i < rotations.Count; i++) 1044 for (int i = 1; i < rotations.Count; i++)
673 { 1045 {
674 tmprot = rotations[i]; 1046 tmprot = rotations[i];
675 tmprot = rootRotConj * tmprot; 1047 tmprot = rootRotConj * tmprot;
1048
1049 grp.Parts[i].RotationOffset = tmprot;
676 1050
677 grp.Parts[i].RotationOffset = tmprot; 1051 offset = positions[i] - rootPos;
678 1052
679 offset = positions[i] - rootPos; 1053 offset *= rootRotConj;
1054 grp.Parts[i].OffsetPosition = offset;
1055 }
680 1056
681 offset *= rootRotConj; 1057 grp.AbsolutePosition = rootPos;
682 grp.Parts[i].OffsetPosition = offset; 1058 grp.UpdateGroupRotationR(rotations[0]);
1059 }
1060 else
1061 {
1062 grp.AbsolutePosition = rootPos;
1063 grp.UpdateGroupRotationR(rotations[0]);
683 } 1064 }
684 1065
685 grp.AbsolutePosition = rootPos; 1066 data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
686 grp.UpdateGroupRotationR(rotations[0]);
687 } 1067 }
688 else 1068
1069 else // not a mesh model
689 { 1070 {
690 grp.AbsolutePosition = rootPos; 1071 m_log.ErrorFormat("[CAPS Asset Upload] got unsuported assetType for object upload");
691 grp.UpdateGroupRotationR(rotations[0]); 1072 return;
692 } 1073 }
693
694 data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
695 } 1074 }
696 1075
697 AssetBase asset; 1076 AssetBase asset;
698 asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString()); 1077 asset = new AssetBase(assetID, assetName, assType, creatorIDstr);
699 asset.Data = data; 1078 asset.Data = data;
1079 if (istest)
1080 asset.Local = true;
700 if (AddNewAsset != null) 1081 if (AddNewAsset != null)
701 AddNewAsset(asset); 1082 AddNewAsset(asset);
702 else if (m_assetService != null) 1083 else if (m_assetService != null)
@@ -704,11 +1085,17 @@ namespace OpenSim.Region.ClientStack.Linden
704 1085
705 InventoryItemBase item = new InventoryItemBase(); 1086 InventoryItemBase item = new InventoryItemBase();
706 item.Owner = m_HostCapsObj.AgentID; 1087 item.Owner = m_HostCapsObj.AgentID;
707 item.CreatorId = m_HostCapsObj.AgentID.ToString(); 1088 item.CreatorId = creatorIDstr;
708 item.CreatorData = String.Empty; 1089 item.CreatorData = String.Empty;
709 item.ID = inventoryItem; 1090 item.ID = inventoryItem;
710 item.AssetID = asset.FullID; 1091 item.AssetID = asset.FullID;
711 item.Description = assetDescription; 1092 if (istest)
1093 {
1094 item.Description = "For testing only. Other uses are prohibited";
1095 item.Flags = (uint) (InventoryItemFlags.SharedSingleReference);
1096 }
1097 else
1098 item.Description = assetDescription;
712 item.Name = assetName; 1099 item.Name = assetName;
713 item.AssetType = assType; 1100 item.AssetType = assType;
714 item.InvType = inType; 1101 item.InvType = inType;
@@ -716,18 +1103,56 @@ namespace OpenSim.Region.ClientStack.Linden
716 1103
717 // If we set PermissionMask.All then when we rez the item the next permissions will replace the current 1104 // 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. 1105 // (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 1106
722 item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; 1107 if (restrictPerms)
723 item.EveryOnePermissions = 0; 1108 {
724 item.NextPermissions = (uint)PermissionMask.All; 1109 item.BasePermissions = (uint)(PermissionMask.Move | PermissionMask.Modify);
1110 item.CurrentPermissions = (uint)(PermissionMask.Move | PermissionMask.Modify);
1111 item.EveryOnePermissions = 0;
1112 item.NextPermissions = 0;
1113 }
1114 else
1115 {
1116 item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1117 item.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1118 item.EveryOnePermissions = 0;
1119 item.NextPermissions = (uint)PermissionMask.Transfer;
1120 }
1121
725 item.CreationDate = Util.UnixTimeSinceEpoch(); 1122 item.CreationDate = Util.UnixTimeSinceEpoch();
726 1123
1124 m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
1125
727 if (AddNewInventoryItem != null) 1126 if (AddNewInventoryItem != null)
728 { 1127 {
729 AddNewInventoryItem(m_HostCapsObj.AgentID, item); 1128 if (istest)
1129 {
1130 m_Scene.AddInventoryItem(client, item);
1131/*
1132 AddNewInventoryItem(m_HostCapsObj.AgentID, item, 0);
1133 if (client != null)
1134 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);
1135 */
1136 }
1137 else
1138 {
1139 AddNewInventoryItem(m_HostCapsObj.AgentID, item, (uint)cost);
1140// if (client != null)
1141// {
1142// // let users see anything.. i don't so far
1143// string str;
1144// if (cost > 0)
1145// // dont remember where is money unit name to put here
1146// str = "Upload complete. charged " + cost.ToString() + "$";
1147// else
1148// str = "Upload complete";
1149// client.SendAgentAlertMessage(str, true);
1150// }
1151 }
730 } 1152 }
1153
1154 lock (m_ModelCost)
1155 m_FileAgentInventoryState = FileAgentInventoryState.idle;
731 } 1156 }
732 1157
733 /// <summary> 1158 /// <summary>
@@ -920,6 +1345,120 @@ namespace OpenSim.Region.ClientStack.Linden
920 return response; 1345 return response;
921 } 1346 }
922 1347
1348 public string GetObjectCost(string request, string path,
1349 string param, IOSHttpRequest httpRequest,
1350 IOSHttpResponse httpResponse)
1351 {
1352 OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
1353 OSDMap resp = new OSDMap();
1354
1355 OSDArray object_ids = (OSDArray)req["object_ids"];
1356
1357 for (int i = 0; i < object_ids.Count; i++)
1358 {
1359 UUID uuid = object_ids[i].AsUUID();
1360
1361 SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid);
1362
1363 if (part != null)
1364 {
1365 SceneObjectGroup grp = part.ParentGroup;
1366 if (grp != null)
1367 {
1368 float linksetCost;
1369 float linksetPhysCost;
1370 float partCost;
1371 float partPhysCost;
1372
1373 grp.GetResourcesCosts(part, out linksetCost, out linksetPhysCost, out partCost, out partPhysCost);
1374
1375 OSDMap object_data = new OSDMap();
1376 object_data["linked_set_resource_cost"] = linksetCost;
1377 object_data["resource_cost"] = partCost;
1378 object_data["physics_cost"] = partPhysCost;
1379 object_data["linked_set_physics_cost"] = linksetPhysCost;
1380
1381 resp[uuid.ToString()] = object_data;
1382 }
1383 }
1384 }
1385
1386 string response = OSDParser.SerializeLLSDXmlString(resp);
1387 return response;
1388 }
1389
1390 public string ResourceCostSelected(string request, string path,
1391 string param, IOSHttpRequest httpRequest,
1392 IOSHttpResponse httpResponse)
1393 {
1394 OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
1395 OSDMap resp = new OSDMap();
1396
1397
1398 float phys=0;
1399 float stream=0;
1400 float simul=0;
1401
1402 if (req.ContainsKey("selected_roots"))
1403 {
1404 OSDArray object_ids = (OSDArray)req["selected_roots"];
1405
1406 // should go by SOG suming costs for all parts
1407 // ll v3 works ok with several objects select we get the list and adds ok
1408 // FS calls per object so results are wrong guess fs bug
1409 for (int i = 0; i < object_ids.Count; i++)
1410 {
1411 UUID uuid = object_ids[i].AsUUID();
1412 float Physc;
1413 float simulc;
1414 float streamc;
1415
1416 SceneObjectGroup grp = m_Scene.GetGroupByPrim(uuid);
1417 if (grp != null)
1418 {
1419 grp.GetSelectedCosts(out Physc, out streamc, out simulc);
1420 phys += Physc;
1421 stream += streamc;
1422 simul += simulc;
1423 }
1424 }
1425 }
1426 else if (req.ContainsKey("selected_prims"))
1427 {
1428 OSDArray object_ids = (OSDArray)req["selected_prims"];
1429
1430 // don't see in use in any of the 2 viewers
1431 // guess it should be for edit linked but... nothing
1432 // should go to SOP per part
1433 for (int i = 0; i < object_ids.Count; i++)
1434 {
1435 UUID uuid = object_ids[i].AsUUID();
1436
1437 SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid);
1438 if (part != null)
1439 {
1440 phys += part.PhysicsCost;
1441 stream += part.StreamingCost;
1442 simul += part.SimulationCost;
1443 }
1444 }
1445 }
1446
1447 if (simul != 0)
1448 {
1449 OSDMap object_data = new OSDMap();
1450
1451 object_data["physics"] = phys;
1452 object_data["streaming"] = stream;
1453 object_data["simulation"] = simul;
1454
1455 resp["selected"] = object_data;
1456 }
1457
1458 string response = OSDParser.SerializeLLSDXmlString(resp);
1459 return response;
1460 }
1461
923 public string UpdateAgentInformation(string request, string path, 1462 public string UpdateAgentInformation(string request, string path,
924 string param, IOSHttpRequest httpRequest, 1463 string param, IOSHttpRequest httpRequest,
925 IOSHttpResponse httpResponse) 1464 IOSHttpResponse httpResponse)
@@ -939,6 +1478,10 @@ namespace OpenSim.Region.ClientStack.Linden
939 1478
940 public class AssetUploader 1479 public class AssetUploader
941 { 1480 {
1481 private static readonly ILog m_log =
1482 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
1483
1484
942 public event UpLoadedAsset OnUpLoad; 1485 public event UpLoadedAsset OnUpLoad;
943 private UpLoadedAsset handlerUpLoad = null; 1486 private UpLoadedAsset handlerUpLoad = null;
944 1487
@@ -953,10 +1496,21 @@ namespace OpenSim.Region.ClientStack.Linden
953 1496
954 private string m_invType = String.Empty; 1497 private string m_invType = String.Empty;
955 private string m_assetType = String.Empty; 1498 private string m_assetType = String.Empty;
1499 private int m_cost;
1500 private string m_error = String.Empty;
1501
1502 private Timer m_timeoutTimer = new Timer();
1503 private UUID m_texturesFolder;
1504 private int m_nreqtextures;
1505 private int m_nreqmeshs;
1506 private int m_nreqinstances;
1507 private bool m_IsAtestUpload;
956 1508
957 public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, 1509 public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem,
958 UUID parentFolderID, string invType, string assetType, string path, 1510 UUID parentFolderID, string invType, string assetType, string path,
959 IHttpServer httpServer, bool dumpAssetsToFile) 1511 IHttpServer httpServer, bool dumpAssetsToFile,
1512 int totalCost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances,
1513 bool IsAtestUpload)
960 { 1514 {
961 m_assetName = assetName; 1515 m_assetName = assetName;
962 m_assetDes = description; 1516 m_assetDes = description;
@@ -968,6 +1522,18 @@ namespace OpenSim.Region.ClientStack.Linden
968 m_assetType = assetType; 1522 m_assetType = assetType;
969 m_invType = invType; 1523 m_invType = invType;
970 m_dumpAssetsToFile = dumpAssetsToFile; 1524 m_dumpAssetsToFile = dumpAssetsToFile;
1525 m_cost = totalCost;
1526
1527 m_texturesFolder = texturesFolder;
1528 m_nreqtextures = nreqtextures;
1529 m_nreqmeshs = nreqmeshs;
1530 m_nreqinstances = nreqinstances;
1531 m_IsAtestUpload = IsAtestUpload;
1532
1533 m_timeoutTimer.Elapsed += TimedOut;
1534 m_timeoutTimer.Interval = 120000;
1535 m_timeoutTimer.AutoReset = false;
1536 m_timeoutTimer.Start();
971 } 1537 }
972 1538
973 /// <summary> 1539 /// <summary>
@@ -982,12 +1548,14 @@ namespace OpenSim.Region.ClientStack.Linden
982 UUID inv = inventoryItemID; 1548 UUID inv = inventoryItemID;
983 string res = String.Empty; 1549 string res = String.Empty;
984 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); 1550 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
1551/*
985 uploadComplete.new_asset = newAssetID.ToString(); 1552 uploadComplete.new_asset = newAssetID.ToString();
986 uploadComplete.new_inventory_item = inv; 1553 uploadComplete.new_inventory_item = inv;
987 uploadComplete.state = "complete"; 1554 uploadComplete.state = "complete";
988 1555
989 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); 1556 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
990 1557*/
1558 m_timeoutTimer.Stop();
991 httpListener.RemoveStreamHandler("POST", uploaderPath); 1559 httpListener.RemoveStreamHandler("POST", uploaderPath);
992 1560
993 // TODO: probably make this a better set of extensions here 1561 // TODO: probably make this a better set of extensions here
@@ -1004,12 +1572,49 @@ namespace OpenSim.Region.ClientStack.Linden
1004 handlerUpLoad = OnUpLoad; 1572 handlerUpLoad = OnUpLoad;
1005 if (handlerUpLoad != null) 1573 if (handlerUpLoad != null)
1006 { 1574 {
1007 handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType); 1575 handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType,
1576 m_cost, m_texturesFolder, m_nreqtextures, m_nreqmeshs, m_nreqinstances, m_IsAtestUpload, ref m_error);
1577 }
1578 if (m_IsAtestUpload)
1579 {
1580 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
1581 resperror.message = "Upload SUCESSEFULL for testing purposes only. Other uses are prohibited. Item will not work after 48 hours or on other regions";
1582 resperror.identifier = inv;
1583
1584 uploadComplete.error = resperror;
1585 uploadComplete.state = "Upload4Testing";
1008 } 1586 }
1587 else
1588 {
1589 if (m_error == String.Empty)
1590 {
1591 uploadComplete.new_asset = newAssetID.ToString();
1592 uploadComplete.new_inventory_item = inv;
1593 // if (m_texturesFolder != UUID.Zero)
1594 // uploadComplete.new_texture_folder_id = m_texturesFolder;
1595 uploadComplete.state = "complete";
1596 }
1597 else
1598 {
1599 LLSDAssetUploadError resperror = new LLSDAssetUploadError();
1600 resperror.message = m_error;
1601 resperror.identifier = inv;
1009 1602
1603 uploadComplete.error = resperror;
1604 uploadComplete.state = "failed";
1605 }
1606 }
1607
1608 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
1010 return res; 1609 return res;
1011 } 1610 }
1012 1611
1612 private void TimedOut(object sender, ElapsedEventArgs args)
1613 {
1614 m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out mesh upload");
1615 httpListener.RemoveStreamHandler("POST", uploaderPath);
1616 }
1617
1013 ///Left this in and commented in case there are unforseen issues 1618 ///Left this in and commented in case there are unforseen issues
1014 //private void SaveAssetToFile(string filename, byte[] data) 1619 //private void SaveAssetToFile(string filename, byte[] data)
1015 //{ 1620 //{