From e67faba4d8cc07c49e5cec1f2eab17f5a823bb49 Mon Sep 17 00:00:00 2001 From: Mark Sturgill Date: Wed, 30 Oct 2013 11:28:34 -0700 Subject: [PATCH] RunUO 2.4 will be the latest release supporting the 2.0 .NET Framework. Framework_4_0 preprocessors have been removed. ScriptCompiler will set Framework_4_0 as legacy. --- Scripts/Accounting/Account.cs | 5 +- Scripts/Commands/Skills.cs | 27 -- Scripts/Mobiles/AI/BaseAI.cs | 2 - Scripts/Mobiles/BaseCreature.cs | 15 +- Scripts/SpecialSystems/Engines/TestCenter.cs | 18 +- Server/Body.cs | 17 +- Server/Effects.cs | 2 - Server/Item.cs | 14 - Server/Main.cs | 14 - Server/Mobile.cs | 21 - Server/Network/NetState.cs | 7 +- Server/Network/Packets.cs | 29 -- Server/Persistence/DynamicSaveStrategy.cs | 6 +- Server/Persistence/SaveStrategy.cs | 9 +- Server/Region.cs | 15 +- Server/ScriptCompiler.cs | 9 +- Server/Serialization.cs | 66 ++-- Server/Timer.cs | 2 - Server/Utility.cs | 4 +- Server/World.cs | 384 +------------------ 20 files changed, 43 insertions(+), 623 deletions(-) diff --git a/Scripts/Accounting/Account.cs b/Scripts/Accounting/Account.cs index fd3fb299b..8458026bf 100644 --- a/Scripts/Accounting/Account.cs +++ b/Scripts/Accounting/Account.cs @@ -668,11 +668,8 @@ namespace Server.Accounting break; } } -#if Framework_4_0 + Enum.TryParse( Utility.GetText( node["accessLevel"], "Player" ), true, out m_AccessLevel ); -#else - m_AccessLevel = (AccessLevel)Enum.Parse( typeof( AccessLevel ), Utility.GetText( node["accessLevel"], "Player" ), true ); -#endif m_Flags = Utility.GetXMLInt32( Utility.GetText( node["flags"], "0" ), 0 ); m_Created = Utility.GetXMLDateTime( Utility.GetText( node["created"], null ), DateTime.UtcNow ); m_LastLogin = Utility.GetXMLDateTime( Utility.GetText( node["lastLogin"], null ), DateTime.UtcNow ); diff --git a/Scripts/Commands/Skills.cs b/Scripts/Commands/Skills.cs index 71dd69911..428aded79 100644 --- a/Scripts/Commands/Skills.cs +++ b/Scripts/Commands/Skills.cs @@ -25,7 +25,6 @@ namespace Server.Commands else { SkillName skill; -#if Framework_4_0 if( Enum.TryParse( arg.GetString( 0 ), true, out skill ) ) { arg.Mobile.Target = new SkillTarget( skill, arg.GetDouble( 1 ) ); @@ -34,18 +33,6 @@ namespace Server.Commands { arg.Mobile.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set. } -#else - try - { - skill = (SkillName)Enum.Parse( typeof( SkillName ), arg.GetString( 0 ), true ); - } - catch - { - arg.Mobile.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set. - return; - } - arg.Mobile.Target = new SkillTarget( skill, arg.GetDouble( 1 ) ); -#endif } } @@ -74,7 +61,6 @@ namespace Server.Commands else { SkillName skill; -#if Framework_4_0 if( Enum.TryParse( arg.GetString( 0 ), true, out skill ) ) { arg.Mobile.Target = new SkillTarget( skill ); @@ -83,19 +69,6 @@ namespace Server.Commands { arg.Mobile.SendMessage( "You have specified an invalid skill to get." ); } -#else - try - { - skill = (SkillName)Enum.Parse( typeof( SkillName ), arg.GetString( 0 ), true ); - } - catch - { - arg.Mobile.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set. - return; - } - - arg.Mobile.Target = new SkillTarget( skill ); -#endif } } diff --git a/Scripts/Mobiles/AI/BaseAI.cs b/Scripts/Mobiles/AI/BaseAI.cs index fd67f7945..adcaf60ce 100644 --- a/Scripts/Mobiles/AI/BaseAI.cs +++ b/Scripts/Mobiles/AI/BaseAI.cs @@ -2,10 +2,8 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; -#if Framework_4_0 using System.Linq; using System.Threading.Tasks; -#endif using Server; using Server.Items; using Server.Targeting; diff --git a/Scripts/Mobiles/BaseCreature.cs b/Scripts/Mobiles/BaseCreature.cs index 8b547a40e..5ac12efaf 100644 --- a/Scripts/Mobiles/BaseCreature.cs +++ b/Scripts/Mobiles/BaseCreature.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -#if Framework_4_0 using System.Threading.Tasks; -#endif using Server.Regions; using Server.Targeting; using Server.Network; @@ -5767,19 +5765,11 @@ namespace Server.Mobiles // added array for wild creatures in house regions to be removed List toRemove = new List(); -#if Framework_4_0 Parallel.ForEach(World.Mobiles.Values, m => { -#else - foreach ( Mobile m in World.Mobiles.Values ) { -#endif if ( m is BaseMount && ((BaseMount)m).Rider != null ) { ((BaseCreature)m).OwnerAbandonTime = DateTime.MinValue; -#if Framework_4_0 return; -#else - continue; -#endif } if ( m is BaseCreature ) @@ -5838,10 +5828,7 @@ namespace Server.Mobiles c.RemoveStep = 0; } } - } -#if Framework_4_0 - ); -#endif + }); foreach ( BaseCreature c in toRelease ) { diff --git a/Scripts/SpecialSystems/Engines/TestCenter.cs b/Scripts/SpecialSystems/Engines/TestCenter.cs index 075256a09..588790ef5 100644 --- a/Scripts/SpecialSystems/Engines/TestCenter.cs +++ b/Scripts/SpecialSystems/Engines/TestCenter.cs @@ -121,29 +121,13 @@ namespace Server.Misc private static void ChangeSkill( Mobile from, string name, double value ) { SkillName index; -#if Framework_4_0 + if( !Enum.TryParse( name, true, out index ) || (!Core.SE && (int)index > 51) || (!Core.AOS && (int)index > 48) ) { from.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set. return; } -#else - try - { - index = (SkillName)Enum.Parse( typeof( SkillName ), name, true ); - } - catch - { - from.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set. - return; - } - if ( ( !Core.SE && (int)index > 51 ) || ( !Core.AOS && (int)index > 48 ) ) - { - from.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set. - return; - } -#endif Skill skill = from.Skills[index]; if ( skill != null ) diff --git a/Server/Body.cs b/Server/Body.cs index 251d791fe..e2a7c7c0a 100644 --- a/Server/Body.cs +++ b/Server/Body.cs @@ -55,7 +55,7 @@ namespace Server continue; string[] split = line.Split( '\t' ); -#if Framework_4_0 + BodyType type; int bodyID; @@ -68,21 +68,6 @@ namespace Server Console.WriteLine( "Warning: Invalid bodyTable entry:" ); Console.WriteLine( line ); } -#else - try - { - int bodyID = int.Parse( split[0] ); - BodyType type = (BodyType)Enum.Parse( typeof( BodyType ), split[1], true ); - - if ( bodyID >= 0 && bodyID < m_Types.Length ) - m_Types[bodyID] = type; - } - catch - { - Console.WriteLine( "Warning: Invalid bodyTable entry:" ); - Console.WriteLine( line ); - } -#endif } } } diff --git a/Server/Effects.cs b/Server/Effects.cs index 104144598..486277b87 100644 --- a/Server/Effects.cs +++ b/Server/Effects.cs @@ -20,10 +20,8 @@ using System; using System.Collections; -#if Framework_4_0 using System.Linq; using System.Threading.Tasks; -#endif using Server.Network; namespace Server diff --git a/Server/Item.cs b/Server/Item.cs index 2b3aa87f8..e41bbf26c 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -22,10 +22,8 @@ using System; using System.IO; using System.Collections; using System.Collections.Generic; -#if Framework_4_0 using System.Linq; using System.Threading.Tasks; -#endif using Server.Network; using Server.Items; using Server.ContextMenus; @@ -3305,7 +3303,6 @@ namespace Server public static void ProcessDeltaQueue() { -#if Framework_4_0 _processing = true; if (m_DeltaQueue.Count >= 512) { @@ -3317,17 +3314,6 @@ namespace Server m_DeltaQueue.Clear(); _processing = false; -#else - int count = m_DeltaQueue.Count; - - for (int i = 0; i < m_DeltaQueue.Count; ++i) { - m_DeltaQueue[i].ProcessDelta(); - - if (i >= count) - break; - } - m_DeltaQueue.Clear(); -#endif } public virtual void OnDelete() diff --git a/Server/Main.cs b/Server/Main.cs index d2c71dc51..d33269a1f 100644 --- a/Server/Main.cs +++ b/Server/Main.cs @@ -28,10 +28,7 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading; -#if Framework_4_0 using System.Threading.Tasks; -#endif - using Server; using Server.Accounting; using Server.Gumps; @@ -157,11 +154,7 @@ namespace Server } } -#if Framework_4_0 public static readonly bool Is64Bit = Environment.Is64BitProcess; -#else - public static readonly bool Is64Bit = (IntPtr.Size == 8); //Returns the size for the current /process/ -#endif private static bool m_MultiProcessor; private static int m_ProcessorCount; @@ -725,17 +718,10 @@ namespace Server if( a == null ) return; -#if Framework_4_0 Parallel.ForEach(a.GetTypes(), t => { VerifyType(t); }); -#else - foreach (Type t in a.GetTypes()) - { - VerifyType(t); - } -#endif } } diff --git a/Server/Mobile.cs b/Server/Mobile.cs index e12567bc8..bef80cf9f 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -23,10 +23,8 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; -#if Framework_4_0 using System.Linq; using System.Threading.Tasks; -#endif using Server; using Server.Accounting; using Server.Commands; @@ -10061,18 +10059,7 @@ namespace Server sendFacialHair = true; } -#if Framework_4_0 Packet[][] cache = new Packet[2][] { new Packet[8], new Packet[8] }; -#else - Packet[][] cache = m_MovingPacketCache; - - /*if( sendMoving || sendNonlocalMoving || sendHealthbarPoison || sendHealthbarYellow ) - { - for( int i = 0; i < cache.Length; ++i ) - for( int j = 0; j < cache[i].Length; ++j ) - Packet.Release( ref cache[i][j] ); - }*/ -#endif NetState ourState = m.m_NetState; @@ -10322,7 +10309,6 @@ namespace Server public static void ProcessDeltaQueue() { -#if Framework_4_0 _processing = true; if (m_DeltaQueue.Count >= 512) { @@ -10335,13 +10321,6 @@ namespace Server _processing = false; while (m_DeltaQueueR.Count > 0) m_DeltaQueueR.Dequeue().ProcessDelta(); -#else - int count = m_DeltaQueue.Count; - int index = 0; - - while (m_DeltaQueue.Count > 0 && index++ < count) - m_DeltaQueue.Dequeue().ProcessDelta(); -#endif } [CommandProperty( AccessLevel.Counselor, AccessLevel.GameMaster )] diff --git a/Server/Network/NetState.cs b/Server/Network/NetState.cs index f65fcc9d7..872f96269 100644 --- a/Server/Network/NetState.cs +++ b/Server/Network/NetState.cs @@ -24,9 +24,7 @@ using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; -#if Framework_4_0 using System.Threading.Tasks; -#endif using Server; using Server.Accounting; using Server.Network; @@ -1051,11 +1049,9 @@ namespace Server.Network { } public static void FlushAll() { -#if Framework_4_0 if (m_Instances.Count >= 1024) Parallel.ForEach(m_Instances, ns => ns.Flush()); else -#endif for ( int i = 0; i < m_Instances.Count; ++i ) { m_Instances[i].Flush(); } @@ -1174,11 +1170,10 @@ namespace Server.Network { public static void CheckAllAlive() { try { long curTicks = Core.TickCount; -#if Framework_4_0 + if (m_Instances.Count >= 1024) Parallel.ForEach(m_Instances, ns => ns.CheckAlive(curTicks)); else -#endif for ( int i = 0; i < m_Instances.Count; ++i ) { m_Instances[i].CheckAlive(curTicks); } diff --git a/Server/Network/Packets.cs b/Server/Network/Packets.cs index bacef3e9e..a33e656e7 100644 --- a/Server/Network/Packets.cs +++ b/Server/Network/Packets.cs @@ -23,9 +23,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Net; -#if Framework_4_0 using System.Threading; -#endif using Server.Accounting; using Server.Targeting; using Server.Items; @@ -3357,13 +3355,8 @@ namespace Server.Network return new MobileIncomingOld(beholder, beheld); } -#if Framework_4_0 private static ThreadLocal m_DupedLayersTL = new ThreadLocal(() => {return new int[256];}); private static ThreadLocal m_VersionTL = new ThreadLocal(); -#else - private static int[] m_DupedLayers = new int[256]; - private static int m_Version; -#endif public Mobile m_Beheld; @@ -3371,12 +3364,8 @@ namespace Server.Network { m_Beheld = beheld; -#if Framework_4_0 int m_Version = ++(m_VersionTL.Value); int[] m_DupedLayers = m_DupedLayersTL.Value; -#else - ++m_Version; -#endif List eq = beheld.Items; int count = eq.Count; @@ -3474,13 +3463,8 @@ namespace Server.Network public sealed class MobileIncomingSA : Packet { -#if Framework_4_0 private static ThreadLocal m_DupedLayersTL = new ThreadLocal(() => {return new int[256];}); private static ThreadLocal m_VersionTL = new ThreadLocal(); -#else - private static int[] m_DupedLayers = new int[256]; - private static int m_Version; -#endif public Mobile m_Beheld; @@ -3488,12 +3472,8 @@ namespace Server.Network { m_Beheld = beheld; -#if Framework_4_0 int m_Version = ++(m_VersionTL.Value); int[] m_DupedLayers = m_DupedLayersTL.Value; -#else - ++m_Version; -#endif List eq = beheld.Items; int count = eq.Count; @@ -3609,13 +3589,8 @@ namespace Server.Network // Pre-7.0.0.0 Mobile Incoming public sealed class MobileIncomingOld : Packet { -#if Framework_4_0 private static ThreadLocal m_DupedLayersTL = new ThreadLocal(() => {return new int[256];}); private static ThreadLocal m_VersionTL = new ThreadLocal(); -#else - private static int[] m_DupedLayers = new int[256]; - private static int m_Version; -#endif public Mobile m_Beheld; @@ -3623,12 +3598,8 @@ namespace Server.Network { m_Beheld = beheld; -#if Framework_4_0 int m_Version = ++(m_VersionTL.Value); int[] m_DupedLayers = m_DupedLayersTL.Value; -#else - ++m_Version; -#endif List eq = beheld.Items; int count = eq.Count; diff --git a/Server/Persistence/DynamicSaveStrategy.cs b/Server/Persistence/DynamicSaveStrategy.cs index a67c7b21c..86fd90268 100644 --- a/Server/Persistence/DynamicSaveStrategy.cs +++ b/Server/Persistence/DynamicSaveStrategy.cs @@ -18,7 +18,6 @@ * ***************************************************************************/ -#if Framework_4_0 using System; using System.Collections.Generic; @@ -158,8 +157,6 @@ namespace Server return commitTask; } - - private Task SaveMobiles() { //Start the blocking consumer; this runs in background. @@ -313,5 +310,4 @@ namespace Server } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Server/Persistence/SaveStrategy.cs b/Server/Persistence/SaveStrategy.cs index 7e8dcdb5b..eb80fb501 100644 --- a/Server/Persistence/SaveStrategy.cs +++ b/Server/Persistence/SaveStrategy.cs @@ -31,17 +31,10 @@ namespace Server { int processorCount = Core.ProcessorCount; -#if Framework_4_0 if (processorCount > 2) { - return new DualSaveStrategy(); // return new DynamicSaveStrategy(); + return new DualSaveStrategy(); // return new DynamicSaveStrategy(); (4.0 or return new ParallelSaveStrategy(processorCount); (2.0) } -#else - if (processorCount > 16) - { - return new DualSaveStrategy(); // return new ParallelSaveStrategy(processorCount); - } -#endif else { return new DualSaveStrategy(); diff --git a/Server/Region.cs b/Server/Region.cs index daeb4e3b8..682631b87 100644 --- a/Server/Region.cs +++ b/Server/Region.cs @@ -1139,7 +1139,7 @@ namespace Server return false; Type type = typeof(T); -#if Framework_4_0 + T tempVal; if( type.IsEnum && Enum.TryParse( s, true, out tempVal ) ) @@ -1152,19 +1152,6 @@ namespace Server Console.WriteLine( "Could not parse {0} enum attribute '{1}' in element '{2}'", type, attribute, xml.Name ); return false; } -#else - try - { - value = (T)Enum.Parse(type, s, true); - } - catch - { - Console.WriteLine( "Could not parse {0} enum attribute '{1}' in element '{2}'", type, attribute, xml.Name ); - return false; - } - - return true; -#endif } public static bool ReadMap( XmlElement xml, string attribute, ref Map value ) diff --git a/Server/ScriptCompiler.cs b/Server/ScriptCompiler.cs index f58ad16cd..ea184a411 100644 --- a/Server/ScriptCompiler.cs +++ b/Server/ScriptCompiler.cs @@ -55,11 +55,7 @@ namespace Server { List list = new List(); -#if Framework_4_0 string path = Path.Combine( Core.BaseDirectory, "Data/Assemblies_4_0.cfg" ); -#else - string path = Path.Combine( Core.BaseDirectory, "Data/Assemblies.cfg" ); -#endif if( File.Exists( path ) ) { @@ -93,14 +89,13 @@ namespace Server AppendCompilerOption( ref sb, "/d:MONO" ); #endif - //These two defines are legacy, ie, depreciated. + //These three defines are legacy, ie, depreciated. if( Core.Is64Bit ) AppendCompilerOption( ref sb, "/d:x64" ); AppendCompilerOption( ref sb, "/d:Framework_2_0" ); -#if Framework_4_0 + AppendCompilerOption( ref sb, "/d:Framework_4_0" ); -#endif return (sb == null ? null : sb.ToString()); } diff --git a/Server/Serialization.cs b/Server/Serialization.cs index b71805103..9ec13f114 100644 --- a/Server/Serialization.cs +++ b/Server/Serialization.cs @@ -38,9 +38,7 @@ namespace Server public abstract string ReadString(); public abstract DateTime ReadDateTime(); -#if Framework_4_0 public abstract DateTimeOffset ReadDateTimeOffset(); -#endif public abstract TimeSpan ReadTimeSpan(); public abstract DateTime ReadDeltaTime(); public abstract decimal ReadDecimal(); @@ -85,7 +83,7 @@ namespace Server public abstract List ReadStrongGuildList(); public abstract List ReadStrongGuildList() where T : BaseGuild; -#if Framework_4_0 + public abstract HashSet ReadItemSet(); public abstract HashSet ReadItemSet() where T: Item; @@ -94,7 +92,7 @@ namespace Server public abstract HashSet ReadGuildSet(); public abstract HashSet ReadGuildSet() where T : BaseGuild; -#endif + public abstract Race ReadRace(); public abstract bool End(); @@ -110,9 +108,7 @@ namespace Server public abstract void Write( string value ); public abstract void Write( DateTime value ); -#if Framework_4_0 public abstract void Write( DateTimeOffset value ); -#endif public abstract void Write( TimeSpan value ); public abstract void Write( decimal value ); public abstract void Write( long value ); @@ -162,37 +158,37 @@ namespace Server public abstract void WriteItemList( List list ) where T : Item; public abstract void WriteItemList( List list, bool tidy ) where T : Item; -#if Framework_4_0 + public abstract void Write( HashSet list ); public abstract void Write( HashSet list, bool tidy ); public abstract void WriteItemSet( HashSet set ) where T : Item; public abstract void WriteItemSet( HashSet set, bool tidy ) where T : Item; -#endif + public abstract void Write( List list ); public abstract void Write( List list, bool tidy ); public abstract void WriteMobileList( List list ) where T : Mobile; public abstract void WriteMobileList( List list, bool tidy ) where T : Mobile; -#if Framework_4_0 + public abstract void Write( HashSet list ); public abstract void Write( HashSet list, bool tidy ); public abstract void WriteMobileSet( HashSet set ) where T : Mobile; public abstract void WriteMobileSet( HashSet set, bool tidy ) where T : Mobile; -#endif + public abstract void Write( List list ); public abstract void Write( List list, bool tidy ); public abstract void WriteGuildList( List list ) where T : BaseGuild; public abstract void WriteGuildList( List list, bool tidy ) where T : BaseGuild; -#if Framework_4_0 + public abstract void Write( HashSet list ); public abstract void Write( HashSet list, bool tidy ); public abstract void WriteGuildSet( HashSet set ) where T : BaseGuild; public abstract void WriteGuildSet( HashSet set, bool tidy ) where T : BaseGuild; -#endif + // Compiler won't notice their 'where' to differentiate the generic methods. } @@ -369,13 +365,13 @@ namespace Server { Write( value.Ticks ); } -#if Framework_4_0 + public override void Write( DateTimeOffset value ) { Write( value.Ticks ); Write( value.Offset.Ticks ); } -#endif + public override void WriteDeltaTime( DateTime value ) { long ticks = value.Ticks; @@ -736,7 +732,7 @@ namespace Server for( int i = 0; i < list.Count; ++i ) Write( list[i] ); } -#if Framework_4_0 + public override void Write( HashSet set ) { Write( set, false ); @@ -774,7 +770,7 @@ namespace Server Write( item ); } } -#endif + public override void Write( List list ) { Write( list, false ); @@ -820,7 +816,7 @@ namespace Server for( int i = 0; i < list.Count; ++i ) Write( list[i] ); } -#if Framework_4_0 + public override void Write( HashSet set ) { Write( set, false ); @@ -858,7 +854,7 @@ namespace Server Write( mob ); } } -#endif + public override void Write( List list ) { Write( list, false ); @@ -904,7 +900,7 @@ namespace Server for( int i = 0; i < list.Count; ++i ) Write( list[i] ); } -#if Framework_4_0 + public override void Write( HashSet set ) { Write( set, false ); @@ -942,7 +938,6 @@ namespace Server Write( guild ); } } -#endif } public sealed class BinaryFileReader : GenericReader @@ -1015,7 +1010,7 @@ namespace Server { return new DateTime( m_File.ReadInt64() ); } -#if Framework_4_0 + public override DateTimeOffset ReadDateTimeOffset() { long ticks = m_File.ReadInt64(); @@ -1023,7 +1018,7 @@ namespace Server return new DateTimeOffset( ticks, offset ); } -#endif + public override TimeSpan ReadTimeSpan() { return new TimeSpan( m_File.ReadInt64() ); @@ -1237,7 +1232,7 @@ namespace Server return new List(); } } -#if Framework_4_0 + public override HashSet ReadItemSet() { return ReadItemSet(); @@ -1268,7 +1263,7 @@ namespace Server return new HashSet(); } } -#endif + public override List ReadStrongMobileList() { return ReadStrongMobileList(); @@ -1294,7 +1289,7 @@ namespace Server return new List(); } } -#if Framework_4_0 + public override HashSet ReadMobileSet() { return ReadMobileSet(); @@ -1325,7 +1320,7 @@ namespace Server return new HashSet(); } } -#endif + public override List ReadStrongGuildList() { return ReadStrongGuildList(); @@ -1351,7 +1346,7 @@ namespace Server return new List(); } } -#if Framework_4_0 + public override HashSet ReadGuildSet() { return ReadGuildSet(); @@ -1382,7 +1377,7 @@ namespace Server return new HashSet(); } } -#endif + public override Race ReadRace() { return Race.Races[ReadByte()]; @@ -1572,14 +1567,14 @@ namespace Server m_Bin.Write( value.Ticks ); OnWrite(); } -#if Framework_4_0 + public override void Write( DateTimeOffset value ) { m_Bin.Write( value.Ticks ); m_Bin.Write( value.Offset.Ticks ); OnWrite(); } -#endif + public override void Write( TimeSpan value ) { m_Bin.Write( value.Ticks ); @@ -1872,7 +1867,7 @@ namespace Server for( int i = 0; i < list.Count; ++i ) Write( list[i] ); } -#if Framework_4_0 + public override void Write( HashSet set ) { Write( set, false ); @@ -1910,7 +1905,7 @@ namespace Server Write( item ); } } -#endif + public override void Write( List list ) { Write( list, false ); @@ -1956,7 +1951,7 @@ namespace Server for( int i = 0; i < list.Count; ++i ) Write( list[i] ); } -#if Framework_4_0 + public override void Write( HashSet set ) { Write( set, false ); @@ -1994,7 +1989,7 @@ namespace Server Write( mob ); } } -#endif + public override void Write( List list ) { Write( list, false ); @@ -2040,7 +2035,7 @@ namespace Server for( int i = 0; i < list.Count; ++i ) Write( list[i] ); } -#if Framework_4_0 + public override void Write( HashSet set ) { Write( set, false ); @@ -2078,7 +2073,6 @@ namespace Server Write( guild ); } } -#endif } public interface ISerializable diff --git a/Server/Timer.cs b/Server/Timer.cs index 1b622d032..2fbd9b28a 100644 --- a/Server/Timer.cs +++ b/Server/Timer.cs @@ -23,9 +23,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading; -#if Framework_4_0 using System.Threading.Tasks; -#endif using Server.Diagnostics; namespace Server diff --git a/Server/Utility.cs b/Server/Utility.cs index 9550a865d..4052e9dec 100644 --- a/Server/Utility.cs +++ b/Server/Utility.cs @@ -553,7 +553,7 @@ namespace Server return defaultValue; } } -#if Framework_4_0 + public static DateTimeOffset GetXMLDateTimeOffset( string dateTimeOffsetString, DateTimeOffset defaultValue ) { try @@ -570,7 +570,7 @@ namespace Server return defaultValue; } } -#endif + public static TimeSpan GetXMLTimeSpan( string timeSpanString, TimeSpan defaultValue ) { try diff --git a/Server/World.cs b/Server/World.cs index 7f95687a2..70b198fd5 100644 --- a/Server/World.cs +++ b/Server/World.cs @@ -281,7 +281,7 @@ namespace Server { } private static readonly Type[] m_SerialTypeArray = new Type[1] { typeof(Serial) }; -#if Framework_4_0 + private static List> ReadTypes( BinaryReader tdbReader ) { int count = tdbReader.ReadInt32(); @@ -662,388 +662,6 @@ namespace Server { Console.WriteLine( "done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, m_Items.Count, m_Mobiles.Count ); } -#else - private static List ReadTypes( BinaryReader tdbReader ) - { - int count = tdbReader.ReadInt32(); - - List types = new List(count); - - for (int i = 0; i < count; ++i) - { - string typeName = tdbReader.ReadString(); - - Type t = ScriptCompiler.FindTypeByFullName(typeName); - - if (t == null) - { - Console.WriteLine("failed"); - - if (!Core.Service) - { - Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName); - - if (Console.ReadKey(true).Key == ConsoleKey.Y) - { - types.Add(null); - Console.Write("World: Loading..."); - continue; - } - - Console.WriteLine("Types will not be deleted. An exception will be thrown."); - } - else - { - Console.WriteLine("Error: Type '{0}' was not found.", typeName); - } - - throw new Exception(String.Format("Bad type '{0}'", typeName)); - } - - ConstructorInfo ctor = t.GetConstructor(m_SerialTypeArray); - - if (ctor != null) - { - types.Add(new object[] { ctor, typeName }); - } - else - { - throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t)); - } - } - - return types; - } - - public static void Load() { - if ( m_Loaded ) - return; - - m_Loaded = true; - m_LoadingType = null; - - Console.Write( "World: Loading..." ); - - Stopwatch watch = Stopwatch.StartNew(); - - m_Loading = true; - - _addQueue = new Queue(); - _deleteQueue = new Queue(); - - int mobileCount = 0, itemCount = 0, guildCount = 0; - - object[] ctorArgs = new object[1]; - - List items = new List(); - List mobiles = new List(); - List guilds = new List(); - - if ( File.Exists( MobileIndexPath ) && File.Exists( MobileTypesPath ) ) { - using ( FileStream idx = new FileStream( MobileIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryReader idxReader = new BinaryReader( idx ); - - using ( FileStream tdb = new FileStream( MobileTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryReader tdbReader = new BinaryReader( tdb ); - - List types = ReadTypes( tdbReader ); - - mobileCount = idxReader.ReadInt32(); - - m_Mobiles = new Dictionary( mobileCount ); - - for ( int i = 0; i < mobileCount; ++i ) { - int typeID = idxReader.ReadInt32(); - int serial = idxReader.ReadInt32(); - long pos = idxReader.ReadInt64(); - int length = idxReader.ReadInt32(); - - object[] objs = types[typeID]; - - if ( objs == null ) - continue; - - Mobile m = null; - ConstructorInfo ctor = ( ConstructorInfo ) objs[0]; - string typeName = ( string ) objs[1]; - - try { - ctorArgs[0] = ( Serial ) serial; - m = ( Mobile ) ( ctor.Invoke( ctorArgs ) ); - } catch { - } - - if ( m != null ) { - mobiles.Add( new MobileEntry( m, typeID, typeName, pos, length ) ); - AddMobile( m ); - } - } - - tdbReader.Close(); - } - - idxReader.Close(); - } - } else { - m_Mobiles = new Dictionary(); - } - - if ( File.Exists( ItemIndexPath ) && File.Exists( ItemTypesPath ) ) { - using ( FileStream idx = new FileStream( ItemIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryReader idxReader = new BinaryReader( idx ); - - using ( FileStream tdb = new FileStream( ItemTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryReader tdbReader = new BinaryReader( tdb ); - - List types = ReadTypes( tdbReader ); - - itemCount = idxReader.ReadInt32(); - - m_Items = new Dictionary( itemCount ); - - for ( int i = 0; i < itemCount; ++i ) { - int typeID = idxReader.ReadInt32(); - int serial = idxReader.ReadInt32(); - long pos = idxReader.ReadInt64(); - int length = idxReader.ReadInt32(); - - object[] objs = types[typeID]; - - if ( objs == null ) - continue; - - Item item = null; - ConstructorInfo ctor = ( ConstructorInfo ) objs[0]; - string typeName = ( string ) objs[1]; - - try { - ctorArgs[0] = ( Serial ) serial; - item = ( Item ) ( ctor.Invoke( ctorArgs ) ); - } catch { - } - - if ( item != null ) { - items.Add( new ItemEntry( item, typeID, typeName, pos, length ) ); - AddItem( item ); - } - } - - tdbReader.Close(); - } - - idxReader.Close(); - } - } else { - m_Items = new Dictionary(); - } - - if ( File.Exists( GuildIndexPath ) ) { - using ( FileStream idx = new FileStream( GuildIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryReader idxReader = new BinaryReader( idx ); - - guildCount = idxReader.ReadInt32(); - - CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs( -1 ); - for ( int i = 0; i < guildCount; ++i ) { - idxReader.ReadInt32();//no typeid for guilds - int id = idxReader.ReadInt32(); - long pos = idxReader.ReadInt64(); - int length = idxReader.ReadInt32(); - - createEventArgs.Id = id; - EventSink.InvokeCreateGuild(createEventArgs); - BaseGuild guild = createEventArgs.Guild; - if ( guild != null ) - guilds.Add( new GuildEntry( guild, pos, length ) ); - } - - idxReader.Close(); - } - } - - bool failedMobiles = false, failedItems = false, failedGuilds = false; - Type failedType = null; - Serial failedSerial = Serial.Zero; - Exception failed = null; - int failedTypeID = 0; - - if ( File.Exists( MobileDataPath ) ) { - using ( FileStream bin = new FileStream( MobileDataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) ); - - for ( int i = 0; i < mobiles.Count; ++i ) { - MobileEntry entry = mobiles[i]; - Mobile m = entry.Mobile; - - if ( m != null ) { - reader.Seek( entry.Position, SeekOrigin.Begin ); - - try { - m_LoadingType = entry.TypeName; - m.Deserialize( reader ); - - if ( reader.Position != ( entry.Position + entry.Length ) ) - throw new Exception( String.Format( "***** Bad serialize on {0} *****", m.GetType() ) ); - } catch ( Exception e ) { - mobiles.RemoveAt( i ); - - failed = e; - failedMobiles = true; - failedType = m.GetType(); - failedTypeID = entry.TypeID; - failedSerial = m.Serial; - - break; - } - } - } - - reader.Close(); - } - } - - if ( !failedMobiles && File.Exists( ItemDataPath ) ) { - using ( FileStream bin = new FileStream( ItemDataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) ); - - for ( int i = 0; i < items.Count; ++i ) { - ItemEntry entry = items[i]; - Item item = entry.Item; - - if ( item != null ) { - reader.Seek( entry.Position, SeekOrigin.Begin ); - - try { - m_LoadingType = entry.TypeName; - item.Deserialize( reader ); - - if ( reader.Position != ( entry.Position + entry.Length ) ) - throw new Exception( String.Format( "***** Bad serialize on {0} *****", item.GetType() ) ); - } catch ( Exception e ) { - items.RemoveAt( i ); - - failed = e; - failedItems = true; - failedType = item.GetType(); - failedTypeID = entry.TypeID; - failedSerial = item.Serial; - - break; - } - } - } - - reader.Close(); - } - } - - m_LoadingType = null; - - if ( !failedMobiles && !failedItems && File.Exists( GuildDataPath ) ) { - using ( FileStream bin = new FileStream( GuildDataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { - BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) ); - - for ( int i = 0; i < guilds.Count; ++i ) { - GuildEntry entry = guilds[i]; - BaseGuild g = entry.Guild; - - if ( g != null ) { - reader.Seek( entry.Position, SeekOrigin.Begin ); - - try { - g.Deserialize( reader ); - - if ( reader.Position != ( entry.Position + entry.Length ) ) - throw new Exception( String.Format( "***** Bad serialize on Guild {0} *****", g.Id ) ); - } catch ( Exception e ) { - guilds.RemoveAt( i ); - - failed = e; - failedGuilds = true; - failedType = typeof( BaseGuild ); - failedTypeID = g.Id; - failedSerial = g.Id; - - break; - } - } - } - - reader.Close(); - } - } - - if ( failedItems || failedMobiles || failedGuilds ) { - Console.WriteLine( "An error was encountered while loading a saved object" ); - - Console.WriteLine( " - Type: {0}", failedType ); - Console.WriteLine( " - Serial: {0}", failedSerial ); - - if ( !Core.Service ) { - Console.WriteLine( "Delete the object? (y/n)" ); - - if ( Console.ReadKey( true ).Key == ConsoleKey.Y ) { - if ( failedType != typeof( BaseGuild ) ) { - Console.WriteLine( "Delete all objects of that type? (y/n)" ); - - if ( Console.ReadKey( true ).Key == ConsoleKey.Y ) { - if ( failedMobiles ) { - for ( int i = 0; i < mobiles.Count; ) { - if ( mobiles[i].TypeID == failedTypeID ) - mobiles.RemoveAt( i ); - else - ++i; - } - } else if ( failedItems ) { - for ( int i = 0; i < items.Count; ) { - if ( items[i].TypeID == failedTypeID ) - items.RemoveAt( i ); - else - ++i; - } - } - } - } - - SaveIndex( mobiles, MobileIndexPath ); - SaveIndex( items, ItemIndexPath ); - SaveIndex( guilds, GuildIndexPath ); - } - - Console.WriteLine( "After pressing return an exception will be thrown and the server will terminate." ); - Console.ReadLine(); - } else { - Console.WriteLine( "An exception will be thrown and the server will terminate." ); - } - - throw new Exception( String.Format( "Load failed (items={0}, mobiles={1}, guilds={2}, type={3}, serial={4})", failedItems, failedMobiles, failedGuilds, failedType, failedSerial ), failed ); - } - - EventSink.InvokeWorldLoad(); - - m_Loading = false; - - ProcessSafetyQueues(); - - foreach ( Item item in m_Items.Values ) { - if ( item.Parent == null ) - item.UpdateTotals(); - - item.ClearProperties(); - } - - foreach ( Mobile m in m_Mobiles.Values ) { - m.UpdateRegion(); // Is this really needed? - m.UpdateTotals(); - - m.ClearProperties(); - } - - watch.Stop(); - - Console.WriteLine( "done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, m_Items.Count, m_Mobiles.Count ); - } -#endif private static void ProcessSafetyQueues() { while ( _addQueue.Count > 0 ) {