Fixes dictionary uses (#7)

This commit is contained in:
Kamron Batman 2018-11-02 08:16:42 -07:00 • committed by GitHub
parent d4a52344f2
commit 916d404c51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
161 changed files with 1211 additions and 1722 deletions

View file

@ -61,7 +61,7 @@ namespace Server.Commands
return Utility.ToInt32(Arguments[index]);
}
public uint GetUInt32(int index)
{
if (index < 0 || index >= Arguments.Length)
@ -126,14 +126,10 @@ namespace Server.Commands
public static class CommandSystem
{
static CommandSystem()
{
Entries = new Dictionary<string, CommandEntry>(StringComparer.OrdinalIgnoreCase);
}
public static string Prefix{ get; set; } = "[";
public static Dictionary<string, CommandEntry> Entries{ get; }
public static Dictionary<string, CommandEntry> Entries{ get; } =
new Dictionary<string, CommandEntry>(StringComparer.OrdinalIgnoreCase);
public static AccessLevel BadCommandIgnoreLevel{ get; set; } = AccessLevel.Player;
@ -191,71 +187,64 @@ namespace Server.Commands
Entries[command] = new CommandEntry(command, handler, access);
}
public static bool Handle(Mobile from, string text)
public static bool Handle(Mobile from, string text, MessageType type = MessageType.Regular)
{
return Handle(from, text, MessageType.Regular);
}
if (!text.StartsWith(Prefix) && type != MessageType.Command)
return false;
public static bool Handle(Mobile from, string text, MessageType type)
{
if (text.StartsWith(Prefix) || type == MessageType.Command)
if (type != MessageType.Command)
text = text.Substring(Prefix.Length);
int indexOf = text.IndexOf(' ');
string command;
string[] args;
string argString;
if (indexOf >= 0)
{
if (type != MessageType.Command)
text = text.Substring(Prefix.Length);
argString = text.Substring(indexOf + 1);
int indexOf = text.IndexOf(' ');
string command;
string[] args;
string argString;
if (indexOf >= 0)
{
argString = text.Substring(indexOf + 1);
command = text.Substring(0, indexOf);
args = Split(argString);
}
else
{
argString = "";
command = text.ToLower();
args = new string[0];
}
Entries.TryGetValue(command, out CommandEntry entry);
if (entry != null)
{
if (from.AccessLevel >= entry.AccessLevel)
{
if (entry.Handler != null)
{
CommandEventArgs e = new CommandEventArgs(from, command, argString, args);
entry.Handler(e);
EventSink.InvokeCommand(e);
}
}
else
{
if (from.AccessLevel <= BadCommandIgnoreLevel)
return false;
from.SendMessage("You do not have access to that command.");
}
}
else
{
if (from.AccessLevel <= BadCommandIgnoreLevel)
return false;
from.SendMessage("That is not a valid command.");
}
return true;
command = text.Substring(0, indexOf);
args = Split(argString);
}
else
{
argString = "";
command = text.ToLower();
args = new string[0];
}
return false;
Entries.TryGetValue(command, out CommandEntry entry);
if (entry != null)
{
if (@from.AccessLevel >= entry.AccessLevel)
{
if (entry.Handler != null)
{
CommandEventArgs e = new CommandEventArgs(@from, command, argString, args);
entry.Handler(e);
EventSink.InvokeCommand(e);
}
}
else
{
if (@from.AccessLevel <= BadCommandIgnoreLevel)
return false;
@from.SendMessage("You do not have access to that command.");
}
}
else
{
if (@from.AccessLevel <= BadCommandIgnoreLevel)
return false;
@from.SendMessage("That is not a valid command.");
}
return true;
}
}
}
}

View file

@ -27,8 +27,7 @@ namespace Server.Diagnostics
{
private static Dictionary<Type, GumpProfile> _profiles = new Dictionary<Type, GumpProfile>();
public GumpProfile(Type type)
: base(type.FullName)
public GumpProfile(Type type) : base(type.FullName)
{
}
@ -36,11 +35,13 @@ namespace Server.Diagnostics
public static GumpProfile Acquire(Type type)
{
if (!Core.Profiling) return null;
if (!Core.Profiling)
return null;
if (!_profiles.TryGetValue(type, out GumpProfile prof)) _profiles.Add(type, prof = new GumpProfile(type));
if (!_profiles.TryGetValue(type, out GumpProfile prof))
_profiles.Add(type, prof = new GumpProfile(type));
return prof;
}
}
}
}

View file

