From d2f79e93ea7a4247dc383ae4caccae73cf9b7553 Mon Sep 17 00:00:00 2001 From: asayre Date: Sat, 31 Dec 2011 07:50:54 +0000 Subject: [PATCH] Potential deletion of item outside of main thread issue resolved Item.Spawner now uses CompactInfo for memory savings. Empty accounts (No Characters) can now be set to go inactive sooner than accounts with characters. --- Scripts/Accounting/Account.cs | 14 +++++++-- Scripts/Commands/Profiling.cs | 8 +++-- Server/Item.cs | 55 +++++++++++++++++++++++++---------- Server/Mobile.cs | 2 +- Server/World.cs | 2 +- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/Scripts/Accounting/Account.cs b/Scripts/Accounting/Account.cs index c001dc032..c7e614ba2 100644 --- a/Scripts/Accounting/Account.cs +++ b/Scripts/Accounting/Account.cs @@ -19,6 +19,8 @@ namespace Server.Accounting public static readonly TimeSpan YoungDuration = TimeSpan.FromHours( 40.0 ); public static readonly TimeSpan InactiveDuration = TimeSpan.FromDays( 180.0 ); + + public static readonly TimeSpan EmptyInactiveDuration = TimeSpan.FromDays( 30.0 ); private string m_Username, m_PlainPassword, m_CryptPassword, m_NewCryptPassword; private AccessLevel m_AccessLevel; @@ -221,11 +223,19 @@ namespace Server.Accounting } /// - /// An account is considered inactive based upon LastLogin and InactiveDuration + /// An account is considered inactive based upon LastLogin and InactiveDuration. If the account is empty, it is based upon EmptyInactiveDuration /// public bool Inactive { - get { return ( ( m_LastLogin + InactiveDuration ) <= DateTime.Now && AccessLevel == AccessLevel.Player ); } + get + { + if( this.AccessLevel != AccessLevel.Player ) + return false; + + TimeSpan inactiveLength = DateTime.Now - m_LastLogin; + + return (inactiveLength > ((this.Count == 0) ? EmptyInactiveDuration : InactiveDuration)); + } } /// diff --git a/Scripts/Commands/Profiling.cs b/Scripts/Commands/Profiling.cs index 554efef09..bfd821eda 100644 --- a/Scripts/Commands/Profiling.cs +++ b/Scripts/Commands/Profiling.cs @@ -210,7 +210,7 @@ namespace Server.Commands int[] countTable = typeTable[itemType] as int[]; if ( countTable == null ) - typeTable[itemType] = countTable = new int[8]; + typeTable[itemType] = countTable = new int[9]; if ( ( flags & ExpandFlag.Name ) != 0 ) ++countTable[0]; @@ -236,6 +236,9 @@ namespace Server.Commands if ( ( flags & ExpandFlag.Weight ) != 0 ) ++countTable[7]; + if ((flags & ExpandFlag.Spawner) != 0) + ++countTable[8]; + itemType = itemType.BaseType; } while ( itemType != typeof( object ) ); } @@ -253,7 +256,8 @@ namespace Server.Commands "Blessed", "TempFlag", "SaveFlag", - "Weight" + "Weight", + "Spawner" }; ArrayList list = new ArrayList( typeTable ); diff --git a/Server/Item.cs b/Server/Item.cs index a85ec7742..0cf951aa6 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -547,16 +547,17 @@ namespace Server [Flags] public enum ExpandFlag { - None = 0x00, + None = 0x000, - Name = 0x01, - Items = 0x02, - Bounce = 0x04, - Holder = 0x08, - Blessed = 0x10, - TempFlag = 0x20, - SaveFlag = 0x40, - Weight = 0x80 + Name = 0x001, + Items = 0x002, + Bounce = 0x004, + Holder = 0x008, + Blessed = 0x010, + TempFlag = 0x020, + SaveFlag = 0x040, + Weight = 0x080, + Spawner = 0x100 } public class Item : IEntity, IHued, IComparable, ISerializable, ISpawnable @@ -704,6 +705,8 @@ namespace Server public Mobile m_HeldBy; public Mobile m_BlessedFor; + public ISpawner m_Spawner; + public int m_TempFlags; public int m_SavedFlags; @@ -735,6 +738,9 @@ namespace Server if ( info.m_Name != null ) flags |= ExpandFlag.Name; + if (info.m_Spawner != null) + flags |= ExpandFlag.Spawner; + if ( info.m_SavedFlags != 0 ) flags |= ExpandFlag.SaveFlag; @@ -778,6 +784,7 @@ namespace Server || ( info.m_Bounce != null ) || ( info.m_HeldBy != null ) || ( info.m_BlessedFor != null ) + || ( info.m_Spawner != null ) || ( info.m_TempFlags != 0 ) || ( info.m_SavedFlags != 0 ) || ( info.m_Weight != -1 ); @@ -3263,10 +3270,10 @@ namespace Server public virtual void OnDelete() { - if ( m_Spawner != null ) + if (this.Spawner != null) { - m_Spawner.Remove( this ); - m_Spawner = null; + this.Spawner.Remove(this); + this.Spawner = null; } } @@ -3438,10 +3445,28 @@ namespace Server return true; } - //TODO: Move to CompactInfo. - private ISpawner m_Spawner; + public ISpawner Spawner + { + get + { + CompactInfo info = LookupCompactInfo(); - public ISpawner Spawner{ get{ return m_Spawner; } set{ m_Spawner = value; } } + if (info != null) + return info.m_Spawner; + + return null; + + } + set + { + CompactInfo info = AcquireCompactInfo(); + + info.m_Spawner = value; + + if (info.m_Spawner == null) + VerifyCompactInfo(); + } + } public virtual void OnBeforeSpawn( Point3D location, Map m ) { diff --git a/Server/Mobile.cs b/Server/Mobile.cs index 695f6ecdd..ed299867c 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -8094,7 +8094,7 @@ namespace Server } } - item.Delete(); + Timer.DelayCall( TimeSpan.Zero, delegate { item.Delete(); } ); } } diff --git a/Server/World.cs b/Server/World.cs index f3f69ef0a..368967a4b 100644 --- a/Server/World.cs +++ b/Server/World.cs @@ -70,7 +70,7 @@ namespace Server { { if( m_DiskWriteHandle.Set()) { - Console.WriteLine("Closing Save Files..."); + Console.WriteLine("Closing Save Files. "); } }