diff options
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework')
8 files changed, 230 insertions, 45 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 1d1a0a1..0ba67d3 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -174,9 +174,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
174 | position.Z = newPosZ; | 174 | position.Z = newPosZ; |
175 | } | 175 | } |
176 | 176 | ||
177 | // Only send this if the event queue is null | 177 | sp.ControllingClient.SendTeleportStart(teleportFlags); |
178 | if (eq == null) | ||
179 | sp.ControllingClient.SendTeleportLocationStart(); | ||
180 | 178 | ||
181 | sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags); | 179 | sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags); |
182 | sp.Teleport(position); | 180 | sp.Teleport(position); |
@@ -257,9 +255,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
257 | 255 | ||
258 | ulong destinationHandle = finalDestination.RegionHandle; | 256 | ulong destinationHandle = finalDestination.RegionHandle; |
259 | 257 | ||
260 | if (eq == null) | ||
261 | sp.ControllingClient.SendTeleportLocationStart(); | ||
262 | |||
263 | // Let's do DNS resolution only once in this process, please! | 258 | // Let's do DNS resolution only once in this process, please! |
264 | // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field, | 259 | // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field, |
265 | // it's actually doing a lot of work. | 260 | // it's actually doing a lot of work. |
@@ -277,6 +272,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
277 | return; | 272 | return; |
278 | } | 273 | } |
279 | 274 | ||
275 | sp.ControllingClient.SendTeleportStart(teleportFlags); | ||
276 | |||
280 | // the avatar.Close below will clear the child region list. We need this below for (possibly) | 277 | // the avatar.Close below will clear the child region list. We need this below for (possibly) |
281 | // closing the child agents, so save it here (we need a copy as it is Clear()-ed). | 278 | // closing the child agents, so save it here (we need a copy as it is Clear()-ed). |
282 | //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList()); | 279 | //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList()); |
@@ -307,7 +304,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
307 | string reason = String.Empty; | 304 | string reason = String.Empty; |
308 | 305 | ||
309 | // Let's create an agent there if one doesn't exist yet. | 306 | // Let's create an agent there if one doesn't exist yet. |
310 | if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason)) | 307 | bool logout = false; |
308 | if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout)) | ||
311 | { | 309 | { |
312 | sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}", | 310 | sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}", |
313 | reason)); | 311 | reason)); |
@@ -319,6 +317,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
319 | 317 | ||
320 | if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY)) | 318 | if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY)) |
321 | { | 319 | { |
320 | //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Creating agent..."); | ||
321 | |||
322 | #region IP Translation for NAT | 322 | #region IP Translation for NAT |
323 | IClientIPEndpoint ipepClient; | 323 | IClientIPEndpoint ipepClient; |
324 | if (sp.ClientView.TryGet(out ipepClient)) | 324 | if (sp.ClientView.TryGet(out ipepClient)) |
@@ -396,6 +396,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
396 | agent.Position = position; | 396 | agent.Position = position; |
397 | SetCallbackURL(agent, sp.Scene.RegionInfo); | 397 | SetCallbackURL(agent, sp.Scene.RegionInfo); |
398 | 398 | ||
399 | //sp.ControllingClient.SendTeleportProgress(teleportFlags, "Updating agent..."); | ||
400 | |||
399 | if (!UpdateAgent(reg, finalDestination, agent)) | 401 | if (!UpdateAgent(reg, finalDestination, agent)) |
400 | { | 402 | { |
401 | // Region doesn't take it | 403 | // Region doesn't take it |
@@ -434,8 +436,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
434 | // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it | 436 | // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it |
435 | CrossAttachmentsIntoNewRegion(finalDestination, sp, true); | 437 | CrossAttachmentsIntoNewRegion(finalDestination, sp, true); |
436 | 438 | ||
439 | // Well, this is it. The agent is over there. | ||
440 | |||
437 | KillEntity(sp.Scene, sp.LocalId); | 441 | KillEntity(sp.Scene, sp.LocalId); |
438 | 442 | ||
443 | // May need to logout or other cleanup | ||
444 | AgentHasMovedAway(sp.ControllingClient.SessionId, logout); | ||
445 | |||
439 | // Now let's make it officially a child agent | 446 | // Now let's make it officially a child agent |
440 | sp.MakeChildAgent(); | 447 | sp.MakeChildAgent(); |
441 | 448 | ||
@@ -483,8 +490,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
483 | 490 | ||
484 | } | 491 | } |
485 | 492 | ||
486 | protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) | 493 | protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason, out bool logout) |
487 | { | 494 | { |
495 | logout = false; | ||
488 | return m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); | 496 | return m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); |
489 | } | 497 | } |
490 | 498 | ||
@@ -500,6 +508,10 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
500 | 508 | ||
501 | } | 509 | } |
502 | 510 | ||
511 | protected virtual void AgentHasMovedAway(UUID sessionID, bool logout) | ||
512 | { | ||
513 | } | ||
514 | |||
503 | protected void KillEntity(Scene scene, uint localID) | 515 | protected void KillEntity(Scene scene, uint localID) |
504 | { | 516 | { |
505 | scene.SendKillObject(localID); | 517 | scene.SendKillObject(localID); |
@@ -1286,18 +1298,18 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
1286 | return handles; | 1298 | return handles; |
1287 | } | 1299 | } |
1288 | 1300 | ||
1289 | private void Dump(string msg, List<ulong> handles) | 1301 | // private void Dump(string msg, List<ulong> handles) |
1290 | { | 1302 | // { |
1291 | m_log.InfoFormat("-------------- HANDLE DUMP ({0}) ---------", msg); | 1303 | // m_log.InfoFormat("-------------- HANDLE DUMP ({0}) ---------", msg); |
1292 | foreach (ulong handle in handles) | 1304 | // foreach (ulong handle in handles) |
1293 | { | 1305 | // { |
1294 | uint x, y; | 1306 | // uint x, y; |
1295 | Utils.LongToUInts(handle, out x, out y); | 1307 | // Utils.LongToUInts(handle, out x, out y); |
1296 | x = x / Constants.RegionSize; | 1308 | // x = x / Constants.RegionSize; |
1297 | y = y / Constants.RegionSize; | 1309 | // y = y / Constants.RegionSize; |
1298 | m_log.InfoFormat("({0}, {1})", x, y); | 1310 | // m_log.InfoFormat("({0}, {1})", x, y); |
1299 | } | 1311 | // } |
1300 | } | 1312 | // } |
1301 | 1313 | ||
1302 | #endregion | 1314 | #endregion |
1303 | 1315 | ||
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 7d26e3f..1ac7508 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs | |||
@@ -140,9 +140,17 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
140 | return false; | 140 | return false; |
141 | } | 141 | } |
142 | 142 | ||
143 | protected override bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) | 143 | protected override void AgentHasMovedAway(UUID sessionID, bool logout) |
144 | { | ||
145 | if (logout) | ||
146 | // Log them out of this grid | ||
147 | m_aScene.PresenceService.LogoutAgent(sessionID); | ||
148 | } | ||
149 | |||
150 | protected override bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason, out bool logout) | ||
144 | { | 151 | { |
145 | reason = string.Empty; | 152 | reason = string.Empty; |
153 | logout = false; | ||
146 | int flags = m_aScene.GridService.GetRegionFlags(m_aScene.RegionInfo.ScopeID, reg.RegionID); | 154 | int flags = m_aScene.GridService.GetRegionFlags(m_aScene.RegionInfo.ScopeID, reg.RegionID); |
147 | if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) | 155 | if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) |
148 | { | 156 | { |
@@ -152,9 +160,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
152 | string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString(); | 160 | string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString(); |
153 | IUserAgentService connector = new UserAgentServiceConnector(userAgentDriver); | 161 | IUserAgentService connector = new UserAgentServiceConnector(userAgentDriver); |
154 | bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, out reason); | 162 | bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, out reason); |
155 | if (success) | 163 | logout = success; // flag for later logout from this grid; this is an HG TP |
156 | // Log them out of this grid | ||
157 | m_aScene.PresenceService.LogoutAgent(agentCircuit.SessionID); | ||
158 | 164 | ||
159 | return success; | 165 | return success; |
160 | } | 166 | } |
diff --git a/OpenSim/Region/CoreModules/Framework/EventQueue/EventQueueHelper.cs b/OpenSim/Region/CoreModules/Framework/EventQueue/EventQueueHelper.cs index efa60bb..e9bcae3 100644 --- a/OpenSim/Region/CoreModules/Framework/EventQueue/EventQueueHelper.cs +++ b/OpenSim/Region/CoreModules/Framework/EventQueue/EventQueueHelper.cs | |||
@@ -54,12 +54,10 @@ namespace OpenSim.Region.CoreModules.Framework.EventQueue | |||
54 | } | 54 | } |
55 | 55 | ||
56 | private static byte[] uintToByteArray(uint uIntValue) | 56 | private static byte[] uintToByteArray(uint uIntValue) |
57 | { | 57 | { |
58 | byte[] resultbytes = Utils.UIntToBytes(uIntValue); | 58 | byte[] result = new byte[4]; |
59 | if (BitConverter.IsLittleEndian) | 59 | Utils.UIntToBytesBig(uIntValue, result, 0); |
60 | Array.Reverse(resultbytes); | 60 | return result; |
61 | |||
62 | return resultbytes; | ||
63 | } | 61 | } |
64 | 62 | ||
65 | public static OSD buildEvent(string eventName, OSD eventBody) | 63 | public static OSD buildEvent(string eventName, OSD eventBody) |
@@ -160,7 +158,7 @@ namespace OpenSim.Region.CoreModules.Framework.EventQueue | |||
160 | info.Add("SimAccess", OSD.FromInteger(simAccess)); | 158 | info.Add("SimAccess", OSD.FromInteger(simAccess)); |
161 | info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); | 159 | info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); |
162 | info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); | 160 | info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); |
163 | info.Add("TeleportFlags", OSD.FromBinary(1L << 4)); // AgentManager.TeleportFlags.ViaLocation | 161 | info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation |
164 | 162 | ||
165 | OSDArray infoArr = new OSDArray(); | 163 | OSDArray infoArr = new OSDArray(); |
166 | infoArr.Add(info); | 164 | infoArr.Add(info); |
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs index b13b9d8..ccb892e 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs | |||
@@ -95,7 +95,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
95 | try | 95 | try |
96 | { | 96 | { |
97 | asset1.ID = url + "/" + asset.ID; | 97 | asset1.ID = url + "/" + asset.ID; |
98 | UUID temp = UUID.Zero; | 98 | // UUID temp = UUID.Zero; |
99 | // TODO: if the creator is local, stick this grid's URL in front | 99 | // TODO: if the creator is local, stick this grid's URL in front |
100 | //if (UUID.TryParse(asset.Metadata.CreatorID, out temp)) | 100 | //if (UUID.TryParse(asset.Metadata.CreatorID, out temp)) |
101 | // asset1.Metadata.CreatorID = ??? + "/" + asset.Metadata.CreatorID; | 101 | // asset1.Metadata.CreatorID = ??? + "/" + asset.Metadata.CreatorID; |
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs index 8ccc941..c673b31 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -54,7 +54,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
54 | get { return m_assMapper; } | 54 | get { return m_assMapper; } |
55 | } | 55 | } |
56 | 56 | ||
57 | private bool m_Initialized = false; | 57 | // private bool m_Initialized = false; |
58 | 58 | ||
59 | #region INonSharedRegionModule | 59 | #region INonSharedRegionModule |
60 | 60 | ||
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index 2517a23..cc12df0 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -572,7 +572,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
572 | } | 572 | } |
573 | if (attachment) | 573 | if (attachment) |
574 | { | 574 | { |
575 | group.RootPart.ObjectFlags |= (uint)PrimFlags.Phantom; | 575 | group.RootPart.Flags |= PrimFlags.Phantom; |
576 | group.RootPart.IsAttachment = true; | 576 | group.RootPart.IsAttachment = true; |
577 | } | 577 | } |
578 | 578 | ||
diff --git a/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs b/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs index 9c20d68..d570608 100644 --- a/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs +++ b/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs | |||
@@ -51,7 +51,7 @@ namespace OpenSim.Region.CoreModules.Framework.Library | |||
51 | private static bool m_HasRunOnce = false; | 51 | private static bool m_HasRunOnce = false; |
52 | 52 | ||
53 | private bool m_Enabled = false; | 53 | private bool m_Enabled = false; |
54 | private string m_LibraryName = "OpenSim Library"; | 54 | // private string m_LibraryName = "OpenSim Library"; |
55 | private Scene m_Scene; | 55 | private Scene m_Scene; |
56 | 56 | ||
57 | private ILibraryService m_Library; | 57 | private ILibraryService m_Library; |
@@ -212,13 +212,13 @@ namespace OpenSim.Region.CoreModules.Framework.Library | |||
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | private void DumpLibrary() | 215 | // private void DumpLibrary() |
216 | { | 216 | // { |
217 | InventoryFolderImpl lib = m_Library.LibraryRootFolder; | 217 | // InventoryFolderImpl lib = m_Library.LibraryRootFolder; |
218 | 218 | // | |
219 | m_log.DebugFormat(" - folder {0}", lib.Name); | 219 | // m_log.DebugFormat(" - folder {0}", lib.Name); |
220 | DumpFolder(lib); | 220 | // DumpFolder(lib); |
221 | } | 221 | // } |
222 | // | 222 | // |
223 | // private void DumpLibrary() | 223 | // private void DumpLibrary() |
224 | // { | 224 | // { |
diff --git a/OpenSim/Region/CoreModules/Framework/Statistics/Logging/BinaryLoggingModule.cs b/OpenSim/Region/CoreModules/Framework/Statistics/Logging/BinaryLoggingModule.cs new file mode 100644 index 0000000..b75a700 --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/Statistics/Logging/BinaryLoggingModule.cs | |||
@@ -0,0 +1,169 @@ | |||
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.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Mono.Addins; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.Packets; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.Framework; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.Avatar.Attachments | ||
43 | { | ||
44 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BinaryLoggingModule")] | ||
45 | public class BinaryLoggingModule : INonSharedRegionModule | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected bool m_collectStats; | ||
50 | protected Scene m_scene = null; | ||
51 | |||
52 | public string Name { get { return "Binary Statistics Logging Module"; } } | ||
53 | public Type ReplaceableInterface { get { return null; } } | ||
54 | |||
55 | public void Initialise(IConfigSource source) | ||
56 | { | ||
57 | try | ||
58 | { | ||
59 | IConfig statConfig = source.Configs["Statistics.Binary"]; | ||
60 | if (statConfig.Contains("enabled") && statConfig.GetBoolean("enabled")) | ||
61 | { | ||
62 | if (statConfig.Contains("collect_region_stats")) | ||
63 | { | ||
64 | if (statConfig.GetBoolean("collect_region_stats")) | ||
65 | { | ||
66 | m_collectStats = true; | ||
67 | } | ||
68 | } | ||
69 | if (statConfig.Contains("region_stats_period_seconds")) | ||
70 | { | ||
71 | m_statLogPeriod = TimeSpan.FromSeconds(statConfig.GetInt("region_stats_period_seconds")); | ||
72 | } | ||
73 | if (statConfig.Contains("stats_dir")) | ||
74 | { | ||
75 | m_statsDir = statConfig.GetString("stats_dir"); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | catch | ||
80 | { | ||
81 | // if it doesn't work, we don't collect anything | ||
82 | } | ||
83 | } | ||
84 | |||
85 | public void AddRegion(Scene scene) | ||
86 | { | ||
87 | m_scene = scene; | ||
88 | } | ||
89 | |||
90 | public void RemoveRegion(Scene scene) | ||
91 | { | ||
92 | } | ||
93 | |||
94 | public void RegionLoaded(Scene scene) | ||
95 | { | ||
96 | if (m_collectStats) | ||
97 | m_scene.StatsReporter.OnSendStatsResult += LogSimStats; | ||
98 | } | ||
99 | |||
100 | public void Close() | ||
101 | { | ||
102 | } | ||
103 | |||
104 | public class StatLogger | ||
105 | { | ||
106 | public DateTime StartTime; | ||
107 | public string Path; | ||
108 | public System.IO.BinaryWriter Log; | ||
109 | } | ||
110 | |||
111 | static StatLogger m_statLog = null; | ||
112 | static TimeSpan m_statLogPeriod = TimeSpan.FromSeconds(300); | ||
113 | static string m_statsDir = String.Empty; | ||
114 | static Object m_statLockObject = new Object(); | ||
115 | |||
116 | private void LogSimStats(SimStats stats) | ||
117 | { | ||
118 | SimStatsPacket pack = new SimStatsPacket(); | ||
119 | pack.Region = new SimStatsPacket.RegionBlock(); | ||
120 | pack.Region.RegionX = stats.RegionX; | ||
121 | pack.Region.RegionY = stats.RegionY; | ||
122 | pack.Region.RegionFlags = stats.RegionFlags; | ||
123 | pack.Region.ObjectCapacity = stats.ObjectCapacity; | ||
124 | //pack.Region = //stats.RegionBlock; | ||
125 | pack.Stat = stats.StatsBlock; | ||
126 | pack.Header.Reliable = false; | ||
127 | |||
128 | // note that we are inside the reporter lock when called | ||
129 | DateTime now = DateTime.Now; | ||
130 | |||
131 | // hide some time information into the packet | ||
132 | pack.Header.Sequence = (uint)now.Ticks; | ||
133 | |||
134 | lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here | ||
135 | { | ||
136 | try | ||
137 | { | ||
138 | if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod) | ||
139 | { | ||
140 | // First log file or time has expired, start writing to a new log file | ||
141 | if (m_statLog != null && m_statLog.Log != null) | ||
142 | { | ||
143 | m_statLog.Log.Close(); | ||
144 | } | ||
145 | m_statLog = new StatLogger(); | ||
146 | m_statLog.StartTime = now; | ||
147 | m_statLog.Path = (m_statsDir.Length > 0 ? m_statsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") | ||
148 | + String.Format("stats-{0}.log", now.ToString("yyyyMMddHHmmss")); | ||
149 | m_statLog.Log = new BinaryWriter(File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write)); | ||
150 | } | ||
151 | |||
152 | // Write the serialized data to disk | ||
153 | if (m_statLog != null && m_statLog.Log != null) | ||
154 | m_statLog.Log.Write(pack.ToBytes()); | ||
155 | } | ||
156 | catch (Exception ex) | ||
157 | { | ||
158 | m_log.Error("statistics gathering failed: " + ex.Message, ex); | ||
159 | if (m_statLog != null && m_statLog.Log != null) | ||
160 | { | ||
161 | m_statLog.Log.Close(); | ||
162 | } | ||
163 | m_statLog = null; | ||
164 | } | ||
165 | } | ||
166 | return; | ||
167 | } | ||
168 | } | ||
169 | } | ||