@ -58,8 +58,7 @@ namespace Server.Diagnostics
private long _created;
public PacketSendProfile(Type type)
: base(type.FullName)
public PacketSendProfile(Type type) : base(type.FullName)
{
}
@ -68,7 +67,8 @@ namespace Server.Diagnostics
[MethodImpl(MethodImplOptions.Synchronized)]
public static PacketSendProfile Acquire(Type type)
{
if (!_profiles.TryGetValue(type, out PacketSendProfile prof)) _profiles.Add(type, prof = new PacketSendProfile(type));
if (!_profiles.TryGetValue(type, out PacketSendProfile prof))
_profiles.Add(type, prof = new PacketSendProfile(type));
return prof;
}
@ -106,4 +106,4 @@ namespace Server.Diagnostics
return prof;
}
}
}
}

View file

@ -36,11 +36,13 @@ namespace Server.Diagnostics
public static TargetProfile Acquire(Type type)
{
if (!Core.Profiling) return null;
if (!Core.Profiling)
return null;
if (!_profiles.TryGetValue(type, out TargetProfile prof)) _profiles.Add(type, prof = new TargetProfile(type));
if (!_profiles.TryGetValue(type, out TargetProfile prof))
_profiles.Add(type, prof = new TargetProfile(type));
return prof;
}
}
}
}

View file

@ -42,9 +42,11 @@ namespace Server.Diagnostics
public static TimerProfile Acquire(string name)
{
if (!Core.Profiling) return null;
if (!Core.Profiling)
return null;
if (!_profiles.TryGetValue(name, out TimerProfile prof)) _profiles.Add(name, prof = new TimerProfile(name));
if (!_profiles.TryGetValue(name, out TimerProfile prof))
_profiles.Add(name, prof = new TimerProfile(name));
return prof;
}
@ -56,4 +58,4 @@ namespace Server.Diagnostics
op.Write("\t{0,12:N0} {1,12:N0} {2,-12:N0}", Created, Started, Stopped);
}
}
}
}

View file

@ -1747,6 +1747,7 @@ namespace Server.Items
}
catch
{
// ignored
}
}
}

View file

@ -907,13 +907,13 @@ namespace Server
{
string regName = reg.Name;
if (regName != null)
{
if (Regions.ContainsKey(regName))
Console.WriteLine("Warning: Duplicate region name '{0}' for map '{1}'", regName, Name);
else
Regions[regName] = reg;
}
if (regName == null)
return;
if (Regions.ContainsKey(regName))
Console.WriteLine("Warning: Duplicate region name '{0}' for map '{1}'", regName, Name);
else
Regions[regName] = reg;
}
public void UnregisterRegion(Region reg)

View file

@ -1612,7 +1612,7 @@ namespace Server.Network
pvSrc.Trace(state);
return;
}
if (ph.Ingame && state.Mobile?.Deleted != false)
{
if (state.Mobile == null)
@ -2491,9 +2491,8 @@ namespace Server.Network
int authID = pvSrc.ReadInt32();
if (m_AuthIDWindow.ContainsKey(authID))
if (m_AuthIDWindow.TryGetValue(authID, out AuthIDPersistence ap))
{
AuthIDPersistence ap = m_AuthIDWindow[authID];
m_AuthIDWindow.Remove(authID);
state.Version = ap.Version;
@ -2685,6 +2684,7 @@ namespace Server.Network
{
if (m_State == null)
Stop();
if (m_State.Version != null)
{
m_State.BlockAllPackets = false;
@ -2706,4 +2706,4 @@ namespace Server.Network
}
}
}
}
}

View file

