Updates to .NET Core 3.1 & Cleanup (#79)

This commit is contained in:
Kamron Batman 2020-01-19 12:47:34 -08:00 committed by GitHub
parent 57b14ad690
commit de74218b89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 100 additions and 188 deletions

View file

@ -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<Reagent>(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)

View file

@ -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);

View file

@ -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();

View file

@ -2,30 +2,28 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
<PropertyGroup>
<RootNamespace>Server</RootNamespace>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Scripts.CS</AssemblyName>
<Authors>Kamron Batman</Authors>
<Company>ModernUO</Company>
<Product>ModernUO Scripts</Product>
<Copyright>2019-2020</Copyright>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<WarningsAsErrors />
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PlatformTarget>x64</PlatformTarget>
<OutDir>..\..\Distribution\Assemblies</OutDir>
<OutputPath>..\..\Distribution\Assemblies</OutputPath>
<PublishDir>..\..\Distribution\Assemblies</PublishDir>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>true</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>false</Optimize>
<OutDir>..\..\Distribution\Assemblies</OutDir>
<OutputPath>..\..\Distribution\Assemblies</OutputPath>
<PublishDir>..\..\Distribution\Assemblies</PublishDir>
<WarningsAsErrors />
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Content Include="SpecialSystems\README.TXT" />
@ -37,6 +35,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="2.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="3.1.1" />
</ItemGroup>
</Project>

View file

@ -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");

View file

@ -4125,10 +4125,7 @@ namespace Server
Spawner = null;
}
public virtual bool CheckSpellCast(ISpell spell)
{
return true;
}
public virtual bool CheckSpellCast(ISpell spell) => true;
/// <summary>
/// Overridable. Virtual event invoked when the Mobile casts a <paramref name="spell" />.
@ -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;

View file

@ -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)

View file

@ -7,36 +7,29 @@
</StartupObject>
<AssemblyName>ModernUO</AssemblyName>
<Win32Resource />
<Version>0.1.2</Version>
<Version>0.2.1</Version>
<Authors>Kamron Batman</Authors>
<Company>ModernUO</Company>
<Product>ModernUO</Product>
<Copyright>2019</Copyright>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Product>ModernUO Server</Product>
<Copyright>2019-2020</Copyright>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>8.0</LangVersion>
<PublishDir>..\..\Distribution</PublishDir>
<OutDir>..\..\Distribution</OutDir>
<OutputPath>..\..\Distribution</OutputPath>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>false</Optimize>
<WarningsAsErrors />
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PublishDir>..\..\Distribution</PublishDir>
<OutDir>..\..\Distribution</OutDir>
<OutputPath>..\..\Distribution</OutputPath>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WarningsAsErrors />
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PlatformTarget>x64</PlatformTarget>
<PublishDir>..\..\Distribution</PublishDir>
<OutDir>..\..\Distribution</OutDir>
<OutputPath>..\..\Distribution</OutputPath>
<LangVersion>8.0</LangVersion>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<Content Include="Assemblies\libdrng.dll" Condition="'$(OS)' == 'Windows_NT'">
@ -53,11 +46,11 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.1" />
<PackageReference Include="System.IO.Pipelines" Version="4.7.0" />
</ItemGroup>
</Project>

View file

@ -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)
{

View file

@ -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<TOutput> CastListContravariant<TInput, TOutput>(List<TInput> list) where TInput : TOutput
{
return list.ConvertAll(value => (TOutput)value);
}
public static List<TOutput> CastListContravariant<TInput, TOutput>(List<TInput> list) where TInput : TOutput =>
list.ConvertAll(value => (TOutput)value);
public static List<TOutput> CastListCovariant<TInput, TOutput>(List<TInput> list) where TOutput : TInput
{
return list.ConvertAll(value => (TOutput)value);
}
public static List<TOutput> CastListCovariant<TInput, TOutput>(List<TInput> list) where TOutput : TInput =>
list.ConvertAll(value => (TOutput)value);
public static List<TOutput> SafeConvertList<TInput, TOutput>(List<TInput> list) where TOutput : class
{
List<TOutput> output = new List<TOutput>(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<TOutput>());
return output;
}

1
Publish-Linux.sh Normal file
View file

@ -0,0 +1 @@
dotnet publish /p:PublishProfile=Linux

1
Publish-OSX.sh Normal file
View file

@ -0,0 +1 @@
dotnet publish /p:PublishProfile=OSX

1
Publish-Windows.cmd Normal file
View file

@ -0,0 +1 @@
dotnet publish /p:PublishProfile=Windows

View file

@ -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.