diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 891 |
1 files changed, 745 insertions, 146 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 1af61db..d7d4708 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 | ||
28 | using System; | 28 | using System; |
29 | using System.Timers; | ||
29 | using System.Collections; | 30 | using System.Collections; |
30 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
31 | using System.IO; | 32 | using System.IO; |
@@ -53,14 +54,16 @@ using OSDMap = OpenMetaverse.StructuredData.OSDMap; | |||
53 | namespace OpenSim.Region.ClientStack.Linden | 54 | namespace 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/"; |
@@ -97,7 +101,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
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. |
99 | private static readonly string m_getObjectPhysicsDataPath = "0101/"; | 103 | private static readonly string m_getObjectPhysicsDataPath = "0101/"; |
100 | /* 0102 - 0103 RESERVED */ | 104 | private static readonly string m_getObjectCostPath = "0102/"; |
105 | private static readonly string m_ResourceCostSelectedPath = "0103/"; | ||
101 | private static readonly string m_UpdateAgentInformationPath = "0500/"; | 106 | private static readonly string m_UpdateAgentInformationPath = "0500/"; |
102 | 107 | ||
103 | // 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 |
@@ -113,12 +118,50 @@ namespace OpenSim.Region.ClientStack.Linden | |||
113 | private IAssetService m_assetService; | 118 | private IAssetService m_assetService; |
114 | private bool m_dumpAssetsToFile = false; | 119 | private bool m_dumpAssetsToFile = false; |
115 | private string m_regionName; | 120 | private string m_regionName; |
121 | |||
116 | private int m_levelUpload = 0; | 122 | private int m_levelUpload = 0; |
117 | 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 | |||
118 | public BunchOfCaps(Scene scene, Caps caps) | 144 | public BunchOfCaps(Scene scene, Caps caps) |
119 | { | 145 | { |
120 | m_Scene = scene; | 146 | m_Scene = scene; |
121 | 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 | |||
122 | IConfigSource config = m_Scene.Config; | 165 | IConfigSource config = m_Scene.Config; |
123 | if (config != null) | 166 | if (config != null) |
124 | { | 167 | { |
@@ -133,6 +176,37 @@ namespace OpenSim.Region.ClientStack.Linden | |||
133 | { | 176 | { |
134 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | 177 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); |
135 | } | 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 | } | ||
136 | } | 210 | } |
137 | 211 | ||
138 | m_assetService = m_Scene.AssetService; | 212 | m_assetService = m_Scene.AssetService; |
@@ -144,6 +218,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
144 | ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; | 218 | ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; |
145 | TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; | 219 | TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; |
146 | GetClient = m_Scene.SceneGraph.GetControllingClient; | 220 | GetClient = m_Scene.SceneGraph.GetControllingClient; |
221 | |||
222 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
147 | } | 223 | } |
148 | 224 | ||
149 | /// <summary> | 225 | /// <summary> |
@@ -189,7 +265,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
189 | { | 265 | { |
190 | try | 266 | try |
191 | { | 267 | { |
192 | // I don't think this one works... | ||
193 | m_HostCapsObj.RegisterHandler( | 268 | m_HostCapsObj.RegisterHandler( |
194 | "NewFileAgentInventory", | 269 | "NewFileAgentInventory", |
195 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( | 270 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( |
@@ -208,6 +283,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
208 | m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); | 283 | m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); |
209 | IRequestHandler getObjectPhysicsDataHandler = new RestStreamHandler("POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData); | 284 | IRequestHandler getObjectPhysicsDataHandler = new RestStreamHandler("POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData); |
210 | m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler); | 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); | ||
211 | IRequestHandler UpdateAgentInformationHandler = new RestStreamHandler("POST", capsBase + m_UpdateAgentInformationPath, UpdateAgentInformation); | 290 | IRequestHandler UpdateAgentInformationHandler = new RestStreamHandler("POST", capsBase + m_UpdateAgentInformationPath, UpdateAgentInformation); |
212 | m_HostCapsObj.RegisterHandler("UpdateAgentInformation", UpdateAgentInformationHandler); | 291 | m_HostCapsObj.RegisterHandler("UpdateAgentInformation", UpdateAgentInformationHandler); |
213 | 292 | ||
@@ -392,62 +471,176 @@ namespace OpenSim.Region.ClientStack.Linden | |||
392 | //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); | 471 | //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); |
393 | //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); |
394 | 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 | |||
395 | if (llsdRequest.asset_type == "texture" || | 516 | if (llsdRequest.asset_type == "texture" || |
396 | llsdRequest.asset_type == "animation" || | 517 | llsdRequest.asset_type == "animation" || |
518 | llsdRequest.asset_type == "mesh" || | ||
397 | llsdRequest.asset_type == "sound") | 519 | llsdRequest.asset_type == "sound") |
398 | { | 520 | { |
399 | ScenePresence avatar = null; | 521 | ScenePresence avatar = null; |
400 | IClientAPI client = null; | ||
401 | m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); | 522 | m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); |
402 | 523 | ||
403 | // check user level | 524 | // check user level |
404 | if (avatar != null) | 525 | if (avatar != null) |
405 | { | 526 | { |
406 | client = avatar.ControllingClient; | ||
407 | |||
408 | if (avatar.UserLevel < m_levelUpload) | 527 | if (avatar.UserLevel < m_levelUpload) |
409 | { | 528 | { |
410 | if (client != null) | 529 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); |
411 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); | 530 | resperror.message = "Insufficient permissions to upload"; |
531 | resperror.identifier = UUID.Zero; | ||
412 | 532 | ||
413 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | 533 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); |
414 | errorResponse.uploader = ""; | 534 | errorResponse.uploader = ""; |
415 | errorResponse.state = "error"; | 535 | errorResponse.state = "error"; |
536 | errorResponse.error = resperror; | ||
537 | lock (m_ModelCost) | ||
538 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
416 | return errorResponse; | 539 | return errorResponse; |
417 | } | 540 | } |
418 | } | 541 | } |
419 | 542 | ||
420 | // check funds | 543 | // check test upload and funds |
421 | if (client != null) | 544 | if (client != null) |
422 | { | 545 | { |
423 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); | 546 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); |
424 | 547 | ||
548 | int baseCost = 0; | ||
425 | if (mm != null) | 549 | if (mm != null) |
550 | baseCost = mm.UploadCharge; | ||
551 | |||
552 | string warning = String.Empty; | ||
553 | |||
554 | if (llsdRequest.asset_type == "mesh") | ||
426 | { | 555 | { |
427 | 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)) | ||
428 | { | 561 | { |
429 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | 562 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); |
563 | resperror.message = error; | ||
564 | resperror.identifier = UUID.Zero; | ||
430 | 565 | ||
431 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | 566 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); |
432 | errorResponse.uploader = ""; | 567 | errorResponse.uploader = ""; |
433 | errorResponse.state = "error"; | 568 | errorResponse.state = "error"; |
569 | errorResponse.error = resperror; | ||
570 | |||
571 | lock (m_ModelCost) | ||
572 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
434 | return errorResponse; | 573 | return errorResponse; |
435 | } | 574 | } |
575 | cost = modelcost; | ||
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 | } | ||
436 | } | 622 | } |
623 | |||
624 | if (client != null && warning != String.Empty) | ||
625 | client.SendAgentAlertMessage(warning, true); | ||
437 | } | 626 | } |
438 | } | 627 | } |
439 | 628 | ||
440 | string assetName = llsdRequest.name; | ||
441 | string assetDes = llsdRequest.description; | 629 | string assetDes = llsdRequest.description; |
442 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; | 630 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; |
443 | UUID newAsset = UUID.Random(); | 631 | UUID newAsset = UUID.Random(); |
444 | UUID newInvItem = UUID.Random(); | 632 | UUID newInvItem = UUID.Random(); |
445 | UUID parentFolder = llsdRequest.folder_id; | 633 | UUID parentFolder = llsdRequest.folder_id; |
446 | 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; | ||
447 | 639 | ||
448 | AssetUploader uploader = | 640 | AssetUploader uploader = |
449 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | 641 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, |
450 | 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); | ||
451 | 644 | ||
452 | m_HostCapsObj.HttpListener.AddStreamHandler( | 645 | m_HostCapsObj.HttpListener.AddStreamHandler( |
453 | new BinaryStreamHandler( | 646 | new BinaryStreamHandler( |
@@ -465,10 +658,22 @@ namespace OpenSim.Region.ClientStack.Linden | |||
465 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + | 658 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + |
466 | uploaderPath; | 659 | uploaderPath; |
467 | 660 | ||
661 | |||
468 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | 662 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); |
469 | uploadResponse.uploader = uploaderURL; | 663 | uploadResponse.uploader = uploaderURL; |
470 | 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 | |||
471 | uploader.OnUpLoad += UploadCompleteHandler; | 672 | uploader.OnUpLoad += UploadCompleteHandler; |
673 | |||
674 | lock (m_ModelCost) | ||
675 | m_FileAgentInventoryState = FileAgentInventoryState.waitUpload; | ||
676 | |||
472 | return uploadResponse; | 677 | return uploadResponse; |
473 | } | 678 | } |
474 | 679 | ||
@@ -480,8 +685,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
480 | /// <param name="data"></param> | 685 | /// <param name="data"></param> |
481 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, | 686 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, |
482 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, | 687 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, |
483 | string assetType) | 688 | string assetType, int cost, |
689 | UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, | ||
690 | bool IsAtestUpload, ref string error) | ||
484 | { | 691 | { |
692 | |||
693 | lock (m_ModelCost) | ||
694 | m_FileAgentInventoryState = FileAgentInventoryState.processUpload; | ||
695 | |||
485 | m_log.DebugFormat( | 696 | m_log.DebugFormat( |
486 | "[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}", |
487 | assetID, inventoryItem, inventoryType, assetType); | 698 | assetID, inventoryItem, inventoryType, assetType); |
@@ -489,117 +700,247 @@ namespace OpenSim.Region.ClientStack.Linden | |||
489 | sbyte assType = 0; | 700 | sbyte assType = 0; |
490 | sbyte inType = 0; | 701 | sbyte inType = 0; |
491 | 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 | ||
492 | if (inventoryType == "sound") | 731 | if (inventoryType == "sound") |
493 | { | 732 | { |
494 | inType = 1; | 733 | inType = (sbyte)InventoryType.Sound; |
495 | assType = 1; | 734 | assType = (sbyte)AssetType.Sound; |
496 | } | 735 | } |
497 | else if (inventoryType == "animation") | 736 | else if (inventoryType == "animation") |
498 | { | 737 | { |
499 | inType = 19; | 738 | inType = (sbyte)InventoryType.Animation; |
500 | assType = 20; | 739 | assType = (sbyte)AssetType.Animation; |
501 | } | 740 | } |
502 | else if (inventoryType == "wearable") | 741 | else if (inventoryType == "wearable") |
503 | { | 742 | { |
504 | inType = 18; | 743 | inType = (sbyte)InventoryType.Wearable; |
505 | switch (assetType) | 744 | switch (assetType) |
506 | { | 745 | { |
507 | case "bodypart": | 746 | case "bodypart": |
508 | assType = 13; | 747 | assType = (sbyte)AssetType.Bodypart; |
509 | break; | 748 | break; |
510 | case "clothing": | 749 | case "clothing": |
511 | assType = 5; | 750 | assType = (sbyte)AssetType.Clothing; |
512 | break; | 751 | break; |
513 | } | 752 | } |
514 | } | 753 | } |
515 | else if (inventoryType == "object") | 754 | else if (inventoryType == "object") |
516 | { | 755 | { |
517 | inType = (sbyte)InventoryType.Object; | 756 | if (assetType == "mesh") // this code for now is for mesh models uploads only |
518 | assType = (sbyte)AssetType.Object; | ||
519 | |||
520 | List<Vector3> positions = new List<Vector3>(); | ||
521 | List<Quaternion> rotations = new List<Quaternion>(); | ||
522 | OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data); | ||
523 | OSDArray instance_list = (OSDArray)request["instance_list"]; | ||
524 | OSDArray mesh_list = (OSDArray)request["mesh_list"]; | ||
525 | OSDArray texture_list = (OSDArray)request["texture_list"]; | ||
526 | SceneObjectGroup grp = null; | ||
527 | |||
528 | List<UUID> textures = new List<UUID>(); | ||
529 | for (int i = 0; i < texture_list.Count; i++) | ||
530 | { | 757 | { |
531 | AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, ""); | 758 | inType = (sbyte)InventoryType.Object; |
532 | textureAsset.Data = texture_list[i].AsBinary(); | 759 | assType = (sbyte)AssetType.Object; |
533 | m_assetService.Store(textureAsset); | ||
534 | textures.Add(textureAsset.FullID); | ||
535 | } | ||
536 | 760 | ||
537 | for (int i = 0; i < mesh_list.Count; i++) | 761 | List<Vector3> positions = new List<Vector3>(); |
538 | { | 762 | List<Quaternion> rotations = new List<Quaternion>(); |
539 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); | 763 | OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data); |
540 | 764 | ||
541 | Primitive.TextureEntry textureEntry | 765 | // compare and get updated information |
542 | = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE); | ||
543 | OSDMap inner_instance_list = (OSDMap)instance_list[i]; | ||
544 | 766 | ||
545 | OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; | 767 | bool mismatchError = true; |
546 | for (uint face = 0; face < face_list.Count; face++) | 768 | |
769 | while (mismatchError) | ||
547 | { | 770 | { |
548 | OSDMap faceMap = (OSDMap)face_list[(int)face]; | 771 | mismatchError = false; |
549 | Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face); | 772 | } |
550 | if(faceMap.ContainsKey("fullbright")) | ||
551 | f.Fullbright = faceMap["fullbright"].AsBoolean(); | ||
552 | if (faceMap.ContainsKey ("diffuse_color")) | ||
553 | f.RGBA = faceMap["diffuse_color"].AsColor4(); | ||
554 | 773 | ||
555 | int textureNum = faceMap["image"].AsInteger(); | 774 | if (mismatchError) |
556 | float imagerot = faceMap["imagerot"].AsInteger(); | 775 | { |
557 | float offsets = (float)faceMap["offsets"].AsReal(); | 776 | error = "Upload and fee estimation information don't match"; |
558 | float offsett = (float)faceMap["offsett"].AsReal(); | 777 | lock (m_ModelCost) |
559 | float scales = (float)faceMap["scales"].AsReal(); | 778 | m_FileAgentInventoryState = FileAgentInventoryState.idle; |
560 | float scalet = (float)faceMap["scalet"].AsReal(); | ||
561 | 779 | ||
562 | if(imagerot != 0) | 780 | return; |
563 | f.Rotation = imagerot; | 781 | } |
564 | 782 | ||
565 | if(offsets != 0) | 783 | OSDArray instance_list = (OSDArray)request["instance_list"]; |
566 | f.OffsetU = offsets; | 784 | OSDArray mesh_list = (OSDArray)request["mesh_list"]; |
785 | OSDArray texture_list = (OSDArray)request["texture_list"]; | ||
786 | SceneObjectGroup grp = null; | ||
567 | 787 | ||
568 | if (offsett != 0) | 788 | // create and store texture assets |
569 | f.OffsetV = offsett; | 789 | bool doTextInv = (!istest && m_enableModelUploadTextureToInventory && |
790 | texturesFolder != UUID.Zero); | ||
570 | 791 | ||
571 | if (scales != 0) | ||
572 | f.RepeatU = scales; | ||
573 | 792 | ||
574 | if (scalet != 0) | 793 | List<UUID> textures = new List<UUID>(); |
575 | f.RepeatV = scalet; | ||
576 | 794 | ||
577 | if (textures.Count > textureNum) | 795 | |
578 | f.TextureID = textures[textureNum]; | 796 | if (doTextInv) |
579 | else | 797 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); |
580 | f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE; | ||
581 | 798 | ||
582 | 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 | } | ||
583 | } | 840 | } |
584 | 841 | ||
585 | 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 | } | ||
853 | |||
854 | int skipedMeshs = 0; | ||
855 | // build prims from instances | ||
856 | for (int i = 0; i < instance_list.Count; i++) | ||
857 | { | ||
858 | OSDMap inner_instance_list = (OSDMap)instance_list[i]; | ||
859 | |||
860 | // skip prims that are 2 small | ||
861 | Vector3 scale = inner_instance_list["scale"].AsVector3(); | ||
862 | |||
863 | if (scale.X < m_PrimScaleMin || scale.Y < m_PrimScaleMin || scale.Z < m_PrimScaleMin) | ||
864 | { | ||
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 | |||
586 | 874 | ||
587 | AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, ""); | 875 | OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; |
588 | meshAsset.Data = mesh_list[i].AsBinary(); | 876 | for (uint face = 0; face < face_list.Count; face++) |
589 | m_assetService.Store(meshAsset); | 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; | ||
590 | 897 | ||
591 | pbs.SculptEntry = true; | 898 | if (offsett != 0) |
592 | pbs.SculptTexture = meshAsset.FullID; | 899 | f.OffsetV = offsett; |
593 | pbs.SculptType = (byte)SculptType.Mesh; | ||
594 | pbs.SculptData = meshAsset.Data; | ||
595 | 900 | ||
596 | Vector3 position = inner_instance_list["position"].AsVector3(); | 901 | if (scales != 0) |
597 | Vector3 scale = inner_instance_list["scale"].AsVector3(); | 902 | f.RepeatU = scales; |
598 | Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); | 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; | ||
599 | 942 | ||
600 | // no longer used - begin ------------------------ | 943 | // no longer used - begin ------------------------ |
601 | // int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger(); | ||
602 | // int material = inner_instance_list["material"].AsInteger(); | ||
603 | // int mesh = inner_instance_list["mesh"].AsInteger(); | 944 | // int mesh = inner_instance_list["mesh"].AsInteger(); |
604 | 945 | ||
605 | // OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; | 946 | // OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; |
@@ -614,24 +955,42 @@ namespace OpenSim.Region.ClientStack.Linden | |||
614 | // UUID owner_id = permissions["owner_id"].AsUUID(); | 955 | // UUID owner_id = permissions["owner_id"].AsUUID(); |
615 | // int owner_mask = permissions["owner_mask"].AsInteger(); | 956 | // int owner_mask = permissions["owner_mask"].AsInteger(); |
616 | // 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(); | ||
617 | 977 | ||
618 | 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 | } | ||
619 | 986 | ||
620 | SceneObjectPart prim | 987 | if(istest) |
621 | = 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 = ""; | ||
622 | 991 | ||
623 | prim.Scale = scale; | 992 | prim.Material = material; |
624 | //prim.OffsetPosition = position; | 993 | prim.PhysicsShapeType = physicsShapeType; |
625 | rotations.Add(rotation); | ||
626 | positions.Add(position); | ||
627 | prim.UUID = UUID.Random(); | ||
628 | prim.CreatorID = owner_id; | ||
629 | prim.OwnerID = owner_id; | ||
630 | prim.GroupID = UUID.Zero; | ||
631 | prim.LastOwnerID = prim.OwnerID; | ||
632 | prim.CreationDate = Util.UnixTimeSinceEpoch(); | ||
633 | prim.Name = assetName; | ||
634 | prim.Description = ""; | ||
635 | 994 | ||
636 | // prim.BaseMask = (uint)base_mask; | 995 | // prim.BaseMask = (uint)base_mask; |
637 | // prim.EveryoneMask = (uint)everyone_mask; | 996 | // prim.EveryoneMask = (uint)everyone_mask; |
@@ -639,52 +998,64 @@ namespace OpenSim.Region.ClientStack.Linden | |||
639 | // prim.NextOwnerMask = (uint)next_owner_mask; | 998 | // prim.NextOwnerMask = (uint)next_owner_mask; |
640 | // prim.OwnerMask = (uint)owner_mask; | 999 | // prim.OwnerMask = (uint)owner_mask; |
641 | 1000 | ||
642 | if (grp == null) | 1001 | if (grp == null) |
643 | grp = new SceneObjectGroup(prim); | 1002 | { |
644 | else | 1003 | grp = new SceneObjectGroup(prim); |
645 | grp.AddPart(prim); | 1004 | grp.LastOwnerID = creatorID; |
646 | } | 1005 | } |
1006 | else | ||
1007 | grp.AddPart(prim); | ||
1008 | } | ||
647 | 1009 | ||
648 | Vector3 rootPos = positions[0]; | 1010 | Vector3 rootPos = positions[0]; |
649 | 1011 | ||
650 | if (grp.Parts.Length > 1) | 1012 | if (grp.Parts.Length > 1) |
651 | { | 1013 | { |
652 | // Fix first link number | 1014 | // Fix first link number |
653 | grp.RootPart.LinkNum++; | 1015 | grp.RootPart.LinkNum++; |
654 | 1016 | ||
655 | Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); | 1017 | Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); |
656 | Quaternion tmprot; | 1018 | Quaternion tmprot; |
657 | Vector3 offset; | 1019 | Vector3 offset; |
658 | 1020 | ||
659 | // fix children rotations and positions | 1021 | // fix children rotations and positions |
660 | for (int i = 1; i < rotations.Count; i++) | 1022 | for (int i = 1; i < rotations.Count; i++) |
661 | { | 1023 | { |
662 | tmprot = rotations[i]; | 1024 | tmprot = rotations[i]; |
663 | tmprot = rootRotConj * tmprot; | 1025 | tmprot = rootRotConj * tmprot; |
1026 | |||
1027 | grp.Parts[i].RotationOffset = tmprot; | ||
664 | 1028 | ||
665 | grp.Parts[i].RotationOffset = tmprot; | 1029 | offset = positions[i] - rootPos; |
666 | 1030 | ||
667 | offset = positions[i] - rootPos; | 1031 | offset *= rootRotConj; |
1032 | grp.Parts[i].OffsetPosition = offset; | ||
1033 | } | ||
668 | 1034 | ||
669 | offset *= rootRotConj; | 1035 | grp.AbsolutePosition = rootPos; |
670 | grp.Parts[i].OffsetPosition = offset; | 1036 | grp.UpdateGroupRotationR(rotations[0]); |
1037 | } | ||
1038 | else | ||
1039 | { | ||
1040 | grp.AbsolutePosition = rootPos; | ||
1041 | grp.UpdateGroupRotationR(rotations[0]); | ||
671 | } | 1042 | } |
672 | 1043 | ||
673 | grp.AbsolutePosition = rootPos; | 1044 | data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp)); |
674 | grp.UpdateGroupRotationR(rotations[0]); | ||
675 | } | 1045 | } |
676 | else | 1046 | |
1047 | else // not a mesh model | ||
677 | { | 1048 | { |
678 | grp.AbsolutePosition = rootPos; | 1049 | m_log.ErrorFormat("[CAPS Asset Upload] got unsuported assetType for object upload"); |
679 | grp.UpdateGroupRotationR(rotations[0]); | 1050 | return; |
680 | } | 1051 | } |
681 | |||
682 | data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp)); | ||
683 | } | 1052 | } |
684 | 1053 | ||
685 | AssetBase asset; | 1054 | AssetBase asset; |
686 | asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString()); | 1055 | asset = new AssetBase(assetID, assetName, assType, creatorIDstr); |
687 | asset.Data = data; | 1056 | asset.Data = data; |
1057 | if (istest) | ||
1058 | asset.Local = true; | ||
688 | if (AddNewAsset != null) | 1059 | if (AddNewAsset != null) |
689 | AddNewAsset(asset); | 1060 | AddNewAsset(asset); |
690 | else if (m_assetService != null) | 1061 | else if (m_assetService != null) |
@@ -692,11 +1063,17 @@ namespace OpenSim.Region.ClientStack.Linden | |||
692 | 1063 | ||
693 | InventoryItemBase item = new InventoryItemBase(); | 1064 | InventoryItemBase item = new InventoryItemBase(); |
694 | item.Owner = m_HostCapsObj.AgentID; | 1065 | item.Owner = m_HostCapsObj.AgentID; |
695 | item.CreatorId = m_HostCapsObj.AgentID.ToString(); | 1066 | item.CreatorId = creatorIDstr; |
696 | item.CreatorData = String.Empty; | 1067 | item.CreatorData = String.Empty; |
697 | item.ID = inventoryItem; | 1068 | item.ID = inventoryItem; |
698 | item.AssetID = asset.FullID; | 1069 | item.AssetID = asset.FullID; |
699 | 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; | ||
700 | item.Name = assetName; | 1077 | item.Name = assetName; |
701 | item.AssetType = assType; | 1078 | item.AssetType = assType; |
702 | item.InvType = inType; | 1079 | item.InvType = inType; |
@@ -704,18 +1081,60 @@ namespace OpenSim.Region.ClientStack.Linden | |||
704 | 1081 | ||
705 | // 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 |
706 | // (owner) permissions. This becomes a problem if next permissions are changed. | 1083 | // (owner) permissions. This becomes a problem if next permissions are changed. |
707 | item.CurrentPermissions | ||
708 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); | ||
709 | 1084 | ||
710 | item.BasePermissions = (uint)PermissionMask.All; | 1085 | if (restrictPerms) |
711 | item.EveryOnePermissions = 0; | 1086 | { |
712 | 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 | |||
713 | item.CreationDate = Util.UnixTimeSinceEpoch(); | 1104 | item.CreationDate = Util.UnixTimeSinceEpoch(); |
714 | 1105 | ||
1106 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); | ||
1107 | |||
715 | if (AddNewInventoryItem != null) | 1108 | if (AddNewInventoryItem != null) |
716 | { | 1109 | { |
717 | 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 | } | ||
718 | } | 1134 | } |
1135 | |||
1136 | lock (m_ModelCost) | ||
1137 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
719 | } | 1138 | } |
720 | 1139 | ||
721 | /// <summary> | 1140 | /// <summary> |
@@ -908,6 +1327,120 @@ namespace OpenSim.Region.ClientStack.Linden | |||
908 | return response; | 1327 | return response; |
909 | } | 1328 | } |
910 | 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 | |||
911 | public string UpdateAgentInformation(string request, string path, | 1444 | public string UpdateAgentInformation(string request, string path, |
912 | string param, IOSHttpRequest httpRequest, | 1445 | string param, IOSHttpRequest httpRequest, |
913 | IOSHttpResponse httpResponse) | 1446 | IOSHttpResponse httpResponse) |
@@ -927,6 +1460,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
927 | 1460 | ||
928 | public class AssetUploader | 1461 | public class AssetUploader |
929 | { | 1462 | { |
1463 | private static readonly ILog m_log = | ||
1464 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
1465 | |||
1466 | |||
930 | public event UpLoadedAsset OnUpLoad; | 1467 | public event UpLoadedAsset OnUpLoad; |
931 | private UpLoadedAsset handlerUpLoad = null; | 1468 | private UpLoadedAsset handlerUpLoad = null; |
932 | 1469 | ||
@@ -941,10 +1478,21 @@ namespace OpenSim.Region.ClientStack.Linden | |||
941 | 1478 | ||
942 | private string m_invType = String.Empty; | 1479 | private string m_invType = String.Empty; |
943 | 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; | ||
944 | 1490 | ||
945 | public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, | 1491 | public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, |
946 | UUID parentFolderID, string invType, string assetType, string path, | 1492 | UUID parentFolderID, string invType, string assetType, string path, |
947 | IHttpServer httpServer, bool dumpAssetsToFile) | 1493 | IHttpServer httpServer, bool dumpAssetsToFile, |
1494 | int totalCost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, | ||
1495 | bool IsAtestUpload) | ||
948 | { | 1496 | { |
949 | m_assetName = assetName; | 1497 | m_assetName = assetName; |
950 | m_assetDes = description; | 1498 | m_assetDes = description; |
@@ -956,6 +1504,18 @@ namespace OpenSim.Region.ClientStack.Linden | |||
956 | m_assetType = assetType; | 1504 | m_assetType = assetType; |
957 | m_invType = invType; | 1505 | m_invType = invType; |
958 | 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(); | ||
959 | } | 1519 | } |
960 | 1520 | ||
961 | /// <summary> | 1521 | /// <summary> |
@@ -970,12 +1530,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
970 | UUID inv = inventoryItemID; | 1530 | UUID inv = inventoryItemID; |
971 | string res = String.Empty; | 1531 | string res = String.Empty; |
972 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | 1532 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); |
1533 | /* | ||
973 | uploadComplete.new_asset = newAssetID.ToString(); | 1534 | uploadComplete.new_asset = newAssetID.ToString(); |
974 | uploadComplete.new_inventory_item = inv; | 1535 | uploadComplete.new_inventory_item = inv; |
975 | uploadComplete.state = "complete"; | 1536 | uploadComplete.state = "complete"; |
976 | 1537 | ||
977 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | 1538 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); |
978 | 1539 | */ | |
1540 | m_timeoutTimer.Stop(); | ||
979 | httpListener.RemoveStreamHandler("POST", uploaderPath); | 1541 | httpListener.RemoveStreamHandler("POST", uploaderPath); |
980 | 1542 | ||
981 | // TODO: probably make this a better set of extensions here | 1543 | // TODO: probably make this a better set of extensions here |
@@ -992,12 +1554,49 @@ namespace OpenSim.Region.ClientStack.Linden | |||
992 | handlerUpLoad = OnUpLoad; | 1554 | handlerUpLoad = OnUpLoad; |
993 | if (handlerUpLoad != null) | 1555 | if (handlerUpLoad != null) |
994 | { | 1556 | { |
995 | 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); | ||
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"; | ||
996 | } | 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; | ||
997 | 1584 | ||
1585 | uploadComplete.error = resperror; | ||
1586 | uploadComplete.state = "failed"; | ||
1587 | } | ||
1588 | } | ||
1589 | |||
1590 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
998 | return res; | 1591 | return res; |
999 | } | 1592 | } |
1000 | 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 | |||
1001 | ///Left this in and commented in case there are unforseen issues | 1600 | ///Left this in and commented in case there are unforseen issues |
1002 | //private void SaveAssetToFile(string filename, byte[] data) | 1601 | //private void SaveAssetToFile(string filename, byte[] data) |
1003 | //{ | 1602 | //{ |