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:
Kamron Batman 2020-11-15 10:03:50 -08:00 • committed by GitHub
parent 4ad8811df2
commit 525cda5413
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
266 changed files with 1348 additions and 1800 deletions

View file

@ -9,7 +9,7 @@ using Server.Spells.Seventh;
namespace Server
{
public class AOS
public static class AOS
{
public static void DisableStatInfluences()
{

View file

@ -3,7 +3,7 @@ using Server.Accounting;
namespace Server.Misc
{
public class AccountPrompt
public static class AccountPrompt
{
public static void Initialize()
{

View file

@ -3,7 +3,7 @@ using Server.Network;
namespace Server.Misc
{
public class AttackMessage
public static class AttackMessage
{
private const string AggressorFormat = "You are attacking {0}!";
private const string AggressedFormat = "{0} is attacking you!";

View file

@ -26,8 +26,7 @@ namespace Server.Misc
CommandSystem.Register("SetSaves", AccessLevel.Administrator, SetSaves_OnCommand);
}
[Usage("SetSaves <true | false>")]
[Description("Enables or disables automatic shard saving.")]
[Usage("SetSaves <true | false>"), Description("Enables or disables automatic shard saving.")]
public static void SetSaves_OnCommand(CommandEventArgs e)
{
if (e.Length == 1)
@ -169,7 +168,7 @@ namespace Server.Misc
{
var info = new DirectoryInfo(paths[i]);
if (info.Name.StartsWith(match))
if (info.Name.StartsWith(match, StringComparison.Ordinal))
{
return info;
}
@ -183,7 +182,7 @@ namespace Server.Misc
private static string FindTimeStamp(string input)
{
var start = input.IndexOf('(');
var start = input.IndexOf('(', StringComparison.Ordinal);
if (start >= 0)
{

View file

@ -5,7 +5,7 @@ using Server.Multis;
namespace Server.Misc
{
public class Cleanup
public static class Cleanup
{
public static void Initialize()
{

View file

@ -185,18 +185,16 @@ namespace Server.Misc
op.WriteLine("- Count: {0}", states.Count);
for (var i = 0; i < states.Count; ++i)
foreach (var ns in TcpServer.Instances)
{
var state = states[i];
op.Write("+ {0}:", ns);
op.Write("+ {0}:", state);
if (state.Account is Account a)
if (ns.Account is Account a)
{
op.Write(" (account = {0})", a.Username);
}
var m = state.Mobile;
var m = ns.Mobile;
if (m != null)
{

View file

@ -3,7 +3,7 @@ using Server.Network;
namespace Server
{
public class DoorGenerator
public static class DoorGenerator
{
private static readonly Rectangle2D[] m_BritRegions =
{
@ -337,8 +337,7 @@ namespace Server
CommandSystem.Register("DoorGen", AccessLevel.Administrator, DoorGen_OnCommand);
}
[Usage("DoorGen")]
[Description("Generates doors by analyzing the map. Slow.")]
[Usage("DoorGen"), Description("Generates doors by analyzing the map. Slow.")]
public static void DoorGen_OnCommand(CommandEventArgs e)
{
Generate();

View file

@ -119,13 +119,13 @@ namespace Server.Misc
try
{
using var client = new SmtpClient();
await client.ConnectAsync(EmailConfiguration.EmailServer, EmailConfiguration.EmailPort, true);
await client.ConnectAsync(EmailConfiguration.EmailServer, EmailConfiguration.EmailPort, true).ConfigureAwait(false);
await client.AuthenticateAsync(
EmailConfiguration.EmailServerUsername,
EmailConfiguration.EmailServerPassword
);
await client.SendAsync(message);
await client.DisconnectAsync(true);
).ConfigureAwait(false);
await client.SendAsync(message).ConfigureAwait(false);
await client.DisconnectAsync(true).ConfigureAwait(false);
return;
}
catch (Exception ex)
@ -138,7 +138,7 @@ namespace Server.Misc
delay *= delay;
await Task.Delay(delay * 1000);
await Task.Delay(delay * 1000).ConfigureAwait(false);
}
}
}

View file

@ -928,10 +928,9 @@ namespace Server.Guilds
Alliance = null;
}
[Usage("GuildProps")]
[Description(
"Opens a menu where you can view and edit guild properties of a targeted player or guild stone. If the new Guild system is active, also brings up the guild gump."
)]
[Usage("GuildProps"), Description(
"Opens a menu where you can view and edit guild properties of a targeted player or guild stone. If the new Guild system is active, also brings up the guild gump."
)]
private static void GuildProps_OnCommand(CommandEventArgs e)
{
var arg = e.ArgString.Trim();

View file

@ -94,8 +94,7 @@ namespace Server
CommandSystem.Register("HWInfo", AccessLevel.GameMaster, HWInfo_OnCommand);
}
[Usage("HWInfo")]
[Description("Displays information about a targeted player's hardware.")]
[Usage("HWInfo"), Description("Displays information about a targeted player's hardware.")]
public static void HWInfo_OnCommand(CommandEventArgs e)
{
e.Mobile.BeginTarget(-1, false, TargetFlags.None, HWInfo_OnTarget);

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using Server.Accounting;
@ -188,8 +187,7 @@ namespace Server.Misc
CommandSystem.Register("LanguageStatistics", AccessLevel.Administrator, LanguageStatistics_OnCommand);
}
[Usage("LanguageStatistics")]
[Description("Generate a file containing the list of languages for each PlayerMobile.")]
[Usage("LanguageStatistics"), Description("Generate a file containing the list of languages for each PlayerMobile.")]
public static void LanguageStatistics_OnCommand(CommandEventArgs e)
{
var ht = new Dictionary<string, InternationalCodeCounter>();

View file

@ -4,6 +4,7 @@ using Server.Network;
namespace Server
{
#pragma warning disable CA1052
public class LightCycle
{
public const int DayLevel = 0;
@ -20,9 +21,8 @@ namespace Server
{
m_LevelOverride = value;
for (var i = 0; i < TcpServer.Instances.Count; ++i)
foreach (var ns in TcpServer.Instances)
{
var ns = TcpServer.Instances[i];
var m = ns.Mobile;
m?.CheckLightLevels(false);
@ -38,8 +38,7 @@ namespace Server
CommandSystem.Register("GlobalLight", AccessLevel.GameMaster, Light_OnCommand);
}
[Usage("GlobalLight <value>")]
[Description("Sets the current global light level.")]
[Usage("GlobalLight <value>"), Description("Sets the current global light level.")]
private static void Light_OnCommand(CommandEventArgs e)
{
if (e.Length >= 1)
@ -111,12 +110,9 @@ namespace Server
protected override void OnTick()
{
for (var i = 0; i < TcpServer.Instances.Count; ++i)
foreach (var ns in TcpServer.Instances)
{
var ns = TcpServer.Instances[i];
var m = ns.Mobile;
m?.CheckLightLevels(false);
ns.Mobile?.CheckLightLevels(false);
}
}
}
@ -139,4 +135,5 @@ namespace Server
}
}
}
#pragma warning restore CA1052
}

View file

@ -2,7 +2,7 @@ using Server.Network;
namespace Server.Misc
{
public class LoginStats
public static class LoginStats
{
public static void Initialize()
{

View file

@ -4,7 +4,7 @@ using Server.Utilities;
namespace Server
{
public class Loot
public static class Loot
{
public static Type[] MLWeaponTypes { get; } =
{

View file

@ -2,7 +2,7 @@ using System;
namespace Server.Misc
{
public class NameVerification
public static class NameVerification
{
public static readonly char[] SpaceDashPeriodQuote =
{
@ -105,8 +105,7 @@ namespace Server.Misc
CommandSystem.Register("ValidateName", AccessLevel.Administrator, ValidateName_OnCommand);
}
[Usage("ValidateName")]
[Description("Checks the result of NameValidation on the specified name.")]
[Usage("ValidateName"), Description("Checks the result of NameValidation on the specified name.")]
public static void ValidateName_OnCommand(CommandEventArgs e)
{
if (Validate(e.ArgString, 2, 16, true, false, true, 1, SpaceDashPeriodQuote))
@ -236,7 +235,7 @@ namespace Server.Misc
for (var i = 0; i < startDisallowed.Length; ++i)
{
if (name.StartsWith(startDisallowed[i]))
if (name.StartsWith(startDisallowed[i], StringComparison.Ordinal))
{
return false;
}

View file

@ -12,7 +12,7 @@ using Server.Spells.Seventh;
namespace Server.Misc
{
public class NotorietyHandlers
public static class NotorietyHandlers
{
public static void Initialize()
{

View file

@ -1,3 +1,5 @@
using System;
namespace Server.Misc
{
public enum ProfanityAction
@ -24,7 +26,7 @@ namespace Server.Misc
'{', '}', '?', '|', '(', ')', '%', '$', '&', '#', '@'
};
public static string[] StartDisallowed { get; } = { };
public static string[] StartDisallowed { get; } = Array.Empty<string>();
public static string[] Disallowed { get; } =
{

View file

@ -1,6 +1,6 @@
namespace Server.Misc
{
public class RaceDefinitions
public static class RaceDefinitions
{
public static void Configure()
{

View file

@ -7,7 +7,7 @@ using Server.Spells.Ninjitsu;
namespace Server.Misc
{
public class RegenRates
public static class RegenRates
{
[CallPriority(10)]
public static void Configure()

View file

@ -25,7 +25,7 @@ namespace Server.Misc
0,
NameVerification.Empty,
NameVerification.StartDisallowed,
Core.ML ? NameVerification.Disallowed : new string[] { }
Core.ML ? NameVerification.Disallowed : Array.Empty<string>()
))
{
if (Core.ML)

View file

@ -870,22 +870,22 @@ namespace Server.Items
/// </summary>
public static CraftResource GetFromOreInfo(OreInfo info)
{
if (info.Name.IndexOf("Spined", StringComparison.Ordinal) >= 0)
if (info.Name.Contains("Spined", StringComparison.Ordinal))
{
return CraftResource.SpinedLeather;
}
if (info.Name.IndexOf("Horned", StringComparison.Ordinal) >= 0)
if (info.Name.Contains("Horned", StringComparison.Ordinal))
{
return CraftResource.HornedLeather;
}
if (info.Name.IndexOf("Barbed", StringComparison.Ordinal) >= 0)
if (info.Name.Contains("Barbed", StringComparison.Ordinal))
{
return CraftResource.BarbedLeather;
}
if (info.Name.IndexOf("Leather", StringComparison.Ordinal) >= 0)
if (info.Name.Contains("Leather", StringComparison.Ordinal))
{
return CraftResource.RegularLeather;
}

View file

@ -3,7 +3,7 @@ using System.IO;
namespace Server
{
public class ShrinkTable
public static class ShrinkTable
{
public const int DefaultItemID = 0x1870; // Yellow virtue stone
@ -56,7 +56,7 @@ namespace Server
{
line = line.Trim();
if (line.Length == 0 || line.StartsWith("#"))
if (line.Length == 0 || line.StartsWith("#", StringComparison.Ordinal))
{
continue;
}

View file

@ -5,7 +5,7 @@ using Server.Regions;
namespace Server.Misc
{
public class SkillCheck
public static class SkillCheck
{
public enum Stat
{

View file

@ -1,4 +1,3 @@
using System.Globalization;
using Server.Gumps;
using Server.Network;
@ -200,14 +199,7 @@ namespace Server
return null;
}
int i;
bool isInteger;
isInteger = value.StartsWith("0x")
? int.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i)
: int.TryParse(value, out i);
return isInteger ? new TextDefinition(i) : new TextDefinition(value);
return Utility.ToInt32(value, out var i) ? new TextDefinition(i) : new TextDefinition(value);
}
public static bool IsNullOrEmpty(TextDefinition def) => def?.IsEmpty != false;

View file

@ -5,7 +5,7 @@ using Server.Mobiles;
namespace Server.Misc
{
public class Titles
public static class Titles
{
public const int MinFame = 0;
public const int MaxFame = 15000;
@ -395,7 +395,7 @@ namespace Server.Misc
var skillLevel = GetSkillLevel(highest);
var skillTitle = highest.Info.Title;
if (mob.Female && skillTitle.EndsWith("man"))
if (mob.Female && skillTitle.EndsWith("man", StringComparison.Ordinal))
{
skillTitle = $"{skillTitle.Substring(0, skillTitle.Length - 3)}woman";
}

View file

@ -40,8 +40,8 @@ namespace Server
CommandSystem.Register("VendorGen", AccessLevel.Administrator, VendorGen_OnCommand);
}
[Usage("VendorGen")]
[Description("Generates vendors based on display cases and floor plans. Analyzes the map files, slow.")]
[Usage("VendorGen"),
Description("Generates vendors based on display cases and floor plans. Analyzes the map files, slow.")]
private static void VendorGen_OnCommand(CommandEventArgs e)
{
Process(Map.Trammel, m_BritRegions);

View file

@ -354,13 +354,10 @@ namespace Server.Misc
type = 2;
}
var states = TcpServer.Instances;
Packet weatherPacket = null;
for (var i = 0; i < states.Count; ++i)
foreach (var ns in TcpServer.Instances)
{
var ns = states[i];
var mob = ns.Mobile;
if (mob == null || mob.Map != Facet)

View file

@ -23,21 +23,12 @@ namespace Server.Misc
public static void FatigueOnDamage(Mobile m, int damage)
{
var fatigue = 0.0;
switch (DFA)
var fatigue = DFA switch
{
case DFAlgorithm.Standard:
{
fatigue = damage * (100.0 / m.Hits) * ((double)m.Stam / 100) - 5.0;
break;
}
case DFAlgorithm.PainSpike:
{
fatigue = damage * (100.0 / m.Hits + (50.0 + m.Stam) / 100 - 1.0) - 5.0;
break;
}
}
DFAlgorithm.Standard => damage * (100.0 / m.Hits) * ((double)m.Stam / 100) - 5.0,
DFAlgorithm.PainSpike => damage * (100.0 / m.Hits + (50.0 + m.Stam) / 100 - 1.0) - 5.0,
_ => 0.0
};
if (fatigue > 0)
{