From de74218b8981af27fdc4e0b7ddc81a2846328f5e Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 19 Jan 2020 12:47:34 -0800 Subject: [PATCH] Updates to .NET Core 3.1 & Cleanup (#79) --- GOALS.md | 6 +- Projects/Scripts/Misc/CrashGuard.cs | 2 +- Projects/Scripts/Misc/ServerList.cs | 81 +++++-------------- Projects/Scripts/Scripts.csproj | 24 +++--- .../SpecialSystems/Engines/TestCenter.cs | 2 +- Projects/Server/Mobile.cs | 57 ++++++------- Projects/Server/Network/PacketHandlers.cs | 1 - Projects/Server/Server.csproj | 43 +++++----- Projects/Server/Timer.cs | 14 +--- Projects/Server/Utilities/Utility.cs | 51 +++--------- Publish-Linux.sh | 1 + Publish-OSX.sh | 1 + Publish-Windows.cmd | 1 + README.md | 4 +- 14 files changed, 100 insertions(+), 188 deletions(-) create mode 100644 Publish-Linux.sh create mode 100644 Publish-OSX.sh create mode 100644 Publish-Windows.cmd diff --git a/GOALS.md b/GOALS.md index 281413e3b..1995b9dc1 100644 --- a/GOALS.md +++ b/GOALS.md @@ -11,8 +11,8 @@ Some of the many high level goals include: ### Networking - [ ] Replace Packet classes with functions -- [ ] Improve asynchronous socket handling using Pipes -- [ ] Improve socket handling (2-5x) and event loop using libuv +- [X] Improve asynchronous socket handling using Pipes +- [X] Improve socket handling (2-5x) and event loop using libuv ### Administration - [ ] Move IP logging and account data to SQL @@ -37,7 +37,7 @@ Some of the many high level goals include: - [ ] Create object pools for high availability items such as gold and reagents * For example, `new MandrakeRoot()` -> `ObjectPool.Get(ReagentType.MandrakeRoot)`. * Pools should be elastic and adjust according to nominal usage. For example, if thousands of gold objects are created and destroyed in a small period of time, the pool should be expanded and replenished properly so it is never empty, or full. -- [ ] Replace timer system with a [wheel](https://github.com/runuo/runuo/pull/42) implementation +- [ ] Replace timer system with libuv implementation - [X] Create `DefaultName` for mobiles ### Plugins (Separate Repos & Optional) diff --git a/Projects/Scripts/Misc/CrashGuard.cs b/Projects/Scripts/Misc/CrashGuard.cs index 092e9ca42..7ab2e9743 100644 --- a/Projects/Scripts/Misc/CrashGuard.cs +++ b/Projects/Scripts/Misc/CrashGuard.cs @@ -171,7 +171,7 @@ namespace Server.Misc op.WriteLine("Server Crash Report"); op.WriteLine("==================="); op.WriteLine(); - op.WriteLine("RunUO Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); + op.WriteLine("ModernUO Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); op.WriteLine("Operating System: {0}", Environment.OSVersion); op.WriteLine(".NET Framework: {0}", Environment.Version); op.WriteLine("Time: {0}", DateTime.UtcNow); diff --git a/Projects/Scripts/Misc/ServerList.cs b/Projects/Scripts/Misc/ServerList.cs index 86a6ea029..87fe8d846 100644 --- a/Projects/Scripts/Misc/ServerList.cs +++ b/Projects/Scripts/Misc/ServerList.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; @@ -39,9 +40,9 @@ namespace Server.Misc */ public static readonly string Address = null; - public static readonly string ServerName = "RunUO TC"; + public const string ServerName = "ModernUO TC"; - public static readonly bool AutoDetect = true; + public const bool AutoDetect = true; private static IPAddress m_PublicAddress; @@ -120,65 +121,23 @@ namespace Server.Misc } } - private static bool HasPublicIPAddress() - { - NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); + private static bool HasPublicIPAddress() => + NetworkInterface.GetAllNetworkInterfaces().Select(adapter => adapter.GetIPProperties()) + .Any(properties => properties.UnicastAddresses.Select(unicast => unicast.Address) + .Any(ip => !IPAddress.IsLoopback(ip) && ip.AddressFamily != AddressFamily.InterNetworkV6 && !IsPrivateNetwork(ip))); - foreach (NetworkInterface adapter in adapters) - { - IPInterfaceProperties properties = adapter.GetIPProperties(); - - foreach (IPAddressInformation unicast in properties.UnicastAddresses) - { - IPAddress ip = unicast.Address; - - if (!IPAddress.IsLoopback(ip) && ip.AddressFamily != AddressFamily.InterNetworkV6 && - !IsPrivateNetwork(ip)) - return true; - } - } - - return false; - - - /* - IPHostEntry iphe = Dns.GetHostEntry( Dns.GetHostName() ); - - IPAddress[] ips = iphe.AddressList; - - for ( int i = 0; i < ips.Length; ++i ) - { - if ( ips[i].AddressFamily != AddressFamily.InterNetworkV6 && !IsPrivateNetwork( ips[i] ) ) - return true; - } - - return false; - */ - } - - private static bool IsPrivateNetwork(IPAddress ip) - { - // 10.0.0.0/8 - // 172.16.0.0/12 - // 192.168.0.0/16 - // 169.254.0.0/16 - // 100.64.0.0/10 RFC 6598 - - if (ip.AddressFamily == AddressFamily.InterNetworkV6) - return false; - - if (Utility.IPMatch("192.168.*", ip)) - return true; - if (Utility.IPMatch("10.*", ip)) - return true; - if (Utility.IPMatch("172.16-31.*", ip)) - return true; - if (Utility.IPMatch("169.254.*", ip)) - return true; - if (Utility.IPMatch("100.64-127.*", ip)) - return true; - return false; - } + // 10.0.0.0/8 + // 172.16.0.0/12 + // 192.168.0.0/16 + // 169.254.0.0/16 + // 100.64.0.0/10 RFC 6598 + private static bool IsPrivateNetwork(IPAddress ip) => + ip.AddressFamily != AddressFamily.InterNetworkV6 && + (Utility.IPMatch("192.168.*", ip) || + Utility.IPMatch("10.*", ip) || + Utility.IPMatch("172.16-31.*", ip) || + Utility.IPMatch("169.254.*", ip) || + Utility.IPMatch("100.64-127.*", ip)); private static IPAddress FindPublicAddress() { @@ -194,7 +153,7 @@ namespace Server.Misc StreamReader sr = new StreamReader(s); - IPAddress ip = IPAddress.Parse(sr.ReadLine()); + IPAddress ip = IPAddress.Parse(sr.ReadLine() ?? ""); sr.Close(); s.Close(); diff --git a/Projects/Scripts/Scripts.csproj b/Projects/Scripts/Scripts.csproj index 336e20fab..71df03a57 100644 --- a/Projects/Scripts/Scripts.csproj +++ b/Projects/Scripts/Scripts.csproj @@ -2,30 +2,28 @@ Server - netcoreapp3.0 + netcoreapp3.1 Scripts.CS + Kamron Batman + ModernUO + ModernUO Scripts + 2019-2020 + true true - - - true - true true x64 ..\..\Distribution\Assemblies ..\..\Distribution\Assemblies ..\..\Distribution\Assemblies + true + + + true TRACE;DEBUG - true false - ..\..\Distribution\Assemblies - ..\..\Distribution\Assemblies - ..\..\Distribution\Assemblies - - true - x64 @@ -37,6 +35,6 @@ - + diff --git a/Projects/Scripts/SpecialSystems/Engines/TestCenter.cs b/Projects/Scripts/SpecialSystems/Engines/TestCenter.cs index 5e8944f8a..a925ddaf8 100644 --- a/Projects/Scripts/SpecialSystems/Engines/TestCenter.cs +++ b/Projects/Scripts/SpecialSystems/Engines/TestCenter.cs @@ -161,7 +161,7 @@ namespace Server.Misc AddBackground(0, 0, 160, 120, 5054); AddButton(10, 10, 0xFB7, 0xFB9, 1); - AddLabel(45, 10, 0x34, "RunUO"); + AddLabel(45, 10, 0x34, "ModernUO"); AddButton(10, 35, 0xFB7, 0xFB9, 2); AddLabel(45, 35, 0x34, "List of skills"); diff --git a/Projects/Server/Mobile.cs b/Projects/Server/Mobile.cs index 99148447b..d752c5c62 100644 --- a/Projects/Server/Mobile.cs +++ b/Projects/Server/Mobile.cs @@ -4125,10 +4125,7 @@ namespace Server Spawner = null; } - public virtual bool CheckSpellCast(ISpell spell) - { - return true; - } + public virtual bool CheckSpellCast(ISpell spell) => true; /// /// Overridable. Virtual event invoked when the Mobile casts a . @@ -4415,10 +4412,7 @@ namespace Server } } - public virtual bool CheckTarget(Mobile from, Target targ, object targeted) - { - return true; - } + public virtual bool CheckTarget(Mobile from, Target targ, object targeted) => true; public virtual void Use(Item item) { @@ -4853,10 +4847,7 @@ namespace Server StringBuilder sb = new StringBuilder(text.Length, text.Length); for (int i = 0; i < text.Length; ++i) - if (text[i] != ' ') - sb.Append(GhostChars[Utility.Random(GhostChars.Length)]); - else - sb.Append(' '); + sb.Append(text[i] != ' ' ? GhostChars[Utility.Random(GhostChars.Length)] : ' '); text = sb.ToString(); context = m_GhostMutateContext; @@ -4930,6 +4921,22 @@ namespace Server YellHue = hue; range = 18; break; + case MessageType.System: + break; + case MessageType.Label: + break; + case MessageType.Focus: + break; + case MessageType.Spell: + break; + case MessageType.Guild: + break; + case MessageType.Alliance: + break; + case MessageType.Command: + break; + case MessageType.Encoded: + break; default: type = MessageType.Regular; break; @@ -5069,10 +5076,7 @@ namespace Server } } - public static Mobile GetDamagerFrom(DamageEntry de) - { - return de?.Damager; - } + public static Mobile GetDamagerFrom(DamageEntry de) => de?.Damager; public Mobile FindMostRecentDamager(bool allowSelf) { @@ -5097,10 +5101,7 @@ namespace Server return null; } - public Mobile FindLeastRecentDamager(bool allowSelf) - { - return GetDamagerFrom(FindLeastRecentDamageEntry(allowSelf)); - } + public Mobile FindLeastRecentDamager(bool allowSelf) => GetDamagerFrom(FindLeastRecentDamageEntry(allowSelf)); public DamageEntry FindLeastRecentDamageEntry(bool allowSelf) { @@ -5125,10 +5126,7 @@ namespace Server return null; } - public Mobile FindMostTotalDamger(bool allowSelf) - { - return GetDamagerFrom(FindMostTotalDamageEntry(allowSelf)); - } + public Mobile FindMostTotalDamager(bool allowSelf) => GetDamagerFrom(FindMostTotalDamageEntry(allowSelf)); public DamageEntry FindMostTotalDamageEntry(bool allowSelf) { @@ -5150,10 +5148,7 @@ namespace Server return mostTotal; } - public Mobile FindLeastTotalDamger(bool allowSelf) - { - return GetDamagerFrom(FindLeastTotalDamageEntry(allowSelf)); - } + public Mobile FindLeastTotalDamager(bool allowSelf) => GetDamagerFrom(FindLeastTotalDamageEntry(allowSelf)); public DamageEntry FindLeastTotalDamageEntry(bool allowSelf) { @@ -7238,11 +7233,11 @@ namespace Server string val; if (prefix.Length > 0 && suffix.Length > 0) - val = string.Concat(prefix, " ", name, " ", suffix); + val = $"{prefix} {name} {suffix}"; else if (prefix.Length > 0) - val = string.Concat(prefix, " ", name); + val = $"{prefix} {name}"; else if (suffix.Length > 0) - val = string.Concat(name, " ", suffix); + val = $"{name} {suffix}"; else val = name; diff --git a/Projects/Server/Network/PacketHandlers.cs b/Projects/Server/Network/PacketHandlers.cs index 97f7c5b79..7aea2c22a 100644 --- a/Projects/Server/Network/PacketHandlers.cs +++ b/Projects/Server/Network/PacketHandlers.cs @@ -1478,7 +1478,6 @@ namespace Server.Network { int packetID = pvSrc.ReadUInt16(); - Console.WriteLine("Extended Packet: {0:X}", packetID); PacketHandler ph = GetExtendedHandler(packetID); if (ph == null) diff --git a/Projects/Server/Server.csproj b/Projects/Server/Server.csproj index 7f7227843..f74b17db5 100644 --- a/Projects/Server/Server.csproj +++ b/Projects/Server/Server.csproj @@ -7,36 +7,29 @@ ModernUO - 0.1.2 + 0.2.1 Kamron Batman ModernUO - ModernUO - 2019 - netcoreapp3.0 + ModernUO Server + 2019-2020 + netcoreapp3.1 true true + x64 + 8.0 + ..\..\Distribution + ..\..\Distribution + ..\..\Distribution + true + + true TRACE;DEBUG - true false - - true - ..\..\Distribution - ..\..\Distribution - ..\..\Distribution - x64 - 8.0 - true - - true - x64 - ..\..\Distribution - ..\..\Distribution - ..\..\Distribution - 8.0 + true @@ -53,11 +46,11 @@ - - - - - + + + + + diff --git a/Projects/Server/Timer.cs b/Projects/Server/Timer.cs index 9d37b32f5..21b9db12b 100644 --- a/Projects/Server/Timer.cs +++ b/Projects/Server/Timer.cs @@ -71,10 +71,7 @@ namespace Server if (!m_PrioritySet) { - if (count == 1) - m_Priority = ComputePriority(delay); - else - m_Priority = ComputePriority(interval); + m_Priority = ComputePriority(count == 1 ? delay : interval); m_PrioritySet = true; } @@ -130,13 +127,8 @@ namespace Server public virtual bool DefRegCreation => true; - private static string FormatDelegate(Delegate callback) - { - if (callback == null) - return "null"; - - return $"{callback.Method.DeclaringType?.FullName ?? ""}.{callback.Method.Name}"; - } + private static string FormatDelegate(Delegate callback) => + callback == null ? "null" : $"{callback.Method.DeclaringType?.FullName ?? ""}.{callback.Method.Name}"; public static void DumpInfo(TextWriter tw) { diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index 8c37f5b5d..1e68ff305 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; @@ -312,15 +313,13 @@ namespace Server bytes[i] = (byte)part; } - uint cidrPrefix = OrderedAddressValue(bytes); - - return IPMatchCIDR(cidrPrefix, ip, cidrLength); + return IPMatchCIDR(OrderedAddressValue(bytes), ip, cidrLength); } public static bool IPMatchCIDR(IPAddress cidrPrefix, IPAddress ip, int cidrLength) { - if (cidrPrefix == null || ip == null || cidrPrefix.AddressFamily == AddressFamily.InterNetworkV6 - ) //Ignore IPv6 for now + //Ignore IPv6 for now + if (cidrPrefix == null || ip == null || cidrPrefix.AddressFamily == AddressFamily.InterNetworkV6) return false; uint cidrValue = SwapUnsignedInt((uint)GetLongAddressValue(cidrPrefix)); @@ -517,26 +516,11 @@ namespace Server int adx = Math.Abs(dx); int ady = Math.Abs(dy); - if (adx >= ady * 3) - { - if (dx > 0) - return Direction.East; - return Direction.West; - } + if (adx >= ady * 3) return dx > 0 ? Direction.East : Direction.West; - if (ady >= adx * 3) - { - if (dy > 0) - return Direction.South; - return Direction.North; - } + if (ady >= adx * 3) return dy > 0 ? Direction.South : Direction.North; - if (dx > 0) - { - if (dy > 0) - return Direction.Down; - return Direction.Right; - } + if (dx > 0) return dy > 0 ? Direction.Down : Direction.Right; return dy > 0 ? Direction.Left : Direction.Up; } @@ -779,27 +763,16 @@ namespace Server m.FacialHairHue = m.Race.RandomHairHue(); } - public static List CastListContravariant(List list) where TInput : TOutput - { - return list.ConvertAll(value => (TOutput)value); - } + public static List CastListContravariant(List list) where TInput : TOutput => + list.ConvertAll(value => (TOutput)value); - public static List CastListCovariant(List list) where TOutput : TInput - { - return list.ConvertAll(value => (TOutput)value); - } + public static List CastListCovariant(List list) where TOutput : TInput => + list.ConvertAll(value => (TOutput)value); public static List SafeConvertList(List list) where TOutput : class { List output = new List(list.Capacity); - - for (int i = 0; i < list.Count; i++) - { - TOutput t = list[i] as TOutput; - - if (t != null) - output.Add(t); - } + output.AddRange(list.OfType()); return output; } diff --git a/Publish-Linux.sh b/Publish-Linux.sh new file mode 100644 index 000000000..6ef54e0ad --- /dev/null +++ b/Publish-Linux.sh @@ -0,0 +1 @@ +dotnet publish /p:PublishProfile=Linux diff --git a/Publish-OSX.sh b/Publish-OSX.sh new file mode 100644 index 000000000..f48b1c373 --- /dev/null +++ b/Publish-OSX.sh @@ -0,0 +1 @@ +dotnet publish /p:PublishProfile=OSX diff --git a/Publish-Windows.cmd b/Publish-Windows.cmd new file mode 100644 index 000000000..1292e613f --- /dev/null +++ b/Publish-Windows.cmd @@ -0,0 +1 @@ +dotnet publish /p:PublishProfile=Windows diff --git a/README.md b/README.md index d8812a82f..6616881f0 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Ultima Online Server Emulator for the modern era! - See [Goals](./GOALS.md) # Requirements to Compile -- [.NET Core 3.0 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.0) +- [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.1) ### Requirements to Run @@ -23,7 +23,7 @@ Ultima Online Server Emulator for the modern era! - `brew install zlib libuv` - Optional: compile and install [Intel DRNG](https://github.com/modernuo/libdrng) -### Building with .NET Core 3.0 SDK +### Building with .NET Core SDK `dotnet publish /p:PublishProfile=[platform][-SelfContained]` - `platform` can be `Windows`, `Linux`, or `OSX` (capitalization matters) - Appending `-SelfContained` will export all .NET Core files required to run portably.