Cleanup & Fixes for .NET 5 (#309)
- [X] Fixes several bugs - [X] Updates more ordinal issues - [X] Cleans up the code a bit - [X] Turns classes static that should have been - [X] Changes TcpServer.Instances to a HashSet Bumps release version
This commit is contained in:
parent
4ad8811df2
commit
525cda5413
266 changed files with 1348 additions and 1800 deletions
|
|
@ -16,7 +16,7 @@ namespace Server
|
|||
{
|
||||
try
|
||||
{
|
||||
var ip = ((IPEndPoint)e.Connection.RemoteEndPoint).Address;
|
||||
var ip = (e.Connection.RemoteEndPoint as IPEndPoint)?.Address;
|
||||
|
||||
if (Firewall.IsBlocked(ip))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -775,7 +775,7 @@ namespace Server.Accounting
|
|||
}
|
||||
|
||||
m_PasswordAlgorithm = algorithm;
|
||||
Password = password?.Replace("-", string.Empty);
|
||||
Password = password.Replace("-", string.Empty, StringComparison.Ordinal);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using Server.Regions;
|
|||
|
||||
namespace Server.Misc
|
||||
{
|
||||
public class AccountHandler
|
||||
public static class AccountHandler
|
||||
{
|
||||
private static int MaxAccountsPerIP;
|
||||
private static bool AutoAccountCreation;
|
||||
|
|
@ -100,10 +100,9 @@ namespace Server.Misc
|
|||
}
|
||||
}
|
||||
|
||||
[Usage("Password <newPassword> <repeatPassword>")]
|
||||
[Description(
|
||||
"Changes the password of the commanding players account. Requires the same C-class IP address as the account's creator."
|
||||
)]
|
||||
[Usage("Password <newPassword> <repeatPassword>"), Description(
|
||||
"Changes the password of the commanding players account. Requires the same C-class IP address as the account's creator."
|
||||
)]
|
||||
public static void Password_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
var from = e.Mobile;
|
||||
|
|
@ -177,7 +176,7 @@ namespace Server.Misc
|
|||
|
||||
if (entry != null)
|
||||
{
|
||||
if (entry.Message.StartsWith("[Automated: Change Password]"))
|
||||
if (entry.Message.StartsWith("[Automated: Change Password]", StringComparison.Ordinal))
|
||||
{
|
||||
from.SendMessage("You already have a password change request in the help system queue.");
|
||||
}
|
||||
|
|
@ -289,7 +288,9 @@ namespace Server.Misc
|
|||
return null;
|
||||
}
|
||||
|
||||
var isSafe = !(un.StartsWith(" ") || un.EndsWith(" ") || un.EndsWith("."));
|
||||
var isSafe = !(un.StartsWith(" ", StringComparison.Ordinal) ||
|
||||
un.EndsWith(" ", StringComparison.Ordinal) ||
|
||||
un.EndsWith(".", StringComparison.Ordinal));
|
||||
|
||||
for (var i = 0; isSafe && i < un.Length; ++i)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Xml;
|
|||
|
||||
namespace Server.Accounting
|
||||
{
|
||||
public class Accounts
|
||||
public static class Accounts
|
||||
{
|
||||
private static Dictionary<string, IAccount> m_Accounts = new Dictionary<string, IAccount>();
|
||||
|
||||
|
|
@ -56,6 +56,11 @@ namespace Server.Accounting
|
|||
|
||||
var root = doc["accounts"];
|
||||
|
||||
if (root == null)
|
||||
{
|
||||
throw new FileLoadException("Unable to load xml file");
|
||||
}
|
||||
|
||||
foreach (XmlElement account in root.GetElementsByTagName("account"))
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class Firewall
|
||||
public static class Firewall
|
||||
{
|
||||
static Firewall()
|
||||
{
|
||||
|
|
@ -30,13 +31,13 @@ namespace Server
|
|||
|
||||
/*
|
||||
object toAdd;
|
||||
|
||||
|
||||
IPAddress addr;
|
||||
if (IPAddress.TryParse( line, out addr ))
|
||||
toAdd = addr;
|
||||
else
|
||||
toAdd = line;
|
||||
|
||||
|
||||
m_Blocked.Add( toAdd.ToString() );
|
||||
* */
|
||||
}
|
||||
|
|
@ -47,22 +48,13 @@ namespace Server
|
|||
|
||||
public static IFirewallEntry ToFirewallEntry(object entry)
|
||||
{
|
||||
if (entry is IFirewallEntry firewallEntry)
|
||||
return entry switch
|
||||
{
|
||||
return firewallEntry;
|
||||
}
|
||||
|
||||
if (entry is IPAddress address)
|
||||
{
|
||||
return new IPFirewallEntry(address);
|
||||
}
|
||||
|
||||
if (entry is string s)
|
||||
{
|
||||
return ToFirewallEntry(s);
|
||||
}
|
||||
|
||||
return null;
|
||||
IFirewallEntry firewallEntry => firewallEntry,
|
||||
IPAddress address => new IPFirewallEntry(address),
|
||||
string s => ToFirewallEntry(s),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public static IFirewallEntry ToFirewallEntry(string entry)
|
||||
|
|
@ -73,9 +65,9 @@ namespace Server
|
|||
}
|
||||
|
||||
// Try CIDR parse
|
||||
var str = entry.Split('/');
|
||||
var str = entry?.Split('/');
|
||||
|
||||
if (str.Length == 2)
|
||||
if (str?.Length == 2)
|
||||
{
|
||||
if (IPAddress.TryParse(str[0], out var cidrPrefix))
|
||||
{
|
||||
|
|
@ -180,7 +172,7 @@ namespace Server
|
|||
return false;
|
||||
/*
|
||||
bool contains = false;
|
||||
|
||||
|
||||
for ( int i = 0; !contains && i < m_Blocked.Count; ++i )
|
||||
{
|
||||
if (m_Blocked[i] is IPAddress)
|
||||
|
|
@ -188,14 +180,14 @@ namespace Server
|
|||
else if (m_Blocked[i] is String)
|
||||
{
|
||||
string s = (string)m_Blocked[i];
|
||||
|
||||
|
||||
contains = Utility.IPMatchCIDR( s, ip );
|
||||
|
||||
|
||||
if (!contains)
|
||||
contains = Utility.IPMatch( s, ip );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return contains;
|
||||
* */
|
||||
}
|
||||
|
|
@ -312,10 +304,10 @@ namespace Server
|
|||
return obj.Equals(m_Entry);
|
||||
}
|
||||
|
||||
return obj is WildcardIPFirewallEntry entry && m_Entry.Equals(entry.m_Entry);
|
||||
return obj is WildcardIPFirewallEntry entry && m_Entry == entry.m_Entry;
|
||||
}
|
||||
|
||||
public override int GetHashCode() => m_Entry.GetHashCode();
|
||||
public override int GetHashCode() => m_Entry.GetHashCode(StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ using Server.Network;
|
|||
|
||||
namespace Server.Misc
|
||||
{
|
||||
public class IPLimiter
|
||||
public static class IPLimiter
|
||||
{
|
||||
public static IPAddress[] Exemptions =
|
||||
public static readonly IPAddress[] Exemptions =
|
||||
{
|
||||
// IPAddress.Parse( "127.0.0.1" ),
|
||||
IPAddress.Parse( "127.0.0.1" )
|
||||
};
|
||||
|
||||
public static bool Enabled { get; private set; }
|
||||
|
|
@ -31,15 +31,11 @@ namespace Server.Misc
|
|||
return true;
|
||||
}
|
||||
|
||||
var netStates = TcpServer.Instances;
|
||||
|
||||
var count = 0;
|
||||
|
||||
for (var i = 0; i < netStates.Count; ++i)
|
||||
foreach (var ns in TcpServer.Instances)
|
||||
{
|
||||
var compState = netStates[i];
|
||||
|
||||
if (ourAddress.Equals(compState.Address))
|
||||
if (ourAddress.Equals(ns.Address))
|
||||
{
|
||||
++count;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ namespace Server.Accounting.Security
|
|||
public class MD5PasswordProtection : IPasswordProtection
|
||||
{
|
||||
public static IPasswordProtection Instance = new MD5PasswordProtection();
|
||||
#pragma warning disable CA5351
|
||||
private readonly MD5CryptoServiceProvider m_MD5HashProvider = new MD5CryptoServiceProvider();
|
||||
#pragma warning restore CA5351
|
||||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ namespace Server.Accounting.Security
|
|||
private const int m_SaltSize = 8;
|
||||
private const int m_HashSize = 32;
|
||||
private const int m_OutputSize = 2 + m_SaltSize + m_HashSize;
|
||||
public static IPasswordProtection Instance = new PBKDF2PasswordProtection();
|
||||
private static readonly HashAlgorithmName m_Algorithm = HashAlgorithmName.SHA256;
|
||||
public static readonly IPasswordProtection Instance = new PBKDF2PasswordProtection();
|
||||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
|
|
@ -35,7 +34,7 @@ namespace Server.Accounting.Security
|
|||
var iterations = Utility.RandomMinMax(m_MinIterations, m_MaxIterations);
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(output.Slice(0, 2), (ushort)iterations);
|
||||
|
||||
var rfc2898 = new Rfc2898DeriveBytes(plainPassword, m_SaltSize, iterations, m_Algorithm);
|
||||
var rfc2898 = new Rfc2898DeriveBytes(plainPassword, m_SaltSize, iterations, HashAlgorithmName.SHA256);
|
||||
rfc2898.Salt.CopyTo(output.Slice(2, m_SaltSize));
|
||||
rfc2898.GetBytes(m_HashSize).CopyTo(output.Slice(m_SaltSize + 2));
|
||||
|
||||
|
|
@ -51,7 +50,7 @@ namespace Server.Accounting.Security
|
|||
var salt = encryptedBytes.Slice(2, m_SaltSize);
|
||||
|
||||
ReadOnlySpan<byte> hash =
|
||||
new Rfc2898DeriveBytes(plainPassword, salt.ToArray(), iterations, m_Algorithm).GetBytes(m_HashSize);
|
||||
new Rfc2898DeriveBytes(plainPassword, salt.ToArray(), iterations, HashAlgorithmName.SHA256).GetBytes(m_HashSize);
|
||||
|
||||
return hash.SequenceEqual(encryptedBytes.Slice(m_SaltSize + 2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ namespace Server.Accounting.Security
|
|||
public class SHA1PasswordProtection : IPasswordProtection
|
||||
{
|
||||
public static IPasswordProtection Instance = new SHA1PasswordProtection();
|
||||
#pragma warning disable CA5350
|
||||
private readonly SHA1CryptoServiceProvider m_SHA1HashProvider = new SHA1CryptoServiceProvider();
|
||||
#pragma warning restore CA5350
|
||||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue