diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps')
11 files changed, 2461 insertions, 520 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 1d4c7f0..762e22a 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; |
@@ -54,14 +55,16 @@ using PermissionMask = OpenSim.Framework.PermissionMask; | |||
54 | namespace OpenSim.Region.ClientStack.Linden | 55 | namespace OpenSim.Region.ClientStack.Linden |
55 | { | 56 | { |
56 | public delegate void UpLoadedAsset( | 57 | public delegate void UpLoadedAsset( |
57 | string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, | 58 | string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, |
58 | byte[] data, string inventoryType, string assetType); | 59 | byte[] data, string inventoryType, string assetType, |
60 | int cost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, | ||
61 | bool IsAtestUpload, ref string error); | ||
59 | 62 | ||
60 | public delegate UUID UpdateItem(UUID itemID, byte[] data); | 63 | public delegate UUID UpdateItem(UUID itemID, byte[] data); |
61 | 64 | ||
62 | public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); | 65 | public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); |
63 | 66 | ||
64 | public delegate void NewInventoryItem(UUID userID, InventoryItemBase item); | 67 | public delegate void NewInventoryItem(UUID userID, InventoryItemBase item, uint cost); |
65 | 68 | ||
66 | public delegate void NewAsset(AssetBase asset); | 69 | public delegate void NewAsset(AssetBase asset); |
67 | 70 | ||
@@ -87,6 +90,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
87 | 90 | ||
88 | private Scene m_Scene; | 91 | private Scene m_Scene; |
89 | private Caps m_HostCapsObj; | 92 | private Caps m_HostCapsObj; |
93 | private ModelCost m_ModelCost; | ||
90 | 94 | ||
91 | private static readonly string m_requestPath = "0000/"; | 95 | private static readonly string m_requestPath = "0000/"; |
92 | // private static readonly string m_mapLayerPath = "0001/"; | 96 | // private static readonly string m_mapLayerPath = "0001/"; |
@@ -98,7 +102,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
98 | private static readonly string m_copyFromNotecardPath = "0007/"; | 102 | private static readonly string m_copyFromNotecardPath = "0007/"; |
99 | // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule. | 103 | // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule. |
100 | private static readonly string m_getObjectPhysicsDataPath = "0101/"; | 104 | private static readonly string m_getObjectPhysicsDataPath = "0101/"; |
101 | /* 0102 - 0103 RESERVED */ | 105 | private static readonly string m_getObjectCostPath = "0102/"; |
106 | private static readonly string m_ResourceCostSelectedPath = "0103/"; | ||
102 | private static readonly string m_UpdateAgentInformationPath = "0500/"; | 107 | private static readonly string m_UpdateAgentInformationPath = "0500/"; |
103 | 108 | ||
104 | // These are callbacks which will be setup by the scene so that we can update scene data when we | 109 | // These are callbacks which will be setup by the scene so that we can update scene data when we |
@@ -114,12 +119,50 @@ namespace OpenSim.Region.ClientStack.Linden | |||
114 | private IAssetService m_assetService; | 119 | private IAssetService m_assetService; |
115 | private bool m_dumpAssetsToFile = false; | 120 | private bool m_dumpAssetsToFile = false; |
116 | private string m_regionName; | 121 | private string m_regionName; |
122 | |||
117 | private int m_levelUpload = 0; | 123 | private int m_levelUpload = 0; |
118 | 124 | ||
125 | private bool m_enableFreeTestUpload = false; // allows "TEST-" prefix hack | ||
126 | private bool m_ForceFreeTestUpload = false; // forces all uploads to be test | ||
127 | |||
128 | private bool m_enableModelUploadTextureToInventory = false; // place uploaded textures also in inventory | ||
129 | // may not be visible till relog | ||
130 | |||
131 | private bool m_RestrictFreeTestUploadPerms = false; // reduces also the permitions. Needs a creator defined!! | ||
132 | private UUID m_testAssetsCreatorID = UUID.Zero; | ||
133 | |||
134 | private float m_PrimScaleMin = 0.001f; | ||
135 | |||
136 | private enum FileAgentInventoryState : int | ||
137 | { | ||
138 | idle = 0, | ||
139 | processRequest = 1, | ||
140 | waitUpload = 2, | ||
141 | processUpload = 3 | ||
142 | } | ||
143 | private FileAgentInventoryState m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
144 | |||
119 | public BunchOfCaps(Scene scene, Caps caps) | 145 | public BunchOfCaps(Scene scene, Caps caps) |
120 | { | 146 | { |
121 | m_Scene = scene; | 147 | m_Scene = scene; |
122 | m_HostCapsObj = caps; | 148 | m_HostCapsObj = caps; |
149 | |||
150 | // create a model upload cost provider | ||
151 | m_ModelCost = new ModelCost(); | ||
152 | // tell it about scene object limits | ||
153 | m_ModelCost.NonPhysicalPrimScaleMax = m_Scene.m_maxNonphys; | ||
154 | m_ModelCost.PhysicalPrimScaleMax = m_Scene.m_maxPhys; | ||
155 | |||
156 | // m_ModelCost.ObjectLinkedPartsMax = ?? | ||
157 | // m_ModelCost.PrimScaleMin = ?? | ||
158 | |||
159 | m_PrimScaleMin = m_ModelCost.PrimScaleMin; | ||
160 | float modelTextureUploadFactor = m_ModelCost.ModelTextureCostFactor; | ||
161 | float modelUploadFactor = m_ModelCost.ModelMeshCostFactor; | ||
162 | float modelMinUploadCostFactor = m_ModelCost.ModelMinCostFactor; | ||
163 | float modelPrimCreationCost = m_ModelCost.primCreationCost; | ||
164 | float modelMeshByteCost = m_ModelCost.bytecost; | ||
165 | |||
123 | IConfigSource config = m_Scene.Config; | 166 | IConfigSource config = m_Scene.Config; |
124 | if (config != null) | 167 | if (config != null) |
125 | { | 168 | { |
@@ -134,6 +177,37 @@ namespace OpenSim.Region.ClientStack.Linden | |||
134 | { | 177 | { |
135 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | 178 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); |
136 | } | 179 | } |
180 | // economy for model upload | ||
181 | IConfig EconomyConfig = config.Configs["Economy"]; | ||
182 | if (EconomyConfig != null) | ||
183 | { | ||
184 | modelUploadFactor = EconomyConfig.GetFloat("MeshModelUploadCostFactor", modelUploadFactor); | ||
185 | modelTextureUploadFactor = EconomyConfig.GetFloat("MeshModelUploadTextureCostFactor", modelTextureUploadFactor); | ||
186 | modelMinUploadCostFactor = EconomyConfig.GetFloat("MeshModelMinCostFactor", modelMinUploadCostFactor); | ||
187 | // next 2 are normalized so final cost is afected by modelUploadFactor above and normal cost | ||
188 | modelPrimCreationCost = EconomyConfig.GetFloat("ModelPrimCreationCost", modelPrimCreationCost); | ||
189 | modelMeshByteCost = EconomyConfig.GetFloat("ModelMeshByteCost", modelMeshByteCost); | ||
190 | |||
191 | m_enableModelUploadTextureToInventory = EconomyConfig.GetBoolean("MeshModelAllowTextureToInventory", m_enableModelUploadTextureToInventory); | ||
192 | |||
193 | m_RestrictFreeTestUploadPerms = EconomyConfig.GetBoolean("m_RestrictFreeTestUploadPerms", m_RestrictFreeTestUploadPerms); | ||
194 | m_enableFreeTestUpload = EconomyConfig.GetBoolean("AllowFreeTestUpload", m_enableFreeTestUpload); | ||
195 | m_ForceFreeTestUpload = EconomyConfig.GetBoolean("ForceFreeTestUpload", m_ForceFreeTestUpload); | ||
196 | string testcreator = EconomyConfig.GetString("TestAssetsCreatorID", ""); | ||
197 | if (testcreator != "") | ||
198 | { | ||
199 | UUID id; | ||
200 | UUID.TryParse(testcreator, out id); | ||
201 | if (id != null) | ||
202 | m_testAssetsCreatorID = id; | ||
203 | } | ||
204 | |||
205 | m_ModelCost.ModelMeshCostFactor = modelUploadFactor; | ||
206 | m_ModelCost.ModelTextureCostFactor = modelTextureUploadFactor; | ||
207 | m_ModelCost.ModelMinCostFactor = modelMinUploadCostFactor; | ||
208 | m_ModelCost.primCreationCost = modelPrimCreationCost; | ||
209 | m_ModelCost.bytecost = modelMeshByteCost; | ||
210 | } | ||
137 | } | 211 | } |
138 | 212 | ||
139 | m_assetService = m_Scene.AssetService; | 213 | m_assetService = m_Scene.AssetService; |
@@ -145,6 +219,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
145 | ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; | 219 | ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; |
146 | TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; | 220 | TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; |
147 | GetClient = m_Scene.SceneGraph.GetControllingClient; | 221 | GetClient = m_Scene.SceneGraph.GetControllingClient; |
222 | |||
223 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
148 | } | 224 | } |
149 | 225 | ||
150 | /// <summary> | 226 | /// <summary> |
@@ -190,7 +266,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
190 | { | 266 | { |
191 | try | 267 | try |
192 | { | 268 | { |
193 | // I don't think this one works... | ||
194 | m_HostCapsObj.RegisterHandler( | 269 | m_HostCapsObj.RegisterHandler( |
195 | "NewFileAgentInventory", | 270 | "NewFileAgentInventory", |
196 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( | 271 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( |
@@ -212,6 +287,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
212 | = new RestStreamHandler( | 287 | = new RestStreamHandler( |
213 | "POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData, "GetObjectPhysicsData", null); | 288 | "POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData, "GetObjectPhysicsData", null); |
214 | m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler); | 289 | m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler); |
290 | IRequestHandler getObjectCostHandler = new RestStreamHandler("POST", capsBase + m_getObjectCostPath, GetObjectCost); | ||
291 | m_HostCapsObj.RegisterHandler("GetObjectCost", getObjectCostHandler); | ||
292 | IRequestHandler ResourceCostSelectedHandler = new RestStreamHandler("POST", capsBase + m_ResourceCostSelectedPath, ResourceCostSelected); | ||
293 | m_HostCapsObj.RegisterHandler("ResourceCostSelected", ResourceCostSelectedHandler); | ||
215 | 294 | ||
216 | IRequestHandler UpdateAgentInformationHandler | 295 | IRequestHandler UpdateAgentInformationHandler |
217 | = new RestStreamHandler( | 296 | = new RestStreamHandler( |
@@ -270,6 +349,9 @@ namespace OpenSim.Region.ClientStack.Linden | |||
270 | m_log.DebugFormat( | 349 | m_log.DebugFormat( |
271 | "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID); | 350 | "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID); |
272 | 351 | ||
352 | if (!m_HostCapsObj.WaitForActivation()) | ||
353 | return string.Empty; | ||
354 | |||
273 | if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint)) | 355 | if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint)) |
274 | { | 356 | { |
275 | m_log.WarnFormat( | 357 | m_log.WarnFormat( |
@@ -399,62 +481,176 @@ namespace OpenSim.Region.ClientStack.Linden | |||
399 | //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); | 481 | //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); |
400 | //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); | 482 | //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); |
401 | 483 | ||
484 | // start by getting the client | ||
485 | IClientAPI client = null; | ||
486 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); | ||
487 | |||
488 | // check current state so we only have one service at a time | ||
489 | lock (m_ModelCost) | ||
490 | { | ||
491 | switch (m_FileAgentInventoryState) | ||
492 | { | ||
493 | case FileAgentInventoryState.processRequest: | ||
494 | case FileAgentInventoryState.processUpload: | ||
495 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
496 | resperror.message = "Uploader busy processing previus request"; | ||
497 | resperror.identifier = UUID.Zero; | ||
498 | |||
499 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | ||
500 | errorResponse.uploader = ""; | ||
501 | errorResponse.state = "error"; | ||
502 | errorResponse.error = resperror; | ||
503 | return errorResponse; | ||
504 | break; | ||
505 | case FileAgentInventoryState.waitUpload: | ||
506 | // todo stop current uploader server | ||
507 | break; | ||
508 | case FileAgentInventoryState.idle: | ||
509 | default: | ||
510 | break; | ||
511 | } | ||
512 | |||
513 | m_FileAgentInventoryState = FileAgentInventoryState.processRequest; | ||
514 | } | ||
515 | |||
516 | int cost = 0; | ||
517 | int nreqtextures = 0; | ||
518 | int nreqmeshs= 0; | ||
519 | int nreqinstances = 0; | ||
520 | bool IsAtestUpload = false; | ||
521 | |||
522 | string assetName = llsdRequest.name; | ||
523 | |||
524 | LLSDAssetUploadResponseData meshcostdata = new LLSDAssetUploadResponseData(); | ||
525 | |||
402 | if (llsdRequest.asset_type == "texture" || | 526 | if (llsdRequest.asset_type == "texture" || |
403 | llsdRequest.asset_type == "animation" || | 527 | llsdRequest.asset_type == "animation" || |
528 | llsdRequest.asset_type == "mesh" || | ||
404 | llsdRequest.asset_type == "sound") | 529 | llsdRequest.asset_type == "sound") |
405 | { | 530 | { |
406 | ScenePresence avatar = null; | 531 | ScenePresence avatar = null; |
407 | IClientAPI client = null; | ||
408 | m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); | 532 | m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); |
409 | 533 | ||
410 | // check user level | 534 | // check user level |
411 | if (avatar != null) | 535 | if (avatar != null) |
412 | { | 536 | { |
413 | client = avatar.ControllingClient; | ||
414 | |||
415 | if (avatar.UserLevel < m_levelUpload) | 537 | if (avatar.UserLevel < m_levelUpload) |
416 | { | 538 | { |
417 | if (client != null) | 539 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); |
418 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); | 540 | resperror.message = "Insufficient permissions to upload"; |
541 | resperror.identifier = UUID.Zero; | ||
419 | 542 | ||
420 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | 543 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); |
421 | errorResponse.uploader = ""; | 544 | errorResponse.uploader = ""; |
422 | errorResponse.state = "error"; | 545 | errorResponse.state = "error"; |
546 | errorResponse.error = resperror; | ||
547 | lock (m_ModelCost) | ||
548 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
423 | return errorResponse; | 549 | return errorResponse; |
424 | } | 550 | } |
425 | } | 551 | } |
426 | 552 | ||
427 | // check funds | 553 | // check test upload and funds |
428 | if (client != null) | 554 | if (client != null) |
429 | { | 555 | { |
430 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); | 556 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); |
431 | 557 | ||
558 | int baseCost = 0; | ||
432 | if (mm != null) | 559 | if (mm != null) |
560 | baseCost = mm.UploadCharge; | ||
561 | |||
562 | string warning = String.Empty; | ||
563 | |||
564 | if (llsdRequest.asset_type == "mesh") | ||
433 | { | 565 | { |
434 | if (!mm.UploadCovered(client.AgentId, mm.UploadCharge)) | 566 | string error; |
567 | int modelcost; | ||
568 | |||
569 | if (!m_ModelCost.MeshModelCost(llsdRequest.asset_resources, baseCost, out modelcost, | ||
570 | meshcostdata, out error, ref warning)) | ||
435 | { | 571 | { |
436 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | 572 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); |
573 | resperror.message = error; | ||
574 | resperror.identifier = UUID.Zero; | ||
437 | 575 | ||
438 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | 576 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); |
439 | errorResponse.uploader = ""; | 577 | errorResponse.uploader = ""; |
440 | errorResponse.state = "error"; | 578 | errorResponse.state = "error"; |
579 | errorResponse.error = resperror; | ||
580 | |||
581 | lock (m_ModelCost) | ||
582 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
441 | return errorResponse; | 583 | return errorResponse; |
442 | } | 584 | } |
585 | cost = modelcost; | ||
586 | } | ||
587 | else | ||
588 | { | ||
589 | cost = baseCost; | ||
590 | } | ||
591 | |||
592 | if (cost > 0 && mm != null) | ||
593 | { | ||
594 | // check for test upload | ||
595 | |||
596 | if (m_ForceFreeTestUpload) // all are test | ||
597 | { | ||
598 | if (!(assetName.Length > 5 && assetName.StartsWith("TEST-"))) // has normal name lets change it | ||
599 | assetName = "TEST-" + assetName; | ||
600 | |||
601 | IsAtestUpload = true; | ||
602 | } | ||
603 | |||
604 | else if (m_enableFreeTestUpload) // only if prefixed with "TEST-" | ||
605 | { | ||
606 | |||
607 | IsAtestUpload = (assetName.Length > 5 && assetName.StartsWith("TEST-")); | ||
608 | } | ||
609 | |||
610 | |||
611 | if(IsAtestUpload) // let user know, still showing cost estimation | ||
612 | 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"; | ||
613 | |||
614 | // check funds | ||
615 | else | ||
616 | { | ||
617 | if (!mm.UploadCovered(client.AgentId, (int)cost)) | ||
618 | { | ||
619 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
620 | resperror.message = "Insuficient funds"; | ||
621 | resperror.identifier = UUID.Zero; | ||
622 | |||
623 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | ||
624 | errorResponse.uploader = ""; | ||
625 | errorResponse.state = "error"; | ||
626 | errorResponse.error = resperror; | ||
627 | lock (m_ModelCost) | ||
628 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
629 | return errorResponse; | ||
630 | } | ||
631 | } | ||
443 | } | 632 | } |
633 | |||
634 | if (client != null && warning != String.Empty) | ||
635 | client.SendAgentAlertMessage(warning, true); | ||
444 | } | 636 | } |
445 | } | 637 | } |
446 | 638 | ||
447 | string assetName = llsdRequest.name; | ||
448 | string assetDes = llsdRequest.description; | 639 | string assetDes = llsdRequest.description; |
449 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; | 640 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; |
450 | UUID newAsset = UUID.Random(); | 641 | UUID newAsset = UUID.Random(); |
451 | UUID newInvItem = UUID.Random(); | 642 | UUID newInvItem = UUID.Random(); |
452 | UUID parentFolder = llsdRequest.folder_id; | 643 | UUID parentFolder = llsdRequest.folder_id; |
453 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | 644 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); |
645 | UUID texturesFolder = UUID.Zero; | ||
646 | |||
647 | if(!IsAtestUpload && m_enableModelUploadTextureToInventory) | ||
648 | texturesFolder = llsdRequest.texture_folder_id; | ||
454 | 649 | ||
455 | AssetUploader uploader = | 650 | AssetUploader uploader = |
456 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | 651 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, |
457 | llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); | 652 | llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost, |
653 | texturesFolder, nreqtextures, nreqmeshs, nreqinstances, IsAtestUpload); | ||
458 | 654 | ||
459 | m_HostCapsObj.HttpListener.AddStreamHandler( | 655 | m_HostCapsObj.HttpListener.AddStreamHandler( |
460 | new BinaryStreamHandler( | 656 | new BinaryStreamHandler( |
@@ -472,10 +668,22 @@ namespace OpenSim.Region.ClientStack.Linden | |||
472 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + | 668 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + |
473 | uploaderPath; | 669 | uploaderPath; |
474 | 670 | ||
671 | |||
475 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | 672 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); |
476 | uploadResponse.uploader = uploaderURL; | 673 | uploadResponse.uploader = uploaderURL; |
477 | uploadResponse.state = "upload"; | 674 | uploadResponse.state = "upload"; |
675 | uploadResponse.upload_price = (int)cost; | ||
676 | |||
677 | if (llsdRequest.asset_type == "mesh") | ||
678 | { | ||
679 | uploadResponse.data = meshcostdata; | ||
680 | } | ||
681 | |||
478 | uploader.OnUpLoad += UploadCompleteHandler; | 682 | uploader.OnUpLoad += UploadCompleteHandler; |
683 | |||
684 | lock (m_ModelCost) | ||
685 | m_FileAgentInventoryState = FileAgentInventoryState.waitUpload; | ||
686 | |||
479 | return uploadResponse; | 687 | return uploadResponse; |
480 | } | 688 | } |
481 | 689 | ||
@@ -487,8 +695,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
487 | /// <param name="data"></param> | 695 | /// <param name="data"></param> |
488 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, | 696 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, |
489 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, | 697 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, |
490 | string assetType) | 698 | string assetType, int cost, |
699 | UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, | ||
700 | bool IsAtestUpload, ref string error) | ||
491 | { | 701 | { |
702 | |||
703 | lock (m_ModelCost) | ||
704 | m_FileAgentInventoryState = FileAgentInventoryState.processUpload; | ||
705 | |||
492 | m_log.DebugFormat( | 706 | m_log.DebugFormat( |
493 | "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", | 707 | "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", |
494 | assetID, inventoryItem, inventoryType, assetType); | 708 | assetID, inventoryItem, inventoryType, assetType); |
@@ -496,117 +710,247 @@ namespace OpenSim.Region.ClientStack.Linden | |||
496 | sbyte assType = 0; | 710 | sbyte assType = 0; |
497 | sbyte inType = 0; | 711 | sbyte inType = 0; |
498 | 712 | ||
713 | IClientAPI client = null; | ||
714 | |||
715 | UUID owner_id = m_HostCapsObj.AgentID; | ||
716 | UUID creatorID; | ||
717 | |||
718 | bool istest = IsAtestUpload && m_enableFreeTestUpload && (cost > 0); | ||
719 | |||
720 | bool restrictPerms = m_RestrictFreeTestUploadPerms && istest; | ||
721 | |||
722 | if (istest && m_testAssetsCreatorID != UUID.Zero) | ||
723 | creatorID = m_testAssetsCreatorID; | ||
724 | else | ||
725 | creatorID = owner_id; | ||
726 | |||
727 | string creatorIDstr = creatorID.ToString(); | ||
728 | |||
729 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); | ||
730 | if (mm != null) | ||
731 | { | ||
732 | // make sure client still has enougth credit | ||
733 | if (!mm.UploadCovered(m_HostCapsObj.AgentID, (int)cost)) | ||
734 | { | ||
735 | error = "Insufficient funds."; | ||
736 | return; | ||
737 | } | ||
738 | } | ||
739 | |||
740 | // strings to types | ||
499 | if (inventoryType == "sound") | 741 | if (inventoryType == "sound") |
500 | { | 742 | { |
501 | inType = 1; | 743 | inType = (sbyte)InventoryType.Sound; |
502 | assType = 1; | 744 | assType = (sbyte)AssetType.Sound; |
503 | } | 745 | } |
504 | else if (inventoryType == "animation") | 746 | else if (inventoryType == "animation") |
505 | { | 747 | { |
506 | inType = 19; | 748 | inType = (sbyte)InventoryType.Animation; |
507 | assType = 20; | 749 | assType = (sbyte)AssetType.Animation; |
508 | } | 750 | } |
509 | else if (inventoryType == "wearable") | 751 | else if (inventoryType == "wearable") |
510 | { | 752 | { |
511 | inType = 18; | 753 | inType = (sbyte)InventoryType.Wearable; |
512 | switch (assetType) | 754 | switch (assetType) |
513 | { | 755 | { |
514 | case "bodypart": | 756 | case "bodypart": |
515 | assType = 13; | 757 | assType = (sbyte)AssetType.Bodypart; |
516 | break; | 758 | break; |
517 | case "clothing": | 759 | case "clothing": |
518 | assType = 5; | 760 | assType = (sbyte)AssetType.Clothing; |
519 | break; | 761 | break; |
520 | } | 762 | } |
521 | } | 763 | } |
522 | else if (inventoryType == "object") | 764 | else if (inventoryType == "object") |
523 | { | 765 | { |
524 | inType = (sbyte)InventoryType.Object; | 766 | if (assetType == "mesh") // this code for now is for mesh models uploads only |
525 | assType = (sbyte)AssetType.Object; | ||
526 | |||
527 | List<Vector3> positions = new List<Vector3>(); | ||
528 | List<Quaternion> rotations = new List<Quaternion>(); | ||
529 | OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data); | ||
530 | OSDArray instance_list = (OSDArray)request["instance_list"]; | ||
531 | OSDArray mesh_list = (OSDArray)request["mesh_list"]; | ||
532 | OSDArray texture_list = (OSDArray)request["texture_list"]; | ||
533 | SceneObjectGroup grp = null; | ||
534 | |||
535 | List<UUID> textures = new List<UUID>(); | ||
536 | for (int i = 0; i < texture_list.Count; i++) | ||
537 | { | 767 | { |
538 | AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, ""); | 768 | inType = (sbyte)InventoryType.Object; |
539 | textureAsset.Data = texture_list[i].AsBinary(); | 769 | assType = (sbyte)AssetType.Object; |
540 | m_assetService.Store(textureAsset); | ||
541 | textures.Add(textureAsset.FullID); | ||
542 | } | ||
543 | 770 | ||
544 | for (int i = 0; i < mesh_list.Count; i++) | 771 | List<Vector3> positions = new List<Vector3>(); |
545 | { | 772 | List<Quaternion> rotations = new List<Quaternion>(); |
546 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); | 773 | OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data); |
547 | 774 | ||
548 | Primitive.TextureEntry textureEntry | 775 | // compare and get updated information |
549 | = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE); | ||
550 | OSDMap inner_instance_list = (OSDMap)instance_list[i]; | ||
551 | 776 | ||
552 | OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; | 777 | bool mismatchError = true; |
553 | for (uint face = 0; face < face_list.Count; face++) | 778 | |
779 | while (mismatchError) | ||
554 | { | 780 | { |
555 | OSDMap faceMap = (OSDMap)face_list[(int)face]; | 781 | mismatchError = false; |
556 | Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face); | 782 | } |
557 | if(faceMap.ContainsKey("fullbright")) | ||
558 | f.Fullbright = faceMap["fullbright"].AsBoolean(); | ||
559 | if (faceMap.ContainsKey ("diffuse_color")) | ||
560 | f.RGBA = faceMap["diffuse_color"].AsColor4(); | ||
561 | 783 | ||
562 | int textureNum = faceMap["image"].AsInteger(); | 784 | if (mismatchError) |
563 | float imagerot = faceMap["imagerot"].AsInteger(); | 785 | { |
564 | float offsets = (float)faceMap["offsets"].AsReal(); | 786 | error = "Upload and fee estimation information don't match"; |
565 | float offsett = (float)faceMap["offsett"].AsReal(); | 787 | lock (m_ModelCost) |
566 | float scales = (float)faceMap["scales"].AsReal(); | 788 | m_FileAgentInventoryState = FileAgentInventoryState.idle; |
567 | float scalet = (float)faceMap["scalet"].AsReal(); | ||
568 | 789 | ||
569 | if(imagerot != 0) | 790 | return; |
570 | f.Rotation = imagerot; | 791 | } |
571 | 792 | ||
572 | if(offsets != 0) | 793 | OSDArray instance_list = (OSDArray)request["instance_list"]; |
573 | f.OffsetU = offsets; | 794 | OSDArray mesh_list = (OSDArray)request["mesh_list"]; |
795 | OSDArray texture_list = (OSDArray)request["texture_list"]; | ||
796 | SceneObjectGroup grp = null; | ||
574 | 797 | ||
575 | if (offsett != 0) | 798 | // create and store texture assets |
576 | f.OffsetV = offsett; | 799 | bool doTextInv = (!istest && m_enableModelUploadTextureToInventory && |
800 | texturesFolder != UUID.Zero); | ||
577 | 801 | ||
578 | if (scales != 0) | ||
579 | f.RepeatU = scales; | ||
580 | 802 | ||
581 | if (scalet != 0) | 803 | List<UUID> textures = new List<UUID>(); |
582 | f.RepeatV = scalet; | ||
583 | 804 | ||
584 | if (textures.Count > textureNum) | 805 | |
585 | f.TextureID = textures[textureNum]; | 806 | if (doTextInv) |
586 | else | 807 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); |
587 | f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE; | ||
588 | 808 | ||
589 | textureEntry.FaceTextures[face] = f; | 809 | if(client == null) // don't put textures in inventory if there is no client |
810 | doTextInv = false; | ||
811 | |||
812 | for (int i = 0; i < texture_list.Count; i++) | ||
813 | { | ||
814 | AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, creatorIDstr); | ||
815 | textureAsset.Data = texture_list[i].AsBinary(); | ||
816 | if (istest) | ||
817 | textureAsset.Local = true; | ||
818 | m_assetService.Store(textureAsset); | ||
819 | textures.Add(textureAsset.FullID); | ||
820 | |||
821 | if (doTextInv) | ||
822 | { | ||
823 | string name = assetName; | ||
824 | if (name.Length > 25) | ||
825 | name = name.Substring(0, 24); | ||
826 | name += "_Texture#" + i.ToString(); | ||
827 | InventoryItemBase texitem = new InventoryItemBase(); | ||
828 | texitem.Owner = m_HostCapsObj.AgentID; | ||
829 | texitem.CreatorId = creatorIDstr; | ||
830 | texitem.CreatorData = String.Empty; | ||
831 | texitem.ID = UUID.Random(); | ||
832 | texitem.AssetID = textureAsset.FullID; | ||
833 | texitem.Description = "mesh model texture"; | ||
834 | texitem.Name = name; | ||
835 | texitem.AssetType = (int)AssetType.Texture; | ||
836 | texitem.InvType = (int)InventoryType.Texture; | ||
837 | texitem.Folder = texturesFolder; | ||
838 | |||
839 | texitem.CurrentPermissions | ||
840 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export); | ||
841 | |||
842 | texitem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
843 | texitem.EveryOnePermissions = 0; | ||
844 | texitem.NextPermissions = (uint)PermissionMask.All; | ||
845 | texitem.CreationDate = Util.UnixTimeSinceEpoch(); | ||
846 | |||
847 | m_Scene.AddInventoryItem(client, texitem); | ||
848 | texitem = null; | ||
849 | } | ||
590 | } | 850 | } |
591 | 851 | ||
592 | pbs.TextureEntry = textureEntry.GetBytes(); | 852 | // create and store meshs assets |
853 | List<UUID> meshAssets = new List<UUID>(); | ||
854 | for (int i = 0; i < mesh_list.Count; i++) | ||
855 | { | ||
856 | AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, creatorIDstr); | ||
857 | meshAsset.Data = mesh_list[i].AsBinary(); | ||
858 | if (istest) | ||
859 | meshAsset.Local = true; | ||
860 | m_assetService.Store(meshAsset); | ||
861 | meshAssets.Add(meshAsset.FullID); | ||
862 | } | ||
863 | |||
864 | int skipedMeshs = 0; | ||
865 | // build prims from instances | ||
866 | for (int i = 0; i < instance_list.Count; i++) | ||
867 | { | ||
868 | OSDMap inner_instance_list = (OSDMap)instance_list[i]; | ||
869 | |||
870 | // skip prims that are 2 small | ||
871 | Vector3 scale = inner_instance_list["scale"].AsVector3(); | ||
872 | |||
873 | if (scale.X < m_PrimScaleMin || scale.Y < m_PrimScaleMin || scale.Z < m_PrimScaleMin) | ||
874 | { | ||
875 | skipedMeshs++; | ||
876 | continue; | ||
877 | } | ||
878 | |||
879 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); | ||
880 | |||
881 | Primitive.TextureEntry textureEntry | ||
882 | = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE); | ||
883 | |||
593 | 884 | ||
594 | AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, ""); | 885 | OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; |
595 | meshAsset.Data = mesh_list[i].AsBinary(); | 886 | for (uint face = 0; face < face_list.Count; face++) |
596 | m_assetService.Store(meshAsset); | 887 | { |
888 | OSDMap faceMap = (OSDMap)face_list[(int)face]; | ||
889 | Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face); | ||
890 | if (faceMap.ContainsKey("fullbright")) | ||
891 | f.Fullbright = faceMap["fullbright"].AsBoolean(); | ||
892 | if (faceMap.ContainsKey("diffuse_color")) | ||
893 | f.RGBA = faceMap["diffuse_color"].AsColor4(); | ||
894 | |||
895 | int textureNum = faceMap["image"].AsInteger(); | ||
896 | float imagerot = faceMap["imagerot"].AsInteger(); | ||
897 | float offsets = (float)faceMap["offsets"].AsReal(); | ||
898 | float offsett = (float)faceMap["offsett"].AsReal(); | ||
899 | float scales = (float)faceMap["scales"].AsReal(); | ||
900 | float scalet = (float)faceMap["scalet"].AsReal(); | ||
901 | |||
902 | if (imagerot != 0) | ||
903 | f.Rotation = imagerot; | ||
904 | |||
905 | if (offsets != 0) | ||
906 | f.OffsetU = offsets; | ||
597 | 907 | ||
598 | pbs.SculptEntry = true; | 908 | if (offsett != 0) |
599 | pbs.SculptTexture = meshAsset.FullID; | 909 | f.OffsetV = offsett; |
600 | pbs.SculptType = (byte)SculptType.Mesh; | ||
601 | pbs.SculptData = meshAsset.Data; | ||
602 | 910 | ||
603 | Vector3 position = inner_instance_list["position"].AsVector3(); | 911 | if (scales != 0) |
604 | Vector3 scale = inner_instance_list["scale"].AsVector3(); | 912 | f.RepeatU = scales; |
605 | Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); | 913 | |
914 | if (scalet != 0) | ||
915 | f.RepeatV = scalet; | ||
916 | |||
917 | if (textures.Count > textureNum) | ||
918 | f.TextureID = textures[textureNum]; | ||
919 | else | ||
920 | f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE; | ||
921 | |||
922 | textureEntry.FaceTextures[face] = f; | ||
923 | } | ||
924 | |||
925 | pbs.TextureEntry = textureEntry.GetBytes(); | ||
926 | |||
927 | bool hasmesh = false; | ||
928 | if (inner_instance_list.ContainsKey("mesh")) // seems to happen always but ... | ||
929 | { | ||
930 | int meshindx = inner_instance_list["mesh"].AsInteger(); | ||
931 | if (meshAssets.Count > meshindx) | ||
932 | { | ||
933 | pbs.SculptEntry = true; | ||
934 | pbs.SculptType = (byte)SculptType.Mesh; | ||
935 | pbs.SculptTexture = meshAssets[meshindx]; // actual asset UUID after meshs suport introduction | ||
936 | // data will be requested from asset on rez (i hope) | ||
937 | hasmesh = true; | ||
938 | } | ||
939 | } | ||
940 | |||
941 | Vector3 position = inner_instance_list["position"].AsVector3(); | ||
942 | Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); | ||
943 | |||
944 | // for now viwers do send fixed defaults | ||
945 | // but this may change | ||
946 | // int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger(); | ||
947 | byte physicsShapeType = (byte)PhysShapeType.prim; // default for mesh is simple convex | ||
948 | if(hasmesh) | ||
949 | physicsShapeType = (byte) PhysShapeType.convex; // default for mesh is simple convex | ||
950 | // int material = inner_instance_list["material"].AsInteger(); | ||
951 | byte material = (byte)Material.Wood; | ||
606 | 952 | ||
607 | // no longer used - begin ------------------------ | 953 | // no longer used - begin ------------------------ |
608 | // int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger(); | ||
609 | // int material = inner_instance_list["material"].AsInteger(); | ||
610 | // int mesh = inner_instance_list["mesh"].AsInteger(); | 954 | // int mesh = inner_instance_list["mesh"].AsInteger(); |
611 | 955 | ||
612 | // OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; | 956 | // OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; |
@@ -621,24 +965,49 @@ namespace OpenSim.Region.ClientStack.Linden | |||
621 | // UUID owner_id = permissions["owner_id"].AsUUID(); | 965 | // UUID owner_id = permissions["owner_id"].AsUUID(); |
622 | // int owner_mask = permissions["owner_mask"].AsInteger(); | 966 | // int owner_mask = permissions["owner_mask"].AsInteger(); |
623 | // no longer used - end ------------------------ | 967 | // no longer used - end ------------------------ |
968 | |||
969 | |||
970 | SceneObjectPart prim | ||
971 | = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero); | ||
972 | |||
973 | prim.Scale = scale; | ||
974 | rotations.Add(rotation); | ||
975 | positions.Add(position); | ||
976 | prim.UUID = UUID.Random(); | ||
977 | prim.CreatorID = creatorID; | ||
978 | prim.OwnerID = owner_id; | ||
979 | prim.GroupID = UUID.Zero; | ||
980 | prim.LastOwnerID = creatorID; | ||
981 | prim.CreationDate = Util.UnixTimeSinceEpoch(); | ||
982 | |||
983 | if (grp == null) | ||
984 | prim.Name = assetName; | ||
985 | else | ||
986 | prim.Name = assetName + "#" + i.ToString(); | ||
624 | 987 | ||
625 | UUID owner_id = m_HostCapsObj.AgentID; | 988 | prim.EveryoneMask = 0; |
989 | prim.GroupMask = 0; | ||
626 | 990 | ||
627 | SceneObjectPart prim | 991 | if (restrictPerms) |
628 | = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero); | 992 | { |
993 | prim.BaseMask = (uint)(PermissionMask.Move | PermissionMask.Modify); | ||
994 | prim.OwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify); | ||
995 | prim.NextOwnerMask = 0; | ||
996 | } | ||
997 | else | ||
998 | { | ||
999 | prim.BaseMask = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1000 | prim.OwnerMask = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1001 | prim.NextOwnerMask = (uint)PermissionMask.Transfer; | ||
1002 | } | ||
1003 | |||
1004 | if(istest) | ||
1005 | prim.Description = "For testing only. Other uses are prohibited"; | ||
1006 | else | ||
1007 | prim.Description = ""; | ||
629 | 1008 | ||
630 | prim.Scale = scale; | 1009 | prim.Material = material; |
631 | //prim.OffsetPosition = position; | 1010 | prim.PhysicsShapeType = physicsShapeType; |
632 | rotations.Add(rotation); | ||
633 | positions.Add(position); | ||
634 | prim.UUID = UUID.Random(); | ||
635 | prim.CreatorID = owner_id; | ||
636 | prim.OwnerID = owner_id; | ||
637 | prim.GroupID = UUID.Zero; | ||
638 | prim.LastOwnerID = prim.OwnerID; | ||
639 | prim.CreationDate = Util.UnixTimeSinceEpoch(); | ||
640 | prim.Name = assetName; | ||
641 | prim.Description = ""; | ||
642 | 1011 | ||
643 | // prim.BaseMask = (uint)base_mask; | 1012 | // prim.BaseMask = (uint)base_mask; |
644 | // prim.EveryoneMask = (uint)everyone_mask; | 1013 | // prim.EveryoneMask = (uint)everyone_mask; |
@@ -646,52 +1015,64 @@ namespace OpenSim.Region.ClientStack.Linden | |||
646 | // prim.NextOwnerMask = (uint)next_owner_mask; | 1015 | // prim.NextOwnerMask = (uint)next_owner_mask; |
647 | // prim.OwnerMask = (uint)owner_mask; | 1016 | // prim.OwnerMask = (uint)owner_mask; |
648 | 1017 | ||
649 | if (grp == null) | 1018 | if (grp == null) |
650 | grp = new SceneObjectGroup(prim); | 1019 | { |
651 | else | 1020 | grp = new SceneObjectGroup(prim); |
652 | grp.AddPart(prim); | 1021 | grp.LastOwnerID = creatorID; |
653 | } | 1022 | } |
1023 | else | ||
1024 | grp.AddPart(prim); | ||
1025 | } | ||
654 | 1026 | ||
655 | Vector3 rootPos = positions[0]; | 1027 | Vector3 rootPos = positions[0]; |
656 | 1028 | ||
657 | if (grp.Parts.Length > 1) | 1029 | if (grp.Parts.Length > 1) |
658 | { | 1030 | { |
659 | // Fix first link number | 1031 | // Fix first link number |
660 | grp.RootPart.LinkNum++; | 1032 | grp.RootPart.LinkNum++; |
661 | 1033 | ||
662 | Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); | 1034 | Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); |
663 | Quaternion tmprot; | 1035 | Quaternion tmprot; |
664 | Vector3 offset; | 1036 | Vector3 offset; |
665 | 1037 | ||
666 | // fix children rotations and positions | 1038 | // fix children rotations and positions |
667 | for (int i = 1; i < rotations.Count; i++) | 1039 | for (int i = 1; i < rotations.Count; i++) |
668 | { | 1040 | { |
669 | tmprot = rotations[i]; | 1041 | tmprot = rotations[i]; |
670 | tmprot = rootRotConj * tmprot; | 1042 | tmprot = rootRotConj * tmprot; |
1043 | |||
1044 | grp.Parts[i].RotationOffset = tmprot; | ||
671 | 1045 | ||
672 | grp.Parts[i].RotationOffset = tmprot; | 1046 | offset = positions[i] - rootPos; |
673 | 1047 | ||
674 | offset = positions[i] - rootPos; | 1048 | offset *= rootRotConj; |
1049 | grp.Parts[i].OffsetPosition = offset; | ||
1050 | } | ||
675 | 1051 | ||
676 | offset *= rootRotConj; | 1052 | grp.AbsolutePosition = rootPos; |
677 | grp.Parts[i].OffsetPosition = offset; | 1053 | grp.UpdateGroupRotationR(rotations[0]); |
1054 | } | ||
1055 | else | ||
1056 | { | ||
1057 | grp.AbsolutePosition = rootPos; | ||
1058 | grp.UpdateGroupRotationR(rotations[0]); | ||
678 | } | 1059 | } |
679 | 1060 | ||
680 | grp.AbsolutePosition = rootPos; | 1061 | data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp)); |
681 | grp.UpdateGroupRotationR(rotations[0]); | ||
682 | } | 1062 | } |
683 | else | 1063 | |
1064 | else // not a mesh model | ||
684 | { | 1065 | { |
685 | grp.AbsolutePosition = rootPos; | 1066 | m_log.ErrorFormat("[CAPS Asset Upload] got unsuported assetType for object upload"); |
686 | grp.UpdateGroupRotationR(rotations[0]); | 1067 | return; |
687 | } | 1068 | } |
688 | |||
689 | data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp)); | ||
690 | } | 1069 | } |
691 | 1070 | ||
692 | AssetBase asset; | 1071 | AssetBase asset; |
693 | asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString()); | 1072 | asset = new AssetBase(assetID, assetName, assType, creatorIDstr); |
694 | asset.Data = data; | 1073 | asset.Data = data; |
1074 | if (istest) | ||
1075 | asset.Local = true; | ||
695 | if (AddNewAsset != null) | 1076 | if (AddNewAsset != null) |
696 | AddNewAsset(asset); | 1077 | AddNewAsset(asset); |
697 | else if (m_assetService != null) | 1078 | else if (m_assetService != null) |
@@ -699,11 +1080,17 @@ namespace OpenSim.Region.ClientStack.Linden | |||
699 | 1080 | ||
700 | InventoryItemBase item = new InventoryItemBase(); | 1081 | InventoryItemBase item = new InventoryItemBase(); |
701 | item.Owner = m_HostCapsObj.AgentID; | 1082 | item.Owner = m_HostCapsObj.AgentID; |
702 | item.CreatorId = m_HostCapsObj.AgentID.ToString(); | 1083 | item.CreatorId = creatorIDstr; |
703 | item.CreatorData = String.Empty; | 1084 | item.CreatorData = String.Empty; |
704 | item.ID = inventoryItem; | 1085 | item.ID = inventoryItem; |
705 | item.AssetID = asset.FullID; | 1086 | item.AssetID = asset.FullID; |
706 | item.Description = assetDescription; | 1087 | if (istest) |
1088 | { | ||
1089 | item.Description = "For testing only. Other uses are prohibited"; | ||
1090 | item.Flags = (uint) (InventoryItemFlags.SharedSingleReference); | ||
1091 | } | ||
1092 | else | ||
1093 | item.Description = assetDescription; | ||
707 | item.Name = assetName; | 1094 | item.Name = assetName; |
708 | item.AssetType = assType; | 1095 | item.AssetType = assType; |
709 | item.InvType = inType; | 1096 | item.InvType = inType; |
@@ -711,18 +1098,56 @@ namespace OpenSim.Region.ClientStack.Linden | |||
711 | 1098 | ||
712 | // If we set PermissionMask.All then when we rez the item the next permissions will replace the current | 1099 | // If we set PermissionMask.All then when we rez the item the next permissions will replace the current |
713 | // (owner) permissions. This becomes a problem if next permissions are changed. | 1100 | // (owner) permissions. This becomes a problem if next permissions are changed. |
714 | item.CurrentPermissions | ||
715 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export); | ||
716 | 1101 | ||
717 | item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | 1102 | if (restrictPerms) |
718 | item.EveryOnePermissions = 0; | 1103 | { |
719 | item.NextPermissions = (uint)PermissionMask.All; | 1104 | item.BasePermissions = (uint)(PermissionMask.Move | PermissionMask.Modify); |
1105 | item.CurrentPermissions = (uint)(PermissionMask.Move | PermissionMask.Modify); | ||
1106 | item.EveryOnePermissions = 0; | ||
1107 | item.NextPermissions = 0; | ||
1108 | } | ||
1109 | else | ||
1110 | { | ||
1111 | item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1112 | item.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1113 | item.EveryOnePermissions = 0; | ||
1114 | item.NextPermissions = (uint)PermissionMask.Transfer; | ||
1115 | } | ||
1116 | |||
720 | item.CreationDate = Util.UnixTimeSinceEpoch(); | 1117 | item.CreationDate = Util.UnixTimeSinceEpoch(); |
721 | 1118 | ||
1119 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); | ||
1120 | |||
722 | if (AddNewInventoryItem != null) | 1121 | if (AddNewInventoryItem != null) |
723 | { | 1122 | { |
724 | AddNewInventoryItem(m_HostCapsObj.AgentID, item); | 1123 | if (istest) |
1124 | { | ||
1125 | m_Scene.AddInventoryItem(client, item); | ||
1126 | /* | ||
1127 | AddNewInventoryItem(m_HostCapsObj.AgentID, item, 0); | ||
1128 | if (client != null) | ||
1129 | 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); | ||
1130 | */ | ||
1131 | } | ||
1132 | else | ||
1133 | { | ||
1134 | AddNewInventoryItem(m_HostCapsObj.AgentID, item, (uint)cost); | ||
1135 | // if (client != null) | ||
1136 | // { | ||
1137 | // // let users see anything.. i don't so far | ||
1138 | // string str; | ||
1139 | // if (cost > 0) | ||
1140 | // // dont remember where is money unit name to put here | ||
1141 | // str = "Upload complete. charged " + cost.ToString() + "$"; | ||
1142 | // else | ||
1143 | // str = "Upload complete"; | ||
1144 | // client.SendAgentAlertMessage(str, true); | ||
1145 | // } | ||
1146 | } | ||
725 | } | 1147 | } |
1148 | |||
1149 | lock (m_ModelCost) | ||
1150 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
726 | } | 1151 | } |
727 | 1152 | ||
728 | /// <summary> | 1153 | /// <summary> |
@@ -915,6 +1340,120 @@ namespace OpenSim.Region.ClientStack.Linden | |||
915 | return response; | 1340 | return response; |
916 | } | 1341 | } |
917 | 1342 | ||
1343 | public string GetObjectCost(string request, string path, | ||
1344 | string param, IOSHttpRequest httpRequest, | ||
1345 | IOSHttpResponse httpResponse) | ||
1346 | { | ||
1347 | OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); | ||
1348 | OSDMap resp = new OSDMap(); | ||
1349 | |||
1350 | OSDArray object_ids = (OSDArray)req["object_ids"]; | ||
1351 | |||
1352 | for (int i = 0; i < object_ids.Count; i++) | ||
1353 | { | ||
1354 | UUID uuid = object_ids[i].AsUUID(); | ||
1355 | |||
1356 | SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid); | ||
1357 | |||
1358 | if (part != null) | ||
1359 | { | ||
1360 | SceneObjectGroup grp = part.ParentGroup; | ||
1361 | if (grp != null) | ||
1362 | { | ||
1363 | float linksetCost; | ||
1364 | float linksetPhysCost; | ||
1365 | float partCost; | ||
1366 | float partPhysCost; | ||
1367 | |||
1368 | grp.GetResourcesCosts(part, out linksetCost, out linksetPhysCost, out partCost, out partPhysCost); | ||
1369 | |||
1370 | OSDMap object_data = new OSDMap(); | ||
1371 | object_data["linked_set_resource_cost"] = linksetCost; | ||
1372 | object_data["resource_cost"] = partCost; | ||
1373 | object_data["physics_cost"] = partPhysCost; | ||
1374 | object_data["linked_set_physics_cost"] = linksetPhysCost; | ||
1375 | |||
1376 | resp[uuid.ToString()] = object_data; | ||
1377 | } | ||
1378 | } | ||
1379 | } | ||
1380 | |||
1381 | string response = OSDParser.SerializeLLSDXmlString(resp); | ||
1382 | return response; | ||
1383 | } | ||
1384 | |||
1385 | public string ResourceCostSelected(string request, string path, | ||
1386 | string param, IOSHttpRequest httpRequest, | ||
1387 | IOSHttpResponse httpResponse) | ||
1388 | { | ||
1389 | OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); | ||
1390 | OSDMap resp = new OSDMap(); | ||
1391 | |||
1392 | |||
1393 | float phys=0; | ||
1394 | float stream=0; | ||
1395 | float simul=0; | ||
1396 | |||
1397 | if (req.ContainsKey("selected_roots")) | ||
1398 | { | ||
1399 | OSDArray object_ids = (OSDArray)req["selected_roots"]; | ||
1400 | |||
1401 | // should go by SOG suming costs for all parts | ||
1402 | // ll v3 works ok with several objects select we get the list and adds ok | ||
1403 | // FS calls per object so results are wrong guess fs bug | ||
1404 | for (int i = 0; i < object_ids.Count; i++) | ||
1405 | { | ||
1406 | UUID uuid = object_ids[i].AsUUID(); | ||
1407 | float Physc; | ||
1408 | float simulc; | ||
1409 | float streamc; | ||
1410 | |||
1411 | SceneObjectGroup grp = m_Scene.GetGroupByPrim(uuid); | ||
1412 | if (grp != null) | ||
1413 | { | ||
1414 | grp.GetSelectedCosts(out Physc, out streamc, out simulc); | ||
1415 | phys += Physc; | ||
1416 | stream += streamc; | ||
1417 | simul += simulc; | ||
1418 | } | ||
1419 | } | ||
1420 | } | ||
1421 | else if (req.ContainsKey("selected_prims")) | ||
1422 | { | ||
1423 | OSDArray object_ids = (OSDArray)req["selected_prims"]; | ||
1424 | |||
1425 | // don't see in use in any of the 2 viewers | ||
1426 | // guess it should be for edit linked but... nothing | ||
1427 | // should go to SOP per part | ||
1428 | for (int i = 0; i < object_ids.Count; i++) | ||
1429 | { | ||
1430 | UUID uuid = object_ids[i].AsUUID(); | ||
1431 | |||
1432 | SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid); | ||
1433 | if (part != null) | ||
1434 | { | ||
1435 | phys += part.PhysicsCost; | ||
1436 | stream += part.StreamingCost; | ||
1437 | simul += part.SimulationCost; | ||
1438 | } | ||
1439 | } | ||
1440 | } | ||
1441 | |||
1442 | if (simul != 0) | ||
1443 | { | ||
1444 | OSDMap object_data = new OSDMap(); | ||
1445 | |||
1446 | object_data["physics"] = phys; | ||
1447 | object_data["streaming"] = stream; | ||
1448 | object_data["simulation"] = simul; | ||
1449 | |||
1450 | resp["selected"] = object_data; | ||
1451 | } | ||
1452 | |||
1453 | string response = OSDParser.SerializeLLSDXmlString(resp); | ||
1454 | return response; | ||
1455 | } | ||
1456 | |||
918 | public string UpdateAgentInformation(string request, string path, | 1457 | public string UpdateAgentInformation(string request, string path, |
919 | string param, IOSHttpRequest httpRequest, | 1458 | string param, IOSHttpRequest httpRequest, |
920 | IOSHttpResponse httpResponse) | 1459 | IOSHttpResponse httpResponse) |
@@ -934,6 +1473,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
934 | 1473 | ||
935 | public class AssetUploader | 1474 | public class AssetUploader |
936 | { | 1475 | { |
1476 | private static readonly ILog m_log = | ||
1477 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
1478 | |||
1479 | |||
937 | public event UpLoadedAsset OnUpLoad; | 1480 | public event UpLoadedAsset OnUpLoad; |
938 | private UpLoadedAsset handlerUpLoad = null; | 1481 | private UpLoadedAsset handlerUpLoad = null; |
939 | 1482 | ||
@@ -948,10 +1491,21 @@ namespace OpenSim.Region.ClientStack.Linden | |||
948 | 1491 | ||
949 | private string m_invType = String.Empty; | 1492 | private string m_invType = String.Empty; |
950 | private string m_assetType = String.Empty; | 1493 | private string m_assetType = String.Empty; |
1494 | private int m_cost; | ||
1495 | private string m_error = String.Empty; | ||
1496 | |||
1497 | private Timer m_timeoutTimer = new Timer(); | ||
1498 | private UUID m_texturesFolder; | ||
1499 | private int m_nreqtextures; | ||
1500 | private int m_nreqmeshs; | ||
1501 | private int m_nreqinstances; | ||
1502 | private bool m_IsAtestUpload; | ||
951 | 1503 | ||
952 | public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, | 1504 | public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, |
953 | UUID parentFolderID, string invType, string assetType, string path, | 1505 | UUID parentFolderID, string invType, string assetType, string path, |
954 | IHttpServer httpServer, bool dumpAssetsToFile) | 1506 | IHttpServer httpServer, bool dumpAssetsToFile, |
1507 | int totalCost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, | ||
1508 | bool IsAtestUpload) | ||
955 | { | 1509 | { |
956 | m_assetName = assetName; | 1510 | m_assetName = assetName; |
957 | m_assetDes = description; | 1511 | m_assetDes = description; |
@@ -963,6 +1517,18 @@ namespace OpenSim.Region.ClientStack.Linden | |||
963 | m_assetType = assetType; | 1517 | m_assetType = assetType; |
964 | m_invType = invType; | 1518 | m_invType = invType; |
965 | m_dumpAssetsToFile = dumpAssetsToFile; | 1519 | m_dumpAssetsToFile = dumpAssetsToFile; |
1520 | m_cost = totalCost; | ||
1521 | |||
1522 | m_texturesFolder = texturesFolder; | ||
1523 | m_nreqtextures = nreqtextures; | ||
1524 | m_nreqmeshs = nreqmeshs; | ||
1525 | m_nreqinstances = nreqinstances; | ||
1526 | m_IsAtestUpload = IsAtestUpload; | ||
1527 | |||
1528 | m_timeoutTimer.Elapsed += TimedOut; | ||
1529 | m_timeoutTimer.Interval = 120000; | ||
1530 | m_timeoutTimer.AutoReset = false; | ||
1531 | m_timeoutTimer.Start(); | ||
966 | } | 1532 | } |
967 | 1533 | ||
968 | /// <summary> | 1534 | /// <summary> |
@@ -977,12 +1543,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
977 | UUID inv = inventoryItemID; | 1543 | UUID inv = inventoryItemID; |
978 | string res = String.Empty; | 1544 | string res = String.Empty; |
979 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | 1545 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); |
1546 | /* | ||
980 | uploadComplete.new_asset = newAssetID.ToString(); | 1547 | uploadComplete.new_asset = newAssetID.ToString(); |
981 | uploadComplete.new_inventory_item = inv; | 1548 | uploadComplete.new_inventory_item = inv; |
982 | uploadComplete.state = "complete"; | 1549 | uploadComplete.state = "complete"; |
983 | 1550 | ||
984 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | 1551 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); |
985 | 1552 | */ | |
1553 | m_timeoutTimer.Stop(); | ||
986 | httpListener.RemoveStreamHandler("POST", uploaderPath); | 1554 | httpListener.RemoveStreamHandler("POST", uploaderPath); |
987 | 1555 | ||
988 | // TODO: probably make this a better set of extensions here | 1556 | // TODO: probably make this a better set of extensions here |
@@ -999,12 +1567,49 @@ namespace OpenSim.Region.ClientStack.Linden | |||
999 | handlerUpLoad = OnUpLoad; | 1567 | handlerUpLoad = OnUpLoad; |
1000 | if (handlerUpLoad != null) | 1568 | if (handlerUpLoad != null) |
1001 | { | 1569 | { |
1002 | handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType); | 1570 | handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType, |
1571 | m_cost, m_texturesFolder, m_nreqtextures, m_nreqmeshs, m_nreqinstances, m_IsAtestUpload, ref m_error); | ||
1572 | } | ||
1573 | if (m_IsAtestUpload) | ||
1574 | { | ||
1575 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
1576 | resperror.message = "Upload SUCESSEFULL for testing purposes only. Other uses are prohibited. Item will not work after 48 hours or on other regions"; | ||
1577 | resperror.identifier = inv; | ||
1578 | |||
1579 | uploadComplete.error = resperror; | ||
1580 | uploadComplete.state = "Upload4Testing"; | ||
1003 | } | 1581 | } |
1582 | else | ||
1583 | { | ||
1584 | if (m_error == String.Empty) | ||
1585 | { | ||
1586 | uploadComplete.new_asset = newAssetID.ToString(); | ||
1587 | uploadComplete.new_inventory_item = inv; | ||
1588 | // if (m_texturesFolder != UUID.Zero) | ||
1589 | // uploadComplete.new_texture_folder_id = m_texturesFolder; | ||
1590 | uploadComplete.state = "complete"; | ||
1591 | } | ||
1592 | else | ||
1593 | { | ||
1594 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
1595 | resperror.message = m_error; | ||
1596 | resperror.identifier = inv; | ||
1004 | 1597 | ||
1598 | uploadComplete.error = resperror; | ||
1599 | uploadComplete.state = "failed"; | ||
1600 | } | ||
1601 | } | ||
1602 | |||
1603 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
1005 | return res; | 1604 | return res; |
1006 | } | 1605 | } |
1007 | 1606 | ||
1607 | private void TimedOut(object sender, ElapsedEventArgs args) | ||
1608 | { | ||
1609 | m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out mesh upload"); | ||
1610 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
1611 | } | ||
1612 | |||
1008 | ///Left this in and commented in case there are unforseen issues | 1613 | ///Left this in and commented in case there are unforseen issues |
1009 | //private void SaveAssetToFile(string filename, byte[] data) | 1614 | //private void SaveAssetToFile(string filename, byte[] data) |
1010 | //{ | 1615 | //{ |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs new file mode 100644 index 0000000..4a3fae6 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs | |||
@@ -0,0 +1,671 @@ | |||
1 | // Proprietary code of Avination Virtual Limited | ||
2 | // (c) 2012 Melanie Thielker, Leal Duarte | ||
3 | // | ||
4 | |||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Collections; | ||
8 | using System.Collections.Generic; | ||
9 | using System.Text; | ||
10 | |||
11 | using OpenMetaverse; | ||
12 | using OpenMetaverse.StructuredData; | ||
13 | |||
14 | using OpenSim.Framework; | ||
15 | using OpenSim.Region.Framework; | ||
16 | using OpenSim.Region.Framework.Scenes; | ||
17 | using OpenSim.Framework.Capabilities; | ||
18 | |||
19 | using ComponentAce.Compression.Libs.zlib; | ||
20 | |||
21 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
22 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
23 | |||
24 | namespace OpenSim.Region.ClientStack.Linden | ||
25 | { | ||
26 | public struct ModelPrimLimits | ||
27 | { | ||
28 | |||
29 | } | ||
30 | |||
31 | public class ModelCost | ||
32 | { | ||
33 | |||
34 | // upload fee defaults | ||
35 | // fees are normalized to 1.0 | ||
36 | // this parameters scale them to basic cost ( so 1.0 translates to 10 ) | ||
37 | |||
38 | public float ModelMeshCostFactor = 0.0f; // scale total cost relative to basic (excluding textures) | ||
39 | public float ModelTextureCostFactor = 1.0f; // scale textures fee to basic. | ||
40 | public float ModelMinCostFactor = 0.0f; // 0.5f; // minimum total model free excluding textures | ||
41 | |||
42 | // itens costs in normalized values | ||
43 | // ie will be multiplied by basicCost and factors above | ||
44 | public float primCreationCost = 0.002f; // extra cost for each prim creation overhead | ||
45 | // weigthed size to normalized cost | ||
46 | public float bytecost = 1e-5f; | ||
47 | |||
48 | // mesh upload fees based on compressed data sizes | ||
49 | // several data sections are counted more that once | ||
50 | // to promote user optimization | ||
51 | // following parameters control how many extra times they are added | ||
52 | // to global size. | ||
53 | // LOD meshs | ||
54 | const float medSizeWth = 1f; // 2x | ||
55 | const float lowSizeWth = 1.5f; // 2.5x | ||
56 | const float lowestSizeWth = 2f; // 3x | ||
57 | // favor potencially physical optimized meshs versus automatic decomposition | ||
58 | const float physMeshSizeWth = 6f; // counts 7x | ||
59 | const float physHullSizeWth = 8f; // counts 9x | ||
60 | |||
61 | // stream cost area factors | ||
62 | // more or less like SL | ||
63 | const float highLodFactor = 17.36f; | ||
64 | const float midLodFactor = 277.78f; | ||
65 | const float lowLodFactor = 1111.11f; | ||
66 | |||
67 | // physics cost is below, identical to SL, assuming shape type convex | ||
68 | // server cost is below identical to SL assuming non scripted non physical object | ||
69 | |||
70 | // internal | ||
71 | const int bytesPerCoord = 6; // 3 coords, 2 bytes per each | ||
72 | |||
73 | // control prims dimensions | ||
74 | public float PrimScaleMin = 0.001f; | ||
75 | public float NonPhysicalPrimScaleMax = 256f; | ||
76 | public float PhysicalPrimScaleMax = 10f; | ||
77 | public int ObjectLinkedPartsMax = 512; | ||
78 | |||
79 | // storage for a single mesh asset cost parameters | ||
80 | private class ameshCostParam | ||
81 | { | ||
82 | // LOD sizes for size dependent streaming cost | ||
83 | public int highLODSize; | ||
84 | public int medLODSize; | ||
85 | public int lowLODSize; | ||
86 | public int lowestLODSize; | ||
87 | // normalized fee based on compressed data sizes | ||
88 | public float costFee; | ||
89 | // physics cost | ||
90 | public float physicsCost; | ||
91 | } | ||
92 | |||
93 | // calculates a mesh model costs | ||
94 | // returns false on error, with a reason on parameter error | ||
95 | // resources input LLSD request | ||
96 | // basicCost input region assets upload cost | ||
97 | // totalcost returns model total upload fee | ||
98 | // meshcostdata returns detailed costs for viewer | ||
99 | public bool MeshModelCost(LLSDAssetResource resources, int basicCost, out int totalcost, | ||
100 | LLSDAssetUploadResponseData meshcostdata, out string error, ref string warning) | ||
101 | { | ||
102 | totalcost = 0; | ||
103 | error = string.Empty; | ||
104 | |||
105 | if (resources == null || | ||
106 | resources.instance_list == null || | ||
107 | resources.instance_list.Array.Count == 0) | ||
108 | { | ||
109 | error = "missing model information."; | ||
110 | return false; | ||
111 | } | ||
112 | |||
113 | int numberInstances = resources.instance_list.Array.Count; | ||
114 | |||
115 | if( numberInstances > ObjectLinkedPartsMax ) | ||
116 | { | ||
117 | error = "Model whould have more than " + ObjectLinkedPartsMax.ToString() + " linked prims"; | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | meshcostdata.model_streaming_cost = 0.0; | ||
122 | meshcostdata.simulation_cost = 0.0; | ||
123 | meshcostdata.physics_cost = 0.0; | ||
124 | meshcostdata.resource_cost = 0.0; | ||
125 | |||
126 | meshcostdata.upload_price_breakdown.mesh_instance = 0; | ||
127 | meshcostdata.upload_price_breakdown.mesh_physics = 0; | ||
128 | meshcostdata.upload_price_breakdown.mesh_streaming = 0; | ||
129 | meshcostdata.upload_price_breakdown.model = 0; | ||
130 | |||
131 | int itmp; | ||
132 | |||
133 | // textures cost | ||
134 | if (resources.texture_list != null && resources.texture_list.Array.Count > 0) | ||
135 | { | ||
136 | float textures_cost = (float)(resources.texture_list.Array.Count * basicCost); | ||
137 | textures_cost *= ModelTextureCostFactor; | ||
138 | |||
139 | itmp = (int)(textures_cost + 0.5f); // round | ||
140 | meshcostdata.upload_price_breakdown.texture = itmp; | ||
141 | totalcost += itmp; | ||
142 | } | ||
143 | |||
144 | // meshs assets cost | ||
145 | float meshsfee = 0; | ||
146 | int numberMeshs = 0; | ||
147 | bool haveMeshs = false; | ||
148 | List<ameshCostParam> meshsCosts = new List<ameshCostParam>(); | ||
149 | |||
150 | if (resources.mesh_list != null && resources.mesh_list.Array.Count > 0) | ||
151 | { | ||
152 | numberMeshs = resources.mesh_list.Array.Count; | ||
153 | |||
154 | for (int i = 0; i < numberMeshs; i++) | ||
155 | { | ||
156 | ameshCostParam curCost = new ameshCostParam(); | ||
157 | byte[] data = (byte[])resources.mesh_list.Array[i]; | ||
158 | |||
159 | if (!MeshCost(data, curCost, out error)) | ||
160 | { | ||
161 | return false; | ||
162 | } | ||
163 | meshsCosts.Add(curCost); | ||
164 | meshsfee += curCost.costFee; | ||
165 | } | ||
166 | haveMeshs = true; | ||
167 | } | ||
168 | |||
169 | // instances (prims) cost | ||
170 | |||
171 | |||
172 | int mesh; | ||
173 | int skipedSmall = 0; | ||
174 | for (int i = 0; i < numberInstances; i++) | ||
175 | { | ||
176 | Hashtable inst = (Hashtable)resources.instance_list.Array[i]; | ||
177 | |||
178 | ArrayList ascale = (ArrayList)inst["scale"]; | ||
179 | Vector3 scale; | ||
180 | double tmp; | ||
181 | tmp = (double)ascale[0]; | ||
182 | scale.X = (float)tmp; | ||
183 | tmp = (double)ascale[1]; | ||
184 | scale.Y = (float)tmp; | ||
185 | tmp = (double)ascale[2]; | ||
186 | scale.Z = (float)tmp; | ||
187 | |||
188 | if (scale.X < PrimScaleMin || scale.Y < PrimScaleMin || scale.Z < PrimScaleMin) | ||
189 | { | ||
190 | skipedSmall++; | ||
191 | continue; | ||
192 | } | ||
193 | |||
194 | if (scale.X > NonPhysicalPrimScaleMax || scale.Y > NonPhysicalPrimScaleMax || scale.Z > NonPhysicalPrimScaleMax) | ||
195 | { | ||
196 | error = "Model contains parts with sides larger than " + NonPhysicalPrimScaleMax.ToString() + "m. Please ajust scale"; | ||
197 | return false; | ||
198 | } | ||
199 | |||
200 | if (haveMeshs && inst.ContainsKey("mesh")) | ||
201 | { | ||
202 | mesh = (int)inst["mesh"]; | ||
203 | |||
204 | if (mesh >= numberMeshs) | ||
205 | { | ||
206 | error = "Incoerent model information."; | ||
207 | return false; | ||
208 | } | ||
209 | |||
210 | // streamming cost | ||
211 | |||
212 | float sqdiam = scale.LengthSquared(); | ||
213 | |||
214 | ameshCostParam curCost = meshsCosts[mesh]; | ||
215 | float mesh_streaming = streamingCost(curCost, sqdiam); | ||
216 | |||
217 | meshcostdata.model_streaming_cost += mesh_streaming; | ||
218 | meshcostdata.physics_cost += curCost.physicsCost; | ||
219 | } | ||
220 | else // instance as no mesh ?? | ||
221 | { | ||
222 | // to do later if needed | ||
223 | meshcostdata.model_streaming_cost += 0.5f; | ||
224 | meshcostdata.physics_cost += 1.0f; | ||
225 | } | ||
226 | |||
227 | // assume unscripted and static prim server cost | ||
228 | meshcostdata.simulation_cost += 0.5f; | ||
229 | // charge for prims creation | ||
230 | meshsfee += primCreationCost; | ||
231 | } | ||
232 | |||
233 | if (skipedSmall > 0) | ||
234 | { | ||
235 | if (skipedSmall > numberInstances / 2) | ||
236 | { | ||
237 | error = "Model contains too many prims smaller than " + PrimScaleMin.ToString() + | ||
238 | "m minimum allowed size. Please check scalling"; | ||
239 | return false; | ||
240 | } | ||
241 | else | ||
242 | warning += skipedSmall.ToString() + " of the requested " +numberInstances.ToString() + | ||
243 | " model prims will not upload because they are smaller than " + PrimScaleMin.ToString() + | ||
244 | "m minimum allowed size. Please check scalling "; | ||
245 | } | ||
246 | |||
247 | if (meshcostdata.physics_cost <= meshcostdata.model_streaming_cost) | ||
248 | meshcostdata.resource_cost = meshcostdata.model_streaming_cost; | ||
249 | else | ||
250 | meshcostdata.resource_cost = meshcostdata.physics_cost; | ||
251 | |||
252 | if (meshcostdata.resource_cost < meshcostdata.simulation_cost) | ||
253 | meshcostdata.resource_cost = meshcostdata.simulation_cost; | ||
254 | |||
255 | // scale cost | ||
256 | // at this point a cost of 1.0 whould mean basic cost | ||
257 | meshsfee *= ModelMeshCostFactor; | ||
258 | |||
259 | if (meshsfee < ModelMinCostFactor) | ||
260 | meshsfee = ModelMinCostFactor; | ||
261 | |||
262 | // actually scale it to basic cost | ||
263 | meshsfee *= (float)basicCost; | ||
264 | |||
265 | meshsfee += 0.5f; // rounding | ||
266 | |||
267 | totalcost += (int)meshsfee; | ||
268 | |||
269 | // breakdown prices | ||
270 | // don't seem to be in use so removed code for now | ||
271 | |||
272 | return true; | ||
273 | } | ||
274 | |||
275 | // single mesh asset cost | ||
276 | private bool MeshCost(byte[] data, ameshCostParam cost, out string error) | ||
277 | { | ||
278 | cost.highLODSize = 0; | ||
279 | cost.medLODSize = 0; | ||
280 | cost.lowLODSize = 0; | ||
281 | cost.lowestLODSize = 0; | ||
282 | cost.physicsCost = 0.0f; | ||
283 | cost.costFee = 0.0f; | ||
284 | |||
285 | error = string.Empty; | ||
286 | |||
287 | if (data == null || data.Length == 0) | ||
288 | { | ||
289 | error = "Missing model information."; | ||
290 | return false; | ||
291 | } | ||
292 | |||
293 | OSD meshOsd = null; | ||
294 | int start = 0; | ||
295 | |||
296 | error = "Invalid model data"; | ||
297 | |||
298 | using (MemoryStream ms = new MemoryStream(data)) | ||
299 | { | ||
300 | try | ||
301 | { | ||
302 | OSD osd = OSDParser.DeserializeLLSDBinary(ms); | ||
303 | if (osd is OSDMap) | ||
304 | meshOsd = (OSDMap)osd; | ||
305 | else | ||
306 | return false; | ||
307 | } | ||
308 | catch (Exception e) | ||
309 | { | ||
310 | return false; | ||
311 | } | ||
312 | start = (int)ms.Position; | ||
313 | } | ||
314 | |||
315 | OSDMap map = (OSDMap)meshOsd; | ||
316 | OSDMap tmpmap; | ||
317 | |||
318 | int highlod_size = 0; | ||
319 | int medlod_size = 0; | ||
320 | int lowlod_size = 0; | ||
321 | int lowestlod_size = 0; | ||
322 | int skin_size = 0; | ||
323 | |||
324 | int hulls_size = 0; | ||
325 | int phys_nhulls; | ||
326 | int phys_hullsvertices = 0; | ||
327 | |||
328 | int physmesh_size = 0; | ||
329 | int phys_ntriangles = 0; | ||
330 | |||
331 | int submesh_offset = -1; | ||
332 | |||
333 | if (map.ContainsKey("physics_convex")) | ||
334 | { | ||
335 | tmpmap = (OSDMap)map["physics_convex"]; | ||
336 | if (tmpmap.ContainsKey("offset")) | ||
337 | submesh_offset = tmpmap["offset"].AsInteger() + start; | ||
338 | if (tmpmap.ContainsKey("size")) | ||
339 | hulls_size = tmpmap["size"].AsInteger(); | ||
340 | } | ||
341 | |||
342 | if (submesh_offset < 0 || hulls_size == 0) | ||
343 | { | ||
344 | error = "Missing physics_convex block"; | ||
345 | return false; | ||
346 | } | ||
347 | |||
348 | if (!hulls(data, submesh_offset, hulls_size, out phys_hullsvertices, out phys_nhulls)) | ||
349 | { | ||
350 | error = "Bad physics_convex block"; | ||
351 | return false; | ||
352 | } | ||
353 | |||
354 | submesh_offset = -1; | ||
355 | |||
356 | // only look for LOD meshs sizes | ||
357 | |||
358 | if (map.ContainsKey("high_lod")) | ||
359 | { | ||
360 | tmpmap = (OSDMap)map["high_lod"]; | ||
361 | // see at least if there is a offset for this one | ||
362 | if (tmpmap.ContainsKey("offset")) | ||
363 | submesh_offset = tmpmap["offset"].AsInteger() + start; | ||
364 | if (tmpmap.ContainsKey("size")) | ||
365 | highlod_size = tmpmap["size"].AsInteger(); | ||
366 | } | ||
367 | |||
368 | if (submesh_offset < 0 || highlod_size <= 0) | ||
369 | { | ||
370 | error = "Missing high_lod block"; | ||
371 | return false; | ||
372 | } | ||
373 | |||
374 | bool haveprev = true; | ||
375 | |||
376 | if (map.ContainsKey("medium_lod")) | ||
377 | { | ||
378 | tmpmap = (OSDMap)map["medium_lod"]; | ||
379 | if (tmpmap.ContainsKey("size")) | ||
380 | medlod_size = tmpmap["size"].AsInteger(); | ||
381 | else | ||
382 | haveprev = false; | ||
383 | } | ||
384 | |||
385 | if (haveprev && map.ContainsKey("low_lod")) | ||
386 | { | ||
387 | tmpmap = (OSDMap)map["low_lod"]; | ||
388 | if (tmpmap.ContainsKey("size")) | ||
389 | lowlod_size = tmpmap["size"].AsInteger(); | ||
390 | else | ||
391 | haveprev = false; | ||
392 | } | ||
393 | |||
394 | if (haveprev && map.ContainsKey("lowest_lod")) | ||
395 | { | ||
396 | tmpmap = (OSDMap)map["lowest_lod"]; | ||
397 | if (tmpmap.ContainsKey("size")) | ||
398 | lowestlod_size = tmpmap["size"].AsInteger(); | ||
399 | } | ||
400 | |||
401 | if (map.ContainsKey("skin")) | ||
402 | { | ||
403 | tmpmap = (OSDMap)map["skin"]; | ||
404 | if (tmpmap.ContainsKey("size")) | ||
405 | skin_size = tmpmap["size"].AsInteger(); | ||
406 | } | ||
407 | |||
408 | cost.highLODSize = highlod_size; | ||
409 | cost.medLODSize = medlod_size; | ||
410 | cost.lowLODSize = lowlod_size; | ||
411 | cost.lowestLODSize = lowestlod_size; | ||
412 | |||
413 | submesh_offset = -1; | ||
414 | |||
415 | tmpmap = null; | ||
416 | if(map.ContainsKey("physics_mesh")) | ||
417 | tmpmap = (OSDMap)map["physics_mesh"]; | ||
418 | else if (map.ContainsKey("physics_shape")) // old naming | ||
419 | tmpmap = (OSDMap)map["physics_shape"]; | ||
420 | |||
421 | if(tmpmap != null) | ||
422 | { | ||
423 | if (tmpmap.ContainsKey("offset")) | ||
424 | submesh_offset = tmpmap["offset"].AsInteger() + start; | ||
425 | if (tmpmap.ContainsKey("size")) | ||
426 | physmesh_size = tmpmap["size"].AsInteger(); | ||
427 | |||
428 | if (submesh_offset >= 0 || physmesh_size > 0) | ||
429 | { | ||
430 | |||
431 | if (!submesh(data, submesh_offset, physmesh_size, out phys_ntriangles)) | ||
432 | { | ||
433 | error = "Model data parsing error"; | ||
434 | return false; | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | |||
439 | // upload is done in convex shape type so only one hull | ||
440 | phys_hullsvertices++; | ||
441 | cost.physicsCost = 0.04f * phys_hullsvertices; | ||
442 | |||
443 | float sfee; | ||
444 | |||
445 | sfee = data.Length; // start with total compressed data size | ||
446 | |||
447 | // penalize lod meshs that should be more builder optimized | ||
448 | sfee += medSizeWth * medlod_size; | ||
449 | sfee += lowSizeWth * lowlod_size; | ||
450 | sfee += lowestSizeWth * lowlod_size; | ||
451 | |||
452 | // physics | ||
453 | // favor potencial optimized meshs versus automatic decomposition | ||
454 | if (physmesh_size != 0) | ||
455 | sfee += physMeshSizeWth * (physmesh_size + hulls_size / 4); // reduce cost of mandatory convex hull | ||
456 | else | ||
457 | sfee += physHullSizeWth * hulls_size; | ||
458 | |||
459 | // bytes to money | ||
460 | sfee *= bytecost; | ||
461 | |||
462 | cost.costFee = sfee; | ||
463 | return true; | ||
464 | } | ||
465 | |||
466 | // parses a LOD or physics mesh component | ||
467 | private bool submesh(byte[] data, int offset, int size, out int ntriangles) | ||
468 | { | ||
469 | ntriangles = 0; | ||
470 | |||
471 | OSD decodedMeshOsd = new OSD(); | ||
472 | byte[] meshBytes = new byte[size]; | ||
473 | System.Buffer.BlockCopy(data, offset, meshBytes, 0, size); | ||
474 | try | ||
475 | { | ||
476 | using (MemoryStream inMs = new MemoryStream(meshBytes)) | ||
477 | { | ||
478 | using (MemoryStream outMs = new MemoryStream()) | ||
479 | { | ||
480 | using (ZOutputStream zOut = new ZOutputStream(outMs)) | ||
481 | { | ||
482 | byte[] readBuffer = new byte[4096]; | ||
483 | int readLen = 0; | ||
484 | while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0) | ||
485 | { | ||
486 | zOut.Write(readBuffer, 0, readLen); | ||
487 | } | ||
488 | zOut.Flush(); | ||
489 | outMs.Seek(0, SeekOrigin.Begin); | ||
490 | |||
491 | byte[] decompressedBuf = outMs.GetBuffer(); | ||
492 | decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf); | ||
493 | } | ||
494 | } | ||
495 | } | ||
496 | } | ||
497 | catch (Exception e) | ||
498 | { | ||
499 | return false; | ||
500 | } | ||
501 | |||
502 | OSDArray decodedMeshOsdArray = null; | ||
503 | if ((!decodedMeshOsd is OSDArray)) | ||
504 | return false; | ||
505 | |||
506 | byte[] dummy; | ||
507 | |||
508 | decodedMeshOsdArray = (OSDArray)decodedMeshOsd; | ||
509 | foreach (OSD subMeshOsd in decodedMeshOsdArray) | ||
510 | { | ||
511 | if (subMeshOsd is OSDMap) | ||
512 | { | ||
513 | OSDMap subtmpmap = (OSDMap)subMeshOsd; | ||
514 | if (subtmpmap.ContainsKey("NoGeometry") && ((OSDBoolean)subtmpmap["NoGeometry"])) | ||
515 | continue; | ||
516 | |||
517 | if (!subtmpmap.ContainsKey("Position")) | ||
518 | return false; | ||
519 | |||
520 | if (subtmpmap.ContainsKey("TriangleList")) | ||
521 | { | ||
522 | dummy = subtmpmap["TriangleList"].AsBinary(); | ||
523 | ntriangles += dummy.Length / bytesPerCoord; | ||
524 | } | ||
525 | else | ||
526 | return false; | ||
527 | } | ||
528 | } | ||
529 | |||
530 | return true; | ||
531 | } | ||
532 | |||
533 | // parses convex hulls component | ||
534 | private bool hulls(byte[] data, int offset, int size, out int nvertices, out int nhulls) | ||
535 | { | ||
536 | nvertices = 0; | ||
537 | nhulls = 1; | ||
538 | |||
539 | OSD decodedMeshOsd = new OSD(); | ||
540 | byte[] meshBytes = new byte[size]; | ||
541 | System.Buffer.BlockCopy(data, offset, meshBytes, 0, size); | ||
542 | try | ||
543 | { | ||
544 | using (MemoryStream inMs = new MemoryStream(meshBytes)) | ||
545 | { | ||
546 | using (MemoryStream outMs = new MemoryStream()) | ||
547 | { | ||
548 | using (ZOutputStream zOut = new ZOutputStream(outMs)) | ||
549 | { | ||
550 | byte[] readBuffer = new byte[4096]; | ||
551 | int readLen = 0; | ||
552 | while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0) | ||
553 | { | ||
554 | zOut.Write(readBuffer, 0, readLen); | ||
555 | } | ||
556 | zOut.Flush(); | ||
557 | outMs.Seek(0, SeekOrigin.Begin); | ||
558 | |||
559 | byte[] decompressedBuf = outMs.GetBuffer(); | ||
560 | decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf); | ||
561 | } | ||
562 | } | ||
563 | } | ||
564 | } | ||
565 | catch (Exception e) | ||
566 | { | ||
567 | return false; | ||
568 | } | ||
569 | |||
570 | OSDMap cmap = (OSDMap)decodedMeshOsd; | ||
571 | if (cmap == null) | ||
572 | return false; | ||
573 | |||
574 | byte[] dummy; | ||
575 | |||
576 | // must have one of this | ||
577 | if (cmap.ContainsKey("BoundingVerts")) | ||
578 | { | ||
579 | dummy = cmap["BoundingVerts"].AsBinary(); | ||
580 | nvertices = dummy.Length / bytesPerCoord; | ||
581 | } | ||
582 | else | ||
583 | return false; | ||
584 | |||
585 | /* upload is done with convex shape type | ||
586 | if (cmap.ContainsKey("HullList")) | ||
587 | { | ||
588 | dummy = cmap["HullList"].AsBinary(); | ||
589 | nhulls += dummy.Length; | ||
590 | } | ||
591 | |||
592 | |||
593 | if (cmap.ContainsKey("Positions")) | ||
594 | { | ||
595 | dummy = cmap["Positions"].AsBinary(); | ||
596 | nvertices = dummy.Length / bytesPerCoord; | ||
597 | } | ||
598 | */ | ||
599 | |||
600 | return true; | ||
601 | } | ||
602 | |||
603 | // returns streaming cost from on mesh LODs sizes in curCost and square of prim size length | ||
604 | private float streamingCost(ameshCostParam curCost, float sqdiam) | ||
605 | { | ||
606 | // compute efective areas | ||
607 | float ma = 262144f; | ||
608 | |||
609 | float mh = sqdiam * highLodFactor; | ||
610 | if (mh > ma) | ||
611 | mh = ma; | ||
612 | float mm = sqdiam * midLodFactor; | ||
613 | if (mm > ma) | ||
614 | mm = ma; | ||
615 | |||
616 | float ml = sqdiam * lowLodFactor; | ||
617 | if (ml > ma) | ||
618 | ml = ma; | ||
619 | |||
620 | float mlst = ma; | ||
621 | |||
622 | mlst -= ml; | ||
623 | ml -= mm; | ||
624 | mm -= mh; | ||
625 | |||
626 | if (mlst < 1.0f) | ||
627 | mlst = 1.0f; | ||
628 | if (ml < 1.0f) | ||
629 | ml = 1.0f; | ||
630 | if (mm < 1.0f) | ||
631 | mm = 1.0f; | ||
632 | if (mh < 1.0f) | ||
633 | mh = 1.0f; | ||
634 | |||
635 | ma = mlst + ml + mm + mh; | ||
636 | |||
637 | // get LODs compressed sizes | ||
638 | // giving 384 bytes bonus | ||
639 | int lst = curCost.lowestLODSize - 384; | ||
640 | int l = curCost.lowLODSize - 384; | ||
641 | int m = curCost.medLODSize - 384; | ||
642 | int h = curCost.highLODSize - 384; | ||
643 | |||
644 | // use previus higher LOD size on missing ones | ||
645 | if (m <= 0) | ||
646 | m = h; | ||
647 | if (l <= 0) | ||
648 | l = m; | ||
649 | if (lst <= 0) | ||
650 | lst = l; | ||
651 | |||
652 | // force minumum sizes | ||
653 | if (lst < 16) | ||
654 | lst = 16; | ||
655 | if (l < 16) | ||
656 | l = 16; | ||
657 | if (m < 16) | ||
658 | m = 16; | ||
659 | if (h < 16) | ||
660 | h = 16; | ||
661 | |||
662 | // compute cost weighted by relative effective areas | ||
663 | float cost = (float)lst * mlst + (float)l * ml + (float)m * mm + (float)h * mh; | ||
664 | cost /= ma; | ||
665 | |||
666 | cost *= 0.004f; // overall tunning parameter | ||
667 | |||
668 | return cost; | ||
669 | } | ||
670 | } | ||
671 | } | ||
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index c28ba94..725bf06 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs | |||
@@ -451,8 +451,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
451 | responsedata["content_type"] = "text/plain"; | 451 | responsedata["content_type"] = "text/plain"; |
452 | responsedata["keepalive"] = false; | 452 | responsedata["keepalive"] = false; |
453 | responsedata["reusecontext"] = false; | 453 | responsedata["reusecontext"] = false; |
454 | responsedata["str_response_string"] = "Upstream error: "; | 454 | responsedata["str_response_string"] = "<llsd></llsd>"; |
455 | responsedata["error_status_text"] = "Upstream error:"; | 455 | responsedata["error_status_text"] = "<llsd></llsd>"; |
456 | responsedata["http_protocol_version"] = "HTTP/1.0"; | 456 | responsedata["http_protocol_version"] = "HTTP/1.0"; |
457 | return responsedata; | 457 | return responsedata; |
458 | } | 458 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs index dab727f..7dcf137 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs | |||
@@ -151,6 +151,12 @@ namespace OpenSim.Region.ClientStack.Linden | |||
151 | ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, | 151 | ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, |
152 | uint locationID, uint flags, string capsURL, UUID agentID) | 152 | uint locationID, uint flags, string capsURL, UUID agentID) |
153 | { | 153 | { |
154 | // not sure why flags get overwritten here | ||
155 | if ((flags & (uint)TeleportFlags.IsFlying) != 0) | ||
156 | flags = (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.IsFlying; | ||
157 | else | ||
158 | flags = (uint)TeleportFlags.ViaLocation; | ||
159 | |||
154 | OSDMap info = new OSDMap(); | 160 | OSDMap info = new OSDMap(); |
155 | info.Add("AgentID", OSD.FromUUID(agentID)); | 161 | info.Add("AgentID", OSD.FromUUID(agentID)); |
156 | info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this? | 162 | info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this? |
@@ -159,7 +165,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
159 | info.Add("SimAccess", OSD.FromInteger(simAccess)); | 165 | info.Add("SimAccess", OSD.FromInteger(simAccess)); |
160 | info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); | 166 | info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); |
161 | info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); | 167 | info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); |
162 | info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation | 168 | // info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation |
169 | info.Add("TeleportFlags", OSD.FromUInteger(flags)); | ||
163 | 170 | ||
164 | OSDArray infoArr = new OSDArray(); | 171 | OSDArray infoArr = new OSDArray(); |
165 | infoArr.Add(info); | 172 | infoArr.Add(info); |
@@ -398,7 +405,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
398 | public static OSD partPhysicsProperties(uint localID, byte physhapetype, | 405 | public static OSD partPhysicsProperties(uint localID, byte physhapetype, |
399 | float density, float friction, float bounce, float gravmod) | 406 | float density, float friction, float bounce, float gravmod) |
400 | { | 407 | { |
401 | 408 | ||
402 | OSDMap physinfo = new OSDMap(6); | 409 | OSDMap physinfo = new OSDMap(6); |
403 | physinfo["LocalID"] = localID; | 410 | physinfo["LocalID"] = localID; |
404 | physinfo["Density"] = density; | 411 | physinfo["Density"] = density; |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs index 8e1f63a..7b15284 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs | |||
@@ -27,11 +27,14 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | ||
30 | using System.Collections.Specialized; | 31 | using System.Collections.Specialized; |
31 | using System.Reflection; | 32 | using System.Reflection; |
32 | using System.IO; | 33 | using System.IO; |
34 | using System.Threading; | ||
33 | using System.Web; | 35 | using System.Web; |
34 | using Mono.Addins; | 36 | using Mono.Addins; |
37 | using OpenSim.Framework.Monitoring; | ||
35 | using log4net; | 38 | using log4net; |
36 | using Nini.Config; | 39 | using Nini.Config; |
37 | using OpenMetaverse; | 40 | using OpenMetaverse; |
@@ -57,9 +60,45 @@ namespace OpenSim.Region.ClientStack.Linden | |||
57 | private IAssetService m_AssetService; | 60 | private IAssetService m_AssetService; |
58 | private bool m_Enabled = true; | 61 | private bool m_Enabled = true; |
59 | private string m_URL; | 62 | private string m_URL; |
63 | |||
64 | struct aPollRequest | ||
65 | { | ||
66 | public PollServiceMeshEventArgs thepoll; | ||
67 | public UUID reqID; | ||
68 | public Hashtable request; | ||
69 | } | ||
70 | |||
71 | public class aPollResponse | ||
72 | { | ||
73 | public Hashtable response; | ||
74 | public int bytes; | ||
75 | public int lod; | ||
76 | } | ||
77 | |||
78 | |||
79 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
80 | |||
81 | private static GetMeshHandler m_getMeshHandler; | ||
82 | |||
83 | private IAssetService m_assetService = null; | ||
84 | |||
85 | private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>(); | ||
86 | private static Thread[] m_workerThreads = null; | ||
87 | |||
88 | private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue = | ||
89 | new OpenMetaverse.BlockingQueue<aPollRequest>(); | ||
90 | |||
91 | private Dictionary<UUID, PollServiceMeshEventArgs> m_pollservices = new Dictionary<UUID, PollServiceMeshEventArgs>(); | ||
60 | 92 | ||
61 | #region Region Module interfaceBase Members | 93 | #region Region Module interfaceBase Members |
62 | 94 | ||
95 | ~GetMeshModule() | ||
96 | { | ||
97 | foreach (Thread t in m_workerThreads) | ||
98 | Watchdog.AbortThread(t.ManagedThreadId); | ||
99 | |||
100 | } | ||
101 | |||
63 | public Type ReplaceableInterface | 102 | public Type ReplaceableInterface |
64 | { | 103 | { |
65 | get { return null; } | 104 | get { return null; } |
@@ -75,6 +114,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
75 | // Cap doesn't exist | 114 | // Cap doesn't exist |
76 | if (m_URL != string.Empty) | 115 | if (m_URL != string.Empty) |
77 | m_Enabled = true; | 116 | m_Enabled = true; |
117 | |||
78 | } | 118 | } |
79 | 119 | ||
80 | public void AddRegion(Scene pScene) | 120 | public void AddRegion(Scene pScene) |
@@ -83,6 +123,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
83 | return; | 123 | return; |
84 | 124 | ||
85 | m_scene = pScene; | 125 | m_scene = pScene; |
126 | |||
127 | m_assetService = pScene.AssetService; | ||
86 | } | 128 | } |
87 | 129 | ||
88 | public void RemoveRegion(Scene scene) | 130 | public void RemoveRegion(Scene scene) |
@@ -91,6 +133,9 @@ namespace OpenSim.Region.ClientStack.Linden | |||
91 | return; | 133 | return; |
92 | 134 | ||
93 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | 135 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; |
136 | m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; | ||
137 | m_scene.EventManager.OnThrottleUpdate -= ThrottleUpdate; | ||
138 | |||
94 | m_scene = null; | 139 | m_scene = null; |
95 | } | 140 | } |
96 | 141 | ||
@@ -101,6 +146,27 @@ namespace OpenSim.Region.ClientStack.Linden | |||
101 | 146 | ||
102 | m_AssetService = m_scene.RequestModuleInterface<IAssetService>(); | 147 | m_AssetService = m_scene.RequestModuleInterface<IAssetService>(); |
103 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 148 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
149 | // We'll reuse the same handler for all requests. | ||
150 | m_getMeshHandler = new GetMeshHandler(m_assetService); | ||
151 | m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; | ||
152 | m_scene.EventManager.OnThrottleUpdate += ThrottleUpdate; | ||
153 | |||
154 | if (m_workerThreads == null) | ||
155 | { | ||
156 | m_workerThreads = new Thread[2]; | ||
157 | |||
158 | for (uint i = 0; i < 2; i++) | ||
159 | { | ||
160 | m_workerThreads[i] = Watchdog.StartThread(DoMeshRequests, | ||
161 | String.Format("MeshWorkerThread{0}", i), | ||
162 | ThreadPriority.Normal, | ||
163 | false, | ||
164 | false, | ||
165 | null, | ||
166 | int.MaxValue); | ||
167 | } | ||
168 | } | ||
169 | |||
104 | } | 170 | } |
105 | 171 | ||
106 | 172 | ||
@@ -110,25 +176,212 @@ namespace OpenSim.Region.ClientStack.Linden | |||
110 | 176 | ||
111 | #endregion | 177 | #endregion |
112 | 178 | ||
179 | private void DoMeshRequests() | ||
180 | { | ||
181 | while (true) | ||
182 | { | ||
183 | aPollRequest poolreq = m_queue.Dequeue(); | ||
184 | |||
185 | poolreq.thepoll.Process(poolreq); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | // Now we know when the throttle is changed by the client in the case of a root agent or by a neighbor region in the case of a child agent. | ||
190 | public void ThrottleUpdate(ScenePresence p) | ||
191 | { | ||
192 | byte[] throttles = p.ControllingClient.GetThrottlesPacked(1); | ||
193 | UUID user = p.UUID; | ||
194 | int imagethrottle = ExtractTaskThrottle(throttles); | ||
195 | PollServiceMeshEventArgs args; | ||
196 | if (m_pollservices.TryGetValue(user, out args)) | ||
197 | { | ||
198 | args.UpdateThrottle(imagethrottle, p); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | private int ExtractTaskThrottle(byte[] pthrottles) | ||
203 | { | ||
204 | |||
205 | byte[] adjData; | ||
206 | int pos = 0; | ||
207 | |||
208 | if (!BitConverter.IsLittleEndian) | ||
209 | { | ||
210 | byte[] newData = new byte[7 * 4]; | ||
211 | Buffer.BlockCopy(pthrottles, 0, newData, 0, 7 * 4); | ||
212 | |||
213 | for (int i = 0; i < 7; i++) | ||
214 | Array.Reverse(newData, i * 4, 4); | ||
215 | |||
216 | adjData = newData; | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | adjData = pthrottles; | ||
221 | } | ||
222 | |||
223 | // 0.125f converts from bits to bytes | ||
224 | //int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
225 | //pos += 4; | ||
226 | // int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
227 | //pos += 4; | ||
228 | // int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
229 | // pos += 4; | ||
230 | // int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
231 | // pos += 4; | ||
232 | pos += 16; | ||
233 | int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
234 | // pos += 4; | ||
235 | //int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); //pos += 4; | ||
236 | //int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
237 | return task; | ||
238 | } | ||
239 | |||
240 | private class PollServiceMeshEventArgs : PollServiceEventArgs | ||
241 | { | ||
242 | private List<Hashtable> requests = | ||
243 | new List<Hashtable>(); | ||
244 | private Dictionary<UUID, aPollResponse> responses = | ||
245 | new Dictionary<UUID, aPollResponse>(); | ||
246 | |||
247 | private Scene m_scene; | ||
248 | private MeshCapsDataThrottler m_throttler; | ||
249 | public PollServiceMeshEventArgs(string uri, UUID pId, Scene scene) : | ||
250 | base(null, uri, null, null, null, pId, int.MaxValue) | ||
251 | { | ||
252 | m_scene = scene; | ||
253 | m_throttler = new MeshCapsDataThrottler(100000, 1400000, 10000, scene, pId); | ||
254 | // x is request id, y is userid | ||
255 | HasEvents = (x, y) => | ||
256 | { | ||
257 | lock (responses) | ||
258 | { | ||
259 | bool ret = m_throttler.hasEvents(x, responses); | ||
260 | m_throttler.ProcessTime(); | ||
261 | return ret; | ||
262 | |||
263 | } | ||
264 | }; | ||
265 | GetEvents = (x, y) => | ||
266 | { | ||
267 | lock (responses) | ||
268 | { | ||
269 | try | ||
270 | { | ||
271 | return responses[x].response; | ||
272 | } | ||
273 | finally | ||
274 | { | ||
275 | m_throttler.ProcessTime(); | ||
276 | responses.Remove(x); | ||
277 | } | ||
278 | } | ||
279 | }; | ||
280 | // x is request id, y is request data hashtable | ||
281 | Request = (x, y) => | ||
282 | { | ||
283 | aPollRequest reqinfo = new aPollRequest(); | ||
284 | reqinfo.thepoll = this; | ||
285 | reqinfo.reqID = x; | ||
286 | reqinfo.request = y; | ||
287 | |||
288 | m_queue.Enqueue(reqinfo); | ||
289 | }; | ||
290 | |||
291 | // this should never happen except possible on shutdown | ||
292 | NoEvents = (x, y) => | ||
293 | { | ||
294 | /* | ||
295 | lock (requests) | ||
296 | { | ||
297 | Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); | ||
298 | requests.Remove(request); | ||
299 | } | ||
300 | */ | ||
301 | Hashtable response = new Hashtable(); | ||
302 | |||
303 | response["int_response_code"] = 500; | ||
304 | response["str_response_string"] = "Script timeout"; | ||
305 | response["content_type"] = "text/plain"; | ||
306 | response["keepalive"] = false; | ||
307 | response["reusecontext"] = false; | ||
308 | |||
309 | return response; | ||
310 | }; | ||
311 | } | ||
312 | |||
313 | public void Process(aPollRequest requestinfo) | ||
314 | { | ||
315 | Hashtable response; | ||
316 | |||
317 | UUID requestID = requestinfo.reqID; | ||
318 | |||
319 | // If the avatar is gone, don't bother to get the texture | ||
320 | if (m_scene.GetScenePresence(Id) == null) | ||
321 | { | ||
322 | response = new Hashtable(); | ||
323 | |||
324 | response["int_response_code"] = 500; | ||
325 | response["str_response_string"] = "Script timeout"; | ||
326 | response["content_type"] = "text/plain"; | ||
327 | response["keepalive"] = false; | ||
328 | response["reusecontext"] = false; | ||
329 | |||
330 | lock (responses) | ||
331 | responses[requestID] = new aPollResponse() { bytes = 0, response = response, lod = 0 }; | ||
332 | |||
333 | return; | ||
334 | } | ||
335 | |||
336 | response = m_getMeshHandler.Handle(requestinfo.request); | ||
337 | lock (responses) | ||
338 | { | ||
339 | responses[requestID] = new aPollResponse() | ||
340 | { | ||
341 | bytes = (int)response["int_bytes"], | ||
342 | lod = (int)response["int_lod"], | ||
343 | response = response | ||
344 | }; | ||
345 | |||
346 | } | ||
347 | m_throttler.ProcessTime(); | ||
348 | } | ||
349 | |||
350 | internal void UpdateThrottle(int pimagethrottle, ScenePresence p) | ||
351 | { | ||
352 | m_throttler.UpdateThrottle(pimagethrottle, p); | ||
353 | } | ||
354 | } | ||
113 | 355 | ||
114 | public void RegisterCaps(UUID agentID, Caps caps) | 356 | public void RegisterCaps(UUID agentID, Caps caps) |
115 | { | 357 | { |
116 | // UUID capID = UUID.Random(); | 358 | // UUID capID = UUID.Random(); |
117 | |||
118 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); | ||
119 | if (m_URL == "localhost") | 359 | if (m_URL == "localhost") |
120 | { | 360 | { |
121 | // m_log.DebugFormat("[GETMESH]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); | 361 | string capUrl = "/CAPS/" + UUID.Random() + "/"; |
122 | GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); | 362 | |
123 | IRequestHandler reqHandler | 363 | // Register this as a poll service |
124 | = new RestHTTPHandler( | 364 | PollServiceMeshEventArgs args = new PollServiceMeshEventArgs(capUrl, agentID, m_scene); |
125 | "GET", | 365 | |
126 | "/CAPS/" + UUID.Random(), | 366 | args.Type = PollServiceEventArgs.EventType.Mesh; |
127 | httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), | 367 | MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); |
128 | "GetMesh", | 368 | |
129 | agentID.ToString()); | 369 | string hostName = m_scene.RegionInfo.ExternalHostName; |
370 | uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; | ||
371 | string protocol = "http"; | ||
130 | 372 | ||
131 | caps.RegisterHandler("GetMesh", reqHandler); | 373 | if (MainServer.Instance.UseSSL) |
374 | { | ||
375 | hostName = MainServer.Instance.SSLCommonName; | ||
376 | port = MainServer.Instance.SSLPort; | ||
377 | protocol = "https"; | ||
378 | } | ||
379 | caps.RegisterHandler("GetMesh", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); | ||
380 | m_pollservices[agentID] = args; | ||
381 | m_capsDict[agentID] = capUrl; | ||
382 | |||
383 | |||
384 | |||
132 | } | 385 | } |
133 | else | 386 | else |
134 | { | 387 | { |
@@ -136,6 +389,177 @@ namespace OpenSim.Region.ClientStack.Linden | |||
136 | caps.RegisterHandler("GetMesh", m_URL); | 389 | caps.RegisterHandler("GetMesh", m_URL); |
137 | } | 390 | } |
138 | } | 391 | } |
392 | private void DeregisterCaps(UUID agentID, Caps caps) | ||
393 | { | ||
394 | string capUrl; | ||
395 | PollServiceMeshEventArgs args; | ||
396 | if (m_capsDict.TryGetValue(agentID, out capUrl)) | ||
397 | { | ||
398 | MainServer.Instance.RemoveHTTPHandler("", capUrl); | ||
399 | m_capsDict.Remove(agentID); | ||
400 | } | ||
401 | if (m_pollservices.TryGetValue(agentID, out args)) | ||
402 | { | ||
403 | m_pollservices.Remove(agentID); | ||
404 | } | ||
405 | } | ||
406 | |||
407 | internal sealed class MeshCapsDataThrottler | ||
408 | { | ||
409 | |||
410 | private volatile int currenttime = 0; | ||
411 | private volatile int lastTimeElapsed = 0; | ||
412 | private volatile int BytesSent = 0; | ||
413 | private int Lod3 = 0; | ||
414 | private int Lod2 = 0; | ||
415 | private int Lod1 = 0; | ||
416 | private int UserSetThrottle = 0; | ||
417 | private int UDPSetThrottle = 0; | ||
418 | private int CapSetThrottle = 0; | ||
419 | private float CapThrottleDistributon = 0.30f; | ||
420 | private readonly Scene m_scene; | ||
421 | private ThrottleOutPacketType Throttle; | ||
422 | private readonly UUID User; | ||
423 | |||
424 | public MeshCapsDataThrottler(int pBytes, int max, int min, Scene pScene, UUID puser) | ||
425 | { | ||
426 | ThrottleBytes = pBytes; | ||
427 | lastTimeElapsed = Util.EnvironmentTickCount(); | ||
428 | Throttle = ThrottleOutPacketType.Task; | ||
429 | m_scene = pScene; | ||
430 | User = puser; | ||
431 | } | ||
432 | |||
433 | |||
434 | public bool hasEvents(UUID key, Dictionary<UUID, aPollResponse> responses) | ||
435 | { | ||
436 | const float ThirtyPercent = 0.30f; | ||
437 | const float FivePercent = 0.05f; | ||
438 | PassTime(); | ||
439 | // Note, this is called IN LOCK | ||
440 | bool haskey = responses.ContainsKey(key); | ||
441 | |||
442 | if (responses.Count > 2) | ||
443 | { | ||
444 | SplitThrottle(ThirtyPercent); | ||
445 | } | ||
446 | else | ||
447 | { | ||
448 | SplitThrottle(FivePercent); | ||
449 | } | ||
450 | |||
451 | if (!haskey) | ||
452 | { | ||
453 | return false; | ||
454 | } | ||
455 | aPollResponse response; | ||
456 | if (responses.TryGetValue(key, out response)) | ||
457 | { | ||
458 | float LOD3Over = (((ThrottleBytes*CapThrottleDistributon)%50000) + 1); | ||
459 | float LOD2Over = (((ThrottleBytes*CapThrottleDistributon)%10000) + 1); | ||
460 | // Normal | ||
461 | if (BytesSent + response.bytes <= ThrottleBytes) | ||
462 | { | ||
463 | BytesSent += response.bytes; | ||
464 | |||
465 | return true; | ||
466 | } | ||
467 | // Lod3 Over Throttle protection to keep things processing even when the throttle bandwidth is set too little. | ||
468 | else if (response.bytes > ThrottleBytes && Lod3 <= ((LOD3Over < 1)? 1: LOD3Over) ) | ||
469 | { | ||
470 | Interlocked.Increment(ref Lod3); | ||
471 | BytesSent += response.bytes; | ||
472 | |||
473 | return true; | ||
474 | } | ||
475 | // Lod2 Over Throttle protection to keep things processing even when the throttle bandwidth is set too little. | ||
476 | else if (response.bytes > ThrottleBytes && Lod2 <= ((LOD2Over < 1) ? 1 : LOD2Over)) | ||
477 | { | ||
478 | Interlocked.Increment(ref Lod2); | ||
479 | BytesSent += response.bytes; | ||
480 | |||
481 | return true; | ||
482 | } | ||
483 | else | ||
484 | { | ||
485 | return false; | ||
486 | } | ||
487 | } | ||
488 | |||
489 | return haskey; | ||
490 | } | ||
491 | public void SubtractBytes(int bytes,int lod) | ||
492 | { | ||
493 | BytesSent -= bytes; | ||
494 | } | ||
495 | private void SplitThrottle(float percentMultiplier) | ||
496 | { | ||
497 | |||
498 | if (CapThrottleDistributon != percentMultiplier) // don't switch it if it's already set at the % multipler | ||
499 | { | ||
500 | CapThrottleDistributon = percentMultiplier; | ||
501 | ScenePresence p; | ||
502 | if (m_scene.TryGetScenePresence(User, out p)) // If we don't get a user they're not here anymore. | ||
503 | { | ||
504 | // AlterThrottle(UserSetThrottle, p); | ||
505 | UpdateThrottle(UserSetThrottle, p); | ||
506 | } | ||
507 | } | ||
508 | } | ||
509 | |||
510 | public void ProcessTime() | ||
511 | { | ||
512 | PassTime(); | ||
513 | } | ||
514 | |||
515 | |||
516 | private void PassTime() | ||
517 | { | ||
518 | currenttime = Util.EnvironmentTickCount(); | ||
519 | int timeElapsed = Util.EnvironmentTickCountSubtract(currenttime, lastTimeElapsed); | ||
520 | //processTimeBasedActions(responses); | ||
521 | if (currenttime - timeElapsed >= 1000) | ||
522 | { | ||
523 | lastTimeElapsed = Util.EnvironmentTickCount(); | ||
524 | BytesSent -= ThrottleBytes; | ||
525 | if (BytesSent < 0) BytesSent = 0; | ||
526 | if (BytesSent < ThrottleBytes) | ||
527 | { | ||
528 | Lod3 = 0; | ||
529 | Lod2 = 0; | ||
530 | Lod1 = 0; | ||
531 | } | ||
532 | } | ||
533 | } | ||
534 | private void AlterThrottle(int setting, ScenePresence p) | ||
535 | { | ||
536 | p.ControllingClient.SetAgentThrottleSilent((int)Throttle,setting); | ||
537 | } | ||
538 | |||
539 | public int ThrottleBytes | ||
540 | { | ||
541 | get { return CapSetThrottle; } | ||
542 | set { CapSetThrottle = value; } | ||
543 | } | ||
544 | |||
545 | internal void UpdateThrottle(int pimagethrottle, ScenePresence p) | ||
546 | { | ||
547 | // Client set throttle ! | ||
548 | UserSetThrottle = pimagethrottle; | ||
549 | CapSetThrottle = (int)(pimagethrottle*CapThrottleDistributon); | ||
550 | // UDPSetThrottle = (int) (pimagethrottle*(100 - CapThrottleDistributon)); | ||
551 | |||
552 | float udp = 1.0f - CapThrottleDistributon; | ||
553 | if(udp < 0.5f) | ||
554 | udp = 0.5f; | ||
555 | UDPSetThrottle = (int) ((float)pimagethrottle * udp); | ||
556 | if (CapSetThrottle < 4068) | ||
557 | CapSetThrottle = 4068; // at least two discovery mesh | ||
558 | p.ControllingClient.SetAgentThrottleSilent((int) Throttle, UDPSetThrottle); | ||
559 | ProcessTime(); | ||
560 | |||
561 | } | ||
562 | } | ||
139 | 563 | ||
140 | } | 564 | } |
141 | } | 565 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs index 54cf285..e053054 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs | |||
@@ -27,18 +27,13 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Specialized; | 30 | using System.Collections.Generic; |
31 | using System.Drawing; | ||
32 | using System.Drawing.Imaging; | ||
33 | using System.Reflection; | 31 | using System.Reflection; |
34 | using System.IO; | 32 | using System.Threading; |
35 | using System.Web; | ||
36 | using log4net; | 33 | using log4net; |
37 | using Nini.Config; | 34 | using Nini.Config; |
38 | using Mono.Addins; | 35 | using Mono.Addins; |
39 | using OpenMetaverse; | 36 | using OpenMetaverse; |
40 | using OpenMetaverse.StructuredData; | ||
41 | using OpenMetaverse.Imaging; | ||
42 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
43 | using OpenSim.Framework.Servers; | 38 | using OpenSim.Framework.Servers; |
44 | using OpenSim.Framework.Servers.HttpServer; | 39 | using OpenSim.Framework.Servers.HttpServer; |
@@ -47,6 +42,7 @@ using OpenSim.Region.Framework.Scenes; | |||
47 | using OpenSim.Services.Interfaces; | 42 | using OpenSim.Services.Interfaces; |
48 | using Caps = OpenSim.Framework.Capabilities.Caps; | 43 | using Caps = OpenSim.Framework.Capabilities.Caps; |
49 | using OpenSim.Capabilities.Handlers; | 44 | using OpenSim.Capabilities.Handlers; |
45 | using OpenSim.Framework.Monitoring; | ||
50 | 46 | ||
51 | namespace OpenSim.Region.ClientStack.Linden | 47 | namespace OpenSim.Region.ClientStack.Linden |
52 | { | 48 | { |
@@ -54,16 +50,39 @@ namespace OpenSim.Region.ClientStack.Linden | |||
54 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetTextureModule")] | 50 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetTextureModule")] |
55 | public class GetTextureModule : INonSharedRegionModule | 51 | public class GetTextureModule : INonSharedRegionModule |
56 | { | 52 | { |
57 | // private static readonly ILog m_log = | 53 | |
58 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 54 | struct aPollRequest |
59 | 55 | { | |
56 | public PollServiceTextureEventArgs thepoll; | ||
57 | public UUID reqID; | ||
58 | public Hashtable request; | ||
59 | public bool send503; | ||
60 | } | ||
61 | |||
62 | public class aPollResponse | ||
63 | { | ||
64 | public Hashtable response; | ||
65 | public int bytes; | ||
66 | } | ||
67 | |||
68 | |||
69 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
70 | |||
60 | private Scene m_scene; | 71 | private Scene m_scene; |
61 | private IAssetService m_assetService; | ||
62 | 72 | ||
63 | private bool m_Enabled = false; | 73 | private static GetTextureHandler m_getTextureHandler; |
74 | |||
75 | private IAssetService m_assetService = null; | ||
76 | |||
77 | private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>(); | ||
78 | private static Thread[] m_workerThreads = null; | ||
79 | |||
80 | private string m_Url = "localhost"; | ||
64 | 81 | ||
65 | // TODO: Change this to a config option | 82 | private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue = |
66 | const string REDIRECT_URL = null; | 83 | new OpenMetaverse.BlockingQueue<aPollRequest>(); |
84 | |||
85 | private Dictionary<UUID,PollServiceTextureEventArgs> m_pollservices = new Dictionary<UUID,PollServiceTextureEventArgs>(); | ||
67 | 86 | ||
68 | private string m_URL; | 87 | private string m_URL; |
69 | 88 | ||
@@ -72,39 +91,98 @@ namespace OpenSim.Region.ClientStack.Linden | |||
72 | public void Initialise(IConfigSource source) | 91 | public void Initialise(IConfigSource source) |
73 | { | 92 | { |
74 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | 93 | IConfig config = source.Configs["ClientStack.LindenCaps"]; |
75 | if (config == null) | 94 | if (config != null) |
76 | return; | 95 | m_Url = config.GetString("Cap_GetTexture", "localhost"); |
77 | |||
78 | m_URL = config.GetString("Cap_GetTexture", string.Empty); | ||
79 | // Cap doesn't exist | ||
80 | if (m_URL != string.Empty) | ||
81 | m_Enabled = true; | ||
82 | } | 96 | } |
83 | 97 | ||
84 | public void AddRegion(Scene s) | 98 | public void AddRegion(Scene s) |
85 | { | 99 | { |
86 | if (!m_Enabled) | ||
87 | return; | ||
88 | |||
89 | m_scene = s; | 100 | m_scene = s; |
101 | m_assetService = s.AssetService; | ||
90 | } | 102 | } |
91 | 103 | ||
92 | public void RemoveRegion(Scene s) | 104 | public void RemoveRegion(Scene s) |
93 | { | 105 | { |
94 | if (!m_Enabled) | ||
95 | return; | ||
96 | |||
97 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | 106 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; |
107 | m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; | ||
108 | m_scene.EventManager.OnThrottleUpdate -= ThrottleUpdate; | ||
98 | m_scene = null; | 109 | m_scene = null; |
99 | } | 110 | } |
100 | 111 | ||
101 | public void RegionLoaded(Scene s) | 112 | public void RegionLoaded(Scene s) |
102 | { | 113 | { |
103 | if (!m_Enabled) | 114 | // We'll reuse the same handler for all requests. |
104 | return; | 115 | m_getTextureHandler = new GetTextureHandler(m_assetService); |
105 | 116 | ||
106 | m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | ||
107 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 117 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
118 | m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; | ||
119 | m_scene.EventManager.OnThrottleUpdate += ThrottleUpdate; | ||
120 | |||
121 | if (m_workerThreads == null) | ||
122 | { | ||
123 | m_workerThreads = new Thread[2]; | ||
124 | |||
125 | for (uint i = 0; i < 2; i++) | ||
126 | { | ||
127 | m_workerThreads[i] = Watchdog.StartThread(DoTextureRequests, | ||
128 | String.Format("TextureWorkerThread{0}", i), | ||
129 | ThreadPriority.Normal, | ||
130 | false, | ||
131 | false, | ||
132 | null, | ||
133 | int.MaxValue); | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | private int ExtractImageThrottle(byte[] pthrottles) | ||
138 | { | ||
139 | |||
140 | byte[] adjData; | ||
141 | int pos = 0; | ||
142 | |||
143 | if (!BitConverter.IsLittleEndian) | ||
144 | { | ||
145 | byte[] newData = new byte[7 * 4]; | ||
146 | Buffer.BlockCopy(pthrottles, 0, newData, 0, 7 * 4); | ||
147 | |||
148 | for (int i = 0; i < 7; i++) | ||
149 | Array.Reverse(newData, i * 4, 4); | ||
150 | |||
151 | adjData = newData; | ||
152 | } | ||
153 | else | ||
154 | { | ||
155 | adjData = pthrottles; | ||
156 | } | ||
157 | |||
158 | // 0.125f converts from bits to bytes | ||
159 | //int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
160 | //pos += 4; | ||
161 | // int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
162 | //pos += 4; | ||
163 | // int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
164 | // pos += 4; | ||
165 | // int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
166 | // pos += 4; | ||
167 | // int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
168 | // pos += 4; | ||
169 | pos = pos + 20; | ||
170 | int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); //pos += 4; | ||
171 | //int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
172 | return texture; | ||
173 | } | ||
174 | |||
175 | // Now we know when the throttle is changed by the client in the case of a root agent or by a neighbor region in the case of a child agent. | ||
176 | public void ThrottleUpdate(ScenePresence p) | ||
177 | { | ||
178 | byte[] throttles = p.ControllingClient.GetThrottlesPacked(1); | ||
179 | UUID user = p.UUID; | ||
180 | int imagethrottle = ExtractImageThrottle(throttles); | ||
181 | PollServiceTextureEventArgs args; | ||
182 | if (m_pollservices.TryGetValue(user,out args)) | ||
183 | { | ||
184 | args.UpdateThrottle(imagethrottle); | ||
185 | } | ||
108 | } | 186 | } |
109 | 187 | ||
110 | public void PostInitialise() | 188 | public void PostInitialise() |
@@ -122,28 +200,290 @@ namespace OpenSim.Region.ClientStack.Linden | |||
122 | 200 | ||
123 | #endregion | 201 | #endregion |
124 | 202 | ||
125 | public void RegisterCaps(UUID agentID, Caps caps) | 203 | ~GetTextureModule() |
126 | { | 204 | { |
127 | UUID capID = UUID.Random(); | 205 | foreach (Thread t in m_workerThreads) |
206 | Watchdog.AbortThread(t.ManagedThreadId); | ||
128 | 207 | ||
129 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); | 208 | } |
130 | if (m_URL == "localhost") | 209 | |
210 | private class PollServiceTextureEventArgs : PollServiceEventArgs | ||
211 | { | ||
212 | private List<Hashtable> requests = | ||
213 | new List<Hashtable>(); | ||
214 | private Dictionary<UUID, aPollResponse> responses = | ||
215 | new Dictionary<UUID, aPollResponse>(); | ||
216 | |||
217 | private Scene m_scene; | ||
218 | private CapsDataThrottler m_throttler = new CapsDataThrottler(100000, 1400000,10000); | ||
219 | public PollServiceTextureEventArgs(UUID pId, Scene scene) : | ||
220 | base(null, "", null, null, null, pId, int.MaxValue) | ||
131 | { | 221 | { |
132 | // m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); | 222 | m_scene = scene; |
133 | caps.RegisterHandler( | 223 | // x is request id, y is userid |
134 | "GetTexture", | 224 | HasEvents = (x, y) => |
135 | new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString())); | 225 | { |
226 | lock (responses) | ||
227 | { | ||
228 | bool ret = m_throttler.hasEvents(x, responses); | ||
229 | m_throttler.ProcessTime(); | ||
230 | return ret; | ||
231 | |||
232 | } | ||
233 | }; | ||
234 | GetEvents = (x, y) => | ||
235 | { | ||
236 | lock (responses) | ||
237 | { | ||
238 | try | ||
239 | { | ||
240 | return responses[x].response; | ||
241 | } | ||
242 | finally | ||
243 | { | ||
244 | responses.Remove(x); | ||
245 | } | ||
246 | } | ||
247 | }; | ||
248 | // x is request id, y is request data hashtable | ||
249 | Request = (x, y) => | ||
250 | { | ||
251 | aPollRequest reqinfo = new aPollRequest(); | ||
252 | reqinfo.thepoll = this; | ||
253 | reqinfo.reqID = x; | ||
254 | reqinfo.request = y; | ||
255 | reqinfo.send503 = false; | ||
256 | |||
257 | lock (responses) | ||
258 | { | ||
259 | if (responses.Count > 0) | ||
260 | { | ||
261 | if (m_queue.Count >= 4) | ||
262 | { | ||
263 | // Never allow more than 4 fetches to wait | ||
264 | reqinfo.send503 = true; | ||
265 | } | ||
266 | } | ||
267 | } | ||
268 | m_queue.Enqueue(reqinfo); | ||
269 | }; | ||
270 | |||
271 | // this should never happen except possible on shutdown | ||
272 | NoEvents = (x, y) => | ||
273 | { | ||
274 | /* | ||
275 | lock (requests) | ||
276 | { | ||
277 | Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); | ||
278 | requests.Remove(request); | ||
279 | } | ||
280 | */ | ||
281 | Hashtable response = new Hashtable(); | ||
282 | |||
283 | response["int_response_code"] = 500; | ||
284 | response["str_response_string"] = "Script timeout"; | ||
285 | response["content_type"] = "text/plain"; | ||
286 | response["keepalive"] = false; | ||
287 | response["reusecontext"] = false; | ||
288 | |||
289 | return response; | ||
290 | }; | ||
136 | } | 291 | } |
137 | else | 292 | |
293 | public void Process(aPollRequest requestinfo) | ||
138 | { | 294 | { |
139 | // m_log.DebugFormat("[GETTEXTURE]: {0} in region {1}", m_URL, m_scene.RegionInfo.RegionName); | 295 | Hashtable response; |
296 | |||
297 | UUID requestID = requestinfo.reqID; | ||
298 | |||
299 | if (requestinfo.send503) | ||
300 | { | ||
301 | response = new Hashtable(); | ||
302 | |||
303 | response["int_response_code"] = 503; | ||
304 | response["str_response_string"] = "Throttled"; | ||
305 | response["content_type"] = "text/plain"; | ||
306 | response["keepalive"] = false; | ||
307 | response["reusecontext"] = false; | ||
308 | |||
309 | lock (responses) | ||
310 | responses[requestID] = new aPollResponse() {bytes = 0, response = response}; | ||
311 | |||
312 | return; | ||
313 | } | ||
314 | |||
315 | // If the avatar is gone, don't bother to get the texture | ||
316 | if (m_scene.GetScenePresence(Id) == null) | ||
317 | { | ||
318 | response = new Hashtable(); | ||
319 | |||
320 | response["int_response_code"] = 500; | ||
321 | response["str_response_string"] = "Script timeout"; | ||
322 | response["content_type"] = "text/plain"; | ||
323 | response["keepalive"] = false; | ||
324 | response["reusecontext"] = false; | ||
325 | |||
326 | lock (responses) | ||
327 | responses[requestID] = new aPollResponse() {bytes = 0, response = response}; | ||
328 | |||
329 | return; | ||
330 | } | ||
331 | |||
332 | response = m_getTextureHandler.Handle(requestinfo.request); | ||
333 | lock (responses) | ||
334 | { | ||
335 | responses[requestID] = new aPollResponse() | ||
336 | { | ||
337 | bytes = (int) response["int_bytes"], | ||
338 | response = response | ||
339 | }; | ||
340 | |||
341 | } | ||
342 | m_throttler.ProcessTime(); | ||
343 | } | ||
344 | |||
345 | internal void UpdateThrottle(int pimagethrottle) | ||
346 | { | ||
347 | m_throttler.ThrottleBytes = pimagethrottle; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | private void RegisterCaps(UUID agentID, Caps caps) | ||
352 | { | ||
353 | if (m_Url == "localhost") | ||
354 | { | ||
355 | string capUrl = "/CAPS/" + UUID.Random() + "/"; | ||
356 | |||
357 | // Register this as a poll service | ||
358 | PollServiceTextureEventArgs args = new PollServiceTextureEventArgs(agentID, m_scene); | ||
359 | |||
360 | args.Type = PollServiceEventArgs.EventType.Texture; | ||
361 | MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); | ||
362 | |||
363 | string hostName = m_scene.RegionInfo.ExternalHostName; | ||
364 | uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; | ||
365 | string protocol = "http"; | ||
366 | |||
367 | if (MainServer.Instance.UseSSL) | ||
368 | { | ||
369 | hostName = MainServer.Instance.SSLCommonName; | ||
370 | port = MainServer.Instance.SSLPort; | ||
371 | protocol = "https"; | ||
372 | } | ||
140 | IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>(); | 373 | IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>(); |
141 | if (handler != null) | 374 | if (handler != null) |
142 | handler.RegisterExternalUserCapsHandler(agentID,caps,"GetTexture",m_URL); | 375 | handler.RegisterExternalUserCapsHandler(agentID, caps, "GetTexture", capUrl); |
143 | else | 376 | else |
144 | caps.RegisterHandler("GetTexture", m_URL); | 377 | caps.RegisterHandler("GetTexture", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); |
378 | m_pollservices[agentID] = args; | ||
379 | m_capsDict[agentID] = capUrl; | ||
380 | } | ||
381 | else | ||
382 | { | ||
383 | caps.RegisterHandler("GetTexture", m_Url); | ||
145 | } | 384 | } |
146 | } | 385 | } |
147 | 386 | ||
387 | private void DeregisterCaps(UUID agentID, Caps caps) | ||
388 | { | ||
389 | PollServiceTextureEventArgs args; | ||
390 | |||
391 | MainServer.Instance.RemoveHTTPHandler("", m_URL); | ||
392 | m_capsDict.Remove(agentID); | ||
393 | |||
394 | if (m_pollservices.TryGetValue(agentID, out args)) | ||
395 | { | ||
396 | m_pollservices.Remove(agentID); | ||
397 | } | ||
398 | } | ||
399 | |||
400 | private void DoTextureRequests() | ||
401 | { | ||
402 | while (true) | ||
403 | { | ||
404 | aPollRequest poolreq = m_queue.Dequeue(); | ||
405 | |||
406 | poolreq.thepoll.Process(poolreq); | ||
407 | } | ||
408 | } | ||
409 | internal sealed class CapsDataThrottler | ||
410 | { | ||
411 | |||
412 | private volatile int currenttime = 0; | ||
413 | private volatile int lastTimeElapsed = 0; | ||
414 | private volatile int BytesSent = 0; | ||
415 | private int oversizedImages = 0; | ||
416 | public CapsDataThrottler(int pBytes, int max, int min) | ||
417 | { | ||
418 | ThrottleBytes = pBytes; | ||
419 | lastTimeElapsed = Util.EnvironmentTickCount(); | ||
420 | } | ||
421 | public bool hasEvents(UUID key, Dictionary<UUID, GetTextureModule.aPollResponse> responses) | ||
422 | { | ||
423 | PassTime(); | ||
424 | // Note, this is called IN LOCK | ||
425 | bool haskey = responses.ContainsKey(key); | ||
426 | if (!haskey) | ||
427 | { | ||
428 | return false; | ||
429 | } | ||
430 | GetTextureModule.aPollResponse response; | ||
431 | if (responses.TryGetValue(key, out response)) | ||
432 | { | ||
433 | // This is any error response | ||
434 | if (response.bytes == 0) | ||
435 | return true; | ||
436 | |||
437 | // Normal | ||
438 | if (BytesSent + response.bytes <= ThrottleBytes) | ||
439 | { | ||
440 | BytesSent += response.bytes; | ||
441 | //TimeBasedAction timeBasedAction = new TimeBasedAction { byteRemoval = response.bytes, requestId = key, timeMS = currenttime + 1000, unlockyn = false }; | ||
442 | //m_actions.Add(timeBasedAction); | ||
443 | return true; | ||
444 | } | ||
445 | // Big textures | ||
446 | else if (response.bytes > ThrottleBytes && oversizedImages <= ((ThrottleBytes % 50000) + 1)) | ||
447 | { | ||
448 | Interlocked.Increment(ref oversizedImages); | ||
449 | BytesSent += response.bytes; | ||
450 | //TimeBasedAction timeBasedAction = new TimeBasedAction { byteRemoval = response.bytes, requestId = key, timeMS = currenttime + (((response.bytes % ThrottleBytes)+1)*1000) , unlockyn = false }; | ||
451 | //m_actions.Add(timeBasedAction); | ||
452 | return true; | ||
453 | } | ||
454 | else | ||
455 | { | ||
456 | return false; | ||
457 | } | ||
458 | } | ||
459 | |||
460 | return haskey; | ||
461 | } | ||
462 | |||
463 | public void ProcessTime() | ||
464 | { | ||
465 | PassTime(); | ||
466 | } | ||
467 | |||
468 | private void PassTime() | ||
469 | { | ||
470 | currenttime = Util.EnvironmentTickCount(); | ||
471 | int timeElapsed = Util.EnvironmentTickCountSubtract(currenttime, lastTimeElapsed); | ||
472 | //processTimeBasedActions(responses); | ||
473 | if (Util.EnvironmentTickCountSubtract(currenttime, timeElapsed) >= 1000) | ||
474 | { | ||
475 | lastTimeElapsed = Util.EnvironmentTickCount(); | ||
476 | BytesSent -= ThrottleBytes; | ||
477 | if (BytesSent < 0) BytesSent = 0; | ||
478 | if (BytesSent < ThrottleBytes) | ||
479 | { | ||
480 | oversizedImages = 0; | ||
481 | } | ||
482 | } | ||
483 | } | ||
484 | public int ThrottleBytes; | ||
485 | } | ||
148 | } | 486 | } |
487 | |||
488 | |||
149 | } | 489 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs index 45d33cd..1b68603 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/MeshUploadFlagModule.cs | |||
@@ -129,15 +129,15 @@ namespace OpenSim.Region.ClientStack.Linden | |||
129 | // m_log.DebugFormat("[MESH UPLOAD FLAG MODULE]: MeshUploadFlag request"); | 129 | // m_log.DebugFormat("[MESH UPLOAD FLAG MODULE]: MeshUploadFlag request"); |
130 | 130 | ||
131 | OSDMap data = new OSDMap(); | 131 | OSDMap data = new OSDMap(); |
132 | ScenePresence sp = m_scene.GetScenePresence(agentID); | 132 | // ScenePresence sp = m_scene.GetScenePresence(m_agentID); |
133 | data["username"] = sp.Firstname + "." + sp.Lastname; | 133 | // data["username"] = sp.Firstname + "." + sp.Lastname; |
134 | data["display_name_next_update"] = new OSDDate(DateTime.Now); | 134 | // data["display_name_next_update"] = new OSDDate(DateTime.Now); |
135 | data["legacy_first_name"] = sp.Firstname; | 135 | // data["legacy_first_name"] = sp.Firstname; |
136 | data["mesh_upload_status"] = "valid"; | 136 | data["mesh_upload_status"] = "valid"; |
137 | data["display_name"] = sp.Firstname + " " + sp.Lastname; | 137 | // data["display_name"] = sp.Firstname + " " + sp.Lastname; |
138 | data["legacy_last_name"] = sp.Lastname; | 138 | // data["legacy_last_name"] = sp.Lastname; |
139 | data["id"] = agentID; | 139 | // data["id"] = m_agentID; |
140 | data["is_display_name_default"] = true; | 140 | // data["is_display_name_default"] = true; |
141 | 141 | ||
142 | //Send back data | 142 | //Send back data |
143 | Hashtable responsedata = new Hashtable(); | 143 | Hashtable responsedata = new Hashtable(); |
@@ -148,4 +148,4 @@ namespace OpenSim.Region.ClientStack.Linden | |||
148 | return responsedata; | 148 | return responsedata; |
149 | } | 149 | } |
150 | } | 150 | } |
151 | } \ No newline at end of file | 151 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs deleted file mode 100644 index f69a0bb..0000000 --- a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs +++ /dev/null | |||
@@ -1,297 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Web; | ||
34 | using Mono.Addins; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | using OpenSim.Region.Framework.Interfaces; | ||
43 | using OpenSim.Region.Framework.Scenes; | ||
44 | using OpenSim.Services.Interfaces; | ||
45 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
46 | using OpenSim.Framework.Capabilities; | ||
47 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
48 | |||
49 | namespace OpenSim.Region.ClientStack.Linden | ||
50 | { | ||
51 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "NewFileAgentInventoryVariablePriceModule")] | ||
52 | public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule | ||
53 | { | ||
54 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private Scene m_scene; | ||
57 | // private IAssetService m_assetService; | ||
58 | private bool m_dumpAssetsToFile = false; | ||
59 | private bool m_enabled = true; | ||
60 | private int m_levelUpload = 0; | ||
61 | |||
62 | #region Region Module interfaceBase Members | ||
63 | |||
64 | |||
65 | public Type ReplaceableInterface | ||
66 | { | ||
67 | get { return null; } | ||
68 | } | ||
69 | |||
70 | public void Initialise(IConfigSource source) | ||
71 | { | ||
72 | IConfig meshConfig = source.Configs["Mesh"]; | ||
73 | if (meshConfig == null) | ||
74 | return; | ||
75 | |||
76 | m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); | ||
77 | m_levelUpload = meshConfig.GetInt("LevelUpload", 0); | ||
78 | } | ||
79 | |||
80 | public void AddRegion(Scene pScene) | ||
81 | { | ||
82 | m_scene = pScene; | ||
83 | } | ||
84 | |||
85 | public void RemoveRegion(Scene scene) | ||
86 | { | ||
87 | |||
88 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
89 | m_scene = null; | ||
90 | } | ||
91 | |||
92 | public void RegionLoaded(Scene scene) | ||
93 | { | ||
94 | |||
95 | // m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | ||
96 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
97 | } | ||
98 | |||
99 | #endregion | ||
100 | |||
101 | |||
102 | #region Region Module interface | ||
103 | |||
104 | |||
105 | |||
106 | public void Close() { } | ||
107 | |||
108 | public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } } | ||
109 | |||
110 | |||
111 | public void RegisterCaps(UUID agentID, Caps caps) | ||
112 | { | ||
113 | if(!m_enabled) | ||
114 | return; | ||
115 | |||
116 | UUID capID = UUID.Random(); | ||
117 | |||
118 | // m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); | ||
119 | caps.RegisterHandler( | ||
120 | "NewFileAgentInventoryVariablePrice", | ||
121 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>( | ||
122 | "POST", | ||
123 | "/CAPS/" + capID.ToString(), | ||
124 | req => NewAgentInventoryRequest(req, agentID), | ||
125 | "NewFileAgentInventoryVariablePrice", | ||
126 | agentID.ToString())); | ||
127 | } | ||
128 | |||
129 | #endregion | ||
130 | |||
131 | public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID) | ||
132 | { | ||
133 | //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit | ||
134 | // you need to be aware of this | ||
135 | |||
136 | //if (llsdRequest.asset_type == "texture" || | ||
137 | // llsdRequest.asset_type == "animation" || | ||
138 | // llsdRequest.asset_type == "sound") | ||
139 | // { | ||
140 | // check user level | ||
141 | |||
142 | ScenePresence avatar = null; | ||
143 | IClientAPI client = null; | ||
144 | m_scene.TryGetScenePresence(agentID, out avatar); | ||
145 | |||
146 | if (avatar != null) | ||
147 | { | ||
148 | client = avatar.ControllingClient; | ||
149 | |||
150 | if (avatar.UserLevel < m_levelUpload) | ||
151 | { | ||
152 | if (client != null) | ||
153 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); | ||
154 | |||
155 | LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); | ||
156 | errorResponse.rsvp = ""; | ||
157 | errorResponse.state = "error"; | ||
158 | return errorResponse; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | // check funds | ||
163 | IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>(); | ||
164 | |||
165 | if (mm != null) | ||
166 | { | ||
167 | if (!mm.UploadCovered(agentID, mm.UploadCharge)) | ||
168 | { | ||
169 | if (client != null) | ||
170 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | ||
171 | |||
172 | LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); | ||
173 | errorResponse.rsvp = ""; | ||
174 | errorResponse.state = "error"; | ||
175 | return errorResponse; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | // } | ||
180 | |||
181 | string assetName = llsdRequest.name; | ||
182 | string assetDes = llsdRequest.description; | ||
183 | string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/"; | ||
184 | UUID newAsset = UUID.Random(); | ||
185 | UUID newInvItem = UUID.Random(); | ||
186 | UUID parentFolder = llsdRequest.folder_id; | ||
187 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/"; | ||
188 | |||
189 | AssetUploader uploader = | ||
190 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | ||
191 | llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile); | ||
192 | |||
193 | MainServer.Instance.AddStreamHandler( | ||
194 | new BinaryStreamHandler( | ||
195 | "POST", | ||
196 | capsBase + uploaderPath, | ||
197 | uploader.uploaderCaps, | ||
198 | "NewFileAgentInventoryVariablePrice", | ||
199 | agentID.ToString())); | ||
200 | |||
201 | string protocol = "http://"; | ||
202 | |||
203 | if (MainServer.Instance.UseSSL) | ||
204 | protocol = "https://"; | ||
205 | |||
206 | string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + | ||
207 | uploaderPath; | ||
208 | |||
209 | |||
210 | LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); | ||
211 | |||
212 | uploadResponse.rsvp = uploaderURL; | ||
213 | uploadResponse.state = "upload"; | ||
214 | uploadResponse.resource_cost = 0; | ||
215 | uploadResponse.upload_price = 0; | ||
216 | |||
217 | uploader.OnUpLoad += //UploadCompleteHandler; | ||
218 | |||
219 | delegate( | ||
220 | string passetName, string passetDescription, UUID passetID, | ||
221 | UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, | ||
222 | string passetType) | ||
223 | { | ||
224 | UploadCompleteHandler(passetName, passetDescription, passetID, | ||
225 | pinventoryItem, pparentFolder, pdata, pinventoryType, | ||
226 | passetType,agentID); | ||
227 | }; | ||
228 | |||
229 | return uploadResponse; | ||
230 | } | ||
231 | |||
232 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, | ||
233 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, | ||
234 | string assetType,UUID AgentID) | ||
235 | { | ||
236 | // m_log.DebugFormat( | ||
237 | // "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); | ||
238 | |||
239 | sbyte assType = 0; | ||
240 | sbyte inType = 0; | ||
241 | |||
242 | if (inventoryType == "sound") | ||
243 | { | ||
244 | inType = 1; | ||
245 | assType = 1; | ||
246 | } | ||
247 | else if (inventoryType == "animation") | ||
248 | { | ||
249 | inType = 19; | ||
250 | assType = 20; | ||
251 | } | ||
252 | else if (inventoryType == "wearable") | ||
253 | { | ||
254 | inType = 18; | ||
255 | switch (assetType) | ||
256 | { | ||
257 | case "bodypart": | ||
258 | assType = 13; | ||
259 | break; | ||
260 | case "clothing": | ||
261 | assType = 5; | ||
262 | break; | ||
263 | } | ||
264 | } | ||
265 | else if (inventoryType == "mesh") | ||
266 | { | ||
267 | inType = (sbyte)InventoryType.Mesh; | ||
268 | assType = (sbyte)AssetType.Mesh; | ||
269 | } | ||
270 | |||
271 | AssetBase asset; | ||
272 | asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); | ||
273 | asset.Data = data; | ||
274 | |||
275 | if (m_scene.AssetService != null) | ||
276 | m_scene.AssetService.Store(asset); | ||
277 | |||
278 | InventoryItemBase item = new InventoryItemBase(); | ||
279 | item.Owner = AgentID; | ||
280 | item.CreatorId = AgentID.ToString(); | ||
281 | item.ID = inventoryItem; | ||
282 | item.AssetID = asset.FullID; | ||
283 | item.Description = assetDescription; | ||
284 | item.Name = assetName; | ||
285 | item.AssetType = assType; | ||
286 | item.InvType = inType; | ||
287 | item.Folder = parentFolder; | ||
288 | item.CurrentPermissions | ||
289 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); | ||
290 | item.BasePermissions = (uint)PermissionMask.All; | ||
291 | item.EveryOnePermissions = 0; | ||
292 | item.NextPermissions = (uint)PermissionMask.All; | ||
293 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
294 | m_scene.AddInventoryItem(item); | ||
295 | } | ||
296 | } | ||
297 | } | ||
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs index a133a69..5196368 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs | |||
@@ -64,6 +64,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
64 | private Commands m_commands = new Commands(); | 64 | private Commands m_commands = new Commands(); |
65 | public ICommands Commands { get { return m_commands; } } | 65 | public ICommands Commands { get { return m_commands; } } |
66 | 66 | ||
67 | public event ConsoleMessage OnConsoleMessage; | ||
68 | |||
67 | public void Initialise(IConfigSource source) | 69 | public void Initialise(IConfigSource source) |
68 | { | 70 | { |
69 | m_commands.AddCommand( "Help", false, "help", "help [<item>]", "Display help on a particular command or on a list of commands in a category", Help); | 71 | m_commands.AddCommand( "Help", false, "help", "help [<item>]", "Display help on a particular command or on a list of commands in a category", Help); |
@@ -102,7 +104,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
102 | 104 | ||
103 | public void RegisterCaps(UUID agentID, Caps caps) | 105 | public void RegisterCaps(UUID agentID, Caps caps) |
104 | { | 106 | { |
105 | if (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(agentID)) | 107 | if (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(agentID) && !m_scene.Permissions.IsGod(agentID)) |
106 | return; | 108 | return; |
107 | 109 | ||
108 | UUID capID = UUID.Random(); | 110 | UUID capID = UUID.Random(); |
@@ -118,6 +120,11 @@ namespace OpenSim.Region.ClientStack.Linden | |||
118 | OSD osd = OSD.FromString(message); | 120 | OSD osd = OSD.FromString(message); |
119 | 121 | ||
120 | m_eventQueue.Enqueue(EventQueueHelper.BuildEvent("SimConsoleResponse", osd), agentID); | 122 | m_eventQueue.Enqueue(EventQueueHelper.BuildEvent("SimConsoleResponse", osd), agentID); |
123 | |||
124 | ConsoleMessage handlerConsoleMessage = OnConsoleMessage; | ||
125 | |||
126 | if (handlerConsoleMessage != null) | ||
127 | handlerConsoleMessage( agentID, message); | ||
121 | } | 128 | } |
122 | 129 | ||
123 | public bool RunCommand(string command, UUID invokerID) | 130 | public bool RunCommand(string command, UUID invokerID) |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs index 4501dd9..47988dd 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | ||
30 | using System.Collections.Specialized; | 31 | using System.Collections.Specialized; |
31 | using System.Drawing; | 32 | using System.Drawing; |
32 | using System.Drawing.Imaging; | 33 | using System.Drawing.Imaging; |
@@ -53,8 +54,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
53 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadBakedTextureModule")] | 54 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadBakedTextureModule")] |
54 | public class UploadBakedTextureModule : INonSharedRegionModule | 55 | public class UploadBakedTextureModule : INonSharedRegionModule |
55 | { | 56 | { |
56 | // private static readonly ILog m_log = | 57 | private static readonly ILog m_log = |
57 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 58 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
58 | 59 | ||
59 | /// <summary> | 60 | /// <summary> |
60 | /// For historical reasons this is fixed, but there | 61 | /// For historical reasons this is fixed, but there |
@@ -65,6 +66,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
65 | private bool m_persistBakedTextures; | 66 | private bool m_persistBakedTextures; |
66 | private string m_URL; | 67 | private string m_URL; |
67 | 68 | ||
69 | private IBakedTextureModule m_BakedTextureModule; | ||
70 | |||
68 | public void Initialise(IConfigSource source) | 71 | public void Initialise(IConfigSource source) |
69 | { | 72 | { |
70 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | 73 | IConfig config = source.Configs["ClientStack.LindenCaps"]; |
@@ -76,26 +79,203 @@ namespace OpenSim.Region.ClientStack.Linden | |||
76 | IConfig appearanceConfig = source.Configs["Appearance"]; | 79 | IConfig appearanceConfig = source.Configs["Appearance"]; |
77 | if (appearanceConfig != null) | 80 | if (appearanceConfig != null) |
78 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | 81 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); |
82 | |||
83 | |||
79 | } | 84 | } |
80 | 85 | ||
81 | public void AddRegion(Scene s) | 86 | public void AddRegion(Scene s) |
82 | { | 87 | { |
83 | m_scene = s; | 88 | m_scene = s; |
89 | |||
84 | } | 90 | } |
85 | 91 | ||
86 | public void RemoveRegion(Scene s) | 92 | public void RemoveRegion(Scene s) |
87 | { | 93 | { |
94 | s.EventManager.OnRegisterCaps -= RegisterCaps; | ||
95 | s.EventManager.OnNewPresence -= RegisterNewPresence; | ||
96 | s.EventManager.OnRemovePresence -= DeRegisterPresence; | ||
97 | m_BakedTextureModule = null; | ||
98 | m_scene = null; | ||
88 | } | 99 | } |
89 | 100 | ||
101 | |||
102 | |||
90 | public void RegionLoaded(Scene s) | 103 | public void RegionLoaded(Scene s) |
91 | { | 104 | { |
92 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 105 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
106 | m_scene.EventManager.OnNewPresence += RegisterNewPresence; | ||
107 | m_scene.EventManager.OnRemovePresence += DeRegisterPresence; | ||
108 | |||
109 | } | ||
110 | |||
111 | private void DeRegisterPresence(UUID agentId) | ||
112 | { | ||
113 | ScenePresence presence = null; | ||
114 | if (m_scene.TryGetScenePresence(agentId, out presence)) | ||
115 | { | ||
116 | presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings; | ||
117 | } | ||
118 | |||
119 | } | ||
120 | |||
121 | private void RegisterNewPresence(ScenePresence presence) | ||
122 | { | ||
123 | presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; | ||
124 | |||
125 | } | ||
126 | |||
127 | private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) | ||
128 | { | ||
129 | int maxCacheitemsLoop = cacheItems.Length; | ||
130 | if (maxCacheitemsLoop > AvatarWearable.MAX_WEARABLES) | ||
131 | { | ||
132 | maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES; | ||
133 | m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES); | ||
134 | } | ||
135 | |||
136 | m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | ||
137 | if (cacheItems.Length > 0) | ||
138 | { | ||
139 | m_log.Debug("[Cacheitems]: " + cacheItems.Length); | ||
140 | for (int iter = 0; iter < maxCacheitemsLoop; iter++) | ||
141 | { | ||
142 | m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + | ||
143 | cacheItems[iter].TextureID); | ||
144 | } | ||
145 | |||
146 | ScenePresence p = null; | ||
147 | if (m_scene.TryGetScenePresence(remoteClient.AgentId, out p)) | ||
148 | { | ||
149 | |||
150 | WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; | ||
151 | if (existingitems == null) | ||
152 | { | ||
153 | if (m_BakedTextureModule != null) | ||
154 | { | ||
155 | WearableCacheItem[] savedcache = null; | ||
156 | try | ||
157 | { | ||
158 | if (p.Appearance.WearableCacheItemsDirty) | ||
159 | { | ||
160 | savedcache = m_BakedTextureModule.Get(p.UUID); | ||
161 | p.Appearance.WearableCacheItems = savedcache; | ||
162 | p.Appearance.WearableCacheItemsDirty = false; | ||
163 | } | ||
164 | |||
165 | } | ||
166 | /* | ||
167 | * The following Catch types DO NOT WORK with m_BakedTextureModule.Get | ||
168 | * it jumps to the General Packet Exception Handler if you don't catch Exception! | ||
169 | * | ||
170 | catch (System.Net.Sockets.SocketException) | ||
171 | { | ||
172 | cacheItems = null; | ||
173 | } | ||
174 | catch (WebException) | ||
175 | { | ||
176 | cacheItems = null; | ||
177 | } | ||
178 | catch (InvalidOperationException) | ||
179 | { | ||
180 | cacheItems = null; | ||
181 | } */ | ||
182 | catch (Exception) | ||
183 | { | ||
184 | // The service logs a sufficient error message. | ||
185 | } | ||
186 | |||
187 | |||
188 | if (savedcache != null) | ||
189 | existingitems = savedcache; | ||
190 | } | ||
191 | } | ||
192 | // Existing items null means it's a fully new appearance | ||
193 | if (existingitems == null) | ||
194 | { | ||
195 | |||
196 | for (int i = 0; i < maxCacheitemsLoop; i++) | ||
197 | { | ||
198 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | ||
199 | { | ||
200 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex]; | ||
201 | if (face == null) | ||
202 | { | ||
203 | textureEntry.CreateFace(cacheItems[i].TextureIndex); | ||
204 | textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID = | ||
205 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; | ||
206 | continue; | ||
207 | } | ||
208 | cacheItems[i].TextureID =face.TextureID; | ||
209 | if (m_scene.AssetService != null) | ||
210 | cacheItems[i].TextureAsset = | ||
211 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); | ||
212 | } | ||
213 | else | ||
214 | { | ||
215 | m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length); | ||
216 | } | ||
217 | |||
218 | |||
219 | } | ||
220 | } | ||
221 | else | ||
222 | |||
223 | |||
224 | { | ||
225 | // for each uploaded baked texture | ||
226 | for (int i = 0; i < maxCacheitemsLoop; i++) | ||
227 | { | ||
228 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | ||
229 | { | ||
230 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex]; | ||
231 | if (face == null) | ||
232 | { | ||
233 | textureEntry.CreateFace(cacheItems[i].TextureIndex); | ||
234 | textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID = | ||
235 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; | ||
236 | continue; | ||
237 | } | ||
238 | cacheItems[i].TextureID = | ||
239 | face.TextureID; | ||
240 | } | ||
241 | else | ||
242 | { | ||
243 | m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | for (int i = 0; i < maxCacheitemsLoop; i++) | ||
248 | { | ||
249 | if (cacheItems[i].TextureAsset == null) | ||
250 | { | ||
251 | cacheItems[i].TextureAsset = | ||
252 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | |||
257 | |||
258 | |||
259 | p.Appearance.WearableCacheItems = cacheItems; | ||
260 | |||
261 | |||
262 | |||
263 | if (m_BakedTextureModule != null) | ||
264 | { | ||
265 | m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); | ||
266 | p.Appearance.WearableCacheItemsDirty = true; | ||
267 | |||
268 | } | ||
269 | } | ||
270 | } | ||
93 | } | 271 | } |
94 | 272 | ||
95 | public void PostInitialise() | 273 | public void PostInitialise() |
96 | { | 274 | { |
97 | } | 275 | } |
98 | 276 | ||
277 | |||
278 | |||
99 | public void Close() { } | 279 | public void Close() { } |
100 | 280 | ||
101 | public string Name { get { return "UploadBakedTextureModule"; } } | 281 | public string Name { get { return "UploadBakedTextureModule"; } } |
@@ -112,13 +292,15 @@ namespace OpenSim.Region.ClientStack.Linden | |||
112 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); | 292 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); |
113 | if (m_URL == "localhost") | 293 | if (m_URL == "localhost") |
114 | { | 294 | { |
295 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( | ||
296 | caps, m_scene.AssetService, m_persistBakedTextures); | ||
297 | |||
115 | caps.RegisterHandler( | 298 | caps.RegisterHandler( |
116 | "UploadBakedTexture", | 299 | "UploadBakedTexture", |
117 | new RestStreamHandler( | 300 | new RestStreamHandler( |
118 | "POST", | 301 | "POST", |
119 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, | 302 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, |
120 | new UploadBakedTextureHandler( | 303 | avatarhandler.UploadBakedTexture, |
121 | caps, m_scene.AssetService, m_persistBakedTextures).UploadBakedTexture, | ||
122 | "UploadBakedTexture", | 304 | "UploadBakedTexture", |
123 | agentID.ToString())); | 305 | agentID.ToString())); |
124 | 306 | ||
@@ -129,4 +311,4 @@ namespace OpenSim.Region.ClientStack.Linden | |||
129 | } | 311 | } |
130 | } | 312 | } |
131 | } | 313 | } |
132 | } \ No newline at end of file | 314 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs index 340d2e7..6fc35cd 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs | |||
@@ -34,9 +34,7 @@ using log4net; | |||
34 | using Nini.Config; | 34 | using Nini.Config; |
35 | using Mono.Addins; | 35 | using Mono.Addins; |
36 | using OpenMetaverse; | 36 | using OpenMetaverse; |
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Monitoring; | ||
40 | using OpenSim.Framework.Servers; | 38 | using OpenSim.Framework.Servers; |
41 | using OpenSim.Framework.Servers.HttpServer; | 39 | using OpenSim.Framework.Servers.HttpServer; |
42 | using OpenSim.Region.Framework.Interfaces; | 40 | using OpenSim.Region.Framework.Interfaces; |
@@ -45,6 +43,9 @@ using OpenSim.Framework.Capabilities; | |||
45 | using OpenSim.Services.Interfaces; | 43 | using OpenSim.Services.Interfaces; |
46 | using Caps = OpenSim.Framework.Capabilities.Caps; | 44 | using Caps = OpenSim.Framework.Capabilities.Caps; |
47 | using OpenSim.Capabilities.Handlers; | 45 | using OpenSim.Capabilities.Handlers; |
46 | using OpenSim.Framework.Monitoring; | ||
47 | using OpenMetaverse; | ||
48 | using OpenMetaverse.StructuredData; | ||
48 | 49 | ||
49 | namespace OpenSim.Region.ClientStack.Linden | 50 | namespace OpenSim.Region.ClientStack.Linden |
50 | { | 51 | { |
@@ -63,7 +64,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
63 | public List<UUID> folders; | 64 | public List<UUID> folders; |
64 | } | 65 | } |
65 | 66 | ||
66 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 67 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
67 | 68 | ||
68 | private Scene m_scene; | 69 | private Scene m_scene; |
69 | 70 | ||
@@ -248,7 +249,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
248 | { | 249 | { |
249 | if (!reqinfo.folders.Contains(folderID)) | 250 | if (!reqinfo.folders.Contains(folderID)) |
250 | { | 251 | { |
251 | //TODO: Port COF handling from Avination | 252 | if (sp.COF != UUID.Zero && sp.COF == folderID) |
253 | highPriority = true; | ||
252 | reqinfo.folders.Add(folderID); | 254 | reqinfo.folders.Add(folderID); |
253 | } | 255 | } |
254 | } | 256 | } |