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