@ -397,19 +397,14 @@ namespace Server
Dictionary<string, List<CompilerError>> table = e.IsWarning ? warnings : errors;
List<CompilerError> list = null;
table.TryGetValue(file, out list);
if (list == null)
if (!table.TryGetValue(file, out List<CompilerError> list))
table[file] = list = new List<CompilerError>();
list.Add(e);
}
if (errors.Count > 0)
Console.WriteLine("failed ({0} errors, {1} warnings)", errors.Count, warnings.Count);
else
Console.WriteLine("done ({0} errors, {1} warnings)", errors.Count, warnings.Count);
Console.WriteLine(errors.Count > 0 ? "failed ({0} errors, {1} warnings)" : "done ({0} errors, {1} warnings)",
errors.Count, warnings.Count);
string scriptRoot =
Path.GetFullPath(Path.Combine(Core.BaseDirectory, "Scripts" + Path.DirectorySeparatorChar));
@ -496,24 +491,16 @@ namespace Server
}
catch
{
// ignored
}
}
catch
{
// ignored
}
}
public static bool Compile()
{
return Compile(false);
}
public static bool Compile(bool debug)
{
return Compile(debug, true);
}
public static bool Compile(bool debug, bool cache)
public static bool Compile(bool debug, bool cache = true)
{
EnsureDirectory("Scripts/");
EnsureDirectory("Scripts/Output/");
@ -596,15 +583,9 @@ namespace Server
{
if (asm == null)
{
if (m_NullCache == null)
m_NullCache = new TypeCache(null);
return m_NullCache;
return m_NullCache ?? (m_NullCache = new TypeCache(null));
}
m_TypeCaches.TryGetValue(asm, out TypeCache c);
if (c == null)
if (!m_TypeCaches.TryGetValue(asm, out TypeCache c))
m_TypeCaches[asm] = c = new TypeCache(asm);
return c;
@ -622,10 +603,7 @@ namespace Server
for (int i = 0; type == null && i < Assemblies.Length; ++i)
type = GetTypeCache(Assemblies[i]).GetTypeByFullName(fullName, ignoreCase);
if (type == null)
type = GetTypeCache(Core.Assembly).GetTypeByFullName(fullName, ignoreCase);
return type;
return type ?? GetTypeCache(Core.Assembly).GetTypeByFullName(fullName, ignoreCase);
}
public static Type FindTypeByName(string name)
@ -640,10 +618,7 @@ namespace Server
for (int i = 0; type == null && i < Assemblies.Length; ++i)
type = GetTypeCache(Assemblies[i]).GetTypeByName(name, ignoreCase);
if (type == null)
type = GetTypeCache(Core.Assembly).GetTypeByName(name, ignoreCase);
return type;
return type ?? GetTypeCache(Core.Assembly).GetTypeByName(name, ignoreCase);
}
public static void EnsureDirectory(string dir)
@ -678,10 +653,7 @@ namespace Server
{
public TypeCache(Assembly asm)
{
if (asm == null)
Types = Type.EmptyTypes;
else
Types = asm.GetTypes();
Types = asm == null ? Type.EmptyTypes : asm.GetTypes();
Names = new TypeTable(Types.Length);
FullNames = new TypeTable(Types.Length);
@ -751,4 +723,4 @@ namespace Server
return t;
}
}
}
}

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
@ -88,8 +88,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -258,6 +258,6 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
</Project>

View file

@ -250,8 +250,7 @@ namespace Server
private static long[] m_NextPriorities = new long[8];
private static long[] m_PriorityDelays = new long[8]
{
private static long[] m_PriorityDelays = {
0,
10,
25,
@ -291,9 +290,7 @@ namespace Server
string key = t.ToString();
hash.TryGetValue(key, out List<Timer> list);
if (list == null)
if (!hash.TryGetValue(key, out List<Timer> list))
hash[key] = list = new List<Timer>();
list.Add(t);
@ -603,4 +600,4 @@ namespace Server
#endregion
}
}
}

View file

@ -119,27 +119,8 @@ namespace Server
private static Stack<ConsoleColor> m_ConsoleColors = new Stack<ConsoleColor>();
public static Encoding UTF8
{
get
{
if (m_UTF8 == null)
m_UTF8 = new UTF8Encoding(false, false);
return m_UTF8;
}
}
public static Encoding UTF8WithEncoding
{
get
{
if (m_UTF8WithEncoding == null)
m_UTF8WithEncoding = new UTF8Encoding(true, false);
return m_UTF8WithEncoding;
}
}
public static Encoding UTF8 => m_UTF8 ?? (m_UTF8 = new UTF8Encoding(false, false));
public static Encoding UTF8WithEncoding => m_UTF8WithEncoding ?? (m_UTF8WithEncoding = new UTF8Encoding(true, false));
public static void Separate(StringBuilder sb, string value, string separator)
{
@ -153,10 +134,8 @@ namespace Server
{
if (str == null)
return null;
if (str.Length == 0)
return string.Empty;
return string.Intern(str);
return str.Length == 0 ? string.Empty : string.Intern(str);
}
public static void Intern(ref string str)

View file

@ -1,24 +1,24 @@
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
</startup>
<runtime>
<gcServer enabled="true" />
<gcServer enabled="true"/>
</runtime>
<!--Linux users will need to uncomment and modify the following line:-->
<!--<dllmap dll="libz" target="/lib/x86_64-linux-gnu/libz.so.1" />-->
<appSettings>
<add key="aspnet:RoslynCompilerLocation" value="roslyn"/>
</appSettings>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
</compilers>
</system.codedom>
<!--Linux users will need to uncomment and modify the following line:-->
<!--<dllmap dll="libz" target="/lib/x86_64-linux-gnu/libz.so.1" />-->
</configuration>

View file

@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
</configuration>
<packages>
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net47" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net47" />
</packages>