diff options
Diffstat (limited to 'OpenSim/Region/ClientStack')
22 files changed, 4261 insertions, 2304 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 774202e..1236e83 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; |
@@ -44,7 +45,6 @@ using OpenSim.Region.Framework.Scenes; | |||
44 | using OpenSim.Region.Framework.Scenes.Serialization; | 45 | using OpenSim.Region.Framework.Scenes.Serialization; |
45 | using OpenSim.Framework.Servers; | 46 | using OpenSim.Framework.Servers; |
46 | using OpenSim.Framework.Servers.HttpServer; | 47 | using OpenSim.Framework.Servers.HttpServer; |
47 | using OpenSim.Framework.Client; | ||
48 | using OpenSim.Services.Interfaces; | 48 | using OpenSim.Services.Interfaces; |
49 | 49 | ||
50 | using Caps = OpenSim.Framework.Capabilities.Caps; | 50 | using Caps = OpenSim.Framework.Capabilities.Caps; |
@@ -55,14 +55,16 @@ using PermissionMask = OpenSim.Framework.PermissionMask; | |||
55 | namespace OpenSim.Region.ClientStack.Linden | 55 | namespace OpenSim.Region.ClientStack.Linden |
56 | { | 56 | { |
57 | public delegate void UpLoadedAsset( | 57 | public delegate void UpLoadedAsset( |
58 | string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, | 58 | string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, |
59 | 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); | ||
60 | 62 | ||
61 | public delegate UUID UpdateItem(UUID itemID, byte[] data); | 63 | public delegate UUID UpdateItem(UUID itemID, byte[] data); |
62 | 64 | ||
63 | 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); |
64 | 66 | ||
65 | public delegate void NewInventoryItem(UUID userID, InventoryItemBase item); | 67 | public delegate void NewInventoryItem(UUID userID, InventoryItemBase item, uint cost); |
66 | 68 | ||
67 | public delegate void NewAsset(AssetBase asset); | 69 | public delegate void NewAsset(AssetBase asset); |
68 | 70 | ||
@@ -88,6 +90,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
88 | 90 | ||
89 | private Scene m_Scene; | 91 | private Scene m_Scene; |
90 | private Caps m_HostCapsObj; | 92 | private Caps m_HostCapsObj; |
93 | private ModelCost m_ModelCost; | ||
91 | 94 | ||
92 | private static readonly string m_requestPath = "0000/"; | 95 | private static readonly string m_requestPath = "0000/"; |
93 | // private static readonly string m_mapLayerPath = "0001/"; | 96 | // private static readonly string m_mapLayerPath = "0001/"; |
@@ -99,8 +102,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
99 | private static readonly string m_copyFromNotecardPath = "0007/"; | 102 | private static readonly string m_copyFromNotecardPath = "0007/"; |
100 | // 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. |
101 | private static readonly string m_getObjectPhysicsDataPath = "0101/"; | 104 | private static readonly string m_getObjectPhysicsDataPath = "0101/"; |
102 | /* 0102 - 0103 RESERVED */ | 105 | private static readonly string m_getObjectCostPath = "0102/"; |
106 | private static readonly string m_ResourceCostSelectedPath = "0103/"; | ||
103 | private static readonly string m_UpdateAgentInformationPath = "0500/"; | 107 | private static readonly string m_UpdateAgentInformationPath = "0500/"; |
108 | private static readonly string m_animSetTaskUpdatePath = "0260/"; | ||
104 | 109 | ||
105 | // These are callbacks which will be setup by the scene so that we can update scene data when we | 110 | // These are callbacks which will be setup by the scene so that we can update scene data when we |
106 | // receive capability calls | 111 | // receive capability calls |
@@ -115,12 +120,50 @@ namespace OpenSim.Region.ClientStack.Linden | |||
115 | private IAssetService m_assetService; | 120 | private IAssetService m_assetService; |
116 | private bool m_dumpAssetsToFile = false; | 121 | private bool m_dumpAssetsToFile = false; |
117 | private string m_regionName; | 122 | private string m_regionName; |
123 | |||
118 | private int m_levelUpload = 0; | 124 | private int m_levelUpload = 0; |
119 | 125 | ||
126 | private bool m_enableFreeTestUpload = false; // allows "TEST-" prefix hack | ||
127 | private bool m_ForceFreeTestUpload = false; // forces all uploads to be test | ||
128 | |||
129 | private bool m_enableModelUploadTextureToInventory = false; // place uploaded textures also in inventory | ||
130 | // may not be visible till relog | ||
131 | |||
132 | private bool m_RestrictFreeTestUploadPerms = false; // reduces also the permitions. Needs a creator defined!! | ||
133 | private UUID m_testAssetsCreatorID = UUID.Zero; | ||
134 | |||
135 | private float m_PrimScaleMin = 0.001f; | ||
136 | |||
137 | private enum FileAgentInventoryState : int | ||
138 | { | ||
139 | idle = 0, | ||
140 | processRequest = 1, | ||
141 | waitUpload = 2, | ||
142 | processUpload = 3 | ||
143 | } | ||
144 | private FileAgentInventoryState m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
145 | |||
120 | public BunchOfCaps(Scene scene, Caps caps) | 146 | public BunchOfCaps(Scene scene, Caps caps) |
121 | { | 147 | { |
122 | m_Scene = scene; | 148 | m_Scene = scene; |
123 | m_HostCapsObj = caps; | 149 | m_HostCapsObj = caps; |
150 | |||
151 | // create a model upload cost provider | ||
152 | m_ModelCost = new ModelCost(); | ||
153 | // tell it about scene object limits | ||
154 | m_ModelCost.NonPhysicalPrimScaleMax = m_Scene.m_maxNonphys; | ||
155 | m_ModelCost.PhysicalPrimScaleMax = m_Scene.m_maxPhys; | ||
156 | |||
157 | // m_ModelCost.ObjectLinkedPartsMax = ?? | ||
158 | // m_ModelCost.PrimScaleMin = ?? | ||
159 | |||
160 | m_PrimScaleMin = m_ModelCost.PrimScaleMin; | ||
161 | float modelTextureUploadFactor = m_ModelCost.ModelTextureCostFactor; | ||
162 | float modelUploadFactor = m_ModelCost.ModelMeshCostFactor; | ||
163 | float modelMinUploadCostFactor = m_ModelCost.ModelMinCostFactor; | ||
164 | float modelPrimCreationCost = m_ModelCost.primCreationCost; | ||
165 | float modelMeshByteCost = m_ModelCost.bytecost; | ||
166 | |||
124 | IConfigSource config = m_Scene.Config; | 167 | IConfigSource config = m_Scene.Config; |
125 | if (config != null) | 168 | if (config != null) |
126 | { | 169 | { |
@@ -135,6 +178,37 @@ namespace OpenSim.Region.ClientStack.Linden | |||
135 | { | 178 | { |
136 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | 179 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); |
137 | } | 180 | } |
181 | // economy for model upload | ||
182 | IConfig EconomyConfig = config.Configs["Economy"]; | ||
183 | if (EconomyConfig != null) | ||
184 | { | ||
185 | modelUploadFactor = EconomyConfig.GetFloat("MeshModelUploadCostFactor", modelUploadFactor); | ||
186 | modelTextureUploadFactor = EconomyConfig.GetFloat("MeshModelUploadTextureCostFactor", modelTextureUploadFactor); | ||
187 | modelMinUploadCostFactor = EconomyConfig.GetFloat("MeshModelMinCostFactor", modelMinUploadCostFactor); | ||
188 | // next 2 are normalized so final cost is afected by modelUploadFactor above and normal cost | ||
189 | modelPrimCreationCost = EconomyConfig.GetFloat("ModelPrimCreationCost", modelPrimCreationCost); | ||
190 | modelMeshByteCost = EconomyConfig.GetFloat("ModelMeshByteCost", modelMeshByteCost); | ||
191 | |||
192 | m_enableModelUploadTextureToInventory = EconomyConfig.GetBoolean("MeshModelAllowTextureToInventory", m_enableModelUploadTextureToInventory); | ||
193 | |||
194 | m_RestrictFreeTestUploadPerms = EconomyConfig.GetBoolean("m_RestrictFreeTestUploadPerms", m_RestrictFreeTestUploadPerms); | ||
195 | m_enableFreeTestUpload = EconomyConfig.GetBoolean("AllowFreeTestUpload", m_enableFreeTestUpload); | ||
196 | m_ForceFreeTestUpload = EconomyConfig.GetBoolean("ForceFreeTestUpload", m_ForceFreeTestUpload); | ||
197 | string testcreator = EconomyConfig.GetString("TestAssetsCreatorID", ""); | ||
198 | if (testcreator != "") | ||
199 | { | ||
200 | UUID id; | ||
201 | UUID.TryParse(testcreator, out id); | ||
202 | if (id != null) | ||
203 | m_testAssetsCreatorID = id; | ||
204 | } | ||
205 | |||
206 | m_ModelCost.ModelMeshCostFactor = modelUploadFactor; | ||
207 | m_ModelCost.ModelTextureCostFactor = modelTextureUploadFactor; | ||
208 | m_ModelCost.ModelMinCostFactor = modelMinUploadCostFactor; | ||
209 | m_ModelCost.primCreationCost = modelPrimCreationCost; | ||
210 | m_ModelCost.bytecost = modelMeshByteCost; | ||
211 | } | ||
138 | } | 212 | } |
139 | 213 | ||
140 | m_assetService = m_Scene.AssetService; | 214 | m_assetService = m_Scene.AssetService; |
@@ -146,6 +220,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
146 | ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; | 220 | ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset; |
147 | TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; | 221 | TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset; |
148 | GetClient = m_Scene.SceneGraph.GetControllingClient; | 222 | GetClient = m_Scene.SceneGraph.GetControllingClient; |
223 | |||
224 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
149 | } | 225 | } |
150 | 226 | ||
151 | /// <summary> | 227 | /// <summary> |
@@ -173,13 +249,31 @@ namespace OpenSim.Region.ClientStack.Linden | |||
173 | //m_capsHandlers["MapLayer"] = | 249 | //m_capsHandlers["MapLayer"] = |
174 | // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST", | 250 | // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST", |
175 | // capsBase + m_mapLayerPath, | 251 | // capsBase + m_mapLayerPath, |
176 | // GetMapLayer); | 252 | // GetMapLayer); |
253 | |||
254 | IRequestHandler getObjectPhysicsDataHandler | ||
255 | = new RestStreamHandler( | ||
256 | "POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData, "GetObjectPhysicsData", null); | ||
257 | m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler); | ||
258 | |||
259 | IRequestHandler getObjectCostHandler = new RestStreamHandler("POST", capsBase + m_getObjectCostPath, GetObjectCost); | ||
260 | m_HostCapsObj.RegisterHandler("GetObjectCost", getObjectCostHandler); | ||
261 | IRequestHandler ResourceCostSelectedHandler = new RestStreamHandler("POST", capsBase + m_ResourceCostSelectedPath, ResourceCostSelected); | ||
262 | m_HostCapsObj.RegisterHandler("ResourceCostSelected", ResourceCostSelectedHandler); | ||
263 | |||
264 | |||
177 | IRequestHandler req | 265 | IRequestHandler req |
178 | = new RestStreamHandler( | 266 | = new RestStreamHandler( |
179 | "POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory, "UpdateScript", null); | 267 | "POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory, "UpdateScript", null); |
180 | 268 | ||
181 | m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req); | 269 | m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req); |
182 | m_HostCapsObj.RegisterHandler("UpdateScriptTask", req); | 270 | m_HostCapsObj.RegisterHandler("UpdateScriptTask", req); |
271 | |||
272 | // IRequestHandler animSetRequestHandler | ||
273 | // = new RestStreamHandler( | ||
274 | // "POST", capsBase + m_animSetTaskUpdatePath, AnimSetTaskInventory, "UpdateScript", null); | ||
275 | |||
276 | // m_HostCapsObj.RegisterHandler("UpdateAnimSetTaskInventory", animSetRequestHandler); | ||
183 | } | 277 | } |
184 | catch (Exception e) | 278 | catch (Exception e) |
185 | { | 279 | { |
@@ -191,7 +285,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
191 | { | 285 | { |
192 | try | 286 | try |
193 | { | 287 | { |
194 | // I don't think this one works... | ||
195 | m_HostCapsObj.RegisterHandler( | 288 | m_HostCapsObj.RegisterHandler( |
196 | "NewFileAgentInventory", | 289 | "NewFileAgentInventory", |
197 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( | 290 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>( |
@@ -206,13 +299,11 @@ namespace OpenSim.Region.ClientStack.Linden | |||
206 | "POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory, "Update*", null); | 299 | "POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory, "Update*", null); |
207 | 300 | ||
208 | m_HostCapsObj.RegisterHandler("UpdateNotecardAgentInventory", req); | 301 | m_HostCapsObj.RegisterHandler("UpdateNotecardAgentInventory", req); |
302 | m_HostCapsObj.RegisterHandler("UpdateAnimSetAgentInventory", req); | ||
209 | m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req); | 303 | m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req); |
210 | m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); | 304 | m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); |
211 | 305 | ||
212 | IRequestHandler getObjectPhysicsDataHandler | 306 | |
213 | = new RestStreamHandler( | ||
214 | "POST", capsBase + m_getObjectPhysicsDataPath, GetObjectPhysicsData, "GetObjectPhysicsData", null); | ||
215 | m_HostCapsObj.RegisterHandler("GetObjectPhysicsData", getObjectPhysicsDataHandler); | ||
216 | 307 | ||
217 | IRequestHandler UpdateAgentInformationHandler | 308 | IRequestHandler UpdateAgentInformationHandler |
218 | = new RestStreamHandler( | 309 | = new RestStreamHandler( |
@@ -268,8 +359,11 @@ namespace OpenSim.Region.ClientStack.Linden | |||
268 | public string SeedCapRequest(string request, string path, string param, | 359 | public string SeedCapRequest(string request, string path, string param, |
269 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 360 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
270 | { | 361 | { |
271 | // m_log.DebugFormat( | 362 | m_log.DebugFormat( |
272 | // "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID); | 363 | "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID); |
364 | |||
365 | if (!m_HostCapsObj.WaitForActivation()) | ||
366 | return string.Empty; | ||
273 | 367 | ||
274 | if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint)) | 368 | if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint)) |
275 | { | 369 | { |
@@ -400,62 +494,178 @@ namespace OpenSim.Region.ClientStack.Linden | |||
400 | //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); | 494 | //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); |
401 | //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); | 495 | //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); |
402 | 496 | ||
497 | // start by getting the client | ||
498 | IClientAPI client = null; | ||
499 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); | ||
500 | |||
501 | // check current state so we only have one service at a time | ||
502 | lock (m_ModelCost) | ||
503 | { | ||
504 | switch (m_FileAgentInventoryState) | ||
505 | { | ||
506 | case FileAgentInventoryState.processRequest: | ||
507 | case FileAgentInventoryState.processUpload: | ||
508 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
509 | resperror.message = "Uploader busy processing previus request"; | ||
510 | resperror.identifier = UUID.Zero; | ||
511 | |||
512 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | ||
513 | errorResponse.uploader = ""; | ||
514 | errorResponse.state = "error"; | ||
515 | errorResponse.error = resperror; | ||
516 | return errorResponse; | ||
517 | break; | ||
518 | case FileAgentInventoryState.waitUpload: | ||
519 | // todo stop current uploader server | ||
520 | break; | ||
521 | case FileAgentInventoryState.idle: | ||
522 | default: | ||
523 | break; | ||
524 | } | ||
525 | |||
526 | m_FileAgentInventoryState = FileAgentInventoryState.processRequest; | ||
527 | } | ||
528 | |||
529 | int cost = 0; | ||
530 | int nreqtextures = 0; | ||
531 | int nreqmeshs= 0; | ||
532 | int nreqinstances = 0; | ||
533 | bool IsAtestUpload = false; | ||
534 | |||
535 | string assetName = llsdRequest.name; | ||
536 | |||
537 | LLSDAssetUploadResponseData meshcostdata = new LLSDAssetUploadResponseData(); | ||
538 | |||
403 | if (llsdRequest.asset_type == "texture" || | 539 | if (llsdRequest.asset_type == "texture" || |
404 | llsdRequest.asset_type == "animation" || | 540 | llsdRequest.asset_type == "animation" || |
541 | llsdRequest.asset_type == "animatn" || // this is the asset name actually used by viewers | ||
542 | llsdRequest.asset_type == "mesh" || | ||
405 | llsdRequest.asset_type == "sound") | 543 | llsdRequest.asset_type == "sound") |
406 | { | 544 | { |
407 | ScenePresence avatar = null; | 545 | ScenePresence avatar = null; |
408 | IClientAPI client = null; | ||
409 | m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); | 546 | m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); |
410 | 547 | ||
411 | // check user level | 548 | // check user level |
412 | if (avatar != null) | 549 | if (avatar != null) |
413 | { | 550 | { |
414 | client = avatar.ControllingClient; | ||
415 | |||
416 | if (avatar.UserLevel < m_levelUpload) | 551 | if (avatar.UserLevel < m_levelUpload) |
417 | { | 552 | { |
418 | if (client != null) | 553 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); |
419 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); | 554 | resperror.message = "Insufficient permissions to upload"; |
555 | resperror.identifier = UUID.Zero; | ||
420 | 556 | ||
421 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | 557 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); |
422 | errorResponse.uploader = ""; | 558 | errorResponse.uploader = ""; |
423 | errorResponse.state = "error"; | 559 | errorResponse.state = "error"; |
560 | errorResponse.error = resperror; | ||
561 | lock (m_ModelCost) | ||
562 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
424 | return errorResponse; | 563 | return errorResponse; |
425 | } | 564 | } |
426 | } | 565 | } |
427 | 566 | ||
428 | // check funds | 567 | // check test upload and funds |
429 | if (client != null) | 568 | if (client != null) |
430 | { | 569 | { |
431 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); | 570 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); |
432 | 571 | ||
572 | int baseCost = 0; | ||
433 | if (mm != null) | 573 | if (mm != null) |
574 | baseCost = mm.UploadCharge; | ||
575 | |||
576 | string warning = String.Empty; | ||
577 | |||
578 | if (llsdRequest.asset_type == "mesh") | ||
434 | { | 579 | { |
435 | if (!mm.UploadCovered(client.AgentId, mm.UploadCharge)) | 580 | string error; |
581 | int modelcost; | ||
582 | |||
583 | |||
584 | if (!m_ModelCost.MeshModelCost(llsdRequest.asset_resources, baseCost, out modelcost, | ||
585 | meshcostdata, out error, ref warning)) | ||
436 | { | 586 | { |
437 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | 587 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); |
588 | resperror.message = error; | ||
589 | resperror.identifier = UUID.Zero; | ||
438 | 590 | ||
439 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | 591 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); |
440 | errorResponse.uploader = ""; | 592 | errorResponse.uploader = ""; |
441 | errorResponse.state = "error"; | 593 | errorResponse.state = "error"; |
594 | errorResponse.error = resperror; | ||
595 | |||
596 | lock (m_ModelCost) | ||
597 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
442 | return errorResponse; | 598 | return errorResponse; |
443 | } | 599 | } |
600 | cost = modelcost; | ||
601 | } | ||
602 | else | ||
603 | { | ||
604 | cost = baseCost; | ||
605 | } | ||
606 | |||
607 | if (cost > 0 && mm != null) | ||
608 | { | ||
609 | // check for test upload | ||
610 | |||
611 | if (m_ForceFreeTestUpload) // all are test | ||
612 | { | ||
613 | if (!(assetName.Length > 5 && assetName.StartsWith("TEST-"))) // has normal name lets change it | ||
614 | assetName = "TEST-" + assetName; | ||
615 | |||
616 | IsAtestUpload = true; | ||
617 | } | ||
618 | |||
619 | else if (m_enableFreeTestUpload) // only if prefixed with "TEST-" | ||
620 | { | ||
621 | |||
622 | IsAtestUpload = (assetName.Length > 5 && assetName.StartsWith("TEST-")); | ||
623 | } | ||
624 | |||
625 | |||
626 | if(IsAtestUpload) // let user know, still showing cost estimation | ||
627 | 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"; | ||
628 | |||
629 | // check funds | ||
630 | else | ||
631 | { | ||
632 | if (!mm.UploadCovered(client.AgentId, (int)cost)) | ||
633 | { | ||
634 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
635 | resperror.message = "Insuficient funds"; | ||
636 | resperror.identifier = UUID.Zero; | ||
637 | |||
638 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | ||
639 | errorResponse.uploader = ""; | ||
640 | errorResponse.state = "error"; | ||
641 | errorResponse.error = resperror; | ||
642 | lock (m_ModelCost) | ||
643 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
644 | return errorResponse; | ||
645 | } | ||
646 | } | ||
444 | } | 647 | } |
648 | |||
649 | if (client != null && warning != String.Empty) | ||
650 | client.SendAgentAlertMessage(warning, true); | ||
445 | } | 651 | } |
446 | } | 652 | } |
447 | 653 | ||
448 | string assetName = llsdRequest.name; | ||
449 | string assetDes = llsdRequest.description; | 654 | string assetDes = llsdRequest.description; |
450 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; | 655 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; |
451 | UUID newAsset = UUID.Random(); | 656 | UUID newAsset = UUID.Random(); |
452 | UUID newInvItem = UUID.Random(); | 657 | UUID newInvItem = UUID.Random(); |
453 | UUID parentFolder = llsdRequest.folder_id; | 658 | UUID parentFolder = llsdRequest.folder_id; |
454 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | 659 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); |
660 | UUID texturesFolder = UUID.Zero; | ||
661 | |||
662 | if(!IsAtestUpload && m_enableModelUploadTextureToInventory) | ||
663 | texturesFolder = llsdRequest.texture_folder_id; | ||
455 | 664 | ||
456 | AssetUploader uploader = | 665 | AssetUploader uploader = |
457 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | 666 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, |
458 | llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); | 667 | llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost, |
668 | texturesFolder, nreqtextures, nreqmeshs, nreqinstances, IsAtestUpload); | ||
459 | 669 | ||
460 | m_HostCapsObj.HttpListener.AddStreamHandler( | 670 | m_HostCapsObj.HttpListener.AddStreamHandler( |
461 | new BinaryStreamHandler( | 671 | new BinaryStreamHandler( |
@@ -473,10 +683,22 @@ namespace OpenSim.Region.ClientStack.Linden | |||
473 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + | 683 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + |
474 | uploaderPath; | 684 | uploaderPath; |
475 | 685 | ||
686 | |||
476 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | 687 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); |
477 | uploadResponse.uploader = uploaderURL; | 688 | uploadResponse.uploader = uploaderURL; |
478 | uploadResponse.state = "upload"; | 689 | uploadResponse.state = "upload"; |
690 | uploadResponse.upload_price = (int)cost; | ||
691 | |||
692 | if (llsdRequest.asset_type == "mesh") | ||
693 | { | ||
694 | uploadResponse.data = meshcostdata; | ||
695 | } | ||
696 | |||
479 | uploader.OnUpLoad += UploadCompleteHandler; | 697 | uploader.OnUpLoad += UploadCompleteHandler; |
698 | |||
699 | lock (m_ModelCost) | ||
700 | m_FileAgentInventoryState = FileAgentInventoryState.waitUpload; | ||
701 | |||
480 | return uploadResponse; | 702 | return uploadResponse; |
481 | } | 703 | } |
482 | 704 | ||
@@ -488,8 +710,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
488 | /// <param name="data"></param> | 710 | /// <param name="data"></param> |
489 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, | 711 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, |
490 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, | 712 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, |
491 | string assetType) | 713 | string assetType, int cost, |
714 | UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, | ||
715 | bool IsAtestUpload, ref string error) | ||
492 | { | 716 | { |
717 | |||
718 | lock (m_ModelCost) | ||
719 | m_FileAgentInventoryState = FileAgentInventoryState.processUpload; | ||
720 | |||
493 | m_log.DebugFormat( | 721 | m_log.DebugFormat( |
494 | "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", | 722 | "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", |
495 | assetID, inventoryItem, inventoryType, assetType); | 723 | assetID, inventoryItem, inventoryType, assetType); |
@@ -497,6 +725,34 @@ namespace OpenSim.Region.ClientStack.Linden | |||
497 | sbyte assType = 0; | 725 | sbyte assType = 0; |
498 | sbyte inType = 0; | 726 | sbyte inType = 0; |
499 | 727 | ||
728 | IClientAPI client = null; | ||
729 | |||
730 | UUID owner_id = m_HostCapsObj.AgentID; | ||
731 | UUID creatorID; | ||
732 | |||
733 | bool istest = IsAtestUpload && m_enableFreeTestUpload && (cost > 0); | ||
734 | |||
735 | bool restrictPerms = m_RestrictFreeTestUploadPerms && istest; | ||
736 | |||
737 | if (istest && m_testAssetsCreatorID != UUID.Zero) | ||
738 | creatorID = m_testAssetsCreatorID; | ||
739 | else | ||
740 | creatorID = owner_id; | ||
741 | |||
742 | string creatorIDstr = creatorID.ToString(); | ||
743 | |||
744 | IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); | ||
745 | if (mm != null) | ||
746 | { | ||
747 | // make sure client still has enougth credit | ||
748 | if (!mm.UploadCovered(m_HostCapsObj.AgentID, (int)cost)) | ||
749 | { | ||
750 | error = "Insufficient funds."; | ||
751 | return; | ||
752 | } | ||
753 | } | ||
754 | |||
755 | // strings to types | ||
500 | if (inventoryType == "sound") | 756 | if (inventoryType == "sound") |
501 | { | 757 | { |
502 | inType = (sbyte)InventoryType.Sound; | 758 | inType = (sbyte)InventoryType.Sound; |
@@ -511,6 +767,12 @@ namespace OpenSim.Region.ClientStack.Linden | |||
511 | inType = (sbyte)InventoryType.Animation; | 767 | inType = (sbyte)InventoryType.Animation; |
512 | assType = (sbyte)AssetType.Animation; | 768 | assType = (sbyte)AssetType.Animation; |
513 | } | 769 | } |
770 | else if (inventoryType == "animset") | ||
771 | { | ||
772 | inType = (sbyte)CustomInventoryType.AnimationSet; | ||
773 | assType = (sbyte)CustomAssetType.AnimationSet; | ||
774 | m_log.Debug("got animset upload request"); | ||
775 | } | ||
514 | else if (inventoryType == "wearable") | 776 | else if (inventoryType == "wearable") |
515 | { | 777 | { |
516 | inType = (sbyte)InventoryType.Wearable; | 778 | inType = (sbyte)InventoryType.Wearable; |
@@ -526,159 +788,253 @@ namespace OpenSim.Region.ClientStack.Linden | |||
526 | } | 788 | } |
527 | else if (inventoryType == "object") | 789 | else if (inventoryType == "object") |
528 | { | 790 | { |
529 | inType = (sbyte)InventoryType.Object; | 791 | if (assetType == "mesh") // this code for now is for mesh models uploads only |
530 | assType = (sbyte)AssetType.Object; | ||
531 | |||
532 | List<Vector3> positions = new List<Vector3>(); | ||
533 | List<Quaternion> rotations = new List<Quaternion>(); | ||
534 | OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data); | ||
535 | OSDArray instance_list = (OSDArray)request["instance_list"]; | ||
536 | OSDArray mesh_list = (OSDArray)request["mesh_list"]; | ||
537 | OSDArray texture_list = (OSDArray)request["texture_list"]; | ||
538 | SceneObjectGroup grp = null; | ||
539 | |||
540 | InventoryFolderBase textureUploadFolder = null; | ||
541 | |||
542 | List<InventoryFolderBase> foldersToUpdate = new List<InventoryFolderBase>(); | ||
543 | List<InventoryItemBase> itemsToUpdate = new List<InventoryItemBase>(); | ||
544 | IClientInventory clientInv = null; | ||
545 | |||
546 | if (texture_list.Count > 0) | ||
547 | { | 792 | { |
548 | ScenePresence avatar = null; | 793 | inType = (sbyte)InventoryType.Object; |
549 | m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); | 794 | assType = (sbyte)AssetType.Object; |
795 | |||
796 | List<Vector3> positions = new List<Vector3>(); | ||
797 | List<Quaternion> rotations = new List<Quaternion>(); | ||
798 | OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data); | ||
799 | |||
800 | // compare and get updated information | ||
801 | /* does nothing still we do need something to avoid special viewer to upload something diferent from the cost estimation | ||
802 | bool mismatchError = true; | ||
550 | 803 | ||
551 | if (avatar != null) | 804 | while (mismatchError) |
552 | { | 805 | { |
553 | IClientCore core = (IClientCore)avatar.ControllingClient; | 806 | mismatchError = false; |
807 | } | ||
808 | |||
809 | if (mismatchError) | ||
810 | { | ||
811 | error = "Upload and fee estimation information don't match"; | ||
812 | lock (m_ModelCost) | ||
813 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
814 | |||
815 | return; | ||
816 | } | ||
817 | */ | ||
818 | OSDArray instance_list = (OSDArray)request["instance_list"]; | ||
819 | OSDArray mesh_list = (OSDArray)request["mesh_list"]; | ||
820 | OSDArray texture_list = (OSDArray)request["texture_list"]; | ||
821 | SceneObjectGroup grp = null; | ||
822 | |||
823 | // create and store texture assets | ||
824 | bool doTextInv = (!istest && m_enableModelUploadTextureToInventory && | ||
825 | texturesFolder != UUID.Zero); | ||
554 | 826 | ||
555 | if (core.TryGet<IClientInventory>(out clientInv)) | 827 | |
828 | List<UUID> textures = new List<UUID>(); | ||
829 | |||
830 | |||
831 | // if (doTextInv) | ||
832 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); | ||
833 | |||
834 | if(client == null) // don't put textures in inventory if there is no client | ||
835 | doTextInv = false; | ||
836 | |||
837 | for (int i = 0; i < texture_list.Count; i++) | ||
838 | { | ||
839 | AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, creatorIDstr); | ||
840 | textureAsset.Data = texture_list[i].AsBinary(); | ||
841 | if (istest) | ||
842 | textureAsset.Local = true; | ||
843 | m_assetService.Store(textureAsset); | ||
844 | textures.Add(textureAsset.FullID); | ||
845 | |||
846 | if (doTextInv) | ||
556 | { | 847 | { |
557 | var systemTextureFolder = m_Scene.InventoryService.GetFolderForType(m_HostCapsObj.AgentID, FolderType.Texture); | 848 | string name = assetName; |
558 | textureUploadFolder = new InventoryFolderBase(UUID.Random(), assetName, m_HostCapsObj.AgentID, (short)FolderType.None, systemTextureFolder.ID, 1); | 849 | if (name.Length > 25) |
559 | if (m_Scene.InventoryService.AddFolder(textureUploadFolder)) | 850 | name = name.Substring(0, 24); |
560 | { | 851 | name += "_Texture#" + i.ToString(); |
561 | foldersToUpdate.Add(textureUploadFolder); | 852 | InventoryItemBase texitem = new InventoryItemBase(); |
853 | texitem.Owner = m_HostCapsObj.AgentID; | ||
854 | texitem.CreatorId = creatorIDstr; | ||
855 | texitem.CreatorData = String.Empty; | ||
856 | texitem.ID = UUID.Random(); | ||
857 | texitem.AssetID = textureAsset.FullID; | ||
858 | texitem.Description = "mesh model texture"; | ||
859 | texitem.Name = name; | ||
860 | texitem.AssetType = (int)AssetType.Texture; | ||
861 | texitem.InvType = (int)InventoryType.Texture; | ||
862 | texitem.Folder = texturesFolder; | ||
863 | |||
864 | texitem.CurrentPermissions | ||
865 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export); | ||
866 | |||
867 | texitem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
868 | texitem.EveryOnePermissions = 0; | ||
869 | texitem.NextPermissions = (uint)PermissionMask.All; | ||
870 | texitem.CreationDate = Util.UnixTimeSinceEpoch(); | ||
871 | |||
872 | m_Scene.AddInventoryItem(client, texitem); | ||
873 | texitem = null; | ||
874 | } | ||
875 | } | ||
562 | 876 | ||
563 | m_log.DebugFormat( | 877 | // create and store meshs assets |
564 | "[BUNCH OF CAPS]: Created new folder '{0}' ({1}) for textures uploaded with mesh object {2}", | 878 | List<UUID> meshAssets = new List<UUID>(); |
565 | textureUploadFolder.Name, textureUploadFolder.ID, assetName); | 879 | List<bool> meshAvatarSkeletons = new List<bool>(); |
566 | } | 880 | List<bool> meshAvatarColliders = new List<bool>(); |
567 | else | 881 | |
882 | bool curAvSkeleton; | ||
883 | bool curAvCollider; | ||
884 | for (int i = 0; i < mesh_list.Count; i++) | ||
885 | { | ||
886 | curAvSkeleton = false; | ||
887 | curAvCollider = false; | ||
888 | |||
889 | // we do need to parse the mesh now | ||
890 | OSD osd = OSDParser.DeserializeLLSDBinary(mesh_list[i]); | ||
891 | if (osd is OSDMap) | ||
892 | { | ||
893 | OSDMap mosd = (OSDMap)osd; | ||
894 | if (mosd.ContainsKey("skeleton")) | ||
568 | { | 895 | { |
569 | textureUploadFolder = null; | 896 | OSDMap skeleton = (OSDMap)mosd["skeleton"]; |
897 | int sksize = skeleton["size"].AsInteger(); | ||
898 | if (sksize > 0) | ||
899 | curAvSkeleton = true; | ||
570 | } | 900 | } |
571 | } | 901 | } |
572 | } | ||
573 | } | ||
574 | 902 | ||
575 | List<UUID> textures = new List<UUID>(); | 903 | AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, creatorIDstr); |
576 | for (int i = 0; i < texture_list.Count; i++) | 904 | meshAsset.Data = mesh_list[i].AsBinary(); |
577 | { | 905 | if (istest) |
578 | AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, ""); | 906 | meshAsset.Local = true; |
579 | textureAsset.Data = texture_list[i].AsBinary(); | 907 | m_assetService.Store(meshAsset); |
580 | m_assetService.Store(textureAsset); | 908 | meshAssets.Add(meshAsset.FullID); |
581 | textures.Add(textureAsset.FullID); | 909 | meshAvatarSkeletons.Add(curAvSkeleton); |
910 | meshAvatarColliders.Add(curAvCollider); | ||
911 | |||
912 | // test code | ||
913 | if (curAvSkeleton && client != null) | ||
914 | { | ||
915 | string name = assetName; | ||
916 | if (name.Length > 25) | ||
917 | name = name.Substring(0, 24); | ||
918 | name += "_Mesh#" + i.ToString(); | ||
919 | InventoryItemBase meshitem = new InventoryItemBase(); | ||
920 | meshitem.Owner = m_HostCapsObj.AgentID; | ||
921 | meshitem.CreatorId = creatorIDstr; | ||
922 | meshitem.CreatorData = String.Empty; | ||
923 | meshitem.ID = UUID.Random(); | ||
924 | meshitem.AssetID = meshAsset.FullID; | ||
925 | meshitem.Description = "mesh "; | ||
926 | meshitem.Name = name; | ||
927 | meshitem.AssetType = (int)AssetType.Mesh; | ||
928 | meshitem.InvType = (int)InventoryType.Mesh; | ||
929 | // meshitem.Folder = UUID.Zero; // send to default | ||
930 | |||
931 | meshitem.Folder = parentFolder; // dont let it go to folder Meshes that viewers dont show | ||
932 | |||
933 | // If we set PermissionMask.All then when we rez the item the next permissions will replace the current | ||
934 | // (owner) permissions. This becomes a problem if next permissions are changed. | ||
935 | meshitem.CurrentPermissions | ||
936 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); | ||
937 | |||
938 | meshitem.BasePermissions = (uint)PermissionMask.All; | ||
939 | meshitem.EveryOnePermissions = 0; | ||
940 | meshitem.NextPermissions = (uint)PermissionMask.All; | ||
941 | meshitem.CreationDate = Util.UnixTimeSinceEpoch(); | ||
942 | |||
943 | m_Scene.AddInventoryItem(client, meshitem); | ||
944 | meshitem = null; | ||
945 | } | ||
946 | } | ||
582 | 947 | ||
583 | if (textureUploadFolder != null) | 948 | int skipedMeshs = 0; |
949 | // build prims from instances | ||
950 | for (int i = 0; i < instance_list.Count; i++) | ||
584 | { | 951 | { |
585 | InventoryItemBase textureItem = new InventoryItemBase(); | 952 | OSDMap inner_instance_list = (OSDMap)instance_list[i]; |
586 | textureItem.Owner = m_HostCapsObj.AgentID; | ||
587 | textureItem.CreatorId = m_HostCapsObj.AgentID.ToString(); | ||
588 | textureItem.CreatorData = String.Empty; | ||
589 | textureItem.ID = UUID.Random(); | ||
590 | textureItem.AssetID = textureAsset.FullID; | ||
591 | textureItem.Description = assetDescription; | ||
592 | textureItem.Name = assetName + " - Texture " + (i + 1).ToString(); | ||
593 | textureItem.AssetType = (int)AssetType.Texture; | ||
594 | textureItem.InvType = (int)InventoryType.Texture; | ||
595 | textureItem.Folder = textureUploadFolder.ID; | ||
596 | textureItem.CurrentPermissions | ||
597 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export); | ||
598 | textureItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
599 | textureItem.EveryOnePermissions = 0; | ||
600 | textureItem.NextPermissions = (uint)PermissionMask.All; | ||
601 | textureItem.CreationDate = Util.UnixTimeSinceEpoch(); | ||
602 | m_Scene.InventoryService.AddItem(textureItem); | ||
603 | itemsToUpdate.Add(textureItem); | ||
604 | |||
605 | m_log.DebugFormat( | ||
606 | "[BUNCH OF CAPS]: Created new inventory item '{0}' ({1}) for texture uploaded with mesh object {2}", | ||
607 | textureItem.Name, textureItem.ID, assetName); | ||
608 | } | ||
609 | } | ||
610 | 953 | ||
611 | if (clientInv != null && (foldersToUpdate.Count > 0 || itemsToUpdate.Count > 0)) | 954 | // skip prims that are 2 small |
612 | { | 955 | Vector3 scale = inner_instance_list["scale"].AsVector3(); |
613 | clientInv.SendBulkUpdateInventory(foldersToUpdate.ToArray(), itemsToUpdate.ToArray()); | ||
614 | } | ||
615 | 956 | ||
616 | for (int i = 0; i < mesh_list.Count; i++) | 957 | if (scale.X < m_PrimScaleMin || scale.Y < m_PrimScaleMin || scale.Z < m_PrimScaleMin) |
617 | { | 958 | { |
618 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); | 959 | skipedMeshs++; |
960 | continue; | ||
961 | } | ||
619 | 962 | ||
620 | Primitive.TextureEntry textureEntry | 963 | PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); |
621 | = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE); | ||
622 | OSDMap inner_instance_list = (OSDMap)instance_list[i]; | ||
623 | 964 | ||
624 | OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; | 965 | Primitive.TextureEntry textureEntry |
625 | for (uint face = 0; face < face_list.Count; face++) | 966 | = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE); |
626 | { | ||
627 | OSDMap faceMap = (OSDMap)face_list[(int)face]; | ||
628 | Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face); | ||
629 | if(faceMap.ContainsKey("fullbright")) | ||
630 | f.Fullbright = faceMap["fullbright"].AsBoolean(); | ||
631 | if (faceMap.ContainsKey ("diffuse_color")) | ||
632 | f.RGBA = faceMap["diffuse_color"].AsColor4(); | ||
633 | 967 | ||
634 | int textureNum = faceMap["image"].AsInteger(); | ||
635 | float imagerot = faceMap["imagerot"].AsInteger(); | ||
636 | float offsets = (float)faceMap["offsets"].AsReal(); | ||
637 | float offsett = (float)faceMap["offsett"].AsReal(); | ||
638 | float scales = (float)faceMap["scales"].AsReal(); | ||
639 | float scalet = (float)faceMap["scalet"].AsReal(); | ||
640 | 968 | ||
641 | if(imagerot != 0) | 969 | OSDArray face_list = (OSDArray)inner_instance_list["face_list"]; |
642 | f.Rotation = imagerot; | 970 | for (uint face = 0; face < face_list.Count; face++) |
971 | { | ||
972 | OSDMap faceMap = (OSDMap)face_list[(int)face]; | ||
973 | Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face); | ||
974 | if (faceMap.ContainsKey("fullbright")) | ||
975 | f.Fullbright = faceMap["fullbright"].AsBoolean(); | ||
976 | if (faceMap.ContainsKey("diffuse_color")) | ||
977 | f.RGBA = faceMap["diffuse_color"].AsColor4(); | ||
643 | 978 | ||
644 | if(offsets != 0) | 979 | int textureNum = faceMap["image"].AsInteger(); |
645 | f.OffsetU = offsets; | 980 | float imagerot = faceMap["imagerot"].AsInteger(); |
981 | float offsets = (float)faceMap["offsets"].AsReal(); | ||
982 | float offsett = (float)faceMap["offsett"].AsReal(); | ||
983 | float scales = (float)faceMap["scales"].AsReal(); | ||
984 | float scalet = (float)faceMap["scalet"].AsReal(); | ||
646 | 985 | ||
647 | if (offsett != 0) | 986 | if (imagerot != 0) |
648 | f.OffsetV = offsett; | 987 | f.Rotation = imagerot; |
649 | 988 | ||
650 | if (scales != 0) | 989 | if (offsets != 0) |
651 | f.RepeatU = scales; | 990 | f.OffsetU = offsets; |
652 | 991 | ||
653 | if (scalet != 0) | 992 | if (offsett != 0) |
654 | f.RepeatV = scalet; | 993 | f.OffsetV = offsett; |
655 | 994 | ||
656 | if (textures.Count > textureNum) | 995 | if (scales != 0) |
657 | f.TextureID = textures[textureNum]; | 996 | f.RepeatU = scales; |
658 | else | ||
659 | f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE; | ||
660 | 997 | ||
661 | textureEntry.FaceTextures[face] = f; | 998 | if (scalet != 0) |
662 | } | 999 | f.RepeatV = scalet; |
663 | 1000 | ||
664 | pbs.TextureEntry = textureEntry.GetBytes(); | 1001 | if (textures.Count > textureNum) |
1002 | f.TextureID = textures[textureNum]; | ||
1003 | else | ||
1004 | f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE; | ||
665 | 1005 | ||
666 | AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, ""); | 1006 | textureEntry.FaceTextures[face] = f; |
667 | meshAsset.Data = mesh_list[i].AsBinary(); | 1007 | } |
668 | m_assetService.Store(meshAsset); | ||
669 | 1008 | ||
670 | pbs.SculptEntry = true; | 1009 | pbs.TextureEntry = textureEntry.GetBytes(); |
671 | pbs.SculptTexture = meshAsset.FullID; | ||
672 | pbs.SculptType = (byte)SculptType.Mesh; | ||
673 | pbs.SculptData = meshAsset.Data; | ||
674 | 1010 | ||
675 | Vector3 position = inner_instance_list["position"].AsVector3(); | 1011 | bool hasmesh = false; |
676 | Vector3 scale = inner_instance_list["scale"].AsVector3(); | 1012 | if (inner_instance_list.ContainsKey("mesh")) // seems to happen always but ... |
677 | Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); | 1013 | { |
1014 | int meshindx = inner_instance_list["mesh"].AsInteger(); | ||
1015 | if (meshAssets.Count > meshindx) | ||
1016 | { | ||
1017 | pbs.SculptEntry = true; | ||
1018 | pbs.SculptType = (byte)SculptType.Mesh; | ||
1019 | pbs.SculptTexture = meshAssets[meshindx]; // actual asset UUID after meshs suport introduction | ||
1020 | // data will be requested from asset on rez (i hope) | ||
1021 | hasmesh = true; | ||
1022 | } | ||
1023 | } | ||
1024 | |||
1025 | Vector3 position = inner_instance_list["position"].AsVector3(); | ||
1026 | Quaternion rotation = inner_instance_list["rotation"].AsQuaternion(); | ||
1027 | |||
1028 | // for now viwers do send fixed defaults | ||
1029 | // but this may change | ||
1030 | // int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger(); | ||
1031 | byte physicsShapeType = (byte)PhysShapeType.prim; // default for mesh is simple convex | ||
1032 | if(hasmesh) | ||
1033 | physicsShapeType = (byte) PhysShapeType.convex; // default for mesh is simple convex | ||
1034 | // int material = inner_instance_list["material"].AsInteger(); | ||
1035 | byte material = (byte)Material.Wood; | ||
678 | 1036 | ||
679 | // no longer used - begin ------------------------ | 1037 | // no longer used - begin ------------------------ |
680 | // int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger(); | ||
681 | // int material = inner_instance_list["material"].AsInteger(); | ||
682 | // int mesh = inner_instance_list["mesh"].AsInteger(); | 1038 | // int mesh = inner_instance_list["mesh"].AsInteger(); |
683 | 1039 | ||
684 | // OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; | 1040 | // OSDMap permissions = (OSDMap)inner_instance_list["permissions"]; |
@@ -693,24 +1049,49 @@ namespace OpenSim.Region.ClientStack.Linden | |||
693 | // UUID owner_id = permissions["owner_id"].AsUUID(); | 1049 | // UUID owner_id = permissions["owner_id"].AsUUID(); |
694 | // int owner_mask = permissions["owner_mask"].AsInteger(); | 1050 | // int owner_mask = permissions["owner_mask"].AsInteger(); |
695 | // no longer used - end ------------------------ | 1051 | // no longer used - end ------------------------ |
1052 | |||
1053 | |||
1054 | SceneObjectPart prim | ||
1055 | = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero); | ||
1056 | |||
1057 | prim.Scale = scale; | ||
1058 | rotations.Add(rotation); | ||
1059 | positions.Add(position); | ||
1060 | prim.UUID = UUID.Random(); | ||
1061 | prim.CreatorID = creatorID; | ||
1062 | prim.OwnerID = owner_id; | ||
1063 | prim.GroupID = UUID.Zero; | ||
1064 | prim.LastOwnerID = creatorID; | ||
1065 | prim.CreationDate = Util.UnixTimeSinceEpoch(); | ||
1066 | |||
1067 | if (grp == null) | ||
1068 | prim.Name = assetName; | ||
1069 | else | ||
1070 | prim.Name = assetName + "#" + i.ToString(); | ||
696 | 1071 | ||
697 | UUID owner_id = m_HostCapsObj.AgentID; | 1072 | prim.EveryoneMask = 0; |
1073 | prim.GroupMask = 0; | ||
698 | 1074 | ||
699 | SceneObjectPart prim | 1075 | if (restrictPerms) |
700 | = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero); | 1076 | { |
1077 | prim.BaseMask = (uint)(PermissionMask.Move | PermissionMask.Modify); | ||
1078 | prim.OwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify); | ||
1079 | prim.NextOwnerMask = 0; | ||
1080 | } | ||
1081 | else | ||
1082 | { | ||
1083 | prim.BaseMask = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1084 | prim.OwnerMask = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1085 | prim.NextOwnerMask = (uint)PermissionMask.Transfer; | ||
1086 | } | ||
701 | 1087 | ||
702 | prim.Scale = scale; | 1088 | if(istest) |
703 | //prim.OffsetPosition = position; | 1089 | prim.Description = "For testing only. Other uses are prohibited"; |
704 | rotations.Add(rotation); | 1090 | else |
705 | positions.Add(position); | 1091 | prim.Description = ""; |
706 | prim.UUID = UUID.Random(); | 1092 | |
707 | prim.CreatorID = owner_id; | 1093 | prim.Material = material; |
708 | prim.OwnerID = owner_id; | 1094 | prim.PhysicsShapeType = physicsShapeType; |
709 | prim.GroupID = UUID.Zero; | ||
710 | prim.LastOwnerID = prim.OwnerID; | ||
711 | prim.CreationDate = Util.UnixTimeSinceEpoch(); | ||
712 | prim.Name = assetName; | ||
713 | prim.Description = ""; | ||
714 | 1095 | ||
715 | // prim.BaseMask = (uint)base_mask; | 1096 | // prim.BaseMask = (uint)base_mask; |
716 | // prim.EveryoneMask = (uint)everyone_mask; | 1097 | // prim.EveryoneMask = (uint)everyone_mask; |
@@ -718,52 +1099,64 @@ namespace OpenSim.Region.ClientStack.Linden | |||
718 | // prim.NextOwnerMask = (uint)next_owner_mask; | 1099 | // prim.NextOwnerMask = (uint)next_owner_mask; |
719 | // prim.OwnerMask = (uint)owner_mask; | 1100 | // prim.OwnerMask = (uint)owner_mask; |
720 | 1101 | ||
721 | if (grp == null) | 1102 | if (grp == null) |
722 | grp = new SceneObjectGroup(prim); | 1103 | { |
723 | else | 1104 | grp = new SceneObjectGroup(prim); |
724 | grp.AddPart(prim); | 1105 | grp.LastOwnerID = creatorID; |
725 | } | 1106 | } |
1107 | else | ||
1108 | grp.AddPart(prim); | ||
1109 | } | ||
726 | 1110 | ||
727 | Vector3 rootPos = positions[0]; | 1111 | Vector3 rootPos = positions[0]; |
728 | 1112 | ||
729 | if (grp.Parts.Length > 1) | 1113 | if (grp.Parts.Length > 1) |
730 | { | 1114 | { |
731 | // Fix first link number | 1115 | // Fix first link number |
732 | grp.RootPart.LinkNum++; | 1116 | grp.RootPart.LinkNum++; |
733 | 1117 | ||
734 | Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); | 1118 | Quaternion rootRotConj = Quaternion.Conjugate(rotations[0]); |
735 | Quaternion tmprot; | 1119 | Quaternion tmprot; |
736 | Vector3 offset; | 1120 | Vector3 offset; |
737 | 1121 | ||
738 | // fix children rotations and positions | 1122 | // fix children rotations and positions |
739 | for (int i = 1; i < rotations.Count; i++) | 1123 | for (int i = 1; i < rotations.Count; i++) |
740 | { | 1124 | { |
741 | tmprot = rotations[i]; | 1125 | tmprot = rotations[i]; |
742 | tmprot = rootRotConj * tmprot; | 1126 | tmprot = rootRotConj * tmprot; |
743 | 1127 | ||
744 | grp.Parts[i].RotationOffset = tmprot; | 1128 | grp.Parts[i].RotationOffset = tmprot; |
745 | 1129 | ||
746 | offset = positions[i] - rootPos; | 1130 | offset = positions[i] - rootPos; |
747 | 1131 | ||
748 | offset *= rootRotConj; | 1132 | offset *= rootRotConj; |
749 | grp.Parts[i].OffsetPosition = offset; | 1133 | grp.Parts[i].OffsetPosition = offset; |
1134 | } | ||
1135 | |||
1136 | grp.AbsolutePosition = rootPos; | ||
1137 | grp.UpdateGroupRotationR(rotations[0]); | ||
1138 | } | ||
1139 | else | ||
1140 | { | ||
1141 | grp.AbsolutePosition = rootPos; | ||
1142 | grp.UpdateGroupRotationR(rotations[0]); | ||
750 | } | 1143 | } |
751 | 1144 | ||
752 | grp.AbsolutePosition = rootPos; | 1145 | data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp)); |
753 | grp.UpdateGroupRotationR(rotations[0]); | ||
754 | } | 1146 | } |
755 | else | 1147 | |
1148 | else // not a mesh model | ||
756 | { | 1149 | { |
757 | grp.AbsolutePosition = rootPos; | 1150 | m_log.ErrorFormat("[CAPS Asset Upload] got unsuported assetType for object upload"); |
758 | grp.UpdateGroupRotationR(rotations[0]); | 1151 | return; |
759 | } | 1152 | } |
760 | |||
761 | data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp)); | ||
762 | } | 1153 | } |
763 | 1154 | ||
764 | AssetBase asset; | 1155 | AssetBase asset; |
765 | asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString()); | 1156 | asset = new AssetBase(assetID, assetName, assType, creatorIDstr); |
766 | asset.Data = data; | 1157 | asset.Data = data; |
1158 | if (istest) | ||
1159 | asset.Local = true; | ||
767 | if (AddNewAsset != null) | 1160 | if (AddNewAsset != null) |
768 | AddNewAsset(asset); | 1161 | AddNewAsset(asset); |
769 | else if (m_assetService != null) | 1162 | else if (m_assetService != null) |
@@ -771,11 +1164,17 @@ namespace OpenSim.Region.ClientStack.Linden | |||
771 | 1164 | ||
772 | InventoryItemBase item = new InventoryItemBase(); | 1165 | InventoryItemBase item = new InventoryItemBase(); |
773 | item.Owner = m_HostCapsObj.AgentID; | 1166 | item.Owner = m_HostCapsObj.AgentID; |
774 | item.CreatorId = m_HostCapsObj.AgentID.ToString(); | 1167 | item.CreatorId = creatorIDstr; |
775 | item.CreatorData = String.Empty; | 1168 | item.CreatorData = String.Empty; |
776 | item.ID = inventoryItem; | 1169 | item.ID = inventoryItem; |
777 | item.AssetID = asset.FullID; | 1170 | item.AssetID = asset.FullID; |
778 | item.Description = assetDescription; | 1171 | if (istest) |
1172 | { | ||
1173 | item.Description = "For testing only. Other uses are prohibited"; | ||
1174 | item.Flags = (uint) (InventoryItemFlags.SharedSingleReference); | ||
1175 | } | ||
1176 | else | ||
1177 | item.Description = assetDescription; | ||
779 | item.Name = assetName; | 1178 | item.Name = assetName; |
780 | item.AssetType = assType; | 1179 | item.AssetType = assType; |
781 | item.InvType = inType; | 1180 | item.InvType = inType; |
@@ -783,18 +1182,61 @@ namespace OpenSim.Region.ClientStack.Linden | |||
783 | 1182 | ||
784 | // If we set PermissionMask.All then when we rez the item the next permissions will replace the current | 1183 | // If we set PermissionMask.All then when we rez the item the next permissions will replace the current |
785 | // (owner) permissions. This becomes a problem if next permissions are changed. | 1184 | // (owner) permissions. This becomes a problem if next permissions are changed. |
786 | item.CurrentPermissions | ||
787 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export); | ||
788 | 1185 | ||
789 | item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | 1186 | if (inType == (sbyte)CustomInventoryType.AnimationSet) |
790 | item.EveryOnePermissions = 0; | 1187 | { |
791 | item.NextPermissions = (uint)PermissionMask.All; | 1188 | AnimationSet.setCreateItemPermitions(item); |
1189 | } | ||
1190 | |||
1191 | else if (restrictPerms) | ||
1192 | { | ||
1193 | item.BasePermissions = (uint)(PermissionMask.Move | PermissionMask.Modify); | ||
1194 | item.CurrentPermissions = (uint)(PermissionMask.Move | PermissionMask.Modify); | ||
1195 | item.EveryOnePermissions = 0; | ||
1196 | item.NextPermissions = 0; | ||
1197 | } | ||
1198 | else | ||
1199 | { | ||
1200 | item.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1201 | item.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; | ||
1202 | item.EveryOnePermissions = 0; | ||
1203 | item.NextPermissions = (uint)PermissionMask.Transfer; | ||
1204 | } | ||
1205 | |||
792 | item.CreationDate = Util.UnixTimeSinceEpoch(); | 1206 | item.CreationDate = Util.UnixTimeSinceEpoch(); |
793 | 1207 | ||
1208 | m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); | ||
1209 | |||
794 | if (AddNewInventoryItem != null) | 1210 | if (AddNewInventoryItem != null) |
795 | { | 1211 | { |
796 | AddNewInventoryItem(m_HostCapsObj.AgentID, item); | 1212 | if (istest) |
1213 | { | ||
1214 | m_Scene.AddInventoryItem(client, item); | ||
1215 | /* | ||
1216 | AddNewInventoryItem(m_HostCapsObj.AgentID, item, 0); | ||
1217 | if (client != null) | ||
1218 | 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); | ||
1219 | */ | ||
1220 | } | ||
1221 | else | ||
1222 | { | ||
1223 | AddNewInventoryItem(m_HostCapsObj.AgentID, item, (uint)cost); | ||
1224 | // if (client != null) | ||
1225 | // { | ||
1226 | // // let users see anything.. i don't so far | ||
1227 | // string str; | ||
1228 | // if (cost > 0) | ||
1229 | // // dont remember where is money unit name to put here | ||
1230 | // str = "Upload complete. charged " + cost.ToString() + "$"; | ||
1231 | // else | ||
1232 | // str = "Upload complete"; | ||
1233 | // client.SendAgentAlertMessage(str, true); | ||
1234 | // } | ||
1235 | } | ||
797 | } | 1236 | } |
1237 | |||
1238 | lock (m_ModelCost) | ||
1239 | m_FileAgentInventoryState = FileAgentInventoryState.idle; | ||
798 | } | 1240 | } |
799 | 1241 | ||
800 | /// <summary> | 1242 | /// <summary> |
@@ -935,24 +1377,17 @@ namespace OpenSim.Region.ClientStack.Linden | |||
935 | { | 1377 | { |
936 | string message; | 1378 | string message; |
937 | copyItem = m_Scene.GiveInventoryItem(m_HostCapsObj.AgentID, item.Owner, itemID, folderID, out message); | 1379 | copyItem = m_Scene.GiveInventoryItem(m_HostCapsObj.AgentID, item.Owner, itemID, folderID, out message); |
938 | if (client != null) | 1380 | if (copyItem != null && client != null) |
939 | { | 1381 | { |
940 | if (copyItem != null) | 1382 | m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, ItemID:{0}, FolderID:{1}", copyItem.ID, copyItem.Folder); |
941 | { | 1383 | client.SendBulkUpdateInventory(copyItem); |
942 | m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, ItemID:{0}, FolderID:{1}", copyItem.ID, copyItem.Folder); | ||
943 | client.SendBulkUpdateInventory(copyItem); | ||
944 | } | ||
945 | else | ||
946 | { | ||
947 | client.SendAgentAlertMessage(message, false); | ||
948 | } | ||
949 | } | 1384 | } |
950 | } | 1385 | } |
951 | else | 1386 | else |
952 | { | 1387 | { |
953 | m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard - Failed to retrieve item {0} from notecard {1}", itemID, notecardID); | 1388 | m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard - Failed to retrieve item {0} from notecard {1}", itemID, notecardID); |
954 | if (client != null) | 1389 | if (client != null) |
955 | client.SendAgentAlertMessage("Failed to retrieve item", false); | 1390 | client.SendAlertMessage("Failed to retrieve item"); |
956 | } | 1391 | } |
957 | } | 1392 | } |
958 | catch (Exception e) | 1393 | catch (Exception e) |
@@ -995,18 +1430,142 @@ namespace OpenSim.Region.ClientStack.Linden | |||
995 | return response; | 1430 | return response; |
996 | } | 1431 | } |
997 | 1432 | ||
998 | public string UpdateAgentInformation(string request, string path, | 1433 | public string GetObjectCost(string request, string path, |
1434 | string param, IOSHttpRequest httpRequest, | ||
1435 | IOSHttpResponse httpResponse) | ||
1436 | { | ||
1437 | OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); | ||
1438 | OSDMap resp = new OSDMap(); | ||
1439 | |||
1440 | OSDArray object_ids = (OSDArray)req["object_ids"]; | ||
1441 | |||
1442 | for (int i = 0; i < object_ids.Count; i++) | ||
1443 | { | ||
1444 | UUID uuid = object_ids[i].AsUUID(); | ||
1445 | |||
1446 | SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid); | ||
1447 | |||
1448 | if (part != null) | ||
1449 | { | ||
1450 | SceneObjectGroup grp = part.ParentGroup; | ||
1451 | if (grp != null) | ||
1452 | { | ||
1453 | float linksetCost; | ||
1454 | float linksetPhysCost; | ||
1455 | float partCost; | ||
1456 | float partPhysCost; | ||
1457 | |||
1458 | grp.GetResourcesCosts(part, out linksetCost, out linksetPhysCost, out partCost, out partPhysCost); | ||
1459 | |||
1460 | OSDMap object_data = new OSDMap(); | ||
1461 | object_data["linked_set_resource_cost"] = linksetCost; | ||
1462 | object_data["resource_cost"] = partCost; | ||
1463 | object_data["physics_cost"] = partPhysCost; | ||
1464 | object_data["linked_set_physics_cost"] = linksetPhysCost; | ||
1465 | |||
1466 | resp[uuid.ToString()] = object_data; | ||
1467 | } | ||
1468 | else | ||
1469 | { | ||
1470 | OSDMap object_data = new OSDMap(); | ||
1471 | object_data["linked_set_resource_cost"] = 0; | ||
1472 | object_data["resource_cost"] = 0; | ||
1473 | object_data["physics_cost"] = 0; | ||
1474 | object_data["linked_set_physics_cost"] = 0; | ||
1475 | |||
1476 | resp[uuid.ToString()] = object_data; | ||
1477 | } | ||
1478 | |||
1479 | } | ||
1480 | } | ||
1481 | |||
1482 | string response = OSDParser.SerializeLLSDXmlString(resp); | ||
1483 | return response; | ||
1484 | } | ||
1485 | |||
1486 | public string ResourceCostSelected(string request, string path, | ||
999 | string param, IOSHttpRequest httpRequest, | 1487 | string param, IOSHttpRequest httpRequest, |
1000 | IOSHttpResponse httpResponse) | 1488 | IOSHttpResponse httpResponse) |
1001 | { | 1489 | { |
1002 | OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); | 1490 | OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); |
1003 | OSDMap accessPrefs = (OSDMap)req["access_prefs"]; | 1491 | OSDMap resp = new OSDMap(); |
1004 | string desiredMaturity = accessPrefs["max"]; | 1492 | |
1493 | |||
1494 | float phys=0; | ||
1495 | float stream=0; | ||
1496 | float simul=0; | ||
1497 | |||
1498 | if (req.ContainsKey("selected_roots")) | ||
1499 | { | ||
1500 | OSDArray object_ids = (OSDArray)req["selected_roots"]; | ||
1501 | |||
1502 | // should go by SOG suming costs for all parts | ||
1503 | // ll v3 works ok with several objects select we get the list and adds ok | ||
1504 | // FS calls per object so results are wrong guess fs bug | ||
1505 | for (int i = 0; i < object_ids.Count; i++) | ||
1506 | { | ||
1507 | UUID uuid = object_ids[i].AsUUID(); | ||
1508 | float Physc; | ||
1509 | float simulc; | ||
1510 | float streamc; | ||
1511 | |||
1512 | SceneObjectGroup grp = m_Scene.GetGroupByPrim(uuid); | ||
1513 | if (grp != null) | ||
1514 | { | ||
1515 | grp.GetSelectedCosts(out Physc, out streamc, out simulc); | ||
1516 | phys += Physc; | ||
1517 | stream += streamc; | ||
1518 | simul += simulc; | ||
1519 | } | ||
1520 | } | ||
1521 | } | ||
1522 | else if (req.ContainsKey("selected_prims")) | ||
1523 | { | ||
1524 | OSDArray object_ids = (OSDArray)req["selected_prims"]; | ||
1525 | |||
1526 | // don't see in use in any of the 2 viewers | ||
1527 | // guess it should be for edit linked but... nothing | ||
1528 | // should go to SOP per part | ||
1529 | for (int i = 0; i < object_ids.Count; i++) | ||
1530 | { | ||
1531 | UUID uuid = object_ids[i].AsUUID(); | ||
1532 | |||
1533 | SceneObjectPart part = m_Scene.GetSceneObjectPart(uuid); | ||
1534 | if (part != null) | ||
1535 | { | ||
1536 | phys += part.PhysicsCost; | ||
1537 | stream += part.StreamingCost; | ||
1538 | simul += part.SimulationCost; | ||
1539 | } | ||
1540 | } | ||
1541 | } | ||
1542 | |||
1543 | // if (simul != 0) | ||
1544 | { | ||
1545 | OSDMap object_data = new OSDMap(); | ||
1546 | |||
1547 | object_data["physics"] = phys; | ||
1548 | object_data["streaming"] = stream; | ||
1549 | object_data["simulation"] = simul; | ||
1550 | |||
1551 | resp["selected"] = object_data; | ||
1552 | } | ||
1553 | |||
1554 | string response = OSDParser.SerializeLLSDXmlString(resp); | ||
1555 | return response; | ||
1556 | } | ||
1005 | 1557 | ||
1558 | public string UpdateAgentInformation(string request, string path, | ||
1559 | string param, IOSHttpRequest httpRequest, | ||
1560 | IOSHttpResponse httpResponse) | ||
1561 | { | ||
1562 | // OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); | ||
1006 | OSDMap resp = new OSDMap(); | 1563 | OSDMap resp = new OSDMap(); |
1007 | OSDMap respAccessPrefs = new OSDMap(); | 1564 | |
1008 | respAccessPrefs["max"] = desiredMaturity; // echoing the maturity back means success | 1565 | OSDMap accessPrefs = new OSDMap(); |
1009 | resp["access_prefs"] = respAccessPrefs; | 1566 | accessPrefs["max"] = "A"; |
1567 | |||
1568 | resp["access_prefs"] = accessPrefs; | ||
1010 | 1569 | ||
1011 | string response = OSDParser.SerializeLLSDXmlString(resp); | 1570 | string response = OSDParser.SerializeLLSDXmlString(resp); |
1012 | return response; | 1571 | return response; |
@@ -1015,6 +1574,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
1015 | 1574 | ||
1016 | public class AssetUploader | 1575 | public class AssetUploader |
1017 | { | 1576 | { |
1577 | private static readonly ILog m_log = | ||
1578 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
1579 | |||
1580 | |||
1018 | public event UpLoadedAsset OnUpLoad; | 1581 | public event UpLoadedAsset OnUpLoad; |
1019 | private UpLoadedAsset handlerUpLoad = null; | 1582 | private UpLoadedAsset handlerUpLoad = null; |
1020 | 1583 | ||
@@ -1029,10 +1592,21 @@ namespace OpenSim.Region.ClientStack.Linden | |||
1029 | 1592 | ||
1030 | private string m_invType = String.Empty; | 1593 | private string m_invType = String.Empty; |
1031 | private string m_assetType = String.Empty; | 1594 | private string m_assetType = String.Empty; |
1032 | 1595 | private int m_cost; | |
1596 | private string m_error = String.Empty; | ||
1597 | |||
1598 | private Timer m_timeoutTimer = new Timer(); | ||
1599 | private UUID m_texturesFolder; | ||
1600 | private int m_nreqtextures; | ||
1601 | private int m_nreqmeshs; | ||
1602 | private int m_nreqinstances; | ||
1603 | private bool m_IsAtestUpload; | ||
1604 | |||
1033 | public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, | 1605 | public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, |
1034 | UUID parentFolderID, string invType, string assetType, string path, | 1606 | UUID parentFolderID, string invType, string assetType, string path, |
1035 | IHttpServer httpServer, bool dumpAssetsToFile) | 1607 | IHttpServer httpServer, bool dumpAssetsToFile, |
1608 | int totalCost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, | ||
1609 | bool IsAtestUpload) | ||
1036 | { | 1610 | { |
1037 | m_assetName = assetName; | 1611 | m_assetName = assetName; |
1038 | m_assetDes = description; | 1612 | m_assetDes = description; |
@@ -1044,6 +1618,18 @@ namespace OpenSim.Region.ClientStack.Linden | |||
1044 | m_assetType = assetType; | 1618 | m_assetType = assetType; |
1045 | m_invType = invType; | 1619 | m_invType = invType; |
1046 | m_dumpAssetsToFile = dumpAssetsToFile; | 1620 | m_dumpAssetsToFile = dumpAssetsToFile; |
1621 | m_cost = totalCost; | ||
1622 | |||
1623 | m_texturesFolder = texturesFolder; | ||
1624 | m_nreqtextures = nreqtextures; | ||
1625 | m_nreqmeshs = nreqmeshs; | ||
1626 | m_nreqinstances = nreqinstances; | ||
1627 | m_IsAtestUpload = IsAtestUpload; | ||
1628 | |||
1629 | m_timeoutTimer.Elapsed += TimedOut; | ||
1630 | m_timeoutTimer.Interval = 120000; | ||
1631 | m_timeoutTimer.AutoReset = false; | ||
1632 | m_timeoutTimer.Start(); | ||
1047 | } | 1633 | } |
1048 | 1634 | ||
1049 | /// <summary> | 1635 | /// <summary> |
@@ -1058,12 +1644,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
1058 | UUID inv = inventoryItemID; | 1644 | UUID inv = inventoryItemID; |
1059 | string res = String.Empty; | 1645 | string res = String.Empty; |
1060 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | 1646 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); |
1647 | /* | ||
1061 | uploadComplete.new_asset = newAssetID.ToString(); | 1648 | uploadComplete.new_asset = newAssetID.ToString(); |
1062 | uploadComplete.new_inventory_item = inv; | 1649 | uploadComplete.new_inventory_item = inv; |
1063 | uploadComplete.state = "complete"; | 1650 | uploadComplete.state = "complete"; |
1064 | 1651 | ||
1065 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | 1652 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); |
1066 | 1653 | */ | |
1654 | m_timeoutTimer.Stop(); | ||
1067 | httpListener.RemoveStreamHandler("POST", uploaderPath); | 1655 | httpListener.RemoveStreamHandler("POST", uploaderPath); |
1068 | 1656 | ||
1069 | // TODO: probably make this a better set of extensions here | 1657 | // TODO: probably make this a better set of extensions here |
@@ -1080,12 +1668,50 @@ namespace OpenSim.Region.ClientStack.Linden | |||
1080 | handlerUpLoad = OnUpLoad; | 1668 | handlerUpLoad = OnUpLoad; |
1081 | if (handlerUpLoad != null) | 1669 | if (handlerUpLoad != null) |
1082 | { | 1670 | { |
1083 | handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType); | 1671 | handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType, |
1672 | m_cost, m_texturesFolder, m_nreqtextures, m_nreqmeshs, m_nreqinstances, m_IsAtestUpload, | ||
1673 | ref m_error); | ||
1674 | } | ||
1675 | if (m_IsAtestUpload) | ||
1676 | { | ||
1677 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
1678 | resperror.message = "Upload SUCESSEFULL for testing purposes only. Other uses are prohibited. Item will not work after 48 hours or on other regions"; | ||
1679 | resperror.identifier = inv; | ||
1680 | |||
1681 | uploadComplete.error = resperror; | ||
1682 | uploadComplete.state = "Upload4Testing"; | ||
1683 | } | ||
1684 | else | ||
1685 | { | ||
1686 | if (m_error == String.Empty) | ||
1687 | { | ||
1688 | uploadComplete.new_asset = newAssetID.ToString(); | ||
1689 | uploadComplete.new_inventory_item = inv; | ||
1690 | // if (m_texturesFolder != UUID.Zero) | ||
1691 | // uploadComplete.new_texture_folder_id = m_texturesFolder; | ||
1692 | uploadComplete.state = "complete"; | ||
1693 | } | ||
1694 | else | ||
1695 | { | ||
1696 | LLSDAssetUploadError resperror = new LLSDAssetUploadError(); | ||
1697 | resperror.message = m_error; | ||
1698 | resperror.identifier = inv; | ||
1699 | |||
1700 | uploadComplete.error = resperror; | ||
1701 | uploadComplete.state = "failed"; | ||
1702 | } | ||
1084 | } | 1703 | } |
1085 | 1704 | ||
1705 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
1086 | return res; | 1706 | return res; |
1087 | } | 1707 | } |
1088 | 1708 | ||
1709 | private void TimedOut(object sender, ElapsedEventArgs args) | ||
1710 | { | ||
1711 | m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out mesh upload"); | ||
1712 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
1713 | } | ||
1714 | |||
1089 | ///Left this in and commented in case there are unforseen issues | 1715 | ///Left this in and commented in case there are unforseen issues |
1090 | //private void SaveAssetToFile(string filename, byte[] data) | 1716 | //private void SaveAssetToFile(string filename, byte[] data) |
1091 | //{ | 1717 | //{ |
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..f6a950f --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs | |||
@@ -0,0 +1,727 @@ | |||
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 | |||
29 | using System; | ||
30 | using System.IO; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.StructuredData; | ||
37 | |||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Region.Framework; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Framework.Capabilities; | ||
42 | |||
43 | using ComponentAce.Compression.Libs.zlib; | ||
44 | |||
45 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
46 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
47 | |||
48 | namespace OpenSim.Region.ClientStack.Linden | ||
49 | { | ||
50 | public struct ModelPrimLimits | ||
51 | { | ||
52 | |||
53 | } | ||
54 | |||
55 | public class ModelCost | ||
56 | { | ||
57 | |||
58 | // upload fee defaults | ||
59 | // fees are normalized to 1.0 | ||
60 | // this parameters scale them to basic cost ( so 1.0 translates to 10 ) | ||
61 | |||
62 | public float ModelMeshCostFactor = 0.0f; // scale total cost relative to basic (excluding textures) | ||
63 | public float ModelTextureCostFactor = 1.0f; // scale textures fee to basic. | ||
64 | public float ModelMinCostFactor = 0.0f; // 0.5f; // minimum total model free excluding textures | ||
65 | |||
66 | // itens costs in normalized values | ||
67 | // ie will be multiplied by basicCost and factors above | ||
68 | public float primCreationCost = 0.002f; // extra cost for each prim creation overhead | ||
69 | // weigthed size to normalized cost | ||
70 | public float bytecost = 1e-5f; | ||
71 | |||
72 | // mesh upload fees based on compressed data sizes | ||
73 | // several data sections are counted more that once | ||
74 | // to promote user optimization | ||
75 | // following parameters control how many extra times they are added | ||
76 | // to global size. | ||
77 | // LOD meshs | ||
78 | const float medSizeWth = 1f; // 2x | ||
79 | const float lowSizeWth = 1.5f; // 2.5x | ||
80 | const float lowestSizeWth = 2f; // 3x | ||
81 | // favor potencially physical optimized meshs versus automatic decomposition | ||
82 | const float physMeshSizeWth = 6f; // counts 7x | ||
83 | const float physHullSizeWth = 8f; // counts 9x | ||
84 | |||
85 | // stream cost area factors | ||
86 | // more or less like SL | ||
87 | const float highLodFactor = 17.36f; | ||
88 | const float midLodFactor = 277.78f; | ||
89 | const float lowLodFactor = 1111.11f; | ||
90 | |||
91 | // physics cost is below, identical to SL, assuming shape type convex | ||
92 | // server cost is below identical to SL assuming non scripted non physical object | ||
93 | |||
94 | // internal | ||
95 | const int bytesPerCoord = 6; // 3 coords, 2 bytes per each | ||
96 | |||
97 | // control prims dimensions | ||
98 | public float PrimScaleMin = 0.001f; | ||
99 | public float NonPhysicalPrimScaleMax = 256f; | ||
100 | public float PhysicalPrimScaleMax = 10f; | ||
101 | public int ObjectLinkedPartsMax = 512; | ||
102 | |||
103 | // storage for a single mesh asset cost parameters | ||
104 | private class ameshCostParam | ||
105 | { | ||
106 | // LOD sizes for size dependent streaming cost | ||
107 | public int highLODSize; | ||
108 | public int medLODSize; | ||
109 | public int lowLODSize; | ||
110 | public int lowestLODSize; | ||
111 | // normalized fee based on compressed data sizes | ||
112 | public float costFee; | ||
113 | // physics cost | ||
114 | public float physicsCost; | ||
115 | } | ||
116 | |||
117 | // calculates a mesh model costs | ||
118 | // returns false on error, with a reason on parameter error | ||
119 | // resources input LLSD request | ||
120 | // basicCost input region assets upload cost | ||
121 | // totalcost returns model total upload fee | ||
122 | // meshcostdata returns detailed costs for viewer | ||
123 | // avatarSkeleton if mesh includes a avatar skeleton | ||
124 | // useAvatarCollider if we should use physics mesh for avatar | ||
125 | public bool MeshModelCost(LLSDAssetResource resources, int basicCost, out int totalcost, | ||
126 | LLSDAssetUploadResponseData meshcostdata, out string error, ref string warning) | ||
127 | { | ||
128 | totalcost = 0; | ||
129 | error = string.Empty; | ||
130 | |||
131 | bool avatarSkeleton = false; | ||
132 | |||
133 | if (resources == null || | ||
134 | resources.instance_list == null || | ||
135 | resources.instance_list.Array.Count == 0) | ||
136 | { | ||
137 | error = "missing model information."; | ||
138 | return false; | ||
139 | } | ||
140 | |||
141 | int numberInstances = resources.instance_list.Array.Count; | ||
142 | |||
143 | if( numberInstances > ObjectLinkedPartsMax ) | ||
144 | { | ||
145 | error = "Model whould have more than " + ObjectLinkedPartsMax.ToString() + " linked prims"; | ||
146 | return false; | ||
147 | } | ||
148 | |||
149 | meshcostdata.model_streaming_cost = 0.0; | ||
150 | meshcostdata.simulation_cost = 0.0; | ||
151 | meshcostdata.physics_cost = 0.0; | ||
152 | meshcostdata.resource_cost = 0.0; | ||
153 | |||
154 | meshcostdata.upload_price_breakdown.mesh_instance = 0; | ||
155 | meshcostdata.upload_price_breakdown.mesh_physics = 0; | ||
156 | meshcostdata.upload_price_breakdown.mesh_streaming = 0; | ||
157 | meshcostdata.upload_price_breakdown.model = 0; | ||
158 | |||
159 | int itmp; | ||
160 | |||
161 | // textures cost | ||
162 | if (resources.texture_list != null && resources.texture_list.Array.Count > 0) | ||
163 | { | ||
164 | float textures_cost = (float)(resources.texture_list.Array.Count * basicCost); | ||
165 | textures_cost *= ModelTextureCostFactor; | ||
166 | |||
167 | itmp = (int)(textures_cost + 0.5f); // round | ||
168 | meshcostdata.upload_price_breakdown.texture = itmp; | ||
169 | totalcost += itmp; | ||
170 | } | ||
171 | |||
172 | // meshs assets cost | ||
173 | float meshsfee = 0; | ||
174 | int numberMeshs = 0; | ||
175 | bool haveMeshs = false; | ||
176 | |||
177 | bool curskeleton; | ||
178 | bool curAvatarPhys; | ||
179 | |||
180 | List<ameshCostParam> meshsCosts = new List<ameshCostParam>(); | ||
181 | |||
182 | if (resources.mesh_list != null && resources.mesh_list.Array.Count > 0) | ||
183 | { | ||
184 | numberMeshs = resources.mesh_list.Array.Count; | ||
185 | |||
186 | for (int i = 0; i < numberMeshs; i++) | ||
187 | { | ||
188 | ameshCostParam curCost = new ameshCostParam(); | ||
189 | byte[] data = (byte[])resources.mesh_list.Array[i]; | ||
190 | |||
191 | if (!MeshCost(data, curCost,out curskeleton, out curAvatarPhys, out error)) | ||
192 | { | ||
193 | return false; | ||
194 | } | ||
195 | |||
196 | if (curskeleton) | ||
197 | { | ||
198 | if (avatarSkeleton) | ||
199 | { | ||
200 | error = "model can only contain a avatar skeleton"; | ||
201 | return false; | ||
202 | } | ||
203 | avatarSkeleton = true; | ||
204 | } | ||
205 | meshsCosts.Add(curCost); | ||
206 | meshsfee += curCost.costFee; | ||
207 | } | ||
208 | haveMeshs = true; | ||
209 | } | ||
210 | |||
211 | // instances (prims) cost | ||
212 | |||
213 | |||
214 | int mesh; | ||
215 | int skipedSmall = 0; | ||
216 | for (int i = 0; i < numberInstances; i++) | ||
217 | { | ||
218 | Hashtable inst = (Hashtable)resources.instance_list.Array[i]; | ||
219 | |||
220 | ArrayList ascale = (ArrayList)inst["scale"]; | ||
221 | Vector3 scale; | ||
222 | double tmp; | ||
223 | tmp = (double)ascale[0]; | ||
224 | scale.X = (float)tmp; | ||
225 | tmp = (double)ascale[1]; | ||
226 | scale.Y = (float)tmp; | ||
227 | tmp = (double)ascale[2]; | ||
228 | scale.Z = (float)tmp; | ||
229 | |||
230 | if (scale.X < PrimScaleMin || scale.Y < PrimScaleMin || scale.Z < PrimScaleMin) | ||
231 | { | ||
232 | skipedSmall++; | ||
233 | continue; | ||
234 | } | ||
235 | |||
236 | if (scale.X > NonPhysicalPrimScaleMax || scale.Y > NonPhysicalPrimScaleMax || scale.Z > NonPhysicalPrimScaleMax) | ||
237 | { | ||
238 | error = "Model contains parts with sides larger than " + NonPhysicalPrimScaleMax.ToString() + "m. Please ajust scale"; | ||
239 | return false; | ||
240 | } | ||
241 | |||
242 | if (haveMeshs && inst.ContainsKey("mesh")) | ||
243 | { | ||
244 | mesh = (int)inst["mesh"]; | ||
245 | |||
246 | if (mesh >= numberMeshs) | ||
247 | { | ||
248 | error = "Incoerent model information."; | ||
249 | return false; | ||
250 | } | ||
251 | |||
252 | // streamming cost | ||
253 | |||
254 | float sqdiam = scale.LengthSquared(); | ||
255 | |||
256 | ameshCostParam curCost = meshsCosts[mesh]; | ||
257 | float mesh_streaming = streamingCost(curCost, sqdiam); | ||
258 | |||
259 | meshcostdata.model_streaming_cost += mesh_streaming; | ||
260 | meshcostdata.physics_cost += curCost.physicsCost; | ||
261 | } | ||
262 | else // instance as no mesh ?? | ||
263 | { | ||
264 | // to do later if needed | ||
265 | meshcostdata.model_streaming_cost += 0.5f; | ||
266 | meshcostdata.physics_cost += 1.0f; | ||
267 | } | ||
268 | |||
269 | // assume unscripted and static prim server cost | ||
270 | meshcostdata.simulation_cost += 0.5f; | ||
271 | // charge for prims creation | ||
272 | meshsfee += primCreationCost; | ||
273 | } | ||
274 | |||
275 | if (skipedSmall > 0) | ||
276 | { | ||
277 | if (skipedSmall > numberInstances / 2) | ||
278 | { | ||
279 | error = "Model contains too many prims smaller than " + PrimScaleMin.ToString() + | ||
280 | "m minimum allowed size. Please check scalling"; | ||
281 | return false; | ||
282 | } | ||
283 | else | ||
284 | warning += skipedSmall.ToString() + " of the requested " +numberInstances.ToString() + | ||
285 | " model prims will not upload because they are smaller than " + PrimScaleMin.ToString() + | ||
286 | "m minimum allowed size. Please check scalling "; | ||
287 | } | ||
288 | |||
289 | if (meshcostdata.physics_cost <= meshcostdata.model_streaming_cost) | ||
290 | meshcostdata.resource_cost = meshcostdata.model_streaming_cost; | ||
291 | else | ||
292 | meshcostdata.resource_cost = meshcostdata.physics_cost; | ||
293 | |||
294 | if (meshcostdata.resource_cost < meshcostdata.simulation_cost) | ||
295 | meshcostdata.resource_cost = meshcostdata.simulation_cost; | ||
296 | |||
297 | // scale cost | ||
298 | // at this point a cost of 1.0 whould mean basic cost | ||
299 | meshsfee *= ModelMeshCostFactor; | ||
300 | |||
301 | if (meshsfee < ModelMinCostFactor) | ||
302 | meshsfee = ModelMinCostFactor; | ||
303 | |||
304 | // actually scale it to basic cost | ||
305 | meshsfee *= (float)basicCost; | ||
306 | |||
307 | meshsfee += 0.5f; // rounding | ||
308 | |||
309 | totalcost += (int)meshsfee; | ||
310 | |||
311 | // breakdown prices | ||
312 | // don't seem to be in use so removed code for now | ||
313 | |||
314 | return true; | ||
315 | } | ||
316 | |||
317 | // single mesh asset cost | ||
318 | private bool MeshCost(byte[] data, ameshCostParam cost,out bool skeleton, out bool avatarPhys, out string error) | ||
319 | { | ||
320 | cost.highLODSize = 0; | ||
321 | cost.medLODSize = 0; | ||
322 | cost.lowLODSize = 0; | ||
323 | cost.lowestLODSize = 0; | ||
324 | cost.physicsCost = 0.0f; | ||
325 | cost.costFee = 0.0f; | ||
326 | |||
327 | error = string.Empty; | ||
328 | |||
329 | skeleton = false; | ||
330 | avatarPhys = false; | ||
331 | |||
332 | if (data == null || data.Length == 0) | ||
333 | { | ||
334 | error = "Missing model information."; | ||
335 | return false; | ||
336 | } | ||
337 | |||
338 | OSD meshOsd = null; | ||
339 | int start = 0; | ||
340 | |||
341 | error = "Invalid model data"; | ||
342 | |||
343 | using (MemoryStream ms = new MemoryStream(data)) | ||
344 | { | ||
345 | try | ||
346 | { | ||
347 | OSD osd = OSDParser.DeserializeLLSDBinary(ms); | ||
348 | if (osd is OSDMap) | ||
349 | meshOsd = (OSDMap)osd; | ||
350 | else | ||
351 | return false; | ||
352 | } | ||
353 | catch (Exception e) | ||
354 | { | ||
355 | return false; | ||
356 | } | ||
357 | start = (int)ms.Position; | ||
358 | } | ||
359 | |||
360 | OSDMap map = (OSDMap)meshOsd; | ||
361 | OSDMap tmpmap; | ||
362 | |||
363 | int highlod_size = 0; | ||
364 | int medlod_size = 0; | ||
365 | int lowlod_size = 0; | ||
366 | int lowestlod_size = 0; | ||
367 | int skin_size = 0; | ||
368 | |||
369 | int hulls_size = 0; | ||
370 | int phys_nhulls; | ||
371 | int phys_hullsvertices = 0; | ||
372 | |||
373 | int physmesh_size = 0; | ||
374 | int phys_ntriangles = 0; | ||
375 | |||
376 | int submesh_offset = -1; | ||
377 | |||
378 | if (map.ContainsKey("skeleton")) | ||
379 | { | ||
380 | tmpmap = (OSDMap)map["skeleton"]; | ||
381 | if (tmpmap.ContainsKey("offset") && tmpmap.ContainsKey("size")) | ||
382 | { | ||
383 | int sksize = tmpmap["size"].AsInteger(); | ||
384 | if(sksize > 0) | ||
385 | skeleton = true; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | if (map.ContainsKey("physics_convex")) | ||
390 | { | ||
391 | tmpmap = (OSDMap)map["physics_convex"]; | ||
392 | if (tmpmap.ContainsKey("offset")) | ||
393 | submesh_offset = tmpmap["offset"].AsInteger() + start; | ||
394 | if (tmpmap.ContainsKey("size")) | ||
395 | hulls_size = tmpmap["size"].AsInteger(); | ||
396 | } | ||
397 | |||
398 | if (submesh_offset < 0 || hulls_size == 0) | ||
399 | { | ||
400 | error = "Missing physics_convex block"; | ||
401 | return false; | ||
402 | } | ||
403 | |||
404 | if (!hulls(data, submesh_offset, hulls_size, out phys_hullsvertices, out phys_nhulls)) | ||
405 | { | ||
406 | error = "Bad physics_convex block"; | ||
407 | return false; | ||
408 | } | ||
409 | |||
410 | submesh_offset = -1; | ||
411 | |||
412 | // only look for LOD meshs sizes | ||
413 | |||
414 | if (map.ContainsKey("high_lod")) | ||
415 | { | ||
416 | tmpmap = (OSDMap)map["high_lod"]; | ||
417 | // see at least if there is a offset for this one | ||
418 | if (tmpmap.ContainsKey("offset")) | ||
419 | submesh_offset = tmpmap["offset"].AsInteger() + start; | ||
420 | if (tmpmap.ContainsKey("size")) | ||
421 | highlod_size = tmpmap["size"].AsInteger(); | ||
422 | } | ||
423 | |||
424 | if (submesh_offset < 0 || highlod_size <= 0) | ||
425 | { | ||
426 | error = "Missing high_lod block"; | ||
427 | return false; | ||
428 | } | ||
429 | |||
430 | bool haveprev = true; | ||
431 | |||
432 | if (map.ContainsKey("medium_lod")) | ||
433 | { | ||
434 | tmpmap = (OSDMap)map["medium_lod"]; | ||
435 | if (tmpmap.ContainsKey("size")) | ||
436 | medlod_size = tmpmap["size"].AsInteger(); | ||
437 | else | ||
438 | haveprev = false; | ||
439 | } | ||
440 | |||
441 | if (haveprev && map.ContainsKey("low_lod")) | ||
442 | { | ||
443 | tmpmap = (OSDMap)map["low_lod"]; | ||
444 | if (tmpmap.ContainsKey("size")) | ||
445 | lowlod_size = tmpmap["size"].AsInteger(); | ||
446 | else | ||
447 | haveprev = false; | ||
448 | } | ||
449 | |||
450 | if (haveprev && map.ContainsKey("lowest_lod")) | ||
451 | { | ||
452 | tmpmap = (OSDMap)map["lowest_lod"]; | ||
453 | if (tmpmap.ContainsKey("size")) | ||
454 | lowestlod_size = tmpmap["size"].AsInteger(); | ||
455 | } | ||
456 | |||
457 | if (map.ContainsKey("skin")) | ||
458 | { | ||
459 | tmpmap = (OSDMap)map["skin"]; | ||
460 | if (tmpmap.ContainsKey("size")) | ||
461 | skin_size = tmpmap["size"].AsInteger(); | ||
462 | } | ||
463 | |||
464 | cost.highLODSize = highlod_size; | ||
465 | cost.medLODSize = medlod_size; | ||
466 | cost.lowLODSize = lowlod_size; | ||
467 | cost.lowestLODSize = lowestlod_size; | ||
468 | |||
469 | submesh_offset = -1; | ||
470 | |||
471 | tmpmap = null; | ||
472 | if(map.ContainsKey("physics_mesh")) | ||
473 | tmpmap = (OSDMap)map["physics_mesh"]; | ||
474 | else if (map.ContainsKey("physics_shape")) // old naming | ||
475 | tmpmap = (OSDMap)map["physics_shape"]; | ||
476 | |||
477 | if(tmpmap != null) | ||
478 | { | ||
479 | if (tmpmap.ContainsKey("offset")) | ||
480 | submesh_offset = tmpmap["offset"].AsInteger() + start; | ||
481 | if (tmpmap.ContainsKey("size")) | ||
482 | physmesh_size = tmpmap["size"].AsInteger(); | ||
483 | |||
484 | if (submesh_offset >= 0 || physmesh_size > 0) | ||
485 | { | ||
486 | |||
487 | if (!submesh(data, submesh_offset, physmesh_size, out phys_ntriangles)) | ||
488 | { | ||
489 | error = "Model data parsing error"; | ||
490 | return false; | ||
491 | } | ||
492 | } | ||
493 | } | ||
494 | |||
495 | // upload is done in convex shape type so only one hull | ||
496 | phys_hullsvertices++; | ||
497 | cost.physicsCost = 0.04f * phys_hullsvertices; | ||
498 | |||
499 | float sfee; | ||
500 | |||
501 | sfee = data.Length; // start with total compressed data size | ||
502 | |||
503 | // penalize lod meshs that should be more builder optimized | ||
504 | sfee += medSizeWth * medlod_size; | ||
505 | sfee += lowSizeWth * lowlod_size; | ||
506 | sfee += lowestSizeWth * lowlod_size; | ||
507 | |||
508 | // physics | ||
509 | // favor potencial optimized meshs versus automatic decomposition | ||
510 | if (physmesh_size != 0) | ||
511 | sfee += physMeshSizeWth * (physmesh_size + hulls_size / 4); // reduce cost of mandatory convex hull | ||
512 | else | ||
513 | sfee += physHullSizeWth * hulls_size; | ||
514 | |||
515 | // bytes to money | ||
516 | sfee *= bytecost; | ||
517 | |||
518 | cost.costFee = sfee; | ||
519 | return true; | ||
520 | } | ||
521 | |||
522 | // parses a LOD or physics mesh component | ||
523 | private bool submesh(byte[] data, int offset, int size, out int ntriangles) | ||
524 | { | ||
525 | ntriangles = 0; | ||
526 | |||
527 | OSD decodedMeshOsd = new OSD(); | ||
528 | byte[] meshBytes = new byte[size]; | ||
529 | System.Buffer.BlockCopy(data, offset, meshBytes, 0, size); | ||
530 | try | ||
531 | { | ||
532 | using (MemoryStream inMs = new MemoryStream(meshBytes)) | ||
533 | { | ||
534 | using (MemoryStream outMs = new MemoryStream()) | ||
535 | { | ||
536 | using (ZOutputStream zOut = new ZOutputStream(outMs)) | ||
537 | { | ||
538 | byte[] readBuffer = new byte[4096]; | ||
539 | int readLen = 0; | ||
540 | while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0) | ||
541 | { | ||
542 | zOut.Write(readBuffer, 0, readLen); | ||
543 | } | ||
544 | zOut.Flush(); | ||
545 | outMs.Seek(0, SeekOrigin.Begin); | ||
546 | |||
547 | byte[] decompressedBuf = outMs.GetBuffer(); | ||
548 | decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf); | ||
549 | } | ||
550 | } | ||
551 | } | ||
552 | } | ||
553 | catch (Exception e) | ||
554 | { | ||
555 | return false; | ||
556 | } | ||
557 | |||
558 | OSDArray decodedMeshOsdArray = null; | ||
559 | if ((!decodedMeshOsd is OSDArray)) | ||
560 | return false; | ||
561 | |||
562 | byte[] dummy; | ||
563 | |||
564 | decodedMeshOsdArray = (OSDArray)decodedMeshOsd; | ||
565 | foreach (OSD subMeshOsd in decodedMeshOsdArray) | ||
566 | { | ||
567 | if (subMeshOsd is OSDMap) | ||
568 | { | ||
569 | OSDMap subtmpmap = (OSDMap)subMeshOsd; | ||
570 | if (subtmpmap.ContainsKey("NoGeometry") && ((OSDBoolean)subtmpmap["NoGeometry"])) | ||
571 | continue; | ||
572 | |||
573 | if (!subtmpmap.ContainsKey("Position")) | ||
574 | return false; | ||
575 | |||
576 | if (subtmpmap.ContainsKey("TriangleList")) | ||
577 | { | ||
578 | dummy = subtmpmap["TriangleList"].AsBinary(); | ||
579 | ntriangles += dummy.Length / bytesPerCoord; | ||
580 | } | ||
581 | else | ||
582 | return false; | ||
583 | } | ||
584 | } | ||
585 | |||
586 | return true; | ||
587 | } | ||
588 | |||
589 | // parses convex hulls component | ||
590 | private bool hulls(byte[] data, int offset, int size, out int nvertices, out int nhulls) | ||
591 | { | ||
592 | nvertices = 0; | ||
593 | nhulls = 1; | ||
594 | |||
595 | OSD decodedMeshOsd = new OSD(); | ||
596 | byte[] meshBytes = new byte[size]; | ||
597 | System.Buffer.BlockCopy(data, offset, meshBytes, 0, size); | ||
598 | try | ||
599 | { | ||
600 | using (MemoryStream inMs = new MemoryStream(meshBytes)) | ||
601 | { | ||
602 | using (MemoryStream outMs = new MemoryStream()) | ||
603 | { | ||
604 | using (ZOutputStream zOut = new ZOutputStream(outMs)) | ||
605 | { | ||
606 | byte[] readBuffer = new byte[4096]; | ||
607 | int readLen = 0; | ||
608 | while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0) | ||
609 | { | ||
610 | zOut.Write(readBuffer, 0, readLen); | ||
611 | } | ||
612 | zOut.Flush(); | ||
613 | outMs.Seek(0, SeekOrigin.Begin); | ||
614 | |||
615 | byte[] decompressedBuf = outMs.GetBuffer(); | ||
616 | decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf); | ||
617 | } | ||
618 | } | ||
619 | } | ||
620 | } | ||
621 | catch (Exception e) | ||
622 | { | ||
623 | return false; | ||
624 | } | ||
625 | |||
626 | OSDMap cmap = (OSDMap)decodedMeshOsd; | ||
627 | if (cmap == null) | ||
628 | return false; | ||
629 | |||
630 | byte[] dummy; | ||
631 | |||
632 | // must have one of this | ||
633 | if (cmap.ContainsKey("BoundingVerts")) | ||
634 | { | ||
635 | dummy = cmap["BoundingVerts"].AsBinary(); | ||
636 | nvertices = dummy.Length / bytesPerCoord; | ||
637 | } | ||
638 | else | ||
639 | return false; | ||
640 | |||
641 | /* upload is done with convex shape type | ||
642 | if (cmap.ContainsKey("HullList")) | ||
643 | { | ||
644 | dummy = cmap["HullList"].AsBinary(); | ||
645 | nhulls += dummy.Length; | ||
646 | } | ||
647 | |||
648 | |||
649 | if (cmap.ContainsKey("Positions")) | ||
650 | { | ||
651 | dummy = cmap["Positions"].AsBinary(); | ||
652 | nvertices = dummy.Length / bytesPerCoord; | ||
653 | } | ||
654 | */ | ||
655 | |||
656 | return true; | ||
657 | } | ||
658 | |||
659 | // returns streaming cost from on mesh LODs sizes in curCost and square of prim size length | ||
660 | private float streamingCost(ameshCostParam curCost, float sqdiam) | ||
661 | { | ||
662 | // compute efective areas | ||
663 | float ma = 262144f; | ||
664 | |||
665 | float mh = sqdiam * highLodFactor; | ||
666 | if (mh > ma) | ||
667 | mh = ma; | ||
668 | float mm = sqdiam * midLodFactor; | ||
669 | if (mm > ma) | ||
670 | mm = ma; | ||
671 | |||
672 | float ml = sqdiam * lowLodFactor; | ||
673 | if (ml > ma) | ||
674 | ml = ma; | ||
675 | |||
676 | float mlst = ma; | ||
677 | |||
678 | mlst -= ml; | ||
679 | ml -= mm; | ||
680 | mm -= mh; | ||
681 | |||
682 | if (mlst < 1.0f) | ||
683 | mlst = 1.0f; | ||
684 | if (ml < 1.0f) | ||
685 | ml = 1.0f; | ||
686 | if (mm < 1.0f) | ||
687 | mm = 1.0f; | ||
688 | if (mh < 1.0f) | ||
689 | mh = 1.0f; | ||
690 | |||
691 | ma = mlst + ml + mm + mh; | ||
692 | |||
693 | // get LODs compressed sizes | ||
694 | // giving 384 bytes bonus | ||
695 | int lst = curCost.lowestLODSize - 384; | ||
696 | int l = curCost.lowLODSize - 384; | ||
697 | int m = curCost.medLODSize - 384; | ||
698 | int h = curCost.highLODSize - 384; | ||
699 | |||
700 | // use previus higher LOD size on missing ones | ||
701 | if (m <= 0) | ||
702 | m = h; | ||
703 | if (l <= 0) | ||
704 | l = m; | ||
705 | if (lst <= 0) | ||
706 | lst = l; | ||
707 | |||
708 | // force minumum sizes | ||
709 | if (lst < 16) | ||
710 | lst = 16; | ||
711 | if (l < 16) | ||
712 | l = 16; | ||
713 | if (m < 16) | ||
714 | m = 16; | ||
715 | if (h < 16) | ||
716 | h = 16; | ||
717 | |||
718 | // compute cost weighted by relative effective areas | ||
719 | float cost = (float)lst * mlst + (float)l * ml + (float)m * mm + (float)h * mh; | ||
720 | cost /= ma; | ||
721 | |||
722 | cost *= 0.004f; // overall tunning parameter | ||
723 | |||
724 | return cost; | ||
725 | } | ||
726 | } | ||
727 | } | ||
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index 9b9f6a7..feb3322 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs | |||
@@ -78,7 +78,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
78 | private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>(); | 78 | private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>(); |
79 | 79 | ||
80 | private Dictionary<UUID, Queue<OSD>> queues = new Dictionary<UUID, Queue<OSD>>(); | 80 | private Dictionary<UUID, Queue<OSD>> queues = new Dictionary<UUID, Queue<OSD>>(); |
81 | private Dictionary<UUID, UUID> m_QueueUUIDAvatarMapping = new Dictionary<UUID, UUID>(); | ||
82 | private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>(); | 81 | private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>(); |
83 | 82 | ||
84 | #region INonSharedRegionModule methods | 83 | #region INonSharedRegionModule methods |
@@ -201,6 +200,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
201 | } | 200 | } |
202 | 201 | ||
203 | /// <summary> | 202 | /// <summary> |
203 | |||
204 | /// May return a null queue | 204 | /// May return a null queue |
205 | /// </summary> | 205 | /// </summary> |
206 | /// <param name="agentId"></param> | 206 | /// <param name="agentId"></param> |
@@ -231,18 +231,12 @@ namespace OpenSim.Region.ClientStack.Linden | |||
231 | lock (queue) | 231 | lock (queue) |
232 | queue.Enqueue(ev); | 232 | queue.Enqueue(ev); |
233 | } | 233 | } |
234 | else if (DebugLevel > 0) | 234 | else |
235 | { | 235 | { |
236 | ScenePresence sp = m_scene.GetScenePresence(avatarID); | ||
237 | |||
238 | // This assumes that an NPC should never have a queue. | ||
239 | if (sp != null && sp.PresenceType != PresenceType.Npc) | ||
240 | { | ||
241 | OSDMap evMap = (OSDMap)ev; | 236 | OSDMap evMap = (OSDMap)ev; |
242 | m_log.WarnFormat( | 237 | m_log.WarnFormat( |
243 | "[EVENTQUEUE]: (Enqueue) No queue found for agent {0} {1} when placing message {2} in region {3}", | 238 | "[EVENTQUEUE]: (Enqueue) No queue found for agent {0} when placing message {1} in region {2}", |
244 | sp.Name, sp.UUID, evMap["message"], m_scene.Name); | 239 | avatarID, evMap["message"], m_scene.Name); |
245 | } | ||
246 | } | 240 | } |
247 | } | 241 | } |
248 | catch (NullReferenceException e) | 242 | catch (NullReferenceException e) |
@@ -263,28 +257,13 @@ namespace OpenSim.Region.ClientStack.Linden | |||
263 | lock (queues) | 257 | lock (queues) |
264 | queues.Remove(agentID); | 258 | queues.Remove(agentID); |
265 | 259 | ||
266 | List<UUID> removeitems = new List<UUID>(); | ||
267 | lock (m_AvatarQueueUUIDMapping) | 260 | lock (m_AvatarQueueUUIDMapping) |
268 | m_AvatarQueueUUIDMapping.Remove(agentID); | 261 | m_AvatarQueueUUIDMapping.Remove(agentID); |
269 | 262 | ||
270 | UUID searchval = UUID.Zero; | 263 | lock (m_ids) |
271 | |||
272 | removeitems.Clear(); | ||
273 | |||
274 | lock (m_QueueUUIDAvatarMapping) | ||
275 | { | 264 | { |
276 | foreach (UUID ky in m_QueueUUIDAvatarMapping.Keys) | 265 | if (!m_ids.ContainsKey(agentID)) |
277 | { | 266 | m_ids.Remove(agentID); |
278 | searchval = m_QueueUUIDAvatarMapping[ky]; | ||
279 | |||
280 | if (searchval == agentID) | ||
281 | { | ||
282 | removeitems.Add(ky); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | foreach (UUID ky in removeitems) | ||
287 | m_QueueUUIDAvatarMapping.Remove(ky); | ||
288 | } | 267 | } |
289 | 268 | ||
290 | // m_log.DebugFormat("[EVENTQUEUE]: Deleted queues for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); | 269 | // m_log.DebugFormat("[EVENTQUEUE]: Deleted queues for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); |
@@ -309,55 +288,95 @@ namespace OpenSim.Region.ClientStack.Linden | |||
309 | "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}", | 288 | "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}", |
310 | agentID, caps, m_scene.RegionInfo.RegionName); | 289 | agentID, caps, m_scene.RegionInfo.RegionName); |
311 | 290 | ||
312 | // Let's instantiate a Queue for this agent right now | ||
313 | TryGetQueue(agentID); | ||
314 | |||
315 | UUID eventQueueGetUUID; | 291 | UUID eventQueueGetUUID; |
292 | Queue<OSD> queue; | ||
293 | Random rnd = new Random(Environment.TickCount); | ||
294 | int nrnd = rnd.Next(30000000); | ||
295 | if (nrnd < 0) | ||
296 | nrnd = -nrnd; | ||
316 | 297 | ||
317 | lock (m_AvatarQueueUUIDMapping) | 298 | lock (queues) |
318 | { | 299 | { |
319 | // Reuse open queues. The client does! | 300 | if (queues.ContainsKey(agentID)) |
320 | if (m_AvatarQueueUUIDMapping.ContainsKey(agentID)) | 301 | queue = queues[agentID]; |
302 | else | ||
303 | queue = null; | ||
304 | |||
305 | if (queue == null) | ||
321 | { | 306 | { |
322 | //m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!"); | 307 | queue = new Queue<OSD>(); |
323 | eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID]; | 308 | queues[agentID] = queue; |
309 | |||
310 | // push markers to handle old responses still waiting | ||
311 | // this will cost at most viewer getting two forced noevents | ||
312 | // even being a new queue better be safe | ||
313 | queue.Enqueue(null); | ||
314 | queue.Enqueue(null); // one should be enough | ||
315 | |||
316 | lock (m_AvatarQueueUUIDMapping) | ||
317 | { | ||
318 | eventQueueGetUUID = UUID.Random(); | ||
319 | if (m_AvatarQueueUUIDMapping.ContainsKey(agentID)) | ||
320 | { | ||
321 | // oops this should not happen ? | ||
322 | m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID without a queue"); | ||
323 | eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID]; | ||
324 | } | ||
325 | m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID); | ||
326 | } | ||
327 | lock (m_ids) | ||
328 | { | ||
329 | if (!m_ids.ContainsKey(agentID)) | ||
330 | m_ids.Add(agentID, nrnd); | ||
331 | else | ||
332 | m_ids[agentID] = nrnd; | ||
333 | } | ||
324 | } | 334 | } |
325 | else | 335 | else |
326 | { | 336 | { |
327 | eventQueueGetUUID = UUID.Random(); | 337 | // push markers to handle old responses still waiting |
328 | //m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!"); | 338 | // this will cost at most viewer getting two forced noevents |
339 | // even being a new queue better be safe | ||
340 | queue.Enqueue(null); | ||
341 | queue.Enqueue(null); // one should be enough | ||
342 | |||
343 | // reuse or not to reuse TODO FIX | ||
344 | lock (m_AvatarQueueUUIDMapping) | ||
345 | { | ||
346 | // Reuse open queues. The client does! | ||
347 | // Its reuse caps path not queues those are been reused already | ||
348 | if (m_AvatarQueueUUIDMapping.ContainsKey(agentID)) | ||
349 | { | ||
350 | m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!"); | ||
351 | eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID]; | ||
352 | } | ||
353 | else | ||
354 | { | ||
355 | eventQueueGetUUID = UUID.Random(); | ||
356 | m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID); | ||
357 | m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!"); | ||
358 | } | ||
359 | } | ||
360 | lock (m_ids) | ||
361 | { | ||
362 | // change to negative numbers so they are changed at end of sending first marker | ||
363 | // old data on a queue may be sent on a response for a new caps | ||
364 | // but at least will be sent with coerent IDs | ||
365 | if (!m_ids.ContainsKey(agentID)) | ||
366 | m_ids.Add(agentID, -nrnd); // should not happen | ||
367 | else | ||
368 | m_ids[agentID] = -m_ids[agentID]; | ||
369 | } | ||
329 | } | 370 | } |
330 | } | 371 | } |
331 | 372 | ||
332 | lock (m_QueueUUIDAvatarMapping) | ||
333 | { | ||
334 | if (!m_QueueUUIDAvatarMapping.ContainsKey(eventQueueGetUUID)) | ||
335 | m_QueueUUIDAvatarMapping.Add(eventQueueGetUUID, agentID); | ||
336 | } | ||
337 | |||
338 | lock (m_AvatarQueueUUIDMapping) | ||
339 | { | ||
340 | if (!m_AvatarQueueUUIDMapping.ContainsKey(agentID)) | ||
341 | m_AvatarQueueUUIDMapping.Add(agentID, eventQueueGetUUID); | ||
342 | } | ||
343 | |||
344 | caps.RegisterPollHandler( | 373 | caps.RegisterPollHandler( |
345 | "EventQueueGet", | 374 | "EventQueueGet", |
346 | new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, agentID, SERVER_EQ_TIME_NO_EVENTS)); | 375 | new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, agentID, SERVER_EQ_TIME_NO_EVENTS)); |
347 | |||
348 | Random rnd = new Random(Environment.TickCount); | ||
349 | lock (m_ids) | ||
350 | { | ||
351 | if (!m_ids.ContainsKey(agentID)) | ||
352 | m_ids.Add(agentID, rnd.Next(30000000)); | ||
353 | } | ||
354 | } | 376 | } |
355 | 377 | ||
356 | public bool HasEvents(UUID requestID, UUID agentID) | 378 | public bool HasEvents(UUID requestID, UUID agentID) |
357 | { | 379 | { |
358 | // Don't use this, because of race conditions at agent closing time | ||
359 | //Queue<OSD> queue = TryGetQueue(agentID); | ||
360 | |||
361 | Queue<OSD> queue = GetQueue(agentID); | 380 | Queue<OSD> queue = GetQueue(agentID); |
362 | if (queue != null) | 381 | if (queue != null) |
363 | lock (queue) | 382 | lock (queue) |
@@ -366,7 +385,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
366 | return queue.Count > 0; | 385 | return queue.Count > 0; |
367 | } | 386 | } |
368 | 387 | ||
369 | return false; | 388 | //m_log.WarnFormat("POLLED FOR EVENTS BY {0} unknown agent", agentID); |
389 | return true; | ||
370 | } | 390 | } |
371 | 391 | ||
372 | /// <summary> | 392 | /// <summary> |
@@ -395,55 +415,65 @@ namespace OpenSim.Region.ClientStack.Linden | |||
395 | return NoEvents(requestID, pAgentId); | 415 | return NoEvents(requestID, pAgentId); |
396 | } | 416 | } |
397 | 417 | ||
398 | OSD element; | 418 | OSD element = null;; |
419 | OSDArray array = new OSDArray(); | ||
420 | int thisID = 0; | ||
421 | bool negativeID = false; | ||
422 | |||
399 | lock (queue) | 423 | lock (queue) |
400 | { | 424 | { |
401 | if (queue.Count == 0) | 425 | if (queue.Count == 0) |
402 | return NoEvents(requestID, pAgentId); | 426 | return NoEvents(requestID, pAgentId); |
403 | element = queue.Dequeue(); // 15s timeout | ||
404 | } | ||
405 | 427 | ||
406 | int thisID = 0; | 428 | lock (m_ids) |
407 | lock (m_ids) | 429 | thisID = m_ids[pAgentId]; |
408 | thisID = m_ids[pAgentId]; | ||
409 | 430 | ||
410 | OSDArray array = new OSDArray(); | 431 | if (thisID < 0) |
411 | if (element == null) // didn't have an event in 15s | ||
412 | { | ||
413 | // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say! | ||
414 | array.Add(EventQueueHelper.KeepAliveEvent()); | ||
415 | //m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", pAgentId, m_scene.RegionInfo.RegionName); | ||
416 | } | ||
417 | else | ||
418 | { | ||
419 | if (DebugLevel > 0) | ||
420 | LogOutboundDebugMessage(element, pAgentId); | ||
421 | |||
422 | array.Add(element); | ||
423 | |||
424 | lock (queue) | ||
425 | { | 432 | { |
426 | while (queue.Count > 0) | 433 | negativeID = true; |
427 | { | 434 | thisID = -thisID; |
428 | element = queue.Dequeue(); | 435 | } |
436 | |||
437 | while (queue.Count > 0) | ||
438 | { | ||
439 | element = queue.Dequeue(); | ||
440 | // add elements until a marker is found | ||
441 | // so they get into a response | ||
442 | if (element == null) | ||
443 | break; | ||
444 | if (DebugLevel > 0) | ||
445 | LogOutboundDebugMessage(element, pAgentId); | ||
446 | array.Add(element); | ||
447 | thisID++; | ||
448 | } | ||
449 | } | ||
429 | 450 | ||
430 | if (DebugLevel > 0) | 451 | OSDMap events = null; |
431 | LogOutboundDebugMessage(element, pAgentId); | ||
432 | 452 | ||
433 | array.Add(element); | 453 | if (array.Count > 0) |
434 | thisID++; | 454 | { |
435 | } | 455 | events = new OSDMap(); |
436 | } | 456 | events.Add("events", array); |
457 | events.Add("id", new OSDInteger(thisID)); | ||
437 | } | 458 | } |
438 | 459 | ||
439 | OSDMap events = new OSDMap(); | 460 | if (negativeID && element == null) |
440 | events.Add("events", array); | 461 | { |
462 | Random rnd = new Random(Environment.TickCount); | ||
463 | thisID = rnd.Next(30000000); | ||
464 | if (thisID < 0) | ||
465 | thisID = -thisID; | ||
466 | } | ||
441 | 467 | ||
442 | events.Add("id", new OSDInteger(thisID)); | ||
443 | lock (m_ids) | 468 | lock (m_ids) |
444 | { | 469 | { |
445 | m_ids[pAgentId] = thisID + 1; | 470 | m_ids[pAgentId] = thisID + 1; |
446 | } | 471 | } |
472 | |||
473 | // if there where no elements before a marker send a NoEvents | ||
474 | if (array.Count == 0) | ||
475 | return NoEvents(requestID, pAgentId); | ||
476 | |||
447 | Hashtable responsedata = new Hashtable(); | 477 | Hashtable responsedata = new Hashtable(); |
448 | responsedata["int_response_code"] = 200; | 478 | responsedata["int_response_code"] = 200; |
449 | responsedata["content_type"] = "application/xml"; | 479 | responsedata["content_type"] = "application/xml"; |
@@ -461,260 +491,12 @@ namespace OpenSim.Region.ClientStack.Linden | |||
461 | responsedata["content_type"] = "text/plain"; | 491 | responsedata["content_type"] = "text/plain"; |
462 | responsedata["keepalive"] = false; | 492 | responsedata["keepalive"] = false; |
463 | responsedata["reusecontext"] = false; | 493 | responsedata["reusecontext"] = false; |
464 | responsedata["str_response_string"] = "Upstream error: "; | 494 | responsedata["str_response_string"] = "<llsd></llsd>"; |
465 | responsedata["error_status_text"] = "Upstream error:"; | 495 | responsedata["error_status_text"] = "<llsd></llsd>"; |
466 | responsedata["http_protocol_version"] = "HTTP/1.0"; | 496 | responsedata["http_protocol_version"] = "HTTP/1.0"; |
467 | return responsedata; | 497 | return responsedata; |
468 | } | 498 | } |
469 | 499 | ||
470 | // public Hashtable ProcessQueue(Hashtable request, UUID agentID, Caps caps) | ||
471 | // { | ||
472 | // // TODO: this has to be redone to not busy-wait (and block the thread), | ||
473 | // // TODO: as soon as we have a non-blocking way to handle HTTP-requests. | ||
474 | // | ||
475 | //// if (m_log.IsDebugEnabled) | ||
476 | //// { | ||
477 | //// String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1} from thread {2}: [ "; | ||
478 | //// foreach (object key in request.Keys) | ||
479 | //// { | ||
480 | //// debug += key.ToString() + "=" + request[key].ToString() + " "; | ||
481 | //// } | ||
482 | //// m_log.DebugFormat(debug + " ]", agentID, m_scene.RegionInfo.RegionName, System.Threading.Thread.CurrentThread.Name); | ||
483 | //// } | ||
484 | // | ||
485 | // Queue<OSD> queue = TryGetQueue(agentID); | ||
486 | // OSD element; | ||
487 | // | ||
488 | // lock (queue) | ||
489 | // element = queue.Dequeue(); // 15s timeout | ||
490 | // | ||
491 | // Hashtable responsedata = new Hashtable(); | ||
492 | // | ||
493 | // int thisID = 0; | ||
494 | // lock (m_ids) | ||
495 | // thisID = m_ids[agentID]; | ||
496 | // | ||
497 | // if (element == null) | ||
498 | // { | ||
499 | // //m_log.ErrorFormat("[EVENTQUEUE]: Nothing to process in " + m_scene.RegionInfo.RegionName); | ||
500 | // if (thisID == -1) // close-request | ||
501 | // { | ||
502 | // m_log.ErrorFormat("[EVENTQUEUE]: 404 in " + m_scene.RegionInfo.RegionName); | ||
503 | // responsedata["int_response_code"] = 404; //501; //410; //404; | ||
504 | // responsedata["content_type"] = "text/plain"; | ||
505 | // responsedata["keepalive"] = false; | ||
506 | // responsedata["str_response_string"] = "Closed EQG"; | ||
507 | // return responsedata; | ||
508 | // } | ||
509 | // responsedata["int_response_code"] = 502; | ||
510 | // responsedata["content_type"] = "text/plain"; | ||
511 | // responsedata["keepalive"] = false; | ||
512 | // responsedata["str_response_string"] = "Upstream error: "; | ||
513 | // responsedata["error_status_text"] = "Upstream error:"; | ||
514 | // responsedata["http_protocol_version"] = "HTTP/1.0"; | ||
515 | // return responsedata; | ||
516 | // } | ||
517 | // | ||
518 | // OSDArray array = new OSDArray(); | ||
519 | // if (element == null) // didn't have an event in 15s | ||
520 | // { | ||
521 | // // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say! | ||
522 | // array.Add(EventQueueHelper.KeepAliveEvent()); | ||
523 | // //m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); | ||
524 | // } | ||
525 | // else | ||
526 | // { | ||
527 | // array.Add(element); | ||
528 | // | ||
529 | // if (element is OSDMap) | ||
530 | // { | ||
531 | // OSDMap ev = (OSDMap)element; | ||
532 | // m_log.DebugFormat( | ||
533 | // "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}", | ||
534 | // ev["message"], m_scene.GetScenePresence(agentID).Name); | ||
535 | // } | ||
536 | // | ||
537 | // lock (queue) | ||
538 | // { | ||
539 | // while (queue.Count > 0) | ||
540 | // { | ||
541 | // element = queue.Dequeue(); | ||
542 | // | ||
543 | // if (element is OSDMap) | ||
544 | // { | ||
545 | // OSDMap ev = (OSDMap)element; | ||
546 | // m_log.DebugFormat( | ||
547 | // "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}", | ||
548 | // ev["message"], m_scene.GetScenePresence(agentID).Name); | ||
549 | // } | ||
550 | // | ||
551 | // array.Add(element); | ||
552 | // thisID++; | ||
553 | // } | ||
554 | // } | ||
555 | // } | ||
556 | // | ||
557 | // OSDMap events = new OSDMap(); | ||
558 | // events.Add("events", array); | ||
559 | // | ||
560 | // events.Add("id", new OSDInteger(thisID)); | ||
561 | // lock (m_ids) | ||
562 | // { | ||
563 | // m_ids[agentID] = thisID + 1; | ||
564 | // } | ||
565 | // | ||
566 | // responsedata["int_response_code"] = 200; | ||
567 | // responsedata["content_type"] = "application/xml"; | ||
568 | // responsedata["keepalive"] = false; | ||
569 | // responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events); | ||
570 | // | ||
571 | // m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]); | ||
572 | // | ||
573 | // return responsedata; | ||
574 | // } | ||
575 | |||
576 | // public Hashtable EventQueuePath2(Hashtable request) | ||
577 | // { | ||
578 | // string capuuid = (string)request["uri"]; //path.Replace("/CAPS/EQG/",""); | ||
579 | // // pull off the last "/" in the path. | ||
580 | // Hashtable responsedata = new Hashtable(); | ||
581 | // capuuid = capuuid.Substring(0, capuuid.Length - 1); | ||
582 | // capuuid = capuuid.Replace("/CAPS/EQG/", ""); | ||
583 | // UUID AvatarID = UUID.Zero; | ||
584 | // UUID capUUID = UUID.Zero; | ||
585 | // | ||
586 | // // parse the path and search for the avatar with it registered | ||
587 | // if (UUID.TryParse(capuuid, out capUUID)) | ||
588 | // { | ||
589 | // lock (m_QueueUUIDAvatarMapping) | ||
590 | // { | ||
591 | // if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID)) | ||
592 | // { | ||
593 | // AvatarID = m_QueueUUIDAvatarMapping[capUUID]; | ||
594 | // } | ||
595 | // } | ||
596 | // | ||
597 | // if (AvatarID != UUID.Zero) | ||
598 | // { | ||
599 | // return ProcessQueue(request, AvatarID, m_scene.CapsModule.GetCapsForUser(AvatarID)); | ||
600 | // } | ||
601 | // else | ||
602 | // { | ||
603 | // responsedata["int_response_code"] = 404; | ||
604 | // responsedata["content_type"] = "text/plain"; | ||
605 | // responsedata["keepalive"] = false; | ||
606 | // responsedata["str_response_string"] = "Not Found"; | ||
607 | // responsedata["error_status_text"] = "Not Found"; | ||
608 | // responsedata["http_protocol_version"] = "HTTP/1.0"; | ||
609 | // return responsedata; | ||
610 | // // return 404 | ||
611 | // } | ||
612 | // } | ||
613 | // else | ||
614 | // { | ||
615 | // responsedata["int_response_code"] = 404; | ||
616 | // responsedata["content_type"] = "text/plain"; | ||
617 | // responsedata["keepalive"] = false; | ||
618 | // responsedata["str_response_string"] = "Not Found"; | ||
619 | // responsedata["error_status_text"] = "Not Found"; | ||
620 | // responsedata["http_protocol_version"] = "HTTP/1.0"; | ||
621 | // return responsedata; | ||
622 | // // return 404 | ||
623 | // } | ||
624 | // } | ||
625 | |||
626 | public OSD EventQueueFallBack(string path, OSD request, string endpoint) | ||
627 | { | ||
628 | // This is a fallback element to keep the client from loosing EventQueueGet | ||
629 | // Why does CAPS fail sometimes!? | ||
630 | m_log.Warn("[EVENTQUEUE]: In the Fallback handler! We lost the Queue in the rest handler!"); | ||
631 | string capuuid = path.Replace("/CAPS/EQG/",""); | ||
632 | capuuid = capuuid.Substring(0, capuuid.Length - 1); | ||
633 | |||
634 | // UUID AvatarID = UUID.Zero; | ||
635 | UUID capUUID = UUID.Zero; | ||
636 | if (UUID.TryParse(capuuid, out capUUID)) | ||
637 | { | ||
638 | /* Don't remove this yet code cleaners! | ||
639 | * Still testing this! | ||
640 | * | ||
641 | lock (m_QueueUUIDAvatarMapping) | ||
642 | { | ||
643 | if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID)) | ||
644 | { | ||
645 | AvatarID = m_QueueUUIDAvatarMapping[capUUID]; | ||
646 | } | ||
647 | } | ||
648 | |||
649 | |||
650 | if (AvatarID != UUID.Zero) | ||
651 | { | ||
652 | // Repair the CAP! | ||
653 | //OpenSim.Framework.Capabilities.Caps caps = m_scene.GetCapsHandlerForUser(AvatarID); | ||
654 | //string capsBase = "/CAPS/EQG/"; | ||
655 | //caps.RegisterHandler("EventQueueGet", | ||
656 | //new RestHTTPHandler("POST", capsBase + capUUID.ToString() + "/", | ||
657 | //delegate(Hashtable m_dhttpMethod) | ||
658 | //{ | ||
659 | // return ProcessQueue(m_dhttpMethod, AvatarID, caps); | ||
660 | //})); | ||
661 | // start new ID sequence. | ||
662 | Random rnd = new Random(System.Environment.TickCount); | ||
663 | lock (m_ids) | ||
664 | { | ||
665 | if (!m_ids.ContainsKey(AvatarID)) | ||
666 | m_ids.Add(AvatarID, rnd.Next(30000000)); | ||
667 | } | ||
668 | |||
669 | |||
670 | int thisID = 0; | ||
671 | lock (m_ids) | ||
672 | thisID = m_ids[AvatarID]; | ||
673 | |||
674 | BlockingLLSDQueue queue = GetQueue(AvatarID); | ||
675 | OSDArray array = new OSDArray(); | ||
676 | LLSD element = queue.Dequeue(15000); // 15s timeout | ||
677 | if (element == null) | ||
678 | { | ||
679 | |||
680 | array.Add(EventQueueHelper.KeepAliveEvent()); | ||
681 | } | ||
682 | else | ||
683 | { | ||
684 | array.Add(element); | ||
685 | while (queue.Count() > 0) | ||
686 | { | ||
687 | array.Add(queue.Dequeue(1)); | ||
688 | thisID++; | ||
689 | } | ||
690 | } | ||
691 | OSDMap events = new OSDMap(); | ||
692 | events.Add("events", array); | ||
693 | |||
694 | events.Add("id", new LLSDInteger(thisID)); | ||
695 | |||
696 | lock (m_ids) | ||
697 | { | ||
698 | m_ids[AvatarID] = thisID + 1; | ||
699 | } | ||
700 | |||
701 | return events; | ||
702 | } | ||
703 | else | ||
704 | { | ||
705 | return new LLSD(); | ||
706 | } | ||
707 | * | ||
708 | */ | ||
709 | } | ||
710 | else | ||
711 | { | ||
712 | //return new LLSD(); | ||
713 | } | ||
714 | |||
715 | return new OSDString("shutdown404!"); | ||
716 | } | ||
717 | |||
718 | public void DisableSimulator(ulong handle, UUID avatarID) | 500 | public void DisableSimulator(ulong handle, UUID avatarID) |
719 | { | 501 | { |
720 | OSD item = EventQueueHelper.DisableSimulator(handle); | 502 | OSD item = EventQueueHelper.DisableSimulator(handle); |
@@ -827,4 +609,4 @@ namespace OpenSim.Region.ClientStack.Linden | |||
827 | Enqueue(item, avatarID); | 609 | Enqueue(item, avatarID); |
828 | } | 610 | } |
829 | } | 611 | } |
830 | } \ No newline at end of file | 612 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs index 384af74..799ad0b 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs | |||
@@ -76,9 +76,9 @@ namespace OpenSim.Region.ClientStack.Linden | |||
76 | 76 | ||
77 | llsdSimInfo.Add("Handle", new OSDBinary(ulongToByteArray(handle))); | 77 | llsdSimInfo.Add("Handle", new OSDBinary(ulongToByteArray(handle))); |
78 | llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes())); | 78 | llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes())); |
79 | llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port)); | 79 | llsdSimInfo.Add("Port", OSD.FromInteger(endPoint.Port)); |
80 | llsdSimInfo.Add("RegionSizeX", OSD.FromUInteger((uint) regionSizeX)); | 80 | llsdSimInfo.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX)); |
81 | llsdSimInfo.Add("RegionSizeY", OSD.FromUInteger((uint) regionSizeY)); | 81 | llsdSimInfo.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY)); |
82 | 82 | ||
83 | OSDArray arr = new OSDArray(1); | 83 | OSDArray arr = new OSDArray(1); |
84 | arr.Add(llsdSimInfo); | 84 | arr.Add(llsdSimInfo); |
@@ -157,6 +157,12 @@ namespace OpenSim.Region.ClientStack.Linden | |||
157 | uint locationID, uint flags, string capsURL, UUID agentID, | 157 | uint locationID, uint flags, string capsURL, UUID agentID, |
158 | int regionSizeX, int regionSizeY) | 158 | int regionSizeX, int regionSizeY) |
159 | { | 159 | { |
160 | // not sure why flags get overwritten here | ||
161 | if ((flags & (uint)TeleportFlags.IsFlying) != 0) | ||
162 | flags = (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.IsFlying; | ||
163 | else | ||
164 | flags = (uint)TeleportFlags.ViaLocation; | ||
165 | |||
160 | OSDMap info = new OSDMap(); | 166 | OSDMap info = new OSDMap(); |
161 | info.Add("AgentID", OSD.FromUUID(agentID)); | 167 | info.Add("AgentID", OSD.FromUUID(agentID)); |
162 | info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this? | 168 | info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this? |
@@ -165,7 +171,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
165 | info.Add("SimAccess", OSD.FromInteger(simAccess)); | 171 | info.Add("SimAccess", OSD.FromInteger(simAccess)); |
166 | info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); | 172 | info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); |
167 | info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); | 173 | info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); |
168 | info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation | 174 | // info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation |
175 | info.Add("TeleportFlags", OSD.FromUInteger(flags)); | ||
169 | info.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX)); | 176 | info.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX)); |
170 | info.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY)); | 177 | info.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY)); |
171 | 178 | ||
@@ -204,8 +211,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
204 | {"sim-ip-and-port", new OSDString(simIpAndPort)}, | 211 | {"sim-ip-and-port", new OSDString(simIpAndPort)}, |
205 | {"seed-capability", new OSDString(seedcap)}, | 212 | {"seed-capability", new OSDString(seedcap)}, |
206 | {"region-handle", OSD.FromULong(regionHandle)}, | 213 | {"region-handle", OSD.FromULong(regionHandle)}, |
207 | {"region-size-x", OSD.FromInteger(regionSizeX)}, | 214 | {"region-size-x", OSD.FromUInteger((uint)regionSizeX)}, |
208 | {"region-size-y", OSD.FromInteger(regionSizeY)} | 215 | {"region-size-y", OSD.FromUInteger((uint)regionSizeY)} |
209 | }; | 216 | }; |
210 | 217 | ||
211 | return BuildEvent("EstablishAgentCommunication", body); | 218 | return BuildEvent("EstablishAgentCommunication", body); |
@@ -412,7 +419,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
412 | public static OSD partPhysicsProperties(uint localID, byte physhapetype, | 419 | public static OSD partPhysicsProperties(uint localID, byte physhapetype, |
413 | float density, float friction, float bounce, float gravmod) | 420 | float density, float friction, float bounce, float gravmod) |
414 | { | 421 | { |
415 | 422 | ||
416 | OSDMap physinfo = new OSDMap(6); | 423 | OSDMap physinfo = new OSDMap(6); |
417 | physinfo["LocalID"] = localID; | 424 | physinfo["LocalID"] = localID; |
418 | physinfo["Density"] = density; | 425 | physinfo["Density"] = density; |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs index f57d857..b5a70040 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,12 +60,50 @@ 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 | |||
60 | private string m_URL2; | 64 | private string m_URL2; |
61 | private string m_RedirectURL = null; | 65 | private string m_RedirectURL = null; |
62 | private string m_RedirectURL2 = null; | 66 | private string m_RedirectURL2 = null; |
67 | |||
68 | struct aPollRequest | ||
69 | { | ||
70 | public PollServiceMeshEventArgs thepoll; | ||
71 | public UUID reqID; | ||
72 | public Hashtable request; | ||
73 | } | ||
74 | |||
75 | public class aPollResponse | ||
76 | { | ||
77 | public Hashtable response; | ||
78 | public int bytes; | ||
79 | public int lod; | ||
80 | } | ||
81 | |||
82 | |||
83 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
84 | |||
85 | private static GetMeshHandler m_getMeshHandler; | ||
86 | |||
87 | private IAssetService m_assetService = null; | ||
88 | |||
89 | private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>(); | ||
90 | private static Thread[] m_workerThreads = null; | ||
91 | |||
92 | private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue = | ||
93 | new OpenMetaverse.BlockingQueue<aPollRequest>(); | ||
94 | |||
95 | private Dictionary<UUID, PollServiceMeshEventArgs> m_pollservices = new Dictionary<UUID, PollServiceMeshEventArgs>(); | ||
96 | |||
63 | 97 | ||
64 | #region Region Module interfaceBase Members | 98 | #region Region Module interfaceBase Members |
65 | 99 | ||
100 | ~GetMeshModule() | ||
101 | { | ||
102 | foreach (Thread t in m_workerThreads) | ||
103 | Watchdog.AbortThread(t.ManagedThreadId); | ||
104 | |||
105 | } | ||
106 | |||
66 | public Type ReplaceableInterface | 107 | public Type ReplaceableInterface |
67 | { | 108 | { |
68 | get { return null; } | 109 | get { return null; } |
@@ -87,6 +128,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
87 | if (m_URL2 != string.Empty) | 128 | if (m_URL2 != string.Empty) |
88 | { | 129 | { |
89 | m_Enabled = true; | 130 | m_Enabled = true; |
131 | |||
90 | m_RedirectURL2 = config.GetString("GetMesh2RedirectURL"); | 132 | m_RedirectURL2 = config.GetString("GetMesh2RedirectURL"); |
91 | } | 133 | } |
92 | } | 134 | } |
@@ -97,6 +139,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
97 | return; | 139 | return; |
98 | 140 | ||
99 | m_scene = pScene; | 141 | m_scene = pScene; |
142 | |||
143 | m_assetService = pScene.AssetService; | ||
100 | } | 144 | } |
101 | 145 | ||
102 | public void RemoveRegion(Scene scene) | 146 | public void RemoveRegion(Scene scene) |
@@ -105,6 +149,9 @@ namespace OpenSim.Region.ClientStack.Linden | |||
105 | return; | 149 | return; |
106 | 150 | ||
107 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | 151 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; |
152 | m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; | ||
153 | m_scene.EventManager.OnThrottleUpdate -= ThrottleUpdate; | ||
154 | |||
108 | m_scene = null; | 155 | m_scene = null; |
109 | } | 156 | } |
110 | 157 | ||
@@ -115,6 +162,27 @@ namespace OpenSim.Region.ClientStack.Linden | |||
115 | 162 | ||
116 | m_AssetService = m_scene.RequestModuleInterface<IAssetService>(); | 163 | m_AssetService = m_scene.RequestModuleInterface<IAssetService>(); |
117 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 164 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
165 | // We'll reuse the same handler for all requests. | ||
166 | m_getMeshHandler = new GetMeshHandler(m_assetService); | ||
167 | m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; | ||
168 | m_scene.EventManager.OnThrottleUpdate += ThrottleUpdate; | ||
169 | |||
170 | if (m_workerThreads == null) | ||
171 | { | ||
172 | m_workerThreads = new Thread[2]; | ||
173 | |||
174 | for (uint i = 0; i < 2; i++) | ||
175 | { | ||
176 | m_workerThreads[i] = WorkManager.StartThread(DoMeshRequests, | ||
177 | String.Format("MeshWorkerThread{0}", i), | ||
178 | ThreadPriority.Normal, | ||
179 | false, | ||
180 | false, | ||
181 | null, | ||
182 | int.MaxValue); | ||
183 | } | ||
184 | } | ||
185 | |||
118 | } | 186 | } |
119 | 187 | ||
120 | 188 | ||
@@ -124,44 +192,346 @@ namespace OpenSim.Region.ClientStack.Linden | |||
124 | 192 | ||
125 | #endregion | 193 | #endregion |
126 | 194 | ||
195 | private void DoMeshRequests() | ||
196 | { | ||
197 | while (true) | ||
198 | { | ||
199 | aPollRequest poolreq = m_queue.Dequeue(); | ||
127 | 200 | ||
128 | public void RegisterCaps(UUID agentID, Caps caps) | 201 | poolreq.thepoll.Process(poolreq); |
202 | } | ||
203 | } | ||
204 | |||
205 | // 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. | ||
206 | public void ThrottleUpdate(ScenePresence p) | ||
207 | { | ||
208 | UUID user = p.UUID; | ||
209 | int imagethrottle = p.ControllingClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Asset); | ||
210 | PollServiceMeshEventArgs args; | ||
211 | if (m_pollservices.TryGetValue(user, out args)) | ||
212 | { | ||
213 | args.UpdateThrottle(imagethrottle, p); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | private class PollServiceMeshEventArgs : PollServiceEventArgs | ||
129 | { | 218 | { |
130 | UUID capID = UUID.Random(); | 219 | private List<Hashtable> requests = |
131 | bool getMeshRegistered = false; | 220 | new List<Hashtable>(); |
221 | private Dictionary<UUID, aPollResponse> responses = | ||
222 | new Dictionary<UUID, aPollResponse>(); | ||
132 | 223 | ||
133 | if (m_URL == string.Empty) | 224 | private Scene m_scene; |
225 | private MeshCapsDataThrottler m_throttler; | ||
226 | public PollServiceMeshEventArgs(string uri, UUID pId, Scene scene) : | ||
227 | base(null, uri, null, null, null, pId, int.MaxValue) | ||
134 | { | 228 | { |
229 | m_scene = scene; | ||
230 | m_throttler = new MeshCapsDataThrottler(100000, 1400000, 10000, scene, pId); | ||
231 | // x is request id, y is userid | ||
232 | HasEvents = (x, y) => | ||
233 | { | ||
234 | lock (responses) | ||
235 | { | ||
236 | bool ret = m_throttler.hasEvents(x, responses); | ||
237 | m_throttler.ProcessTime(); | ||
238 | return ret; | ||
239 | |||
240 | } | ||
241 | }; | ||
242 | GetEvents = (x, y) => | ||
243 | { | ||
244 | lock (responses) | ||
245 | { | ||
246 | try | ||
247 | { | ||
248 | return responses[x].response; | ||
249 | } | ||
250 | finally | ||
251 | { | ||
252 | m_throttler.ProcessTime(); | ||
253 | responses.Remove(x); | ||
254 | } | ||
255 | } | ||
256 | }; | ||
257 | // x is request id, y is request data hashtable | ||
258 | Request = (x, y) => | ||
259 | { | ||
260 | aPollRequest reqinfo = new aPollRequest(); | ||
261 | reqinfo.thepoll = this; | ||
262 | reqinfo.reqID = x; | ||
263 | reqinfo.request = y; | ||
264 | |||
265 | m_queue.Enqueue(reqinfo); | ||
266 | }; | ||
267 | |||
268 | // this should never happen except possible on shutdown | ||
269 | NoEvents = (x, y) => | ||
270 | { | ||
271 | /* | ||
272 | lock (requests) | ||
273 | { | ||
274 | Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); | ||
275 | requests.Remove(request); | ||
276 | } | ||
277 | */ | ||
278 | Hashtable response = new Hashtable(); | ||
279 | |||
280 | response["int_response_code"] = 500; | ||
281 | response["str_response_string"] = "Script timeout"; | ||
282 | response["content_type"] = "text/plain"; | ||
283 | response["keepalive"] = false; | ||
284 | response["reusecontext"] = false; | ||
285 | |||
286 | return response; | ||
287 | }; | ||
288 | } | ||
289 | |||
290 | public void Process(aPollRequest requestinfo) | ||
291 | { | ||
292 | Hashtable response; | ||
293 | |||
294 | UUID requestID = requestinfo.reqID; | ||
295 | |||
296 | // If the avatar is gone, don't bother to get the texture | ||
297 | if (m_scene.GetScenePresence(Id) == null) | ||
298 | { | ||
299 | response = new Hashtable(); | ||
300 | |||
301 | response["int_response_code"] = 500; | ||
302 | response["str_response_string"] = "Script timeout"; | ||
303 | response["content_type"] = "text/plain"; | ||
304 | response["keepalive"] = false; | ||
305 | response["reusecontext"] = false; | ||
306 | |||
307 | lock (responses) | ||
308 | responses[requestID] = new aPollResponse() { bytes = 0, response = response, lod = 0 }; | ||
309 | |||
310 | return; | ||
311 | } | ||
312 | |||
313 | response = m_getMeshHandler.Handle(requestinfo.request); | ||
314 | lock (responses) | ||
315 | { | ||
316 | responses[requestID] = new aPollResponse() | ||
317 | { | ||
318 | bytes = (int)response["int_bytes"], | ||
319 | lod = (int)response["int_lod"], | ||
320 | response = response | ||
321 | }; | ||
135 | 322 | ||
323 | } | ||
324 | m_throttler.ProcessTime(); | ||
136 | } | 325 | } |
137 | else if (m_URL == "localhost") | 326 | |
327 | internal void UpdateThrottle(int pimagethrottle, ScenePresence p) | ||
138 | { | 328 | { |
139 | getMeshRegistered = true; | 329 | m_throttler.UpdateThrottle(pimagethrottle, p); |
140 | caps.RegisterHandler( | 330 | } |
141 | "GetMesh", | 331 | } |
142 | new GetMeshHandler("/CAPS/" + capID + "/", m_AssetService, "GetMesh", agentID.ToString(), m_RedirectURL)); | 332 | |
333 | public void RegisterCaps(UUID agentID, Caps caps) | ||
334 | { | ||
335 | // UUID capID = UUID.Random(); | ||
336 | if (m_URL == "localhost") | ||
337 | { | ||
338 | string capUrl = "/CAPS/" + UUID.Random() + "/"; | ||
339 | |||
340 | // Register this as a poll service | ||
341 | PollServiceMeshEventArgs args = new PollServiceMeshEventArgs(capUrl, agentID, m_scene); | ||
342 | |||
343 | args.Type = PollServiceEventArgs.EventType.Mesh; | ||
344 | MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); | ||
345 | |||
346 | string hostName = m_scene.RegionInfo.ExternalHostName; | ||
347 | uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; | ||
348 | string protocol = "http"; | ||
349 | |||
350 | if (MainServer.Instance.UseSSL) | ||
351 | { | ||
352 | hostName = MainServer.Instance.SSLCommonName; | ||
353 | port = MainServer.Instance.SSLPort; | ||
354 | protocol = "https"; | ||
355 | } | ||
356 | caps.RegisterHandler("GetMesh", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); | ||
357 | m_pollservices[agentID] = args; | ||
358 | m_capsDict[agentID] = capUrl; | ||
143 | } | 359 | } |
144 | else | 360 | else |
145 | { | 361 | { |
146 | caps.RegisterHandler("GetMesh", m_URL); | 362 | caps.RegisterHandler("GetMesh", m_URL); |
147 | } | 363 | } |
364 | } | ||
365 | |||
366 | private void DeregisterCaps(UUID agentID, Caps caps) | ||
367 | { | ||
368 | string capUrl; | ||
369 | PollServiceMeshEventArgs args; | ||
370 | if (m_capsDict.TryGetValue(agentID, out capUrl)) | ||
371 | { | ||
372 | MainServer.Instance.RemoveHTTPHandler("", capUrl); | ||
373 | m_capsDict.Remove(agentID); | ||
374 | } | ||
375 | if (m_pollservices.TryGetValue(agentID, out args)) | ||
376 | { | ||
377 | m_pollservices.Remove(agentID); | ||
378 | } | ||
379 | } | ||
380 | |||
381 | internal sealed class MeshCapsDataThrottler | ||
382 | { | ||
383 | |||
384 | private volatile int currenttime = 0; | ||
385 | private volatile int lastTimeElapsed = 0; | ||
386 | private volatile int BytesSent = 0; | ||
387 | private int Lod3 = 0; | ||
388 | private int Lod2 = 0; | ||
389 | private int Lod1 = 0; | ||
390 | private int UserSetThrottle = 0; | ||
391 | private int UDPSetThrottle = 0; | ||
392 | private int CapSetThrottle = 0; | ||
393 | private float CapThrottleDistributon = 0.30f; | ||
394 | private readonly Scene m_scene; | ||
395 | private ThrottleOutPacketType Throttle; | ||
396 | private readonly UUID User; | ||
397 | |||
398 | public MeshCapsDataThrottler(int pBytes, int max, int min, Scene pScene, UUID puser) | ||
399 | { | ||
400 | ThrottleBytes = pBytes; | ||
401 | lastTimeElapsed = Util.EnvironmentTickCount(); | ||
402 | Throttle = ThrottleOutPacketType.Asset; | ||
403 | m_scene = pScene; | ||
404 | User = puser; | ||
405 | } | ||
406 | |||
407 | |||
408 | public bool hasEvents(UUID key, Dictionary<UUID, aPollResponse> responses) | ||
409 | { | ||
410 | const float ThirtyPercent = 0.30f; | ||
411 | const float FivePercent = 0.05f; | ||
412 | PassTime(); | ||
413 | // Note, this is called IN LOCK | ||
414 | bool haskey = responses.ContainsKey(key); | ||
415 | |||
416 | if (responses.Count > 2) | ||
417 | { | ||
418 | SplitThrottle(ThirtyPercent); | ||
419 | } | ||
420 | else | ||
421 | { | ||
422 | SplitThrottle(FivePercent); | ||
423 | } | ||
148 | 424 | ||
149 | if(m_URL2 == string.Empty) | 425 | if (!haskey) |
426 | { | ||
427 | return false; | ||
428 | } | ||
429 | aPollResponse response; | ||
430 | if (responses.TryGetValue(key, out response)) | ||
431 | { | ||
432 | float LOD3Over = (((ThrottleBytes*CapThrottleDistributon)%50000) + 1); | ||
433 | float LOD2Over = (((ThrottleBytes*CapThrottleDistributon)%10000) + 1); | ||
434 | // Normal | ||
435 | if (BytesSent + response.bytes <= ThrottleBytes) | ||
436 | { | ||
437 | BytesSent += response.bytes; | ||
438 | |||
439 | return true; | ||
440 | } | ||
441 | // Lod3 Over Throttle protection to keep things processing even when the throttle bandwidth is set too little. | ||
442 | else if (response.bytes > ThrottleBytes && Lod3 <= ((LOD3Over < 1)? 1: LOD3Over) ) | ||
443 | { | ||
444 | Interlocked.Increment(ref Lod3); | ||
445 | BytesSent += response.bytes; | ||
446 | |||
447 | return true; | ||
448 | } | ||
449 | // Lod2 Over Throttle protection to keep things processing even when the throttle bandwidth is set too little. | ||
450 | else if (response.bytes > ThrottleBytes && Lod2 <= ((LOD2Over < 1) ? 1 : LOD2Over)) | ||
451 | { | ||
452 | Interlocked.Increment(ref Lod2); | ||
453 | BytesSent += response.bytes; | ||
454 | |||
455 | return true; | ||
456 | } | ||
457 | else | ||
458 | { | ||
459 | return false; | ||
460 | } | ||
461 | } | ||
462 | |||
463 | return haskey; | ||
464 | } | ||
465 | public void SubtractBytes(int bytes,int lod) | ||
466 | { | ||
467 | BytesSent -= bytes; | ||
468 | } | ||
469 | private void SplitThrottle(float percentMultiplier) | ||
150 | { | 470 | { |
151 | 471 | ||
472 | if (CapThrottleDistributon != percentMultiplier) // don't switch it if it's already set at the % multipler | ||
473 | { | ||
474 | CapThrottleDistributon = percentMultiplier; | ||
475 | ScenePresence p; | ||
476 | if (m_scene.TryGetScenePresence(User, out p)) // If we don't get a user they're not here anymore. | ||
477 | { | ||
478 | // AlterThrottle(UserSetThrottle, p); | ||
479 | UpdateThrottle(UserSetThrottle, p); | ||
480 | } | ||
481 | } | ||
152 | } | 482 | } |
153 | else if (m_URL2 == "localhost") | 483 | |
484 | public void ProcessTime() | ||
154 | { | 485 | { |
155 | if (!getMeshRegistered) | 486 | PassTime(); |
487 | } | ||
488 | |||
489 | |||
490 | private void PassTime() | ||
491 | { | ||
492 | currenttime = Util.EnvironmentTickCount(); | ||
493 | int timeElapsed = Util.EnvironmentTickCountSubtract(currenttime, lastTimeElapsed); | ||
494 | //processTimeBasedActions(responses); | ||
495 | if (currenttime - timeElapsed >= 1000) | ||
156 | { | 496 | { |
157 | caps.RegisterHandler( | 497 | lastTimeElapsed = Util.EnvironmentTickCount(); |
158 | "GetMesh2", | 498 | BytesSent -= ThrottleBytes; |
159 | new GetMeshHandler("/CAPS/" + capID + "/", m_AssetService, "GetMesh2", agentID.ToString(), m_RedirectURL2)); | 499 | if (BytesSent < 0) BytesSent = 0; |
500 | if (BytesSent < ThrottleBytes) | ||
501 | { | ||
502 | Lod3 = 0; | ||
503 | Lod2 = 0; | ||
504 | Lod1 = 0; | ||
505 | } | ||
160 | } | 506 | } |
161 | } | 507 | } |
162 | else | 508 | private void AlterThrottle(int setting, ScenePresence p) |
509 | { | ||
510 | p.ControllingClient.SetAgentThrottleSilent((int)Throttle,setting); | ||
511 | } | ||
512 | |||
513 | public int ThrottleBytes | ||
163 | { | 514 | { |
164 | caps.RegisterHandler("GetMesh2", m_URL2); | 515 | get { return CapSetThrottle; } |
516 | set { CapSetThrottle = value; } | ||
517 | } | ||
518 | |||
519 | internal void UpdateThrottle(int pimagethrottle, ScenePresence p) | ||
520 | { | ||
521 | // Client set throttle ! | ||
522 | UserSetThrottle = pimagethrottle; | ||
523 | CapSetThrottle = (int)(pimagethrottle*CapThrottleDistributon); | ||
524 | // UDPSetThrottle = (int) (pimagethrottle*(100 - CapThrottleDistributon)); | ||
525 | |||
526 | float udp = 1.0f - CapThrottleDistributon; | ||
527 | if(udp < 0.7f) | ||
528 | udp = 0.7f; | ||
529 | UDPSetThrottle = (int) ((float)pimagethrottle * udp); | ||
530 | if (CapSetThrottle < 4068) | ||
531 | CapSetThrottle = 4068; // at least two discovery mesh | ||
532 | p.ControllingClient.SetAgentThrottleSilent((int) Throttle, UDPSetThrottle); | ||
533 | ProcessTime(); | ||
534 | |||
165 | } | 535 | } |
166 | } | 536 | } |
167 | 537 | ||
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs index bb932f2..79a3458 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,27 +50,54 @@ 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"; | ||
81 | |||
82 | private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue = | ||
83 | new OpenMetaverse.BlockingQueue<aPollRequest>(); | ||
84 | |||
64 | 85 | ||
65 | // TODO: Change this to a config option | 86 | // TODO: Change this to a config option |
66 | private string m_RedirectURL = null; | 87 | private string m_RedirectURL = null; |
67 | 88 | ||
68 | private string m_URL; | 89 | private Dictionary<UUID,PollServiceTextureEventArgs> m_pollservices = new Dictionary<UUID,PollServiceTextureEventArgs>(); |
90 | |||
69 | 91 | ||
70 | #region ISharedRegionModule Members | 92 | #region ISharedRegionModule Members |
71 | 93 | ||
72 | public void Initialise(IConfigSource source) | 94 | public void Initialise(IConfigSource source) |
73 | { | 95 | { |
74 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | 96 | IConfig config = source.Configs["ClientStack.LindenCaps"]; |
97 | |||
75 | if (config == null) | 98 | if (config == null) |
76 | return; | 99 | return; |
77 | 100 | /* | |
78 | m_URL = config.GetString("Cap_GetTexture", string.Empty); | 101 | m_URL = config.GetString("Cap_GetTexture", string.Empty); |
79 | // Cap doesn't exist | 102 | // Cap doesn't exist |
80 | if (m_URL != string.Empty) | 103 | if (m_URL != string.Empty) |
@@ -82,32 +105,98 @@ namespace OpenSim.Region.ClientStack.Linden | |||
82 | m_Enabled = true; | 105 | m_Enabled = true; |
83 | m_RedirectURL = config.GetString("GetTextureRedirectURL"); | 106 | m_RedirectURL = config.GetString("GetTextureRedirectURL"); |
84 | } | 107 | } |
108 | */ | ||
109 | m_Url = config.GetString("Cap_GetTexture", "localhost"); | ||
85 | } | 110 | } |
86 | 111 | ||
87 | public void AddRegion(Scene s) | 112 | public void AddRegion(Scene s) |
88 | { | 113 | { |
89 | if (!m_Enabled) | ||
90 | return; | ||
91 | |||
92 | m_scene = s; | 114 | m_scene = s; |
115 | m_assetService = s.AssetService; | ||
93 | } | 116 | } |
94 | 117 | ||
95 | public void RemoveRegion(Scene s) | 118 | public void RemoveRegion(Scene s) |
96 | { | 119 | { |
97 | if (!m_Enabled) | ||
98 | return; | ||
99 | |||
100 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | 120 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; |
121 | m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; | ||
122 | m_scene.EventManager.OnThrottleUpdate -= ThrottleUpdate; | ||
101 | m_scene = null; | 123 | m_scene = null; |
102 | } | 124 | } |
103 | 125 | ||
104 | public void RegionLoaded(Scene s) | 126 | public void RegionLoaded(Scene s) |
105 | { | 127 | { |
106 | if (!m_Enabled) | 128 | // We'll reuse the same handler for all requests. |
107 | return; | 129 | m_getTextureHandler = new GetTextureHandler(m_assetService); |
108 | 130 | ||
109 | m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | ||
110 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 131 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
132 | m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; | ||
133 | m_scene.EventManager.OnThrottleUpdate += ThrottleUpdate; | ||
134 | |||
135 | if (m_workerThreads == null) | ||
136 | { | ||
137 | m_workerThreads = new Thread[2]; | ||
138 | |||
139 | for (uint i = 0; i < 2; i++) | ||
140 | { | ||
141 | m_workerThreads[i] = WorkManager.StartThread(DoTextureRequests, | ||
142 | String.Format("TextureWorkerThread{0}", i), | ||
143 | ThreadPriority.Normal, | ||
144 | false, | ||
145 | false, | ||
146 | null, | ||
147 | int.MaxValue); | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | private int ExtractImageThrottle(byte[] pthrottles) | ||
152 | { | ||
153 | |||
154 | byte[] adjData; | ||
155 | int pos = 0; | ||
156 | |||
157 | if (!BitConverter.IsLittleEndian) | ||
158 | { | ||
159 | byte[] newData = new byte[7 * 4]; | ||
160 | Buffer.BlockCopy(pthrottles, 0, newData, 0, 7 * 4); | ||
161 | |||
162 | for (int i = 0; i < 7; i++) | ||
163 | Array.Reverse(newData, i * 4, 4); | ||
164 | |||
165 | adjData = newData; | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | adjData = pthrottles; | ||
170 | } | ||
171 | |||
172 | // 0.125f converts from bits to bytes | ||
173 | //int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
174 | //pos += 4; | ||
175 | // int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
176 | //pos += 4; | ||
177 | // int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
178 | // pos += 4; | ||
179 | // int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
180 | // pos += 4; | ||
181 | // int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
182 | // pos += 4; | ||
183 | pos = pos + 20; | ||
184 | int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); //pos += 4; | ||
185 | //int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
186 | return texture; | ||
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 = ExtractImageThrottle(throttles); | ||
195 | PollServiceTextureEventArgs args; | ||
196 | if (m_pollservices.TryGetValue(user,out args)) | ||
197 | { | ||
198 | args.UpdateThrottle(imagethrottle); | ||
199 | } | ||
111 | } | 200 | } |
112 | 201 | ||
113 | public void PostInitialise() | 202 | public void PostInitialise() |
@@ -125,28 +214,295 @@ namespace OpenSim.Region.ClientStack.Linden | |||
125 | 214 | ||
126 | #endregion | 215 | #endregion |
127 | 216 | ||
128 | public void RegisterCaps(UUID agentID, Caps caps) | 217 | ~GetTextureModule() |
218 | { | ||
219 | foreach (Thread t in m_workerThreads) | ||
220 | Watchdog.AbortThread(t.ManagedThreadId); | ||
221 | |||
222 | } | ||
223 | |||
224 | private class PollServiceTextureEventArgs : PollServiceEventArgs | ||
129 | { | 225 | { |
130 | UUID capID = UUID.Random(); | 226 | private List<Hashtable> requests = |
227 | new List<Hashtable>(); | ||
228 | private Dictionary<UUID, aPollResponse> responses = | ||
229 | new Dictionary<UUID, aPollResponse>(); | ||
131 | 230 | ||
132 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); | 231 | private Scene m_scene; |
133 | if (m_URL == "localhost") | 232 | private CapsDataThrottler m_throttler = new CapsDataThrottler(100000, 1400000,10000); |
233 | public PollServiceTextureEventArgs(UUID pId, Scene scene) : | ||
234 | base(null, "", null, null, null, pId, int.MaxValue) | ||
134 | { | 235 | { |
135 | // m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); | 236 | m_scene = scene; |
136 | caps.RegisterHandler( | 237 | // x is request id, y is userid |
137 | "GetTexture", | 238 | HasEvents = (x, y) => |
138 | new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString(), m_RedirectURL)); | 239 | { |
240 | lock (responses) | ||
241 | { | ||
242 | bool ret = m_throttler.hasEvents(x, responses); | ||
243 | m_throttler.ProcessTime(); | ||
244 | return ret; | ||
245 | |||
246 | } | ||
247 | }; | ||
248 | GetEvents = (x, y) => | ||
249 | { | ||
250 | lock (responses) | ||
251 | { | ||
252 | try | ||
253 | { | ||
254 | return responses[x].response; | ||
255 | } | ||
256 | finally | ||
257 | { | ||
258 | responses.Remove(x); | ||
259 | } | ||
260 | } | ||
261 | }; | ||
262 | // x is request id, y is request data hashtable | ||
263 | Request = (x, y) => | ||
264 | { | ||
265 | aPollRequest reqinfo = new aPollRequest(); | ||
266 | reqinfo.thepoll = this; | ||
267 | reqinfo.reqID = x; | ||
268 | reqinfo.request = y; | ||
269 | reqinfo.send503 = false; | ||
270 | |||
271 | lock (responses) | ||
272 | { | ||
273 | if (responses.Count > 0) | ||
274 | { | ||
275 | if (m_queue.Count >= 4) | ||
276 | { | ||
277 | // Never allow more than 4 fetches to wait | ||
278 | reqinfo.send503 = true; | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | m_queue.Enqueue(reqinfo); | ||
283 | }; | ||
284 | |||
285 | // this should never happen except possible on shutdown | ||
286 | NoEvents = (x, y) => | ||
287 | { | ||
288 | /* | ||
289 | lock (requests) | ||
290 | { | ||
291 | Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); | ||
292 | requests.Remove(request); | ||
293 | } | ||
294 | */ | ||
295 | Hashtable response = new Hashtable(); | ||
296 | |||
297 | response["int_response_code"] = 500; | ||
298 | response["str_response_string"] = "Script timeout"; | ||
299 | response["content_type"] = "text/plain"; | ||
300 | response["keepalive"] = false; | ||
301 | response["reusecontext"] = false; | ||
302 | |||
303 | return response; | ||
304 | }; | ||
139 | } | 305 | } |
140 | else | 306 | |
307 | public void Process(aPollRequest requestinfo) | ||
308 | { | ||
309 | Hashtable response; | ||
310 | |||
311 | UUID requestID = requestinfo.reqID; | ||
312 | |||
313 | if (requestinfo.send503) | ||
314 | { | ||
315 | response = new Hashtable(); | ||
316 | |||
317 | |||
318 | response["int_response_code"] = 503; | ||
319 | response["str_response_string"] = "Throttled"; | ||
320 | response["content_type"] = "text/plain"; | ||
321 | response["keepalive"] = false; | ||
322 | response["reusecontext"] = false; | ||
323 | |||
324 | Hashtable headers = new Hashtable(); | ||
325 | headers["Retry-After"] = 30; | ||
326 | response["headers"] = headers; | ||
327 | |||
328 | lock (responses) | ||
329 | responses[requestID] = new aPollResponse() {bytes = 0, response = response}; | ||
330 | |||
331 | return; | ||
332 | } | ||
333 | |||
334 | // If the avatar is gone, don't bother to get the texture | ||
335 | if (m_scene.GetScenePresence(Id) == null) | ||
336 | { | ||
337 | response = new Hashtable(); | ||
338 | |||
339 | response["int_response_code"] = 500; | ||
340 | response["str_response_string"] = "Script timeout"; | ||
341 | response["content_type"] = "text/plain"; | ||
342 | response["keepalive"] = false; | ||
343 | response["reusecontext"] = false; | ||
344 | |||
345 | lock (responses) | ||
346 | responses[requestID] = new aPollResponse() {bytes = 0, response = response}; | ||
347 | |||
348 | return; | ||
349 | } | ||
350 | |||
351 | response = m_getTextureHandler.Handle(requestinfo.request); | ||
352 | lock (responses) | ||
353 | { | ||
354 | responses[requestID] = new aPollResponse() | ||
355 | { | ||
356 | bytes = (int) response["int_bytes"], | ||
357 | response = response | ||
358 | }; | ||
359 | |||
360 | } | ||
361 | m_throttler.ProcessTime(); | ||
362 | } | ||
363 | |||
364 | internal void UpdateThrottle(int pimagethrottle) | ||
141 | { | 365 | { |
142 | // m_log.DebugFormat("[GETTEXTURE]: {0} in region {1}", m_URL, m_scene.RegionInfo.RegionName); | 366 | m_throttler.ThrottleBytes = pimagethrottle; |
367 | } | ||
368 | } | ||
369 | |||
370 | private void RegisterCaps(UUID agentID, Caps caps) | ||
371 | { | ||
372 | if (m_Url == "localhost") | ||
373 | { | ||
374 | string capUrl = "/CAPS/" + UUID.Random() + "/"; | ||
375 | |||
376 | // Register this as a poll service | ||
377 | PollServiceTextureEventArgs args = new PollServiceTextureEventArgs(agentID, m_scene); | ||
378 | |||
379 | args.Type = PollServiceEventArgs.EventType.Texture; | ||
380 | MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); | ||
381 | |||
382 | string hostName = m_scene.RegionInfo.ExternalHostName; | ||
383 | uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; | ||
384 | string protocol = "http"; | ||
385 | |||
386 | if (MainServer.Instance.UseSSL) | ||
387 | { | ||
388 | hostName = MainServer.Instance.SSLCommonName; | ||
389 | port = MainServer.Instance.SSLPort; | ||
390 | protocol = "https"; | ||
391 | } | ||
143 | IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>(); | 392 | IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>(); |
144 | if (handler != null) | 393 | if (handler != null) |
145 | handler.RegisterExternalUserCapsHandler(agentID,caps,"GetTexture", m_URL); | 394 | handler.RegisterExternalUserCapsHandler(agentID, caps, "GetTexture", capUrl); |
146 | else | 395 | else |
147 | caps.RegisterHandler("GetTexture", m_URL); | 396 | caps.RegisterHandler("GetTexture", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); |
397 | m_pollservices[agentID] = args; | ||
398 | m_capsDict[agentID] = capUrl; | ||
399 | } | ||
400 | else | ||
401 | { | ||
402 | caps.RegisterHandler("GetTexture", m_Url); | ||
148 | } | 403 | } |
149 | } | 404 | } |
150 | 405 | ||
406 | private void DeregisterCaps(UUID agentID, Caps caps) | ||
407 | { | ||
408 | PollServiceTextureEventArgs args; | ||
409 | |||
410 | MainServer.Instance.RemoveHTTPHandler("", m_Url); | ||
411 | m_capsDict.Remove(agentID); | ||
412 | |||
413 | if (m_pollservices.TryGetValue(agentID, out args)) | ||
414 | { | ||
415 | m_pollservices.Remove(agentID); | ||
416 | } | ||
417 | } | ||
418 | |||
419 | private void DoTextureRequests() | ||
420 | { | ||
421 | while (true) | ||
422 | { | ||
423 | aPollRequest poolreq = m_queue.Dequeue(); | ||
424 | |||
425 | poolreq.thepoll.Process(poolreq); | ||
426 | } | ||
427 | } | ||
428 | internal sealed class CapsDataThrottler | ||
429 | { | ||
430 | |||
431 | private volatile int currenttime = 0; | ||
432 | private volatile int lastTimeElapsed = 0; | ||
433 | private volatile int BytesSent = 0; | ||
434 | private int oversizedImages = 0; | ||
435 | public CapsDataThrottler(int pBytes, int max, int min) | ||
436 | { | ||
437 | ThrottleBytes = pBytes; | ||
438 | lastTimeElapsed = Util.EnvironmentTickCount(); | ||
439 | } | ||
440 | public bool hasEvents(UUID key, Dictionary<UUID, GetTextureModule.aPollResponse> responses) | ||
441 | { | ||
442 | PassTime(); | ||
443 | // Note, this is called IN LOCK | ||
444 | bool haskey = responses.ContainsKey(key); | ||
445 | if (!haskey) | ||
446 | { | ||
447 | return false; | ||
448 | } | ||
449 | GetTextureModule.aPollResponse response; | ||
450 | if (responses.TryGetValue(key, out response)) | ||
451 | { | ||
452 | // This is any error response | ||
453 | if (response.bytes == 0) | ||
454 | return true; | ||
455 | |||
456 | // Normal | ||
457 | if (BytesSent + response.bytes <= ThrottleBytes) | ||
458 | { | ||
459 | BytesSent += response.bytes; | ||
460 | //TimeBasedAction timeBasedAction = new TimeBasedAction { byteRemoval = response.bytes, requestId = key, timeMS = currenttime + 1000, unlockyn = false }; | ||
461 | //m_actions.Add(timeBasedAction); | ||
462 | return true; | ||
463 | } | ||
464 | // Big textures | ||
465 | else if (response.bytes > ThrottleBytes && oversizedImages <= ((ThrottleBytes % 50000) + 1)) | ||
466 | { | ||
467 | Interlocked.Increment(ref oversizedImages); | ||
468 | BytesSent += response.bytes; | ||
469 | //TimeBasedAction timeBasedAction = new TimeBasedAction { byteRemoval = response.bytes, requestId = key, timeMS = currenttime + (((response.bytes % ThrottleBytes)+1)*1000) , unlockyn = false }; | ||
470 | //m_actions.Add(timeBasedAction); | ||
471 | return true; | ||
472 | } | ||
473 | else | ||
474 | { | ||
475 | return false; | ||
476 | } | ||
477 | } | ||
478 | |||
479 | return haskey; | ||
480 | } | ||
481 | |||
482 | public void ProcessTime() | ||
483 | { | ||
484 | PassTime(); | ||
485 | } | ||
486 | |||
487 | private void PassTime() | ||
488 | { | ||
489 | currenttime = Util.EnvironmentTickCount(); | ||
490 | int timeElapsed = Util.EnvironmentTickCountSubtract(currenttime, lastTimeElapsed); | ||
491 | //processTimeBasedActions(responses); | ||
492 | if (Util.EnvironmentTickCountSubtract(currenttime, timeElapsed) >= 1000) | ||
493 | { | ||
494 | lastTimeElapsed = Util.EnvironmentTickCount(); | ||
495 | BytesSent -= ThrottleBytes; | ||
496 | if (BytesSent < 0) BytesSent = 0; | ||
497 | if (BytesSent < ThrottleBytes) | ||
498 | { | ||
499 | oversizedImages = 0; | ||
500 | } | ||
501 | } | ||
502 | } | ||
503 | public int ThrottleBytes; | ||
504 | } | ||
151 | } | 505 | } |
506 | |||
507 | |||
152 | } | 508 | } |
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/SimulatorFeaturesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs index e258bcb..d07f66e 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs | |||
@@ -155,6 +155,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
155 | m_features["MeshRezEnabled"] = true; | 155 | m_features["MeshRezEnabled"] = true; |
156 | m_features["MeshUploadEnabled"] = true; | 156 | m_features["MeshUploadEnabled"] = true; |
157 | m_features["MeshXferEnabled"] = true; | 157 | m_features["MeshXferEnabled"] = true; |
158 | |||
158 | m_features["PhysicsMaterialsEnabled"] = true; | 159 | m_features["PhysicsMaterialsEnabled"] = true; |
159 | 160 | ||
160 | OSDMap typesMap = new OSDMap(); | 161 | OSDMap typesMap = new OSDMap(); |
@@ -173,6 +174,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
173 | else | 174 | else |
174 | extrasMap = new OSDMap(); | 175 | extrasMap = new OSDMap(); |
175 | 176 | ||
177 | extrasMap["AvatarSkeleton"] = true; | ||
178 | extrasMap["AnimationSet"] = true; | ||
179 | |||
180 | // TODO: Take these out of here into their respective modules, like map-server-url | ||
176 | if (m_SearchURL != string.Empty) | 181 | if (m_SearchURL != string.Empty) |
177 | extrasMap["search-server-url"] = m_SearchURL; | 182 | extrasMap["search-server-url"] = m_SearchURL; |
178 | if (!string.IsNullOrEmpty(m_DestinationGuideURL)) | 183 | if (!string.IsNullOrEmpty(m_DestinationGuideURL)) |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs index dd4a691..db16ccb 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs | |||
@@ -52,6 +52,7 @@ using OSDMap = OpenMetaverse.StructuredData.OSDMap; | |||
52 | 52 | ||
53 | namespace OpenSim.Region.ClientStack.Linden.Caps.Tests | 53 | namespace OpenSim.Region.ClientStack.Linden.Caps.Tests |
54 | { | 54 | { |
55 | /* | ||
55 | [TestFixture] | 56 | [TestFixture] |
56 | public class WebFetchInvDescModuleTests : OpenSimTestCase | 57 | public class WebFetchInvDescModuleTests : OpenSimTestCase |
57 | { | 58 | { |
@@ -156,4 +157,5 @@ namespace OpenSim.Region.ClientStack.Linden.Caps.Tests | |||
156 | Assert.That((int)folderOsd["descendents"], Is.EqualTo(16)); | 157 | Assert.That((int)folderOsd["descendents"], Is.EqualTo(16)); |
157 | } | 158 | } |
158 | } | 159 | } |
160 | */ | ||
159 | } \ No newline at end of file | 161 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs index 8cdebcd..8fd8d1f 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | |||
@@ -66,14 +66,19 @@ namespace OpenSim.Region.ClientStack.Linden | |||
66 | private bool m_persistBakedTextures; | 66 | private bool m_persistBakedTextures; |
67 | 67 | ||
68 | private IBakedTextureModule m_BakedTextureModule; | 68 | private IBakedTextureModule m_BakedTextureModule; |
69 | private string m_URL; | ||
69 | 70 | ||
70 | public void Initialise(IConfigSource source) | 71 | public void Initialise(IConfigSource source) |
71 | { | 72 | { |
73 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | ||
74 | if (config == null) | ||
75 | return; | ||
76 | |||
77 | m_URL = config.GetString("Cap_UploadBakedTexture", string.Empty); | ||
78 | |||
72 | IConfig appearanceConfig = source.Configs["Appearance"]; | 79 | IConfig appearanceConfig = source.Configs["Appearance"]; |
73 | if (appearanceConfig != null) | 80 | if (appearanceConfig != null) |
74 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | 81 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); |
75 | |||
76 | |||
77 | } | 82 | } |
78 | 83 | ||
79 | public void AddRegion(Scene s) | 84 | public void AddRegion(Scene s) |
@@ -89,9 +94,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
89 | s.EventManager.OnRemovePresence -= DeRegisterPresence; | 94 | s.EventManager.OnRemovePresence -= DeRegisterPresence; |
90 | m_BakedTextureModule = null; | 95 | m_BakedTextureModule = null; |
91 | m_scene = null; | 96 | m_scene = null; |
92 | } | 97 | } |
93 | |||
94 | |||
95 | 98 | ||
96 | public void RegionLoaded(Scene s) | 99 | public void RegionLoaded(Scene s) |
97 | { | 100 | { |
@@ -103,44 +106,52 @@ namespace OpenSim.Region.ClientStack.Linden | |||
103 | 106 | ||
104 | private void DeRegisterPresence(UUID agentId) | 107 | private void DeRegisterPresence(UUID agentId) |
105 | { | 108 | { |
106 | ScenePresence presence = null; | ||
107 | if (m_scene.TryGetScenePresence(agentId, out presence)) | ||
108 | { | ||
109 | presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings; | ||
110 | } | ||
111 | |||
112 | } | 109 | } |
113 | 110 | ||
114 | private void RegisterNewPresence(ScenePresence presence) | 111 | private void RegisterNewPresence(ScenePresence presence) |
115 | { | 112 | { |
116 | presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; | 113 | // presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; |
117 | |||
118 | } | 114 | } |
119 | 115 | ||
120 | private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) | 116 | /* not in use. work done in AvatarFactoryModule ValidateBakedTextureCache() and UpdateBakedTextureCache() |
121 | { | 117 | private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) |
122 | int maxCacheitemsLoop = cacheItems.Length; | ||
123 | if (maxCacheitemsLoop > AvatarWearable.MAX_WEARABLES) | ||
124 | { | ||
125 | maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES; | ||
126 | m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES); | ||
127 | } | ||
128 | |||
129 | m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | ||
130 | if (cacheItems.Length > 0) | ||
131 | { | ||
132 | // m_log.Debug("[Cacheitems]: " + cacheItems.Length); | ||
133 | // for (int iter = 0; iter < maxCacheitemsLoop; iter++) | ||
134 | // { | ||
135 | // m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + | ||
136 | // cacheItems[iter].TextureID); | ||
137 | // } | ||
138 | |||
139 | ScenePresence p = null; | ||
140 | if (m_scene.TryGetScenePresence(remoteClient.AgentId, out p)) | ||
141 | { | 118 | { |
119 | // if cacheItems.Length > 0 viewer is giving us current textures information. | ||
120 | // baked ones should had been uploaded and in assets cache as local itens | ||
121 | |||
122 | |||
123 | if (cacheItems.Length == 0) | ||
124 | return; // no textures information, nothing to do | ||
125 | |||
126 | ScenePresence p = null; | ||
127 | if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out p)) | ||
128 | return; // what are we doing if there is no presence to cache for? | ||
129 | |||
130 | if (p.IsDeleted) | ||
131 | return; // does this really work? | ||
132 | |||
133 | int maxCacheitemsLoop = cacheItems.Length; | ||
134 | if (maxCacheitemsLoop > 20) | ||
135 | { | ||
136 | maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES; | ||
137 | m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES); | ||
138 | } | ||
139 | |||
140 | m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | ||
141 | |||
142 | |||
143 | // some nice debug | ||
144 | m_log.Debug("[Cacheitems]: " + cacheItems.Length); | ||
145 | for (int iter = 0; iter < maxCacheitemsLoop; iter++) | ||
146 | { | ||
147 | m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + | ||
148 | cacheItems[iter].TextureID); | ||
149 | } | ||
150 | |||
151 | // p.Appearance.WearableCacheItems is in memory primary cashID to textures mapper | ||
142 | 152 | ||
143 | WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; | 153 | WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; |
154 | |||
144 | if (existingitems == null) | 155 | if (existingitems == null) |
145 | { | 156 | { |
146 | if (m_BakedTextureModule != null) | 157 | if (m_BakedTextureModule != null) |
@@ -154,38 +165,22 @@ namespace OpenSim.Region.ClientStack.Linden | |||
154 | p.Appearance.WearableCacheItems = savedcache; | 165 | p.Appearance.WearableCacheItems = savedcache; |
155 | p.Appearance.WearableCacheItemsDirty = false; | 166 | p.Appearance.WearableCacheItemsDirty = false; |
156 | } | 167 | } |
157 | |||
158 | } | ||
159 | /* | ||
160 | * The following Catch types DO NOT WORK with m_BakedTextureModule.Get | ||
161 | * it jumps to the General Packet Exception Handler if you don't catch Exception! | ||
162 | * | ||
163 | catch (System.Net.Sockets.SocketException) | ||
164 | { | ||
165 | cacheItems = null; | ||
166 | } | 168 | } |
167 | catch (WebException) | 169 | |
168 | { | ||
169 | cacheItems = null; | ||
170 | } | ||
171 | catch (InvalidOperationException) | ||
172 | { | ||
173 | cacheItems = null; | ||
174 | } */ | ||
175 | catch (Exception) | 170 | catch (Exception) |
176 | { | 171 | { |
177 | // The service logs a sufficient error message. | 172 | // The service logs a sufficient error message. |
178 | } | 173 | } |
179 | 174 | ||
180 | 175 | ||
181 | if (savedcache != null) | 176 | if (savedcache != null) |
182 | existingitems = savedcache; | 177 | existingitems = savedcache; |
183 | } | 178 | } |
184 | } | 179 | } |
180 | |||
185 | // Existing items null means it's a fully new appearance | 181 | // Existing items null means it's a fully new appearance |
186 | if (existingitems == null) | 182 | if (existingitems == null) |
187 | { | 183 | { |
188 | |||
189 | for (int i = 0; i < maxCacheitemsLoop; i++) | 184 | for (int i = 0; i < maxCacheitemsLoop; i++) |
190 | { | 185 | { |
191 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | 186 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) |
@@ -198,7 +193,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
198 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; | 193 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; |
199 | continue; | 194 | continue; |
200 | } | 195 | } |
201 | cacheItems[i].TextureID =face.TextureID; | 196 | cacheItems[i].TextureID = face.TextureID; |
202 | if (m_scene.AssetService != null) | 197 | if (m_scene.AssetService != null) |
203 | cacheItems[i].TextureAsset = | 198 | cacheItems[i].TextureAsset = |
204 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); | 199 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); |
@@ -207,15 +202,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
207 | { | 202 | { |
208 | 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); | 203 | 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); |
209 | } | 204 | } |
210 | |||
211 | |||
212 | } | 205 | } |
213 | } | 206 | } |
214 | else | 207 | else |
215 | 208 | { | |
216 | |||
217 | { | ||
218 | // for each uploaded baked texture | ||
219 | for (int i = 0; i < maxCacheitemsLoop; i++) | 209 | for (int i = 0; i < maxCacheitemsLoop; i++) |
220 | { | 210 | { |
221 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) | 211 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) |
@@ -246,23 +236,24 @@ namespace OpenSim.Region.ClientStack.Linden | |||
246 | } | 236 | } |
247 | } | 237 | } |
248 | } | 238 | } |
249 | |||
250 | |||
251 | |||
252 | p.Appearance.WearableCacheItems = cacheItems; | 239 | p.Appearance.WearableCacheItems = cacheItems; |
253 | |||
254 | |||
255 | 240 | ||
256 | if (m_BakedTextureModule != null) | 241 | if (m_BakedTextureModule != null) |
257 | { | 242 | { |
258 | m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); | 243 | m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); |
259 | p.Appearance.WearableCacheItemsDirty = true; | 244 | p.Appearance.WearableCacheItemsDirty = true; |
260 | 245 | ||
261 | } | 246 | } |
262 | } | 247 | else |
263 | } | 248 | p.Appearance.WearableCacheItemsDirty = false; |
264 | } | ||
265 | 249 | ||
250 | for (int iter = 0; iter < maxCacheitemsLoop; iter++) | ||
251 | { | ||
252 | m_log.Debug("[CacheitemsLeaving] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + | ||
253 | cacheItems[iter].TextureID); | ||
254 | } | ||
255 | } | ||
256 | */ | ||
266 | public void PostInitialise() | 257 | public void PostInitialise() |
267 | { | 258 | { |
268 | } | 259 | } |
@@ -280,23 +271,26 @@ namespace OpenSim.Region.ClientStack.Linden | |||
280 | 271 | ||
281 | public void RegisterCaps(UUID agentID, Caps caps) | 272 | public void RegisterCaps(UUID agentID, Caps caps) |
282 | { | 273 | { |
283 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( | 274 | //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); |
284 | caps, m_scene.AssetService, m_persistBakedTextures); | 275 | if (m_URL == "localhost") |
276 | { | ||
277 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( | ||
278 | caps, m_scene.AssetService, m_persistBakedTextures); | ||
285 | 279 | ||
286 | 280 | caps.RegisterHandler( | |
287 | |||
288 | caps.RegisterHandler( | ||
289 | "UploadBakedTexture", | ||
290 | new RestStreamHandler( | ||
291 | "POST", | ||
292 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, | ||
293 | avatarhandler.UploadBakedTexture, | ||
294 | "UploadBakedTexture", | 281 | "UploadBakedTexture", |
295 | agentID.ToString())); | 282 | new RestStreamHandler( |
296 | 283 | "POST", | |
297 | 284 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, | |
298 | 285 | avatarhandler.UploadBakedTexture, | |
299 | 286 | "UploadBakedTexture", | |
287 | agentID.ToString())); | ||
288 | |||
289 | } | ||
290 | else | ||
291 | { | ||
292 | caps.RegisterHandler("UploadBakedTexture", m_URL); | ||
293 | } | ||
300 | } | 294 | } |
301 | } | 295 | } |
302 | } | 296 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs index 025ffea..1a19c1b 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 | /// <summary> | 69 | /// <summary> |
69 | /// Control whether requests will be processed asynchronously. | 70 | /// Control whether requests will be processed asynchronously. |
@@ -92,7 +93,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
92 | private bool m_Enabled; | 93 | private bool m_Enabled; |
93 | 94 | ||
94 | private string m_fetchInventoryDescendents2Url; | 95 | private string m_fetchInventoryDescendents2Url; |
95 | private string m_webFetchInventoryDescendentsUrl; | 96 | // private string m_webFetchInventoryDescendentsUrl; |
96 | 97 | ||
97 | private static FetchInvDescHandler m_webFetchHandler; | 98 | private static FetchInvDescHandler m_webFetchHandler; |
98 | 99 | ||
@@ -117,9 +118,10 @@ namespace OpenSim.Region.ClientStack.Linden | |||
117 | return; | 118 | return; |
118 | 119 | ||
119 | m_fetchInventoryDescendents2Url = config.GetString("Cap_FetchInventoryDescendents2", string.Empty); | 120 | m_fetchInventoryDescendents2Url = config.GetString("Cap_FetchInventoryDescendents2", string.Empty); |
120 | m_webFetchInventoryDescendentsUrl = config.GetString("Cap_WebFetchInventoryDescendents", string.Empty); | 121 | // m_webFetchInventoryDescendentsUrl = config.GetString("Cap_WebFetchInventoryDescendents", string.Empty); |
121 | 122 | ||
122 | if (m_fetchInventoryDescendents2Url != string.Empty || m_webFetchInventoryDescendentsUrl != string.Empty) | 123 | // if (m_fetchInventoryDescendents2Url != string.Empty || m_webFetchInventoryDescendentsUrl != string.Empty) |
124 | if (m_fetchInventoryDescendents2Url != string.Empty) | ||
123 | { | 125 | { |
124 | m_Enabled = true; | 126 | m_Enabled = true; |
125 | } | 127 | } |
@@ -312,7 +314,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
312 | { | 314 | { |
313 | if (!reqinfo.folders.Contains(folderID)) | 315 | if (!reqinfo.folders.Contains(folderID)) |
314 | { | 316 | { |
315 | //TODO: Port COF handling from Avination | 317 | if (sp.COF != UUID.Zero && sp.COF == folderID) |
318 | highPriority = true; | ||
316 | reqinfo.folders.Add(folderID); | 319 | reqinfo.folders.Add(folderID); |
317 | } | 320 | } |
318 | } | 321 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs b/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs index 4d0568d..15d6f7f 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/J2KImage.cs | |||
@@ -234,6 +234,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
234 | m_stopPacket = TexturePacketCount(); | 234 | m_stopPacket = TexturePacketCount(); |
235 | } | 235 | } |
236 | 236 | ||
237 | //Give them at least two packets, to play nice with some broken viewers (SL also behaves this way) | ||
238 | if (m_stopPacket == 1 && m_layers[0].End > FIRST_PACKET_SIZE) m_stopPacket++; | ||
239 | |||
237 | m_currentPacket = StartPacket; | 240 | m_currentPacket = StartPacket; |
238 | } | 241 | } |
239 | } | 242 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index e7dd9d3..62206e9 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | |||
@@ -100,6 +100,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
100 | public event AvatarPickerRequest OnAvatarPickerRequest; | 100 | public event AvatarPickerRequest OnAvatarPickerRequest; |
101 | public event StartAnim OnStartAnim; | 101 | public event StartAnim OnStartAnim; |
102 | public event StopAnim OnStopAnim; | 102 | public event StopAnim OnStopAnim; |
103 | public event ChangeAnim OnChangeAnim; | ||
103 | public event Action<IClientAPI> OnRequestAvatarsData; | 104 | public event Action<IClientAPI> OnRequestAvatarsData; |
104 | public event LinkObjects OnLinkObjects; | 105 | public event LinkObjects OnLinkObjects; |
105 | public event DelinkObjects OnDelinkObjects; | 106 | public event DelinkObjects OnDelinkObjects; |
@@ -127,6 +128,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
127 | public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily; | 128 | public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily; |
128 | public event UpdatePrimFlags OnUpdatePrimFlags; | 129 | public event UpdatePrimFlags OnUpdatePrimFlags; |
129 | public event UpdatePrimTexture OnUpdatePrimTexture; | 130 | public event UpdatePrimTexture OnUpdatePrimTexture; |
131 | public event ClientChangeObject onClientChangeObject; | ||
130 | public event UpdateVector OnUpdatePrimGroupPosition; | 132 | public event UpdateVector OnUpdatePrimGroupPosition; |
131 | public event UpdateVector OnUpdatePrimSinglePosition; | 133 | public event UpdateVector OnUpdatePrimSinglePosition; |
132 | public event UpdatePrimRotation OnUpdatePrimGroupRotation; | 134 | public event UpdatePrimRotation OnUpdatePrimGroupRotation; |
@@ -156,6 +158,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
156 | public event RequestTaskInventory OnRequestTaskInventory; | 158 | public event RequestTaskInventory OnRequestTaskInventory; |
157 | public event UpdateInventoryItem OnUpdateInventoryItem; | 159 | public event UpdateInventoryItem OnUpdateInventoryItem; |
158 | public event CopyInventoryItem OnCopyInventoryItem; | 160 | public event CopyInventoryItem OnCopyInventoryItem; |
161 | public event MoveItemsAndLeaveCopy OnMoveItemsAndLeaveCopy; | ||
159 | public event MoveInventoryItem OnMoveInventoryItem; | 162 | public event MoveInventoryItem OnMoveInventoryItem; |
160 | public event RemoveInventoryItem OnRemoveInventoryItem; | 163 | public event RemoveInventoryItem OnRemoveInventoryItem; |
161 | public event RemoveInventoryFolder OnRemoveInventoryFolder; | 164 | public event RemoveInventoryFolder OnRemoveInventoryFolder; |
@@ -250,7 +253,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
250 | public event ClassifiedInfoRequest OnClassifiedInfoRequest; | 253 | public event ClassifiedInfoRequest OnClassifiedInfoRequest; |
251 | public event ClassifiedInfoUpdate OnClassifiedInfoUpdate; | 254 | public event ClassifiedInfoUpdate OnClassifiedInfoUpdate; |
252 | public event ClassifiedDelete OnClassifiedDelete; | 255 | public event ClassifiedDelete OnClassifiedDelete; |
253 | public event ClassifiedDelete OnClassifiedGodDelete; | 256 | public event ClassifiedGodDelete OnClassifiedGodDelete; |
254 | public event EventNotificationAddRequest OnEventNotificationAddRequest; | 257 | public event EventNotificationAddRequest OnEventNotificationAddRequest; |
255 | public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest; | 258 | public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest; |
256 | public event EventGodDelete OnEventGodDelete; | 259 | public event EventGodDelete OnEventGodDelete; |
@@ -281,10 +284,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
281 | public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest; | 284 | public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest; |
282 | public event SimWideDeletesDelegate OnSimWideDeletes; | 285 | public event SimWideDeletesDelegate OnSimWideDeletes; |
283 | public event SendPostcard OnSendPostcard; | 286 | public event SendPostcard OnSendPostcard; |
287 | public event ChangeInventoryItemFlags OnChangeInventoryItemFlags; | ||
284 | public event MuteListEntryUpdate OnUpdateMuteListEntry; | 288 | public event MuteListEntryUpdate OnUpdateMuteListEntry; |
285 | public event MuteListEntryRemove OnRemoveMuteListEntry; | 289 | public event MuteListEntryRemove OnRemoveMuteListEntry; |
286 | public event GodlikeMessage onGodlikeMessage; | 290 | public event GodlikeMessage onGodlikeMessage; |
287 | public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; | 291 | public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; |
292 | public event GenericCall2 OnUpdateThrottles; | ||
288 | 293 | ||
289 | #pragma warning disable 0067 | 294 | #pragma warning disable 0067 |
290 | public event GenericMessage OnGenericMessage; | 295 | public event GenericMessage OnGenericMessage; |
@@ -333,7 +338,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
333 | private PriorityQueue m_entityProps; | 338 | private PriorityQueue m_entityProps; |
334 | private Prioritizer m_prioritizer; | 339 | private Prioritizer m_prioritizer; |
335 | private bool m_disableFacelights = false; | 340 | private bool m_disableFacelights = false; |
336 | private volatile bool m_justEditedTerrain = false; | 341 | |
342 | private bool m_VelocityInterpolate = false; | ||
343 | private const uint MaxTransferBytesPerPacket = 600; | ||
344 | |||
337 | /// <value> | 345 | /// <value> |
338 | /// List used in construction of data blocks for an object update packet. This is to stop us having to | 346 | /// List used in construction of data blocks for an object update packet. This is to stop us having to |
339 | /// continually recreate it. | 347 | /// continually recreate it. |
@@ -345,14 +353,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
345 | /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an | 353 | /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an |
346 | /// ownerless phantom. | 354 | /// ownerless phantom. |
347 | /// | 355 | /// |
348 | /// All manipulation of this set has to occur under a lock | 356 | /// All manipulation of this set has to occur under an m_entityUpdates.SyncRoot lock |
349 | /// | 357 | /// |
350 | /// </value> | 358 | /// </value> |
351 | protected HashSet<uint> m_killRecord; | 359 | // protected HashSet<uint> m_killRecord; |
352 | 360 | ||
353 | // protected HashSet<uint> m_attachmentsSent; | 361 | // protected HashSet<uint> m_attachmentsSent; |
354 | 362 | ||
355 | private int m_animationSequenceNumber = 1; | 363 | private bool m_deliverPackets = true; |
364 | |||
356 | private bool m_SendLogoutPacketWhenClosing = true; | 365 | private bool m_SendLogoutPacketWhenClosing = true; |
357 | 366 | ||
358 | /// <summary> | 367 | /// <summary> |
@@ -398,6 +407,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
398 | get { return m_startpos; } | 407 | get { return m_startpos; } |
399 | set { m_startpos = value; } | 408 | set { m_startpos = value; } |
400 | } | 409 | } |
410 | public bool DeliverPackets | ||
411 | { | ||
412 | get { return m_deliverPackets; } | ||
413 | set { | ||
414 | m_deliverPackets = value; | ||
415 | m_udpClient.m_deliverPackets = value; | ||
416 | } | ||
417 | } | ||
401 | public UUID AgentId { get { return m_agentId; } } | 418 | public UUID AgentId { get { return m_agentId; } } |
402 | public ISceneAgent SceneAgent { get; set; } | 419 | public ISceneAgent SceneAgent { get; set; } |
403 | public UUID ActiveGroupId { get { return m_activeGroupID; } private set { m_activeGroupID = value; } } | 420 | public UUID ActiveGroupId { get { return m_activeGroupID; } private set { m_activeGroupID = value; } } |
@@ -405,6 +422,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
405 | public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } private set { m_activeGroupPowers = value; } } | 422 | public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } private set { m_activeGroupPowers = value; } } |
406 | public bool IsGroupMember(UUID groupID) { return m_groupPowers.ContainsKey(groupID); } | 423 | public bool IsGroupMember(UUID groupID) { return m_groupPowers.ContainsKey(groupID); } |
407 | 424 | ||
425 | public int PingTimeMS | ||
426 | { | ||
427 | get | ||
428 | { | ||
429 | if (UDPClient != null) | ||
430 | return UDPClient.PingTimeMS; | ||
431 | return 0; | ||
432 | } | ||
433 | } | ||
434 | |||
408 | /// <summary> | 435 | /// <summary> |
409 | /// Entity update queues | 436 | /// Entity update queues |
410 | /// </summary> | 437 | /// </summary> |
@@ -426,7 +453,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
426 | public string Name { get { return FirstName + " " + LastName; } } | 453 | public string Name { get { return FirstName + " " + LastName; } } |
427 | 454 | ||
428 | public uint CircuitCode { get { return m_circuitCode; } } | 455 | public uint CircuitCode { get { return m_circuitCode; } } |
429 | public int NextAnimationSequenceNumber { get { return m_animationSequenceNumber++; } } | 456 | public int NextAnimationSequenceNumber |
457 | { | ||
458 | get { return m_udpServer.NextAnimationSequenceNumber; } | ||
459 | } | ||
430 | 460 | ||
431 | /// <summary> | 461 | /// <summary> |
432 | /// As well as it's function in IClientAPI, in LLClientView we are locking on this property in order to | 462 | /// As well as it's function in IClientAPI, in LLClientView we are locking on this property in order to |
@@ -447,7 +477,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
447 | set { m_disableFacelights = value; } | 477 | set { m_disableFacelights = value; } |
448 | } | 478 | } |
449 | 479 | ||
480 | public List<uint> SelectedObjects {get; private set;} | ||
481 | |||
450 | public bool SendLogoutPacketWhenClosing { set { m_SendLogoutPacketWhenClosing = value; } } | 482 | public bool SendLogoutPacketWhenClosing { set { m_SendLogoutPacketWhenClosing = value; } } |
483 | |||
451 | 484 | ||
452 | #endregion Properties | 485 | #endregion Properties |
453 | 486 | ||
@@ -465,6 +498,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
465 | // DebugPacketLevel = 1; | 498 | // DebugPacketLevel = 1; |
466 | 499 | ||
467 | CloseSyncLock = new Object(); | 500 | CloseSyncLock = new Object(); |
501 | SelectedObjects = new List<uint>(); | ||
468 | 502 | ||
469 | RegisterInterface<IClientIM>(this); | 503 | RegisterInterface<IClientIM>(this); |
470 | RegisterInterface<IClientInventory>(this); | 504 | RegisterInterface<IClientInventory>(this); |
@@ -474,7 +508,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
474 | m_entityUpdates = new PriorityQueue(m_scene.Entities.Count); | 508 | m_entityUpdates = new PriorityQueue(m_scene.Entities.Count); |
475 | m_entityProps = new PriorityQueue(m_scene.Entities.Count); | 509 | m_entityProps = new PriorityQueue(m_scene.Entities.Count); |
476 | m_fullUpdateDataBlocksBuilder = new List<ObjectUpdatePacket.ObjectDataBlock>(); | 510 | m_fullUpdateDataBlocksBuilder = new List<ObjectUpdatePacket.ObjectDataBlock>(); |
477 | m_killRecord = new HashSet<uint>(); | 511 | // m_killRecord = new HashSet<uint>(); |
478 | // m_attachmentsSent = new HashSet<uint>(); | 512 | // m_attachmentsSent = new HashSet<uint>(); |
479 | 513 | ||
480 | m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | 514 | m_assetService = m_scene.RequestModuleInterface<IAssetService>(); |
@@ -504,12 +538,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
504 | 538 | ||
505 | #region Client Methods | 539 | #region Client Methods |
506 | 540 | ||
541 | |||
542 | /// <summary> | ||
543 | /// Close down the client view | ||
544 | /// </summary> | ||
507 | public void Close() | 545 | public void Close() |
508 | { | 546 | { |
509 | Close(false); | 547 | Close(true, false); |
510 | } | 548 | } |
511 | 549 | ||
512 | public void Close(bool force) | 550 | public void Close(bool sendStop, bool force) |
513 | { | 551 | { |
514 | // We lock here to prevent race conditions between two threads calling close simultaneously (e.g. | 552 | // We lock here to prevent race conditions between two threads calling close simultaneously (e.g. |
515 | // a simultaneous relog just as a client is being closed out due to no packet ack from the old connection. | 553 | // a simultaneous relog just as a client is being closed out due to no packet ack from the old connection. |
@@ -526,7 +564,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
526 | } | 564 | } |
527 | 565 | ||
528 | IsActive = false; | 566 | IsActive = false; |
529 | CloseWithoutChecks(); | 567 | CloseWithoutChecks(sendStop); |
530 | } | 568 | } |
531 | } | 569 | } |
532 | 570 | ||
@@ -539,12 +577,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
539 | /// | 577 | /// |
540 | /// Callers must lock ClosingSyncLock before calling. | 578 | /// Callers must lock ClosingSyncLock before calling. |
541 | /// </remarks> | 579 | /// </remarks> |
542 | public void CloseWithoutChecks() | 580 | public void CloseWithoutChecks(bool sendStop) |
543 | { | 581 | { |
544 | m_log.DebugFormat( | 582 | m_log.DebugFormat( |
545 | "[CLIENT]: Close has been called for {0} attached to scene {1}", | 583 | "[CLIENT]: Close has been called for {0} attached to scene {1}", |
546 | Name, m_scene.RegionInfo.RegionName); | 584 | Name, m_scene.RegionInfo.RegionName); |
547 | 585 | ||
586 | if (sendStop) | ||
587 | { | ||
588 | // Send the STOP packet | ||
589 | DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator); | ||
590 | OutPacket(disable, ThrottleOutPacketType.Unknown); | ||
591 | } | ||
592 | |||
548 | // Shutdown the image manager | 593 | // Shutdown the image manager |
549 | ImageManager.Close(); | 594 | ImageManager.Close(); |
550 | 595 | ||
@@ -566,7 +611,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
566 | 611 | ||
567 | // Disable UDP handling for this client | 612 | // Disable UDP handling for this client |
568 | m_udpClient.Shutdown(); | 613 | m_udpClient.Shutdown(); |
569 | 614 | ||
615 | |||
570 | //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false)); | 616 | //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false)); |
571 | //GC.Collect(); | 617 | //GC.Collect(); |
572 | //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true)); | 618 | //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true)); |
@@ -858,6 +904,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
858 | 904 | ||
859 | public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look) | 905 | public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look) |
860 | { | 906 | { |
907 | m_thisAgentUpdateArgs.CameraAtAxis.X = float.MinValue; | ||
908 | m_thisAgentUpdateArgs.ControlFlags = uint.MaxValue; | ||
909 | |||
861 | AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete); | 910 | AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete); |
862 | mov.SimData.ChannelVersion = m_channelVersion; | 911 | mov.SimData.ChannelVersion = m_channelVersion; |
863 | mov.AgentData.SessionID = m_sessionId; | 912 | mov.AgentData.SessionID = m_sessionId; |
@@ -893,7 +942,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
893 | reply.ChatData.OwnerID = ownerID; | 942 | reply.ChatData.OwnerID = ownerID; |
894 | reply.ChatData.SourceID = fromAgentID; | 943 | reply.ChatData.SourceID = fromAgentID; |
895 | 944 | ||
896 | OutPacket(reply, ThrottleOutPacketType.Task); | 945 | OutPacket(reply, ThrottleOutPacketType.Unknown); |
897 | } | 946 | } |
898 | 947 | ||
899 | /// <summary> | 948 | /// <summary> |
@@ -926,32 +975,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
926 | msg.MessageBlock.Message = Util.StringToBytes1024(im.message); | 975 | msg.MessageBlock.Message = Util.StringToBytes1024(im.message); |
927 | msg.MessageBlock.BinaryBucket = im.binaryBucket; | 976 | msg.MessageBlock.BinaryBucket = im.binaryBucket; |
928 | 977 | ||
929 | if (im.message.StartsWith("[grouptest]")) | 978 | OutPacket(msg, ThrottleOutPacketType.Task); |
930 | { // this block is test code for implementing group IM - delete when group IM is finished | ||
931 | IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>(); | ||
932 | if (eq != null) | ||
933 | { | ||
934 | im.dialog = 17; | ||
935 | |||
936 | //eq.ChatterboxInvitation( | ||
937 | // new UUID("00000000-68f9-1111-024e-222222111123"), | ||
938 | // "OpenSimulator Testing", im.fromAgentID, im.message, im.toAgentID, im.fromAgentName, im.dialog, 0, | ||
939 | // false, 0, new Vector3(), 1, im.imSessionID, im.fromGroup, im.binaryBucket); | ||
940 | |||
941 | eq.ChatterboxInvitation( | ||
942 | new UUID("00000000-68f9-1111-024e-222222111123"), | ||
943 | "OpenSimulator Testing", new UUID(im.fromAgentID), im.message, new UUID(im.toAgentID), im.fromAgentName, im.dialog, 0, | ||
944 | false, 0, new Vector3(), 1, new UUID(im.imSessionID), im.fromGroup, Util.StringToBytes256("OpenSimulator Testing")); | ||
945 | |||
946 | eq.ChatterBoxSessionAgentListUpdates( | ||
947 | new UUID("00000000-68f9-1111-024e-222222111123"), | ||
948 | new UUID(im.fromAgentID), new UUID(im.toAgentID), false, false, false); | ||
949 | } | ||
950 | |||
951 | Console.WriteLine("SendInstantMessage: " + msg); | ||
952 | } | ||
953 | else | ||
954 | OutPacket(msg, ThrottleOutPacketType.Task); | ||
955 | } | 979 | } |
956 | } | 980 | } |
957 | 981 | ||
@@ -1182,6 +1206,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1182 | OutPacket(GATRP, ThrottleOutPacketType.Task); | 1206 | OutPacket(GATRP, ThrottleOutPacketType.Task); |
1183 | } | 1207 | } |
1184 | 1208 | ||
1209 | |||
1210 | public virtual bool CanSendLayerData() | ||
1211 | { | ||
1212 | int n = m_udpClient.GetPacketsQueuedCount(ThrottleOutPacketType.Land); | ||
1213 | if ( n > 128) | ||
1214 | return false; | ||
1215 | return true; | ||
1216 | } | ||
1217 | |||
1185 | /// <summary> | 1218 | /// <summary> |
1186 | /// Send the region heightmap to the client | 1219 | /// Send the region heightmap to the client |
1187 | /// This method is only called when not doing intellegent terrain patch sending and | 1220 | /// This method is only called when not doing intellegent terrain patch sending and |
@@ -1192,6 +1225,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1192 | public virtual void SendLayerData(float[] map) | 1225 | public virtual void SendLayerData(float[] map) |
1193 | { | 1226 | { |
1194 | Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData(), "LLClientView.DoSendLayerData"); | 1227 | Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData(), "LLClientView.DoSendLayerData"); |
1228 | |||
1229 | // Send it sync, and async. It's not that much data | ||
1230 | // and it improves user experience just so much! | ||
1231 | // DoSendLayerData(map); | ||
1195 | } | 1232 | } |
1196 | 1233 | ||
1197 | /// <summary> | 1234 | /// <summary> |
@@ -1214,7 +1251,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1214 | //} | 1251 | //} |
1215 | 1252 | ||
1216 | // Send LayerData in a spiral pattern. Fun! | 1253 | // Send LayerData in a spiral pattern. Fun! |
1217 | SendLayerTopRight(map, 0, 0, map.SizeX/Constants.TerrainPatchSize-1, map.SizeY/Constants.TerrainPatchSize-1); | 1254 | SendLayerTopRight(map, 0, 0, map.SizeX / Constants.TerrainPatchSize - 1, map.SizeY / Constants.TerrainPatchSize - 1); |
1218 | } | 1255 | } |
1219 | catch (Exception e) | 1256 | catch (Exception e) |
1220 | { | 1257 | { |
@@ -1250,23 +1287,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1250 | SendLayerTopRight(map, x1 + 1, y1, x2, y2 - 1); | 1287 | SendLayerTopRight(map, x1 + 1, y1, x2, y2 - 1); |
1251 | } | 1288 | } |
1252 | 1289 | ||
1253 | /// <summary> | ||
1254 | /// Sends a set of four patches (x, x+1, ..., x+3) to the client | ||
1255 | /// </summary> | ||
1256 | /// <param name="map">heightmap</param> | ||
1257 | /// <param name="px">X coordinate for patches 0..12</param> | ||
1258 | /// <param name="py">Y coordinate for patches 0..15</param> | ||
1259 | // private void SendLayerPacket(float[] map, int y, int x) | ||
1260 | // { | ||
1261 | // int[] patches = new int[4]; | ||
1262 | // patches[0] = x + 0 + y * 16; | ||
1263 | // patches[1] = x + 1 + y * 16; | ||
1264 | // patches[2] = x + 2 + y * 16; | ||
1265 | // patches[3] = x + 3 + y * 16; | ||
1266 | |||
1267 | // Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches); | ||
1268 | // OutPacket(layerpack, ThrottleOutPacketType.Land); | ||
1269 | // } | ||
1270 | 1290 | ||
1271 | // Legacy form of invocation that passes around a bare data array. | 1291 | // Legacy form of invocation that passes around a bare data array. |
1272 | // Just ignore what was passed and use the real terrain info that is part of the scene. | 1292 | // Just ignore what was passed and use the real terrain info that is part of the scene. |
@@ -1316,6 +1336,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1316 | } | 1336 | } |
1317 | 1337 | ||
1318 | /// <summary> | 1338 | /// <summary> |
1339 | |||
1319 | /// Sends a terrain packet for the point specified. | 1340 | /// Sends a terrain packet for the point specified. |
1320 | /// This is a legacy call that has refarbed the terrain into a flat map of floats. | 1341 | /// This is a legacy call that has refarbed the terrain into a flat map of floats. |
1321 | /// We just use the terrain from the region we know about. | 1342 | /// We just use the terrain from the region we know about. |
@@ -1334,32 +1355,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1334 | { | 1355 | { |
1335 | try | 1356 | try |
1336 | { | 1357 | { |
1337 | /* test code using the terrain compressor in libOpenMetaverse | 1358 | byte landPacketType; |
1338 | int[] patchInd = new int[1]; | 1359 | if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize) |
1339 | patchInd[0] = px + (py * Constants.TerrainPatchSize); | 1360 | landPacketType = (byte)TerrainPatch.LayerType.LandExtended; |
1340 | LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(terrData.GetFloatsSerialized(), patchInd); | 1361 | else |
1341 | */ | 1362 | landPacketType = (byte)TerrainPatch.LayerType.Land; |
1342 | // Many, many patches could have been passed to us. Since the patches will be compressed | ||
1343 | // into variable sized blocks, we cannot pre-compute how many will fit into one | ||
1344 | // packet. While some fancy packing algorithm is possible, 4 seems to always fit. | ||
1345 | int PatchesAssumedToFit = 4; | ||
1346 | for (int pcnt = 0; pcnt < px.Length; pcnt += PatchesAssumedToFit) | ||
1347 | { | ||
1348 | int remaining = Math.Min(px.Length - pcnt, PatchesAssumedToFit); | ||
1349 | int[] xPatches = new int[remaining]; | ||
1350 | int[] yPatches = new int[remaining]; | ||
1351 | for (int ii = 0; ii < remaining; ii++) | ||
1352 | { | ||
1353 | xPatches[ii] = px[pcnt + ii]; | ||
1354 | yPatches[ii] = py[pcnt + ii]; | ||
1355 | } | ||
1356 | LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLandPacket(terrData, xPatches, yPatches); | ||
1357 | // DebugSendingPatches("SendLayerDataInternal", xPatches, yPatches); | ||
1358 | |||
1359 | SendTheLayerPacket(layerpack); | ||
1360 | } | ||
1361 | // LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLandPacket(terrData, px, py); | ||
1362 | 1363 | ||
1364 | List<LayerDataPacket> packets = OpenSimTerrainCompressor.CreateLayerDataPackets(terrData, px, py, landPacketType); | ||
1365 | foreach(LayerDataPacket pkt in packets) | ||
1366 | OutPacket(pkt, ThrottleOutPacketType.Land); | ||
1363 | } | 1367 | } |
1364 | catch (Exception e) | 1368 | catch (Exception e) |
1365 | { | 1369 | { |
@@ -1367,36 +1371,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1367 | } | 1371 | } |
1368 | } | 1372 | } |
1369 | 1373 | ||
1370 | // When a user edits the terrain, so much data is sent, the data queues up fast and presents a | ||
1371 | // sub optimal editing experience. To alleviate this issue, when the user edits the terrain, we | ||
1372 | // start skipping the queues until they're done editing the terrain. We also make them | ||
1373 | // unreliable because it's extremely likely that multiple packets will be sent for a terrain patch | ||
1374 | // area invalidating previous packets for that area. | ||
1375 | |||
1376 | // It's possible for an editing user to flood themselves with edited packets but the majority | ||
1377 | // of use cases are such that only a tiny percentage of users will be editing the terrain. | ||
1378 | // Other, non-editing users will see the edits much slower. | ||
1379 | |||
1380 | // One last note on this topic, by the time users are going to be editing the terrain, it's | ||
1381 | // extremely likely that the sim will have rezzed already and therefore this is not likely going | ||
1382 | // to cause any additional issues with lost packets, objects or terrain patches. | ||
1383 | |||
1384 | // m_justEditedTerrain is volatile, so test once and duplicate two affected statements so we | ||
1385 | // only have one cache miss. | ||
1386 | private void SendTheLayerPacket(LayerDataPacket layerpack) | ||
1387 | { | ||
1388 | if (m_justEditedTerrain) | ||
1389 | { | ||
1390 | layerpack.Header.Reliable = false; | ||
1391 | OutPacket(layerpack, ThrottleOutPacketType.Unknown ); | ||
1392 | } | ||
1393 | else | ||
1394 | { | ||
1395 | layerpack.Header.Reliable = true; | ||
1396 | OutPacket(layerpack, ThrottleOutPacketType.Land); | ||
1397 | } | ||
1398 | } | ||
1399 | |||
1400 | /// <summary> | 1374 | /// <summary> |
1401 | /// Send the wind matrix to the client | 1375 | /// Send the wind matrix to the client |
1402 | /// </summary> | 1376 | /// </summary> |
@@ -1432,13 +1406,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1432 | patches[1].Data[x] = windSpeeds[x].Y; | 1406 | patches[1].Data[x] = windSpeeds[x].Y; |
1433 | } | 1407 | } |
1434 | 1408 | ||
1409 | // neither we or viewers have extended wind | ||
1435 | byte layerType = (byte)TerrainPatch.LayerType.Wind; | 1410 | byte layerType = (byte)TerrainPatch.LayerType.Wind; |
1436 | if (m_scene.RegionInfo.RegionSizeX > Constants.RegionSize || m_scene.RegionInfo.RegionSizeY > Constants.RegionSize) | ||
1437 | layerType = (byte)TerrainPatch.LayerType.WindExtended; | ||
1438 | 1411 | ||
1439 | // LayerDataPacket layerpack = TerrainCompressor.CreateLayerDataPacket(patches, (TerrainPatch.LayerType)layerType); | 1412 | LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(patches, layerType); |
1440 | LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLayerDataPacket(patches, layerType, | ||
1441 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY); | ||
1442 | layerpack.Header.Zerocoded = true; | 1413 | layerpack.Header.Zerocoded = true; |
1443 | OutPacket(layerpack, ThrottleOutPacketType.Wind); | 1414 | OutPacket(layerpack, ThrottleOutPacketType.Wind); |
1444 | } | 1415 | } |
@@ -1461,14 +1432,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1461 | patches[0].Data[y * 16 + x] = cloudCover[y * 16 + x]; | 1432 | patches[0].Data[y * 16 + x] = cloudCover[y * 16 + x]; |
1462 | } | 1433 | } |
1463 | } | 1434 | } |
1464 | 1435 | // neither we or viewers have extended clouds | |
1465 | byte layerType = (byte)TerrainPatch.LayerType.Cloud; | 1436 | byte layerType = (byte)TerrainPatch.LayerType.Cloud; |
1466 | if (m_scene.RegionInfo.RegionSizeX > Constants.RegionSize || m_scene.RegionInfo.RegionSizeY > Constants.RegionSize) | ||
1467 | layerType = (byte)TerrainPatch.LayerType.CloudExtended; | ||
1468 | 1437 | ||
1469 | // LayerDataPacket layerpack = TerrainCompressor.CreateLayerDataPacket(patches, (TerrainPatch.LayerType)layerType); | 1438 | LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLayerDataPacketStandardSize(patches, layerType); |
1470 | LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLayerDataPacket(patches, layerType, | ||
1471 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY); | ||
1472 | layerpack.Header.Zerocoded = true; | 1439 | layerpack.Header.Zerocoded = true; |
1473 | OutPacket(layerpack, ThrottleOutPacketType.Cloud); | 1440 | OutPacket(layerpack, ThrottleOutPacketType.Cloud); |
1474 | } | 1441 | } |
@@ -1735,11 +1702,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1735 | pc.PingID.OldestUnacked = 0; | 1702 | pc.PingID.OldestUnacked = 0; |
1736 | 1703 | ||
1737 | OutPacket(pc, ThrottleOutPacketType.Unknown); | 1704 | OutPacket(pc, ThrottleOutPacketType.Unknown); |
1705 | UDPClient.m_lastStartpingTimeMS = Util.EnvironmentTickCount(); | ||
1738 | } | 1706 | } |
1739 | 1707 | ||
1740 | public void SendKillObject(List<uint> localIDs) | 1708 | public void SendKillObject(List<uint> localIDs) |
1741 | { | 1709 | { |
1742 | // m_log.DebugFormat("[CLIENT]: Sending KillObjectPacket to {0} for {1} in {2}", Name, localID, regionHandle); | 1710 | // think we do need this |
1711 | // foreach (uint id in localIDs) | ||
1712 | // m_log.DebugFormat("[CLIENT]: Sending KillObjectPacket to {0} for {1} in {2}", Name, id, regionHandle); | ||
1713 | |||
1714 | // remove pending entities | ||
1715 | lock (m_entityProps.SyncRoot) | ||
1716 | m_entityProps.Remove(localIDs); | ||
1717 | lock (m_entityUpdates.SyncRoot) | ||
1718 | m_entityUpdates.Remove(localIDs); | ||
1743 | 1719 | ||
1744 | KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject); | 1720 | KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject); |
1745 | // TODO: don't create new blocks if recycling an old packet | 1721 | // TODO: don't create new blocks if recycling an old packet |
@@ -1752,28 +1728,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1752 | kill.Header.Reliable = true; | 1728 | kill.Header.Reliable = true; |
1753 | kill.Header.Zerocoded = true; | 1729 | kill.Header.Zerocoded = true; |
1754 | 1730 | ||
1755 | if (localIDs.Count == 1 && m_scene.GetScenePresence(localIDs[0]) != null) | 1731 | OutPacket(kill, ThrottleOutPacketType.Task); |
1756 | { | 1732 | } |
1757 | OutPacket(kill, ThrottleOutPacketType.Task); | ||
1758 | } | ||
1759 | else | ||
1760 | { | ||
1761 | // We MUST lock for both manipulating the kill record and sending the packet, in order to avoid a race | ||
1762 | // condition where a kill can be processed before an out-of-date update for the same object. | ||
1763 | // ProcessEntityUpdates() also takes the m_killRecord lock. | ||
1764 | lock (m_killRecord) | ||
1765 | { | ||
1766 | foreach (uint localID in localIDs) | ||
1767 | m_killRecord.Add(localID); | ||
1768 | |||
1769 | // The throttle queue used here must match that being used for updates. Otherwise, there is a | ||
1770 | // chance that a kill packet put on a separate queue will be sent to the client before an existing | ||
1771 | // update packet on another queue. Receiving updates after kills results in unowned and undeletable | ||
1772 | // scene objects in a viewer until that viewer is relogged in. | ||
1773 | OutPacket(kill, ThrottleOutPacketType.Task); | ||
1774 | } | ||
1775 | } | ||
1776 | } | ||
1777 | 1733 | ||
1778 | /// <summary> | 1734 | /// <summary> |
1779 | /// Send information about the items contained in a folder to the client. | 1735 | /// Send information about the items contained in a folder to the client. |
@@ -1895,7 +1851,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1895 | newBlock.CreationDate = item.CreationDate; | 1851 | newBlock.CreationDate = item.CreationDate; |
1896 | newBlock.SalePrice = item.SalePrice; | 1852 | newBlock.SalePrice = item.SalePrice; |
1897 | newBlock.SaleType = item.SaleType; | 1853 | newBlock.SaleType = item.SaleType; |
1898 | newBlock.Flags = item.Flags; | 1854 | newBlock.Flags = item.Flags & 0x2000ff; |
1899 | 1855 | ||
1900 | newBlock.CRC = | 1856 | newBlock.CRC = |
1901 | Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType, | 1857 | Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType, |
@@ -2151,7 +2107,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2151 | itemBlock.GroupID = item.GroupID; | 2107 | itemBlock.GroupID = item.GroupID; |
2152 | itemBlock.GroupOwned = item.GroupOwned; | 2108 | itemBlock.GroupOwned = item.GroupOwned; |
2153 | itemBlock.GroupMask = item.GroupPermissions; | 2109 | itemBlock.GroupMask = item.GroupPermissions; |
2154 | itemBlock.Flags = item.Flags; | 2110 | itemBlock.Flags = item.Flags & 0x2000ff; |
2155 | itemBlock.SalePrice = item.SalePrice; | 2111 | itemBlock.SalePrice = item.SalePrice; |
2156 | itemBlock.SaleType = item.SaleType; | 2112 | itemBlock.SaleType = item.SaleType; |
2157 | itemBlock.CreationDate = item.CreationDate; | 2113 | itemBlock.CreationDate = item.CreationDate; |
@@ -2218,7 +2174,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2218 | bulkUpdate.ItemData[0].GroupID = item.GroupID; | 2174 | bulkUpdate.ItemData[0].GroupID = item.GroupID; |
2219 | bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned; | 2175 | bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned; |
2220 | bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions; | 2176 | bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions; |
2221 | bulkUpdate.ItemData[0].Flags = item.Flags; | 2177 | bulkUpdate.ItemData[0].Flags = item.Flags & 0x2000ff; |
2222 | bulkUpdate.ItemData[0].SalePrice = item.SalePrice; | 2178 | bulkUpdate.ItemData[0].SalePrice = item.SalePrice; |
2223 | bulkUpdate.ItemData[0].SaleType = item.SaleType; | 2179 | bulkUpdate.ItemData[0].SaleType = item.SaleType; |
2224 | 2180 | ||
@@ -2234,9 +2190,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2234 | OutPacket(bulkUpdate, ThrottleOutPacketType.Asset); | 2190 | OutPacket(bulkUpdate, ThrottleOutPacketType.Asset); |
2235 | } | 2191 | } |
2236 | 2192 | ||
2237 | /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see> | ||
2238 | public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId) | 2193 | public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId) |
2239 | { | 2194 | { |
2195 | SendInventoryItemCreateUpdate(Item, UUID.Zero, callbackId); | ||
2196 | } | ||
2197 | |||
2198 | /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see> | ||
2199 | public void SendInventoryItemCreateUpdate(InventoryItemBase Item, UUID transactionID, uint callbackId) | ||
2200 | { | ||
2240 | const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff; | 2201 | const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff; |
2241 | 2202 | ||
2242 | UpdateCreateInventoryItemPacket InventoryReply | 2203 | UpdateCreateInventoryItemPacket InventoryReply |
@@ -2246,6 +2207,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2246 | // TODO: don't create new blocks if recycling an old packet | 2207 | // TODO: don't create new blocks if recycling an old packet |
2247 | InventoryReply.AgentData.AgentID = AgentId; | 2208 | InventoryReply.AgentData.AgentID = AgentId; |
2248 | InventoryReply.AgentData.SimApproved = true; | 2209 | InventoryReply.AgentData.SimApproved = true; |
2210 | InventoryReply.AgentData.TransactionID = transactionID; | ||
2249 | InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1]; | 2211 | InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1]; |
2250 | InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock(); | 2212 | InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock(); |
2251 | InventoryReply.InventoryData[0].ItemID = Item.ID; | 2213 | InventoryReply.InventoryData[0].ItemID = Item.ID; |
@@ -2266,7 +2228,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2266 | InventoryReply.InventoryData[0].GroupID = Item.GroupID; | 2228 | InventoryReply.InventoryData[0].GroupID = Item.GroupID; |
2267 | InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned; | 2229 | InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned; |
2268 | InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions; | 2230 | InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions; |
2269 | InventoryReply.InventoryData[0].Flags = Item.Flags; | 2231 | InventoryReply.InventoryData[0].Flags = Item.Flags & 0x2000ff; |
2270 | InventoryReply.InventoryData[0].SalePrice = Item.SalePrice; | 2232 | InventoryReply.InventoryData[0].SalePrice = Item.SalePrice; |
2271 | InventoryReply.InventoryData[0].SaleType = Item.SaleType; | 2233 | InventoryReply.InventoryData[0].SaleType = Item.SaleType; |
2272 | InventoryReply.InventoryData[0].CreationDate = Item.CreationDate; | 2234 | InventoryReply.InventoryData[0].CreationDate = Item.CreationDate; |
@@ -2315,16 +2277,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2315 | replytask.InventoryData.TaskID = taskID; | 2277 | replytask.InventoryData.TaskID = taskID; |
2316 | replytask.InventoryData.Serial = serial; | 2278 | replytask.InventoryData.Serial = serial; |
2317 | replytask.InventoryData.Filename = fileName; | 2279 | replytask.InventoryData.Filename = fileName; |
2318 | OutPacket(replytask, ThrottleOutPacketType.Asset); | 2280 | OutPacket(replytask, ThrottleOutPacketType.Task); |
2319 | } | 2281 | } |
2320 | 2282 | ||
2321 | public void SendXferPacket(ulong xferID, uint packet, byte[] data) | 2283 | public void SendXferPacket(ulong xferID, uint packet, byte[] data, bool isTaskInventory) |
2322 | { | 2284 | { |
2285 | ThrottleOutPacketType type = ThrottleOutPacketType.Asset; | ||
2286 | if (isTaskInventory) | ||
2287 | type = ThrottleOutPacketType.Task; | ||
2288 | |||
2323 | SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket); | 2289 | SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket); |
2324 | sendXfer.XferID.ID = xferID; | 2290 | sendXfer.XferID.ID = xferID; |
2325 | sendXfer.XferID.Packet = packet; | 2291 | sendXfer.XferID.Packet = packet; |
2326 | sendXfer.DataPacket.Data = data; | 2292 | sendXfer.DataPacket.Data = data; |
2327 | OutPacket(sendXfer, ThrottleOutPacketType.Asset); | 2293 | OutPacket(sendXfer, type); |
2328 | } | 2294 | } |
2329 | 2295 | ||
2330 | public void SendAbortXferPacket(ulong xferID) | 2296 | public void SendAbortXferPacket(ulong xferID) |
@@ -2471,14 +2437,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2471 | // this is the username of the *owner* | 2437 | // this is the username of the *owner* |
2472 | dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName); | 2438 | dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName); |
2473 | dialog.Data.LastName = Util.StringToBytes256(ownerLastName); | 2439 | dialog.Data.LastName = Util.StringToBytes256(ownerLastName); |
2474 | dialog.Data.Message = Util.StringToBytes1024(msg); | 2440 | dialog.Data.Message = Util.StringToBytes(msg,512); |
2475 | dialog.Data.ImageID = textureID; | 2441 | dialog.Data.ImageID = textureID; |
2476 | dialog.Data.ChatChannel = ch; | 2442 | dialog.Data.ChatChannel = ch; |
2477 | ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length]; | 2443 | ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length]; |
2478 | for (int i = 0; i < buttonlabels.Length; i++) | 2444 | for (int i = 0; i < buttonlabels.Length; i++) |
2479 | { | 2445 | { |
2480 | buttons[i] = new ScriptDialogPacket.ButtonsBlock(); | 2446 | buttons[i] = new ScriptDialogPacket.ButtonsBlock(); |
2481 | buttons[i].ButtonLabel = Util.StringToBytes256(buttonlabels[i]); | 2447 | buttons[i].ButtonLabel = Util.StringToBytes(buttonlabels[i],24); |
2482 | } | 2448 | } |
2483 | dialog.Buttons = buttons; | 2449 | dialog.Buttons = buttons; |
2484 | 2450 | ||
@@ -2514,6 +2480,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2514 | OutPacket(sound, ThrottleOutPacketType.Task); | 2480 | OutPacket(sound, ThrottleOutPacketType.Task); |
2515 | } | 2481 | } |
2516 | 2482 | ||
2483 | public void SendTransferAbort(TransferRequestPacket transferRequest) | ||
2484 | { | ||
2485 | TransferAbortPacket abort = (TransferAbortPacket)PacketPool.Instance.GetPacket(PacketType.TransferAbort); | ||
2486 | abort.TransferInfo.TransferID = transferRequest.TransferInfo.TransferID; | ||
2487 | abort.TransferInfo.ChannelType = transferRequest.TransferInfo.ChannelType; | ||
2488 | m_log.Debug("[Assets] Aborting transfer; asset request failed"); | ||
2489 | OutPacket(abort, ThrottleOutPacketType.Task); | ||
2490 | } | ||
2491 | |||
2517 | public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain) | 2492 | public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain) |
2518 | { | 2493 | { |
2519 | SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger); | 2494 | SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger); |
@@ -2730,8 +2705,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2730 | OutPacket(offp, ThrottleOutPacketType.Task); | 2705 | OutPacket(offp, ThrottleOutPacketType.Task); |
2731 | } | 2706 | } |
2732 | 2707 | ||
2733 | public void SendSitResponse(UUID TargetID, Vector3 OffsetPos, Quaternion SitOrientation, bool autopilot, | 2708 | public void SendFindAgent(UUID HunterID, UUID PreyID, double GlobalX, double GlobalY) |
2734 | Vector3 CameraAtOffset, Vector3 CameraEyeOffset, bool ForceMouseLook) | 2709 | { |
2710 | FindAgentPacket fap = new FindAgentPacket(); | ||
2711 | fap.AgentBlock.Hunter = HunterID; | ||
2712 | fap.AgentBlock.Prey = PreyID; | ||
2713 | fap.AgentBlock.SpaceIP = 0; | ||
2714 | |||
2715 | fap.LocationBlock = new FindAgentPacket.LocationBlockBlock[1]; | ||
2716 | fap.LocationBlock[0] = new FindAgentPacket.LocationBlockBlock(); | ||
2717 | fap.LocationBlock[0].GlobalX = GlobalX; | ||
2718 | fap.LocationBlock[0].GlobalY = GlobalY; | ||
2719 | |||
2720 | OutPacket(fap, ThrottleOutPacketType.Task); | ||
2721 | } | ||
2722 | |||
2723 | public void SendSitResponse(UUID TargetID, Vector3 OffsetPos, | ||
2724 | Quaternion SitOrientation, bool autopilot, | ||
2725 | Vector3 CameraAtOffset, Vector3 CameraEyeOffset, bool ForceMouseLook) | ||
2735 | { | 2726 | { |
2736 | AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket(); | 2727 | AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket(); |
2737 | avatarSitResponse.SitObject.ID = TargetID; | 2728 | avatarSitResponse.SitObject.ID = TargetID; |
@@ -2819,6 +2810,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2819 | float friction = part.Friction; | 2810 | float friction = part.Friction; |
2820 | float bounce = part.Restitution; | 2811 | float bounce = part.Restitution; |
2821 | float gravmod = part.GravityModifier; | 2812 | float gravmod = part.GravityModifier; |
2813 | |||
2822 | eq.partPhysicsProperties(localid, physshapetype, density, friction, bounce, gravmod,AgentId); | 2814 | eq.partPhysicsProperties(localid, physshapetype, density, friction, bounce, gravmod,AgentId); |
2823 | } | 2815 | } |
2824 | } | 2816 | } |
@@ -2889,8 +2881,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2889 | LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType); | 2881 | LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType); |
2890 | return; | 2882 | return; |
2891 | } | 2883 | } |
2884 | int WearableOut = 0; | ||
2885 | bool isWearable = false; | ||
2886 | |||
2887 | if (req.AssetInf != null) | ||
2888 | isWearable = | ||
2889 | ((AssetType) req.AssetInf.Type == | ||
2890 | AssetType.Bodypart || (AssetType) req.AssetInf.Type == AssetType.Clothing); | ||
2892 | 2891 | ||
2893 | //m_log.Debug("sending asset " + req.RequestAssetID); | 2892 | |
2893 | //m_log.Debug("sending asset " + req.RequestAssetID + ", iswearable: " + isWearable); | ||
2894 | |||
2895 | |||
2896 | //if (isWearable) | ||
2897 | // m_log.Debug((AssetType)req.AssetInf.Type); | ||
2898 | |||
2894 | TransferInfoPacket Transfer = new TransferInfoPacket(); | 2899 | TransferInfoPacket Transfer = new TransferInfoPacket(); |
2895 | Transfer.TransferInfo.ChannelType = 2; | 2900 | Transfer.TransferInfo.ChannelType = 2; |
2896 | Transfer.TransferInfo.Status = 0; | 2901 | Transfer.TransferInfo.Status = 0; |
@@ -2912,7 +2917,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2912 | Transfer.TransferInfo.Size = req.AssetInf.Data.Length; | 2917 | Transfer.TransferInfo.Size = req.AssetInf.Data.Length; |
2913 | Transfer.TransferInfo.TransferID = req.TransferRequestID; | 2918 | Transfer.TransferInfo.TransferID = req.TransferRequestID; |
2914 | Transfer.Header.Zerocoded = true; | 2919 | Transfer.Header.Zerocoded = true; |
2915 | OutPacket(Transfer, ThrottleOutPacketType.Asset); | 2920 | OutPacket(Transfer, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset); |
2916 | 2921 | ||
2917 | if (req.NumPackets == 1) | 2922 | if (req.NumPackets == 1) |
2918 | { | 2923 | { |
@@ -2923,12 +2928,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2923 | TransferPacket.TransferData.Data = req.AssetInf.Data; | 2928 | TransferPacket.TransferData.Data = req.AssetInf.Data; |
2924 | TransferPacket.TransferData.Status = 1; | 2929 | TransferPacket.TransferData.Status = 1; |
2925 | TransferPacket.Header.Zerocoded = true; | 2930 | TransferPacket.Header.Zerocoded = true; |
2926 | OutPacket(TransferPacket, ThrottleOutPacketType.Asset); | 2931 | OutPacket(TransferPacket, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset); |
2927 | } | 2932 | } |
2928 | else | 2933 | else |
2929 | { | 2934 | { |
2930 | int processedLength = 0; | 2935 | int processedLength = 0; |
2931 | int maxChunkSize = Settings.MAX_PACKET_SIZE - 100; | 2936 | // int maxChunkSize = Settings.MAX_PACKET_SIZE - 100; |
2937 | |||
2938 | int maxChunkSize = (int) MaxTransferBytesPerPacket; | ||
2932 | int packetNumber = 0; | 2939 | int packetNumber = 0; |
2933 | 2940 | ||
2934 | while (processedLength < req.AssetInf.Data.Length) | 2941 | while (processedLength < req.AssetInf.Data.Length) |
@@ -2954,7 +2961,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2954 | TransferPacket.TransferData.Status = 1; | 2961 | TransferPacket.TransferData.Status = 1; |
2955 | } | 2962 | } |
2956 | TransferPacket.Header.Zerocoded = true; | 2963 | TransferPacket.Header.Zerocoded = true; |
2957 | OutPacket(TransferPacket, ThrottleOutPacketType.Asset); | 2964 | OutPacket(TransferPacket, isWearable ? ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority : ThrottleOutPacketType.Asset); |
2958 | 2965 | ||
2959 | processedLength += chunkSize; | 2966 | processedLength += chunkSize; |
2960 | packetNumber++; | 2967 | packetNumber++; |
@@ -2999,7 +3006,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2999 | reply.Data.ParcelID = parcelID; | 3006 | reply.Data.ParcelID = parcelID; |
3000 | reply.Data.OwnerID = land.OwnerID; | 3007 | reply.Data.OwnerID = land.OwnerID; |
3001 | reply.Data.Name = Utils.StringToBytes(land.Name); | 3008 | reply.Data.Name = Utils.StringToBytes(land.Name); |
3002 | reply.Data.Desc = Utils.StringToBytes(land.Description); | 3009 | if (land != null && land.Description != null && land.Description != String.Empty) |
3010 | reply.Data.Desc = Utils.StringToBytes(land.Description.Substring(0, land.Description.Length > 254 ? 254: land.Description.Length)); | ||
3011 | else | ||
3012 | reply.Data.Desc = new Byte[0]; | ||
3003 | reply.Data.ActualArea = land.Area; | 3013 | reply.Data.ActualArea = land.Area; |
3004 | reply.Data.BillableArea = land.Area; // TODO: what is this? | 3014 | reply.Data.BillableArea = land.Area; // TODO: what is this? |
3005 | 3015 | ||
@@ -3385,7 +3395,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3385 | AgentData.Add(AgentDataMap); | 3395 | AgentData.Add(AgentDataMap); |
3386 | llsd.Add("AgentData", AgentData); | 3396 | llsd.Add("AgentData", AgentData); |
3387 | OSDArray GroupData = new OSDArray(data.Length); | 3397 | OSDArray GroupData = new OSDArray(data.Length); |
3388 | OSDArray NewGroupData = new OSDArray(data.Length); | 3398 | // OSDArray NewGroupData = new OSDArray(data.Length); |
3389 | foreach (GroupMembershipData m in data) | 3399 | foreach (GroupMembershipData m in data) |
3390 | { | 3400 | { |
3391 | OSDMap GroupDataMap = new OSDMap(6); | 3401 | OSDMap GroupDataMap = new OSDMap(6); |
@@ -3396,12 +3406,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3396 | GroupDataMap.Add("GroupID", OSD.FromUUID(m.GroupID)); | 3406 | GroupDataMap.Add("GroupID", OSD.FromUUID(m.GroupID)); |
3397 | GroupDataMap.Add("GroupName", OSD.FromString(m.GroupName)); | 3407 | GroupDataMap.Add("GroupName", OSD.FromString(m.GroupName)); |
3398 | GroupDataMap.Add("GroupInsigniaID", OSD.FromUUID(m.GroupPicture)); | 3408 | GroupDataMap.Add("GroupInsigniaID", OSD.FromUUID(m.GroupPicture)); |
3399 | NewGroupDataMap.Add("ListInProfile", OSD.FromBoolean(m.ListInProfile)); | 3409 | // NewGroupDataMap.Add("ListInProfile", OSD.FromBoolean(m.ListInProfile)); |
3400 | GroupData.Add(GroupDataMap); | 3410 | GroupData.Add(GroupDataMap); |
3401 | NewGroupData.Add(NewGroupDataMap); | 3411 | // NewGroupData.Add(NewGroupDataMap); |
3402 | } | 3412 | } |
3403 | llsd.Add("GroupData", GroupData); | 3413 | llsd.Add("GroupData", GroupData); |
3404 | llsd.Add("NewGroupData", NewGroupData); | 3414 | // llsd.Add("NewGroupData", NewGroupData); |
3405 | 3415 | ||
3406 | IEventQueue eq = this.Scene.RequestModuleInterface<IEventQueue>(); | 3416 | IEventQueue eq = this.Scene.RequestModuleInterface<IEventQueue>(); |
3407 | if (eq != null) | 3417 | if (eq != null) |
@@ -3410,6 +3420,45 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3410 | } | 3420 | } |
3411 | } | 3421 | } |
3412 | 3422 | ||
3423 | public void SendAgentGroupDataUpdate(UUID avatarID, GroupMembershipData[] data) | ||
3424 | { | ||
3425 | IEventQueue eq = this.Scene.RequestModuleInterface<IEventQueue>(); | ||
3426 | |||
3427 | // use UDP if no caps | ||
3428 | if (eq == null) | ||
3429 | { | ||
3430 | SendGroupMembership(data); | ||
3431 | } | ||
3432 | |||
3433 | OSDMap llsd = new OSDMap(3); | ||
3434 | OSDArray AgentData = new OSDArray(1); | ||
3435 | OSDMap AgentDataMap = new OSDMap(1); | ||
3436 | AgentDataMap.Add("AgentID", OSD.FromUUID(this.AgentId)); | ||
3437 | AgentDataMap.Add("AvatarID", OSD.FromUUID(avatarID)); | ||
3438 | AgentData.Add(AgentDataMap); | ||
3439 | llsd.Add("AgentData", AgentData); | ||
3440 | OSDArray GroupData = new OSDArray(data.Length); | ||
3441 | OSDArray NewGroupData = new OSDArray(data.Length); | ||
3442 | foreach (GroupMembershipData m in data) | ||
3443 | { | ||
3444 | OSDMap GroupDataMap = new OSDMap(6); | ||
3445 | OSDMap NewGroupDataMap = new OSDMap(1); | ||
3446 | GroupDataMap.Add("GroupPowers", OSD.FromULong(m.GroupPowers)); | ||
3447 | GroupDataMap.Add("AcceptNotices", OSD.FromBoolean(m.AcceptNotices)); | ||
3448 | GroupDataMap.Add("GroupTitle", OSD.FromString(m.GroupTitle)); | ||
3449 | GroupDataMap.Add("GroupID", OSD.FromUUID(m.GroupID)); | ||
3450 | GroupDataMap.Add("GroupName", OSD.FromString(m.GroupName)); | ||
3451 | GroupDataMap.Add("GroupInsigniaID", OSD.FromUUID(m.GroupPicture)); | ||
3452 | NewGroupDataMap.Add("ListInProfile", OSD.FromBoolean(m.ListInProfile)); | ||
3453 | GroupData.Add(GroupDataMap); | ||
3454 | NewGroupData.Add(NewGroupDataMap); | ||
3455 | } | ||
3456 | llsd.Add("GroupData", GroupData); | ||
3457 | llsd.Add("NewGroupData", NewGroupData); | ||
3458 | |||
3459 | eq.Enqueue(BuildEvent("AgentGroupDataUpdate", llsd), this.AgentId); | ||
3460 | } | ||
3461 | |||
3413 | public void SendJoinGroupReply(UUID groupID, bool success) | 3462 | public void SendJoinGroupReply(UUID groupID, bool success) |
3414 | { | 3463 | { |
3415 | JoinGroupReplyPacket p = (JoinGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.JoinGroupReply); | 3464 | JoinGroupReplyPacket p = (JoinGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.JoinGroupReply); |
@@ -3706,24 +3755,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3706 | aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count]; | 3755 | aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count]; |
3707 | AgentWearablesUpdatePacket.WearableDataBlock awb; | 3756 | AgentWearablesUpdatePacket.WearableDataBlock awb; |
3708 | int idx = 0; | 3757 | int idx = 0; |
3709 | for (int i = 0; i < wearables.Length; i++) | 3758 | |
3710 | { | 3759 | for (int i = 0; i < wearables.Length; i++) |
3711 | for (int j = 0; j < wearables[i].Count; j++) | 3760 | { |
3712 | { | 3761 | for (int j = 0; j < wearables[i].Count; j++) |
3713 | awb = new AgentWearablesUpdatePacket.WearableDataBlock(); | 3762 | { |
3714 | awb.WearableType = (byte)i; | 3763 | awb = new AgentWearablesUpdatePacket.WearableDataBlock(); |
3715 | awb.AssetID = wearables[i][j].AssetID; | 3764 | awb.WearableType = (byte) i; |
3716 | awb.ItemID = wearables[i][j].ItemID; | 3765 | awb.AssetID = wearables[i][j].AssetID; |
3717 | aw.WearableData[idx] = awb; | 3766 | awb.ItemID = wearables[i][j].ItemID; |
3718 | idx++; | 3767 | aw.WearableData[idx] = awb; |
3719 | 3768 | idx++; | |
3720 | // m_log.DebugFormat( | 3769 | |
3721 | // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}", | 3770 | // m_log.DebugFormat( |
3722 | // awb.ItemID, awb.AssetID, i, Name); | 3771 | // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}", |
3723 | } | 3772 | // awb.ItemID, awb.AssetID, i, Name); |
3724 | } | 3773 | } |
3774 | } | ||
3725 | 3775 | ||
3726 | OutPacket(aw, ThrottleOutPacketType.Task); | 3776 | OutPacket(aw, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority); |
3727 | } | 3777 | } |
3728 | 3778 | ||
3729 | public void SendAppearance(UUID agentID, byte[] visualParams, byte[] textureEntry) | 3779 | public void SendAppearance(UUID agentID, byte[] visualParams, byte[] textureEntry) |
@@ -3749,8 +3799,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3749 | avp.Sender.ID = agentID; | 3799 | avp.Sender.ID = agentID; |
3750 | avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0]; | 3800 | avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0]; |
3751 | avp.AppearanceHover = new AvatarAppearancePacket.AppearanceHoverBlock[0]; | 3801 | avp.AppearanceHover = new AvatarAppearancePacket.AppearanceHoverBlock[0]; |
3802 | |||
3803 | // this need be use in future ? | ||
3804 | // avp.AppearanceData[0].AppearanceVersion = 0; | ||
3805 | // avp.AppearanceData[0].CofVersion = 0; | ||
3806 | |||
3752 | //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString()); | 3807 | //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString()); |
3753 | OutPacket(avp, ThrottleOutPacketType.Task); | 3808 | OutPacket(avp, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority); |
3754 | } | 3809 | } |
3755 | 3810 | ||
3756 | public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs) | 3811 | public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs) |
@@ -3778,7 +3833,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3778 | ani.AnimationSourceList[i].ObjectID = objectIDs[i]; | 3833 | ani.AnimationSourceList[i].ObjectID = objectIDs[i]; |
3779 | } | 3834 | } |
3780 | ani.Header.Reliable = false; | 3835 | ani.Header.Reliable = false; |
3781 | OutPacket(ani, ThrottleOutPacketType.Task); | 3836 | OutPacket(ani, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority); |
3782 | } | 3837 | } |
3783 | 3838 | ||
3784 | #endregion | 3839 | #endregion |
@@ -3802,12 +3857,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3802 | objupdate.Header.Zerocoded = true; | 3857 | objupdate.Header.Zerocoded = true; |
3803 | 3858 | ||
3804 | objupdate.RegionData.RegionHandle = presence.RegionHandle; | 3859 | objupdate.RegionData.RegionHandle = presence.RegionHandle; |
3805 | objupdate.RegionData.TimeDilation = ushort.MaxValue; | 3860 | // objupdate.RegionData.TimeDilation = ushort.MaxValue; |
3806 | 3861 | objupdate.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f); | |
3807 | objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; | 3862 | objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; |
3808 | objupdate.ObjectData[0] = CreateAvatarUpdateBlock(presence); | 3863 | objupdate.ObjectData[0] = CreateAvatarUpdateBlock(presence); |
3809 | 3864 | ||
3810 | OutPacket(objupdate, ThrottleOutPacketType.Task); | 3865 | OutPacket(objupdate, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority); |
3811 | 3866 | ||
3812 | // We need to record the avatar local id since the root prim of an attachment points to this. | 3867 | // We need to record the avatar local id since the root prim of an attachment points to this. |
3813 | // m_attachmentsSent.Add(avatar.LocalId); | 3868 | // m_attachmentsSent.Add(avatar.LocalId); |
@@ -3866,6 +3921,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3866 | /// </summary> | 3921 | /// </summary> |
3867 | public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags) | 3922 | public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags) |
3868 | { | 3923 | { |
3924 | /* | ||
3869 | if (entity.UUID == m_agentId && !updateFlags.HasFlag(PrimUpdateFlags.FullUpdate)) | 3925 | if (entity.UUID == m_agentId && !updateFlags.HasFlag(PrimUpdateFlags.FullUpdate)) |
3870 | { | 3926 | { |
3871 | ImprovedTerseObjectUpdatePacket packet | 3927 | ImprovedTerseObjectUpdatePacket packet |
@@ -3876,15 +3932,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3876 | packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | 3932 | packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; |
3877 | packet.ObjectData[0] = CreateImprovedTerseBlock(entity, false); | 3933 | packet.ObjectData[0] = CreateImprovedTerseBlock(entity, false); |
3878 | OutPacket(packet, ThrottleOutPacketType.Unknown, true); | 3934 | OutPacket(packet, ThrottleOutPacketType.Unknown, true); |
3935 | return; | ||
3879 | } | 3936 | } |
3880 | else | 3937 | */ |
3938 | if (entity is SceneObjectPart) | ||
3881 | { | 3939 | { |
3882 | //double priority = m_prioritizer.GetUpdatePriority(this, entity); | 3940 | SceneObjectPart e = (SceneObjectPart)entity; |
3883 | uint priority = m_prioritizer.GetUpdatePriority(this, entity); | 3941 | SceneObjectGroup g = e.ParentGroup; |
3884 | 3942 | if (g.HasPrivateAttachmentPoint && g.OwnerID != AgentId) | |
3885 | lock (m_entityUpdates.SyncRoot) | 3943 | return; // Don't send updates for other people's HUDs |
3886 | m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags, m_scene.TimeDilation)); | ||
3887 | } | 3944 | } |
3945 | |||
3946 | //double priority = m_prioritizer.GetUpdatePriority(this, entity); | ||
3947 | uint priority = m_prioritizer.GetUpdatePriority(this, entity); | ||
3948 | |||
3949 | lock (m_entityUpdates.SyncRoot) | ||
3950 | m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags, m_scene.TimeDilation)); | ||
3888 | } | 3951 | } |
3889 | 3952 | ||
3890 | /// <summary> | 3953 | /// <summary> |
@@ -3894,8 +3957,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3894 | /// The original update time is used for the merged update. | 3957 | /// The original update time is used for the merged update. |
3895 | /// </summary> | 3958 | /// </summary> |
3896 | private void ResendPrimUpdate(EntityUpdate update) | 3959 | private void ResendPrimUpdate(EntityUpdate update) |
3897 | { | 3960 | { |
3898 | // If the update exists in priority queue, it will be updated. | 3961 | // If the update exists in priority queue, it will be updated. |
3899 | // If it does not exist then it will be added with the current (rather than its original) priority | 3962 | // If it does not exist then it will be added with the current (rather than its original) priority |
3900 | uint priority = m_prioritizer.GetUpdatePriority(this, update.Entity); | 3963 | uint priority = m_prioritizer.GetUpdatePriority(this, update.Entity); |
3901 | 3964 | ||
@@ -3919,7 +3982,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3919 | m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber); | 3982 | m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber); |
3920 | 3983 | ||
3921 | // Count this as a resent packet since we are going to requeue all of the updates contained in it | 3984 | // Count this as a resent packet since we are going to requeue all of the updates contained in it |
3922 | Interlocked.Increment(ref m_udpClient.PacketsResent); | 3985 | Interlocked.Increment(ref m_udpClient.PacketsResent); |
3923 | 3986 | ||
3924 | // We're not going to worry about interlock yet since its not currently critical that this total count | 3987 | // We're not going to worry about interlock yet since its not currently critical that this total count |
3925 | // is 100% correct | 3988 | // is 100% correct |
@@ -3928,18 +3991,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3928 | foreach (EntityUpdate update in updates) | 3991 | foreach (EntityUpdate update in updates) |
3929 | ResendPrimUpdate(update); | 3992 | ResendPrimUpdate(update); |
3930 | } | 3993 | } |
3931 | 3994 | ||
3932 | // OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>(); | ||
3933 | // OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>> compressedUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>>(); | ||
3934 | // OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>(); | ||
3935 | // OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseAgentUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>(); | ||
3936 | // | ||
3937 | // OpenSim.Framework.Lazy<List<EntityUpdate>> objectUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); | ||
3938 | // OpenSim.Framework.Lazy<List<EntityUpdate>> compressedUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); | ||
3939 | // OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); | ||
3940 | // OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); | ||
3941 | |||
3942 | |||
3943 | private void ProcessEntityUpdates(int maxUpdates) | 3995 | private void ProcessEntityUpdates(int maxUpdates) |
3944 | { | 3996 | { |
3945 | OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>(); | 3997 | OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>(); |
@@ -3952,15 +4004,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3952 | OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); | 4004 | OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); |
3953 | OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); | 4005 | OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>(); |
3954 | 4006 | ||
3955 | // objectUpdateBlocks.Value.Clear(); | ||
3956 | // compressedUpdateBlocks.Value.Clear(); | ||
3957 | // terseUpdateBlocks.Value.Clear(); | ||
3958 | // terseAgentUpdateBlocks.Value.Clear(); | ||
3959 | // objectUpdates.Value.Clear(); | ||
3960 | // compressedUpdates.Value.Clear(); | ||
3961 | // terseUpdates.Value.Clear(); | ||
3962 | // terseAgentUpdates.Value.Clear(); | ||
3963 | |||
3964 | // Check to see if this is a flush | 4007 | // Check to see if this is a flush |
3965 | if (maxUpdates <= 0) | 4008 | if (maxUpdates <= 0) |
3966 | { | 4009 | { |
@@ -3971,54 +4014,71 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3971 | 4014 | ||
3972 | // We must lock for both manipulating the kill record and sending the packet, in order to avoid a race | 4015 | // We must lock for both manipulating the kill record and sending the packet, in order to avoid a race |
3973 | // condition where a kill can be processed before an out-of-date update for the same object. | 4016 | // condition where a kill can be processed before an out-of-date update for the same object. |
3974 | lock (m_killRecord) | 4017 | // float avgTimeDilation = 0.0f; |
4018 | IEntityUpdate iupdate; | ||
4019 | Int32 timeinqueue; // this is just debugging code & can be dropped later | ||
4020 | |||
4021 | while (updatesThisCall < maxUpdates) | ||
3975 | { | 4022 | { |
3976 | float avgTimeDilation = 1.0f; | 4023 | lock (m_entityUpdates.SyncRoot) |
3977 | IEntityUpdate iupdate; | 4024 | if (!m_entityUpdates.TryDequeue(out iupdate, out timeinqueue)) |
3978 | Int32 timeinqueue; // this is just debugging code & can be dropped later | 4025 | break; |
3979 | 4026 | ||
3980 | while (updatesThisCall < maxUpdates) | 4027 | EntityUpdate update = (EntityUpdate)iupdate; |
4028 | |||
4029 | // avgTimeDilation += update.TimeDilation; | ||
4030 | |||
4031 | if (update.Entity is SceneObjectPart) | ||
3981 | { | 4032 | { |
3982 | lock (m_entityUpdates.SyncRoot) | 4033 | SceneObjectPart part = (SceneObjectPart)update.Entity; |
3983 | if (!m_entityUpdates.TryDequeue(out iupdate, out timeinqueue)) | ||
3984 | break; | ||
3985 | 4034 | ||
3986 | EntityUpdate update = (EntityUpdate)iupdate; | 4035 | if (part.ParentGroup.IsDeleted || part.ParentGroup.inTransit) |
3987 | 4036 | continue; | |
3988 | avgTimeDilation += update.TimeDilation; | ||
3989 | avgTimeDilation *= 0.5f; | ||
3990 | 4037 | ||
3991 | if (update.Entity is SceneObjectPart) | 4038 | if (part.ParentGroup.IsAttachment) |
3992 | { | 4039 | { // Someone else's HUD, why are we getting these? |
3993 | SceneObjectPart part = (SceneObjectPart)update.Entity; | 4040 | if (part.ParentGroup.OwnerID != AgentId && part.ParentGroup.HasPrivateAttachmentPoint) |
3994 | |||
3995 | // Please do not remove this unless you can demonstrate on the OpenSim mailing list that a client | ||
3996 | // will never receive an update after a prim kill. Even then, keeping the kill record may be a good | ||
3997 | // safety measure. | ||
3998 | // | ||
3999 | // If a Linden Lab 1.23.5 client (and possibly later and earlier) receives an object update | ||
4000 | // after a kill, it will keep displaying the deleted object until relog. OpenSim currently performs | ||
4001 | // updates and kills on different threads with different scheduling strategies, hence this protection. | ||
4002 | // | ||
4003 | // This doesn't appear to apply to child prims - a client will happily ignore these updates | ||
4004 | // after the root prim has been deleted. | ||
4005 | if (m_killRecord.Contains(part.LocalId)) | ||
4006 | { | ||
4007 | // m_log.WarnFormat( | ||
4008 | // "[CLIENT]: Preventing update for prim with local id {0} after client for user {1} told it was deleted", | ||
4009 | // part.LocalId, Name); | ||
4010 | continue; | 4041 | continue; |
4011 | } | 4042 | ScenePresence sp; |
4012 | 4043 | // Owner is not in the sim, don't update it to | |
4013 | if (part.ParentGroup.IsAttachment && m_disableFacelights) | 4044 | // anyone |
4045 | if (!m_scene.TryGetScenePresence(part.OwnerID, out sp)) | ||
4046 | continue; | ||
4047 | |||
4048 | List<SceneObjectGroup> atts = sp.GetAttachments(); | ||
4049 | bool found = false; | ||
4050 | foreach (SceneObjectGroup att in atts) | ||
4014 | { | 4051 | { |
4015 | if (part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand && | 4052 | if (att == part.ParentGroup) |
4016 | part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.RightHand) | ||
4017 | { | 4053 | { |
4018 | part.Shape.LightEntry = false; | 4054 | found = true; |
4055 | break; | ||
4019 | } | 4056 | } |
4020 | } | 4057 | } |
4021 | 4058 | ||
4059 | // It's an attachment of a valid avatar, but | ||
4060 | // doesn't seem to be attached, skip | ||
4061 | if (!found) | ||
4062 | continue; | ||
4063 | |||
4064 | // On vehicle crossing, the attachments are received | ||
4065 | // while the avatar is still a child. Don't send | ||
4066 | // updates here because the LocalId has not yet | ||
4067 | // been updated and the viewer will derender the | ||
4068 | // attachments until the avatar becomes root. | ||
4069 | if (sp.IsChildAgent) | ||
4070 | continue; | ||
4071 | |||
4072 | } | ||
4073 | |||
4074 | if (part.ParentGroup.IsAttachment && m_disableFacelights) | ||
4075 | { | ||
4076 | if (part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand && | ||
4077 | part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.RightHand) | ||
4078 | { | ||
4079 | part.Shape.LightEntry = false; | ||
4080 | } | ||
4081 | |||
4022 | if (part.Shape != null && (part.Shape.SculptType == (byte)SculptType.Mesh)) | 4082 | if (part.Shape != null && (part.Shape.SculptType == (byte)SculptType.Mesh)) |
4023 | { | 4083 | { |
4024 | // Ensure that mesh has at least 8 valid faces | 4084 | // Ensure that mesh has at least 8 valid faces |
@@ -4027,233 +4087,218 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
4027 | part.Shape.ProfileHollow = 27500; | 4087 | part.Shape.ProfileHollow = 27500; |
4028 | } | 4088 | } |
4029 | } | 4089 | } |
4030 | 4090 | ||
4031 | #region UpdateFlags to packet type conversion | 4091 | if (part.Shape != null && (part.Shape.SculptType == (byte)SculptType.Mesh)) |
4032 | |||
4033 | PrimUpdateFlags updateFlags = (PrimUpdateFlags)update.Flags; | ||
4034 | |||
4035 | bool canUseCompressed = true; | ||
4036 | bool canUseImproved = true; | ||
4037 | |||
4038 | // Compressed object updates only make sense for LL primitives | ||
4039 | if (!(update.Entity is SceneObjectPart)) | ||
4040 | { | 4092 | { |
4041 | canUseCompressed = false; | 4093 | // Ensure that mesh has at least 8 valid faces |
4094 | part.Shape.ProfileBegin = 12500; | ||
4095 | part.Shape.ProfileEnd = 0; | ||
4096 | part.Shape.ProfileHollow = 27500; | ||
4042 | } | 4097 | } |
4043 | 4098 | } | |
4044 | if (updateFlags.HasFlag(PrimUpdateFlags.FullUpdate)) | 4099 | else if (update.Entity is ScenePresence) |
4100 | { | ||
4101 | ScenePresence presence = (ScenePresence)update.Entity; | ||
4102 | if (presence.IsDeleted) | ||
4103 | continue; | ||
4104 | // If ParentUUID is not UUID.Zero and ParentID is 0, this | ||
4105 | // avatar is in the process of crossing regions while | ||
4106 | // sat on an object. In this state, we don't want any | ||
4107 | // updates because they will visually orbit the avatar. | ||
4108 | // Update will be forced once crossing is completed anyway. | ||
4109 | if (presence.ParentUUID != UUID.Zero && presence.ParentID == 0) | ||
4110 | continue; | ||
4111 | } | ||
4112 | |||
4113 | ++updatesThisCall; | ||
4114 | |||
4115 | #region UpdateFlags to packet type conversion | ||
4116 | |||
4117 | PrimUpdateFlags updateFlags = (PrimUpdateFlags)update.Flags; | ||
4118 | |||
4119 | bool canUseCompressed = true; | ||
4120 | bool canUseImproved = true; | ||
4121 | |||
4122 | // Compressed object updates only make sense for LL primitives | ||
4123 | if (!(update.Entity is SceneObjectPart)) | ||
4124 | { | ||
4125 | canUseCompressed = false; | ||
4126 | } | ||
4127 | |||
4128 | if (updateFlags.HasFlag(PrimUpdateFlags.FullUpdate)) | ||
4129 | { | ||
4130 | canUseCompressed = false; | ||
4131 | canUseImproved = false; | ||
4132 | } | ||
4133 | else | ||
4134 | { | ||
4135 | if (updateFlags.HasFlag(PrimUpdateFlags.Velocity) || | ||
4136 | updateFlags.HasFlag(PrimUpdateFlags.Acceleration) || | ||
4137 | updateFlags.HasFlag(PrimUpdateFlags.CollisionPlane) || | ||
4138 | updateFlags.HasFlag(PrimUpdateFlags.Joint)) | ||
4045 | { | 4139 | { |
4046 | canUseCompressed = false; | 4140 | canUseCompressed = false; |
4047 | canUseImproved = false; | ||
4048 | } | 4141 | } |
4049 | else | 4142 | |
4143 | if (updateFlags.HasFlag(PrimUpdateFlags.PrimFlags) || | ||
4144 | updateFlags.HasFlag(PrimUpdateFlags.ParentID) || | ||
4145 | updateFlags.HasFlag(PrimUpdateFlags.Scale) || | ||
4146 | updateFlags.HasFlag(PrimUpdateFlags.PrimData) || | ||
4147 | updateFlags.HasFlag(PrimUpdateFlags.Text) || | ||
4148 | updateFlags.HasFlag(PrimUpdateFlags.NameValue) || | ||
4149 | updateFlags.HasFlag(PrimUpdateFlags.ExtraData) || | ||
4150 | updateFlags.HasFlag(PrimUpdateFlags.TextureAnim) || | ||
4151 | updateFlags.HasFlag(PrimUpdateFlags.Sound) || | ||
4152 | updateFlags.HasFlag(PrimUpdateFlags.Particles) || | ||
4153 | updateFlags.HasFlag(PrimUpdateFlags.Material) || | ||
4154 | updateFlags.HasFlag(PrimUpdateFlags.ClickAction) || | ||
4155 | updateFlags.HasFlag(PrimUpdateFlags.MediaURL) || | ||
4156 | updateFlags.HasFlag(PrimUpdateFlags.Joint)) | ||
4050 | { | 4157 | { |
4051 | if (updateFlags.HasFlag(PrimUpdateFlags.Velocity) || | 4158 | canUseImproved = false; |
4052 | updateFlags.HasFlag(PrimUpdateFlags.Acceleration) || | ||
4053 | updateFlags.HasFlag(PrimUpdateFlags.CollisionPlane) || | ||
4054 | updateFlags.HasFlag(PrimUpdateFlags.Joint)) | ||
4055 | { | ||
4056 | canUseCompressed = false; | ||
4057 | } | ||
4058 | |||
4059 | if (updateFlags.HasFlag(PrimUpdateFlags.PrimFlags) || | ||
4060 | updateFlags.HasFlag(PrimUpdateFlags.ParentID) || | ||
4061 | updateFlags.HasFlag(PrimUpdateFlags.Scale) || | ||
4062 | updateFlags.HasFlag(PrimUpdateFlags.PrimData) || | ||
4063 | updateFlags.HasFlag(PrimUpdateFlags.Text) || | ||
4064 | updateFlags.HasFlag(PrimUpdateFlags.NameValue) || | ||
4065 | updateFlags.HasFlag(PrimUpdateFlags.ExtraData) || | ||
4066 | updateFlags.HasFlag(PrimUpdateFlags.TextureAnim) || | ||
4067 | updateFlags.HasFlag(PrimUpdateFlags.Sound) || | ||
4068 | updateFlags.HasFlag(PrimUpdateFlags.Particles) || | ||
4069 | updateFlags.HasFlag(PrimUpdateFlags.Material) || | ||
4070 | updateFlags.HasFlag(PrimUpdateFlags.ClickAction) || | ||
4071 | updateFlags.HasFlag(PrimUpdateFlags.MediaURL) || | ||
4072 | updateFlags.HasFlag(PrimUpdateFlags.Joint)) | ||
4073 | { | ||
4074 | canUseImproved = false; | ||
4075 | } | ||
4076 | } | 4159 | } |
4160 | } | ||
4077 | 4161 | ||
4078 | #endregion UpdateFlags to packet type conversion | 4162 | #endregion UpdateFlags to packet type conversion |
4079 | |||
4080 | #region Block Construction | ||
4081 | |||
4082 | // TODO: Remove this once we can build compressed updates | ||
4083 | canUseCompressed = false; | ||
4084 | |||
4085 | if (!canUseImproved && !canUseCompressed) | ||
4086 | { | ||
4087 | ObjectUpdatePacket.ObjectDataBlock updateBlock; | ||
4088 | 4163 | ||
4089 | if (update.Entity is ScenePresence) | 4164 | #region Block Construction |
4090 | { | ||
4091 | updateBlock = CreateAvatarUpdateBlock((ScenePresence)update.Entity); | ||
4092 | } | ||
4093 | else | ||
4094 | { | ||
4095 | SceneObjectPart part = (SceneObjectPart)update.Entity; | ||
4096 | updateBlock = CreatePrimUpdateBlock(part, AgentId); | ||
4097 | |||
4098 | // If the part has become a private hud since the update was scheduled then we do not | ||
4099 | // want to send it to other avatars. | ||
4100 | if (part.ParentGroup.IsAttachment | ||
4101 | && part.ParentGroup.HasPrivateAttachmentPoint | ||
4102 | && part.ParentGroup.AttachedAvatar != AgentId) | ||
4103 | continue; | ||
4104 | |||
4105 | // If the part has since been deleted, then drop the update. In the case of attachments, | ||
4106 | // this is to avoid spurious updates to other viewers since post-processing of attachments | ||
4107 | // has to change the IsAttachment flag for various reasons (which will end up in a pass | ||
4108 | // of the test above). | ||
4109 | // | ||
4110 | // Actual deletions (kills) happen in another method. | ||
4111 | if (part.ParentGroup.IsDeleted) | ||
4112 | continue; | ||
4113 | } | ||
4114 | 4165 | ||
4115 | objectUpdateBlocks.Value.Add(updateBlock); | 4166 | // TODO: Remove this once we can build compressed updates |
4116 | objectUpdates.Value.Add(update); | 4167 | canUseCompressed = false; |
4117 | } | ||
4118 | else if (!canUseImproved) | ||
4119 | { | ||
4120 | SceneObjectPart part = (SceneObjectPart)update.Entity; | ||
4121 | ObjectUpdateCompressedPacket.ObjectDataBlock compressedBlock | ||
4122 | = CreateCompressedUpdateBlock(part, updateFlags); | ||
4123 | |||
4124 | // If the part has since been deleted, then drop the update. In the case of attachments, | ||
4125 | // this is to avoid spurious updates to other viewers since post-processing of attachments | ||
4126 | // has to change the IsAttachment flag for various reasons (which will end up in a pass | ||
4127 | // of the test above). | ||
4128 | // | ||
4129 | // Actual deletions (kills) happen in another method. | ||
4130 | if (part.ParentGroup.IsDeleted) | ||
4131 | continue; | ||
4132 | 4168 | ||
4133 | compressedUpdateBlocks.Value.Add(compressedBlock); | 4169 | if (!canUseImproved && !canUseCompressed) |
4134 | compressedUpdates.Value.Add(update); | 4170 | { |
4171 | if (update.Entity is ScenePresence) | ||
4172 | { | ||
4173 | objectUpdateBlocks.Value.Add(CreateAvatarUpdateBlock((ScenePresence)update.Entity)); | ||
4135 | } | 4174 | } |
4136 | else | 4175 | else |
4137 | { | 4176 | { |
4138 | if (update.Entity is ScenePresence && ((ScenePresence)update.Entity).UUID == AgentId) | 4177 | objectUpdateBlocks.Value.Add(CreatePrimUpdateBlock((SceneObjectPart)update.Entity, this.m_agentId)); |
4139 | { | 4178 | } |
4140 | // Self updates go into a special list | 4179 | } |
4141 | terseAgentUpdateBlocks.Value.Add(CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures))); | 4180 | else if (!canUseImproved) |
4142 | terseAgentUpdates.Value.Add(update); | 4181 | { |
4143 | } | 4182 | compressedUpdateBlocks.Value.Add(CreateCompressedUpdateBlock((SceneObjectPart)update.Entity, updateFlags)); |
4144 | else | 4183 | } |
4145 | { | 4184 | else |
4146 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseUpdateBlock | 4185 | { |
4147 | = CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures)); | 4186 | if (update.Entity is ScenePresence) |
4187 | // ALL presence updates go into a special list | ||
4188 | terseAgentUpdateBlocks.Value.Add(CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures))); | ||
4189 | else | ||
4190 | // Everything else goes here | ||
4191 | terseUpdateBlocks.Value.Add(CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures))); | ||
4192 | } | ||
4148 | 4193 | ||
4149 | // Everything else goes here | 4194 | #endregion Block Construction |
4150 | if (update.Entity is SceneObjectPart) | 4195 | } |
4151 | { | ||
4152 | SceneObjectPart part = (SceneObjectPart)update.Entity; | ||
4153 | |||
4154 | // If the part has become a private hud since the update was scheduled then we do not | ||
4155 | // want to send it to other avatars. | ||
4156 | if (part.ParentGroup.IsAttachment | ||
4157 | && part.ParentGroup.HasPrivateAttachmentPoint | ||
4158 | && part.ParentGroup.AttachedAvatar != AgentId) | ||
4159 | continue; | ||
4160 | |||
4161 | // If the part has since been deleted, then drop the update. In the case of attachments, | ||
4162 | // this is to avoid spurious updates to other viewers since post-processing of attachments | ||
4163 | // has to change the IsAttachment flag for various reasons (which will end up in a pass | ||
4164 | // of the test above). | ||
4165 | // | ||
4166 | // Actual deletions (kills) happen in another method. | ||
4167 | if (part.ParentGroup.IsDeleted) | ||
4168 | continue; | ||
4169 | } | ||
4170 | 4196 | ||
4171 | terseUpdateBlocks.Value.Add(terseUpdateBlock); | 4197 | #region Packet Sending |
4172 | terseUpdates.Value.Add(update); | 4198 | |
4173 | } | 4199 | // const float TIME_DILATION = 1.0f; |
4174 | } | 4200 | ushort timeDilation; |
4201 | // if(updatesThisCall > 0) | ||
4202 | // timeDilation = Utils.FloatToUInt16(avgTimeDilation/updatesThisCall, 0.0f, 1.0f); | ||
4203 | // else | ||
4204 | // timeDilation = ushort.MaxValue; // 1.0; | ||
4205 | |||
4206 | timeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f); | ||
4175 | 4207 | ||
4176 | ++updatesThisCall; | 4208 | if (terseAgentUpdateBlocks.IsValueCreated) |
4209 | { | ||
4210 | List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseAgentUpdateBlocks.Value; | ||
4211 | |||
4212 | ImprovedTerseObjectUpdatePacket packet | ||
4213 | = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate); | ||
4214 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | ||
4215 | packet.RegionData.TimeDilation = timeDilation; | ||
4216 | packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count]; | ||
4217 | |||
4218 | for (int i = 0; i < blocks.Count; i++) | ||
4219 | packet.ObjectData[i] = blocks[i]; | ||
4220 | |||
4221 | OutPacket(packet, ThrottleOutPacketType.Unknown, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseUpdates.Value, oPacket); }); | ||
4222 | } | ||
4223 | |||
4224 | if (objectUpdateBlocks.IsValueCreated) | ||
4225 | { | ||
4226 | List<ObjectUpdatePacket.ObjectDataBlock> blocks = objectUpdateBlocks.Value; | ||
4177 | 4227 | ||
4178 | #endregion Block Construction | 4228 | ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate); |
4179 | } | 4229 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; |
4230 | packet.RegionData.TimeDilation = timeDilation; | ||
4231 | packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[blocks.Count]; | ||
4232 | |||
4233 | for (int i = 0; i < blocks.Count; i++) | ||
4234 | packet.ObjectData[i] = blocks[i]; | ||
4180 | 4235 | ||
4181 | #region Packet Sending | 4236 | OutPacket(packet, ThrottleOutPacketType.Task, true); |
4182 | ushort timeDilation = Utils.FloatToUInt16(avgTimeDilation, 0.0f, 1.0f); | 4237 | } |
4238 | |||
4239 | if (compressedUpdateBlocks.IsValueCreated) | ||
4240 | { | ||
4241 | List<ObjectUpdateCompressedPacket.ObjectDataBlock> blocks = compressedUpdateBlocks.Value; | ||
4242 | |||
4243 | ObjectUpdateCompressedPacket packet = (ObjectUpdateCompressedPacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdateCompressed); | ||
4244 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | ||
4245 | packet.RegionData.TimeDilation = timeDilation; | ||
4246 | packet.ObjectData = new ObjectUpdateCompressedPacket.ObjectDataBlock[blocks.Count]; | ||
4183 | 4247 | ||
4184 | if (terseAgentUpdateBlocks.IsValueCreated) | 4248 | for (int i = 0; i < blocks.Count; i++) |
4185 | { | 4249 | packet.ObjectData[i] = blocks[i]; |
4186 | List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseAgentUpdateBlocks.Value; | 4250 | |
4251 | OutPacket(packet, ThrottleOutPacketType.Task, true); | ||
4252 | } | ||
4253 | |||
4254 | if (terseUpdateBlocks.IsValueCreated) | ||
4255 | { | ||
4256 | List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseUpdateBlocks.Value; | ||
4257 | |||
4258 | ImprovedTerseObjectUpdatePacket packet | ||
4259 | = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket( | ||
4260 | PacketType.ImprovedTerseObjectUpdate); | ||
4261 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | ||
4262 | packet.RegionData.TimeDilation = timeDilation; | ||
4263 | packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count]; | ||
4264 | |||
4265 | for (int i = 0; i < blocks.Count; i++) | ||
4266 | packet.ObjectData[i] = blocks[i]; | ||
4187 | 4267 | ||
4188 | ImprovedTerseObjectUpdatePacket packet | 4268 | OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseUpdates.Value, oPacket); }); |
4189 | = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate); | 4269 | } |
4190 | 4270 | ||
4191 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | 4271 | #endregion Packet Sending |
4192 | packet.RegionData.TimeDilation = timeDilation; | 4272 | } |
4193 | packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count]; | ||
4194 | 4273 | ||
4195 | for (int i = 0; i < blocks.Count; i++) | 4274 | // hack.. dont use |
4196 | packet.ObjectData[i] = blocks[i]; | 4275 | public void SendPartFullUpdate(ISceneEntity ent, uint? parentID) |
4197 | // If any of the packets created from this call go unacknowledged, all of the updates will be resent | 4276 | { |
4198 | OutPacket(packet, ThrottleOutPacketType.Unknown, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseAgentUpdates.Value, oPacket); }); | 4277 | if (ent is SceneObjectPart) |
4199 | } | 4278 | { |
4279 | SceneObjectPart part = (SceneObjectPart)ent; | ||
4280 | ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate); | ||
4281 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | ||
4282 | packet.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f); | ||
4283 | packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; | ||
4200 | 4284 | ||
4201 | if (objectUpdateBlocks.IsValueCreated) | 4285 | ObjectUpdatePacket.ObjectDataBlock blk = CreatePrimUpdateBlock(part, this.m_agentId); |
4202 | { | 4286 | if (parentID.HasValue) |
4203 | List<ObjectUpdatePacket.ObjectDataBlock> blocks = objectUpdateBlocks.Value; | ||
4204 | |||
4205 | ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate); | ||
4206 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | ||
4207 | packet.RegionData.TimeDilation = timeDilation; | ||
4208 | packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[blocks.Count]; | ||
4209 | |||
4210 | for (int i = 0; i < blocks.Count; i++) | ||
4211 | packet.ObjectData[i] = blocks[i]; | ||
4212 | // If any of the packets created from this call go unacknowledged, all of the updates will be resent | ||
4213 | OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(objectUpdates.Value, oPacket); }); | ||
4214 | } | ||
4215 | |||
4216 | if (compressedUpdateBlocks.IsValueCreated) | ||
4217 | { | 4287 | { |
4218 | List<ObjectUpdateCompressedPacket.ObjectDataBlock> blocks = compressedUpdateBlocks.Value; | 4288 | blk.ParentID = parentID.Value; |
4219 | |||
4220 | ObjectUpdateCompressedPacket packet = (ObjectUpdateCompressedPacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdateCompressed); | ||
4221 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | ||
4222 | packet.RegionData.TimeDilation = timeDilation; | ||
4223 | packet.ObjectData = new ObjectUpdateCompressedPacket.ObjectDataBlock[blocks.Count]; | ||
4224 | |||
4225 | for (int i = 0; i < blocks.Count; i++) | ||
4226 | packet.ObjectData[i] = blocks[i]; | ||
4227 | // If any of the packets created from this call go unacknowledged, all of the updates will be resent | ||
4228 | OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(compressedUpdates.Value, oPacket); }); | ||
4229 | } | 4289 | } |
4230 | 4290 | ||
4231 | if (terseUpdateBlocks.IsValueCreated) | 4291 | packet.ObjectData[0] = blk; |
4232 | { | ||
4233 | List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseUpdateBlocks.Value; | ||
4234 | |||
4235 | ImprovedTerseObjectUpdatePacket packet | ||
4236 | = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket( | ||
4237 | PacketType.ImprovedTerseObjectUpdate); | ||
4238 | 4292 | ||
4239 | packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; | 4293 | OutPacket(packet, ThrottleOutPacketType.Task, true); |
4240 | packet.RegionData.TimeDilation = timeDilation; | ||
4241 | packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count]; | ||
4242 | |||
4243 | for (int i = 0; i < blocks.Count; i++) | ||
4244 | packet.ObjectData[i] = blocks[i]; | ||
4245 | // If any of the packets created from this call go unacknowledged, all of the updates will be resent | ||
4246 | OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseUpdates.Value, oPacket); }); | ||
4247 | } | ||
4248 | } | 4294 | } |
4249 | 4295 | ||
4250 | // m_log.DebugFormat( | 4296 | // m_log.DebugFormat( |
4251 | // "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}", | 4297 | // "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}", |
4252 | // updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name); | 4298 | // updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name); |
4253 | // | 4299 | // |
4254 | #endregion Packet Sending | ||
4255 | } | 4300 | } |
4256 | 4301 | ||
4257 | public void ReprioritizeUpdates() | 4302 | public void ReprioritizeUpdates() |
4258 | { | 4303 | { |
4259 | lock (m_entityUpdates.SyncRoot) | 4304 | lock (m_entityUpdates.SyncRoot) |
@@ -4572,11 +4617,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
4572 | 4617 | ||
4573 | // Pass in the delegate so that if this packet needs to be resent, we send the current properties | 4618 | // Pass in the delegate so that if this packet needs to be resent, we send the current properties |
4574 | // of the object rather than the properties when the packet was created | 4619 | // of the object rather than the properties when the packet was created |
4575 | OutPacket(packet, ThrottleOutPacketType.Task, true, | 4620 | // HACK : Remove intelligent resending until it's fixed in core |
4576 | delegate(OutgoingPacket oPacket) | 4621 | //OutPacket(packet, ThrottleOutPacketType.Task, true, |
4577 | { | 4622 | // delegate(OutgoingPacket oPacket) |
4578 | ResendPropertyUpdates(updates, oPacket); | 4623 | // { |
4579 | }); | 4624 | // ResendPropertyUpdates(updates, oPacket); |
4625 | // }); | ||
4626 | OutPacket(packet, ThrottleOutPacketType.Task, true); | ||
4580 | 4627 | ||
4581 | // pbcnt += blocks.Count; | 4628 | // pbcnt += blocks.Count; |
4582 | // ppcnt++; | 4629 | // ppcnt++; |
@@ -4602,11 +4649,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
4602 | // of the object rather than the properties when the packet was created | 4649 | // of the object rather than the properties when the packet was created |
4603 | List<ObjectPropertyUpdate> updates = new List<ObjectPropertyUpdate>(); | 4650 | List<ObjectPropertyUpdate> updates = new List<ObjectPropertyUpdate>(); |
4604 | updates.Add(familyUpdates.Value[i]); | 4651 | updates.Add(familyUpdates.Value[i]); |
4605 | OutPacket(packet, ThrottleOutPacketType.Task, true, | 4652 | // HACK : Remove intelligent resending until it's fixed in core |
4606 | delegate(OutgoingPacket oPacket) | 4653 | //OutPacket(packet, ThrottleOutPacketType.Task, true, |
4607 | { | 4654 | // delegate(OutgoingPacket oPacket) |
4608 | ResendPropertyUpdates(updates, oPacket); | 4655 | // { |
4609 | }); | 4656 | // ResendPropertyUpdates(updates, oPacket); |
4657 | // }); | ||
4658 | OutPacket(packet, ThrottleOutPacketType.Task, true); | ||
4610 | 4659 | ||
4611 | // fpcnt++; | 4660 | // fpcnt++; |
4612 | // fbcnt++; | 4661 | // fbcnt++; |
@@ -4939,7 +4988,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
4939 | packet.ParcelData.Data = data; | 4988 | packet.ParcelData.Data = data; |
4940 | packet.ParcelData.SequenceID = sequence_id; | 4989 | packet.ParcelData.SequenceID = sequence_id; |
4941 | packet.Header.Zerocoded = true; | 4990 | packet.Header.Zerocoded = true; |
4942 | OutPacket(packet, ThrottleOutPacketType.Task); | 4991 | // OutPacket(packet, ThrottleOutPacketType.Task); |
4992 | OutPacket(packet, ThrottleOutPacketType.Land); | ||
4943 | } | 4993 | } |
4944 | 4994 | ||
4945 | public void SendLandProperties( | 4995 | public void SendLandProperties( |
@@ -5004,7 +5054,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5004 | 5054 | ||
5005 | if (landData.SimwideArea > 0) | 5055 | if (landData.SimwideArea > 0) |
5006 | { | 5056 | { |
5007 | int simulatorCapacity = (int)(((float)landData.SimwideArea / 65536.0f) * (float)m_scene.RegionInfo.ObjectCapacity * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus); | 5057 | int simulatorCapacity = (int)((long)landData.SimwideArea * (long)m_scene.RegionInfo.ObjectCapacity * (long)m_scene.RegionInfo.RegionSettings.ObjectBonus / 65536L); |
5058 | // Never report more than sim total capacity | ||
5059 | if (simulatorCapacity > m_scene.RegionInfo.ObjectCapacity) | ||
5060 | simulatorCapacity = m_scene.RegionInfo.ObjectCapacity; | ||
5008 | updateMessage.SimWideMaxPrims = simulatorCapacity; | 5061 | updateMessage.SimWideMaxPrims = simulatorCapacity; |
5009 | } | 5062 | } |
5010 | else | 5063 | else |
@@ -5039,7 +5092,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5039 | IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>(); | 5092 | IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>(); |
5040 | if (eq != null) | 5093 | if (eq != null) |
5041 | { | 5094 | { |
5042 | eq.ParcelProperties(updateMessage, this.AgentId); | 5095 | |
5096 | OSD message_body = updateMessage.Serialize(); | ||
5097 | // Add new fields here until OMV has them | ||
5098 | OSDMap bodyMap = (OSDMap)message_body; | ||
5099 | OSDArray parcelDataArray = (OSDArray)bodyMap["ParcelData"]; | ||
5100 | OSDMap parcelData = (OSDMap)parcelDataArray[0]; | ||
5101 | parcelData["SeeAVs"] = OSD.FromBoolean(landData.SeeAVs); | ||
5102 | parcelData["AnyAVSounds"] = OSD.FromBoolean(landData.AnyAVSounds); | ||
5103 | parcelData["GroupAVSounds"] = OSD.FromBoolean(landData.GroupAVSounds); | ||
5104 | OSDMap message = new OSDMap(); | ||
5105 | message.Add("message", OSD.FromString("ParcelProperties")); | ||
5106 | message.Add("body", message_body); | ||
5107 | |||
5108 | eq.Enqueue (message, this.AgentId); | ||
5109 | |||
5110 | // eq.ParcelProperties(updateMessage, this.AgentId); | ||
5043 | } | 5111 | } |
5044 | else | 5112 | else |
5045 | { | 5113 | { |
@@ -5133,14 +5201,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5133 | 5201 | ||
5134 | if (notifyCount > 0) | 5202 | if (notifyCount > 0) |
5135 | { | 5203 | { |
5136 | if (notifyCount > 32) | 5204 | // if (notifyCount > 32) |
5137 | { | 5205 | // { |
5138 | m_log.InfoFormat( | 5206 | // m_log.InfoFormat( |
5139 | "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}" | 5207 | // "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}" |
5140 | + " - a developer might want to investigate whether this is a hard limit", 32); | 5208 | // + " - a developer might want to investigate whether this is a hard limit", 32); |
5141 | 5209 | // | |
5142 | notifyCount = 32; | 5210 | // notifyCount = 32; |
5143 | } | 5211 | // } |
5144 | 5212 | ||
5145 | ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock | 5213 | ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock |
5146 | = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount]; | 5214 | = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount]; |
@@ -5195,41 +5263,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5195 | { | 5263 | { |
5196 | ScenePresence presence = (ScenePresence)entity; | 5264 | ScenePresence presence = (ScenePresence)entity; |
5197 | 5265 | ||
5198 | // m_log.DebugFormat( | ||
5199 | // "[LLCLIENTVIEW]: Sending terse update to {0} with pos {1}, vel {2} in {3}", | ||
5200 | // Name, presence.OffsetPosition, presence.Velocity, m_scene.Name); | ||
5201 | |||
5202 | attachPoint = presence.State; | ||
5203 | collisionPlane = presence.CollisionPlane; | ||
5204 | position = presence.OffsetPosition; | 5266 | position = presence.OffsetPosition; |
5205 | velocity = presence.Velocity; | 5267 | rotation = presence.Rotation; |
5206 | acceleration = Vector3.Zero; | ||
5207 | |||
5208 | // Interestingly, sending this to non-zero will cause the client's avatar to start moving & accelerating | ||
5209 | // in that direction, even though we don't model this on the server. Implementing this in the future | ||
5210 | // may improve movement smoothness. | ||
5211 | // acceleration = new Vector3(1, 0, 0); | ||
5212 | |||
5213 | angularVelocity = presence.AngularVelocity; | 5268 | angularVelocity = presence.AngularVelocity; |
5214 | |||
5215 | // Whilst not in mouselook, an avatar will transmit only the Z rotation as this is the only axis | ||
5216 | // it rotates around. | ||
5217 | // In mouselook, X and Y co-ordinate will also be sent but when used in Rotation, these cause unwanted | ||
5218 | // excessive up and down movements of the camera when looking up and down. | ||
5219 | // See http://opensimulator.org/mantis/view.php?id=3274 | ||
5220 | // This does not affect head movement, since this is controlled entirely by camera movement rather than | ||
5221 | // body rotation. We still need to transmit X and Y for sitting avatars but mouselook does not change | ||
5222 | // the rotation in this case. | ||
5223 | rotation = presence.Rotation; | 5269 | rotation = presence.Rotation; |
5224 | 5270 | ||
5225 | if (!presence.IsSatOnObject) | 5271 | attachPoint = 0; |
5226 | { | 5272 | // m_log.DebugFormat( |
5227 | rotation.X = 0; | 5273 | // "[LLCLIENTVIEW]: Sending terse update to {0} with position {1} in {2}", Name, presence.OffsetPosition, m_scene.Name); |
5228 | rotation.Y = 0; | 5274 | |
5229 | } | 5275 | // attachPoint = presence.State; // Core: commented |
5276 | collisionPlane = presence.CollisionPlane; | ||
5277 | velocity = presence.Velocity; | ||
5278 | acceleration = Vector3.Zero; | ||
5230 | 5279 | ||
5231 | if (sendTexture) | 5280 | if (sendTexture) |
5281 | { | ||
5232 | textureEntry = presence.Appearance.Texture.GetBytes(); | 5282 | textureEntry = presence.Appearance.Texture.GetBytes(); |
5283 | } | ||
5233 | else | 5284 | else |
5234 | textureEntry = null; | 5285 | textureEntry = null; |
5235 | } | 5286 | } |
@@ -5333,34 +5384,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5333 | 5384 | ||
5334 | protected ObjectUpdatePacket.ObjectDataBlock CreateAvatarUpdateBlock(ScenePresence data) | 5385 | protected ObjectUpdatePacket.ObjectDataBlock CreateAvatarUpdateBlock(ScenePresence data) |
5335 | { | 5386 | { |
5387 | Vector3 offsetPosition = data.OffsetPosition; | ||
5388 | Quaternion rotation = data.Rotation; | ||
5389 | uint parentID = data.ParentID; | ||
5390 | |||
5336 | // m_log.DebugFormat( | 5391 | // m_log.DebugFormat( |
5337 | // "[LLCLIENTVIEW]: Sending full update to {0} with pos {1}, vel {2} in {3}", Name, data.OffsetPosition, data.Velocity, m_scene.Name); | 5392 | // "[LLCLIENTVIEW]: Sending full update to {0} with pos {1}, vel {2} in {3}", Name, data.OffsetPosition, data.Velocity, m_scene.Name); |
5338 | 5393 | ||
5339 | byte[] objectData = new byte[76]; | 5394 | byte[] objectData = new byte[76]; |
5340 | 5395 | ||
5341 | data.CollisionPlane.ToBytes(objectData, 0); | 5396 | Vector3 velocity = new Vector3(0, 0, 0); |
5342 | data.OffsetPosition.ToBytes(objectData, 16); | 5397 | Vector3 acceleration = new Vector3(0, 0, 0); |
5343 | data.Velocity.ToBytes(objectData, 28); | 5398 | rotation.Normalize(); |
5344 | // data.Acceleration.ToBytes(objectData, 40); | ||
5345 | |||
5346 | // Whilst not in mouselook, an avatar will transmit only the Z rotation as this is the only axis | ||
5347 | // it rotates around. | ||
5348 | // In mouselook, X and Y co-ordinate will also be sent but when used in Rotation, these cause unwanted | ||
5349 | // excessive up and down movements of the camera when looking up and down. | ||
5350 | // See http://opensimulator.org/mantis/view.php?id=3274 | ||
5351 | // This does not affect head movement, since this is controlled entirely by camera movement rather than | ||
5352 | // body rotation. We still need to transmit X and Y for sitting avatars but mouselook does not change | ||
5353 | // the rotation in this case. | ||
5354 | Quaternion rot = data.Rotation; | ||
5355 | |||
5356 | if (!data.IsSatOnObject) | ||
5357 | { | ||
5358 | rot.X = 0; | ||
5359 | rot.Y = 0; | ||
5360 | } | ||
5361 | 5399 | ||
5362 | rot.ToBytes(objectData, 52); | 5400 | data.CollisionPlane.ToBytes(objectData, 0); |
5363 | //data.AngularVelocity.ToBytes(objectData, 64); | 5401 | offsetPosition.ToBytes(objectData, 16); |
5402 | velocity.ToBytes(objectData, 28); | ||
5403 | acceleration.ToBytes(objectData, 40); | ||
5404 | rotation.ToBytes(objectData, 52); | ||
5405 | data.AngularVelocity.ToBytes(objectData, 64); | ||
5364 | 5406 | ||
5365 | ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock(); | 5407 | ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock(); |
5366 | 5408 | ||
@@ -5386,7 +5428,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5386 | update.PCode = (byte)PCode.Avatar; | 5428 | update.PCode = (byte)PCode.Avatar; |
5387 | update.ProfileCurve = 1; | 5429 | update.ProfileCurve = 1; |
5388 | update.PSBlock = Utils.EmptyBytes; | 5430 | update.PSBlock = Utils.EmptyBytes; |
5389 | update.Scale = new Vector3(0.45f, 0.6f, 1.9f); | 5431 | update.Scale = data.Appearance.AvatarSize; |
5432 | // update.Scale.Z -= 0.2f; | ||
5433 | |||
5390 | update.Text = Utils.EmptyBytes; | 5434 | update.Text = Utils.EmptyBytes; |
5391 | update.TextColor = new byte[4]; | 5435 | update.TextColor = new byte[4]; |
5392 | 5436 | ||
@@ -5397,10 +5441,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5397 | update.TextureEntry = Utils.EmptyBytes; | 5441 | update.TextureEntry = Utils.EmptyBytes; |
5398 | // update.TextureEntry = (data.Appearance.Texture != null) ? data.Appearance.Texture.GetBytes() : Utils.EmptyBytes; | 5442 | // update.TextureEntry = (data.Appearance.Texture != null) ? data.Appearance.Texture.GetBytes() : Utils.EmptyBytes; |
5399 | 5443 | ||
5444 | /* all this flags seem related to prims and not avatars. This allow for wrong viewer side move of a avatar in prim edition mode (anv mantis 854) | ||
5400 | update.UpdateFlags = (uint)( | 5445 | update.UpdateFlags = (uint)( |
5401 | PrimFlags.Physics | PrimFlags.ObjectModify | PrimFlags.ObjectCopy | PrimFlags.ObjectAnyOwner | | 5446 | PrimFlags.Physics | PrimFlags.ObjectModify | PrimFlags.ObjectCopy | PrimFlags.ObjectAnyOwner | |
5402 | PrimFlags.ObjectYouOwner | PrimFlags.ObjectMove | PrimFlags.InventoryEmpty | PrimFlags.ObjectTransfer | | 5447 | PrimFlags.ObjectYouOwner | PrimFlags.ObjectMove | PrimFlags.InventoryEmpty | PrimFlags.ObjectTransfer | |
5403 | PrimFlags.ObjectOwnerModify); | 5448 | PrimFlags.ObjectOwnerModify); |
5449 | */ | ||
5450 | update.UpdateFlags = 0; | ||
5404 | 5451 | ||
5405 | return update; | 5452 | return update; |
5406 | } | 5453 | } |
@@ -5411,15 +5458,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5411 | data.RelativePosition.ToBytes(objectData, 0); | 5458 | data.RelativePosition.ToBytes(objectData, 0); |
5412 | data.Velocity.ToBytes(objectData, 12); | 5459 | data.Velocity.ToBytes(objectData, 12); |
5413 | data.Acceleration.ToBytes(objectData, 24); | 5460 | data.Acceleration.ToBytes(objectData, 24); |
5414 | try | 5461 | |
5415 | { | 5462 | Quaternion rotation = data.RotationOffset; |
5416 | data.RotationOffset.ToBytes(objectData, 36); | 5463 | rotation.Normalize(); |
5417 | } | 5464 | rotation.ToBytes(objectData, 36); |
5418 | catch (Exception e) | ||
5419 | { | ||
5420 | m_log.Warn("[LLClientView]: exception converting quaternion to bytes, using Quaternion.Identity. Exception: " + e.ToString()); | ||
5421 | OpenMetaverse.Quaternion.Identity.ToBytes(objectData, 36); | ||
5422 | } | ||
5423 | data.AngularVelocity.ToBytes(objectData, 48); | 5465 | data.AngularVelocity.ToBytes(objectData, 48); |
5424 | 5466 | ||
5425 | ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock(); | 5467 | ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock(); |
@@ -5433,7 +5475,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5433 | //update.JointType = 0; | 5475 | //update.JointType = 0; |
5434 | update.Material = data.Material; | 5476 | update.Material = data.Material; |
5435 | update.MediaURL = Utils.EmptyBytes; // FIXME: Support this in OpenSim | 5477 | update.MediaURL = Utils.EmptyBytes; // FIXME: Support this in OpenSim |
5436 | 5478 | /* | |
5437 | if (data.ParentGroup.IsAttachment) | 5479 | if (data.ParentGroup.IsAttachment) |
5438 | { | 5480 | { |
5439 | update.NameValue | 5481 | update.NameValue |
@@ -5458,6 +5500,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5458 | // case for attachments may contain conflicting values that can end up crashing the viewer. | 5500 | // case for attachments may contain conflicting values that can end up crashing the viewer. |
5459 | update.State = data.ParentGroup.RootPart.Shape.State; | 5501 | update.State = data.ParentGroup.RootPart.Shape.State; |
5460 | } | 5502 | } |
5503 | */ | ||
5504 | |||
5505 | if (data.ParentGroup.IsAttachment) | ||
5506 | { | ||
5507 | if (data.IsRoot) | ||
5508 | { | ||
5509 | update.NameValue = Util.StringToBytes256("AttachItemID STRING RW SV " + data.ParentGroup.FromItemID); | ||
5510 | } | ||
5511 | else | ||
5512 | update.NameValue = Utils.EmptyBytes; | ||
5513 | |||
5514 | int st = (int)data.ParentGroup.AttachmentPoint; | ||
5515 | update.State = (byte)(((st & 0xf0) >> 4) + ((st & 0x0f) << 4)); ; | ||
5516 | } | ||
5517 | else | ||
5518 | { | ||
5519 | update.NameValue = Utils.EmptyBytes; | ||
5520 | update.State = data.Shape.State; // not sure about this | ||
5521 | } | ||
5522 | |||
5461 | 5523 | ||
5462 | update.ObjectData = objectData; | 5524 | update.ObjectData = objectData; |
5463 | update.ParentID = data.ParentID; | 5525 | update.ParentID = data.ParentID; |
@@ -5579,8 +5641,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5579 | // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs | 5641 | // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs |
5580 | // for each AgentUpdate packet. | 5642 | // for each AgentUpdate packet. |
5581 | AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false); | 5643 | AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false); |
5582 | 5644 | ||
5583 | AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false); | 5645 | AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false); |
5646 | AddLocalPacketHandler(PacketType.VelocityInterpolateOff, HandleVelocityInterpolateOff, false); | ||
5647 | AddLocalPacketHandler(PacketType.VelocityInterpolateOn, HandleVelocityInterpolateOn, false); | ||
5584 | AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false); | 5648 | AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false); |
5585 | AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false); | 5649 | AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false); |
5586 | AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false); | 5650 | AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false); |
@@ -5732,6 +5796,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5732 | AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false); | 5796 | AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false); |
5733 | AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false); | 5797 | AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false); |
5734 | AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode); | 5798 | AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode); |
5799 | AddLocalPacketHandler(PacketType.CreateNewOutfitAttachments, HandleCreateNewOutfitAttachments); | ||
5735 | AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false); | 5800 | AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false); |
5736 | AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents); | 5801 | AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents); |
5737 | AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery); | 5802 | AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery); |
@@ -5798,6 +5863,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5798 | AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest); | 5863 | AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest); |
5799 | AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes); | 5864 | AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes); |
5800 | AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard); | 5865 | AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard); |
5866 | AddLocalPacketHandler(PacketType.ChangeInventoryItemFlags, HandleChangeInventoryItemFlags); | ||
5801 | 5867 | ||
5802 | AddGenericPacketHandler("autopilot", HandleAutopilot); | 5868 | AddGenericPacketHandler("autopilot", HandleAutopilot); |
5803 | } | 5869 | } |
@@ -5809,7 +5875,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5809 | #region Scene/Avatar | 5875 | #region Scene/Avatar |
5810 | 5876 | ||
5811 | // Threshold for body rotation to be a significant agent update | 5877 | // Threshold for body rotation to be a significant agent update |
5812 | private const float QDELTA = 0.000001f; | 5878 | // use the abs of cos |
5879 | private const float QDELTABody = 1.0f - 0.0001f; | ||
5880 | private const float QDELTAHead = 1.0f - 0.0001f; | ||
5813 | // Threshold for camera rotation to be a significant agent update | 5881 | // Threshold for camera rotation to be a significant agent update |
5814 | private const float VDELTA = 0.01f; | 5882 | private const float VDELTA = 0.01f; |
5815 | 5883 | ||
@@ -5832,18 +5900,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5832 | /// <param name='x'></param> | 5900 | /// <param name='x'></param> |
5833 | private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x) | 5901 | private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x) |
5834 | { | 5902 | { |
5835 | float qdelta1 = 1 - (float)Math.Pow(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation), 2); | 5903 | float qdelta1 = Math.Abs(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation)); |
5836 | //qdelta2 = 1 - (float)Math.Pow(Quaternion.Dot(x.HeadRotation, m_thisAgentUpdateArgs.HeadRotation), 2); | 5904 | //qdelta2 = Math.Abs(Quaternion.Dot(x.HeadRotation, m_thisAgentUpdateArgs.HeadRotation)); |
5837 | 5905 | ||
5838 | bool movementSignificant = | 5906 | bool movementSignificant = |
5839 | (qdelta1 > QDELTA) // significant if body rotation above threshold | 5907 | (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed |
5840 | // Ignoring head rotation altogether, because it's not being used for anything interesting up the stack | ||
5841 | // || (qdelta2 > QDELTA * 10) // significant if head rotation above threshold | ||
5842 | || (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed | ||
5843 | || (x.ControlFlags != (byte)AgentManager.ControlFlags.NONE) // significant if user supplying any movement update commands | 5908 | || (x.ControlFlags != (byte)AgentManager.ControlFlags.NONE) // significant if user supplying any movement update commands |
5844 | || (x.Far != m_thisAgentUpdateArgs.Far) // significant if far distance changed | ||
5845 | || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed | 5909 | || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed |
5846 | || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed | 5910 | || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed |
5911 | || (qdelta1 < QDELTABody) // significant if body rotation above(below cos) threshold | ||
5912 | // Ignoring head rotation altogether, because it's not being used for anything interesting up the stack | ||
5913 | // || (qdelta2 < QDELTAHead) // significant if head rotation above(below cos) threshold | ||
5914 | || (Math.Abs(x.Far - m_thisAgentUpdateArgs.Far) >= 32) // significant if far distance changed | ||
5847 | ; | 5915 | ; |
5848 | //if (movementSignificant) | 5916 | //if (movementSignificant) |
5849 | //{ | 5917 | //{ |
@@ -5886,55 +5954,63 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5886 | return cameraSignificant; | 5954 | return cameraSignificant; |
5887 | } | 5955 | } |
5888 | 5956 | ||
5889 | private bool HandleAgentUpdate(IClientAPI sener, Packet packet) | 5957 | private bool HandleAgentUpdate(IClientAPI sender, Packet packet) |
5890 | { | 5958 | { |
5891 | // We got here, which means that something in agent update was significant | 5959 | // We got here, which means that something in agent update was significant |
5892 | 5960 | ||
5893 | AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet; | 5961 | AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet; |
5894 | AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData; | 5962 | AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData; |
5895 | 5963 | ||
5896 | if (x.AgentID != AgentId || x.SessionID != SessionId) | 5964 | if (x.AgentID != AgentId || x.SessionID != SessionId) |
5965 | { | ||
5966 | PacketPool.Instance.ReturnPacket(packet); | ||
5897 | return false; | 5967 | return false; |
5968 | } | ||
5969 | |||
5970 | TotalAgentUpdates++; | ||
5898 | 5971 | ||
5899 | // Before we update the current m_thisAgentUpdateArgs, let's check this again | ||
5900 | // to see what exactly changed | ||
5901 | bool movement = CheckAgentMovementUpdateSignificance(x); | 5972 | bool movement = CheckAgentMovementUpdateSignificance(x); |
5902 | bool camera = CheckAgentCameraUpdateSignificance(x); | 5973 | bool camera = CheckAgentCameraUpdateSignificance(x); |
5903 | 5974 | ||
5904 | m_thisAgentUpdateArgs.AgentID = x.AgentID; | ||
5905 | m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation; | ||
5906 | m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis; | ||
5907 | m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter; | ||
5908 | m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis; | ||
5909 | m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis; | ||
5910 | m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags; | ||
5911 | m_thisAgentUpdateArgs.Far = x.Far; | ||
5912 | m_thisAgentUpdateArgs.Flags = x.Flags; | ||
5913 | m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation; | ||
5914 | m_thisAgentUpdateArgs.SessionID = x.SessionID; | ||
5915 | m_thisAgentUpdateArgs.State = x.State; | ||
5916 | |||
5917 | UpdateAgent handlerAgentUpdate = OnAgentUpdate; | ||
5918 | UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate; | ||
5919 | UpdateAgent handlerAgentCameraUpdate = OnAgentCameraUpdate; | ||
5920 | |||
5921 | // Was there a significant movement/state change? | 5975 | // Was there a significant movement/state change? |
5922 | if (movement) | 5976 | if (movement) |
5923 | { | 5977 | { |
5978 | m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation; | ||
5979 | m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags; | ||
5980 | m_thisAgentUpdateArgs.Far = x.Far; | ||
5981 | m_thisAgentUpdateArgs.Flags = x.Flags; | ||
5982 | m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation; | ||
5983 | // m_thisAgentUpdateArgs.SessionID = x.SessionID; | ||
5984 | m_thisAgentUpdateArgs.State = x.State; | ||
5985 | |||
5986 | UpdateAgent handlerAgentUpdate = OnAgentUpdate; | ||
5987 | UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate; | ||
5988 | |||
5924 | if (handlerPreAgentUpdate != null) | 5989 | if (handlerPreAgentUpdate != null) |
5925 | OnPreAgentUpdate(this, m_thisAgentUpdateArgs); | 5990 | OnPreAgentUpdate(this, m_thisAgentUpdateArgs); |
5926 | 5991 | ||
5927 | if (handlerAgentUpdate != null) | 5992 | if (handlerAgentUpdate != null) |
5928 | OnAgentUpdate(this, m_thisAgentUpdateArgs); | 5993 | OnAgentUpdate(this, m_thisAgentUpdateArgs); |
5994 | |||
5995 | handlerAgentUpdate = null; | ||
5996 | handlerPreAgentUpdate = null; | ||
5929 | } | 5997 | } |
5998 | |||
5930 | // Was there a significant camera(s) change? | 5999 | // Was there a significant camera(s) change? |
5931 | if (camera) | 6000 | if (camera) |
6001 | { | ||
6002 | m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis; | ||
6003 | m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter; | ||
6004 | m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis; | ||
6005 | m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis; | ||
6006 | |||
6007 | UpdateAgent handlerAgentCameraUpdate = OnAgentCameraUpdate; | ||
6008 | |||
5932 | if (handlerAgentCameraUpdate != null) | 6009 | if (handlerAgentCameraUpdate != null) |
5933 | handlerAgentCameraUpdate(this, m_thisAgentUpdateArgs); | 6010 | handlerAgentCameraUpdate(this, m_thisAgentUpdateArgs); |
5934 | 6011 | ||
5935 | handlerAgentUpdate = null; | 6012 | handlerAgentCameraUpdate = null; |
5936 | handlerPreAgentUpdate = null; | 6013 | } |
5937 | handlerAgentCameraUpdate = null; | ||
5938 | 6014 | ||
5939 | PacketPool.Instance.ReturnPacket(packet); | 6015 | PacketPool.Instance.ReturnPacket(packet); |
5940 | 6016 | ||
@@ -6150,6 +6226,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6150 | return true; | 6226 | return true; |
6151 | } | 6227 | } |
6152 | 6228 | ||
6229 | private bool HandleVelocityInterpolateOff(IClientAPI sender, Packet Pack) | ||
6230 | { | ||
6231 | VelocityInterpolateOffPacket p = (VelocityInterpolateOffPacket)Pack; | ||
6232 | if (p.AgentData.SessionID != SessionId || | ||
6233 | p.AgentData.AgentID != AgentId) | ||
6234 | return true; | ||
6235 | |||
6236 | m_VelocityInterpolate = false; | ||
6237 | return true; | ||
6238 | } | ||
6239 | |||
6240 | private bool HandleVelocityInterpolateOn(IClientAPI sender, Packet Pack) | ||
6241 | { | ||
6242 | VelocityInterpolateOnPacket p = (VelocityInterpolateOnPacket)Pack; | ||
6243 | if (p.AgentData.SessionID != SessionId || | ||
6244 | p.AgentData.AgentID != AgentId) | ||
6245 | return true; | ||
6246 | |||
6247 | m_VelocityInterpolate = true; | ||
6248 | return true; | ||
6249 | } | ||
6250 | |||
6251 | |||
6153 | private bool HandleAvatarPropertiesRequest(IClientAPI sender, Packet Pack) | 6252 | private bool HandleAvatarPropertiesRequest(IClientAPI sender, Packet Pack) |
6154 | { | 6253 | { |
6155 | AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; | 6254 | AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; |
@@ -6503,7 +6602,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6503 | { | 6602 | { |
6504 | // Note: the ModifyTerrain event handler sends out updated packets before the end of this event. Therefore, | 6603 | // Note: the ModifyTerrain event handler sends out updated packets before the end of this event. Therefore, |
6505 | // a simple boolean value should work and perhaps queue up just a few terrain patch packets at the end of the edit. | 6604 | // a simple boolean value should work and perhaps queue up just a few terrain patch packets at the end of the edit. |
6506 | m_justEditedTerrain = true; // Prevent terrain packet (Land layer) from being queued, make it unreliable | ||
6507 | if (OnModifyTerrain != null) | 6605 | if (OnModifyTerrain != null) |
6508 | { | 6606 | { |
6509 | for (int i = 0; i < modify.ParcelData.Length; i++) | 6607 | for (int i = 0; i < modify.ParcelData.Length; i++) |
@@ -6519,7 +6617,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6519 | } | 6617 | } |
6520 | } | 6618 | } |
6521 | } | 6619 | } |
6522 | m_justEditedTerrain = false; // Queue terrain packet (Land layer) if necessary, make it reliable again | ||
6523 | } | 6620 | } |
6524 | 6621 | ||
6525 | return true; | 6622 | return true; |
@@ -6581,16 +6678,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6581 | for (int i = 0; i < appear.VisualParam.Length; i++) | 6678 | for (int i = 0; i < appear.VisualParam.Length; i++) |
6582 | visualparams[i] = appear.VisualParam[i].ParamValue; | 6679 | visualparams[i] = appear.VisualParam[i].ParamValue; |
6583 | //var b = appear.WearableData[0]; | 6680 | //var b = appear.WearableData[0]; |
6584 | 6681 | ||
6585 | Primitive.TextureEntry te = null; | 6682 | Primitive.TextureEntry te = null; |
6586 | if (appear.ObjectData.TextureEntry.Length > 1) | 6683 | if (appear.ObjectData.TextureEntry.Length > 1) |
6587 | te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); | 6684 | te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); |
6588 | 6685 | ||
6589 | WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length]; | 6686 | WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length]; |
6590 | for (int i=0; i<appear.WearableData.Length;i++) | 6687 | for (int i=0; i<appear.WearableData.Length;i++) |
6591 | cacheitems[i] = new WearableCacheItem(){CacheId = appear.WearableData[i].CacheID,TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex)}; | 6688 | cacheitems[i] = new WearableCacheItem(){ |
6592 | 6689 | CacheId = appear.WearableData[i].CacheID, | |
6690 | TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex) | ||
6691 | }; | ||
6593 | 6692 | ||
6693 | |||
6594 | 6694 | ||
6595 | handlerSetAppearance(sender, te, visualparams,avSize, cacheitems); | 6695 | handlerSetAppearance(sender, te, visualparams,avSize, cacheitems); |
6596 | } | 6696 | } |
@@ -6794,13 +6894,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6794 | return true; | 6894 | return true; |
6795 | } | 6895 | } |
6796 | 6896 | ||
6797 | private bool HandleCompleteAgentMovement(IClientAPI sender, Packet Pack) | 6897 | private bool HandleCompleteAgentMovement(IClientAPI sender, Packet Pack) |
6798 | { | 6898 | { |
6899 | m_log.DebugFormat("[LLClientView] HandleCompleteAgentMovement"); | ||
6900 | |||
6799 | Action<IClientAPI, bool> handlerCompleteMovementToRegion = OnCompleteMovementToRegion; | 6901 | Action<IClientAPI, bool> handlerCompleteMovementToRegion = OnCompleteMovementToRegion; |
6800 | if (handlerCompleteMovementToRegion != null) | 6902 | if (handlerCompleteMovementToRegion != null) |
6801 | { | 6903 | { |
6802 | handlerCompleteMovementToRegion(sender, true); | 6904 | handlerCompleteMovementToRegion(sender, true); |
6803 | } | 6905 | } |
6906 | else | ||
6907 | m_log.Debug("HandleCompleteAgentMovement NULL handler"); | ||
6908 | |||
6804 | handlerCompleteMovementToRegion = null; | 6909 | handlerCompleteMovementToRegion = null; |
6805 | 6910 | ||
6806 | return true; | 6911 | return true; |
@@ -6818,7 +6923,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6818 | return true; | 6923 | return true; |
6819 | } | 6924 | } |
6820 | #endregion | 6925 | #endregion |
6821 | 6926 | /* | |
6822 | StartAnim handlerStartAnim = null; | 6927 | StartAnim handlerStartAnim = null; |
6823 | StopAnim handlerStopAnim = null; | 6928 | StopAnim handlerStopAnim = null; |
6824 | 6929 | ||
@@ -6842,6 +6947,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6842 | } | 6947 | } |
6843 | } | 6948 | } |
6844 | return true; | 6949 | return true; |
6950 | */ | ||
6951 | ChangeAnim handlerChangeAnim = null; | ||
6952 | |||
6953 | for (int i = 0; i < AgentAni.AnimationList.Length; i++) | ||
6954 | { | ||
6955 | handlerChangeAnim = OnChangeAnim; | ||
6956 | if (handlerChangeAnim != null) | ||
6957 | { | ||
6958 | handlerChangeAnim(AgentAni.AnimationList[i].AnimID, AgentAni.AnimationList[i].StartAnim, false); | ||
6959 | } | ||
6960 | } | ||
6961 | |||
6962 | handlerChangeAnim = OnChangeAnim; | ||
6963 | if (handlerChangeAnim != null) | ||
6964 | { | ||
6965 | handlerChangeAnim(UUID.Zero, false, true); | ||
6966 | } | ||
6967 | |||
6968 | return true; | ||
6845 | } | 6969 | } |
6846 | 6970 | ||
6847 | private bool HandleAgentRequestSit(IClientAPI sender, Packet Pack) | 6971 | private bool HandleAgentRequestSit(IClientAPI sender, Packet Pack) |
@@ -7087,6 +7211,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
7087 | #endregion | 7211 | #endregion |
7088 | 7212 | ||
7089 | m_udpClient.SetThrottles(atpack.Throttle.Throttles); | 7213 | m_udpClient.SetThrottles(atpack.Throttle.Throttles); |
7214 | GenericCall2 handler = OnUpdateThrottles; | ||
7215 | if (handler != null) | ||
7216 | { | ||
7217 | handler(); | ||
7218 | } | ||
7090 | return true; | 7219 | return true; |
7091 | } | 7220 | } |
7092 | 7221 | ||
@@ -7359,6 +7488,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
7359 | 7488 | ||
7360 | for (int i = 0; i < incomingselect.ObjectData.Length; i++) | 7489 | for (int i = 0; i < incomingselect.ObjectData.Length; i++) |
7361 | { | 7490 | { |
7491 | if (!SelectedObjects.Contains(incomingselect.ObjectData[i].ObjectLocalID)) | ||
7492 | SelectedObjects.Add(incomingselect.ObjectData[i].ObjectLocalID); | ||
7362 | handlerObjectSelect = OnObjectSelect; | 7493 | handlerObjectSelect = OnObjectSelect; |
7363 | if (handlerObjectSelect != null) | 7494 | if (handlerObjectSelect != null) |
7364 | { | 7495 | { |
@@ -7385,6 +7516,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
7385 | 7516 | ||
7386 | for (int i = 0; i < incomingdeselect.ObjectData.Length; i++) | 7517 | for (int i = 0; i < incomingdeselect.ObjectData.Length; i++) |
7387 | { | 7518 | { |
7519 | if (!SelectedObjects.Contains(incomingdeselect.ObjectData[i].ObjectLocalID)) | ||
7520 | SelectedObjects.Add(incomingdeselect.ObjectData[i].ObjectLocalID); | ||
7388 | handlerObjectDeselect = OnObjectDeselect; | 7521 | handlerObjectDeselect = OnObjectDeselect; |
7389 | if (handlerObjectDeselect != null) | 7522 | if (handlerObjectDeselect != null) |
7390 | { | 7523 | { |
@@ -7511,7 +7644,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
7511 | physdata.Bounce = phsblock.Restitution; | 7644 | physdata.Bounce = phsblock.Restitution; |
7512 | physdata.Density = phsblock.Density; | 7645 | physdata.Density = phsblock.Density; |
7513 | physdata.Friction = phsblock.Friction; | 7646 | physdata.Friction = phsblock.Friction; |
7514 | physdata.GravitationModifier = phsblock.GravityMultiplier; | 7647 | physdata.GravitationModifier = phsblock.GravityMultiplier; |
7515 | } | 7648 | } |
7516 | 7649 | ||
7517 | handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this); | 7650 | handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this); |
@@ -8097,6 +8230,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
8097 | // surrounding scene | 8230 | // surrounding scene |
8098 | if ((ImageType)block.Type == ImageType.Baked) | 8231 | if ((ImageType)block.Type == ImageType.Baked) |
8099 | args.Priority *= 2.0f; | 8232 | args.Priority *= 2.0f; |
8233 | int wearableout = 0; | ||
8100 | 8234 | ||
8101 | ImageManager.EnqueueReq(args); | 8235 | ImageManager.EnqueueReq(args); |
8102 | } | 8236 | } |
@@ -9106,7 +9240,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
9106 | if ((locX >= m_scene.RegionInfo.WorldLocX) | 9240 | if ((locX >= m_scene.RegionInfo.WorldLocX) |
9107 | && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX)) | 9241 | && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX)) |
9108 | && (locY >= m_scene.RegionInfo.WorldLocY) | 9242 | && (locY >= m_scene.RegionInfo.WorldLocY) |
9109 | && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)) ) | 9243 | && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY))) |
9110 | { | 9244 | { |
9111 | tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle; | 9245 | tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle; |
9112 | tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX; | 9246 | tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX; |
@@ -9146,16 +9280,61 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
9146 | 9280 | ||
9147 | #region Parcel related packets | 9281 | #region Parcel related packets |
9148 | 9282 | ||
9283 | // acumulate several HandleRegionHandleRequest consecutive overlaping requests | ||
9284 | // to be done with minimal resources as possible | ||
9285 | // variables temporary here while in test | ||
9286 | |||
9287 | Queue<UUID> RegionHandleRequests = new Queue<UUID>(); | ||
9288 | bool RegionHandleRequestsInService = false; | ||
9289 | |||
9149 | private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack) | 9290 | private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack) |
9150 | { | 9291 | { |
9151 | RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack; | 9292 | UUID currentUUID; |
9152 | 9293 | ||
9153 | RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest; | 9294 | RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest; |
9154 | if (handlerRegionHandleRequest != null) | 9295 | |
9296 | if (handlerRegionHandleRequest == null) | ||
9297 | return true; | ||
9298 | |||
9299 | RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack; | ||
9300 | |||
9301 | lock (RegionHandleRequests) | ||
9155 | { | 9302 | { |
9156 | handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID); | 9303 | if (RegionHandleRequestsInService) |
9304 | { | ||
9305 | // we are already busy doing a previus request | ||
9306 | // so enqueue it | ||
9307 | RegionHandleRequests.Enqueue(rhrPack.RequestBlock.RegionID); | ||
9308 | return true; | ||
9309 | } | ||
9310 | |||
9311 | // else do it | ||
9312 | currentUUID = rhrPack.RequestBlock.RegionID; | ||
9313 | RegionHandleRequestsInService = true; | ||
9157 | } | 9314 | } |
9158 | return true; | 9315 | |
9316 | while (true) | ||
9317 | { | ||
9318 | handlerRegionHandleRequest(this, currentUUID); | ||
9319 | |||
9320 | lock (RegionHandleRequests) | ||
9321 | { | ||
9322 | // exit condition, nothing to do or closed | ||
9323 | // current code seems to assume we may loose the handler at anytime, | ||
9324 | // so keep checking it | ||
9325 | handlerRegionHandleRequest = OnRegionHandleRequest; | ||
9326 | |||
9327 | if (RegionHandleRequests.Count == 0 || !IsActive || handlerRegionHandleRequest == null) | ||
9328 | { | ||
9329 | RegionHandleRequests.Clear(); | ||
9330 | RegionHandleRequestsInService = false; | ||
9331 | return true; | ||
9332 | } | ||
9333 | currentUUID = RegionHandleRequests.Dequeue(); | ||
9334 | } | ||
9335 | } | ||
9336 | |||
9337 | return true; // actually unreached | ||
9159 | } | 9338 | } |
9160 | 9339 | ||
9161 | private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack) | 9340 | private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack) |
@@ -10425,7 +10604,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
10425 | handlerUpdateMuteListEntry(this, UpdateMuteListEntry.MuteData.MuteID, | 10604 | handlerUpdateMuteListEntry(this, UpdateMuteListEntry.MuteData.MuteID, |
10426 | Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName), | 10605 | Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName), |
10427 | UpdateMuteListEntry.MuteData.MuteType, | 10606 | UpdateMuteListEntry.MuteData.MuteType, |
10428 | UpdateMuteListEntry.AgentData.AgentID); | 10607 | UpdateMuteListEntry.MuteData.MuteFlags); |
10429 | return true; | 10608 | return true; |
10430 | } | 10609 | } |
10431 | return false; | 10610 | return false; |
@@ -10440,8 +10619,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
10440 | { | 10619 | { |
10441 | handlerRemoveMuteListEntry(this, | 10620 | handlerRemoveMuteListEntry(this, |
10442 | RemoveMuteListEntry.MuteData.MuteID, | 10621 | RemoveMuteListEntry.MuteData.MuteID, |
10443 | Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName), | 10622 | Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName)); |
10444 | RemoveMuteListEntry.AgentData.AgentID); | ||
10445 | return true; | 10623 | return true; |
10446 | } | 10624 | } |
10447 | return false; | 10625 | return false; |
@@ -10485,10 +10663,55 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
10485 | return false; | 10663 | return false; |
10486 | } | 10664 | } |
10487 | 10665 | ||
10666 | private bool HandleChangeInventoryItemFlags(IClientAPI client, Packet packet) | ||
10667 | { | ||
10668 | ChangeInventoryItemFlagsPacket ChangeInventoryItemFlags = | ||
10669 | (ChangeInventoryItemFlagsPacket)packet; | ||
10670 | ChangeInventoryItemFlags handlerChangeInventoryItemFlags = OnChangeInventoryItemFlags; | ||
10671 | if (handlerChangeInventoryItemFlags != null) | ||
10672 | { | ||
10673 | foreach(ChangeInventoryItemFlagsPacket.InventoryDataBlock b in ChangeInventoryItemFlags.InventoryData) | ||
10674 | handlerChangeInventoryItemFlags(this, b.ItemID, b.Flags); | ||
10675 | return true; | ||
10676 | } | ||
10677 | return false; | ||
10678 | } | ||
10679 | |||
10488 | private bool HandleUseCircuitCode(IClientAPI sender, Packet Pack) | 10680 | private bool HandleUseCircuitCode(IClientAPI sender, Packet Pack) |
10489 | { | 10681 | { |
10490 | return true; | 10682 | return true; |
10491 | } | 10683 | } |
10684 | |||
10685 | private bool HandleCreateNewOutfitAttachments(IClientAPI sender, Packet Pack) | ||
10686 | { | ||
10687 | CreateNewOutfitAttachmentsPacket packet = (CreateNewOutfitAttachmentsPacket)Pack; | ||
10688 | |||
10689 | #region Packet Session and User Check | ||
10690 | if (m_checkPackets) | ||
10691 | { | ||
10692 | if (packet.AgentData.SessionID != SessionId || | ||
10693 | packet.AgentData.AgentID != AgentId) | ||
10694 | return true; | ||
10695 | } | ||
10696 | #endregion | ||
10697 | MoveItemsAndLeaveCopy handlerMoveItemsAndLeaveCopy = null; | ||
10698 | List<InventoryItemBase> items = new List<InventoryItemBase>(); | ||
10699 | foreach (CreateNewOutfitAttachmentsPacket.ObjectDataBlock n in packet.ObjectData) | ||
10700 | { | ||
10701 | InventoryItemBase b = new InventoryItemBase(); | ||
10702 | b.ID = n.OldItemID; | ||
10703 | b.Folder = n.OldFolderID; | ||
10704 | items.Add(b); | ||
10705 | } | ||
10706 | |||
10707 | handlerMoveItemsAndLeaveCopy = OnMoveItemsAndLeaveCopy; | ||
10708 | if (handlerMoveItemsAndLeaveCopy != null) | ||
10709 | { | ||
10710 | handlerMoveItemsAndLeaveCopy(this, items, packet.HeaderData.NewFolderID); | ||
10711 | } | ||
10712 | |||
10713 | return true; | ||
10714 | } | ||
10492 | 10715 | ||
10493 | private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack) | 10716 | private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack) |
10494 | { | 10717 | { |
@@ -10915,6 +11138,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
10915 | groupProfileReply.GroupData.MaturePublish = d.MaturePublish; | 11138 | groupProfileReply.GroupData.MaturePublish = d.MaturePublish; |
10916 | groupProfileReply.GroupData.OwnerRole = d.OwnerRole; | 11139 | groupProfileReply.GroupData.OwnerRole = d.OwnerRole; |
10917 | 11140 | ||
11141 | Scene scene = (Scene)m_scene; | ||
11142 | if (scene.Permissions.IsGod(sender.AgentId) && (!sender.IsGroupMember(groupProfileRequest.GroupData.GroupID))) | ||
11143 | { | ||
11144 | ScenePresence p; | ||
11145 | if (scene.TryGetScenePresence(sender.AgentId, out p)) | ||
11146 | { | ||
11147 | if (p.GodLevel >= 200) | ||
11148 | { | ||
11149 | groupProfileReply.GroupData.OpenEnrollment = true; | ||
11150 | groupProfileReply.GroupData.MembershipFee = 0; | ||
11151 | } | ||
11152 | } | ||
11153 | } | ||
11154 | |||
10918 | OutPacket(groupProfileReply, ThrottleOutPacketType.Task); | 11155 | OutPacket(groupProfileReply, ThrottleOutPacketType.Task); |
10919 | } | 11156 | } |
10920 | return true; | 11157 | return true; |
@@ -11488,11 +11725,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
11488 | 11725 | ||
11489 | StartLure handlerStartLure = OnStartLure; | 11726 | StartLure handlerStartLure = OnStartLure; |
11490 | if (handlerStartLure != null) | 11727 | if (handlerStartLure != null) |
11491 | handlerStartLure(startLureRequest.Info.LureType, | 11728 | { |
11492 | Utils.BytesToString( | 11729 | for (int i = 0 ; i < startLureRequest.TargetData.Length ; i++) |
11493 | startLureRequest.Info.Message), | 11730 | { |
11494 | startLureRequest.TargetData[0].TargetID, | 11731 | handlerStartLure(startLureRequest.Info.LureType, |
11495 | this); | 11732 | Utils.BytesToString( |
11733 | startLureRequest.Info.Message), | ||
11734 | startLureRequest.TargetData[i].TargetID, | ||
11735 | this); | ||
11736 | } | ||
11737 | } | ||
11496 | return true; | 11738 | return true; |
11497 | } | 11739 | } |
11498 | private bool HandleTeleportLureRequest(IClientAPI sender, Packet Pack) | 11740 | private bool HandleTeleportLureRequest(IClientAPI sender, Packet Pack) |
@@ -11606,10 +11848,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
11606 | } | 11848 | } |
11607 | #endregion | 11849 | #endregion |
11608 | 11850 | ||
11609 | ClassifiedDelete handlerClassifiedGodDelete = OnClassifiedGodDelete; | 11851 | ClassifiedGodDelete handlerClassifiedGodDelete = OnClassifiedGodDelete; |
11610 | if (handlerClassifiedGodDelete != null) | 11852 | if (handlerClassifiedGodDelete != null) |
11611 | handlerClassifiedGodDelete( | 11853 | handlerClassifiedGodDelete( |
11612 | classifiedGodDelete.Data.ClassifiedID, | 11854 | classifiedGodDelete.Data.ClassifiedID, |
11855 | classifiedGodDelete.Data.QueryID, | ||
11613 | this); | 11856 | this); |
11614 | return true; | 11857 | return true; |
11615 | } | 11858 | } |
@@ -11912,6 +12155,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
11912 | /// <param name="simclient"></param> | 12155 | /// <param name="simclient"></param> |
11913 | /// <param name="packet"></param> | 12156 | /// <param name="packet"></param> |
11914 | /// <returns></returns> | 12157 | /// <returns></returns> |
12158 | // TODO: Convert old handler to use new method | ||
12159 | /* | ||
11915 | protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet) | 12160 | protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet) |
11916 | { | 12161 | { |
11917 | AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet; | 12162 | AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet; |
@@ -11919,6 +12164,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
11919 | 12164 | ||
11920 | if (cachedtex.AgentData.SessionID != SessionId) | 12165 | if (cachedtex.AgentData.SessionID != SessionId) |
11921 | return false; | 12166 | return false; |
12167 | |||
11922 | 12168 | ||
11923 | 12169 | ||
11924 | // TODO: don't create new blocks if recycling an old packet | 12170 | // TODO: don't create new blocks if recycling an old packet |
@@ -11966,32 +12212,61 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
11966 | } | 12212 | } |
11967 | } | 12213 | } |
11968 | 12214 | ||
11969 | if (cacheItems != null) | 12215 | CachedTextureRequest handlerCachedTextureRequest = OnCachedTextureRequest; |
12216 | if (handlerCachedTextureRequest != null) | ||
11970 | { | 12217 | { |
11971 | // We need to make sure the asset stored in the bake is available on this server also by its assetid before we map it to a Cacheid. | 12218 | handlerCachedTextureRequest(simclient,cachedtex.AgentData.SerialNum,requestArgs); |
11972 | // Copy the baked textures to the sim's assets cache (local only). | 12219 | } |
11973 | foreach (WearableCacheItem item in cacheItems) | 12220 | |
11974 | { | 12221 | return true; |
11975 | if (cache.GetCached(item.TextureID.ToString()) == null) | 12222 | } |
11976 | { | 12223 | */ |
11977 | item.TextureAsset.Temporary = true; | 12224 | |
11978 | item.TextureAsset.Local = true; | 12225 | protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet) |
11979 | cache.Store(item.TextureAsset); | 12226 | { |
11980 | } | 12227 | //m_log.Debug("texture cached: " + packet.ToString()); |
11981 | } | 12228 | AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet; |
12229 | AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse); | ||
12230 | |||
12231 | if (cachedtex.AgentData.SessionID != SessionId) | ||
12232 | return false; | ||
12233 | |||
12234 | // TODO: don't create new blocks if recycling an old packet | ||
12235 | cachedresp.AgentData.AgentID = AgentId; | ||
12236 | cachedresp.AgentData.SessionID = m_sessionId; | ||
12237 | cachedresp.AgentData.SerialNum = cachedtex.AgentData.SerialNum; | ||
12238 | cachedresp.WearableData = | ||
12239 | new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length]; | ||
12240 | |||
12241 | int cacheHits = 0; | ||
12242 | |||
12243 | // We need to make sure the asset stored in the bake is available on this server also by it's assetid before we map it to a Cacheid | ||
12244 | |||
12245 | WearableCacheItem[] cacheItems = null; | ||
11982 | 12246 | ||
11983 | // Return the cached textures | 12247 | ScenePresence p = m_scene.GetScenePresence(AgentId); |
12248 | |||
12249 | if (p != null && p.Appearance != null) | ||
12250 | { | ||
12251 | cacheItems = p.Appearance.WearableCacheItems; | ||
12252 | } | ||
12253 | |||
12254 | int maxWearablesLoop = cachedtex.WearableData.Length; | ||
12255 | if (maxWearablesLoop > cacheItems.Length) | ||
12256 | maxWearablesLoop = cacheItems.Length; | ||
12257 | |||
12258 | if (cacheItems != null) | ||
12259 | { | ||
11984 | for (int i = 0; i < maxWearablesLoop; i++) | 12260 | for (int i = 0; i < maxWearablesLoop; i++) |
11985 | { | 12261 | { |
11986 | WearableCacheItem item = | 12262 | int idx = cachedtex.WearableData[i].TextureIndex; |
11987 | WearableCacheItem.SearchTextureIndex(cachedtex.WearableData[i].TextureIndex, cacheItems); | ||
11988 | |||
11989 | cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); | 12263 | cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); |
11990 | cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex; | 12264 | cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex; |
11991 | cachedresp.WearableData[i].HostName = new byte[0]; | 12265 | cachedresp.WearableData[i].HostName = new byte[0]; |
11992 | if (item != null && cachedtex.WearableData[i].ID == item.CacheId) | 12266 | if (cachedtex.WearableData[i].ID == cacheItems[idx].CacheId) |
11993 | { | 12267 | { |
11994 | cachedresp.WearableData[i].TextureID = item.TextureID; | 12268 | cachedresp.WearableData[i].TextureID = cacheItems[idx].TextureID; |
12269 | cacheHits++; | ||
11995 | } | 12270 | } |
11996 | else | 12271 | else |
11997 | { | 12272 | { |
@@ -12001,7 +12276,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12001 | } | 12276 | } |
12002 | else | 12277 | else |
12003 | { | 12278 | { |
12004 | // Cached textures not available | ||
12005 | for (int i = 0; i < maxWearablesLoop; i++) | 12279 | for (int i = 0; i < maxWearablesLoop; i++) |
12006 | { | 12280 | { |
12007 | cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); | 12281 | cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); |
@@ -12010,13 +12284,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12010 | cachedresp.WearableData[i].HostName = new byte[0]; | 12284 | cachedresp.WearableData[i].HostName = new byte[0]; |
12011 | } | 12285 | } |
12012 | } | 12286 | } |
12013 | 12287 | ||
12288 | m_log.DebugFormat("texture cached: hits {0}", cacheHits); | ||
12289 | |||
12014 | cachedresp.Header.Zerocoded = true; | 12290 | cachedresp.Header.Zerocoded = true; |
12015 | OutPacket(cachedresp, ThrottleOutPacketType.Task); | 12291 | OutPacket(cachedresp, ThrottleOutPacketType.Task); |
12016 | 12292 | ||
12017 | return true; | 12293 | return true; |
12018 | } | 12294 | } |
12019 | 12295 | ||
12020 | /// <summary> | 12296 | /// <summary> |
12021 | /// Send a response back to a client when it asks the asset server (via the region server) if it has | 12297 | /// Send a response back to a client when it asks the asset server (via the region server) if it has |
12022 | /// its appearance texture cached. | 12298 | /// its appearance texture cached. |
@@ -12080,209 +12356,147 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12080 | } | 12356 | } |
12081 | else | 12357 | else |
12082 | { | 12358 | { |
12083 | // m_log.DebugFormat( | 12359 | ClientChangeObject updatehandler = onClientChangeObject; |
12084 | // "[CLIENT]: Processing block {0} type {1} for {2} {3}", | ||
12085 | // i, block.Type, part.Name, part.LocalId); | ||
12086 | 12360 | ||
12087 | // // Do this once since fetch parts creates a new array. | 12361 | if (updatehandler != null) |
12088 | // SceneObjectPart[] parts = part.ParentGroup.Parts; | 12362 | { |
12089 | // for (int j = 0; j < parts.Length; j++) | 12363 | ObjectChangeData udata = new ObjectChangeData(); |
12090 | // { | ||
12091 | // part.StoreUndoState(); | ||
12092 | // parts[j].IgnoreUndoUpdate = true; | ||
12093 | // } | ||
12094 | 12364 | ||
12095 | UpdatePrimGroupRotation handlerUpdatePrimGroupRotation; | 12365 | /*ubit from ll JIRA: |
12366 | * 0x01 position | ||
12367 | * 0x02 rotation | ||
12368 | * 0x04 scale | ||
12369 | |||
12370 | * 0x08 LINK_SET | ||
12371 | * 0x10 UNIFORM for scale | ||
12372 | */ | ||
12096 | 12373 | ||
12097 | switch (block.Type) | 12374 | // translate to internal changes |
12098 | { | 12375 | // not all cases .. just the ones older code did |
12099 | case 1: | ||
12100 | Vector3 pos1 = new Vector3(block.Data, 0); | ||
12101 | 12376 | ||
12102 | UpdateVector handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; | 12377 | switch (block.Type) |
12103 | if (handlerUpdatePrimSinglePosition != null) | 12378 | { |
12104 | { | 12379 | case 1: //change position sp |
12105 | // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z); | 12380 | udata.position = new Vector3(block.Data, 0); |
12106 | handlerUpdatePrimSinglePosition(localId, pos1, this); | ||
12107 | } | ||
12108 | break; | ||
12109 | 12381 | ||
12110 | case 2: | 12382 | udata.change = ObjectChangeType.primP; |
12111 | Quaternion rot1 = new Quaternion(block.Data, 0, true); | 12383 | updatehandler(localId, udata, this); |
12384 | break; | ||
12112 | 12385 | ||
12113 | UpdatePrimSingleRotation handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation; | 12386 | case 2: // rotation sp |
12114 | if (handlerUpdatePrimSingleRotation != null) | 12387 | udata.rotation = new Quaternion(block.Data, 0, true); |
12115 | { | ||
12116 | // m_log.Info("new tab rotation is " + rot1.X + " , " + rot1.Y + " , " + rot1.Z + " , " + rot1.W); | ||
12117 | handlerUpdatePrimSingleRotation(localId, rot1, this); | ||
12118 | } | ||
12119 | break; | ||
12120 | 12388 | ||
12121 | case 3: | 12389 | udata.change = ObjectChangeType.primR; |
12122 | Vector3 rotPos = new Vector3(block.Data, 0); | 12390 | updatehandler(localId, udata, this); |
12123 | Quaternion rot2 = new Quaternion(block.Data, 12, true); | 12391 | break; |
12124 | 12392 | ||
12125 | UpdatePrimSingleRotationPosition handlerUpdatePrimSingleRotationPosition = OnUpdatePrimSingleRotationPosition; | 12393 | case 3: // position plus rotation |
12126 | if (handlerUpdatePrimSingleRotationPosition != null) | 12394 | udata.position = new Vector3(block.Data, 0); |
12127 | { | 12395 | udata.rotation = new Quaternion(block.Data, 12, true); |
12128 | // m_log.Debug("new mouse rotation position is " + rotPos.X + " , " + rotPos.Y + " , " + rotPos.Z); | ||
12129 | // m_log.Info("new mouse rotation is " + rot2.X + " , " + rot2.Y + " , " + rot2.Z + " , " + rot2.W); | ||
12130 | handlerUpdatePrimSingleRotationPosition(localId, rot2, rotPos, this); | ||
12131 | } | ||
12132 | break; | ||
12133 | 12396 | ||
12134 | case 4: | 12397 | udata.change = ObjectChangeType.primPR; |
12135 | case 20: | 12398 | updatehandler(localId, udata, this); |
12136 | Vector3 scale4 = new Vector3(block.Data, 0); | 12399 | break; |
12137 | 12400 | ||
12138 | UpdateVector handlerUpdatePrimScale = OnUpdatePrimScale; | 12401 | case 4: // scale sp |
12139 | if (handlerUpdatePrimScale != null) | 12402 | udata.scale = new Vector3(block.Data, 0); |
12140 | { | 12403 | udata.change = ObjectChangeType.primS; |
12141 | // m_log.Debug("new scale is " + scale4.X + " , " + scale4.Y + " , " + scale4.Z); | ||
12142 | handlerUpdatePrimScale(localId, scale4, this); | ||
12143 | } | ||
12144 | break; | ||
12145 | 12404 | ||
12146 | case 5: | 12405 | updatehandler(localId, udata, this); |
12147 | Vector3 scale1 = new Vector3(block.Data, 12); | 12406 | break; |
12148 | Vector3 pos11 = new Vector3(block.Data, 0); | ||
12149 | 12407 | ||
12150 | handlerUpdatePrimScale = OnUpdatePrimScale; | 12408 | case 0x14: // uniform scale sp |
12151 | if (handlerUpdatePrimScale != null) | 12409 | udata.scale = new Vector3(block.Data, 0); |
12152 | { | ||
12153 | // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); | ||
12154 | handlerUpdatePrimScale(localId, scale1, this); | ||
12155 | 12410 | ||
12156 | handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; | 12411 | udata.change = ObjectChangeType.primUS; |
12157 | if (handlerUpdatePrimSinglePosition != null) | 12412 | updatehandler(localId, udata, this); |
12158 | { | 12413 | break; |
12159 | handlerUpdatePrimSinglePosition(localId, pos11, this); | ||
12160 | } | ||
12161 | } | ||
12162 | break; | ||
12163 | 12414 | ||
12164 | case 9: | 12415 | case 5: // scale and position sp |
12165 | Vector3 pos2 = new Vector3(block.Data, 0); | 12416 | udata.position = new Vector3(block.Data, 0); |
12417 | udata.scale = new Vector3(block.Data, 12); | ||
12166 | 12418 | ||
12167 | UpdateVector handlerUpdateVector = OnUpdatePrimGroupPosition; | 12419 | udata.change = ObjectChangeType.primPS; |
12420 | updatehandler(localId, udata, this); | ||
12421 | break; | ||
12168 | 12422 | ||
12169 | if (handlerUpdateVector != null) | 12423 | case 0x15: //uniform scale and position |
12170 | { | 12424 | udata.position = new Vector3(block.Data, 0); |
12171 | handlerUpdateVector(localId, pos2, this); | 12425 | udata.scale = new Vector3(block.Data, 12); |
12172 | } | ||
12173 | break; | ||
12174 | 12426 | ||
12175 | case 10: | 12427 | udata.change = ObjectChangeType.primPUS; |
12176 | Quaternion rot3 = new Quaternion(block.Data, 0, true); | 12428 | updatehandler(localId, udata, this); |
12429 | break; | ||
12177 | 12430 | ||
12178 | UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation; | 12431 | // now group related (bit 4) |
12179 | if (handlerUpdatePrimRotation != null) | 12432 | case 9: //( 8 + 1 )group position |
12180 | { | 12433 | udata.position = new Vector3(block.Data, 0); |
12181 | // Console.WriteLine("new rotation is " + rot3.X + " , " + rot3.Y + " , " + rot3.Z + " , " + rot3.W); | ||
12182 | handlerUpdatePrimRotation(localId, rot3, this); | ||
12183 | } | ||
12184 | break; | ||
12185 | 12434 | ||
12186 | case 11: | 12435 | udata.change = ObjectChangeType.groupP; |
12187 | Vector3 pos3 = new Vector3(block.Data, 0); | 12436 | updatehandler(localId, udata, this); |
12188 | Quaternion rot4 = new Quaternion(block.Data, 12, true); | 12437 | break; |
12189 | 12438 | ||
12190 | handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation; | 12439 | case 0x0A: // (8 + 2) group rotation |
12191 | if (handlerUpdatePrimGroupRotation != null) | 12440 | udata.rotation = new Quaternion(block.Data, 0, true); |
12192 | { | ||
12193 | // m_log.Debug("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z); | ||
12194 | // m_log.Debug("new group mouse rotation is " + rot4.X + " , " + rot4.Y + " , " + rot4.Z + " , " + rot4.W); | ||
12195 | handlerUpdatePrimGroupRotation(localId, pos3, rot4, this); | ||
12196 | } | ||
12197 | break; | ||
12198 | case 12: | ||
12199 | case 28: | ||
12200 | Vector3 scale7 = new Vector3(block.Data, 0); | ||
12201 | 12441 | ||
12202 | UpdateVector handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale; | 12442 | udata.change = ObjectChangeType.groupR; |
12203 | if (handlerUpdatePrimGroupScale != null) | 12443 | updatehandler(localId, udata, this); |
12204 | { | 12444 | break; |
12205 | // m_log.Debug("new scale is " + scale7.X + " , " + scale7.Y + " , " + scale7.Z); | ||
12206 | handlerUpdatePrimGroupScale(localId, scale7, this); | ||
12207 | } | ||
12208 | break; | ||
12209 | 12445 | ||
12210 | case 13: | 12446 | case 0x0B: //( 8 + 2 + 1) group rotation and position |
12211 | Vector3 scale2 = new Vector3(block.Data, 12); | 12447 | udata.position = new Vector3(block.Data, 0); |
12212 | Vector3 pos4 = new Vector3(block.Data, 0); | 12448 | udata.rotation = new Quaternion(block.Data, 12, true); |
12213 | 12449 | ||
12214 | handlerUpdatePrimScale = OnUpdatePrimScale; | 12450 | udata.change = ObjectChangeType.groupPR; |
12215 | if (handlerUpdatePrimScale != null) | 12451 | updatehandler(localId, udata, this); |
12216 | { | 12452 | break; |
12217 | //m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); | ||
12218 | handlerUpdatePrimScale(localId, scale2, this); | ||
12219 | 12453 | ||
12220 | // Change the position based on scale (for bug number 246) | 12454 | case 0x0C: // (8 + 4) group scale |
12221 | handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; | 12455 | // only afects root prim and only sent by viewer editor object tab scaling |
12222 | // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z); | 12456 | // mouse edition only allows uniform scaling |
12223 | if (handlerUpdatePrimSinglePosition != null) | 12457 | // SL MAY CHANGE THIS in viewers |
12224 | { | ||
12225 | handlerUpdatePrimSinglePosition(localId, pos4, this); | ||
12226 | } | ||
12227 | } | ||
12228 | break; | ||
12229 | 12458 | ||
12230 | case 29: | 12459 | udata.scale = new Vector3(block.Data, 0); |
12231 | Vector3 scale5 = new Vector3(block.Data, 12); | ||
12232 | Vector3 pos5 = new Vector3(block.Data, 0); | ||
12233 | 12460 | ||
12234 | handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale; | 12461 | udata.change = ObjectChangeType.groupS; |
12235 | if (handlerUpdatePrimGroupScale != null) | 12462 | updatehandler(localId, udata, this); |
12236 | { | ||
12237 | // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); | ||
12238 | part.StoreUndoState(true); | ||
12239 | part.IgnoreUndoUpdate = true; | ||
12240 | handlerUpdatePrimGroupScale(localId, scale5, this); | ||
12241 | handlerUpdateVector = OnUpdatePrimGroupPosition; | ||
12242 | 12463 | ||
12243 | if (handlerUpdateVector != null) | 12464 | break; |
12244 | { | ||
12245 | handlerUpdateVector(localId, pos5, this); | ||
12246 | } | ||
12247 | 12465 | ||
12248 | part.IgnoreUndoUpdate = false; | 12466 | case 0x0D: //(8 + 4 + 1) group scale and position |
12249 | } | 12467 | // exception as above |
12250 | 12468 | ||
12251 | break; | 12469 | udata.position = new Vector3(block.Data, 0); |
12470 | udata.scale = new Vector3(block.Data, 12); | ||
12252 | 12471 | ||
12253 | case 21: | 12472 | udata.change = ObjectChangeType.groupPS; |
12254 | Vector3 scale6 = new Vector3(block.Data, 12); | 12473 | updatehandler(localId, udata, this); |
12255 | Vector3 pos6 = new Vector3(block.Data, 0); | 12474 | break; |
12256 | 12475 | ||
12257 | handlerUpdatePrimScale = OnUpdatePrimScale; | 12476 | case 0x1C: // (0x10 + 8 + 4 ) group scale UNIFORM |
12258 | if (handlerUpdatePrimScale != null) | 12477 | udata.scale = new Vector3(block.Data, 0); |
12259 | { | ||
12260 | part.StoreUndoState(false); | ||
12261 | part.IgnoreUndoUpdate = true; | ||
12262 | 12478 | ||
12263 | // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); | 12479 | udata.change = ObjectChangeType.groupUS; |
12264 | handlerUpdatePrimScale(localId, scale6, this); | 12480 | updatehandler(localId, udata, this); |
12265 | handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition; | 12481 | break; |
12266 | if (handlerUpdatePrimSinglePosition != null) | ||
12267 | { | ||
12268 | handlerUpdatePrimSinglePosition(localId, pos6, this); | ||
12269 | } | ||
12270 | 12482 | ||
12271 | part.IgnoreUndoUpdate = false; | 12483 | case 0x1D: // (UNIFORM + GROUP + SCALE + POS) |
12272 | } | 12484 | udata.position = new Vector3(block.Data, 0); |
12273 | break; | 12485 | udata.scale = new Vector3(block.Data, 12); |
12274 | 12486 | ||
12275 | default: | 12487 | udata.change = ObjectChangeType.groupPUS; |
12276 | m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type)); | 12488 | updatehandler(localId, udata, this); |
12277 | break; | 12489 | break; |
12490 | |||
12491 | default: | ||
12492 | m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type)); | ||
12493 | break; | ||
12494 | } | ||
12278 | } | 12495 | } |
12279 | 12496 | ||
12280 | // for (int j = 0; j < parts.Length; j++) | ||
12281 | // parts[j].IgnoreUndoUpdate = false; | ||
12282 | } | 12497 | } |
12283 | } | 12498 | } |
12284 | } | 12499 | } |
12285 | |||
12286 | return true; | 12500 | return true; |
12287 | } | 12501 | } |
12288 | 12502 | ||
@@ -12342,7 +12556,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12342 | /// <param name="throttles"></param> | 12556 | /// <param name="throttles"></param> |
12343 | public void SetChildAgentThrottle(byte[] throttles) | 12557 | public void SetChildAgentThrottle(byte[] throttles) |
12344 | { | 12558 | { |
12345 | m_udpClient.SetThrottles(throttles); | 12559 | SetChildAgentThrottle(throttles, 1.0f); |
12560 | } | ||
12561 | |||
12562 | public void SetChildAgentThrottle(byte[] throttles,float factor) | ||
12563 | { | ||
12564 | m_udpClient.SetThrottles(throttles, factor); | ||
12565 | GenericCall2 handler = OnUpdateThrottles; | ||
12566 | if (handler != null) | ||
12567 | { | ||
12568 | handler(); | ||
12569 | } | ||
12570 | } | ||
12571 | |||
12572 | /// <summary> | ||
12573 | /// Sets the throttles from values supplied caller | ||
12574 | /// </summary> | ||
12575 | /// <param name="throttles"></param> | ||
12576 | public void SetAgentThrottleSilent(int throttle, int setting) | ||
12577 | { | ||
12578 | m_udpClient.ForceThrottleSetting(throttle,setting); | ||
12579 | } | ||
12580 | |||
12581 | public int GetAgentThrottleSilent(int throttle) | ||
12582 | { | ||
12583 | return m_udpClient.GetThrottleSetting(throttle); | ||
12346 | } | 12584 | } |
12347 | 12585 | ||
12348 | /// <summary> | 12586 | /// <summary> |
@@ -12450,8 +12688,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12450 | uint regionY = 0; | 12688 | uint regionY = 0; |
12451 | 12689 | ||
12452 | Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY); | 12690 | Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY); |
12453 | locx = Convert.ToSingle(args[0]) - (float)regionX; | 12691 | locx = (float)(Convert.ToDouble(args[0]) - (double)regionX); |
12454 | locy = Convert.ToSingle(args[1]) - (float)regionY; | 12692 | locy = (float)(Convert.ToDouble(args[1]) - (double)regionY); |
12455 | locz = Convert.ToSingle(args[2]); | 12693 | locz = Convert.ToSingle(args[2]); |
12456 | 12694 | ||
12457 | Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo; | 12695 | Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo; |
@@ -12736,7 +12974,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12736 | // "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}", | 12974 | // "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}", |
12737 | // requestID, taskID, (SourceType)sourceType, Name); | 12975 | // requestID, taskID, (SourceType)sourceType, Name); |
12738 | 12976 | ||
12977 | |||
12978 | //Note, the bool returned from the below function is useless since it is always false. | ||
12739 | m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived); | 12979 | m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived); |
12980 | |||
12740 | } | 12981 | } |
12741 | 12982 | ||
12742 | /// <summary> | 12983 | /// <summary> |
@@ -12819,7 +13060,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12819 | /// <returns></returns> | 13060 | /// <returns></returns> |
12820 | private static int CalculateNumPackets(byte[] data) | 13061 | private static int CalculateNumPackets(byte[] data) |
12821 | { | 13062 | { |
12822 | const uint m_maxPacketSize = 600; | 13063 | // const uint m_maxPacketSize = 600; |
13064 | uint m_maxPacketSize = MaxTransferBytesPerPacket; | ||
12823 | int numPackets = 1; | 13065 | int numPackets = 1; |
12824 | 13066 | ||
12825 | if (data == null) | 13067 | if (data == null) |
@@ -12930,7 +13172,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12930 | // this is the username of the *owner* | 13172 | // this is the username of the *owner* |
12931 | dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName); | 13173 | dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName); |
12932 | dialog.Data.LastName = Util.StringToBytes256(ownerLastName); | 13174 | dialog.Data.LastName = Util.StringToBytes256(ownerLastName); |
12933 | dialog.Data.Message = Util.StringToBytes256(message); | 13175 | dialog.Data.Message = Util.StringToBytes(message,512); |
12934 | 13176 | ||
12935 | ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[1]; | 13177 | ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[1]; |
12936 | buttons[0] = new ScriptDialogPacket.ButtonsBlock(); | 13178 | buttons[0] = new ScriptDialogPacket.ButtonsBlock(); |
@@ -12962,8 +13204,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
12962 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock block = | 13204 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock block = |
12963 | CreateImprovedTerseBlock(p, false); | 13205 | CreateImprovedTerseBlock(p, false); |
12964 | 13206 | ||
12965 | const float TIME_DILATION = 1.0f; | 13207 | // const float TIME_DILATION = 1.0f; |
12966 | ushort timeDilation = Utils.FloatToUInt16(TIME_DILATION, 0.0f, 1.0f); | 13208 | ushort timeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);; |
12967 | 13209 | ||
12968 | ImprovedTerseObjectUpdatePacket packet | 13210 | ImprovedTerseObjectUpdatePacket packet |
12969 | = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket( | 13211 | = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket( |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs index 0394e54..36e0a0e 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs | |||
@@ -96,9 +96,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
96 | set | 96 | set |
97 | { | 97 | { |
98 | m_throttleDebugLevel = value; | 98 | m_throttleDebugLevel = value; |
99 | /* | ||
99 | m_throttleClient.DebugLevel = m_throttleDebugLevel; | 100 | m_throttleClient.DebugLevel = m_throttleDebugLevel; |
100 | foreach (TokenBucket tb in m_throttleCategories) | 101 | foreach (TokenBucket tb in m_throttleCategories) |
101 | tb.DebugLevel = m_throttleDebugLevel; | 102 | tb.DebugLevel = m_throttleDebugLevel; |
103 | */ | ||
102 | } | 104 | } |
103 | } | 105 | } |
104 | private int m_throttleDebugLevel; | 106 | private int m_throttleDebugLevel; |
@@ -120,16 +122,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
120 | /// <summary>Sequence numbers of packets we've received (for duplicate checking)</summary> | 122 | /// <summary>Sequence numbers of packets we've received (for duplicate checking)</summary> |
121 | public readonly IncomingPacketHistoryCollection PacketArchive = new IncomingPacketHistoryCollection(200); | 123 | public readonly IncomingPacketHistoryCollection PacketArchive = new IncomingPacketHistoryCollection(200); |
122 | 124 | ||
123 | /// <summary> | ||
124 | /// If true then we take action in response to unacked reliably sent packets such as resending the packet. | ||
125 | /// </summary> | ||
126 | public bool ProcessUnackedSends { get; set; } | ||
127 | |||
128 | /// <summary>Packets we have sent that need to be ACKed by the client</summary> | 125 | /// <summary>Packets we have sent that need to be ACKed by the client</summary> |
129 | public readonly UnackedPacketCollection NeedAcks = new UnackedPacketCollection(); | 126 | public readonly UnackedPacketCollection NeedAcks = new UnackedPacketCollection(); |
130 | 127 | ||
131 | /// <summary>ACKs that are queued up, waiting to be sent to the client</summary> | 128 | /// <summary>ACKs that are queued up, waiting to be sent to the client</summary> |
132 | public readonly OpenSim.Framework.LocklessQueue<uint> PendingAcks = new OpenSim.Framework.LocklessQueue<uint>(); | 129 | public readonly DoubleLocklessQueue<uint> PendingAcks = new DoubleLocklessQueue<uint>(); |
133 | 130 | ||
134 | /// <summary>Current packet sequence number</summary> | 131 | /// <summary>Current packet sequence number</summary> |
135 | public int CurrentSequence; | 132 | public int CurrentSequence; |
@@ -181,7 +178,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
181 | /// <summary>Throttle buckets for each packet category</summary> | 178 | /// <summary>Throttle buckets for each packet category</summary> |
182 | private readonly TokenBucket[] m_throttleCategories; | 179 | private readonly TokenBucket[] m_throttleCategories; |
183 | /// <summary>Outgoing queues for throttled packets</summary> | 180 | /// <summary>Outgoing queues for throttled packets</summary> |
184 | private readonly OpenSim.Framework.LocklessQueue<OutgoingPacket>[] m_packetOutboxes = new OpenSim.Framework.LocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT]; | 181 | private readonly DoubleLocklessQueue<OutgoingPacket>[] m_packetOutboxes = new DoubleLocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT]; |
185 | /// <summary>A container that can hold one packet for each outbox, used to store | 182 | /// <summary>A container that can hold one packet for each outbox, used to store |
186 | /// dequeued packets that are being held for throttling</summary> | 183 | /// dequeued packets that are being held for throttling</summary> |
187 | private readonly OutgoingPacket[] m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT]; | 184 | private readonly OutgoingPacket[] m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT]; |
@@ -193,6 +190,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
193 | 190 | ||
194 | private int m_defaultRTO = 1000; // 1sec is the recommendation in the RFC | 191 | private int m_defaultRTO = 1000; // 1sec is the recommendation in the RFC |
195 | private int m_maxRTO = 60000; | 192 | private int m_maxRTO = 60000; |
193 | public bool m_deliverPackets = true; | ||
194 | |||
195 | private float m_burstTime; | ||
196 | |||
197 | public int m_lastStartpingTimeMS; | ||
198 | public int m_pingMS; | ||
199 | |||
200 | public int PingTimeMS | ||
201 | { | ||
202 | get | ||
203 | { | ||
204 | if (m_pingMS < 10) | ||
205 | return 10; | ||
206 | if(m_pingMS > 2000) | ||
207 | return 2000; | ||
208 | return m_pingMS; | ||
209 | } | ||
210 | } | ||
196 | 211 | ||
197 | /// <summary> | 212 | /// <summary> |
198 | /// This is the percentage of the udp texture queue to add to the task queue since | 213 | /// This is the percentage of the udp texture queue to add to the task queue since |
@@ -232,31 +247,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
232 | if (maxRTO != 0) | 247 | if (maxRTO != 0) |
233 | m_maxRTO = maxRTO; | 248 | m_maxRTO = maxRTO; |
234 | 249 | ||
235 | ProcessUnackedSends = true; | 250 | m_burstTime = rates.BrustTime; |
251 | float m_burst = rates.ClientMaxRate * m_burstTime; | ||
236 | 252 | ||
237 | // Create a token bucket throttle for this client that has the scene token bucket as a parent | 253 | // Create a token bucket throttle for this client that has the scene token bucket as a parent |
238 | m_throttleClient | 254 | m_throttleClient = new AdaptiveTokenBucket(parentThrottle, rates.ClientMaxRate, m_burst, rates.AdaptiveThrottlesEnabled); |
239 | = new AdaptiveTokenBucket( | ||
240 | string.Format("adaptive throttle for {0} in {1}", AgentID, server.Scene.Name), | ||
241 | parentThrottle, 0, rates.Total, rates.MinimumAdaptiveThrottleRate, rates.AdaptiveThrottlesEnabled); | ||
242 | 255 | ||
243 | // Create an array of token buckets for this clients different throttle categories | 256 | // Create an array of token buckets for this clients different throttle categories |
244 | m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT]; | 257 | m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT]; |
245 | 258 | ||
246 | m_cannibalrate = rates.CannibalizeTextureRate; | 259 | m_cannibalrate = rates.CannibalizeTextureRate; |
247 | 260 | ||
261 | m_burst = rates.Total * rates.BrustTime; | ||
262 | |||
248 | for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) | 263 | for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) |
249 | { | 264 | { |
250 | ThrottleOutPacketType type = (ThrottleOutPacketType)i; | 265 | ThrottleOutPacketType type = (ThrottleOutPacketType)i; |
251 | 266 | ||
252 | // Initialize the packet outboxes, where packets sit while they are waiting for tokens | 267 | // Initialize the packet outboxes, where packets sit while they are waiting for tokens |
253 | m_packetOutboxes[i] = new OpenSim.Framework.LocklessQueue<OutgoingPacket>(); | 268 | m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>(); |
254 | |||
255 | // Initialize the token buckets that control the throttling for each category | 269 | // Initialize the token buckets that control the throttling for each category |
256 | m_throttleCategories[i] | 270 | m_throttleCategories[i] = new TokenBucket(m_throttleClient, rates.GetRate(type), m_burst); |
257 | = new TokenBucket( | ||
258 | string.Format("{0} throttle for {1} in {2}", type, AgentID, server.Scene.Name), | ||
259 | m_throttleClient, rates.GetRate(type), 0); | ||
260 | } | 271 | } |
261 | 272 | ||
262 | // Default the retransmission timeout to one second | 273 | // Default the retransmission timeout to one second |
@@ -264,6 +275,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
264 | 275 | ||
265 | // Initialize this to a sane value to prevent early disconnects | 276 | // Initialize this to a sane value to prevent early disconnects |
266 | TickLastPacketReceived = Environment.TickCount & Int32.MaxValue; | 277 | TickLastPacketReceived = Environment.TickCount & Int32.MaxValue; |
278 | m_pingMS = (int)(3.0 * server.TickCountResolution); // so filter doesnt start at 0; | ||
267 | } | 279 | } |
268 | 280 | ||
269 | /// <summary> | 281 | /// <summary> |
@@ -302,9 +314,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
302 | m_info.assetThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Asset].DripRate; | 314 | m_info.assetThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Asset].DripRate; |
303 | m_info.textureThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Texture].DripRate; | 315 | m_info.textureThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Texture].DripRate; |
304 | m_info.totalThrottle = (int)m_throttleClient.DripRate; | 316 | m_info.totalThrottle = (int)m_throttleClient.DripRate; |
305 | m_info.targetThrottle = (int)m_throttleClient.TargetDripRate; | ||
306 | m_info.maxThrottle = (int)m_throttleClient.MaxDripRate; | ||
307 | |||
308 | return m_info; | 317 | return m_info; |
309 | } | 318 | } |
310 | 319 | ||
@@ -341,8 +350,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
341 | /// <param name="throttleType"></param> | 350 | /// <param name="throttleType"></param> |
342 | public int GetPacketsQueuedCount(ThrottleOutPacketType throttleType) | 351 | public int GetPacketsQueuedCount(ThrottleOutPacketType throttleType) |
343 | { | 352 | { |
344 | if ((int)throttleType > 0) | 353 | int icat = (int)throttleType; |
345 | return m_packetOutboxes[(int)throttleType].Count; | 354 | if (icat > 0 && icat < THROTTLE_CATEGORY_COUNT) |
355 | return m_packetOutboxes[icat].Count; | ||
346 | else | 356 | else |
347 | return 0; | 357 | return 0; |
348 | } | 358 | } |
@@ -389,6 +399,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
389 | 399 | ||
390 | public void SetThrottles(byte[] throttleData) | 400 | public void SetThrottles(byte[] throttleData) |
391 | { | 401 | { |
402 | SetThrottles(throttleData, 1.0f); | ||
403 | } | ||
404 | |||
405 | public void SetThrottles(byte[] throttleData, float factor) | ||
406 | { | ||
392 | byte[] adjData; | 407 | byte[] adjData; |
393 | int pos = 0; | 408 | int pos = 0; |
394 | 409 | ||
@@ -408,24 +423,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
408 | } | 423 | } |
409 | 424 | ||
410 | // 0.125f converts from bits to bytes | 425 | // 0.125f converts from bits to bytes |
411 | int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | 426 | float scale = 0.125f * factor; |
412 | int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | 427 | int resend = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4; |
413 | int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | 428 | int land = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4; |
414 | int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | 429 | int wind = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4; |
415 | int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | 430 | int cloud = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4; |
416 | int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | 431 | int task = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4; |
417 | int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | 432 | int texture = (int)(BitConverter.ToSingle(adjData, pos) * scale); pos += 4; |
433 | int asset = (int)(BitConverter.ToSingle(adjData, pos) * scale); | ||
434 | |||
418 | 435 | ||
419 | if (ThrottleDebugLevel > 0) | ||
420 | { | ||
421 | long total = resend + land + wind + cloud + task + texture + asset; | ||
422 | m_log.DebugFormat( | ||
423 | "[LLUDPCLIENT]: {0} is setting throttles in {1} to Resend={2}, Land={3}, Wind={4}, Cloud={5}, Task={6}, Texture={7}, Asset={8}, TOTAL = {9}", | ||
424 | AgentID, m_udpServer.Scene.Name, resend, land, wind, cloud, task, texture, asset, total); | ||
425 | } | ||
426 | 436 | ||
427 | // Make sure none of the throttles are set below our packet MTU, | 437 | // Make sure none of the throttles are set below our packet MTU, |
428 | // otherwise a throttle could become permanently clogged | 438 | // otherwise a throttle could become permanently clogged |
439 | |||
440 | /* now using floats | ||
429 | resend = Math.Max(resend, LLUDPServer.MTU); | 441 | resend = Math.Max(resend, LLUDPServer.MTU); |
430 | land = Math.Max(land, LLUDPServer.MTU); | 442 | land = Math.Max(land, LLUDPServer.MTU); |
431 | wind = Math.Max(wind, LLUDPServer.MTU); | 443 | wind = Math.Max(wind, LLUDPServer.MTU); |
@@ -433,52 +445,54 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
433 | task = Math.Max(task, LLUDPServer.MTU); | 445 | task = Math.Max(task, LLUDPServer.MTU); |
434 | texture = Math.Max(texture, LLUDPServer.MTU); | 446 | texture = Math.Max(texture, LLUDPServer.MTU); |
435 | asset = Math.Max(asset, LLUDPServer.MTU); | 447 | asset = Math.Max(asset, LLUDPServer.MTU); |
448 | */ | ||
436 | 449 | ||
437 | // Since most textures are now delivered through http, make it possible | 450 | // Since most textures are now delivered through http, make it possible |
438 | // to cannibalize some of the bw from the texture throttle to use for | 451 | // to cannibalize some of the bw from the texture throttle to use for |
439 | // the task queue (e.g. object updates) | 452 | // the task queue (e.g. object updates) |
440 | task = task + (int)(m_cannibalrate * texture); | 453 | task = task + (int)(m_cannibalrate * texture); |
441 | texture = (int)((1 - m_cannibalrate) * texture); | 454 | texture = (int)((1 - m_cannibalrate) * texture); |
442 | 455 | ||
443 | //int total = resend + land + wind + cloud + task + texture + asset; | 456 | int total = resend + land + wind + cloud + task + texture + asset; |
457 | |||
458 | float m_burst = total * m_burstTime; | ||
444 | 459 | ||
445 | if (ThrottleDebugLevel > 0) | 460 | if (ThrottleDebugLevel > 0) |
446 | { | 461 | { |
447 | long total = resend + land + wind + cloud + task + texture + asset; | ||
448 | m_log.DebugFormat( | 462 | m_log.DebugFormat( |
449 | "[LLUDPCLIENT]: {0} is setting throttles in {1} to Resend={2}, Land={3}, Wind={4}, Cloud={5}, Task={6}, Texture={7}, Asset={8}, TOTAL = {9}", | 463 | "[LLUDPCLIENT]: {0} is setting throttles in {1} to Resend={2}, Land={3}, Wind={4}, Cloud={5}, Task={6}, Texture={7}, Asset={8}, TOTAL = {9}", |
450 | AgentID, m_udpServer.Scene.Name, resend, land, wind, cloud, task, texture, asset, total); | 464 | AgentID, m_udpServer.Scene.Name, resend, land, wind, cloud, task, texture, asset, total); |
451 | } | 465 | } |
452 | 466 | ||
453 | // Update the token buckets with new throttle values | ||
454 | if (m_throttleClient.AdaptiveEnabled) | ||
455 | { | ||
456 | long total = resend + land + wind + cloud + task + texture + asset; | ||
457 | m_throttleClient.TargetDripRate = total; | ||
458 | } | ||
459 | |||
460 | TokenBucket bucket; | 467 | TokenBucket bucket; |
461 | 468 | ||
462 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Resend]; | 469 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Resend]; |
463 | bucket.RequestedDripRate = resend; | 470 | bucket.RequestedDripRate = resend; |
471 | bucket.RequestedBurst = m_burst; | ||
464 | 472 | ||
465 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Land]; | 473 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Land]; |
466 | bucket.RequestedDripRate = land; | 474 | bucket.RequestedDripRate = land; |
475 | bucket.RequestedBurst = m_burst; | ||
467 | 476 | ||
468 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Wind]; | 477 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Wind]; |
469 | bucket.RequestedDripRate = wind; | 478 | bucket.RequestedDripRate = wind; |
479 | bucket.RequestedBurst = m_burst; | ||
470 | 480 | ||
471 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Cloud]; | 481 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Cloud]; |
472 | bucket.RequestedDripRate = cloud; | 482 | bucket.RequestedDripRate = cloud; |
483 | bucket.RequestedBurst = m_burst; | ||
473 | 484 | ||
474 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Asset]; | 485 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Asset]; |
475 | bucket.RequestedDripRate = asset; | 486 | bucket.RequestedDripRate = asset; |
487 | bucket.RequestedBurst = m_burst; | ||
476 | 488 | ||
477 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Task]; | 489 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Task]; |
478 | bucket.RequestedDripRate = task; | 490 | bucket.RequestedDripRate = task; |
491 | bucket.RequestedBurst = m_burst; | ||
479 | 492 | ||
480 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Texture]; | 493 | bucket = m_throttleCategories[(int)ThrottleOutPacketType.Texture]; |
481 | bucket.RequestedDripRate = texture; | 494 | bucket.RequestedDripRate = texture; |
495 | bucket.RequestedBurst = m_burst; | ||
482 | 496 | ||
483 | // Reset the packed throttles cached data | 497 | // Reset the packed throttles cached data |
484 | m_packedThrottles = null; | 498 | m_packedThrottles = null; |
@@ -496,25 +510,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
496 | int i = 0; | 510 | int i = 0; |
497 | 511 | ||
498 | // multiply by 8 to convert bytes back to bits | 512 | // multiply by 8 to convert bytes back to bits |
499 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Resend].RequestedDripRate * 8 * multiplier; | 513 | multiplier *= 8; |
514 | |||
515 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Resend].RequestedDripRate * multiplier; | ||
500 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; | 516 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; |
501 | 517 | ||
502 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Land].RequestedDripRate * 8 * multiplier; | 518 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Land].RequestedDripRate * multiplier; |
503 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; | 519 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; |
504 | 520 | ||
505 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Wind].RequestedDripRate * 8 * multiplier; | 521 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Wind].RequestedDripRate * multiplier; |
506 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; | 522 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; |
507 | 523 | ||
508 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Cloud].RequestedDripRate * 8 * multiplier; | 524 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Cloud].RequestedDripRate * multiplier; |
509 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; | 525 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; |
510 | 526 | ||
511 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Task].RequestedDripRate * 8 * multiplier; | 527 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Task].RequestedDripRate * multiplier; |
512 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; | 528 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; |
513 | 529 | ||
514 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Texture].RequestedDripRate * 8 * multiplier; | 530 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Texture].RequestedDripRate * multiplier; |
515 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; | 531 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; |
516 | 532 | ||
517 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Asset].RequestedDripRate * 8 * multiplier; | 533 | rate = (float)m_throttleCategories[(int)ThrottleOutPacketType.Asset].RequestedDripRate * multiplier; |
518 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; | 534 | Buffer.BlockCopy(Utils.FloatToBytes(rate), 0, data, i, 4); i += 4; |
519 | 535 | ||
520 | m_packedThrottles = data; | 536 | m_packedThrottles = data; |
@@ -522,6 +538,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
522 | 538 | ||
523 | return data; | 539 | return data; |
524 | } | 540 | } |
541 | |||
542 | public int GetCatBytesCanSend(ThrottleOutPacketType cat, int timeMS) | ||
543 | { | ||
544 | int icat = (int)cat; | ||
545 | if (icat > 0 && icat < THROTTLE_CATEGORY_COUNT) | ||
546 | { | ||
547 | TokenBucket bucket = m_throttleCategories[icat]; | ||
548 | return bucket.GetCatBytesCanSend(timeMS); | ||
549 | } | ||
550 | else | ||
551 | return 0; | ||
552 | } | ||
525 | 553 | ||
526 | /// <summary> | 554 | /// <summary> |
527 | /// Queue an outgoing packet if appropriate. | 555 | /// Queue an outgoing packet if appropriate. |
@@ -534,32 +562,42 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
534 | /// </returns> | 562 | /// </returns> |
535 | public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue) | 563 | public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue) |
536 | { | 564 | { |
565 | return EnqueueOutgoing(packet, forceQueue, false); | ||
566 | } | ||
567 | |||
568 | public bool EnqueueOutgoing(OutgoingPacket packet, bool forceQueue, bool highPriority) | ||
569 | { | ||
537 | int category = (int)packet.Category; | 570 | int category = (int)packet.Category; |
538 | 571 | ||
539 | if (category >= 0 && category < m_packetOutboxes.Length) | 572 | if (category >= 0 && category < m_packetOutboxes.Length) |
540 | { | 573 | { |
541 | OpenSim.Framework.LocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category]; | 574 | DoubleLocklessQueue<OutgoingPacket> queue = m_packetOutboxes[category]; |
575 | |||
576 | if (m_deliverPackets == false) | ||
577 | { | ||
578 | queue.Enqueue(packet, highPriority); | ||
579 | return true; | ||
580 | } | ||
581 | |||
542 | TokenBucket bucket = m_throttleCategories[category]; | 582 | TokenBucket bucket = m_throttleCategories[category]; |
543 | 583 | ||
544 | // Don't send this packet if there is already a packet waiting in the queue | 584 | // Don't send this packet if queue is not empty |
545 | // even if we have the tokens to send it, tokens should go to the already | 585 | if (queue.Count > 0 || m_nextPackets[category] != null) |
546 | // queued packets | ||
547 | if (queue.Count > 0) | ||
548 | { | 586 | { |
549 | queue.Enqueue(packet); | 587 | queue.Enqueue(packet, highPriority); |
550 | return true; | 588 | return true; |
551 | } | 589 | } |
552 | 590 | ||
553 | 591 | if (!forceQueue && bucket.CheckTokens(packet.Buffer.DataLength)) | |
554 | if (!forceQueue && bucket.RemoveTokens(packet.Buffer.DataLength)) | ||
555 | { | 592 | { |
556 | // Enough tokens were removed from the bucket, the packet will not be queued | 593 | // enough tokens so it can be sent imediatly by caller |
594 | bucket.RemoveTokens(packet.Buffer.DataLength); | ||
557 | return false; | 595 | return false; |
558 | } | 596 | } |
559 | else | 597 | else |
560 | { | 598 | { |
561 | // Force queue specified or not enough tokens in the bucket, queue this packet | 599 | // Force queue specified or not enough tokens in the bucket, queue this packet |
562 | queue.Enqueue(packet); | 600 | queue.Enqueue(packet, highPriority); |
563 | return true; | 601 | return true; |
564 | } | 602 | } |
565 | } | 603 | } |
@@ -568,6 +606,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
568 | // We don't have a token bucket for this category, so it will not be queued | 606 | // We don't have a token bucket for this category, so it will not be queued |
569 | return false; | 607 | return false; |
570 | } | 608 | } |
609 | |||
571 | } | 610 | } |
572 | 611 | ||
573 | /// <summary> | 612 | /// <summary> |
@@ -588,8 +627,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
588 | /// <returns>True if any packets were sent, otherwise false</returns> | 627 | /// <returns>True if any packets were sent, otherwise false</returns> |
589 | public bool DequeueOutgoing() | 628 | public bool DequeueOutgoing() |
590 | { | 629 | { |
591 | OutgoingPacket packet; | 630 | // if (m_deliverPackets == false) return false; |
592 | OpenSim.Framework.LocklessQueue<OutgoingPacket> queue; | 631 | |
632 | OutgoingPacket packet = null; | ||
633 | DoubleLocklessQueue<OutgoingPacket> queue; | ||
593 | TokenBucket bucket; | 634 | TokenBucket bucket; |
594 | bool packetSent = false; | 635 | bool packetSent = false; |
595 | ThrottleOutPacketTypeFlags emptyCategories = 0; | 636 | ThrottleOutPacketTypeFlags emptyCategories = 0; |
@@ -613,6 +654,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
613 | m_udpServer.SendPacketFinal(nextPacket); | 654 | m_udpServer.SendPacketFinal(nextPacket); |
614 | m_nextPackets[i] = null; | 655 | m_nextPackets[i] = null; |
615 | packetSent = true; | 656 | packetSent = true; |
657 | |||
658 | if (m_packetOutboxes[i].Count < 5) | ||
659 | emptyCategories |= CategoryToFlag(i); | ||
616 | } | 660 | } |
617 | } | 661 | } |
618 | else | 662 | else |
@@ -620,32 +664,47 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
620 | // No dequeued packet waiting to be sent, try to pull one off | 664 | // No dequeued packet waiting to be sent, try to pull one off |
621 | // this queue | 665 | // this queue |
622 | queue = m_packetOutboxes[i]; | 666 | queue = m_packetOutboxes[i]; |
623 | if (queue.Dequeue(out packet)) | 667 | if (queue != null) |
624 | { | 668 | { |
625 | // A packet was pulled off the queue. See if we have | 669 | bool success = false; |
626 | // enough tokens in the bucket to send it out | 670 | try |
627 | if (bucket.RemoveTokens(packet.Buffer.DataLength)) | ||
628 | { | 671 | { |
629 | // Send the packet | 672 | success = queue.Dequeue(out packet); |
630 | m_udpServer.SendPacketFinal(packet); | ||
631 | packetSent = true; | ||
632 | } | 673 | } |
633 | else | 674 | catch |
634 | { | 675 | { |
635 | // Save the dequeued packet for the next iteration | 676 | m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>(); |
636 | m_nextPackets[i] = packet; | ||
637 | } | 677 | } |
678 | if (success) | ||
679 | { | ||
680 | // A packet was pulled off the queue. See if we have | ||
681 | // enough tokens in the bucket to send it out | ||
682 | if (bucket.RemoveTokens(packet.Buffer.DataLength)) | ||
683 | { | ||
684 | // Send the packet | ||
685 | m_udpServer.SendPacketFinal(packet); | ||
686 | packetSent = true; | ||
687 | |||
688 | if (queue.Count < 5) | ||
689 | emptyCategories |= CategoryToFlag(i); | ||
690 | } | ||
691 | else | ||
692 | { | ||
693 | // Save the dequeued packet for the next iteration | ||
694 | m_nextPackets[i] = packet; | ||
695 | } | ||
638 | 696 | ||
639 | // If the queue is empty after this dequeue, fire the queue | 697 | } |
640 | // empty callback now so it has a chance to fill before we | 698 | else |
641 | // get back here | 699 | { |
642 | if (queue.Count == 0) | 700 | // No packets in this queue. Fire the queue empty callback |
701 | // if it has not been called recently | ||
643 | emptyCategories |= CategoryToFlag(i); | 702 | emptyCategories |= CategoryToFlag(i); |
703 | } | ||
644 | } | 704 | } |
645 | else | 705 | else |
646 | { | 706 | { |
647 | // No packets in this queue. Fire the queue empty callback | 707 | m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>(); |
648 | // if it has not been called recently | ||
649 | emptyCategories |= CategoryToFlag(i); | 708 | emptyCategories |= CategoryToFlag(i); |
650 | } | 709 | } |
651 | } | 710 | } |
@@ -712,6 +771,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
712 | RTO = Math.Min(RTO * 2, m_maxRTO); | 771 | RTO = Math.Min(RTO * 2, m_maxRTO); |
713 | } | 772 | } |
714 | 773 | ||
774 | |||
775 | const int MIN_CALLBACK_MS = 10; | ||
776 | |||
715 | /// <summary> | 777 | /// <summary> |
716 | /// Does an early check to see if this queue empty callback is already | 778 | /// Does an early check to see if this queue empty callback is already |
717 | /// running, then asynchronously firing the event | 779 | /// running, then asynchronously firing the event |
@@ -719,24 +781,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
719 | /// <param name="categories">Throttle categories to fire the callback for</param> | 781 | /// <param name="categories">Throttle categories to fire the callback for</param> |
720 | private void BeginFireQueueEmpty(ThrottleOutPacketTypeFlags categories) | 782 | private void BeginFireQueueEmpty(ThrottleOutPacketTypeFlags categories) |
721 | { | 783 | { |
722 | // if (m_nextOnQueueEmpty != 0 && (Environment.TickCount & Int32.MaxValue) >= m_nextOnQueueEmpty) | 784 | if (!m_isQueueEmptyRunning) |
723 | if (!m_isQueueEmptyRunning && (Environment.TickCount & Int32.MaxValue) >= m_nextOnQueueEmpty) | ||
724 | { | 785 | { |
725 | m_isQueueEmptyRunning = true; | ||
726 | |||
727 | int start = Environment.TickCount & Int32.MaxValue; | 786 | int start = Environment.TickCount & Int32.MaxValue; |
728 | const int MIN_CALLBACK_MS = 30; | 787 | |
788 | if (start < m_nextOnQueueEmpty) | ||
789 | return; | ||
790 | |||
791 | m_isQueueEmptyRunning = true; | ||
729 | 792 | ||
730 | m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; | 793 | m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; |
731 | if (m_nextOnQueueEmpty == 0) | 794 | if (m_nextOnQueueEmpty == 0) |
732 | m_nextOnQueueEmpty = 1; | 795 | m_nextOnQueueEmpty = 1; |
733 | 796 | ||
734 | // Use a value of 0 to signal that FireQueueEmpty is running | 797 | if (HasUpdates(categories)) |
735 | // m_nextOnQueueEmpty = 0; | ||
736 | |||
737 | m_categories = categories; | ||
738 | |||
739 | if (HasUpdates(m_categories)) | ||
740 | { | 798 | { |
741 | if (!m_udpServer.OqrEngine.IsRunning) | 799 | if (!m_udpServer.OqrEngine.IsRunning) |
742 | { | 800 | { |
@@ -756,7 +814,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
756 | } | 814 | } |
757 | 815 | ||
758 | private bool m_isQueueEmptyRunning; | 816 | private bool m_isQueueEmptyRunning; |
759 | private ThrottleOutPacketTypeFlags m_categories = 0; | 817 | |
760 | 818 | ||
761 | /// <summary> | 819 | /// <summary> |
762 | /// Fires the OnQueueEmpty callback and sets the minimum time that it | 820 | /// Fires the OnQueueEmpty callback and sets the minimum time that it |
@@ -767,33 +825,33 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
767 | /// signature</param> | 825 | /// signature</param> |
768 | public void FireQueueEmpty(object o) | 826 | public void FireQueueEmpty(object o) |
769 | { | 827 | { |
770 | // m_log.DebugFormat("[LLUDPCLIENT]: FireQueueEmpty for {0} in {1}", AgentID, m_udpServer.Scene.Name); | 828 | ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o; |
771 | 829 | QueueEmpty callback = OnQueueEmpty; | |
772 | // int start = Environment.TickCount & Int32.MaxValue; | ||
773 | // const int MIN_CALLBACK_MS = 30; | ||
774 | 830 | ||
775 | // if (m_udpServer.IsRunningOutbound) | 831 | if (callback != null) |
776 | // { | 832 | { |
777 | ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o; | 833 | // if (m_udpServer.IsRunningOutbound) |
778 | QueueEmpty callback = OnQueueEmpty; | 834 | // { |
779 | 835 | try { callback(categories); } | |
780 | if (callback != null) | 836 | catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); } |
781 | { | 837 | // } |
782 | // if (m_udpServer.IsRunningOutbound) | 838 | } |
783 | // { | ||
784 | try { callback(categories); } | ||
785 | catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); } | ||
786 | // } | ||
787 | } | ||
788 | // } | ||
789 | 839 | ||
790 | // m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; | 840 | m_isQueueEmptyRunning = false; |
791 | // if (m_nextOnQueueEmpty == 0) | 841 | } |
792 | // m_nextOnQueueEmpty = 1; | ||
793 | 842 | ||
794 | // } | 843 | internal void ForceThrottleSetting(int throttle, int setting) |
844 | { | ||
845 | if (throttle > 0 && throttle < THROTTLE_CATEGORY_COUNT) | ||
846 | m_throttleCategories[throttle].RequestedDripRate = Math.Max(setting, LLUDPServer.MTU); | ||
847 | } | ||
795 | 848 | ||
796 | m_isQueueEmptyRunning = false; | 849 | internal int GetThrottleSetting(int throttle) |
850 | { | ||
851 | if (throttle > 0 && throttle < THROTTLE_CATEGORY_COUNT) | ||
852 | return (int)m_throttleCategories[throttle].RequestedDripRate; | ||
853 | else | ||
854 | return 0; | ||
797 | } | 855 | } |
798 | 856 | ||
799 | /// <summary> | 857 | /// <summary> |
@@ -839,4 +897,33 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
839 | } | 897 | } |
840 | } | 898 | } |
841 | } | 899 | } |
900 | |||
901 | public class DoubleLocklessQueue<T> : OpenSim.Framework.LocklessQueue<T> | ||
902 | { | ||
903 | OpenSim.Framework.LocklessQueue<T> highQueue = new OpenSim.Framework.LocklessQueue<T>(); | ||
904 | |||
905 | public override int Count | ||
906 | { | ||
907 | get | ||
908 | { | ||
909 | return base.Count + highQueue.Count; | ||
910 | } | ||
911 | } | ||
912 | |||
913 | public override bool Dequeue(out T item) | ||
914 | { | ||
915 | if (highQueue.Dequeue(out item)) | ||
916 | return true; | ||
917 | |||
918 | return base.Dequeue(out item); | ||
919 | } | ||
920 | |||
921 | public void Enqueue(T item, bool highPriority) | ||
922 | { | ||
923 | if (highPriority) | ||
924 | highQueue.Enqueue(item); | ||
925 | else | ||
926 | Enqueue(item); | ||
927 | } | ||
928 | } | ||
842 | } | 929 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 4528714..8f345e7 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | |||
@@ -284,7 +284,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
284 | /// <summary>Handlers for incoming packets</summary> | 284 | /// <summary>Handlers for incoming packets</summary> |
285 | //PacketEventDictionary packetEvents = new PacketEventDictionary(); | 285 | //PacketEventDictionary packetEvents = new PacketEventDictionary(); |
286 | /// <summary>Incoming packets that are awaiting handling</summary> | 286 | /// <summary>Incoming packets that are awaiting handling</summary> |
287 | private OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>(); | 287 | //private OpenMetaverse.BlockingQueue<IncomingPacket> packetInbox = new OpenMetaverse.BlockingQueue<IncomingPacket>(); |
288 | |||
289 | private DoubleQueue<IncomingPacket> packetInbox = new DoubleQueue<IncomingPacket>(); | ||
288 | 290 | ||
289 | /// <summary>Bandwidth throttle for this UDP server</summary> | 291 | /// <summary>Bandwidth throttle for this UDP server</summary> |
290 | public TokenBucket Throttle { get; private set; } | 292 | public TokenBucket Throttle { get; private set; } |
@@ -342,14 +344,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
342 | /// <summary>Flag to signal when clients should send pings</summary> | 344 | /// <summary>Flag to signal when clients should send pings</summary> |
343 | protected bool m_sendPing; | 345 | protected bool m_sendPing; |
344 | 346 | ||
347 | private int m_animationSequenceNumber; | ||
348 | |||
349 | public int NextAnimationSequenceNumber | ||
350 | { | ||
351 | get | ||
352 | { | ||
353 | m_animationSequenceNumber++; | ||
354 | if (m_animationSequenceNumber > 2147482624) | ||
355 | m_animationSequenceNumber = 1; | ||
356 | return m_animationSequenceNumber; | ||
357 | } | ||
358 | } | ||
359 | |||
360 | |||
361 | |||
362 | private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>(); | ||
363 | |||
345 | /// <summary> | 364 | /// <summary> |
346 | /// Event used to signal when queued packets are available for sending. | 365 | /// Event used to signal when queued packets are available for sending. |
347 | /// </summary> | 366 | /// </summary> |
348 | /// <remarks> | 367 | /// <remarks> |
349 | /// This allows the outbound loop to only operate when there is data to send rather than continuously polling. | 368 | /// This allows the outbound loop to only operate when there is data to send rather than continuously polling. |
350 | /// Some data is sent immediately and not queued. That data would not trigger this event. | 369 | /// Some data is sent immediately and not queued. That data would not trigger this event. |
370 | /// WRONG use. May be usefull in future revision | ||
351 | /// </remarks> | 371 | /// </remarks> |
352 | private AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false); | 372 | // private AutoResetEvent m_dataPresentEvent = new AutoResetEvent(false); |
353 | 373 | ||
354 | private Pool<IncomingPacket> m_incomingPacketPool; | 374 | private Pool<IncomingPacket> m_incomingPacketPool; |
355 | 375 | ||
@@ -431,16 +451,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
431 | 451 | ||
432 | // Measure the resolution of Environment.TickCount | 452 | // Measure the resolution of Environment.TickCount |
433 | TickCountResolution = 0f; | 453 | TickCountResolution = 0f; |
434 | for (int i = 0; i < 5; i++) | 454 | for (int i = 0; i < 10; i++) |
435 | { | 455 | { |
436 | int start = Environment.TickCount; | 456 | int start = Environment.TickCount; |
437 | int now = start; | 457 | int now = start; |
438 | while (now == start) | 458 | while (now == start) |
439 | now = Environment.TickCount; | 459 | now = Environment.TickCount; |
440 | TickCountResolution += (float)(now - start) * 0.2f; | 460 | TickCountResolution += (float)(now - start) * 0.1f; |
441 | } | 461 | } |
442 | m_log.Info("[LLUDPSERVER]: Average Environment.TickCount resolution: " + TickCountResolution + "ms"); | ||
443 | TickCountResolution = (float)Math.Ceiling(TickCountResolution); | 462 | TickCountResolution = (float)Math.Ceiling(TickCountResolution); |
463 | m_log.Info("[LLUDPSERVER]: Average Environment.TickCount resolution: " + TickCountResolution + "ms"); | ||
444 | 464 | ||
445 | #endregion Environment.TickCount Measurement | 465 | #endregion Environment.TickCount Measurement |
446 | 466 | ||
@@ -448,6 +468,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
448 | int sceneThrottleBps = 0; | 468 | int sceneThrottleBps = 0; |
449 | bool usePools = false; | 469 | bool usePools = false; |
450 | 470 | ||
471 | |||
472 | |||
451 | IConfig config = configSource.Configs["ClientStack.LindenUDP"]; | 473 | IConfig config = configSource.Configs["ClientStack.LindenUDP"]; |
452 | if (config != null) | 474 | if (config != null) |
453 | { | 475 | { |
@@ -494,15 +516,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
494 | } | 516 | } |
495 | #endregion BinaryStats | 517 | #endregion BinaryStats |
496 | 518 | ||
497 | // FIXME: Can't add info here because don't know scene yet. | 519 | Throttle = new TokenBucket(null, sceneThrottleBps, sceneThrottleBps * 10e-3f); |
498 | // m_throttle | ||
499 | // = new TokenBucket( | ||
500 | // string.Format("server throttle bucket for {0}", Scene.Name), null, sceneThrottleBps); | ||
501 | |||
502 | Throttle = new TokenBucket("server throttle bucket", null, 0, sceneThrottleBps); | ||
503 | |||
504 | ThrottleRates = new ThrottleRates(configSource); | 520 | ThrottleRates = new ThrottleRates(configSource); |
505 | 521 | ||
522 | Random rnd = new Random(Util.EnvironmentTickCount()); | ||
523 | m_animationSequenceNumber = rnd.Next(11474826); | ||
524 | |||
506 | if (usePools) | 525 | if (usePools) |
507 | EnablePools(); | 526 | EnablePools(); |
508 | } | 527 | } |
@@ -798,8 +817,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
798 | if (UsePools) | 817 | if (UsePools) |
799 | EnablePoolStats(); | 818 | EnablePoolStats(); |
800 | 819 | ||
820 | |||
801 | LLUDPServerCommands commands = new LLUDPServerCommands(MainConsole.Instance, this); | 821 | LLUDPServerCommands commands = new LLUDPServerCommands(MainConsole.Instance, this); |
802 | commands.Register(); | 822 | commands.Register(); |
823 | |||
803 | } | 824 | } |
804 | 825 | ||
805 | public bool HandlesRegion(Location x) | 826 | public bool HandlesRegion(Location x) |
@@ -907,8 +928,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
907 | 928 | ||
908 | PacketPool.Instance.ReturnPacket(packet); | 929 | PacketPool.Instance.ReturnPacket(packet); |
909 | 930 | ||
910 | if (packetQueued) | 931 | /// WRONG use. May be usefull in future revision |
911 | m_dataPresentEvent.Set(); | 932 | // if (packetQueued) |
933 | // m_dataPresentEvent.Set(); | ||
912 | } | 934 | } |
913 | 935 | ||
914 | /// <summary> | 936 | /// <summary> |
@@ -969,8 +991,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
969 | bufferSize = dataLength; | 991 | bufferSize = dataLength; |
970 | buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize); | 992 | buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize); |
971 | 993 | ||
972 | // m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" + | 994 | m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" + |
973 | // type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet"); | 995 | type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length); |
974 | Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); | 996 | Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); |
975 | } | 997 | } |
976 | } | 998 | } |
@@ -979,6 +1001,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
979 | 1001 | ||
980 | #region Queue or Send | 1002 | #region Queue or Send |
981 | 1003 | ||
1004 | bool highPriority = false; | ||
1005 | |||
1006 | if (category != ThrottleOutPacketType.Unknown && (category & ThrottleOutPacketType.HighPriority) != 0) | ||
1007 | { | ||
1008 | category = (ThrottleOutPacketType)((int)category & 127); | ||
1009 | highPriority = true; | ||
1010 | } | ||
1011 | |||
982 | OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, null); | 1012 | OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, null); |
983 | 1013 | ||
984 | // If we were not provided a method for handling unacked, use the UDPServer default method | 1014 | // If we were not provided a method for handling unacked, use the UDPServer default method |
@@ -988,26 +1018,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
988 | // If a Linden Lab 1.23.5 client receives an update packet after a kill packet for an object, it will | 1018 | // If a Linden Lab 1.23.5 client receives an update packet after a kill packet for an object, it will |
989 | // continue to display the deleted object until relog. Therefore, we need to always queue a kill object | 1019 | // continue to display the deleted object until relog. Therefore, we need to always queue a kill object |
990 | // packet so that it isn't sent before a queued update packet. | 1020 | // packet so that it isn't sent before a queued update packet. |
991 | bool forceQueue = (type == PacketType.KillObject); | ||
992 | 1021 | ||
993 | // if (type == PacketType.ImprovedTerseObjectUpdate) | 1022 | bool requestQueue = type == PacketType.KillObject; |
994 | // { | 1023 | if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, requestQueue, highPriority)) |
995 | // m_log.DebugFormat("Direct send ITOU to {0} in {1}", udpClient.AgentID, Scene.Name); | ||
996 | // SendPacketFinal(outgoingPacket); | ||
997 | // return false; | ||
998 | // } | ||
999 | // else | ||
1000 | // { | ||
1001 | if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, forceQueue)) | ||
1002 | { | 1024 | { |
1003 | SendPacketFinal(outgoingPacket); | 1025 | SendPacketFinal(outgoingPacket); |
1004 | return true; | 1026 | return true; |
1005 | } | 1027 | } |
1006 | else | 1028 | |
1007 | { | 1029 | return false; |
1008 | return false; | ||
1009 | } | ||
1010 | // } | ||
1011 | 1030 | ||
1012 | #endregion Queue or Send | 1031 | #endregion Queue or Send |
1013 | } | 1032 | } |
@@ -1048,6 +1067,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1048 | pc.PingID.OldestUnacked = 0; | 1067 | pc.PingID.OldestUnacked = 0; |
1049 | 1068 | ||
1050 | SendPacket(udpClient, pc, ThrottleOutPacketType.Unknown, false, null); | 1069 | SendPacket(udpClient, pc, ThrottleOutPacketType.Unknown, false, null); |
1070 | udpClient.m_lastStartpingTimeMS = Util.EnvironmentTickCount(); | ||
1051 | } | 1071 | } |
1052 | 1072 | ||
1053 | public void CompletePing(LLUDPClient udpClient, byte pingID) | 1073 | public void CompletePing(LLUDPClient udpClient, byte pingID) |
@@ -1145,7 +1165,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1145 | int dataLength = buffer.DataLength; | 1165 | int dataLength = buffer.DataLength; |
1146 | 1166 | ||
1147 | // NOTE: I'm seeing problems with some viewers when ACKs are appended to zerocoded packets so I've disabled that here | 1167 | // NOTE: I'm seeing problems with some viewers when ACKs are appended to zerocoded packets so I've disabled that here |
1148 | if (!isZerocoded) | 1168 | if (!isZerocoded && !isResend && outgoingPacket.UnackedMethod == null) |
1149 | { | 1169 | { |
1150 | // Keep appending ACKs until there is no room left in the buffer or there are | 1170 | // Keep appending ACKs until there is no room left in the buffer or there are |
1151 | // no more ACKs to append | 1171 | // no more ACKs to append |
@@ -1180,7 +1200,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1180 | Utils.UIntToBytesBig(sequenceNumber, buffer.Data, 1); | 1200 | Utils.UIntToBytesBig(sequenceNumber, buffer.Data, 1); |
1181 | outgoingPacket.SequenceNumber = sequenceNumber; | 1201 | outgoingPacket.SequenceNumber = sequenceNumber; |
1182 | 1202 | ||
1183 | if (udpClient.ProcessUnackedSends && isReliable) | 1203 | if (isReliable) |
1184 | { | 1204 | { |
1185 | // Add this packet to the list of ACK responses we are waiting on from the server | 1205 | // Add this packet to the list of ACK responses we are waiting on from the server |
1186 | udpClient.NeedAcks.Add(outgoingPacket); | 1206 | udpClient.NeedAcks.Add(outgoingPacket); |
@@ -1311,35 +1331,62 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1311 | 1331 | ||
1312 | #region Packet to Client Mapping | 1332 | #region Packet to Client Mapping |
1313 | 1333 | ||
1314 | // UseCircuitCode handling | 1334 | // If there is already a client for this endpoint, don't process UseCircuitCode |
1315 | if (packet.Type == PacketType.UseCircuitCode) | 1335 | IClientAPI client = null; |
1336 | if (!Scene.TryGetClient(endPoint, out client) || !(client is LLClientView)) | ||
1316 | { | 1337 | { |
1317 | // We need to copy the endpoint so that it doesn't get changed when another thread reuses the | 1338 | // UseCircuitCode handling |
1318 | // buffer. | 1339 | if (packet.Type == PacketType.UseCircuitCode) |
1319 | object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet }; | 1340 | { |
1341 | // And if there is a UseCircuitCode pending, also drop it | ||
1342 | lock (m_pendingCache) | ||
1343 | { | ||
1344 | if (m_pendingCache.Contains(endPoint)) | ||
1345 | return; | ||
1320 | 1346 | ||
1321 | Util.FireAndForget(HandleUseCircuitCode, array, "LLUDPServer.HandleUseCircuitCode"); | 1347 | m_pendingCache.AddOrUpdate(endPoint, new Queue<UDPPacketBuffer>(), 60); |
1348 | } | ||
1322 | 1349 | ||
1323 | return; | 1350 | // We need to copy the endpoint so that it doesn't get changed when another thread reuses the |
1351 | // buffer. | ||
1352 | object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet }; | ||
1353 | |||
1354 | Util.FireAndForget(HandleUseCircuitCode, array); | ||
1355 | |||
1356 | return; | ||
1357 | } | ||
1324 | } | 1358 | } |
1325 | else if (packet.Type == PacketType.CompleteAgentMovement) | 1359 | |
1360 | // If this is a pending connection, enqueue, don't process yet | ||
1361 | lock (m_pendingCache) | ||
1326 | { | 1362 | { |
1327 | // Send ack straight away to let the viewer know that we got it. | 1363 | Queue<UDPPacketBuffer> queue; |
1328 | SendAckImmediate(endPoint, packet.Header.Sequence); | 1364 | if (m_pendingCache.TryGetValue(endPoint, out queue)) |
1365 | { | ||
1366 | //m_log.DebugFormat("[LLUDPSERVER]: Enqueued a {0} packet into the pending queue", packet.Type); | ||
1367 | queue.Enqueue(buffer); | ||
1368 | return; | ||
1369 | } | ||
1329 | 1370 | ||
1330 | // We need to copy the endpoint so that it doesn't get changed when another thread reuses the | 1371 | /* |
1331 | // buffer. | 1372 | else if (packet.Type == PacketType.CompleteAgentMovement) |
1332 | object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet }; | 1373 | { |
1374 | // Send ack straight away to let the viewer know that we got it. | ||
1375 | SendAckImmediate(endPoint, packet.Header.Sequence); | ||
1333 | 1376 | ||
1334 | Util.FireAndForget( | 1377 | // We need to copy the endpoint so that it doesn't get changed when another thread reuses the |
1335 | HandleCompleteMovementIntoRegion, array, "LLUDPServer.HandleCompleteMovementIntoRegion"); | 1378 | // buffer. |
1379 | object[] array = new object[] { new IPEndPoint(endPoint.Address, endPoint.Port), packet }; | ||
1336 | 1380 | ||
1337 | return; | 1381 | Util.FireAndForget(HandleCompleteMovementIntoRegion, array); |
1382 | |||
1383 | return; | ||
1384 | } | ||
1385 | */ | ||
1338 | } | 1386 | } |
1339 | 1387 | ||
1340 | // Determine which agent this packet came from | 1388 | // Determine which agent this packet came from |
1341 | IClientAPI client; | 1389 | if (client == null || !(client is LLClientView)) |
1342 | if (!Scene.TryGetClient(endPoint, out client) || !(client is LLClientView)) | ||
1343 | { | 1390 | { |
1344 | //m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + " in " + m_scene.RegionInfo.RegionName); | 1391 | //m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + " in " + m_scene.RegionInfo.RegionName); |
1345 | 1392 | ||
@@ -1356,7 +1403,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1356 | udpClient = ((LLClientView)client).UDPClient; | 1403 | udpClient = ((LLClientView)client).UDPClient; |
1357 | 1404 | ||
1358 | if (!udpClient.IsConnected) | 1405 | if (!udpClient.IsConnected) |
1406 | { | ||
1407 | m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet for a unConnected client in " + Scene.RegionInfo.RegionName); | ||
1359 | return; | 1408 | return; |
1409 | } | ||
1360 | 1410 | ||
1361 | #endregion Packet to Client Mapping | 1411 | #endregion Packet to Client Mapping |
1362 | 1412 | ||
@@ -1368,37 +1418,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1368 | 1418 | ||
1369 | #region ACK Receiving | 1419 | #region ACK Receiving |
1370 | 1420 | ||
1371 | if (udpClient.ProcessUnackedSends) | 1421 | // Handle appended ACKs |
1422 | if (packet.Header.AppendedAcks && packet.Header.AckList != null) | ||
1372 | { | 1423 | { |
1373 | // Handle appended ACKs | 1424 | // m_log.DebugFormat( |
1374 | if (packet.Header.AppendedAcks && packet.Header.AckList != null) | 1425 | // "[LLUDPSERVER]: Handling {0} appended acks from {1} in {2}", |
1375 | { | 1426 | // packet.Header.AckList.Length, client.Name, m_scene.Name); |
1376 | // m_log.DebugFormat( | ||
1377 | // "[LLUDPSERVER]: Handling {0} appended acks from {1} in {2}", | ||
1378 | // packet.Header.AckList.Length, client.Name, m_scene.Name); | ||
1379 | 1427 | ||
1380 | for (int i = 0; i < packet.Header.AckList.Length; i++) | 1428 | for (int i = 0; i < packet.Header.AckList.Length; i++) |
1381 | udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent); | 1429 | udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent); |
1382 | } | 1430 | } |
1383 | 1431 | ||
1384 | // Handle PacketAck packets | 1432 | // Handle PacketAck packets |
1385 | if (packet.Type == PacketType.PacketAck) | 1433 | if (packet.Type == PacketType.PacketAck) |
1386 | { | 1434 | { |
1387 | PacketAckPacket ackPacket = (PacketAckPacket)packet; | 1435 | PacketAckPacket ackPacket = (PacketAckPacket)packet; |
1388 | 1436 | ||
1389 | // m_log.DebugFormat( | 1437 | // m_log.DebugFormat( |
1390 | // "[LLUDPSERVER]: Handling {0} packet acks for {1} in {2}", | 1438 | // "[LLUDPSERVER]: Handling {0} packet acks for {1} in {2}", |
1391 | // ackPacket.Packets.Length, client.Name, m_scene.Name); | 1439 | // ackPacket.Packets.Length, client.Name, m_scene.Name); |
1392 | 1440 | ||
1393 | for (int i = 0; i < ackPacket.Packets.Length; i++) | 1441 | for (int i = 0; i < ackPacket.Packets.Length; i++) |
1394 | udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent); | 1442 | udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent); |
1395 | 1443 | ||
1396 | // We don't need to do anything else with PacketAck packets | 1444 | // We don't need to do anything else with PacketAck packets |
1397 | return; | ||
1398 | } | ||
1399 | } | ||
1400 | else if (packet.Type == PacketType.PacketAck) | ||
1401 | { | ||
1402 | return; | 1445 | return; |
1403 | } | 1446 | } |
1404 | 1447 | ||
@@ -1459,24 +1502,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1459 | LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length); | 1502 | LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length); |
1460 | #endregion BinaryStats | 1503 | #endregion BinaryStats |
1461 | 1504 | ||
1462 | if (packet.Type == PacketType.AgentUpdate) | ||
1463 | { | ||
1464 | if (DiscardInboundAgentUpdates) | ||
1465 | return; | ||
1466 | 1505 | ||
1467 | ((LLClientView)client).TotalAgentUpdates++; | 1506 | //AgentUpdate removed from here |
1468 | 1507 | ||
1469 | AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet; | ||
1470 | |||
1471 | LLClientView llClient = client as LLClientView; | ||
1472 | if (agentUpdate.AgentData.SessionID != client.SessionId | ||
1473 | || agentUpdate.AgentData.AgentID != client.AgentId | ||
1474 | || !(llClient == null || llClient.CheckAgentUpdateSignificance(agentUpdate.AgentData)) ) | ||
1475 | { | ||
1476 | PacketPool.Instance.ReturnPacket(packet); | ||
1477 | return; | ||
1478 | } | ||
1479 | } | ||
1480 | 1508 | ||
1481 | #region Ping Check Handling | 1509 | #region Ping Check Handling |
1482 | 1510 | ||
@@ -1487,7 +1515,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1487 | // We don't need to do anything else with ping checks | 1515 | // We don't need to do anything else with ping checks |
1488 | StartPingCheckPacket startPing = (StartPingCheckPacket)packet; | 1516 | StartPingCheckPacket startPing = (StartPingCheckPacket)packet; |
1489 | CompletePing(udpClient, startPing.PingID.PingID); | 1517 | CompletePing(udpClient, startPing.PingID.PingID); |
1490 | 1518 | ||
1491 | if ((Environment.TickCount - m_elapsedMSSinceLastStatReport) >= 3000) | 1519 | if ((Environment.TickCount - m_elapsedMSSinceLastStatReport) >= 3000) |
1492 | { | 1520 | { |
1493 | udpClient.SendPacketStats(); | 1521 | udpClient.SendPacketStats(); |
@@ -1497,7 +1525,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1497 | } | 1525 | } |
1498 | else if (packet.Type == PacketType.CompletePingCheck) | 1526 | else if (packet.Type == PacketType.CompletePingCheck) |
1499 | { | 1527 | { |
1500 | // We don't currently track client ping times | 1528 | int t = Util.EnvironmentTickCountSubtract(udpClient.m_lastStartpingTimeMS); |
1529 | int c = udpClient.m_pingMS; | ||
1530 | c = 800 * c + 200 * t; | ||
1531 | c /= 1000; | ||
1532 | udpClient.m_pingMS = c; | ||
1501 | return; | 1533 | return; |
1502 | } | 1534 | } |
1503 | 1535 | ||
@@ -1517,7 +1549,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1517 | incomingPacket = new IncomingPacket((LLClientView)client, packet); | 1549 | incomingPacket = new IncomingPacket((LLClientView)client, packet); |
1518 | } | 1550 | } |
1519 | 1551 | ||
1520 | packetInbox.Enqueue(incomingPacket); | 1552 | // if (incomingPacket.Packet.Type == PacketType.AgentUpdate || |
1553 | // incomingPacket.Packet.Type == PacketType.ChatFromViewer) | ||
1554 | if (incomingPacket.Packet.Type == PacketType.ChatFromViewer) | ||
1555 | packetInbox.EnqueueHigh(incomingPacket); | ||
1556 | else | ||
1557 | packetInbox.EnqueueLow(incomingPacket); | ||
1558 | |||
1521 | } | 1559 | } |
1522 | 1560 | ||
1523 | #region BinaryStats | 1561 | #region BinaryStats |
@@ -1634,7 +1672,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1634 | 1672 | ||
1635 | try | 1673 | try |
1636 | { | 1674 | { |
1637 | // DateTime startTime = DateTime.Now; | 1675 | // DateTime startTime = DateTime.Now; |
1638 | object[] array = (object[])o; | 1676 | object[] array = (object[])o; |
1639 | endPoint = (IPEndPoint)array[0]; | 1677 | endPoint = (IPEndPoint)array[0]; |
1640 | UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1]; | 1678 | UseCircuitCodePacket uccp = (UseCircuitCodePacket)array[1]; |
@@ -1646,6 +1684,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1646 | AuthenticateResponse sessionInfo; | 1684 | AuthenticateResponse sessionInfo; |
1647 | if (IsClientAuthorized(uccp, out sessionInfo)) | 1685 | if (IsClientAuthorized(uccp, out sessionInfo)) |
1648 | { | 1686 | { |
1687 | AgentCircuitData aCircuit = Scene.AuthenticateHandler.GetAgentCircuitData(uccp.CircuitCode.Code); | ||
1688 | |||
1649 | // Begin the process of adding the client to the simulator | 1689 | // Begin the process of adding the client to the simulator |
1650 | client | 1690 | client |
1651 | = AddClient( | 1691 | = AddClient( |
@@ -1654,20 +1694,55 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1654 | uccp.CircuitCode.SessionID, | 1694 | uccp.CircuitCode.SessionID, |
1655 | endPoint, | 1695 | endPoint, |
1656 | sessionInfo); | 1696 | sessionInfo); |
1657 | 1697 | ||
1698 | // This will be true if the client is new, e.g. not | ||
1699 | // an existing child agent, and there is no circuit data | ||
1700 | if (client != null && aCircuit == null) | ||
1701 | { | ||
1702 | Scene.CloseAgent(client.AgentId, true); | ||
1703 | return; | ||
1704 | } | ||
1705 | |||
1706 | // Now we know we can handle more data | ||
1707 | Thread.Sleep(200); | ||
1708 | |||
1709 | // Obtain the pending queue and remove it from the cache | ||
1710 | Queue<UDPPacketBuffer> queue = null; | ||
1711 | |||
1712 | lock (m_pendingCache) | ||
1713 | { | ||
1714 | if (!m_pendingCache.TryGetValue(endPoint, out queue)) | ||
1715 | { | ||
1716 | m_log.DebugFormat("[LLUDPSERVER]: Client created but no pending queue present"); | ||
1717 | return; | ||
1718 | |||
1719 | } | ||
1720 | m_pendingCache.Remove(endPoint); | ||
1721 | } | ||
1722 | |||
1723 | m_log.DebugFormat("[LLUDPSERVER]: Client created, processing pending queue, {0} entries", queue.Count); | ||
1724 | |||
1725 | // Reinject queued packets | ||
1726 | while (queue.Count > 0) | ||
1727 | { | ||
1728 | UDPPacketBuffer buf = queue.Dequeue(); | ||
1729 | PacketReceived(buf); | ||
1730 | } | ||
1731 | |||
1732 | queue = null; | ||
1733 | |||
1658 | // Send ack straight away to let the viewer know that the connection is active. | 1734 | // Send ack straight away to let the viewer know that the connection is active. |
1659 | // The client will be null if it already exists (e.g. if on a region crossing the client sends a use | 1735 | // The client will be null if it already exists (e.g. if on a region crossing the client sends a use |
1660 | // circuit code to the existing child agent. This is not particularly obvious. | 1736 | // circuit code to the existing child agent. This is not particularly obvious. |
1661 | SendAckImmediate(endPoint, uccp.Header.Sequence); | 1737 | SendAckImmediate(endPoint, uccp.Header.Sequence); |
1662 | 1738 | ||
1663 | // We only want to send initial data to new clients, not ones which are being converted from child to root. | 1739 | // We only want to send initial data to new clients, not ones which are being converted from child to root. |
1664 | if (client != null) | 1740 | if (client != null) |
1665 | { | 1741 | { |
1666 | AgentCircuitData aCircuit = Scene.AuthenticateHandler.GetAgentCircuitData(uccp.CircuitCode.Code); | ||
1667 | bool tp = (aCircuit.teleportFlags > 0); | 1742 | bool tp = (aCircuit.teleportFlags > 0); |
1668 | // Let's delay this for TP agents, otherwise the viewer doesn't know where to get resources from | 1743 | // Let's delay this for TP agents, otherwise the viewer doesn't know where to get resources from |
1669 | if (!tp && !client.SceneAgent.SentInitialDataToClient) | 1744 | if (!tp) |
1670 | client.SceneAgent.SendInitialDataToClient(); | 1745 | client.SceneAgent.SendInitialDataToMe(); |
1671 | } | 1746 | } |
1672 | } | 1747 | } |
1673 | else | 1748 | else |
@@ -1675,9 +1750,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1675 | // Don't create clients for unauthorized requesters. | 1750 | // Don't create clients for unauthorized requesters. |
1676 | m_log.WarnFormat( | 1751 | m_log.WarnFormat( |
1677 | "[LLUDPSERVER]: Ignoring connection request for {0} to {1} with unknown circuit code {2} from IP {3}", | 1752 | "[LLUDPSERVER]: Ignoring connection request for {0} to {1} with unknown circuit code {2} from IP {3}", |
1753 | |||
1678 | uccp.CircuitCode.ID, Scene.RegionInfo.RegionName, uccp.CircuitCode.Code, endPoint); | 1754 | uccp.CircuitCode.ID, Scene.RegionInfo.RegionName, uccp.CircuitCode.Code, endPoint); |
1679 | } | 1755 | |
1680 | 1756 | lock (m_pendingCache) | |
1757 | m_pendingCache.Remove(endPoint); | ||
1758 | } | ||
1759 | |||
1681 | // m_log.DebugFormat( | 1760 | // m_log.DebugFormat( |
1682 | // "[LLUDPSERVER]: Handling UseCircuitCode request from {0} took {1}ms", | 1761 | // "[LLUDPSERVER]: Handling UseCircuitCode request from {0} took {1}ms", |
1683 | // buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds); | 1762 | // buffer.RemoteEndPoint, (DateTime.Now - startTime).Milliseconds); |
@@ -1694,8 +1773,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1694 | e.StackTrace); | 1773 | e.StackTrace); |
1695 | } | 1774 | } |
1696 | } | 1775 | } |
1697 | 1776 | /* | |
1698 | private void HandleCompleteMovementIntoRegion(object o) | 1777 | private void HandleCompleteMovementIntoRegion(object o) |
1699 | { | 1778 | { |
1700 | IPEndPoint endPoint = null; | 1779 | IPEndPoint endPoint = null; |
1701 | IClientAPI client = null; | 1780 | IClientAPI client = null; |
@@ -1804,6 +1883,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1804 | e.StackTrace); | 1883 | e.StackTrace); |
1805 | } | 1884 | } |
1806 | } | 1885 | } |
1886 | */ | ||
1807 | 1887 | ||
1808 | /// <summary> | 1888 | /// <summary> |
1809 | /// Send an ack immediately to the given endpoint. | 1889 | /// Send an ack immediately to the given endpoint. |
@@ -1861,6 +1941,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1861 | uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) | 1941 | uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) |
1862 | { | 1942 | { |
1863 | IClientAPI client = null; | 1943 | IClientAPI client = null; |
1944 | bool createNew = false; | ||
1864 | 1945 | ||
1865 | // We currently synchronize this code across the whole scene to avoid issues such as | 1946 | // We currently synchronize this code across the whole scene to avoid issues such as |
1866 | // http://opensimulator.org/mantis/view.php?id=5365 However, once locking per agent circuit can be done | 1947 | // http://opensimulator.org/mantis/view.php?id=5365 However, once locking per agent circuit can be done |
@@ -1869,7 +1950,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1869 | { | 1950 | { |
1870 | if (!Scene.TryGetClient(agentID, out client)) | 1951 | if (!Scene.TryGetClient(agentID, out client)) |
1871 | { | 1952 | { |
1953 | createNew = true; | ||
1954 | } | ||
1955 | else | ||
1956 | { | ||
1957 | if (client.SceneAgent == null) | ||
1958 | { | ||
1959 | Scene.CloseAgent(agentID, true); | ||
1960 | createNew = true; | ||
1961 | } | ||
1962 | } | ||
1963 | |||
1964 | if (createNew) | ||
1965 | { | ||
1872 | LLUDPClient udpClient = new LLUDPClient(this, ThrottleRates, Throttle, circuitCode, agentID, remoteEndPoint, m_defaultRTO, m_maxRTO); | 1966 | LLUDPClient udpClient = new LLUDPClient(this, ThrottleRates, Throttle, circuitCode, agentID, remoteEndPoint, m_defaultRTO, m_maxRTO); |
1967 | |||
1873 | 1968 | ||
1874 | client = new LLClientView(Scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); | 1969 | client = new LLClientView(Scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); |
1875 | client.OnLogout += LogoutHandler; | 1970 | client.OnLogout += LogoutHandler; |
@@ -1899,15 +1994,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1899 | { | 1994 | { |
1900 | ClientLogoutsDueToNoReceives++; | 1995 | ClientLogoutsDueToNoReceives++; |
1901 | 1996 | ||
1902 | m_log.WarnFormat( | 1997 | if (client.SceneAgent != null) |
1903 | "[LLUDPSERVER]: No packets received from {0} agent of {1} for {2}ms in {3}. Disconnecting.", | 1998 | { |
1904 | client.SceneAgent.IsChildAgent ? "child" : "root", client.Name, timeoutTicks, Scene.Name); | 1999 | m_log.WarnFormat( |
2000 | "[LLUDPSERVER]: No packets received from {0} agent of {1} for {2}ms in {3}. Disconnecting.", | ||
2001 | client.SceneAgent.IsChildAgent ? "child" : "root", client.Name, timeoutTicks, Scene.Name); | ||
1905 | 2002 | ||
1906 | if (!client.SceneAgent.IsChildAgent) | 2003 | if (!client.SceneAgent.IsChildAgent) |
1907 | client.Kick("Simulator logged you out due to connection timeout."); | 2004 | client.Kick("Simulator logged you out due to connection timeout."); |
2005 | } | ||
1908 | } | 2006 | } |
1909 | 2007 | ||
1910 | Scene.CloseAgent(client.AgentId, true); | 2008 | if (!Scene.CloseAgent(client.AgentId, true)) |
2009 | client.Close(true,true); | ||
1911 | } | 2010 | } |
1912 | 2011 | ||
1913 | private void IncomingPacketHandler() | 2012 | private void IncomingPacketHandler() |
@@ -1920,6 +2019,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1920 | 2019 | ||
1921 | while (IsRunningInbound) | 2020 | while (IsRunningInbound) |
1922 | { | 2021 | { |
2022 | Scene.ThreadAlive(1); | ||
1923 | try | 2023 | try |
1924 | { | 2024 | { |
1925 | IncomingPacket incomingPacket = null; | 2025 | IncomingPacket incomingPacket = null; |
@@ -1942,7 +2042,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1942 | m_incomingPacketPool.ReturnObject(incomingPacket); | 2042 | m_incomingPacketPool.ReturnObject(incomingPacket); |
1943 | } | 2043 | } |
1944 | } | 2044 | } |
1945 | catch (Exception ex) | 2045 | catch(Exception ex) |
1946 | { | 2046 | { |
1947 | m_log.Error("[LLUDPSERVER]: Error in the incoming packet handler loop: " + ex.Message, ex); | 2047 | m_log.Error("[LLUDPSERVER]: Error in the incoming packet handler loop: " + ex.Message, ex); |
1948 | } | 2048 | } |
@@ -1971,6 +2071,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1971 | 2071 | ||
1972 | while (base.IsRunningOutbound) | 2072 | while (base.IsRunningOutbound) |
1973 | { | 2073 | { |
2074 | Scene.ThreadAlive(2); | ||
1974 | try | 2075 | try |
1975 | { | 2076 | { |
1976 | m_packetSent = false; | 2077 | m_packetSent = false; |
@@ -2029,13 +2130,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2029 | 2130 | ||
2030 | // If nothing was sent, sleep for the minimum amount of time before a | 2131 | // If nothing was sent, sleep for the minimum amount of time before a |
2031 | // token bucket could get more tokens | 2132 | // token bucket could get more tokens |
2032 | //if (!m_packetSent) | 2133 | |
2033 | // Thread.Sleep((int)TickCountResolution); | ||
2034 | // | ||
2035 | // Instead, now wait for data present to be explicitly signalled. Evidence so far is that with | ||
2036 | // modern mono it reduces CPU base load since there is no more continuous polling. | ||
2037 | if (!m_packetSent) | 2134 | if (!m_packetSent) |
2038 | m_dataPresentEvent.WaitOne(100); | 2135 | Thread.Sleep((int)TickCountResolution); |
2136 | |||
2137 | // .... wrong core code removed | ||
2138 | |||
2039 | 2139 | ||
2040 | Watchdog.UpdateThread(); | 2140 | Watchdog.UpdateThread(); |
2041 | } | 2141 | } |
@@ -2061,7 +2161,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2061 | 2161 | ||
2062 | if (udpClient.IsConnected) | 2162 | if (udpClient.IsConnected) |
2063 | { | 2163 | { |
2064 | if (udpClient.ProcessUnackedSends && m_resendUnacked) | 2164 | if (m_resendUnacked) |
2065 | HandleUnacked(llClient); | 2165 | HandleUnacked(llClient); |
2066 | 2166 | ||
2067 | if (m_sendAcks) | 2167 | if (m_sendAcks) |
@@ -2206,8 +2306,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2206 | Packet packet = incomingPacket.Packet; | 2306 | Packet packet = incomingPacket.Packet; |
2207 | LLClientView client = incomingPacket.Client; | 2307 | LLClientView client = incomingPacket.Client; |
2208 | 2308 | ||
2209 | if (client.IsActive) | 2309 | // if (client.IsActive) |
2210 | { | 2310 | // { |
2211 | m_currentIncomingClient = client; | 2311 | m_currentIncomingClient = client; |
2212 | 2312 | ||
2213 | try | 2313 | try |
@@ -2234,13 +2334,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
2234 | { | 2334 | { |
2235 | m_currentIncomingClient = null; | 2335 | m_currentIncomingClient = null; |
2236 | } | 2336 | } |
2237 | } | 2337 | // } |
2238 | else | 2338 | // else |
2239 | { | 2339 | // { |
2240 | m_log.DebugFormat( | 2340 | // m_log.DebugFormat( |
2241 | "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", | 2341 | // "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", |
2242 | packet.Type, client.Name, Scene.RegionInfo.RegionName); | 2342 | // packet.Type, client.Name, m_scene.RegionInfo.RegionName); |
2243 | } | 2343 | // } |
2244 | 2344 | ||
2245 | IncomingPacketsProcessed++; | 2345 | IncomingPacketsProcessed++; |
2246 | } | 2346 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServerCommands.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServerCommands.cs index ac6c0b4..6e6a2d1 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServerCommands.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServerCommands.cs | |||
@@ -48,6 +48,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
48 | 48 | ||
49 | public void Register() | 49 | public void Register() |
50 | { | 50 | { |
51 | /* | ||
51 | m_console.Commands.AddCommand( | 52 | m_console.Commands.AddCommand( |
52 | "Comms", false, "show server throttles", | 53 | "Comms", false, "show server throttles", |
53 | "show server throttles", | 54 | "show server throttles", |
@@ -213,6 +214,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
213 | "Set a debug parameter for a particular client. If no name is given then the value is set on all clients.", | 214 | "Set a debug parameter for a particular client. If no name is given then the value is set on all clients.", |
214 | "process-unacked-sends - Do we take action if a sent reliable packet has not been acked.", | 215 | "process-unacked-sends - Do we take action if a sent reliable packet has not been acked.", |
215 | HandleClientSetCommand); | 216 | HandleClientSetCommand); |
217 | */ | ||
216 | } | 218 | } |
217 | 219 | ||
218 | private void HandleShowServerThrottlesCommand(string module, string[] args) | 220 | private void HandleShowServerThrottlesCommand(string module, string[] args) |
@@ -224,7 +226,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
224 | ConsoleDisplayList cdl = new ConsoleDisplayList(); | 226 | ConsoleDisplayList cdl = new ConsoleDisplayList(); |
225 | cdl.AddRow("Adaptive throttles", m_udpServer.ThrottleRates.AdaptiveThrottlesEnabled); | 227 | cdl.AddRow("Adaptive throttles", m_udpServer.ThrottleRates.AdaptiveThrottlesEnabled); |
226 | 228 | ||
227 | long maxSceneDripRate = m_udpServer.Throttle.MaxDripRate; | 229 | long maxSceneDripRate = (long)m_udpServer.Throttle.MaxDripRate; |
228 | cdl.AddRow( | 230 | cdl.AddRow( |
229 | "Max scene throttle", | 231 | "Max scene throttle", |
230 | maxSceneDripRate != 0 ? string.Format("{0} kbps", maxSceneDripRate * 8 / 1000) : "unset"); | 232 | maxSceneDripRate != 0 ? string.Format("{0} kbps", maxSceneDripRate * 8 / 1000) : "unset"); |
@@ -505,7 +507,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
505 | m_console.OutputFormat("Debug settings for {0}", m_udpServer.Scene.Name); | 507 | m_console.OutputFormat("Debug settings for {0}", m_udpServer.Scene.Name); |
506 | ConsoleDisplayList cdl = new ConsoleDisplayList(); | 508 | ConsoleDisplayList cdl = new ConsoleDisplayList(); |
507 | 509 | ||
508 | long maxSceneDripRate = m_udpServer.Throttle.MaxDripRate; | 510 | long maxSceneDripRate = (long)m_udpServer.Throttle.MaxDripRate; |
509 | cdl.AddRow( | 511 | cdl.AddRow( |
510 | "max-scene-throttle", | 512 | "max-scene-throttle", |
511 | maxSceneDripRate != 0 ? string.Format("{0} kbps", maxSceneDripRate * 8 / 1000) : "unset"); | 513 | maxSceneDripRate != 0 ? string.Format("{0} kbps", maxSceneDripRate * 8 / 1000) : "unset"); |
@@ -556,6 +558,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
556 | m_console.OutputFormat("{0} set to {1} in {2}", param, rawValue, m_udpServer.Scene.Name); | 558 | m_console.OutputFormat("{0} set to {1} in {2}", param, rawValue, m_udpServer.Scene.Name); |
557 | } | 559 | } |
558 | 560 | ||
561 | /* not in use, nothing to set/get from lludp | ||
559 | private void HandleClientGetCommand(string module, string[] args) | 562 | private void HandleClientGetCommand(string module, string[] args) |
560 | { | 563 | { |
561 | if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene) | 564 | if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene) |
@@ -582,11 +585,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
582 | m_console.OutputFormat( | 585 | m_console.OutputFormat( |
583 | "Client debug parameters for {0} ({1}) in {2}", | 586 | "Client debug parameters for {0} ({1}) in {2}", |
584 | sp.Name, sp.IsChildAgent ? "child" : "root", m_udpServer.Scene.Name); | 587 | sp.Name, sp.IsChildAgent ? "child" : "root", m_udpServer.Scene.Name); |
585 | |||
586 | ConsoleDisplayList cdl = new ConsoleDisplayList(); | ||
587 | cdl.AddRow("process-unacked-sends", udpClient.ProcessUnackedSends); | ||
588 | |||
589 | m_console.Output(cdl.ToString()); | ||
590 | } | 588 | } |
591 | }); | 589 | }); |
592 | } | 590 | } |
@@ -609,28 +607,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
609 | 607 | ||
610 | if (args.Length == 8) | 608 | if (args.Length == 8) |
611 | name = string.Format("{0} {1}", args[6], args[7]); | 609 | name = string.Format("{0} {1}", args[6], args[7]); |
612 | 610 | // nothing here now | |
613 | if (param == "process-unacked-sends") | ||
614 | { | ||
615 | bool newValue; | ||
616 | |||
617 | if (!ConsoleUtil.TryParseConsoleBool(MainConsole.Instance, rawValue, out newValue)) | ||
618 | return; | ||
619 | |||
620 | m_udpServer.Scene.ForEachScenePresence( | ||
621 | sp => | ||
622 | { | ||
623 | if ((name == null || sp.Name == name) && sp.ControllingClient is LLClientView) | ||
624 | { | ||
625 | LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient; | ||
626 | udpClient.ProcessUnackedSends = newValue; | ||
627 | |||
628 | m_console.OutputFormat("{0} set to {1} for {2} in {3}", param, newValue, sp.Name, m_udpServer.Scene.Name); | ||
629 | } | ||
630 | }); | ||
631 | } | ||
632 | } | 611 | } |
633 | 612 | */ | |
634 | private void HandlePacketCommand(string module, string[] args) | 613 | private void HandlePacketCommand(string module, string[] args) |
635 | { | 614 | { |
636 | if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene) | 615 | if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene) |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs index f62dc15..7171974 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | |||
@@ -206,16 +206,16 @@ namespace OpenMetaverse | |||
206 | const int SIO_UDP_CONNRESET = -1744830452; | 206 | const int SIO_UDP_CONNRESET = -1744830452; |
207 | 207 | ||
208 | IPEndPoint ipep = new IPEndPoint(m_localBindAddress, m_udpPort); | 208 | IPEndPoint ipep = new IPEndPoint(m_localBindAddress, m_udpPort); |
209 | |||
210 | m_log.DebugFormat( | ||
211 | "[UDPBASE]: Binding UDP listener using internal IP address config {0}:{1}", | ||
212 | ipep.Address, ipep.Port); | ||
213 | 209 | ||
214 | m_udpSocket = new Socket( | 210 | m_udpSocket = new Socket( |
215 | AddressFamily.InterNetwork, | 211 | AddressFamily.InterNetwork, |
216 | SocketType.Dgram, | 212 | SocketType.Dgram, |
217 | ProtocolType.Udp); | 213 | ProtocolType.Udp); |
218 | 214 | ||
215 | // OpenSim may need this but in AVN, this messes up automated | ||
216 | // sim restarts badly | ||
217 | //m_udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, false); | ||
218 | |||
219 | try | 219 | try |
220 | { | 220 | { |
221 | if (m_udpSocket.Ttl < 128) | 221 | if (m_udpSocket.Ttl < 128) |
@@ -501,4 +501,4 @@ namespace OpenMetaverse | |||
501 | catch (ObjectDisposedException) { } | 501 | catch (ObjectDisposedException) { } |
502 | } | 502 | } |
503 | } | 503 | } |
504 | } \ No newline at end of file | 504 | } |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs index 3c82a78..5e41dbd 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs | |||
@@ -35,6 +35,7 @@ using OpenSim.Tests.Common; | |||
35 | 35 | ||
36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | 36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests |
37 | { | 37 | { |
38 | /* | ||
38 | [TestFixture] | 39 | [TestFixture] |
39 | public class ThrottleTests : OpenSimTestCase | 40 | public class ThrottleTests : OpenSimTestCase |
40 | { | 41 | { |
@@ -57,16 +58,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
57 | [Test] | 58 | [Test] |
58 | public void TestSetRequestDripRate() | 59 | public void TestSetRequestDripRate() |
59 | { | 60 | { |
61 | |||
60 | TestHelpers.InMethod(); | 62 | TestHelpers.InMethod(); |
61 | 63 | ||
62 | TokenBucket tb = new TokenBucket("tb", null, 5000, 0); | 64 | TokenBucket tb = new TokenBucket(null, 5000f,10000f); |
63 | AssertRates(tb, 5000, 0, 5000, 0); | 65 | AssertRates(tb, 5000, 0, 5000, 0); |
64 | 66 | ||
65 | tb.RequestedDripRate = 4000; | 67 | tb.RequestedDripRate = 4000f; |
66 | AssertRates(tb, 4000, 0, 4000, 0); | 68 | AssertRates(tb, 4000, 0, 4000, 0); |
67 | 69 | ||
68 | tb.RequestedDripRate = 6000; | 70 | tb.RequestedDripRate = 6000; |
69 | AssertRates(tb, 6000, 0, 6000, 0); | 71 | AssertRates(tb, 6000, 0, 6000, 0); |
72 | |||
70 | } | 73 | } |
71 | 74 | ||
72 | [Test] | 75 | [Test] |
@@ -74,7 +77,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
74 | { | 77 | { |
75 | TestHelpers.InMethod(); | 78 | TestHelpers.InMethod(); |
76 | 79 | ||
77 | TokenBucket tb = new TokenBucket("tb", null, 5000, 10000); | 80 | TokenBucket tb = new TokenBucket(null, 5000,15000); |
78 | AssertRates(tb, 5000, 0, 5000, 10000); | 81 | AssertRates(tb, 5000, 0, 5000, 10000); |
79 | 82 | ||
80 | tb.RequestedDripRate = 4000; | 83 | tb.RequestedDripRate = 4000; |
@@ -92,9 +95,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
92 | { | 95 | { |
93 | TestHelpers.InMethod(); | 96 | TestHelpers.InMethod(); |
94 | 97 | ||
95 | TokenBucket tbParent = new TokenBucket("tbParent", null, 0, 0); | 98 | TokenBucket tbParent = new TokenBucket("tbParent", null, 0); |
96 | TokenBucket tbChild1 = new TokenBucket("tbChild1", tbParent, 3000, 0); | 99 | TokenBucket tbChild1 = new TokenBucket("tbChild1", tbParent, 3000); |
97 | TokenBucket tbChild2 = new TokenBucket("tbChild2", tbParent, 5000, 0); | 100 | TokenBucket tbChild2 = new TokenBucket("tbChild2", tbParent, 5000); |
98 | 101 | ||
99 | AssertRates(tbParent, 8000, 8000, 8000, 0); | 102 | AssertRates(tbParent, 8000, 8000, 8000, 0); |
100 | AssertRates(tbChild1, 3000, 0, 3000, 0); | 103 | AssertRates(tbChild1, 3000, 0, 3000, 0); |
@@ -113,6 +116,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
113 | AssertRates(tbParent, 6000, 8000, 6000, 0); | 116 | AssertRates(tbParent, 6000, 8000, 6000, 0); |
114 | AssertRates(tbChild1, 3000, 0, 6000 / 8 * 3, 0); | 117 | AssertRates(tbChild1, 3000, 0, 6000 / 8 * 3, 0); |
115 | AssertRates(tbChild2, 5000, 0, 6000 / 8 * 5, 0); | 118 | AssertRates(tbChild2, 5000, 0, 6000 / 8 * 5, 0); |
119 | |||
116 | } | 120 | } |
117 | 121 | ||
118 | private void AssertRates( | 122 | private void AssertRates( |
@@ -424,4 +428,5 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
424 | udpClient.SetThrottles(throttles); | 428 | udpClient.SetThrottles(throttles); |
425 | } | 429 | } |
426 | } | 430 | } |
431 | */ | ||
427 | } \ No newline at end of file | 432 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs b/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs index 7a2756b..076551f 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs | |||
@@ -69,6 +69,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
69 | /// <summary>Amount of the texture throttle to steal for the task throttle</summary> | 69 | /// <summary>Amount of the texture throttle to steal for the task throttle</summary> |
70 | public double CannibalizeTextureRate; | 70 | public double CannibalizeTextureRate; |
71 | 71 | ||
72 | public int ClientMaxRate; | ||
73 | public float BrustTime; | ||
74 | |||
72 | /// <summary> | 75 | /// <summary> |
73 | /// Default constructor | 76 | /// Default constructor |
74 | /// </summary> | 77 | /// </summary> |
@@ -88,7 +91,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
88 | Texture = throttleConfig.GetInt("texture_default", 18500); | 91 | Texture = throttleConfig.GetInt("texture_default", 18500); |
89 | Asset = throttleConfig.GetInt("asset_default", 10500); | 92 | Asset = throttleConfig.GetInt("asset_default", 10500); |
90 | 93 | ||
91 | Total = throttleConfig.GetInt("client_throttle_max_bps", 0); | 94 | Total = Resend + Land + Wind + Cloud + Task + Texture + Asset; |
95 | // 3000000 bps default max | ||
96 | ClientMaxRate = throttleConfig.GetInt("client_throttle_max_bps", 375000); | ||
97 | if (ClientMaxRate > 1000000) | ||
98 | ClientMaxRate = 1000000; // no more than 8Mbps | ||
99 | |||
100 | BrustTime = (float)throttleConfig.GetInt("client_throttle_burtsTimeMS", 10); | ||
101 | BrustTime *= 1e-3f; | ||
92 | 102 | ||
93 | AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false); | 103 | AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false); |
94 | MinimumAdaptiveThrottleRate = throttleConfig.GetInt("adaptive_throttle_min_bps", 32000); | 104 | MinimumAdaptiveThrottleRate = throttleConfig.GetInt("adaptive_throttle_min_bps", 32000); |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs b/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs index 4616203..0f71222 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs | |||
@@ -43,25 +43,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
43 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 45 | ||
46 | public string Identifier { get; private set; } | 46 | private static Int32 m_counter = 0; |
47 | |||
48 | public int DebugLevel { get; set; } | ||
49 | 47 | ||
50 | /// <summary> | 48 | // private Int32 m_identifier; |
51 | /// Number of ticks (ms) per quantum, drip rate and max burst | 49 | |
52 | /// are defined over this interval. | 50 | protected const float m_timeScale = 1e-3f; |
53 | /// </summary> | ||
54 | protected const Int32 m_ticksPerQuantum = 1000; | ||
55 | 51 | ||
56 | /// <summary> | 52 | /// <summary> |
57 | /// This is the number of quantums worth of packets that can | 53 | /// This is the number of m_minimumDripRate bytes |
58 | /// be accommodated during a burst | 54 | /// allowed in a burst |
55 | /// roughtly, with this settings, the maximum time system will take | ||
56 | /// to recheck a bucket in ms | ||
57 | /// | ||
59 | /// </summary> | 58 | /// </summary> |
60 | protected const Double m_quantumsPerBurst = 1.5; | 59 | protected const float m_quantumsPerBurst = 5; |
61 | 60 | ||
62 | /// <summary> | 61 | /// <summary> |
63 | /// </summary> | 62 | /// </summary> |
64 | protected const Int32 m_minimumDripRate = LLUDPServer.MTU; | 63 | protected const float m_minimumDripRate = 1500; |
65 | 64 | ||
66 | /// <summary>Time of the last drip, in system ticks</summary> | 65 | /// <summary>Time of the last drip, in system ticks</summary> |
67 | protected Int32 m_lastDrip; | 66 | protected Int32 m_lastDrip; |
@@ -70,40 +69,57 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
70 | /// The number of bytes that can be sent at this moment. This is the | 69 | /// The number of bytes that can be sent at this moment. This is the |
71 | /// current number of tokens in the bucket | 70 | /// current number of tokens in the bucket |
72 | /// </summary> | 71 | /// </summary> |
73 | protected Int64 m_tokenCount; | 72 | protected float m_tokenCount; |
74 | 73 | ||
75 | /// <summary> | 74 | /// <summary> |
76 | /// Map of children buckets and their requested maximum burst rate | 75 | /// Map of children buckets and their requested maximum burst rate |
77 | /// </summary> | 76 | /// </summary> |
78 | protected Dictionary<TokenBucket,Int64> m_children = new Dictionary<TokenBucket,Int64>(); | 77 | |
78 | protected Dictionary<TokenBucket, float> m_children = new Dictionary<TokenBucket, float>(); | ||
79 | |||
80 | #region Properties | ||
79 | 81 | ||
80 | /// <summary> | 82 | /// <summary> |
81 | /// The parent bucket of this bucket, or null if this bucket has no | 83 | /// The parent bucket of this bucket, or null if this bucket has no |
82 | /// parent. The parent bucket will limit the aggregate bandwidth of all | 84 | /// parent. The parent bucket will limit the aggregate bandwidth of all |
83 | /// of its children buckets | 85 | /// of its children buckets |
84 | /// </summary> | 86 | /// </summary> |
85 | public TokenBucket Parent { get; protected set; } | 87 | protected TokenBucket m_parent; |
86 | 88 | public TokenBucket Parent | |
89 | { | ||
90 | get { return m_parent; } | ||
91 | set { m_parent = value; } | ||
92 | } | ||
87 | /// <summary> | 93 | /// <summary> |
88 | /// Maximum burst rate in bytes per second. This is the maximum number | 94 | /// This is the maximum number |
89 | /// of tokens that can accumulate in the bucket at any one time. This | 95 | /// of tokens that can accumulate in the bucket at any one time. This |
90 | /// also sets the total request for leaf nodes | 96 | /// also sets the total request for leaf nodes |
91 | /// </summary> | 97 | /// </summary> |
92 | protected Int64 m_burstRate; | 98 | protected float m_burst; |
93 | public Int64 RequestedBurstRate | 99 | //not in use |
100 | public float MaxDripRate { get; set; } | ||
101 | |||
102 | public float RequestedBurst | ||
94 | { | 103 | { |
95 | get { return m_burstRate; } | 104 | get { return m_burst; } |
96 | set { m_burstRate = (value < 0 ? 0 : value); } | 105 | set { |
106 | float rate = (value < 0 ? 0 : value); | ||
107 | if (rate < 1.5f * m_minimumDripRate) | ||
108 | rate = 1.5f * m_minimumDripRate; | ||
109 | else if (rate > m_minimumDripRate * m_quantumsPerBurst) | ||
110 | rate = m_minimumDripRate * m_quantumsPerBurst; | ||
111 | |||
112 | m_burst = rate; | ||
113 | } | ||
97 | } | 114 | } |
98 | 115 | ||
99 | public Int64 BurstRate | 116 | public float Burst |
100 | { | 117 | { |
101 | get { | 118 | get { |
102 | double rate = RequestedBurstRate * BurstRateModifier(); | 119 | float rate = RequestedBurst * BurstModifier(); |
103 | if (rate < m_minimumDripRate * m_quantumsPerBurst) | 120 | if (rate < m_minimumDripRate) |
104 | rate = m_minimumDripRate * m_quantumsPerBurst; | 121 | rate = m_minimumDripRate; |
105 | 122 | return (float)rate; | |
106 | return (Int64) rate; | ||
107 | } | 123 | } |
108 | } | 124 | } |
109 | 125 | ||
@@ -115,78 +131,50 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
115 | /// Can never be above MaxDripRate. | 131 | /// Can never be above MaxDripRate. |
116 | /// Tokens are added to the bucket at any time | 132 | /// Tokens are added to the bucket at any time |
117 | /// <seealso cref="RemoveTokens"/> is called, at the granularity of | 133 | /// <seealso cref="RemoveTokens"/> is called, at the granularity of |
118 | /// the system tick interval (typically around 15-22ms) | 134 | /// the system tick interval (typically around 15-22ms)</remarks> |
119 | /// FIXME: It is extremely confusing to be able to set a RequestedDripRate of 0 and then receive a positive | 135 | protected float m_dripRate; |
120 | /// number on get if TotalDripRequest is set. This also stops us being able to retrieve the fact that | ||
121 | /// RequestedDripRate is set to 0. Really, this should always return m_dripRate and then we can get | ||
122 | /// (m_dripRate == 0 ? TotalDripRequest : m_dripRate) on some other properties. | ||
123 | /// </remarks> | ||
124 | public virtual Int64 RequestedDripRate | ||
125 | { | ||
126 | get { return (m_dripRate == 0 ? TotalDripRequest : m_dripRate); } | ||
127 | set | ||
128 | { | ||
129 | if (value <= 0) | ||
130 | m_dripRate = 0; | ||
131 | else if (MaxDripRate > 0 && value > MaxDripRate) | ||
132 | m_dripRate = MaxDripRate; | ||
133 | else | ||
134 | m_dripRate = value; | ||
135 | 136 | ||
136 | m_burstRate = (Int64)((double)m_dripRate * m_quantumsPerBurst); | 137 | public virtual float RequestedDripRate |
138 | { | ||
139 | get { return (m_dripRate == 0 ? m_totalDripRequest : m_dripRate); } | ||
140 | set { | ||
141 | m_dripRate = (value < 0 ? 0 : value); | ||
142 | m_totalDripRequest = m_dripRate; | ||
137 | 143 | ||
138 | if (Parent != null) | 144 | if (m_parent != null) |
139 | Parent.RegisterRequest(this, m_dripRate); | 145 | m_parent.RegisterRequest(this,m_dripRate); |
140 | } | 146 | } |
141 | } | 147 | } |
142 | 148 | ||
143 | /// <summary> | 149 | public virtual float DripRate |
144 | /// Gets the drip rate. | ||
145 | /// </summary> | ||
146 | /// <value> | ||
147 | /// DripRate can never be above max drip rate or below min drip rate. | ||
148 | /// If we are a child bucket then the drip rate return is modifed by the total load on the capacity of the | ||
149 | /// parent bucket. | ||
150 | /// </value> | ||
151 | public virtual Int64 DripRate | ||
152 | { | 150 | { |
153 | get | 151 | get { |
154 | { | 152 | float rate = Math.Min(RequestedDripRate,TotalDripRequest); |
155 | double rate; | 153 | if (m_parent == null) |
156 | 154 | return rate; | |
157 | // FIXME: This doesn't properly work if we have a parent and children and a requested drip rate set | ||
158 | // on ourselves which is not equal to the child drip rates. | ||
159 | if (Parent == null) | ||
160 | { | ||
161 | if (TotalDripRequest > 0) | ||
162 | rate = Math.Min(RequestedDripRate, TotalDripRequest); | ||
163 | else | ||
164 | rate = RequestedDripRate; | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | rate = (double)RequestedDripRate * Parent.DripRateModifier(); | ||
169 | } | ||
170 | 155 | ||
156 | rate *= m_parent.DripRateModifier(); | ||
171 | if (rate < m_minimumDripRate) | 157 | if (rate < m_minimumDripRate) |
172 | rate = m_minimumDripRate; | 158 | rate = m_minimumDripRate; |
173 | else if (MaxDripRate > 0 && rate > MaxDripRate) | ||
174 | rate = MaxDripRate; | ||
175 | 159 | ||
176 | return (Int64)rate; | 160 | return (float)rate; |
177 | } | 161 | } |
178 | } | 162 | } |
179 | protected Int64 m_dripRate; | ||
180 | |||
181 | // <summary> | ||
182 | // The maximum rate for flow control. Drip rate can never be greater than this. | ||
183 | // </summary> | ||
184 | public Int64 MaxDripRate { get; set; } | ||
185 | 163 | ||
186 | /// <summary> | 164 | /// <summary> |
187 | /// The current total of the requested maximum burst rates of children buckets. | 165 | /// The current total of the requested maximum burst rates of children buckets. |
188 | /// </summary> | 166 | /// </summary> |
189 | public Int64 TotalDripRequest { get; protected set; } | 167 | protected float m_totalDripRequest; |
168 | public float TotalDripRequest | ||
169 | { | ||
170 | get { return m_totalDripRequest; } | ||
171 | set { m_totalDripRequest = value; } | ||
172 | } | ||
173 | |||
174 | #endregion Properties | ||
175 | |||
176 | #region Constructor | ||
177 | |||
190 | 178 | ||
191 | /// <summary> | 179 | /// <summary> |
192 | /// Default constructor | 180 | /// Default constructor |
@@ -194,20 +182,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
194 | /// <param name="identifier">Identifier for this token bucket</param> | 182 | /// <param name="identifier">Identifier for this token bucket</param> |
195 | /// <param name="parent">Parent bucket if this is a child bucket, or | 183 | /// <param name="parent">Parent bucket if this is a child bucket, or |
196 | /// null if this is a root bucket</param> | 184 | /// null if this is a root bucket</param> |
197 | /// <param name="requestedDripRate"> | 185 | /// <param name="maxBurst">Maximum size of the bucket in bytes, or |
198 | /// Requested rate that the bucket fills, in bytes per | 186 | /// zero if this bucket has no maximum capacity</param> |
199 | /// second. If zero, the bucket always remains full. | 187 | /// <param name="dripRate">Rate that the bucket fills, in bytes per |
200 | /// </param> | 188 | /// second. If zero, the bucket always remains full</param> |
201 | public TokenBucket(string identifier, TokenBucket parent, Int64 requestedDripRate, Int64 maxDripRate) | 189 | public TokenBucket(TokenBucket parent, float dripRate, float MaxBurst) |
202 | { | 190 | { |
203 | Identifier = identifier; | 191 | m_counter++; |
204 | 192 | ||
205 | Parent = parent; | 193 | Parent = parent; |
206 | RequestedDripRate = requestedDripRate; | 194 | RequestedDripRate = dripRate; |
207 | MaxDripRate = maxDripRate; | 195 | RequestedBurst = MaxBurst; |
208 | m_lastDrip = Util.EnvironmentTickCount(); | 196 | // TotalDripRequest = dripRate; // this will be overwritten when a child node registers |
197 | // MaxBurst = (Int64)((double)dripRate * m_quantumsPerBurst); | ||
198 | m_lastDrip = Util.EnvironmentTickCount() + 100000; | ||
209 | } | 199 | } |
210 | 200 | ||
201 | #endregion Constructor | ||
202 | |||
211 | /// <summary> | 203 | /// <summary> |
212 | /// Compute a modifier for the MaxBurst rate. This is 1.0, meaning | 204 | /// Compute a modifier for the MaxBurst rate. This is 1.0, meaning |
213 | /// no modification if the requested bandwidth is less than the | 205 | /// no modification if the requested bandwidth is less than the |
@@ -215,22 +207,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
215 | /// hierarchy. However, if any of the parents is over-booked, then | 207 | /// hierarchy. However, if any of the parents is over-booked, then |
216 | /// the modifier will be less than 1. | 208 | /// the modifier will be less than 1. |
217 | /// </summary> | 209 | /// </summary> |
218 | protected double DripRateModifier() | 210 | protected float DripRateModifier() |
219 | { | 211 | { |
220 | Int64 driprate = DripRate; | 212 | float driprate = DripRate; |
221 | double modifier = driprate >= TotalDripRequest ? 1.0 : (double)driprate / (double)TotalDripRequest; | 213 | return driprate >= TotalDripRequest ? 1.0f : driprate / TotalDripRequest; |
222 | |||
223 | // if (DebugLevel > 0) | ||
224 | // m_log.DebugFormat( | ||
225 | // "[TOKEN BUCKET]: Returning drip modifier {0}/{1} = {2} from {3}", | ||
226 | // driprate, TotalDripRequest, modifier, Identifier); | ||
227 | |||
228 | return modifier; | ||
229 | } | 214 | } |
230 | 215 | ||
231 | /// <summary> | 216 | /// <summary> |
232 | /// </summary> | 217 | /// </summary> |
233 | protected double BurstRateModifier() | 218 | protected float BurstModifier() |
234 | { | 219 | { |
235 | // for now... burst rate is always m_quantumsPerBurst (constant) | 220 | // for now... burst rate is always m_quantumsPerBurst (constant) |
236 | // larger than drip rate so the ratio of burst requests is the | 221 | // larger than drip rate so the ratio of burst requests is the |
@@ -242,29 +227,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
242 | /// Register drip rate requested by a child of this throttle. Pass the | 227 | /// Register drip rate requested by a child of this throttle. Pass the |
243 | /// changes up the hierarchy. | 228 | /// changes up the hierarchy. |
244 | /// </summary> | 229 | /// </summary> |
245 | public void RegisterRequest(TokenBucket child, Int64 request) | 230 | public void RegisterRequest(TokenBucket child, float request) |
246 | { | 231 | { |
247 | lock (m_children) | 232 | lock (m_children) |
248 | { | 233 | { |
249 | m_children[child] = request; | 234 | m_children[child] = request; |
250 | 235 | ||
251 | TotalDripRequest = 0; | 236 | m_totalDripRequest = 0; |
252 | foreach (KeyValuePair<TokenBucket, Int64> cref in m_children) | 237 | foreach (KeyValuePair<TokenBucket, float> cref in m_children) |
253 | TotalDripRequest += cref.Value; | 238 | m_totalDripRequest += cref.Value; |
254 | } | 239 | } |
255 | 240 | ||
256 | // Pass the new values up to the parent | 241 | // Pass the new values up to the parent |
257 | if (Parent != null) | 242 | if (m_parent != null) |
258 | { | 243 | m_parent.RegisterRequest(this, Math.Min(RequestedDripRate, TotalDripRequest)); |
259 | Int64 effectiveDripRate; | ||
260 | |||
261 | if (RequestedDripRate > 0) | ||
262 | effectiveDripRate = Math.Min(RequestedDripRate, TotalDripRequest); | ||
263 | else | ||
264 | effectiveDripRate = TotalDripRequest; | ||
265 | |||
266 | Parent.RegisterRequest(this, effectiveDripRate); | ||
267 | } | ||
268 | } | 244 | } |
269 | 245 | ||
270 | /// <summary> | 246 | /// <summary> |
@@ -277,9 +253,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
277 | { | 253 | { |
278 | m_children.Remove(child); | 254 | m_children.Remove(child); |
279 | 255 | ||
280 | TotalDripRequest = 0; | 256 | m_totalDripRequest = 0; |
281 | foreach (KeyValuePair<TokenBucket, Int64> cref in m_children) | 257 | foreach (KeyValuePair<TokenBucket, float> cref in m_children) |
282 | TotalDripRequest += cref.Value; | 258 | m_totalDripRequest += cref.Value; |
283 | } | 259 | } |
284 | 260 | ||
285 | // Pass the new values up to the parent | 261 | // Pass the new values up to the parent |
@@ -293,7 +269,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
293 | /// <param name="amount">Number of tokens to remove from the bucket</param> | 269 | /// <param name="amount">Number of tokens to remove from the bucket</param> |
294 | /// <returns>True if the requested number of tokens were removed from | 270 | /// <returns>True if the requested number of tokens were removed from |
295 | /// the bucket, otherwise false</returns> | 271 | /// the bucket, otherwise false</returns> |
296 | public bool RemoveTokens(Int64 amount) | 272 | public bool RemoveTokens(int amount) |
297 | { | 273 | { |
298 | // Deposit tokens for this interval | 274 | // Deposit tokens for this interval |
299 | Drip(); | 275 | Drip(); |
@@ -310,19 +286,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
310 | return false; | 286 | return false; |
311 | } | 287 | } |
312 | 288 | ||
313 | /// <summary> | 289 | public bool CheckTokens(int amount) |
314 | /// Deposit tokens into the bucket from a child bucket that did | ||
315 | /// not use all of its available tokens | ||
316 | /// </summary> | ||
317 | protected void Deposit(Int64 count) | ||
318 | { | 290 | { |
319 | m_tokenCount += count; | 291 | return (m_tokenCount - amount >= 0); |
292 | } | ||
320 | 293 | ||
321 | // Deposit the overflow in the parent bucket, this is how we share | 294 | public int GetCatBytesCanSend(int timeMS) |
322 | // unused bandwidth | 295 | { |
323 | Int64 burstrate = BurstRate; | 296 | // return (int)(m_tokenCount + timeMS * m_dripRate * 1e-3); |
324 | if (m_tokenCount > burstrate) | 297 | return (int)(timeMS * DripRate * 1e-3); |
325 | m_tokenCount = burstrate; | ||
326 | } | 298 | } |
327 | 299 | ||
328 | /// <summary> | 300 | /// <summary> |
@@ -337,21 +309,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
337 | // with no drip rate... | 309 | // with no drip rate... |
338 | if (DripRate == 0) | 310 | if (DripRate == 0) |
339 | { | 311 | { |
340 | m_log.WarnFormat("[TOKENBUCKET] something odd is happening and drip rate is 0 for {0}", Identifier); | 312 | m_log.WarnFormat("[TOKENBUCKET] something odd is happening and drip rate is 0 for {0}", m_counter); |
341 | return; | 313 | return; |
342 | } | 314 | } |
343 | 315 | ||
344 | // Determine the interval over which we are adding tokens, never add | 316 | Int32 now = Util.EnvironmentTickCount(); |
345 | // more than a single quantum of tokens | 317 | Int32 deltaMS = now - m_lastDrip; |
346 | Int32 deltaMS = Math.Min(Util.EnvironmentTickCountSubtract(m_lastDrip), m_ticksPerQuantum); | 318 | m_lastDrip = now; |
347 | m_lastDrip = Util.EnvironmentTickCount(); | ||
348 | 319 | ||
349 | // This can be 0 in the very unusual case that the timer wrapped | ||
350 | // It can be 0 if we try add tokens at a sub-tick rate | ||
351 | if (deltaMS <= 0) | 320 | if (deltaMS <= 0) |
352 | return; | 321 | return; |
353 | 322 | ||
354 | Deposit(deltaMS * DripRate / m_ticksPerQuantum); | 323 | m_tokenCount += deltaMS * DripRate * m_timeScale; |
324 | |||
325 | float burst = Burst; | ||
326 | if (m_tokenCount > burst) | ||
327 | m_tokenCount = burst; | ||
355 | } | 328 | } |
356 | } | 329 | } |
357 | 330 | ||
@@ -362,103 +335,79 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
362 | public bool AdaptiveEnabled { get; set; } | 335 | public bool AdaptiveEnabled { get; set; } |
363 | 336 | ||
364 | /// <summary> | 337 | /// <summary> |
365 | /// Target drip rate for this bucket. | 338 | /// The minimum rate for flow control. Minimum drip rate is one |
339 | /// packet per second. | ||
366 | /// </summary> | 340 | /// </summary> |
367 | /// <remarks>Usually set by the client. If adaptive is enabled then throttles will increase until we reach this.</remarks> | 341 | |
368 | public Int64 TargetDripRate | 342 | protected const float m_minimumFlow = 50000; |
369 | { | 343 | |
370 | get { return m_targetDripRate; } | 344 | // <summary> |
371 | set | 345 | // The maximum rate for flow control. Drip rate can never be |
346 | // greater than this. | ||
347 | // </summary> | ||
348 | |||
349 | protected float m_maxDripRate = 0; | ||
350 | public float MaxDripRate | ||
351 | { | ||
352 | get { return (m_maxDripRate == 0 ? m_totalDripRequest : m_maxDripRate); } | ||
353 | set | ||
372 | { | 354 | { |
373 | m_targetDripRate = Math.Max(value, m_minimumFlow); | 355 | m_maxDripRate = (value == 0 ? m_totalDripRequest : Math.Max(value, m_minimumFlow)); |
374 | } | 356 | } |
375 | } | 357 | } |
376 | protected Int64 m_targetDripRate; | 358 | |
359 | private bool m_enabled = false; | ||
377 | 360 | ||
378 | // <summary> | 361 | // <summary> |
379 | // Adjust drip rate in response to network conditions. | 362 | // Adjust drip rate in response to network conditions. |
380 | // </summary> | 363 | // </summary> |
381 | public virtual Int64 AdjustedDripRate | 364 | public virtual float AdjustedDripRate |
382 | { | 365 | { |
383 | get { return m_dripRate; } | 366 | get { return m_dripRate; } |
384 | set | 367 | set |
385 | { | 368 | { |
386 | m_dripRate = OpenSim.Framework.Util.Clamp<Int64>(value, m_minimumFlow, TargetDripRate); | 369 | m_dripRate = OpenSim.Framework.Util.Clamp<float>(value, m_minimumFlow, MaxDripRate); |
387 | m_burstRate = (Int64)((double)m_dripRate * m_quantumsPerBurst); | ||
388 | 370 | ||
389 | if (Parent != null) | 371 | if (m_parent != null) |
390 | Parent.RegisterRequest(this, m_dripRate); | 372 | m_parent.RegisterRequest(this, m_dripRate); |
391 | } | 373 | } |
392 | } | 374 | } |
393 | 375 | ||
394 | /// <summary> | 376 | |
395 | /// The minimum rate for adaptive flow control. | 377 | // <summary> |
396 | /// </summary> | 378 | // |
397 | protected Int64 m_minimumFlow = 32000; | 379 | // </summary> |
398 | 380 | public AdaptiveTokenBucket(TokenBucket parent, float maxDripRate, float maxBurst, bool enabled) | |
399 | /// <summary> | 381 | : base(parent, maxDripRate, maxBurst) |
400 | /// Constructor for the AdaptiveTokenBucket class | ||
401 | /// <param name="identifier">Unique identifier for the client</param> | ||
402 | /// <param name="parent">Parent bucket in the hierarchy</param> | ||
403 | /// <param name="requestedDripRate"></param> | ||
404 | /// <param name="maxDripRate">The ceiling rate for adaptation</param> | ||
405 | /// <param name="minDripRate">The floor rate for adaptation</param> | ||
406 | /// </summary> | ||
407 | public AdaptiveTokenBucket(string identifier, TokenBucket parent, Int64 requestedDripRate, Int64 maxDripRate, Int64 minDripRate, bool enabled) | ||
408 | : base(identifier, parent, requestedDripRate, maxDripRate) | ||
409 | { | 382 | { |
410 | AdaptiveEnabled = enabled; | 383 | m_enabled = enabled; |
411 | 384 | ||
412 | if (AdaptiveEnabled) | 385 | MaxDripRate = maxDripRate; |
413 | { | 386 | |
414 | // m_log.DebugFormat("[TOKENBUCKET]: Adaptive throttle enabled"); | 387 | if (enabled) |
415 | m_minimumFlow = minDripRate; | 388 | AdjustedDripRate = m_maxDripRate * .5f; |
416 | TargetDripRate = m_minimumFlow; | 389 | else |
417 | AdjustedDripRate = m_minimumFlow; | 390 | AdjustedDripRate = m_maxDripRate; |
418 | } | ||
419 | } | 391 | } |
420 | 392 | ||
421 | /// <summary> | 393 | /// <summary> |
422 | /// Reliable packets sent to the client for which we never received an ack adjust the drip rate down. | 394 | /// Reliable packets sent to the client for which we never received an ack adjust the drip rate down. |
423 | /// <param name="packets">Number of packets that expired without successful delivery</param> | 395 | /// <param name="packets">Number of packets that expired without successful delivery</param> |
424 | /// </summary> | 396 | /// </summary> |
425 | public void ExpirePackets(Int32 packets) | 397 | public void ExpirePackets(Int32 count) |
426 | { | 398 | { |
427 | if (AdaptiveEnabled) | 399 | // m_log.WarnFormat("[ADAPTIVEBUCKET] drop {0} by {1} expired packets",AdjustedDripRate,count); |
428 | { | 400 | if (m_enabled) |
429 | if (DebugLevel > 0) | 401 | AdjustedDripRate = (Int64)(AdjustedDripRate / Math.Pow(2, count)); |
430 | m_log.WarnFormat( | ||
431 | "[ADAPTIVEBUCKET] drop {0} by {1} expired packets for {2}", | ||
432 | AdjustedDripRate, packets, Identifier); | ||
433 | |||
434 | // AdjustedDripRate = (Int64) (AdjustedDripRate / Math.Pow(2,packets)); | ||
435 | |||
436 | // Compute the fallback solely on the rate allocated beyond the minimum, this | ||
437 | // should smooth out the fallback to the minimum rate | ||
438 | AdjustedDripRate = m_minimumFlow + (Int64) ((AdjustedDripRate - m_minimumFlow) / Math.Pow(2, packets)); | ||
439 | } | ||
440 | } | 402 | } |
441 | 403 | ||
442 | /// <summary> | 404 | // <summary> |
443 | /// Reliable packets acked by the client adjust the drip rate up. | 405 | // |
444 | /// <param name="packets">Number of packets successfully acknowledged</param> | 406 | // </summary> |
445 | /// </summary> | 407 | public void AcknowledgePackets(Int32 count) |
446 | public void AcknowledgePackets(Int32 packets) | ||
447 | { | ||
448 | if (AdaptiveEnabled) | ||
449 | AdjustedDripRate = AdjustedDripRate + packets * LLUDPServer.MTU; | ||
450 | } | ||
451 | |||
452 | /// <summary> | ||
453 | /// Adjust the minimum flow level for the adaptive throttle, this will drop adjusted | ||
454 | /// throttles back to the minimum levels | ||
455 | /// <param>minDripRate--the new minimum flow</param> | ||
456 | /// </summary> | ||
457 | public void ResetMinimumAdaptiveFlow(Int64 minDripRate) | ||
458 | { | 408 | { |
459 | m_minimumFlow = minDripRate; | 409 | if (m_enabled) |
460 | TargetDripRate = m_minimumFlow; | 410 | AdjustedDripRate = AdjustedDripRate + count; |
461 | AdjustedDripRate = m_minimumFlow; | ||
462 | } | 411 | } |
463 | } | 412 | } |
464 | } \ No newline at end of file | 413 | } |