Adds style cop (#109)
This commit is contained in:
parent
3e715bcb60
commit
556a17aba8
1725 changed files with 33831 additions and 38046 deletions
|
|
@ -47,7 +47,7 @@ namespace Server
|
|||
Refresh();
|
||||
}
|
||||
|
||||
public static TimeSpan ExpireDelay{ get; set; } = TimeSpan.FromMinutes(2.0);
|
||||
public static TimeSpan ExpireDelay { get; set; } = TimeSpan.FromMinutes(2.0);
|
||||
|
||||
public bool Expired
|
||||
{
|
||||
|
|
@ -184,7 +184,7 @@ namespace Server
|
|||
|
||||
public static void DumpAccess()
|
||||
{
|
||||
using StreamWriter op = new StreamWriter("warnings.log", true);
|
||||
using var op = new StreamWriter("warnings.log", true);
|
||||
op.WriteLine("Warning: Access to queued AggressorInfo:");
|
||||
op.WriteLine(new StackTrace());
|
||||
op.WriteLine();
|
||||
|
|
@ -200,4 +200,4 @@ namespace Server
|
|||
m_Reported = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: AssemblyHandler.cs - Created: 2019/08/02 - Updated: 2020/01/19 *
|
||||
* *
|
||||
|
|
@ -17,13 +17,13 @@
|
|||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
|
|
@ -33,7 +33,7 @@ namespace Server
|
|||
private static TypeCache m_NullCache;
|
||||
public static Assembly[] Assemblies { get; set; }
|
||||
|
||||
public static string AssembliesPath = EnsureDirectory("Assemblies");
|
||||
public static readonly string AssembliesPath = EnsureDirectory("Assemblies");
|
||||
|
||||
public static void LoadScripts(string path = null) =>
|
||||
Assemblies = Directory.GetFiles(path ?? AssembliesPath, "*.dll")
|
||||
|
|
@ -41,15 +41,15 @@ namespace Server
|
|||
|
||||
public static void Invoke(string method)
|
||||
{
|
||||
List<MethodInfo> invoke = new List<MethodInfo>();
|
||||
var invoke = new List<MethodInfo>();
|
||||
|
||||
for (int a = 0; a < Assemblies.Length; ++a)
|
||||
for (var a = 0; a < Assemblies.Length; ++a)
|
||||
invoke.AddRange(Assemblies[a].GetTypes()
|
||||
.Select(t => t.GetMethod(method, BindingFlags.Static | BindingFlags.Public)).Where(m => m != null));
|
||||
|
||||
invoke.Sort(new CallPriorityComparer());
|
||||
|
||||
for (int i = 0; i < invoke.Count; ++i)
|
||||
for (var i = 0; i < invoke.Count; ++i)
|
||||
invoke[i].Invoke(null, null);
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ namespace Server
|
|||
{
|
||||
if (asm == null) return m_NullCache ??= new TypeCache(null);
|
||||
|
||||
if (m_TypeCaches.TryGetValue(asm, out TypeCache c))
|
||||
if (m_TypeCaches.TryGetValue(asm, out var c))
|
||||
return c;
|
||||
|
||||
return m_TypeCaches[asm] = new TypeCache(asm);
|
||||
|
|
@ -86,10 +86,10 @@ namespace Server
|
|||
|
||||
public static IEnumerable<Type> FindTypesByName(string name, bool ignoreCase = false)
|
||||
{
|
||||
List<Type> types = new List<Type>();
|
||||
if(ignoreCase)
|
||||
var types = new List<Type>();
|
||||
if (ignoreCase)
|
||||
name = name.ToLower();
|
||||
for (int i = 0; i < Assemblies.Length; i++) types.AddRange(GetTypeCache(Assemblies[i])[name]);
|
||||
for (var i = 0; i < Assemblies.Length; i++) types.AddRange(GetTypeCache(Assemblies[i])[name]);
|
||||
if (types.Count == 0)
|
||||
types.AddRange(GetTypeCache(Core.Assembly)[name]);
|
||||
return types;
|
||||
|
|
@ -97,7 +97,7 @@ namespace Server
|
|||
|
||||
public static string EnsureDirectory(string dir)
|
||||
{
|
||||
string path = Path.Combine(Core.BaseDirectory, dir);
|
||||
var path = Path.Combine(Core.BaseDirectory, dir);
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
|
|
@ -113,7 +113,8 @@ namespace Server
|
|||
public IEnumerable<Type> Types => m_Types;
|
||||
public IEnumerable<string> Names => m_NameMap.Keys;
|
||||
|
||||
public IEnumerable<Type> this[string name] => m_NameMap.TryGetValue(name, out int[] value) ? value.Select(x => m_Types[x]) : new Type[0];
|
||||
public IEnumerable<Type> this[string name] =>
|
||||
m_NameMap.TryGetValue(name, out var value) ? value.Select(x => m_Types[x]) : Array.Empty<Type>();
|
||||
|
||||
public TypeCache(Assembly asm)
|
||||
{
|
||||
|
|
@ -123,31 +124,31 @@ namespace Server
|
|||
Action<int, string> addToRefs = (index, key) =>
|
||||
{
|
||||
if (nameMap.TryGetValue(key, out refs))
|
||||
{
|
||||
refs.Add(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
refs = new HashSet<int> {index};
|
||||
refs = new HashSet<int> { index };
|
||||
nameMap.Add(key, refs);
|
||||
}
|
||||
};
|
||||
Type current;
|
||||
Type aliasType = typeof(TypeAliasAttribute);
|
||||
TypeAliasAttribute alias;
|
||||
for (int i = 0; i < m_Types.Length; i++)
|
||||
var aliasType = typeof(TypeAliasAttribute);
|
||||
for (var i = 0; i < m_Types.Length; i++)
|
||||
{
|
||||
current = m_Types[i];
|
||||
var current = m_Types[i];
|
||||
addToRefs(i, current.Name);
|
||||
addToRefs(i, current.Name.ToLower());
|
||||
addToRefs(i, current.FullName);
|
||||
addToRefs(i, current.FullName?.ToLower());
|
||||
alias = current.GetCustomAttribute(aliasType, false) as TypeAliasAttribute;
|
||||
if (alias != null)
|
||||
for (int j = 0; j < alias.Aliases.Length; j++)
|
||||
if (current.GetCustomAttribute(aliasType, false) is TypeAliasAttribute alias)
|
||||
for (var j = 0; j < alias.Aliases.Length; j++)
|
||||
{
|
||||
addToRefs(i, alias.Aliases[j]);
|
||||
addToRefs(i, alias.Aliases[j].ToLower());
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (key, value) in nameMap)
|
||||
m_NameMap[key] = value.ToArray();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace Server
|
|||
{
|
||||
public CallPriorityAttribute(int priority) => Priority = priority;
|
||||
|
||||
public int Priority{ get; set; }
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
|
||||
public class CallPriorityComparer : IComparer<MethodInfo>
|
||||
|
|
@ -65,8 +65,8 @@ namespace Server
|
|||
if (y == null)
|
||||
return -1;
|
||||
|
||||
int xPriority = GetPriority(x);
|
||||
int yPriority = GetPriority(y);
|
||||
var xPriority = GetPriority(x);
|
||||
var yPriority = GetPriority(y);
|
||||
|
||||
if (xPriority > yPriority)
|
||||
return 1;
|
||||
|
|
@ -79,7 +79,7 @@ namespace Server
|
|||
|
||||
private int GetPriority(MethodInfo mi)
|
||||
{
|
||||
object[] objs = mi.GetCustomAttributes(typeof(CallPriorityAttribute), true);
|
||||
var objs = mi.GetCustomAttributes(typeof(CallPriorityAttribute), true);
|
||||
|
||||
if (objs.Length == 0)
|
||||
return 0;
|
||||
|
|
@ -96,7 +96,7 @@ namespace Server
|
|||
{
|
||||
public TypeAliasAttribute(params string[] aliases) => Aliases = aliases;
|
||||
|
||||
public string[] Aliases{ get; }
|
||||
public string[] Aliases { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
|
||||
|
|
@ -109,20 +109,19 @@ namespace Server
|
|||
{
|
||||
public CustomEnumAttribute(string[] names) => Names = names;
|
||||
|
||||
public string[] Names{ get; }
|
||||
public string[] Names { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Constructor)]
|
||||
public class ConstructibleAttribute : Attribute
|
||||
{
|
||||
public ConstructibleAttribute() :
|
||||
this(AccessLevel.Player) //Lowest accesslevel for current functionality (Level determined by access to [add)
|
||||
public ConstructibleAttribute() : this(AccessLevel.Player) // Lowest accesslevel for current functionality (Level determined by access to [add)
|
||||
{
|
||||
}
|
||||
|
||||
public ConstructibleAttribute(AccessLevel accessLevel) => AccessLevel = accessLevel;
|
||||
|
||||
public AccessLevel AccessLevel{ get; set; }
|
||||
public AccessLevel AccessLevel { get; set; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
|
|
@ -144,10 +143,10 @@ namespace Server
|
|||
WriteLevel = writeLevel;
|
||||
}
|
||||
|
||||
public AccessLevel ReadLevel{ get; }
|
||||
public AccessLevel ReadLevel { get; }
|
||||
|
||||
public AccessLevel WriteLevel{ get; }
|
||||
public AccessLevel WriteLevel { get; }
|
||||
|
||||
public bool ReadOnly{ get; }
|
||||
public bool ReadOnly { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ namespace Server
|
|||
Amount = amount;
|
||||
}
|
||||
|
||||
public Serial Serial{ get; }
|
||||
public Serial Serial { get; }
|
||||
|
||||
public int Amount{ get; }
|
||||
public int Amount { get; }
|
||||
}
|
||||
|
||||
public class SellItemResponse
|
||||
|
|
@ -55,9 +55,9 @@ namespace Server
|
|||
Amount = amount;
|
||||
}
|
||||
|
||||
public Item Item{ get; }
|
||||
public Item Item { get; }
|
||||
|
||||
public int Amount{ get; }
|
||||
public int Amount { get; }
|
||||
}
|
||||
|
||||
public class SellItemState
|
||||
|
|
@ -69,11 +69,11 @@ namespace Server
|
|||
Name = name;
|
||||
}
|
||||
|
||||
public Item Item{ get; }
|
||||
public Item Item { get; }
|
||||
|
||||
public int Price{ get; }
|
||||
public int Price { get; }
|
||||
|
||||
public string Name{ get; }
|
||||
public string Name { get; }
|
||||
}
|
||||
|
||||
public class BuyItemState
|
||||
|
|
@ -89,18 +89,18 @@ namespace Server
|
|||
Hue = hue;
|
||||
}
|
||||
|
||||
public int Price{ get; }
|
||||
public int Price { get; }
|
||||
|
||||
public Serial MySerial{ get; }
|
||||
public Serial MySerial { get; }
|
||||
|
||||
public Serial ContainerSerial{ get; }
|
||||
public Serial ContainerSerial { get; }
|
||||
|
||||
public int ItemID{ get; }
|
||||
public int ItemID { get; }
|
||||
|
||||
public int Amount{ get; }
|
||||
public int Amount { get; }
|
||||
|
||||
public int Hue{ get; }
|
||||
public int Hue { get; }
|
||||
|
||||
public string Description{ get; }
|
||||
public string Description { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ namespace Server
|
|||
Equipment
|
||||
}
|
||||
|
||||
public struct Body
|
||||
public readonly struct Body : IEquatable<object>, IEquatable<Body>, IEquatable<int>
|
||||
{
|
||||
private static readonly BodyType[] m_Types;
|
||||
private static readonly BodyType[] m_Types = Array.Empty<BodyType>();
|
||||
|
||||
static Body()
|
||||
{
|
||||
if (File.Exists("Data/bodyTable.cfg"))
|
||||
{
|
||||
using StreamReader ip = new StreamReader("Data/bodyTable.cfg");
|
||||
using var ip = new StreamReader("Data/bodyTable.cfg");
|
||||
m_Types = new BodyType[0x1000];
|
||||
|
||||
string line;
|
||||
|
|
@ -51,9 +51,9 @@ namespace Server
|
|||
if (line.Length == 0 || line.StartsWith("#"))
|
||||
continue;
|
||||
|
||||
string[] split = line.Split('\t');
|
||||
var split = line.Split('\t');
|
||||
|
||||
if (int.TryParse(split[0], out int bodyID) && Enum.TryParse(split[1], true, out BodyType type) && bodyID >= 0 &&
|
||||
if (int.TryParse(split[0], out var bodyID) && Enum.TryParse(split[1], true, out BodyType type) && bodyID >= 0 &&
|
||||
bodyID < m_Types.Length)
|
||||
{
|
||||
m_Types[bodyID] = type;
|
||||
|
|
@ -68,8 +68,6 @@ namespace Server
|
|||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Data/bodyTable.cfg does not exist");
|
||||
|
||||
m_Types = new BodyType[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +139,7 @@ namespace Server
|
|||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Equipment;
|
||||
|
||||
public int BodyID{ get; }
|
||||
public int BodyID { get; }
|
||||
|
||||
public static implicit operator int(Body a) => a.BodyID;
|
||||
|
||||
|
|
@ -153,6 +151,10 @@ namespace Server
|
|||
|
||||
public override bool Equals(object o) => o is Body b && b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(Body b) => b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(int number) => number == BodyID;
|
||||
|
||||
public static bool operator ==(Body l, Body r) => l.BodyID == r.BodyID;
|
||||
|
||||
public static bool operator !=(Body l, Body r) => l.BodyID != r.BodyID;
|
||||
|
|
|
|||
|
|
@ -75,10 +75,10 @@ namespace System.Buffers
|
|||
{
|
||||
if (length < 0)
|
||||
{
|
||||
Debug.Assert(usingSequence, "usingSequence");
|
||||
// Cast-away readonly to initialize lazy field
|
||||
Volatile.Write(ref Unsafe.AsRef(length), sequence.Length);
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
|
@ -139,27 +139,25 @@ namespace System.Buffers
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentOutOfRangeException($"Rewind went past the start of the memory by {count}.", nameof(count));
|
||||
throw new ArgumentOutOfRangeException(nameof(count), $"Rewind went past the start of the memory by {count}.");
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void RetreatToPreviousSpan(long consumed)
|
||||
{
|
||||
Debug.Assert(usingSequence, "usingSequence");
|
||||
ResetReader();
|
||||
Advance(consumed);
|
||||
}
|
||||
|
||||
private void ResetReader()
|
||||
{
|
||||
Debug.Assert(usingSequence, "usingSequence");
|
||||
CurrentSpanIndex = 0;
|
||||
Consumed = 0;
|
||||
currentPosition = sequence.Start;
|
||||
nextPosition = currentPosition;
|
||||
|
||||
if (sequence.TryGet(ref nextPosition, out ReadOnlyMemory<T> memory))
|
||||
if (sequence.TryGet(ref nextPosition, out var memory))
|
||||
{
|
||||
moreData = true;
|
||||
|
||||
|
|
@ -184,11 +182,10 @@ namespace System.Buffers
|
|||
|
||||
private void GetNextSpan()
|
||||
{
|
||||
Debug.Assert(usingSequence, "usingSequence");
|
||||
if (!sequence.IsSingleSegment)
|
||||
{
|
||||
SequencePosition previousNextPosition = nextPosition;
|
||||
while (sequence.TryGet(ref nextPosition, out ReadOnlyMemory<T> memory))
|
||||
var previousNextPosition = nextPosition;
|
||||
while (sequence.TryGet(ref nextPosition, out var memory))
|
||||
{
|
||||
currentPosition = previousNextPosition;
|
||||
if (memory.Length > 0)
|
||||
|
|
@ -203,6 +200,7 @@ namespace System.Buffers
|
|||
previousNextPosition = nextPosition;
|
||||
}
|
||||
}
|
||||
|
||||
moreData = false;
|
||||
}
|
||||
|
||||
|
|
@ -234,13 +232,12 @@ namespace System.Buffers
|
|||
|
||||
private void AdvanceToNextSpan(long count)
|
||||
{
|
||||
Debug.Assert(usingSequence, "usingSequence");
|
||||
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
|
||||
Consumed += count;
|
||||
while (moreData)
|
||||
{
|
||||
int remaining = CurrentSpan.Length - CurrentSpanIndex;
|
||||
var remaining = CurrentSpan.Length - CurrentSpanIndex;
|
||||
|
||||
if (remaining > count)
|
||||
{
|
||||
|
|
@ -253,7 +250,6 @@ namespace System.Buffers
|
|||
// push the current index to the end of the span.
|
||||
CurrentSpanIndex += remaining;
|
||||
count -= remaining;
|
||||
Debug.Assert(count >= 0);
|
||||
|
||||
GetNextSpan();
|
||||
|
||||
|
|
@ -275,7 +271,7 @@ namespace System.Buffers
|
|||
// We don't provide an advance option to allow easier utilizing of stack allocated destination spans.
|
||||
// (Because we can make this method readonly we can guarantee that we won't capture the span.)
|
||||
|
||||
ReadOnlySpan<T> firstSpan = UnreadSpan;
|
||||
var firstSpan = UnreadSpan;
|
||||
if (firstSpan.Length >= destination.Length)
|
||||
{
|
||||
firstSpan.Slice(0, destination.Length).CopyTo(destination);
|
||||
|
|
@ -292,17 +288,16 @@ namespace System.Buffers
|
|||
if (Remaining < destination.Length)
|
||||
return false;
|
||||
|
||||
ReadOnlySpan<T> firstSpan = UnreadSpan;
|
||||
Debug.Assert(firstSpan.Length < destination.Length);
|
||||
var firstSpan = UnreadSpan;
|
||||
firstSpan.CopyTo(destination);
|
||||
int copied = firstSpan.Length;
|
||||
var copied = firstSpan.Length;
|
||||
|
||||
SequencePosition next = nextPosition;
|
||||
while (sequence.TryGet(ref next, out ReadOnlyMemory<T> nextSegment))
|
||||
var next = nextPosition;
|
||||
while (sequence.TryGet(ref next, out var nextSegment))
|
||||
if (nextSegment.Length > 0)
|
||||
{
|
||||
ReadOnlySpan<T> nextSpan = nextSegment.Span;
|
||||
int toCopy = Math.Min(nextSpan.Length, destination.Length - copied);
|
||||
var nextSpan = nextSegment.Span;
|
||||
var toCopy = Math.Min(nextSpan.Length, destination.Length - copied);
|
||||
nextSpan.Slice(0, toCopy).CopyTo(destination.Slice(copied));
|
||||
copied += toCopy;
|
||||
if (copied >= destination.Length) break;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace System.Buffers
|
|||
private static unsafe bool TryRead<T>(ref this BufferReader<byte> reader, out T value)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlySpan<byte> span = reader.UnreadSpan;
|
||||
var span = reader.UnreadSpan;
|
||||
if (span.Length < sizeof(T)) return TryReadMultisegment(ref reader, out value);
|
||||
|
||||
value = Unsafe.ReadUnaligned<T>(ref MemoryMarshal.GetReference(span));
|
||||
|
|
@ -25,11 +25,9 @@ namespace System.Buffers
|
|||
private static unsafe bool TryReadMultisegment<T>(ref BufferReader<byte> reader, out T value)
|
||||
where T : unmanaged
|
||||
{
|
||||
Debug.Assert(reader.UnreadSpan.Length < sizeof(T), "reader.UnreadSpan.Length < sizeof(T)");
|
||||
|
||||
// Not enough data in the current segment, try to peek for the data we need.
|
||||
T buffer = default;
|
||||
Span<byte> tempSpan = new Span<byte>(&buffer, sizeof(T));
|
||||
var tempSpan = new Span<byte>(&buffer, sizeof(T));
|
||||
|
||||
if (!reader.TryCopyTo(tempSpan))
|
||||
{
|
||||
|
|
@ -153,7 +151,6 @@ namespace System.Buffers
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static bool TryReadLittleEndian(ref this BufferReader<byte> reader, out ulong value)
|
||||
{
|
||||
if (TryReadLittleEndian(ref reader, out long signedvalue))
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace System.Buffers
|
|||
/// relocated and enables any subsections of the array to be used as native memory pointers to P/Invoked API calls.
|
||||
/// </summary>
|
||||
private GCHandle _gcHandle;
|
||||
|
||||
private bool _isDisposed;
|
||||
|
||||
public MemoryPoolSlab(byte[] data)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Buffers
|
||||
{
|
||||
|
|
@ -16,7 +15,9 @@ namespace System.Buffers
|
|||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(int sourceLength, int offset) =>
|
||||
(uint)offset > (uint)sourceLength ? new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.offset)) : new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.length));
|
||||
(uint)offset > (uint)sourceLength
|
||||
? new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.offset))
|
||||
: new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.length));
|
||||
|
||||
public static void ThrowArgumentOutOfRangeException_BufferRequestTooLarge(int maxSize)
|
||||
{
|
||||
|
|
@ -29,17 +30,15 @@ namespace System.Buffers
|
|||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static ArgumentOutOfRangeException GetArgumentOutOfRangeException_BufferRequestTooLarge(int maxSize) => new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.size), $"Cannot allocate more than {maxSize} bytes in a single buffer");
|
||||
private static ArgumentOutOfRangeException GetArgumentOutOfRangeException_BufferRequestTooLarge(int maxSize) =>
|
||||
new ArgumentOutOfRangeException(GetArgumentName(ExceptionArgument.size),
|
||||
$"Cannot allocate more than {maxSize} bytes in a single buffer");
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static ObjectDisposedException GetObjectDisposedException(ExceptionArgument argument) => new ObjectDisposedException(GetArgumentName(argument));
|
||||
private static ObjectDisposedException GetObjectDisposedException(ExceptionArgument argument) =>
|
||||
new ObjectDisposedException(GetArgumentName(argument));
|
||||
|
||||
private static string GetArgumentName(ExceptionArgument argument)
|
||||
{
|
||||
Debug.Assert(Enum.IsDefined(typeof(ExceptionArgument), argument), "The enum value is not defined, please check the ExceptionArgument Enum.");
|
||||
|
||||
return argument.ToString();
|
||||
}
|
||||
private static string GetArgumentName(ExceptionArgument argument) => argument.ToString();
|
||||
|
||||
public enum ExceptionArgument
|
||||
{
|
||||
|
|
|
|||
|
|
@ -80,15 +80,17 @@ namespace System.Buffers
|
|||
/// <returns>The block that is reserved for the called. It must be passed to Return when it is no longer being used.</returns>
|
||||
private MemoryPoolBlock Lease()
|
||||
{
|
||||
if (_isDisposed) MemoryPoolThrowHelper.ThrowObjectDisposedException(MemoryPoolThrowHelper.ExceptionArgument.MemoryPool);
|
||||
if (_isDisposed)
|
||||
MemoryPoolThrowHelper.ThrowObjectDisposedException(MemoryPoolThrowHelper.ExceptionArgument.MemoryPool);
|
||||
|
||||
if (_blocks.TryDequeue(out MemoryPoolBlock block))
|
||||
if (_blocks.TryDequeue(out var block))
|
||||
{
|
||||
// block successfully taken from the stack - return it
|
||||
|
||||
block.Lease();
|
||||
return block;
|
||||
}
|
||||
|
||||
// no blocks available - grow the pool
|
||||
block = AllocateSlab();
|
||||
block.Lease();
|
||||
|
|
@ -101,21 +103,21 @@ namespace System.Buffers
|
|||
/// </summary>
|
||||
private MemoryPoolBlock AllocateSlab()
|
||||
{
|
||||
#pragma warning disable CA2000 // Dispose objects before losing scope
|
||||
var slab = MemoryPoolSlab.Create(_slabLength);
|
||||
#pragma warning restore CA2000 // Dispose objects before losing scope
|
||||
_slabs.Push(slab);
|
||||
|
||||
var basePtr = slab.NativePointer;
|
||||
// Page align the blocks
|
||||
var offset = (int)((((ulong)basePtr + _blockSize - 1) & ~((uint)_blockSize - 1)) - (ulong)basePtr);
|
||||
// Ensure page aligned
|
||||
Debug.Assert(((ulong)basePtr + (uint)offset) % _blockSize == 0);
|
||||
|
||||
var blockCount = (_slabLength - offset) / _blockSize;
|
||||
Interlocked.Add(ref _totalAllocatedBlocks, blockCount);
|
||||
|
||||
MemoryPoolBlock block = null;
|
||||
|
||||
for (int i = 0; i < blockCount; i++)
|
||||
for (var i = 0; i < blockCount; i++)
|
||||
{
|
||||
block = new MemoryPoolBlock(this, slab, offset, _blockSize);
|
||||
|
||||
|
|
@ -143,12 +145,6 @@ namespace System.Buffers
|
|||
/// <param name="block">The block to return. It must have been acquired by calling Lease on the same memory pool instance.</param>
|
||||
internal void Return(MemoryPoolBlock block)
|
||||
{
|
||||
#if BLOCK_LEASE_TRACKING
|
||||
Debug.Assert(block.Pool == this, "Returned block was not leased from this pool");
|
||||
Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}");
|
||||
block.IsLeased = false;
|
||||
#endif
|
||||
|
||||
if (!_isDisposed)
|
||||
_blocks.Enqueue(block);
|
||||
else
|
||||
|
|
@ -177,12 +173,12 @@ namespace System.Buffers
|
|||
_isDisposed = true;
|
||||
|
||||
if (disposing)
|
||||
while (_slabs.TryPop(out MemoryPoolSlab slab))
|
||||
while (_slabs.TryPop(out var slab))
|
||||
// dispose managed state (managed objects).
|
||||
slab.Dispose();
|
||||
|
||||
// Discard blocks in pool
|
||||
while (_blocks.TryDequeue(out MemoryPoolBlock block)) GC.SuppressFinalize(block);
|
||||
while (_blocks.TryDequeue(out var block)) GC.SuppressFinalize(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: SpanWriter.cs - Created: 2019/08/05 - Updated: 2019/12/24 *
|
||||
* *
|
||||
|
|
@ -176,7 +176,7 @@ namespace Server.Buffers
|
|||
/// </summary>
|
||||
public void Write(ReadOnlySpan<byte> input)
|
||||
{
|
||||
int size = Math.Min(input.Length, Length - Position);
|
||||
var size = Math.Min(input.Length, Length - Position);
|
||||
|
||||
input.Slice(0, size).CopyTo(RawSpan.Slice(Position));
|
||||
Position += size;
|
||||
|
|
@ -197,7 +197,7 @@ namespace Server.Buffers
|
|||
{
|
||||
value ??= "";
|
||||
|
||||
int length = Math.Min(size, value.Length);
|
||||
var length = Math.Min(size, value.Length);
|
||||
|
||||
Encoding.ASCII.GetBytes(value.AsSpan(0, length), RawSpan.Slice(Position));
|
||||
|
||||
|
|
@ -207,7 +207,9 @@ namespace Server.Buffers
|
|||
Fill(size - length);
|
||||
}
|
||||
else
|
||||
{
|
||||
Position += size;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: CityInfo.cs - Created: 2019/10/04 - Updated: 2020/01/19 *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Server
|
|||
Patch = pat;
|
||||
Type = type;
|
||||
|
||||
SourceString = _ToStringImpl();
|
||||
SourceString = ToStringImpl();
|
||||
}
|
||||
|
||||
public ClientVersion(string fmt)
|
||||
|
|
@ -53,10 +53,10 @@ namespace Server
|
|||
{
|
||||
fmt = fmt.ToLower();
|
||||
|
||||
int br1 = fmt.IndexOf('.');
|
||||
int br2 = fmt.IndexOf('.', br1 + 1);
|
||||
var br1 = fmt.IndexOf('.');
|
||||
var br2 = fmt.IndexOf('.', br1 + 1);
|
||||
|
||||
int br3 = br2 + 1;
|
||||
var br3 = br2 + 1;
|
||||
while (br3 < fmt.Length && char.IsDigit(fmt, br3))
|
||||
br3++;
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ namespace Server
|
|||
|
||||
if (br3 < fmt.Length)
|
||||
{
|
||||
if (Major <= 5 && Minor <= 0 && Revision <= 6) //Anything before 5.0.7
|
||||
if (Major <= 5 && Minor <= 0 && Revision <= 6) // Anything before 5.0.7
|
||||
{
|
||||
if (!char.IsWhiteSpace(fmt, br3))
|
||||
Patch = fmt[br3] - 'a' + 1;
|
||||
|
|
@ -95,17 +95,17 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public int Major{ get; }
|
||||
public int Major { get; }
|
||||
|
||||
public int Minor{ get; }
|
||||
public int Minor { get; }
|
||||
|
||||
public int Revision{ get; }
|
||||
public int Revision { get; }
|
||||
|
||||
public int Patch{ get; }
|
||||
public int Patch { get; }
|
||||
|
||||
public ClientType Type{ get; }
|
||||
public ClientType Type { get; }
|
||||
|
||||
public string SourceString{ get; }
|
||||
public string SourceString { get; }
|
||||
|
||||
public int CompareTo(ClientVersion o)
|
||||
{
|
||||
|
|
@ -149,7 +149,7 @@ namespace Server
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
ClientVersion v = obj as ClientVersion;
|
||||
var v = obj as ClientVersion;
|
||||
|
||||
return Major == v?.Major
|
||||
&& Minor == v.Minor
|
||||
|
|
@ -158,9 +158,9 @@ namespace Server
|
|||
&& Type == v.Type;
|
||||
}
|
||||
|
||||
private string _ToStringImpl()
|
||||
private string ToStringImpl()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(16);
|
||||
var builder = new StringBuilder(16);
|
||||
|
||||
builder.Append(Major);
|
||||
builder.Append('.');
|
||||
|
|
@ -168,7 +168,7 @@ namespace Server
|
|||
builder.Append('.');
|
||||
builder.Append(Revision);
|
||||
|
||||
if (Major <= 5 && Minor <= 0 && Revision <= 6) //Anything before 5.0.7
|
||||
if (Major <= 5 && Minor <= 0 && Revision <= 6) // Anything before 5.0.7
|
||||
{
|
||||
if (Patch > 0)
|
||||
builder.Append((char)('a' + (Patch - 1)));
|
||||
|
|
@ -188,7 +188,7 @@ namespace Server
|
|||
return builder.ToString();
|
||||
}
|
||||
|
||||
public override string ToString() => _ToStringImpl();
|
||||
public override string ToString() => ToStringImpl();
|
||||
|
||||
public static bool IsNull(object x) => ReferenceEquals(x, null);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ArraySet.cs - Created: 2019/10/04 - Updated: 2019/12/30 *
|
||||
* *
|
||||
|
|
@ -28,7 +28,11 @@ namespace Server.Collections
|
|||
{
|
||||
private readonly List<T> m_List = new List<T>();
|
||||
|
||||
public T this[int index] { get => m_List[index]; set => m_List[index] = value; }
|
||||
public T this[int index]
|
||||
{
|
||||
get => m_List[index];
|
||||
set => m_List[index] = value;
|
||||
}
|
||||
|
||||
public int Count => m_List.Count;
|
||||
|
||||
|
|
@ -36,7 +40,7 @@ namespace Server.Collections
|
|||
|
||||
public int Add(T item)
|
||||
{
|
||||
int indexOf = m_List.IndexOf(item);
|
||||
var indexOf = m_List.IndexOf(item);
|
||||
|
||||
if (indexOf >= 0) return indexOf;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ namespace Server
|
|||
Arguments = arguments;
|
||||
}
|
||||
|
||||
public Mobile Mobile{ get; }
|
||||
public Mobile Mobile { get; }
|
||||
|
||||
public string Command{ get; }
|
||||
public string Command { get; }
|
||||
|
||||
public string ArgString{ get; }
|
||||
public string ArgString { get; }
|
||||
|
||||
public string[] Arguments{ get; }
|
||||
public string[] Arguments { get; }
|
||||
|
||||
public int Length => Arguments.Length;
|
||||
|
||||
|
|
@ -110,39 +110,39 @@ namespace Server
|
|||
AccessLevel = accessLevel;
|
||||
}
|
||||
|
||||
public string Command{ get; }
|
||||
public string Command { get; }
|
||||
|
||||
public CommandEventHandler Handler{ get; }
|
||||
public CommandEventHandler Handler { get; }
|
||||
|
||||
public AccessLevel AccessLevel{ get; }
|
||||
public AccessLevel AccessLevel { get; }
|
||||
|
||||
public int CompareTo(CommandEntry e) => e == null ? 1 : Command.CompareTo(e.Command);
|
||||
}
|
||||
|
||||
public static class CommandSystem
|
||||
{
|
||||
public static string Prefix{ get; set; } = "[";
|
||||
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;
|
||||
public static AccessLevel BadCommandIgnoreLevel { get; set; } = AccessLevel.Player;
|
||||
|
||||
public static string[] Split(string value)
|
||||
{
|
||||
char[] array = value.ToCharArray();
|
||||
List<string> list = new List<string>();
|
||||
var array = value.ToCharArray();
|
||||
var list = new List<string>();
|
||||
|
||||
int start = 0;
|
||||
var start = 0;
|
||||
|
||||
while (start < array.Length)
|
||||
{
|
||||
char c = array[start];
|
||||
var c = array[start];
|
||||
|
||||
if (c == '"')
|
||||
{
|
||||
++start;
|
||||
int end = start;
|
||||
var end = start;
|
||||
|
||||
while (end < array.Length)
|
||||
if (array[end] != '"' || array[end - 1] == '\\')
|
||||
|
|
@ -156,7 +156,7 @@ namespace Server
|
|||
}
|
||||
else if (c != ' ')
|
||||
{
|
||||
int end = start;
|
||||
var end = start;
|
||||
|
||||
while (end < array.Length)
|
||||
if (array[end] != ' ')
|
||||
|
|
@ -190,7 +190,7 @@ namespace Server
|
|||
if (type != MessageType.Command)
|
||||
text = text.Substring(Prefix.Length);
|
||||
|
||||
int indexOf = text.IndexOf(' ');
|
||||
var indexOf = text.IndexOf(' ');
|
||||
|
||||
string command;
|
||||
string[] args;
|
||||
|
|
@ -207,10 +207,10 @@ namespace Server
|
|||
{
|
||||
argString = "";
|
||||
command = text.ToLower();
|
||||
args = new string[0];
|
||||
args = Array.Empty<string>();
|
||||
}
|
||||
|
||||
Entries.TryGetValue(command, out CommandEntry entry);
|
||||
Entries.TryGetValue(command, out var entry);
|
||||
|
||||
if (entry != null)
|
||||
{
|
||||
|
|
@ -218,7 +218,7 @@ namespace Server
|
|||
{
|
||||
if (entry.Handler != null)
|
||||
{
|
||||
CommandEventArgs e = new CommandEventArgs(from, command, argString, args);
|
||||
var e = new CommandEventArgs(from, command, argString, args);
|
||||
entry.Handler(e);
|
||||
EventSink.InvokeCommand(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: Configuration.cs - Created: 2019/10/04 - Updated: 2020/01/19 *
|
||||
* *
|
||||
|
|
@ -56,13 +56,13 @@ namespace Server
|
|||
|
||||
private static Configuration ReadConfiguration()
|
||||
{
|
||||
string relPath = new Uri($"{Core.BaseDirectory}/").MakeRelativeUri(new Uri(FilePath)).ToString();
|
||||
var relPath = new Uri($"{Core.BaseDirectory}/").MakeRelativeUri(new Uri(FilePath)).ToString();
|
||||
Console.Write($"Reading configuration from {relPath}...");
|
||||
Configuration config;
|
||||
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
using FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
using var fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
Span<byte> configBytes = stackalloc byte[(int)fs.Length];
|
||||
fs.Read(configBytes);
|
||||
config = JsonSerializer.Deserialize<Configuration>(Utility.UTF8WithEncoding.GetString(configBytes));
|
||||
|
|
@ -86,10 +86,10 @@ namespace Server
|
|||
|
||||
public void Flush()
|
||||
{
|
||||
using FileStream fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);
|
||||
string configJson = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
|
||||
using var fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);
|
||||
var configJson = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
|
||||
Span<byte> data = stackalloc byte[Utility.UTF8WithEncoding.GetMaxByteCount(configJson.Length)];
|
||||
int bytesWritten = Utility.UTF8WithEncoding.GetBytes(configJson, data);
|
||||
var bytesWritten = Utility.UTF8WithEncoding.GetBytes(configJson, data);
|
||||
fs.Write(data.Slice(0, bytesWritten));
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine($"Configuration saved to {FilePath}");
|
||||
|
|
@ -102,22 +102,31 @@ namespace Server
|
|||
{
|
||||
[JsonPropertyName("fromAddress")]
|
||||
public string FromAddress { get; set; }
|
||||
|
||||
[JsonPropertyName("fromName")]
|
||||
public string FromName { get; set; }
|
||||
|
||||
[JsonPropertyName("crashAddress")]
|
||||
public string crashAddress { get; set; }
|
||||
|
||||
[JsonPropertyName("crashName")]
|
||||
public string crashName { get; set; }
|
||||
|
||||
[JsonPropertyName("speechLogPageAddress")]
|
||||
public string speechLogPageAddress { get; set; }
|
||||
|
||||
[JsonPropertyName("speechLogPageName")]
|
||||
public string speechLogPageName { get; set; }
|
||||
|
||||
[JsonPropertyName("emailServer")]
|
||||
public string emailServer { get; set; }
|
||||
|
||||
[JsonPropertyName("emailPort")]
|
||||
public int emailPort { get; set; }
|
||||
|
||||
[JsonPropertyName("emailUsername")]
|
||||
public string emailUsername { get; set; }
|
||||
|
||||
[JsonPropertyName("emailPassword")]
|
||||
public string emailPassword { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,35 +45,35 @@ namespace Server.ContextMenus
|
|||
From = from;
|
||||
Target = target;
|
||||
|
||||
List<ContextMenuEntry> list = new List<ContextMenuEntry>();
|
||||
var list = new List<ContextMenuEntry>();
|
||||
|
||||
if (target is Mobile mobile)
|
||||
mobile.GetContextMenuEntries(from, list);
|
||||
else if (target is Item item)
|
||||
item.GetContextMenuEntries(from, list);
|
||||
|
||||
//m_Entries = (ContextMenuEntry[])list.ToArray( typeof( ContextMenuEntry ) );
|
||||
// m_Entries = (ContextMenuEntry[])list.ToArray( typeof( ContextMenuEntry ) );
|
||||
|
||||
Entries = list.ToArray();
|
||||
|
||||
for (int i = 0; i < Entries.Length; ++i)
|
||||
for (var i = 0; i < Entries.Length; ++i)
|
||||
Entries[i].Owner = this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Mobile" /> who opened this ContextMenu.
|
||||
/// </summary>
|
||||
public Mobile From{ get; }
|
||||
public Mobile From { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an object of the <see cref="Mobile" /> or <see cref="Item" /> for which this ContextMenu is on.
|
||||
/// </summary>
|
||||
public object Target{ get; }
|
||||
public object Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="ContextMenuEntry">entries</see> contained in this ContextMenu.
|
||||
/// </summary>
|
||||
public ContextMenuEntry[] Entries{ get; }
|
||||
public ContextMenuEntry[] Entries { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this ContextMenu requires packet version 2.
|
||||
|
|
@ -82,7 +82,7 @@ namespace Server.ContextMenus
|
|||
{
|
||||
get
|
||||
{
|
||||
for (int i = 0; i < Entries.Length; ++i)
|
||||
for (var i = 0; i < Entries.Length; ++i)
|
||||
if (Entries[i].Number < 3000000 || Entries[i].Number > 3032767)
|
||||
return true;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,33 +55,33 @@ namespace Server.ContextMenus
|
|||
/// <summary>
|
||||
/// Gets or sets additional <see cref="CMEFlags">flags</see> used in client communication.
|
||||
/// </summary>
|
||||
public CMEFlags Flags{ get; set; }
|
||||
public CMEFlags Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ContextMenu" /> that owns this entry.
|
||||
/// </summary>
|
||||
public ContextMenu Owner{ get; set; }
|
||||
public ContextMenu Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the localization number containing the name of this entry.
|
||||
/// </summary>
|
||||
public int Number{ get; set; }
|
||||
public int Number { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum range at which this entry may be used, in tiles. A value of -1 signifies no maximum range.
|
||||
/// </summary>
|
||||
public int Range{ get; set; }
|
||||
public int Range { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color for this entry. Format is A1-R5-G5-B5.
|
||||
/// </summary>
|
||||
public int Color{ get; set; }
|
||||
public int Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this entry is enabled. When false, the entry will appear in a gray hue and <see cref="OnClick" />
|
||||
/// will never be invoked.
|
||||
/// </summary>
|
||||
public bool Enabled{ get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating if non local use of this entry is permitted.
|
||||
|
|
|
|||
|
|
@ -31,4 +31,4 @@ namespace Server.ContextMenus
|
|||
m_Mobile.Use(m_Mobile.Backpack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,4 @@ namespace Server.ContextMenus
|
|||
m_Mobile.DisplayPaperdollTo(Owner.From);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,23 +36,23 @@ namespace Server.Diagnostics
|
|||
_stopwatch = new Stopwatch();
|
||||
}
|
||||
|
||||
public string Name{ get; }
|
||||
public string Name { get; }
|
||||
|
||||
public long Count{ get; private set; }
|
||||
public long Count { get; private set; }
|
||||
|
||||
public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(1, Count));
|
||||
|
||||
public TimeSpan PeakTime{ get; private set; }
|
||||
public TimeSpan PeakTime { get; private set; }
|
||||
|
||||
public TimeSpan TotalTime{ get; private set; }
|
||||
public TimeSpan TotalTime { get; private set; }
|
||||
|
||||
public static void WriteAll<T>(TextWriter op, IEnumerable<T> profiles) where T : BaseProfile
|
||||
{
|
||||
List<T> list = new List<T>(profiles);
|
||||
var list = new List<T>(profiles);
|
||||
|
||||
list.Sort(delegate(T a, T b) { return -a.TotalTime.CompareTo(b.TotalTime); });
|
||||
list.Sort((a, b) => -a.TotalTime.CompareTo(b.TotalTime));
|
||||
|
||||
foreach (T prof in list)
|
||||
foreach (var prof in list)
|
||||
{
|
||||
prof.WriteTo(op);
|
||||
op.WriteLine();
|
||||
|
|
@ -68,7 +68,7 @@ namespace Server.Diagnostics
|
|||
|
||||
public virtual void Finish()
|
||||
{
|
||||
TimeSpan elapsed = _stopwatch.Elapsed;
|
||||
var elapsed = _stopwatch.Elapsed;
|
||||
|
||||
TotalTime += elapsed;
|
||||
|
||||
|
|
@ -85,4 +85,4 @@ namespace Server.Diagnostics
|
|||
PeakTime.TotalSeconds, TotalTime.TotalSeconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Server.Diagnostics
|
|||
if (!Core.Profiling)
|
||||
return null;
|
||||
|
||||
if (!_profiles.TryGetValue(type, out GumpProfile prof))
|
||||
if (!_profiles.TryGetValue(type, out var prof))
|
||||
_profiles.Add(type, prof = new GumpProfile(type));
|
||||
|
||||
return prof;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Server.Diagnostics
|
|||
{
|
||||
}
|
||||
|
||||
public long TotalLength{ get; private set; }
|
||||
public long TotalLength { get; private set; }
|
||||
|
||||
public double AverageLength => (double)TotalLength / Math.Max(1, Count);
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ namespace Server.Diagnostics
|
|||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static PacketSendProfile Acquire(Type type)
|
||||
{
|
||||
if (!_profiles.TryGetValue(type, out PacketSendProfile prof))
|
||||
if (!_profiles.TryGetValue(type, out var prof))
|
||||
_profiles.Add(type, prof = new PacketSendProfile(type));
|
||||
|
||||
return prof;
|
||||
|
|
@ -99,7 +99,7 @@ namespace Server.Diagnostics
|
|||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static PacketReceiveProfile Acquire(int packetId)
|
||||
{
|
||||
if (!_profiles.TryGetValue(packetId, out PacketReceiveProfile prof))
|
||||
if (!_profiles.TryGetValue(packetId, out var prof))
|
||||
_profiles.Add(packetId, prof = new PacketReceiveProfile(packetId));
|
||||
|
||||
return prof;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Server.Diagnostics
|
|||
if (!Core.Profiling)
|
||||
return null;
|
||||
|
||||
if (!_profiles.TryGetValue(type, out TargetProfile prof))
|
||||
if (!_profiles.TryGetValue(type, out var prof))
|
||||
_profiles.Add(type, prof = new TargetProfile(type));
|
||||
|
||||
return prof;
|
||||
|
|
|
|||
|
|
@ -34,18 +34,18 @@ namespace Server.Diagnostics
|
|||
|
||||
public static IEnumerable<TimerProfile> Profiles => _profiles.Values;
|
||||
|
||||
public long Created{ get; set; }
|
||||
public long Created { get; set; }
|
||||
|
||||
public long Started{ get; set; }
|
||||
public long Started { get; set; }
|
||||
|
||||
public long Stopped{ get; set; }
|
||||
public long Stopped { get; set; }
|
||||
|
||||
public static TimerProfile Acquire(string name)
|
||||
{
|
||||
if (!Core.Profiling)
|
||||
return null;
|
||||
|
||||
if (!_profiles.TryGetValue(name, out TimerProfile prof))
|
||||
if (!_profiles.TryGetValue(name, out var prof))
|
||||
_profiles.Add(name, prof = new TimerProfile(name));
|
||||
|
||||
return prof;
|
||||
|
|
|
|||
|
|
@ -42,11 +42,11 @@ namespace Server
|
|||
|
||||
public static class Effects
|
||||
{
|
||||
public static ParticleSupportType ParticleSupportType{ get; set; } = ParticleSupportType.Detect;
|
||||
public static ParticleSupportType ParticleSupportType { get; set; } = ParticleSupportType.Detect;
|
||||
|
||||
public static bool SendParticlesTo(NetState state) =>
|
||||
ParticleSupportType == ParticleSupportType.Full ||
|
||||
ParticleSupportType == ParticleSupportType.Detect && state.IsUOTDClient;
|
||||
(ParticleSupportType == ParticleSupportType.Detect && state.IsUOTDClient);
|
||||
|
||||
public static void PlaySound(IPoint3D p, Map map, int soundID)
|
||||
{
|
||||
|
|
@ -57,9 +57,9 @@ namespace Server
|
|||
{
|
||||
Packet playSound = null;
|
||||
|
||||
IPooledEnumerable<NetState> eable = map.GetClientsInRange(new Point3D(p));
|
||||
var eable = map.GetClientsInRange(new Point3D(p));
|
||||
|
||||
foreach (NetState state in eable)
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ namespace Server
|
|||
|
||||
public static void SendBoltEffect(IEntity e, bool sound, int hue)
|
||||
{
|
||||
Map map = e.Map;
|
||||
var map = e.Map;
|
||||
|
||||
if (map == null)
|
||||
return;
|
||||
|
|
@ -95,9 +95,9 @@ namespace Server
|
|||
|
||||
Packet preEffect = null, boltEffect = null, playSound = null;
|
||||
|
||||
IPooledEnumerable<NetState> eable = map.GetClientsInRange(e.Location);
|
||||
var eable = map.GetClientsInRange(e.Location);
|
||||
|
||||
foreach (NetState state in eable)
|
||||
foreach (var state in eable)
|
||||
if (state.Mobile.CanSee(e))
|
||||
{
|
||||
if (SendParticlesTo(state))
|
||||
|
|
@ -160,21 +160,22 @@ namespace Server
|
|||
public static void SendLocationParticles(IEntity e, int itemID, int speed, int duration, int hue, int renderMode,
|
||||
int effect, int unknown)
|
||||
{
|
||||
Map map = e.Map;
|
||||
var map = e.Map;
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
Packet particles = null, regular = null;
|
||||
|
||||
IPooledEnumerable<NetState> eable = map.GetClientsInRange(e.Location);
|
||||
var eable = map.GetClientsInRange(e.Location);
|
||||
|
||||
foreach (NetState state in eable)
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
if (SendParticlesTo(state))
|
||||
{
|
||||
particles ??= Packet.Acquire(new LocationParticleEffect(e, itemID, speed, duration, hue, renderMode, effect, unknown));
|
||||
particles ??=
|
||||
Packet.Acquire(new LocationParticleEffect(e, itemID, speed, duration, hue, renderMode, effect, unknown));
|
||||
|
||||
state.Send(particles);
|
||||
}
|
||||
|
|
@ -192,7 +193,7 @@ namespace Server
|
|||
eable.Free();
|
||||
}
|
||||
|
||||
//SendPacket( e.Location, e.Map, new LocationParticleEffect( e, itemID, speed, duration, hue, renderMode, effect, unknown ) );
|
||||
// SendPacket( e.Location, e.Map, new LocationParticleEffect( e, itemID, speed, duration, hue, renderMode, effect, unknown ) );
|
||||
}
|
||||
|
||||
public static void SendTargetEffect(IEntity target, int itemID, int duration)
|
||||
|
|
@ -236,21 +237,22 @@ namespace Server
|
|||
if (target is Mobile mobile)
|
||||
mobile.ProcessDelta();
|
||||
|
||||
Map map = target.Map;
|
||||
var map = target.Map;
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
Packet particles = null, regular = null;
|
||||
|
||||
IPooledEnumerable<NetState> eable = map.GetClientsInRange(target.Location);
|
||||
var eable = map.GetClientsInRange(target.Location);
|
||||
|
||||
foreach (NetState state in eable)
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
if (SendParticlesTo(state))
|
||||
{
|
||||
particles ??= Packet.Acquire(new TargetParticleEffect(target, itemID, speed, duration, hue, renderMode, effect, (int)layer, unknown));
|
||||
particles ??= Packet.Acquire(new TargetParticleEffect(target, itemID, speed, duration, hue, renderMode, effect,
|
||||
(int)layer, unknown));
|
||||
|
||||
state.Send(particles);
|
||||
}
|
||||
|
|
@ -268,7 +270,7 @@ namespace Server
|
|||
eable.Free();
|
||||
}
|
||||
|
||||
//SendPacket( target.Location, target.Map, new TargetParticleEffect( target, itemID, speed, duration, hue, renderMode, effect, (int)layer, unknown ) );
|
||||
// SendPacket( target.Location, target.Map, new TargetParticleEffect( target, itemID, speed, duration, hue, renderMode, effect, (int)layer, unknown ) );
|
||||
}
|
||||
|
||||
public static void SendMovingEffect(IEntity from, IEntity to, int itemID, int speed, int duration,
|
||||
|
|
@ -316,15 +318,15 @@ namespace Server
|
|||
if (to is Mobile toMob)
|
||||
toMob.ProcessDelta();
|
||||
|
||||
Map map = from.Map;
|
||||
var map = from.Map;
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
Packet particles = null, regular = null;
|
||||
|
||||
IPooledEnumerable<NetState> eable = map.GetClientsInRange(from.Location);
|
||||
var eable = map.GetClientsInRange(from.Location);
|
||||
|
||||
foreach (NetState state in eable)
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
|
||||
|
|
@ -337,7 +339,8 @@ namespace Server
|
|||
}
|
||||
else if (itemID > 1)
|
||||
{
|
||||
regular ??= Packet.Acquire(new MovingEffect(from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode));
|
||||
regular ??= Packet.Acquire(new MovingEffect(from, to, itemID, speed, duration, fixedDirection, explodes, hue,
|
||||
renderMode));
|
||||
|
||||
state.Send(regular);
|
||||
}
|
||||
|
|
@ -349,7 +352,7 @@ namespace Server
|
|||
eable.Free();
|
||||
}
|
||||
|
||||
//SendPacket( from.Location, from.Map, new MovingParticleEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode, effect, explodeEffect, explodeSound, unknown ) );
|
||||
// SendPacket( from.Location, from.Map, new MovingParticleEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode, effect, explodeEffect, explodeSound, unknown ) );
|
||||
}
|
||||
|
||||
public static void SendPacket(Point3D origin, Map map, Packet p)
|
||||
|
|
@ -357,11 +360,11 @@ namespace Server
|
|||
if (map == null)
|
||||
return;
|
||||
|
||||
IPooledEnumerable<NetState> eable = map.GetClientsInRange(origin);
|
||||
var eable = map.GetClientsInRange(origin);
|
||||
|
||||
p.Acquire();
|
||||
|
||||
foreach (NetState state in eable)
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
state.Send(p);
|
||||
|
|
@ -377,11 +380,11 @@ namespace Server
|
|||
if (map == null)
|
||||
return;
|
||||
|
||||
IPooledEnumerable<NetState> eable = map.GetClientsInRange(new Point3D(origin));
|
||||
var eable = map.GetClientsInRange(new Point3D(origin));
|
||||
|
||||
p.Acquire();
|
||||
|
||||
foreach (NetState state in eable)
|
||||
foreach (var state in eable)
|
||||
{
|
||||
state.Mobile.ProcessDelta();
|
||||
state.Send(p);
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ namespace Server
|
|||
Password = password;
|
||||
}
|
||||
|
||||
public NetState State{ get; }
|
||||
public NetState State { get; }
|
||||
|
||||
public string Username{ get; }
|
||||
public string Username { get; }
|
||||
|
||||
public string Password{ get; }
|
||||
public string Password { get; }
|
||||
|
||||
public bool Accepted{ get; set; }
|
||||
public bool Accepted { get; set; }
|
||||
|
||||
public ALRReason RejectReason{ get; set; }
|
||||
public ALRReason RejectReason { get; set; }
|
||||
}
|
||||
|
||||
public static partial class EventSink
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Server
|
|||
{
|
||||
public class AggressiveActionEventArgs : EventArgs
|
||||
{
|
||||
private static Queue<AggressiveActionEventArgs> m_Pool = new Queue<AggressiveActionEventArgs>();
|
||||
private static readonly Queue<AggressiveActionEventArgs> m_Pool = new Queue<AggressiveActionEventArgs>();
|
||||
|
||||
private AggressiveActionEventArgs(Mobile aggressed, Mobile aggressor, bool criminal)
|
||||
{
|
||||
|
|
@ -35,11 +35,11 @@ namespace Server
|
|||
Criminal = criminal;
|
||||
}
|
||||
|
||||
public Mobile Aggressed{ get; private set; }
|
||||
public Mobile Aggressed { get; private set; }
|
||||
|
||||
public Mobile Aggressor{ get; private set; }
|
||||
public Mobile Aggressor { get; private set; }
|
||||
|
||||
public bool Criminal{ get; private set; }
|
||||
public bool Criminal { get; private set; }
|
||||
|
||||
public static AggressiveActionEventArgs Create(Mobile aggressed, Mobile aggressor, bool criminal)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,50 +51,50 @@ namespace Server
|
|||
Race = race;
|
||||
}
|
||||
|
||||
public NetState State{ get; }
|
||||
public NetState State { get; }
|
||||
|
||||
public IAccount Account{ get; }
|
||||
public IAccount Account { get; }
|
||||
|
||||
public Mobile Mobile{ get; set; }
|
||||
public Mobile Mobile { get; set; }
|
||||
|
||||
public string Name{ get; }
|
||||
public string Name { get; }
|
||||
|
||||
public bool Female{ get; }
|
||||
public bool Female { get; }
|
||||
|
||||
public int Hue{ get; }
|
||||
public int Hue { get; }
|
||||
|
||||
public int Str{ get; }
|
||||
public int Str { get; }
|
||||
|
||||
public int Dex{ get; }
|
||||
public int Dex { get; }
|
||||
|
||||
public int Int{ get; }
|
||||
public int Int { get; }
|
||||
|
||||
public CityInfo City{ get; }
|
||||
public CityInfo City { get; }
|
||||
|
||||
public SkillNameValue[] Skills{ get; }
|
||||
public SkillNameValue[] Skills { get; }
|
||||
|
||||
public int ShirtHue{ get; }
|
||||
public int ShirtHue { get; }
|
||||
|
||||
public int PantsHue{ get; }
|
||||
public int PantsHue { get; }
|
||||
|
||||
public int HairID{ get; }
|
||||
public int HairID { get; }
|
||||
|
||||
public int HairHue{ get; }
|
||||
public int HairHue { get; }
|
||||
|
||||
public int BeardID{ get; }
|
||||
public int BeardID { get; }
|
||||
|
||||
public int BeardHue{ get; }
|
||||
public int BeardHue { get; }
|
||||
|
||||
public int Profession{ get; set; }
|
||||
public int Profession { get; set; }
|
||||
|
||||
public Race Race{ get; }
|
||||
public Race Race { get; }
|
||||
}
|
||||
|
||||
public struct SkillNameValue
|
||||
{
|
||||
public SkillName Name{ get; }
|
||||
public SkillName Name { get; }
|
||||
|
||||
public int Value{ get; }
|
||||
public int Value { get; }
|
||||
|
||||
public SkillNameValue(SkillName name, int value)
|
||||
{
|
||||
|
|
@ -103,7 +103,8 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public static partial class EventSink {
|
||||
public static partial class EventSink
|
||||
{
|
||||
public static event Action<CharacterCreatedEventArgs> CharacterCreated;
|
||||
public static void InvokeCharacterCreated(CharacterCreatedEventArgs e) => CharacterCreated?.Invoke(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ namespace Server
|
|||
{
|
||||
public CreateGuildEventArgs(uint id) => Id = id;
|
||||
|
||||
public uint Id{ get; set; }
|
||||
public uint Id { get; set; }
|
||||
|
||||
public BaseGuild Guild{ get; set; }
|
||||
public BaseGuild Guild { get; set; }
|
||||
}
|
||||
|
||||
public static partial class EventSink
|
||||
|
|
|
|||
|
|
@ -52,10 +52,14 @@ namespace Server
|
|||
public static void InvokeOpenSpellbookRequest(Mobile m, int type) => OpenSpellbookRequest?.Invoke(m, type);
|
||||
|
||||
public static event Action<Mobile, int, Item> CastSpellRequest;
|
||||
public static void InvokeCastSpellRequest(Mobile m, int spellID, Item book) => CastSpellRequest?.Invoke(m, spellID, book);
|
||||
|
||||
public static void InvokeCastSpellRequest(Mobile m, int spellID, Item book) =>
|
||||
CastSpellRequest?.Invoke(m, spellID, book);
|
||||
|
||||
public static event Action<Mobile, Item, Mobile> BandageTargetRequest;
|
||||
public static void InvokeBandageTargetRequest(Mobile m, Item bandage, Mobile target) => BandageTargetRequest?.Invoke(m, bandage, target);
|
||||
|
||||
public static void InvokeBandageTargetRequest(Mobile m, Item bandage, Mobile target) =>
|
||||
BandageTargetRequest?.Invoke(m, bandage, target);
|
||||
|
||||
public static event Action<Mobile, string> AnimateRequest;
|
||||
public static void InvokeAnimateRequest(Mobile m, string action) => AnimateRequest?.Invoke(m, action);
|
||||
|
|
@ -70,16 +74,22 @@ namespace Server
|
|||
public static void InvokeDisconnected(Mobile m) => Disconnected?.Invoke(m);
|
||||
|
||||
public static event Action<Mobile, Mobile, string> RenameRequest;
|
||||
public static void InvokeRenameRequest(Mobile from, Mobile target, string name) => RenameRequest?.Invoke(from, target, name);
|
||||
|
||||
public static void InvokeRenameRequest(Mobile from, Mobile target, string name) =>
|
||||
RenameRequest?.Invoke(from, target, name);
|
||||
|
||||
public static event Action<Mobile> PlayerDeath;
|
||||
public static void InvokePlayerDeath(Mobile m) => PlayerDeath?.Invoke(m);
|
||||
|
||||
public static event Action<Mobile, Mobile> VirtueGumpRequest;
|
||||
public static void InvokeVirtueGumpRequest(Mobile beholder, Mobile beheld) => VirtueGumpRequest?.Invoke(beholder, beheld);
|
||||
|
||||
public static void InvokeVirtueGumpRequest(Mobile beholder, Mobile beheld) =>
|
||||
VirtueGumpRequest?.Invoke(beholder, beheld);
|
||||
|
||||
public static event Action<Mobile, Mobile, int> VirtueItemRequest;
|
||||
public static void InvokeVirtueItemRequest(Mobile beholder, Mobile beheld, int gumpID) => VirtueItemRequest?.Invoke(beholder, beheld, gumpID);
|
||||
|
||||
public static void InvokeVirtueItemRequest(Mobile beholder, Mobile beheld, int gumpID) =>
|
||||
VirtueItemRequest?.Invoke(beholder, beheld, gumpID);
|
||||
|
||||
public static event Action<Mobile, int> VirtueMacroRequest;
|
||||
public static void InvokeVirtueMacroRequest(Mobile mobile, int virtueID) => VirtueMacroRequest?.Invoke(mobile, virtueID);
|
||||
|
|
@ -87,18 +97,17 @@ namespace Server
|
|||
public static event Action<Mobile> ChatRequest;
|
||||
public static void InvokeChatRequest(Mobile m) => ChatRequest?.Invoke(m);
|
||||
|
||||
|
||||
public static event Action<Mobile, Mobile> PaperdollRequest;
|
||||
public static void InvokePaperdollRequest(Mobile beholder, Mobile beheld) => PaperdollRequest?.Invoke(beholder ,beheld);
|
||||
public static void InvokePaperdollRequest(Mobile beholder, Mobile beheld) => PaperdollRequest?.Invoke(beholder, beheld);
|
||||
|
||||
public static event Action<Mobile, Mobile> ProfileRequest;
|
||||
public static void InvokeProfileRequest(Mobile beholder, Mobile beheld) => ProfileRequest?.Invoke(beholder, beheld);
|
||||
|
||||
public static event Action<Mobile, Mobile, string> ChangeProfileRequest;
|
||||
|
||||
public static void InvokeChangeProfileRequest(Mobile beholder, Mobile beheld, string text) =>
|
||||
ChangeProfileRequest?.Invoke(beholder, beheld, text);
|
||||
|
||||
|
||||
public static event Action<NetState, int> DeleteRequest;
|
||||
public static void InvokeDeleteRequest(NetState state, int index) => DeleteRequest?.Invoke(state, index);
|
||||
|
||||
|
|
@ -121,9 +130,12 @@ namespace Server
|
|||
public static void InvokeQuestGumpRequest(Mobile m) => QuestGumpRequest?.Invoke(m);
|
||||
|
||||
public static event Action<NetState, ClientVersion> ClientVersionReceived;
|
||||
public static void InvokeClientVersionReceived(NetState state, ClientVersion cv) => ClientVersionReceived?.Invoke(state, cv);
|
||||
|
||||
public static void InvokeClientVersionReceived(NetState state, ClientVersion cv) =>
|
||||
ClientVersionReceived?.Invoke(state, cv);
|
||||
|
||||
public static event Action<Mobile, List<Serial>> EquipMacro;
|
||||
|
||||
public static void InvokeEquipMacro(Mobile m, List<Serial> list)
|
||||
{
|
||||
if (list?.Count > 0)
|
||||
|
|
@ -139,12 +151,18 @@ namespace Server
|
|||
}
|
||||
|
||||
public static event Action<Mobile, IEntity, int> TargetedSpell;
|
||||
public static void InvokeTargetedSpell(Mobile m, IEntity target, int spellId) => TargetedSpell?.Invoke(m, target, spellId);
|
||||
|
||||
public static void InvokeTargetedSpell(Mobile m, IEntity target, int spellId) =>
|
||||
TargetedSpell?.Invoke(m, target, spellId);
|
||||
|
||||
public static event Action<Mobile, IEntity, int> TargetedSkillUse;
|
||||
public static void InvokeTargetedSkillUse(Mobile m, IEntity target, int skillId) => TargetedSkillUse?.Invoke(m, target, skillId);
|
||||
|
||||
public static void InvokeTargetedSkillUse(Mobile m, IEntity target, int skillId) =>
|
||||
TargetedSkillUse?.Invoke(m, target, skillId);
|
||||
|
||||
public static event Action<Mobile, Item, short> TargetByResourceMacro;
|
||||
public static void InvokeTargetByResourceMacro(Mobile m, Item item, short resourceType) => TargetByResourceMacro?.Invoke(m, item, resourceType);
|
||||
|
||||
public static void InvokeTargetByResourceMacro(Mobile m, Item item, short resourceType) =>
|
||||
TargetByResourceMacro?.Invoke(m, item, resourceType);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ namespace Server
|
|||
Blocked = false;
|
||||
}
|
||||
|
||||
public NetState NetState{ get; }
|
||||
public NetState NetState { get; }
|
||||
|
||||
public bool Blocked{ get; set; }
|
||||
public bool Blocked { get; set; }
|
||||
}
|
||||
|
||||
public static partial class EventSink
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ namespace Server
|
|||
Password = pw;
|
||||
}
|
||||
|
||||
public NetState State{ get; }
|
||||
public NetState State { get; }
|
||||
|
||||
public string Username{ get; }
|
||||
public string Username { get; }
|
||||
|
||||
public string Password{ get; }
|
||||
public string Password { get; }
|
||||
|
||||
public bool Accepted{ get; set; }
|
||||
public bool Accepted { get; set; }
|
||||
|
||||
public CityInfo[] CityInfo{ get; set; }
|
||||
public CityInfo[] CityInfo { get; set; }
|
||||
}
|
||||
|
||||
public static partial class EventSink
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Server
|
|||
{
|
||||
public class MovementEventArgs : EventArgs
|
||||
{
|
||||
private static Queue<MovementEventArgs> m_Pool = new Queue<MovementEventArgs>();
|
||||
private static readonly Queue<MovementEventArgs> m_Pool = new Queue<MovementEventArgs>();
|
||||
|
||||
public MovementEventArgs(Mobile mobile, Direction dir)
|
||||
{
|
||||
|
|
@ -34,11 +34,11 @@ namespace Server
|
|||
Direction = dir;
|
||||
}
|
||||
|
||||
public Mobile Mobile{ get; private set; }
|
||||
public Mobile Mobile { get; private set; }
|
||||
|
||||
public Direction Direction{ get; private set; }
|
||||
public Direction Direction { get; private set; }
|
||||
|
||||
public bool Blocked{ get; set; }
|
||||
public bool Blocked { get; set; }
|
||||
|
||||
public static MovementEventArgs Create(Mobile mobile, Direction dir)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ namespace Server
|
|||
{
|
||||
public ServerCrashedEventArgs(Exception e) => Exception = e;
|
||||
|
||||
public Exception Exception{ get; }
|
||||
public Exception Exception { get; }
|
||||
|
||||
public bool Close{ get; set; }
|
||||
public bool Close { get; set; }
|
||||
}
|
||||
|
||||
public static partial class EventSink
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ namespace Server
|
|||
Servers = new List<ServerInfo>();
|
||||
}
|
||||
|
||||
public NetState State{ get; }
|
||||
public NetState State { get; }
|
||||
|
||||
public IAccount Account{ get; }
|
||||
public IAccount Account { get; }
|
||||
|
||||
public bool Rejected{ get; set; }
|
||||
public bool Rejected { get; set; }
|
||||
|
||||
public List<ServerInfo> Servers{ get; }
|
||||
public List<ServerInfo> Servers { get; }
|
||||
|
||||
public void AddServer(string name, IPEndPoint address)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ namespace Server
|
|||
AllowConnection = true;
|
||||
}
|
||||
|
||||
public ConnectionContext Context{ get; }
|
||||
public ConnectionContext Context { get; }
|
||||
|
||||
public bool AllowConnection{ get; set; }
|
||||
public bool AllowConnection { get; set; }
|
||||
}
|
||||
|
||||
public static partial class EventSink
|
||||
|
|
|
|||
|
|
@ -14,23 +14,23 @@ namespace Server
|
|||
Keywords = keywords;
|
||||
}
|
||||
|
||||
public Mobile Mobile{ get; }
|
||||
public Mobile Mobile { get; }
|
||||
|
||||
public string Speech{ get; set; }
|
||||
public string Speech { get; set; }
|
||||
|
||||
public MessageType Type{ get; }
|
||||
public MessageType Type { get; }
|
||||
|
||||
public int Hue{ get; }
|
||||
public int Hue { get; }
|
||||
|
||||
public int[] Keywords{ get; }
|
||||
public int[] Keywords { get; }
|
||||
|
||||
public bool Handled{ get; set; }
|
||||
public bool Handled { get; set; }
|
||||
|
||||
public bool Blocked{ get; set; }
|
||||
public bool Blocked { get; set; }
|
||||
|
||||
public bool HasKeyword(int keyword)
|
||||
{
|
||||
for (int i = 0; i < Keywords.Length; ++i)
|
||||
for (var i = 0; i < Keywords.Length; ++i)
|
||||
if (Keywords[i] == keyword)
|
||||
return true;
|
||||
|
||||
|
|
|
|||
|
|
@ -117,11 +117,11 @@ namespace Server
|
|||
NewMovementSystem = 0x00004000,
|
||||
NewFeluccaAreas = 0x00008000,
|
||||
|
||||
ExpansionNone = ContextMenus, //
|
||||
ExpansionT2A = ContextMenus, //
|
||||
ExpansionUOR = ContextMenus, // None
|
||||
ExpansionUOTD = ContextMenus, //
|
||||
ExpansionLBR = ContextMenus, //
|
||||
ExpansionNone = ContextMenus,
|
||||
ExpansionT2A = ContextMenus,
|
||||
ExpansionUOR = ContextMenus,
|
||||
ExpansionUOTD = ContextMenus,
|
||||
ExpansionLBR = ContextMenus,
|
||||
ExpansionAOS = ContextMenus | AOS,
|
||||
ExpansionSE = ExpansionAOS | SE,
|
||||
ExpansionML = ExpansionSE | ML,
|
||||
|
|
@ -169,96 +169,84 @@ namespace Server
|
|||
ClientFlags.None,
|
||||
FeatureFlags.ExpansionNone,
|
||||
CharacterListFlags.ExpansionNone,
|
||||
HousingFlags.None
|
||||
),
|
||||
HousingFlags.None),
|
||||
new ExpansionInfo(
|
||||
1,
|
||||
"The Second Age",
|
||||
ClientFlags.Felucca,
|
||||
FeatureFlags.ExpansionT2A,
|
||||
CharacterListFlags.ExpansionT2A,
|
||||
HousingFlags.None
|
||||
),
|
||||
HousingFlags.None),
|
||||
new ExpansionInfo(
|
||||
2,
|
||||
"Renaissance",
|
||||
ClientFlags.Trammel,
|
||||
FeatureFlags.ExpansionUOR,
|
||||
CharacterListFlags.ExpansionUOR,
|
||||
HousingFlags.None
|
||||
),
|
||||
HousingFlags.None),
|
||||
new ExpansionInfo(
|
||||
3,
|
||||
"Third Dawn",
|
||||
ClientFlags.Ilshenar,
|
||||
FeatureFlags.ExpansionUOTD,
|
||||
CharacterListFlags.ExpansionUOTD,
|
||||
HousingFlags.None
|
||||
),
|
||||
HousingFlags.None),
|
||||
new ExpansionInfo(
|
||||
4,
|
||||
"Blackthorn's Revenge",
|
||||
ClientFlags.Ilshenar,
|
||||
FeatureFlags.ExpansionLBR,
|
||||
CharacterListFlags.ExpansionLBR,
|
||||
HousingFlags.None
|
||||
),
|
||||
HousingFlags.None),
|
||||
new ExpansionInfo(
|
||||
5,
|
||||
"Age of Shadows",
|
||||
ClientFlags.Malas,
|
||||
FeatureFlags.ExpansionAOS,
|
||||
CharacterListFlags.ExpansionAOS,
|
||||
HousingFlags.HousingAOS
|
||||
),
|
||||
HousingFlags.HousingAOS),
|
||||
new ExpansionInfo(
|
||||
6,
|
||||
"Samurai Empire",
|
||||
ClientFlags.Tokuno,
|
||||
FeatureFlags.ExpansionSE,
|
||||
CharacterListFlags.ExpansionSE,
|
||||
HousingFlags.HousingSE
|
||||
),
|
||||
HousingFlags.HousingSE),
|
||||
new ExpansionInfo(
|
||||
7,
|
||||
"Mondain's Legacy",
|
||||
new ClientVersion("5.0.0a"),
|
||||
FeatureFlags.ExpansionML,
|
||||
CharacterListFlags.ExpansionML,
|
||||
HousingFlags.HousingML
|
||||
),
|
||||
HousingFlags.HousingML),
|
||||
new ExpansionInfo(
|
||||
8,
|
||||
"Stygian Abyss",
|
||||
ClientFlags.TerMur,
|
||||
FeatureFlags.ExpansionSA,
|
||||
CharacterListFlags.ExpansionSA,
|
||||
HousingFlags.HousingSA
|
||||
),
|
||||
HousingFlags.HousingSA),
|
||||
new ExpansionInfo(
|
||||
9,
|
||||
"High Seas",
|
||||
new ClientVersion("7.0.9.0"),
|
||||
FeatureFlags.ExpansionHS,
|
||||
CharacterListFlags.ExpansionHS,
|
||||
HousingFlags.HousingHS
|
||||
),
|
||||
HousingFlags.HousingHS),
|
||||
new ExpansionInfo(
|
||||
10,
|
||||
"Time of Legends",
|
||||
new ClientVersion("7.0.45.65"),
|
||||
FeatureFlags.ExpansionTOL,
|
||||
CharacterListFlags.ExpansionTOL,
|
||||
HousingFlags.HousingTOL
|
||||
),
|
||||
HousingFlags.HousingTOL),
|
||||
new ExpansionInfo(
|
||||
11,
|
||||
"Endless Journey",
|
||||
new ClientVersion("7.0.61.0"),
|
||||
FeatureFlags.ExpansionEJ,
|
||||
CharacterListFlags.ExpansionEJ,
|
||||
HousingFlags.HousingEJ
|
||||
)
|
||||
HousingFlags.HousingEJ)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -299,20 +287,20 @@ namespace Server
|
|||
|
||||
public static ExpansionInfo CoreExpansion => GetInfo(Core.Expansion);
|
||||
|
||||
public static ExpansionInfo[] Table{ get; }
|
||||
public static ExpansionInfo[] Table { get; }
|
||||
|
||||
public int ID{ get; }
|
||||
public string Name{ get; set; }
|
||||
public int ID { get; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public ClientFlags ClientFlags{ get; set; }
|
||||
public FeatureFlags SupportedFeatures{ get; set; }
|
||||
public CharacterListFlags CharacterListFlags{ get; set; }
|
||||
public ClientVersion RequiredClient{ get; set; }
|
||||
public HousingFlags CustomHousingFlag{ get; set; }
|
||||
public ClientFlags ClientFlags { get; set; }
|
||||
public FeatureFlags SupportedFeatures { get; set; }
|
||||
public CharacterListFlags CharacterListFlags { get; set; }
|
||||
public ClientVersion RequiredClient { get; set; }
|
||||
public HousingFlags CustomHousingFlag { get; set; }
|
||||
|
||||
public static FeatureFlags GetFeatures(Expansion ex)
|
||||
{
|
||||
ExpansionInfo info = GetInfo(ex);
|
||||
var info = GetInfo(ex);
|
||||
|
||||
if (info != null) return info.SupportedFeatures;
|
||||
|
||||
|
|
@ -338,7 +326,7 @@ namespace Server
|
|||
|
||||
public static ExpansionInfo GetInfo(int ex)
|
||||
{
|
||||
int v = ex;
|
||||
var v = ex;
|
||||
|
||||
if (v < 0 || v >= Table.Length) v = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ using System;
|
|||
namespace Server
|
||||
{
|
||||
[Parsable]
|
||||
public struct Point2D : IPoint2D, IComparable<Point2D>
|
||||
public struct Point2D : IPoint2D, IComparable<Point2D>, IEquatable<object>, IEquatable<Point2D>
|
||||
{
|
||||
internal int m_X;
|
||||
internal int m_Y;
|
||||
|
|
@ -58,22 +58,22 @@ namespace Server
|
|||
|
||||
public static Point2D Parse(string value)
|
||||
{
|
||||
int start = value.IndexOf('(');
|
||||
int end = value.IndexOf(',', start + 1);
|
||||
var start = value.IndexOf('(');
|
||||
var end = value.IndexOf(',', start + 1);
|
||||
|
||||
string param1 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param1 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(')', start + 1);
|
||||
|
||||
string param2 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param2 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
return new Point2D(Convert.ToInt32(param1), Convert.ToInt32(param2));
|
||||
}
|
||||
|
||||
public int CompareTo(Point2D other)
|
||||
{
|
||||
int v = m_X.CompareTo(other.m_X);
|
||||
var v = m_X.CompareTo(other.m_X);
|
||||
|
||||
if (v == 0)
|
||||
v = m_Y.CompareTo(other.m_Y);
|
||||
|
|
@ -83,6 +83,8 @@ namespace Server
|
|||
|
||||
public override bool Equals(object o) => o is IPoint2D p && m_X == p.X && m_Y == p.Y;
|
||||
|
||||
public bool Equals(Point2D p) => m_X == p.X && m_Y == p.Y;
|
||||
|
||||
public override int GetHashCode() => m_X ^ m_Y;
|
||||
|
||||
public static bool operator ==(Point2D l, Point2D r) => l.m_X == r.m_X && l.m_Y == r.m_Y;
|
||||
|
|
@ -119,7 +121,7 @@ namespace Server
|
|||
}
|
||||
|
||||
[Parsable]
|
||||
public struct Point3D : IPoint3D, IComparable<Point3D>
|
||||
public struct Point3D : IPoint3D, IComparable<Point3D>, IEquatable<object>, IEquatable<Point3D>
|
||||
{
|
||||
internal int m_X;
|
||||
internal int m_Y;
|
||||
|
|
@ -169,24 +171,26 @@ namespace Server
|
|||
|
||||
public override bool Equals(object o) => o is IPoint3D p && m_X == p.X && m_Y == p.Y && m_Z == p.Z;
|
||||
|
||||
public bool Equals(Point3D p) => m_X == p.X && m_Y == p.Y && m_Z == p.Z;
|
||||
|
||||
public override int GetHashCode() => m_X ^ m_Y ^ m_Z;
|
||||
|
||||
public static Point3D Parse(string value)
|
||||
{
|
||||
int start = value.IndexOf('(');
|
||||
int end = value.IndexOf(',', start + 1);
|
||||
var start = value.IndexOf('(');
|
||||
var end = value.IndexOf(',', start + 1);
|
||||
|
||||
string param1 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param1 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(',', start + 1);
|
||||
|
||||
string param2 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param2 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(')', start + 1);
|
||||
|
||||
string param3 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param3 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
return new Point3D(Convert.ToInt32(param1), Convert.ToInt32(param2), Convert.ToInt32(param3));
|
||||
}
|
||||
|
|
@ -195,13 +199,15 @@ namespace Server
|
|||
|
||||
public static bool operator !=(Point3D l, Point3D r) => l.m_X != r.m_X || l.m_Y != r.m_Y || l.m_Z != r.m_Z;
|
||||
|
||||
public static bool operator ==(Point3D l, IPoint3D r) => !ReferenceEquals(r, null) && l.m_X == r.X && l.m_Y == r.Y && l.m_Z == r.Z;
|
||||
public static bool operator ==(Point3D l, IPoint3D r) =>
|
||||
!ReferenceEquals(r, null) && l.m_X == r.X && l.m_Y == r.Y && l.m_Z == r.Z;
|
||||
|
||||
public static bool operator !=(Point3D l, IPoint3D r) => !ReferenceEquals(r, null) && (l.m_X != r.X || l.m_Y != r.Y || l.m_Z != r.Z);
|
||||
public static bool operator !=(Point3D l, IPoint3D r) =>
|
||||
!ReferenceEquals(r, null) && (l.m_X != r.X || l.m_Y != r.Y || l.m_Z != r.Z);
|
||||
|
||||
public int CompareTo(Point3D other)
|
||||
{
|
||||
int v = m_X.CompareTo(other.m_X);
|
||||
var v = m_X.CompareTo(other.m_X);
|
||||
|
||||
if (v == 0)
|
||||
{
|
||||
|
|
@ -243,25 +249,25 @@ namespace Server
|
|||
|
||||
public static Rectangle2D Parse(string value)
|
||||
{
|
||||
int start = value.IndexOf('(');
|
||||
int end = value.IndexOf(',', start + 1);
|
||||
var start = value.IndexOf('(');
|
||||
var end = value.IndexOf(',', start + 1);
|
||||
|
||||
string param1 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param1 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(',', start + 1);
|
||||
|
||||
string param2 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param2 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(',', start + 1);
|
||||
|
||||
string param3 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param3 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(')', start + 1);
|
||||
|
||||
string param4 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
var param4 = value.Substring(start + 1, end - (start + 1)).Trim();
|
||||
|
||||
return new Rectangle2D(Convert.ToInt32(param1), Convert.ToInt32(param2), Convert.ToInt32(param3),
|
||||
Convert.ToInt32(param4));
|
||||
|
|
@ -324,9 +330,11 @@ namespace Server
|
|||
m_End.m_Y = r.m_End.m_Y;
|
||||
}
|
||||
|
||||
public bool Contains(Point3D p) => m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
|
||||
public bool Contains(Point3D p) =>
|
||||
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
|
||||
|
||||
public bool Contains(Point2D p) => m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
|
||||
public bool Contains(Point2D p) =>
|
||||
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
|
||||
|
||||
public bool Contains(IPoint2D p) => m_Start <= p && m_End > p;
|
||||
|
||||
|
|
@ -350,10 +358,10 @@ namespace Server
|
|||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public Point3D Start{ get; set; }
|
||||
public Point3D Start { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public Point3D End{ get; set; }
|
||||
public Point3D End { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public int Width => End.X - Start.X;
|
||||
|
|
|
|||
|
|
@ -35,43 +35,42 @@ namespace Server.Guilds
|
|||
private readonly BufferWriter m_SaveBuffer;
|
||||
public BufferWriter SaveBuffer => m_SaveBuffer;
|
||||
|
||||
private static uint m_NextID = 1;
|
||||
private static Serial m_NextID = 1;
|
||||
|
||||
protected BaseGuild(uint Id) //serialization ctor
|
||||
protected BaseGuild(uint id) // serialization ctor
|
||||
{
|
||||
this.Id = Id;
|
||||
List.Add(this.Id, this);
|
||||
if (this.Id + 1 > m_NextID)
|
||||
m_NextID = this.Id + 1;
|
||||
this.Serial = id;
|
||||
List.Add(this.Serial, this);
|
||||
if (this.Serial + 1 > m_NextID)
|
||||
m_NextID = this.Serial + 1;
|
||||
m_SaveBuffer = new BufferWriter(true);
|
||||
}
|
||||
|
||||
protected BaseGuild()
|
||||
{
|
||||
Id = m_NextID++;
|
||||
List.Add(Id, this);
|
||||
Serial = m_NextID++;
|
||||
List.Add(Serial, this);
|
||||
m_SaveBuffer = new BufferWriter(true);
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public uint Id{ get; }
|
||||
public Serial Serial { get; }
|
||||
|
||||
public abstract string Abbreviation{ get; set; }
|
||||
public abstract string Name{ get; set; }
|
||||
public abstract GuildType Type{ get; set; }
|
||||
public abstract bool Disbanded{ get; }
|
||||
public abstract string Abbreviation { get; set; }
|
||||
public abstract string Name { get; set; }
|
||||
public abstract GuildType Type { get; set; }
|
||||
public abstract bool Disbanded { get; }
|
||||
|
||||
public static Dictionary<uint, BaseGuild> List{ get; } = new Dictionary<uint, BaseGuild>();
|
||||
public static Dictionary<uint, BaseGuild> List { get; } = new Dictionary<uint, BaseGuild>();
|
||||
|
||||
int ISerializable.TypeReference => 0;
|
||||
|
||||
uint ISerializable.SerialIdentity => Id;
|
||||
public int TypeRef => 0;
|
||||
|
||||
public void Serialize()
|
||||
{
|
||||
SaveBuffer.Flush();
|
||||
Serialize(SaveBuffer);
|
||||
}
|
||||
|
||||
public abstract void Serialize(IGenericWriter writer);
|
||||
|
||||
public abstract void Deserialize(IGenericReader reader);
|
||||
|
|
@ -79,7 +78,7 @@ namespace Server.Guilds
|
|||
|
||||
public static BaseGuild Find(uint id)
|
||||
{
|
||||
List.TryGetValue(id, out BaseGuild g);
|
||||
List.TryGetValue(id, out var g);
|
||||
|
||||
return g;
|
||||
}
|
||||
|
|
@ -90,12 +89,12 @@ namespace Server.Guilds
|
|||
|
||||
public static List<BaseGuild> Search(string find)
|
||||
{
|
||||
string[] words = find.ToLower().Split(' ');
|
||||
List<BaseGuild> results = new List<BaseGuild>();
|
||||
var words = find.ToLower().Split(' ');
|
||||
var results = new List<BaseGuild>();
|
||||
|
||||
foreach (BaseGuild g in List.Values)
|
||||
foreach (var g in List.Values)
|
||||
{
|
||||
string name = g.Name.ToLower();
|
||||
var name = g.Name.ToLower();
|
||||
|
||||
if (words.All(t => name.IndexOf(t) != -1))
|
||||
results.Add(g);
|
||||
|
|
@ -104,6 +103,6 @@ namespace Server.Guilds
|
|||
return results;
|
||||
}
|
||||
|
||||
public override string ToString() => $"0x{Id:X} \"{Name} [{Abbreviation}]\"";
|
||||
public override string ToString() => $"0x{Serial:X} \"{Name} [{Abbreviation}]\"";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ namespace Server.HuePickers
|
|||
ItemID = itemID;
|
||||
}
|
||||
|
||||
public int Serial{ get; }
|
||||
public int Serial { get; }
|
||||
|
||||
public int ItemID{ get; }
|
||||
public int ItemID { get; }
|
||||
|
||||
public virtual void OnResponse(int hue)
|
||||
{
|
||||
|
|
@ -50,4 +50,4 @@ namespace Server.HuePickers
|
|||
state.AddHuePicker(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace Server.Accounting
|
|||
/// 0 to 999,999,999 by default.
|
||||
/// </summary>
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
int TotalGold{ get; }
|
||||
int TotalGold { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This amount represents the current amount of Platinum owned by the player.
|
||||
|
|
@ -66,7 +66,7 @@ namespace Server.Accounting
|
|||
/// One Platinum represents the value of CurrencyThreshold in Gold.
|
||||
/// </summary>
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
int TotalPlat{ get; }
|
||||
int TotalPlat { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to deposit the given amount of Gold into this account.
|
||||
|
|
@ -110,17 +110,17 @@ namespace Server.Accounting
|
|||
|
||||
public interface IAccount : IGoldAccount, IComparable<IAccount>
|
||||
{
|
||||
string Username{ get; set; }
|
||||
string Email{ get; set; }
|
||||
AccessLevel AccessLevel{ get; set; }
|
||||
string Username { get; set; }
|
||||
string Email { get; set; }
|
||||
AccessLevel AccessLevel { get; set; }
|
||||
|
||||
int Length{ get; }
|
||||
int Limit{ get; }
|
||||
int Count{ get; }
|
||||
Mobile this[int index]{ get; set; }
|
||||
int Length { get; }
|
||||
int Limit { get; }
|
||||
int Count { get; }
|
||||
Mobile this[int index] { get; set; }
|
||||
|
||||
void Delete();
|
||||
void SetPassword(string password);
|
||||
bool CheckPassword(string password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ namespace Server
|
|||
{
|
||||
public interface IEntity : IPoint3D, IComparable<IEntity>
|
||||
{
|
||||
Serial Serial{ get; }
|
||||
Point3D Location{ get; }
|
||||
Map Map{ get; }
|
||||
bool Deleted{ get; }
|
||||
Serial Serial { get; }
|
||||
Point3D Location { get; }
|
||||
Map Map { get; }
|
||||
bool Deleted { get; }
|
||||
void MoveToWorld(Point3D location, Map map);
|
||||
|
||||
void Delete();
|
||||
|
|
@ -54,9 +54,9 @@ namespace Server
|
|||
|
||||
public int CompareTo(IEntity other) => other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
|
||||
public Serial Serial{ get; }
|
||||
public Serial Serial { get; }
|
||||
|
||||
public Point3D Location{ get; private set; }
|
||||
public Point3D Location { get; private set; }
|
||||
|
||||
public int X => Location.X;
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ namespace Server
|
|||
|
||||
public int Z => Location.Z;
|
||||
|
||||
public Map Map{ get; private set; }
|
||||
public Map Map { get; private set; }
|
||||
|
||||
public virtual void MoveToWorld(Point3D newLocation, Map map)
|
||||
{
|
||||
|
|
@ -72,7 +72,7 @@ namespace Server
|
|||
Map = map;
|
||||
}
|
||||
|
||||
public bool Deleted{ get; }
|
||||
public bool Deleted { get; }
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Server
|
|||
public static int Compare(string a, string b) => Comparer.Compare(a, b);
|
||||
|
||||
public static bool Equals(string a, string b) =>
|
||||
a == null && b == null || a != null && b != null && a.Length == b.Length && Comparer.Compare(a, b) == 0;
|
||||
(a == null && b == null) || (a != null && b != null && a.Length == b.Length && Comparer.Compare(a, b) == 0);
|
||||
|
||||
public static bool StartsWith(string a, string b) =>
|
||||
a != null && b != null && a.Length >= b.Length && Comparer.Compare(a.Substring(0, b.Length), b) == 0;
|
||||
|
|
|
|||
|
|
@ -19,42 +19,18 @@
|
|||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Mobiles
|
||||
{
|
||||
public interface IMount
|
||||
{
|
||||
Mobile Rider{ get; set; }
|
||||
void OnRiderDamaged(int amount, Mobile from, bool willKill);
|
||||
}
|
||||
|
||||
public interface IMountItem
|
||||
{
|
||||
IMount Mount{ get; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public interface IVendor
|
||||
{
|
||||
DateTime LastRestock{ get; set; }
|
||||
TimeSpan RestockDelay{ get; }
|
||||
bool OnBuyItems(Mobile from, List<BuyItemResponse> list);
|
||||
bool OnSellItems(Mobile from, List<SellItemResponse> list);
|
||||
void Restock();
|
||||
}
|
||||
|
||||
public interface IPoint2D
|
||||
{
|
||||
int X{ get; }
|
||||
int Y{ get; }
|
||||
int X { get; }
|
||||
int Y { get; }
|
||||
}
|
||||
|
||||
public interface IPoint3D : IPoint2D
|
||||
{
|
||||
int Z{ get; }
|
||||
int Z { get; }
|
||||
}
|
||||
|
||||
public interface ICarvable
|
||||
|
|
@ -64,7 +40,7 @@ namespace Server
|
|||
|
||||
public interface IWeapon
|
||||
{
|
||||
int MaxRange{ get; }
|
||||
int MaxRange { get; }
|
||||
void OnBeforeSwing(Mobile attacker, Mobile defender);
|
||||
TimeSpan OnSwing(Mobile attacker, Mobile defender);
|
||||
void GetStatusDamage(Mobile from, out int min, out int max);
|
||||
|
|
@ -72,12 +48,12 @@ namespace Server
|
|||
|
||||
public interface IHued
|
||||
{
|
||||
int HuedItemID{ get; }
|
||||
int HuedItemID { get; }
|
||||
}
|
||||
|
||||
public interface ISpell
|
||||
{
|
||||
bool IsCasting{ get; }
|
||||
bool IsCasting { get; }
|
||||
void OnCasterHurt();
|
||||
void OnCasterKilled();
|
||||
void OnConnectionChanged();
|
||||
|
|
@ -97,17 +73,17 @@ namespace Server
|
|||
|
||||
public interface ISpawner
|
||||
{
|
||||
bool UnlinkOnTaming{ get; }
|
||||
Point3D HomeLocation{ get; }
|
||||
int HomeRange{ get; }
|
||||
Region Region{ get; }
|
||||
bool UnlinkOnTaming { get; }
|
||||
Point3D HomeLocation { get; }
|
||||
int HomeRange { get; }
|
||||
Region Region { get; }
|
||||
|
||||
void Remove(ISpawnable spawn);
|
||||
}
|
||||
|
||||
public interface ISpawnable : IEntity
|
||||
{
|
||||
ISpawner Spawner{ get; set; }
|
||||
ISpawner Spawner { get; set; }
|
||||
void OnBeforeSpawn(Point3D location, Map map);
|
||||
void OnAfterSpawn();
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -31,13 +31,13 @@ namespace Server
|
|||
|
||||
if (File.Exists("Data/Binary/Bounds.bin"))
|
||||
{
|
||||
using FileStream fs = new FileStream("Data/Binary/Bounds.bin", FileMode.Open, FileAccess.Read,
|
||||
using var fs = new FileStream("Data/Binary/Bounds.bin", FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
BinaryReader bin = new BinaryReader(fs);
|
||||
var bin = new BinaryReader(fs);
|
||||
|
||||
int count = Math.Min(Table.Length, (int)(fs.Length / 8));
|
||||
var count = Math.Min(Table.Length, (int)(fs.Length / 8));
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
int xMin = bin.ReadInt16();
|
||||
int yMin = bin.ReadInt16();
|
||||
|
|
@ -50,9 +50,11 @@ namespace Server
|
|||
bin.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Data/Binary/Bounds.bin does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
public static Rectangle2D[] Table{ get; }
|
||||
public static Rectangle2D[] Table { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Server.Items
|
|||
{
|
||||
if (base.ItemID != value)
|
||||
{
|
||||
Map facet = Parent == null ? Map : null;
|
||||
var facet = Parent == null ? Map : null;
|
||||
|
||||
facet?.OnLeave(this);
|
||||
|
||||
|
|
@ -53,11 +53,11 @@ namespace Server.Items
|
|||
{
|
||||
get
|
||||
{
|
||||
MultiComponentList mcl = Components;
|
||||
var mcl = Components;
|
||||
|
||||
if (mcl.List.Length > 0)
|
||||
{
|
||||
int id = mcl.List[0].m_ItemID;
|
||||
int id = mcl.List[0].ItemId;
|
||||
|
||||
if (id < 0x4000)
|
||||
return 1020000 + id;
|
||||
|
|
@ -77,7 +77,7 @@ namespace Server.Items
|
|||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
Map facet = Map;
|
||||
var facet = Map;
|
||||
|
||||
if (facet != null)
|
||||
{
|
||||
|
|
@ -99,7 +99,7 @@ namespace Server.Items
|
|||
|
||||
public virtual bool Contains(int x, int y)
|
||||
{
|
||||
MultiComponentList mcl = Components;
|
||||
var mcl = Components;
|
||||
|
||||
x -= X + mcl.Min.m_X;
|
||||
y -= Y + mcl.Min.m_Y;
|
||||
|
|
@ -126,7 +126,7 @@ namespace Server.Items
|
|||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
var version = reader.ReadInt();
|
||||
|
||||
if (version == 0)
|
||||
if (ItemID >= 0x4000)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -40,11 +40,11 @@ namespace Server.Items
|
|||
|
||||
public override bool IsVirtualItem => true;
|
||||
|
||||
public Mobile Owner{ get; private set; }
|
||||
public Mobile Owner { get; private set; }
|
||||
|
||||
public bool Opened{ get; private set; }
|
||||
public bool Opened { get; private set; }
|
||||
|
||||
public static bool SendDeleteOnClose{ get; set; }
|
||||
public static bool SendDeleteOnClose { get; set; }
|
||||
|
||||
public void Open()
|
||||
{
|
||||
|
|
@ -73,20 +73,20 @@ namespace Server.Items
|
|||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
var version = reader.ReadInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Owner = reader.ReadMobile();
|
||||
Opened = reader.ReadBool();
|
||||
{
|
||||
Owner = reader.ReadMobile();
|
||||
Opened = reader.ReadBool();
|
||||
|
||||
if (Owner == null)
|
||||
Delete();
|
||||
if (Owner == null)
|
||||
Delete();
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ItemID == 0xE41)
|
||||
|
|
@ -111,12 +111,14 @@ namespace Server.Items
|
|||
|
||||
public override DeathMoveResult OnParentDeath(Mobile parent) => DeathMoveResult.RemainEquipped;
|
||||
|
||||
public override bool IsAccessibleTo(Mobile check) => (check == Owner && Opened || check.AccessLevel >= AccessLevel.GameMaster) && base.IsAccessibleTo(check);
|
||||
public override bool IsAccessibleTo(Mobile check) =>
|
||||
((check == Owner && Opened) || check.AccessLevel >= AccessLevel.GameMaster) && base.IsAccessibleTo(check);
|
||||
|
||||
public override bool OnDragDrop(Mobile from, Item dropped) => (from == Owner && Opened || from.AccessLevel >= AccessLevel.GameMaster) && base.OnDragDrop(from, dropped);
|
||||
public override bool OnDragDrop(Mobile from, Item dropped) =>
|
||||
((from == Owner && Opened) || from.AccessLevel >= AccessLevel.GameMaster) && base.OnDragDrop(from, dropped);
|
||||
|
||||
public override bool OnDragDropInto(Mobile from, Item item, Point3D p) =>
|
||||
(from == Owner && Opened || from.AccessLevel >= AccessLevel.GameMaster) &&
|
||||
((from == Owner && Opened) || from.AccessLevel >= AccessLevel.GameMaster) &&
|
||||
base.OnDragDropInto(from, item, p);
|
||||
|
||||
public override int GetTotal(TotalType type)
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ namespace Server.Items
|
|||
{
|
||||
}
|
||||
|
||||
public SecureTrade Trade{ get; }
|
||||
public SecureTrade Trade { get; }
|
||||
|
||||
public override bool CheckHold(Mobile m, Item item, bool message, bool checkItems, int plusItems, int plusWeight)
|
||||
{
|
||||
if (item == Trade.From.VirtualCheck || item == Trade.To.VirtualCheck) return true;
|
||||
|
||||
Mobile to = Trade.From.Container != this ? Trade.From.Mobile : Trade.To.Mobile;
|
||||
var to = Trade.From.Container != this ? Trade.From.Mobile : Trade.To.Mobile;
|
||||
|
||||
return m.CheckTrade(to, item, this, message, checkItems, plusItems, plusWeight);
|
||||
}
|
||||
|
|
@ -53,7 +53,8 @@ namespace Server.Items
|
|||
return false;
|
||||
}
|
||||
|
||||
public override bool IsAccessibleTo(Mobile check) => IsChildOf(check) && Trade?.Valid == true && base.IsAccessibleTo(check);
|
||||
public override bool IsAccessibleTo(Mobile check) =>
|
||||
IsChildOf(check) && Trade?.Valid == true && base.IsAccessibleTo(check);
|
||||
|
||||
public override void OnItemAdded(Item item)
|
||||
{
|
||||
|
|
@ -109,7 +110,7 @@ namespace Server.Items
|
|||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
var version = reader.ReadInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
namespace Server.Items
|
||||
{
|
||||
public sealed class VirtualCheck : Item
|
||||
{
|
||||
// TODO: Move to configuration
|
||||
public static bool UseEditGump = false;
|
||||
|
||||
private int _Gold;
|
||||
private int m_Gold;
|
||||
|
||||
private int _Plat;
|
||||
private int m_Plat;
|
||||
|
||||
public VirtualCheck(int plat = 0, int gold = 0)
|
||||
: base(0x14F0)
|
||||
|
|
@ -35,15 +35,15 @@ namespace Server
|
|||
|
||||
public override string DefaultName => "Offer Of Currency";
|
||||
|
||||
public EditGump Editor{ get; private set; }
|
||||
public EditGump Editor { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public int Plat
|
||||
{
|
||||
get => _Plat;
|
||||
get => m_Plat;
|
||||
set
|
||||
{
|
||||
_Plat = value;
|
||||
m_Plat = value;
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
|
@ -51,17 +51,17 @@ namespace Server
|
|||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public int Gold
|
||||
{
|
||||
get => _Gold;
|
||||
get => m_Gold;
|
||||
set
|
||||
{
|
||||
_Gold = value;
|
||||
m_Gold = value;
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsAccessibleTo(Mobile check)
|
||||
{
|
||||
SecureTradeContainer c = GetSecureTradeCont();
|
||||
var c = GetSecureTradeCont();
|
||||
|
||||
if (check == null || c == null) return base.IsAccessibleTo(check);
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ namespace Server
|
|||
|
||||
public void UpdateTrade(Mobile user)
|
||||
{
|
||||
SecureTradeContainer c = GetSecureTradeCont();
|
||||
var c = GetSecureTradeCont();
|
||||
|
||||
if (c?.Trade == null) return;
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ namespace Server
|
|||
AllGold
|
||||
}
|
||||
|
||||
private int _Plat, _Gold;
|
||||
private int m_Plat, m_Gold;
|
||||
|
||||
public EditGump(Mobile user, VirtualCheck check)
|
||||
: base(50, 50)
|
||||
|
|
@ -158,8 +158,8 @@ namespace Server
|
|||
User = user;
|
||||
Check = check;
|
||||
|
||||
_Plat = Check.Plat;
|
||||
_Gold = Check.Gold;
|
||||
m_Plat = Check.Plat;
|
||||
m_Gold = Check.Gold;
|
||||
|
||||
Closable = true;
|
||||
Disposable = true;
|
||||
|
|
@ -171,8 +171,8 @@ namespace Server
|
|||
CompileLayout();
|
||||
}
|
||||
|
||||
public Mobile User{ get; }
|
||||
public VirtualCheck Check{ get; private set; }
|
||||
public Mobile User { get; }
|
||||
public VirtualCheck Check { get; private set; }
|
||||
|
||||
public override void OnServerClose(NetState owner)
|
||||
{
|
||||
|
|
@ -232,7 +232,7 @@ namespace Server
|
|||
AddImage(10, 8, 113);
|
||||
AddImage(360, 8, 113);
|
||||
|
||||
string title =
|
||||
var title =
|
||||
$"<BASEFONT COLOR=#FF2F4F4F><CENTER>BANK OF {User.RawName.ToUpper()}</CENTER>";
|
||||
|
||||
AddHtml(40, 15, 320, 20, title);
|
||||
|
|
@ -247,7 +247,7 @@ namespace Server
|
|||
|
||||
AddBackground(210, 60, 175, 20, 9300);
|
||||
AddBackground(215, 45, 165, 30, 9350);
|
||||
AddTextEntry(225, 50, 145, 20, 0, 0, _Plat.ToString(), User.Account.TotalPlat.ToString().Length);
|
||||
AddTextEntry(225, 50, 145, 20, 0, 0, m_Plat.ToString(), User.Account.TotalPlat.ToString().Length);
|
||||
|
||||
// Gold Row
|
||||
AddBackground(15, 100, 175, 20, 9300);
|
||||
|
|
@ -259,7 +259,7 @@ namespace Server
|
|||
|
||||
AddBackground(210, 100, 175, 20, 9300);
|
||||
AddBackground(215, 85, 165, 30, 9350);
|
||||
AddTextEntry(225, 90, 145, 20, 0, 1, _Gold.ToString(), User.Account.TotalGold.ToString().Length);
|
||||
AddTextEntry(225, 90, 145, 20, 0, 1, m_Gold.ToString(), User.Account.TotalGold.ToString().Length);
|
||||
|
||||
// Buttons
|
||||
AddButton(20, 128, 12006, 12007, (int)Buttons.Close);
|
||||
|
|
@ -282,58 +282,58 @@ namespace Server
|
|||
case Buttons.Close:
|
||||
break;
|
||||
case Buttons.Clear:
|
||||
{
|
||||
_Plat = _Gold = 0;
|
||||
refresh = true;
|
||||
}
|
||||
{
|
||||
m_Plat = m_Gold = 0;
|
||||
refresh = true;
|
||||
}
|
||||
break;
|
||||
case Buttons.Accept:
|
||||
{
|
||||
string platText = info.GetTextEntry(0).Text;
|
||||
string goldText = info.GetTextEntry(1).Text;
|
||||
{
|
||||
var platText = info.GetTextEntry(0).Text;
|
||||
var goldText = info.GetTextEntry(1).Text;
|
||||
|
||||
if (!int.TryParse(platText, out _Plat))
|
||||
{
|
||||
User.SendMessage("That is not a valid amount of platinum.");
|
||||
refresh = true;
|
||||
}
|
||||
else if (!int.TryParse(goldText, out _Gold))
|
||||
{
|
||||
User.SendMessage("That is not a valid amount of gold.");
|
||||
refresh = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int totalPlat = User.Account.TotalPlat;
|
||||
int totalGold = User.Account.TotalGold;
|
||||
|
||||
if (totalPlat < _Plat || totalGold < _Gold)
|
||||
if (!int.TryParse(platText, out m_Plat))
|
||||
{
|
||||
_Plat = User.Account.TotalPlat;
|
||||
_Gold = User.Account.TotalGold;
|
||||
User.SendMessage("You do not have that much currency.");
|
||||
User.SendMessage("That is not a valid amount of platinum.");
|
||||
refresh = true;
|
||||
}
|
||||
else if (!int.TryParse(goldText, out m_Gold))
|
||||
{
|
||||
User.SendMessage("That is not a valid amount of gold.");
|
||||
refresh = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Plat = _Plat;
|
||||
Check.Gold = _Gold;
|
||||
updated = true;
|
||||
var totalPlat = User.Account.TotalPlat;
|
||||
var totalGold = User.Account.TotalGold;
|
||||
|
||||
if (totalPlat < m_Plat || totalGold < m_Gold)
|
||||
{
|
||||
m_Plat = User.Account.TotalPlat;
|
||||
m_Gold = User.Account.TotalGold;
|
||||
User.SendMessage("You do not have that much currency.");
|
||||
refresh = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Plat = m_Plat;
|
||||
Check.Gold = m_Gold;
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Buttons.AllPlat:
|
||||
{
|
||||
_Plat = User.Account.TotalPlat;
|
||||
refresh = true;
|
||||
}
|
||||
{
|
||||
m_Plat = User.Account.TotalPlat;
|
||||
refresh = true;
|
||||
}
|
||||
break;
|
||||
case Buttons.AllGold:
|
||||
{
|
||||
_Gold = User.Account.TotalGold;
|
||||
refresh = true;
|
||||
}
|
||||
{
|
||||
m_Gold = User.Account.TotalGold;
|
||||
refresh = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,28 +32,28 @@ namespace Server
|
|||
|
||||
protected BaseHairInfo(IGenericReader reader)
|
||||
{
|
||||
int version = reader.ReadInt();
|
||||
var version = reader.ReadInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
ItemID = reader.ReadInt();
|
||||
Hue = reader.ReadInt();
|
||||
break;
|
||||
}
|
||||
{
|
||||
ItemID = reader.ReadInt();
|
||||
Hue = reader.ReadInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int ItemID{ get; set; }
|
||||
public int ItemID { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int Hue{ get; set; }
|
||||
public int Hue { get; set; }
|
||||
|
||||
public virtual void Serialize(IGenericWriter writer)
|
||||
{
|
||||
writer.Write(0); //version
|
||||
writer.Write(0); // version
|
||||
writer.Write(ItemID);
|
||||
writer.Write(Hue);
|
||||
}
|
||||
|
|
@ -106,14 +106,14 @@ namespace Server
|
|||
public HairEquipUpdate(Mobile parent)
|
||||
: base(0x2E, 15)
|
||||
{
|
||||
int hue = parent.SolidHueOverride >= 0 ? parent.SolidHueOverride : parent.HairHue;
|
||||
var hue = parent.SolidHueOverride >= 0 ? parent.SolidHueOverride : parent.HairHue;
|
||||
|
||||
m_Stream.Write(HairInfo.FakeSerial(parent));
|
||||
m_Stream.Write((short)parent.HairItemID);
|
||||
m_Stream.Write((byte)0);
|
||||
m_Stream.Write((byte)Layer.Hair);
|
||||
m_Stream.Write(parent.Serial);
|
||||
m_Stream.Write((short)hue);
|
||||
Stream.Write(HairInfo.FakeSerial(parent));
|
||||
Stream.Write((short)parent.HairItemID);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)Layer.Hair);
|
||||
Stream.Write(parent.Serial);
|
||||
Stream.Write((short)hue);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,14 +122,14 @@ namespace Server
|
|||
public FacialHairEquipUpdate(Mobile parent)
|
||||
: base(0x2E, 15)
|
||||
{
|
||||
int hue = parent.SolidHueOverride >= 0 ? parent.SolidHueOverride : parent.FacialHairHue;
|
||||
var hue = parent.SolidHueOverride >= 0 ? parent.SolidHueOverride : parent.FacialHairHue;
|
||||
|
||||
m_Stream.Write(FacialHairInfo.FakeSerial(parent));
|
||||
m_Stream.Write((short)parent.FacialHairItemID);
|
||||
m_Stream.Write((byte)0);
|
||||
m_Stream.Write((byte)Layer.FacialHair);
|
||||
m_Stream.Write(parent.Serial);
|
||||
m_Stream.Write((short)hue);
|
||||
Stream.Write(FacialHairInfo.FakeSerial(parent));
|
||||
Stream.Write((short)parent.FacialHairItemID);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)Layer.FacialHair);
|
||||
Stream.Write(parent.Serial);
|
||||
Stream.Write((short)hue);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ namespace Server
|
|||
public RemoveHair(Mobile parent)
|
||||
: base(0x1D, 5)
|
||||
{
|
||||
m_Stream.Write(HairInfo.FakeSerial(parent));
|
||||
Stream.Write(HairInfo.FakeSerial(parent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ namespace Server
|
|||
public RemoveFacialHair(Mobile parent)
|
||||
: base(0x1D, 5)
|
||||
{
|
||||
m_Stream.Write(FacialHairInfo.FakeSerial(parent));
|
||||
Stream.Write(FacialHairInfo.FakeSerial(parent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
|
@ -13,7 +12,7 @@ namespace Server.Json
|
|||
throw new JsonException("Point3d must be an array of x, y, z");
|
||||
|
||||
var data = new int[3];
|
||||
int count = 0;
|
||||
var count = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
|
@ -35,6 +34,7 @@ namespace Server.Json
|
|||
|
||||
return new Point3D(data[0], data[1], data[2]);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Point3D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Server
|
|||
{
|
||||
public class KeywordList
|
||||
{
|
||||
private static readonly int[] m_EmptyInts = new int[0];
|
||||
private static readonly int[] m_EmptyInts = System.Array.Empty<int>();
|
||||
private int[] m_Keywords;
|
||||
|
||||
public KeywordList()
|
||||
|
|
@ -31,13 +31,13 @@ namespace Server
|
|||
Count = 0;
|
||||
}
|
||||
|
||||
public int Count{ get; private set; }
|
||||
public int Count { get; private set; }
|
||||
|
||||
public bool Contains(int keyword)
|
||||
{
|
||||
bool contains = false;
|
||||
var contains = false;
|
||||
|
||||
for (int i = 0; !contains && i < Count; ++i)
|
||||
for (var i = 0; !contains && i < Count; ++i)
|
||||
contains = keyword == m_Keywords[i];
|
||||
|
||||
return contains;
|
||||
|
|
@ -47,10 +47,10 @@ namespace Server
|
|||
{
|
||||
if (Count + 1 > m_Keywords.Length)
|
||||
{
|
||||
int[] old = m_Keywords;
|
||||
var old = m_Keywords;
|
||||
m_Keywords = new int[old.Length * 2];
|
||||
|
||||
for (int i = 0; i < old.Length; ++i)
|
||||
for (var i = 0; i < old.Length; ++i)
|
||||
m_Keywords[i] = old[i];
|
||||
}
|
||||
|
||||
|
|
@ -62,9 +62,9 @@ namespace Server
|
|||
if (Count == 0)
|
||||
return m_EmptyInts;
|
||||
|
||||
int[] keywords = new int[Count];
|
||||
var keywords = new int[Count];
|
||||
|
||||
for (int i = 0; i < Count; ++i)
|
||||
for (var i = 0; i < Count; ++i)
|
||||
keywords[i] = m_Keywords[i];
|
||||
|
||||
Count = 0;
|
||||
|
|
@ -72,4 +72,4 @@ namespace Server
|
|||
return keywords;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: Layer.cs - Created: 2019/03/15 - Updated: 2020/01/19 *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: LightType.cs - Created: 2019/03/15 - Updated: 2020/01/19 *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -64,12 +64,12 @@ namespace Server
|
|||
* enabling the usage of DateTime.UtcNow instead.
|
||||
*/
|
||||
|
||||
private static readonly bool _HighRes = Stopwatch.IsHighResolution;
|
||||
private static readonly bool m_HighRes = Stopwatch.IsHighResolution;
|
||||
|
||||
private static readonly double _HighFrequency = 1000.0 / Stopwatch.Frequency;
|
||||
private static readonly double _LowFrequency = 1000.0 / TimeSpan.TicksPerSecond;
|
||||
private static readonly double m_HighFrequency = 1000.0 / Stopwatch.Frequency;
|
||||
private static readonly double m_LowFrequency = 1000.0 / TimeSpan.TicksPerSecond;
|
||||
|
||||
private static bool _UseHRT;
|
||||
private static bool m_UseHRT;
|
||||
|
||||
public static readonly bool Is64Bit = Environment.Is64BitProcess;
|
||||
internal static ConsoleEventHandler m_ConsoleEventHandler;
|
||||
|
|
@ -111,22 +111,22 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public static bool Service{ get; private set; }
|
||||
public static bool Service { get; private set; }
|
||||
|
||||
public static bool Debug { get; private set; }
|
||||
|
||||
internal static bool HaltOnWarning{ get; private set; }
|
||||
internal static bool HaltOnWarning { get; private set; }
|
||||
|
||||
public static Assembly Assembly{ get; set; }
|
||||
public static Assembly Assembly { get; set; }
|
||||
|
||||
public static Version Version => Assembly.GetName().Version;
|
||||
public static Process Process{ get; private set; }
|
||||
public static Process Process { get; private set; }
|
||||
|
||||
public static Thread Thread{ get; private set; }
|
||||
public static Thread Thread { get; private set; }
|
||||
|
||||
public static MultiTextWriter MultiConsoleOut{ get; private set; }
|
||||
public static MultiTextWriter MultiConsoleOut { get; private set; }
|
||||
|
||||
public static bool UsingHighResolutionTiming => _UseHRT && _HighRes && !Unix;
|
||||
public static bool UsingHighResolutionTiming => m_UseHRT && m_HighRes && !Unix;
|
||||
|
||||
public static long TickCount => (long)Ticks;
|
||||
|
||||
|
|
@ -134,15 +134,15 @@ namespace Server
|
|||
{
|
||||
get
|
||||
{
|
||||
if (_UseHRT && _HighRes && !Unix) return Stopwatch.GetTimestamp() * _HighFrequency;
|
||||
if (m_UseHRT && m_HighRes && !Unix) return Stopwatch.GetTimestamp() * m_HighFrequency;
|
||||
|
||||
return DateTime.UtcNow.Ticks * _LowFrequency;
|
||||
return DateTime.UtcNow.Ticks * m_LowFrequency;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool MultiProcessor{ get; private set; }
|
||||
public static bool MultiProcessor { get; private set; }
|
||||
|
||||
public static int ProcessorCount{ get; private set; }
|
||||
public static int ProcessorCount { get; private set; }
|
||||
|
||||
public static bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
public static bool IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
|
|
@ -173,7 +173,7 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public static bool Closing{ get; private set; }
|
||||
public static bool Closing { get; private set; }
|
||||
|
||||
public static float CyclesPerSecond => m_CyclesPerSecond[(m_CycleIndex - 1) % m_CyclesPerSecond.Length];
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ namespace Server
|
|||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (Debug)
|
||||
Utility.Separate(sb, "-debug", " ");
|
||||
|
|
@ -200,30 +200,30 @@ namespace Server
|
|||
if (HaltOnWarning)
|
||||
Utility.Separate(sb, "-haltonwarning", " ");
|
||||
|
||||
if (_UseHRT)
|
||||
if (m_UseHRT)
|
||||
Utility.Separate(sb, "-usehrt", " ");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static int GlobalUpdateRange{ get; set; } = 18;
|
||||
public static int GlobalUpdateRange { get; set; } = 18;
|
||||
|
||||
public static int GlobalMaxUpdateRange{ get; set; } = 24;
|
||||
public static int GlobalMaxUpdateRange { get; set; } = 24;
|
||||
|
||||
public static int ScriptItems => m_ItemCount;
|
||||
public static int ScriptMobiles => m_MobileCount;
|
||||
|
||||
public static string FindDataFile(string path)
|
||||
{
|
||||
Configuration config = Configuration.Instance;
|
||||
var config = Configuration.Instance;
|
||||
if (config.DataDirectories.Count == 0)
|
||||
throw new InvalidOperationException(
|
||||
"Attempted to FindDataFile before DataDirectories list has been filled.");
|
||||
|
||||
string fullPath = null;
|
||||
|
||||
foreach (string p in config.DataDirectories)
|
||||
foreach (var p in config.DataDirectories)
|
||||
{
|
||||
fullPath = Path.Combine(p, path);
|
||||
|
||||
|
|
@ -247,11 +247,11 @@ namespace Server
|
|||
{
|
||||
m_Crashed = true;
|
||||
|
||||
bool close = false;
|
||||
var close = false;
|
||||
|
||||
try
|
||||
{
|
||||
ServerCrashedEventArgs args = new ServerCrashedEventArgs(e.ExceptionObject as Exception);
|
||||
var args = new ServerCrashedEventArgs(e.ExceptionObject as Exception);
|
||||
|
||||
EventSink.InvokeServerCrashed(args);
|
||||
|
||||
|
|
@ -283,10 +283,10 @@ namespace Server
|
|||
|
||||
private static bool OnConsoleEvent(ConsoleEventType type)
|
||||
{
|
||||
if (World.Saving || Service && type == ConsoleEventType.CTRL_LOGOFF_EVENT)
|
||||
if (World.Saving || (Service && type == ConsoleEventType.CTRL_LOGOFF_EVENT))
|
||||
return true;
|
||||
|
||||
Kill(); //Kill -> HandleClosed will handle waiting for the completion of flushing to disk
|
||||
Kill(); // Kill -> HandleClosed will handle waiting for the completion of flushing to disk
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -335,7 +335,7 @@ namespace Server
|
|||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
|
||||
|
||||
foreach (string a in args)
|
||||
foreach (var a in args)
|
||||
if (Insensitive.Equals(a, "-debug"))
|
||||
Debug = true;
|
||||
else if (Insensitive.Equals(a, "-service"))
|
||||
|
|
@ -347,7 +347,7 @@ namespace Server
|
|||
else if (Insensitive.Equals(a, "-haltonwarning"))
|
||||
HaltOnWarning = true;
|
||||
else if (Insensitive.Equals(a, "-usehrt"))
|
||||
_UseHRT = true;
|
||||
m_UseHRT = true;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -378,32 +378,32 @@ namespace Server
|
|||
if (BaseDirectory.Length > 0)
|
||||
Directory.SetCurrentDirectory(BaseDirectory);
|
||||
|
||||
|
||||
Version ver = Assembly.GetName().Version;
|
||||
var ver = Assembly.GetName().Version;
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
// Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
|
||||
Console.WriteLine("ModernUO - [https://github.com/kamronbatman/ModernUO] Version {0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build,
|
||||
Console.WriteLine("ModernUO - [https://github.com/kamronbatman/ModernUO] Version {0}.{1}.{2}.{3}", ver.Major,
|
||||
ver.Minor, ver.Build,
|
||||
ver.Revision);
|
||||
Console.WriteLine("Core: Running on {0}", RuntimeInformation.FrameworkDescription);
|
||||
Console.ResetColor();
|
||||
Console.WriteLine();
|
||||
|
||||
Configuration config = Configuration.Instance;
|
||||
foreach (string dir in config.DataDirectories.Where(dir => !Directory.Exists(dir)))
|
||||
var config = Configuration.Instance;
|
||||
foreach (var dir in config.DataDirectories.Where(dir => !Directory.Exists(dir)))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
Console.WriteLine("Core: Config directory {0} does not exist.", dir);
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
Timer.TimerThread ttObj = new Timer.TimerThread();
|
||||
var ttObj = new Timer.TimerThread();
|
||||
timerThread = new Thread(ttObj.TimerMain)
|
||||
{
|
||||
Name = "Timer Thread"
|
||||
};
|
||||
|
||||
string s = Arguments;
|
||||
var s = Arguments;
|
||||
|
||||
if (s.Length > 0)
|
||||
Console.WriteLine("Core: Running with arguments: {0}", s);
|
||||
|
|
@ -426,7 +426,7 @@ namespace Server
|
|||
if (GCSettings.IsServerGC)
|
||||
Console.WriteLine("Core: Server garbage collection mode enabled");
|
||||
|
||||
if (_UseHRT)
|
||||
if (m_UseHRT)
|
||||
Console.WriteLine("Core: Requested high resolution timing ({0})",
|
||||
UsingHighResolutionTiming ? "Supported" : "Unsupported");
|
||||
|
||||
|
|
@ -447,13 +447,13 @@ namespace Server
|
|||
|
||||
timerThread.Start();
|
||||
|
||||
foreach (Map m in Map.AllMaps)
|
||||
foreach (var m in Map.AllMaps)
|
||||
m.Tiles.Force();
|
||||
|
||||
EventSink.InvokeServerStarted();
|
||||
|
||||
// Start net socket server
|
||||
var host = TcpServer.CreateWebHostBuilder(new string[0]).Build();
|
||||
var host = TcpServer.CreateWebHostBuilder().Build();
|
||||
var life = host.Services.GetRequiredService<IHostApplicationLifetime>();
|
||||
life.ApplicationStopping.Register(() => { Kill(); });
|
||||
|
||||
|
|
@ -464,7 +464,7 @@ namespace Server
|
|||
{
|
||||
try
|
||||
{
|
||||
long last = TickCount;
|
||||
var last = TickCount;
|
||||
|
||||
const int sampleInterval = 100;
|
||||
const float ticksPerSecond = 1000.0f * sampleInterval;
|
||||
|
|
@ -477,8 +477,7 @@ namespace Server
|
|||
|
||||
Task.WaitAll(
|
||||
Task.Run(Mobile.ProcessDeltaQueue),
|
||||
Task.Run(Item.ProcessDeltaQueue)
|
||||
);
|
||||
Task.Run(Item.ProcessDeltaQueue));
|
||||
|
||||
Timer.Slice();
|
||||
messagePumpService.DoWork();
|
||||
|
|
@ -490,7 +489,7 @@ namespace Server
|
|||
if (sample++ % sampleInterval != 0)
|
||||
continue;
|
||||
|
||||
long now = TickCount;
|
||||
var now = TickCount;
|
||||
m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] = ticksPerSecond / (now - last);
|
||||
last = now;
|
||||
}
|
||||
|
|
@ -506,16 +505,16 @@ namespace Server
|
|||
m_ItemCount = 0;
|
||||
m_MobileCount = 0;
|
||||
|
||||
Assembly ca = Assembly.GetCallingAssembly();
|
||||
var ca = Assembly.GetCallingAssembly();
|
||||
|
||||
VerifySerialization(ca);
|
||||
|
||||
foreach (Assembly a in AssemblyHandler.Assemblies.Where(a => a != ca)) VerifySerialization(a);
|
||||
foreach (var a in AssemblyHandler.Assemblies.Where(a => a != ca)) VerifySerialization(a);
|
||||
}
|
||||
|
||||
private static void VerifyType(Type t)
|
||||
{
|
||||
bool isItem = t.IsSubclassOf(typeof(Item));
|
||||
var isItem = t.IsSubclassOf(typeof(Item));
|
||||
|
||||
if (!isItem && !t.IsSubclassOf(typeof(Mobile))) return;
|
||||
|
||||
|
|
@ -587,9 +586,7 @@ namespace Server
|
|||
internal static extern bool SetConsoleCtrlHandler(ConsoleEventHandler callback, bool add);
|
||||
}
|
||||
|
||||
#region Expansions
|
||||
|
||||
public static Expansion Expansion{ get; set; }
|
||||
public static Expansion Expansion { get; set; }
|
||||
|
||||
public static bool T2A => Expansion >= Expansion.T2A;
|
||||
|
||||
|
|
@ -612,45 +609,43 @@ namespace Server
|
|||
public static bool TOL => Expansion >= Expansion.TOL;
|
||||
|
||||
public static bool EJ => Expansion >= Expansion.EJ;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class FileLogger : TextWriter
|
||||
{
|
||||
public const string DateFormat = "[MMMM dd hh:mm:ss.f tt]: ";
|
||||
|
||||
private bool _NewLine;
|
||||
private bool m_NewLine;
|
||||
|
||||
public FileLogger(string file, bool append = false)
|
||||
{
|
||||
FileName = file;
|
||||
|
||||
using (
|
||||
StreamWriter writer =
|
||||
var writer =
|
||||
new StreamWriter(
|
||||
new FileStream(FileName, append ? FileMode.Append : FileMode.Create, FileAccess.Write,
|
||||
FileShare.Read)))
|
||||
{
|
||||
writer.WriteLine(">>>Logging started on {0}.", DateTime.UtcNow.ToString("f"));
|
||||
//f = Tuesday, April 10, 2001 3:51 PM
|
||||
// f = Tuesday, April 10, 2001 3:51 PM
|
||||
}
|
||||
|
||||
_NewLine = true;
|
||||
m_NewLine = true;
|
||||
}
|
||||
|
||||
public string FileName{ get; }
|
||||
public string FileName { get; }
|
||||
|
||||
public override Encoding Encoding => Encoding.Default;
|
||||
|
||||
public override void Write(char ch)
|
||||
{
|
||||
using StreamWriter writer =
|
||||
using var writer =
|
||||
new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read));
|
||||
if (_NewLine)
|
||||
if (m_NewLine)
|
||||
{
|
||||
writer.Write(DateTime.UtcNow.ToString(DateFormat));
|
||||
_NewLine = false;
|
||||
m_NewLine = false;
|
||||
}
|
||||
|
||||
writer.Write(ch);
|
||||
|
|
@ -658,12 +653,12 @@ namespace Server
|
|||
|
||||
public override void Write(string str)
|
||||
{
|
||||
using StreamWriter writer =
|
||||
using var writer =
|
||||
new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read));
|
||||
if (_NewLine)
|
||||
if (m_NewLine)
|
||||
{
|
||||
writer.Write(DateTime.UtcNow.ToString(DateFormat));
|
||||
_NewLine = false;
|
||||
m_NewLine = false;
|
||||
}
|
||||
|
||||
writer.Write(str);
|
||||
|
|
@ -671,46 +666,46 @@ namespace Server
|
|||
|
||||
public override void WriteLine(string line)
|
||||
{
|
||||
using StreamWriter writer =
|
||||
using var writer =
|
||||
new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read));
|
||||
if (_NewLine) writer.Write(DateTime.UtcNow.ToString(DateFormat));
|
||||
if (m_NewLine) writer.Write(DateTime.UtcNow.ToString(DateFormat));
|
||||
|
||||
writer.WriteLine(line);
|
||||
_NewLine = true;
|
||||
m_NewLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class MultiTextWriter : TextWriter
|
||||
{
|
||||
private readonly List<TextWriter> _Streams;
|
||||
private readonly List<TextWriter> m_Streams;
|
||||
|
||||
public MultiTextWriter(params TextWriter[] streams)
|
||||
{
|
||||
_Streams = new List<TextWriter>(streams);
|
||||
m_Streams = new List<TextWriter>(streams);
|
||||
|
||||
if (_Streams.Count < 0) throw new ArgumentException("You must specify at least one stream.");
|
||||
if (m_Streams.Count < 0) throw new ArgumentException("You must specify at least one stream.");
|
||||
}
|
||||
|
||||
public override Encoding Encoding => Encoding.Default;
|
||||
|
||||
public void Add(TextWriter tw)
|
||||
{
|
||||
_Streams.Add(tw);
|
||||
m_Streams.Add(tw);
|
||||
}
|
||||
|
||||
public void Remove(TextWriter tw)
|
||||
{
|
||||
_Streams.Remove(tw);
|
||||
m_Streams.Remove(tw);
|
||||
}
|
||||
|
||||
public override void Write(char ch)
|
||||
{
|
||||
foreach (TextWriter t in _Streams) t.Write(ch);
|
||||
foreach (var t in m_Streams) t.Write(ch);
|
||||
}
|
||||
|
||||
public override void WriteLine(string line)
|
||||
{
|
||||
foreach (TextWriter t in _Streams) t.WriteLine(line);
|
||||
foreach (var t in m_Streams) t.WriteLine(line);
|
||||
}
|
||||
|
||||
public override void WriteLine(string line, params object[] args)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -24,10 +24,10 @@ namespace Server.Menus
|
|||
{
|
||||
public interface IMenu
|
||||
{
|
||||
int Serial{ get; }
|
||||
int EntryLength{ get; }
|
||||
int Serial { get; }
|
||||
int EntryLength { get; }
|
||||
void SendTo(NetState state);
|
||||
void OnCancel(NetState state);
|
||||
void OnResponse(NetState state, int index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,16 @@ namespace Server.Menus.ItemLists
|
|||
Hue = hue;
|
||||
}
|
||||
|
||||
public string Name{ get; }
|
||||
public string Name { get; }
|
||||
|
||||
public int ItemID{ get; }
|
||||
public int ItemID { get; }
|
||||
|
||||
public int Hue{ get; }
|
||||
public int Hue { get; }
|
||||
}
|
||||
|
||||
public class ItemListMenu : IMenu
|
||||
{
|
||||
private static int m_NextSerial;
|
||||
private readonly int m_Serial;
|
||||
|
||||
public ItemListMenu(string question, ItemListEntry[] entries)
|
||||
{
|
||||
|
|
@ -50,20 +49,20 @@ namespace Server.Menus.ItemLists
|
|||
|
||||
do
|
||||
{
|
||||
m_Serial = m_NextSerial++;
|
||||
m_Serial &= 0x7FFFFFFF;
|
||||
} while (m_Serial == 0);
|
||||
Serial = m_NextSerial++;
|
||||
Serial &= 0x7FFFFFFF;
|
||||
} while (Serial == 0);
|
||||
|
||||
m_Serial = (int)((uint)m_Serial | 0x80000000);
|
||||
Serial = (int)((uint)Serial | 0x80000000);
|
||||
}
|
||||
|
||||
public string Question{ get; }
|
||||
public string Question { get; }
|
||||
|
||||
public ItemListEntry[] Entries{ get; set; }
|
||||
public ItemListEntry[] Entries { get; set; }
|
||||
|
||||
int IMenu.Serial => m_Serial;
|
||||
public int Serial { get; }
|
||||
|
||||
int IMenu.EntryLength => Entries.Length;
|
||||
public int EntryLength => Entries.Length;
|
||||
|
||||
public virtual void OnCancel(NetState state)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ namespace Server.Menus.Questions
|
|||
public class QuestionMenu : IMenu
|
||||
{
|
||||
private static int m_NextSerial;
|
||||
private readonly int m_Serial;
|
||||
|
||||
public QuestionMenu(string question, string[] answers)
|
||||
{
|
||||
|
|
@ -34,18 +33,18 @@ namespace Server.Menus.Questions
|
|||
|
||||
do
|
||||
{
|
||||
m_Serial = ++m_NextSerial;
|
||||
m_Serial &= 0x7FFFFFFF;
|
||||
} while (m_Serial == 0);
|
||||
Serial = ++m_NextSerial;
|
||||
Serial &= 0x7FFFFFFF;
|
||||
} while (Serial == 0);
|
||||
}
|
||||
|
||||
public string Question{ get; set; }
|
||||
public string Question { get; set; }
|
||||
|
||||
public string[] Answers{ get; }
|
||||
public string[] Answers { get; }
|
||||
|
||||
int IMenu.Serial => m_Serial;
|
||||
public int Serial { get; }
|
||||
|
||||
int IMenu.EntryLength => Answers.Length;
|
||||
public int EntryLength => Answers.Length;
|
||||
|
||||
public virtual void OnCancel(NetState state)
|
||||
{
|
||||
|
|
@ -61,4 +60,4 @@ namespace Server.Menus.Questions
|
|||
state.Send(new DisplayQuestionMenu(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
34
Projects/Server/Mobiles/IMount.cs
Normal file
34
Projects/Server/Mobiles/IMount.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: IMount.cs *
|
||||
* Created: 2020/04/25 - Updated: 2020/04/25 *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
namespace Server.Mobiles
|
||||
{
|
||||
public interface IMount
|
||||
{
|
||||
Mobile Rider { get; set; }
|
||||
void OnRiderDamaged(int amount, Mobile from, bool willKill);
|
||||
}
|
||||
|
||||
public interface IMountItem
|
||||
{
|
||||
IMount Mount { get; }
|
||||
}
|
||||
}
|
||||
33
Projects/Server/Mobiles/IVendor.cs
Normal file
33
Projects/Server/Mobiles/IVendor.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: IVendor.cs *
|
||||
* Created: 2020/04/25 - Updated: 2020/04/25 *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server;
|
||||
|
||||
public interface IVendor
|
||||
{
|
||||
DateTime LastRestock { get; set; }
|
||||
TimeSpan RestockDelay { get; }
|
||||
bool OnBuyItems(Mobile from, List<BuyItemResponse> list);
|
||||
bool OnSellItems(Mobile from, List<SellItemResponse> list);
|
||||
void Restock();
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ namespace Server.Movement
|
|||
{
|
||||
public static class Movement
|
||||
{
|
||||
public static IMovementImpl Impl{ get; set; }
|
||||
public static IMovementImpl Impl { get; set; }
|
||||
|
||||
public static bool CheckMovement(Mobile m, Direction d, out int newZ)
|
||||
{
|
||||
|
|
@ -83,4 +83,4 @@ namespace Server.Movement
|
|||
bool CheckMovement(Mobile m, Direction d, out int newZ);
|
||||
bool CheckMovement(Mobile m, Map map, Point3D loc, Direction d, out int newZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace Server
|
|||
|
||||
static MultiData()
|
||||
{
|
||||
string multiUOPPath = Core.FindDataFile("MultiCollection.uop");
|
||||
var multiUOPPath = Core.FindDataFile("MultiCollection.uop");
|
||||
|
||||
if (File.Exists(multiUOPPath))
|
||||
{
|
||||
|
|
@ -46,8 +46,8 @@ namespace Server
|
|||
return;
|
||||
}
|
||||
|
||||
string idxPath = Core.FindDataFile("multi.idx");
|
||||
string mulPath = Core.FindDataFile("multi.mul");
|
||||
var idxPath = Core.FindDataFile("multi.idx");
|
||||
var mulPath = Core.FindDataFile("multi.mul");
|
||||
|
||||
if (File.Exists(idxPath) && File.Exists(mulPath))
|
||||
{
|
||||
|
|
@ -57,21 +57,21 @@ namespace Server
|
|||
var stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
m_StreamReader = new BinaryReader(stream);
|
||||
|
||||
string vdPath = Core.FindDataFile("verdata.mul");
|
||||
var vdPath = Core.FindDataFile("verdata.mul");
|
||||
|
||||
if (!File.Exists(vdPath)) return;
|
||||
|
||||
using FileStream fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
BinaryReader bin = new BinaryReader(fs);
|
||||
using var fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var bin = new BinaryReader(fs);
|
||||
|
||||
int count = bin.ReadInt32();
|
||||
var count = bin.ReadInt32();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
int file = bin.ReadInt32();
|
||||
int index = bin.ReadInt32();
|
||||
int lookup = bin.ReadInt32();
|
||||
int length = bin.ReadInt32();
|
||||
var file = bin.ReadInt32();
|
||||
var index = bin.ReadInt32();
|
||||
var lookup = bin.ReadInt32();
|
||||
var length = bin.ReadInt32();
|
||||
bin.ReadInt32(); // extra
|
||||
|
||||
if (file == 14 && index >= 0 && lookup >= 0 && length > 0)
|
||||
|
|
@ -87,7 +87,9 @@ namespace Server
|
|||
bin.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Multi data files not found");
|
||||
}
|
||||
}
|
||||
|
||||
public static MultiComponentList GetComponents(int multiID)
|
||||
|
|
@ -109,7 +111,7 @@ namespace Server
|
|||
public static void LoadUOP(string path)
|
||||
{
|
||||
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
BinaryReader streamReader = new BinaryReader(stream);
|
||||
var streamReader = new BinaryReader(stream);
|
||||
|
||||
// Head Information Start
|
||||
if (streamReader.ReadInt32() != 0x0050594D) // Not a UOP Files
|
||||
|
|
@ -122,34 +124,34 @@ namespace Server
|
|||
UOPHash.BuildChunkIDs(out var chunkIds);
|
||||
// Multi ID List Array End
|
||||
|
||||
streamReader.ReadUInt32(); // format timestamp? 0xFD23EC43
|
||||
long startAddress = streamReader.ReadInt64();
|
||||
streamReader.ReadUInt32(); // format timestamp? 0xFD23EC43
|
||||
var startAddress = streamReader.ReadInt64();
|
||||
|
||||
streamReader.ReadInt32();
|
||||
streamReader.ReadInt32();
|
||||
|
||||
stream.Seek(startAddress, SeekOrigin.Begin); // Head Information End
|
||||
stream.Seek(startAddress, SeekOrigin.Begin); // Head Information End
|
||||
|
||||
long nextBlock;
|
||||
|
||||
do
|
||||
{
|
||||
int blockFileCount = streamReader.ReadInt32();
|
||||
var blockFileCount = streamReader.ReadInt32();
|
||||
nextBlock = streamReader.ReadInt64();
|
||||
|
||||
int index = 0;
|
||||
var index = 0;
|
||||
|
||||
do
|
||||
{
|
||||
long offset = streamReader.ReadInt64();
|
||||
var offset = streamReader.ReadInt64();
|
||||
|
||||
int headerSize = streamReader.ReadInt32(); // header length
|
||||
int compressedSize = streamReader.ReadInt32(); // compressed size
|
||||
int decompressedSize = streamReader.ReadInt32(); // decompressed size
|
||||
var headerSize = streamReader.ReadInt32(); // header length
|
||||
var compressedSize = streamReader.ReadInt32(); // compressed size
|
||||
var decompressedSize = streamReader.ReadInt32(); // decompressed size
|
||||
|
||||
ulong filehash = streamReader.ReadUInt64(); // filename hash (HashLittle2)
|
||||
var filehash = streamReader.ReadUInt64(); // filename hash (HashLittle2)
|
||||
streamReader.ReadUInt32();
|
||||
short compressionMethod = streamReader.ReadInt16(); // compression method (0 = none, 1 = zlib)
|
||||
var compressionMethod = streamReader.ReadInt16(); // compression method (0 = none, 1 = zlib)
|
||||
|
||||
index++;
|
||||
|
||||
|
|
@ -158,7 +160,7 @@ namespace Server
|
|||
|
||||
chunkIds.TryGetValue(filehash, out var chunkID);
|
||||
|
||||
long position = stream.Position; // save current position
|
||||
var position = stream.Position; // save current position
|
||||
|
||||
stream.Seek(offset + headerSize, SeekOrigin.Begin);
|
||||
|
||||
|
|
@ -172,15 +174,17 @@ namespace Server
|
|||
if (compressionMethod == 1)
|
||||
{
|
||||
data = new byte[decompressedSize];
|
||||
Compression.Unpack(data, ref decompressedSize, sourceData, compressedSize);
|
||||
NetworkCompression.Unpack(data, ref decompressedSize, sourceData, compressedSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = sourceData;
|
||||
}
|
||||
|
||||
var tileList = new List<MultiTileEntry>();
|
||||
|
||||
// Skip the first 4 bytes
|
||||
BufferReader<byte> reader = new BufferReader<byte>(data);
|
||||
var reader = new BufferReader<byte>(data);
|
||||
|
||||
reader.Advance(4); // ???
|
||||
reader.TryReadLittleEndian(out uint count);
|
||||
|
|
@ -193,7 +197,7 @@ namespace Server
|
|||
reader.TryReadLittleEndian(out short z);
|
||||
reader.TryReadLittleEndian(out ushort flagValue);
|
||||
|
||||
TileFlag tileFlag = flagValue switch
|
||||
var tileFlag = flagValue switch
|
||||
{
|
||||
1 => TileFlag.None,
|
||||
257 => TileFlag.Generic,
|
||||
|
|
@ -209,10 +213,8 @@ namespace Server
|
|||
Components[chunkID] = new MultiComponentList(tileList);
|
||||
|
||||
stream.Seek(position, SeekOrigin.Begin); // back to position
|
||||
}
|
||||
while (index < blockFileCount);
|
||||
}
|
||||
while (stream.Seek(nextBlock, SeekOrigin.Begin) != 0);
|
||||
} while (index < blockFileCount);
|
||||
} while (stream.Seek(nextBlock, SeekOrigin.Begin) != 0);
|
||||
}
|
||||
|
||||
// TODO: Change this to read the file all during load time
|
||||
|
|
@ -222,8 +224,8 @@ namespace Server
|
|||
{
|
||||
m_IndexReader.BaseStream.Seek(multiID * 12, SeekOrigin.Begin);
|
||||
|
||||
int lookup = m_IndexReader.ReadInt32();
|
||||
int length = m_IndexReader.ReadInt32();
|
||||
var lookup = m_IndexReader.ReadInt32();
|
||||
var length = m_IndexReader.ReadInt32();
|
||||
|
||||
if (lookup < 0 || length <= 0)
|
||||
return MultiComponentList.Empty;
|
||||
|
|
@ -241,17 +243,19 @@ namespace Server
|
|||
|
||||
public struct MultiTileEntry
|
||||
{
|
||||
public ushort m_ItemID;
|
||||
public short m_OffsetX, m_OffsetY, m_OffsetZ;
|
||||
public TileFlag m_Flags;
|
||||
public ushort ItemId { get; set; }
|
||||
public short OffsetX { get; set; }
|
||||
public short OffsetY { get; set; }
|
||||
public short OffsetZ { get; set; }
|
||||
public TileFlag Flags { get; set; }
|
||||
|
||||
public MultiTileEntry(ushort itemID, short xOffset, short yOffset, short zOffset, TileFlag flags)
|
||||
{
|
||||
m_ItemID = itemID;
|
||||
m_OffsetX = xOffset;
|
||||
m_OffsetY = yOffset;
|
||||
m_OffsetZ = zOffset;
|
||||
m_Flags = flags;
|
||||
ItemId = itemID;
|
||||
OffsetX = xOffset;
|
||||
OffsetY = yOffset;
|
||||
OffsetZ = zOffset;
|
||||
Flags = flags;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -273,28 +277,28 @@ namespace Server
|
|||
|
||||
Tiles = new StaticTile[Width][][];
|
||||
|
||||
for (int x = 0; x < Width; ++x)
|
||||
for (var x = 0; x < Width; ++x)
|
||||
{
|
||||
Tiles[x] = new StaticTile[Height][];
|
||||
|
||||
for (int y = 0; y < Height; ++y)
|
||||
for (var y = 0; y < Height; ++y)
|
||||
{
|
||||
Tiles[x][y] = new StaticTile[toCopy.Tiles[x][y].Length];
|
||||
|
||||
for (int i = 0; i < Tiles[x][y].Length; ++i)
|
||||
for (var i = 0; i < Tiles[x][y].Length; ++i)
|
||||
Tiles[x][y][i] = toCopy.Tiles[x][y][i];
|
||||
}
|
||||
}
|
||||
|
||||
List = new MultiTileEntry[toCopy.List.Length];
|
||||
|
||||
for (int i = 0; i < List.Length; ++i)
|
||||
for (var i = 0; i < List.Length; ++i)
|
||||
List[i] = toCopy.List[i];
|
||||
}
|
||||
|
||||
public MultiComponentList(IGenericReader reader)
|
||||
{
|
||||
int version = reader.ReadInt();
|
||||
var version = reader.ReadInt();
|
||||
|
||||
m_Min = reader.ReadPoint2D();
|
||||
m_Max = reader.ReadPoint2D();
|
||||
|
|
@ -302,90 +306,90 @@ namespace Server
|
|||
Width = reader.ReadInt();
|
||||
Height = reader.ReadInt();
|
||||
|
||||
int length = reader.ReadInt();
|
||||
var length = reader.ReadInt();
|
||||
|
||||
MultiTileEntry[] allTiles = List = new MultiTileEntry[length];
|
||||
var allTiles = List = new MultiTileEntry[length];
|
||||
|
||||
if (version == 0)
|
||||
for (int i = 0; i < length; ++i)
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
int id = reader.ReadShort();
|
||||
if (id >= 0x4000)
|
||||
id -= 0x4000;
|
||||
|
||||
allTiles[i].m_ItemID = (ushort)id;
|
||||
allTiles[i].m_OffsetX = reader.ReadShort();
|
||||
allTiles[i].m_OffsetY = reader.ReadShort();
|
||||
allTiles[i].m_OffsetZ = reader.ReadShort();
|
||||
allTiles[i].m_Flags = (TileFlag)reader.ReadInt();
|
||||
allTiles[i].ItemId = (ushort)id;
|
||||
allTiles[i].OffsetX = reader.ReadShort();
|
||||
allTiles[i].OffsetY = reader.ReadShort();
|
||||
allTiles[i].OffsetZ = reader.ReadShort();
|
||||
allTiles[i].Flags = (TileFlag)reader.ReadInt();
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < length; ++i)
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
allTiles[i].m_ItemID = reader.ReadUShort();
|
||||
allTiles[i].m_OffsetX = reader.ReadShort();
|
||||
allTiles[i].m_OffsetY = reader.ReadShort();
|
||||
allTiles[i].m_OffsetZ = reader.ReadShort();
|
||||
allTiles[i].m_Flags = (TileFlag)reader.ReadInt();
|
||||
allTiles[i].ItemId = reader.ReadUShort();
|
||||
allTiles[i].OffsetX = reader.ReadShort();
|
||||
allTiles[i].OffsetY = reader.ReadShort();
|
||||
allTiles[i].OffsetZ = reader.ReadShort();
|
||||
allTiles[i].Flags = (TileFlag)reader.ReadInt();
|
||||
}
|
||||
|
||||
TileList[][] tiles = new TileList[Width][];
|
||||
var tiles = new TileList[Width][];
|
||||
Tiles = new StaticTile[Width][][];
|
||||
|
||||
for (int x = 0; x < Width; ++x)
|
||||
for (var x = 0; x < Width; ++x)
|
||||
{
|
||||
tiles[x] = new TileList[Height];
|
||||
Tiles[x] = new StaticTile[Height][];
|
||||
|
||||
for (int y = 0; y < Height; ++y)
|
||||
for (var y = 0; y < Height; ++y)
|
||||
tiles[x][y] = new TileList();
|
||||
}
|
||||
|
||||
for (int i = 0; i < allTiles.Length; ++i)
|
||||
if (i == 0 || allTiles[i].m_Flags != 0)
|
||||
for (var i = 0; i < allTiles.Length; ++i)
|
||||
if (i == 0 || allTiles[i].Flags != 0)
|
||||
{
|
||||
int xOffset = allTiles[i].m_OffsetX + Center.m_X;
|
||||
int yOffset = allTiles[i].m_OffsetY + Center.m_Y;
|
||||
var xOffset = allTiles[i].OffsetX + Center.m_X;
|
||||
var yOffset = allTiles[i].OffsetY + Center.m_Y;
|
||||
|
||||
tiles[xOffset][yOffset].Add(allTiles[i].m_ItemID, (sbyte)allTiles[i].m_OffsetZ);
|
||||
tiles[xOffset][yOffset].Add(allTiles[i].ItemId, (sbyte)allTiles[i].OffsetZ);
|
||||
}
|
||||
|
||||
for (int x = 0; x < Width; ++x)
|
||||
for (int y = 0; y < Height; ++y)
|
||||
Tiles[x][y] = tiles[x][y].ToArray();
|
||||
for (var x = 0; x < Width; ++x)
|
||||
for (var y = 0; y < Height; ++y)
|
||||
Tiles[x][y] = tiles[x][y].ToArray();
|
||||
}
|
||||
|
||||
public MultiComponentList(BinaryReader reader, int count)
|
||||
{
|
||||
MultiTileEntry[] allTiles = List = new MultiTileEntry[count];
|
||||
var allTiles = List = new MultiTileEntry[count];
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
allTiles[i].m_ItemID = reader.ReadUInt16();
|
||||
allTiles[i].m_OffsetX = reader.ReadInt16();
|
||||
allTiles[i].m_OffsetY = reader.ReadInt16();
|
||||
allTiles[i].m_OffsetZ = reader.ReadInt16();
|
||||
allTiles[i].ItemId = reader.ReadUInt16();
|
||||
allTiles[i].OffsetX = reader.ReadInt16();
|
||||
allTiles[i].OffsetY = reader.ReadInt16();
|
||||
allTiles[i].OffsetZ = reader.ReadInt16();
|
||||
|
||||
if (PostHSFormat)
|
||||
allTiles[i].m_Flags = (TileFlag)reader.ReadUInt64();
|
||||
allTiles[i].Flags = (TileFlag)reader.ReadUInt64();
|
||||
else
|
||||
allTiles[i].m_Flags = (TileFlag)reader.ReadUInt32();
|
||||
allTiles[i].Flags = (TileFlag)reader.ReadUInt32();
|
||||
|
||||
MultiTileEntry e = allTiles[i];
|
||||
var e = allTiles[i];
|
||||
|
||||
if (i == 0 || e.m_Flags != 0)
|
||||
if (i == 0 || e.Flags != 0)
|
||||
{
|
||||
if (e.m_OffsetX < m_Min.m_X)
|
||||
m_Min.m_X = e.m_OffsetX;
|
||||
if (e.OffsetX < m_Min.m_X)
|
||||
m_Min.m_X = e.OffsetX;
|
||||
|
||||
if (e.m_OffsetY < m_Min.m_Y)
|
||||
m_Min.m_Y = e.m_OffsetY;
|
||||
if (e.OffsetY < m_Min.m_Y)
|
||||
m_Min.m_Y = e.OffsetY;
|
||||
|
||||
if (e.m_OffsetX > m_Max.m_X)
|
||||
m_Max.m_X = e.m_OffsetX;
|
||||
if (e.OffsetX > m_Max.m_X)
|
||||
m_Max.m_X = e.OffsetX;
|
||||
|
||||
if (e.m_OffsetY > m_Max.m_Y)
|
||||
m_Max.m_Y = e.m_OffsetY;
|
||||
if (e.OffsetY > m_Max.m_Y)
|
||||
m_Max.m_Y = e.OffsetY;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -393,127 +397,127 @@ namespace Server
|
|||
Width = m_Max.m_X - m_Min.m_X + 1;
|
||||
Height = m_Max.m_Y - m_Min.m_Y + 1;
|
||||
|
||||
TileList[][] tiles = new TileList[Width][];
|
||||
var tiles = new TileList[Width][];
|
||||
Tiles = new StaticTile[Width][][];
|
||||
|
||||
for (int x = 0; x < Width; ++x)
|
||||
for (var x = 0; x < Width; ++x)
|
||||
{
|
||||
tiles[x] = new TileList[Height];
|
||||
Tiles[x] = new StaticTile[Height][];
|
||||
|
||||
for (int y = 0; y < Height; ++y)
|
||||
for (var y = 0; y < Height; ++y)
|
||||
tiles[x][y] = new TileList();
|
||||
}
|
||||
|
||||
for (int i = 0; i < allTiles.Length; ++i)
|
||||
if (i == 0 || allTiles[i].m_Flags != 0)
|
||||
for (var i = 0; i < allTiles.Length; ++i)
|
||||
if (i == 0 || allTiles[i].Flags != 0)
|
||||
{
|
||||
int xOffset = allTiles[i].m_OffsetX + Center.m_X;
|
||||
int yOffset = allTiles[i].m_OffsetY + Center.m_Y;
|
||||
var xOffset = allTiles[i].OffsetX + Center.m_X;
|
||||
var yOffset = allTiles[i].OffsetY + Center.m_Y;
|
||||
|
||||
tiles[xOffset][yOffset].Add(allTiles[i].m_ItemID, (sbyte)allTiles[i].m_OffsetZ);
|
||||
tiles[xOffset][yOffset].Add(allTiles[i].ItemId, (sbyte)allTiles[i].OffsetZ);
|
||||
}
|
||||
|
||||
for (int x = 0; x < Width; ++x)
|
||||
for (int y = 0; y < Height; ++y)
|
||||
Tiles[x][y] = tiles[x][y].ToArray();
|
||||
for (var x = 0; x < Width; ++x)
|
||||
for (var y = 0; y < Height; ++y)
|
||||
Tiles[x][y] = tiles[x][y].ToArray();
|
||||
}
|
||||
|
||||
public MultiComponentList(List<MultiTileEntry> list)
|
||||
{
|
||||
var allTiles = List = new MultiTileEntry[list.Count];
|
||||
|
||||
for (int i = 0; i < list.Count; ++i)
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
allTiles[i].m_ItemID = list[i].m_ItemID;
|
||||
allTiles[i].m_OffsetX = list[i].m_OffsetX;
|
||||
allTiles[i].m_OffsetY = list[i].m_OffsetY;
|
||||
allTiles[i].m_OffsetZ = list[i].m_OffsetZ;
|
||||
allTiles[i].ItemId = list[i].ItemId;
|
||||
allTiles[i].OffsetX = list[i].OffsetX;
|
||||
allTiles[i].OffsetY = list[i].OffsetY;
|
||||
allTiles[i].OffsetZ = list[i].OffsetZ;
|
||||
|
||||
allTiles[i].m_Flags = list[i].m_Flags;
|
||||
allTiles[i].Flags = list[i].Flags;
|
||||
|
||||
MultiTileEntry e = allTiles[i];
|
||||
var e = allTiles[i];
|
||||
|
||||
if (i == 0 || e.m_Flags != 0)
|
||||
if (i == 0 || e.Flags != 0)
|
||||
{
|
||||
if (e.m_OffsetX < m_Min.m_X) m_Min.m_X = e.m_OffsetX;
|
||||
if (e.OffsetX < m_Min.m_X) m_Min.m_X = e.OffsetX;
|
||||
|
||||
if (e.m_OffsetY < m_Min.m_Y) m_Min.m_Y = e.m_OffsetY;
|
||||
if (e.OffsetY < m_Min.m_Y) m_Min.m_Y = e.OffsetY;
|
||||
|
||||
if (e.m_OffsetX > m_Max.m_X) m_Max.m_X = e.m_OffsetX;
|
||||
if (e.OffsetX > m_Max.m_X) m_Max.m_X = e.OffsetX;
|
||||
|
||||
if (e.m_OffsetY > m_Max.m_Y) m_Max.m_Y = e.m_OffsetY;
|
||||
if (e.OffsetY > m_Max.m_Y) m_Max.m_Y = e.OffsetY;
|
||||
}
|
||||
}
|
||||
|
||||
Center = new Point2D(-m_Min.m_X, -m_Min.m_Y);
|
||||
Width = (m_Max.m_X - m_Min.m_X) + 1;
|
||||
Height = (m_Max.m_Y - m_Min.m_Y) + 1;
|
||||
Width = m_Max.m_X - m_Min.m_X + 1;
|
||||
Height = m_Max.m_Y - m_Min.m_Y + 1;
|
||||
|
||||
var tiles = new TileList[Width][];
|
||||
Tiles = new StaticTile[Width][][];
|
||||
|
||||
for (int x = 0; x < Width; ++x)
|
||||
for (var x = 0; x < Width; ++x)
|
||||
{
|
||||
tiles[x] = new TileList[Height];
|
||||
Tiles[x] = new StaticTile[Height][];
|
||||
|
||||
for (int y = 0; y < Height; ++y) tiles[x][y] = new TileList();
|
||||
for (var y = 0; y < Height; ++y) tiles[x][y] = new TileList();
|
||||
}
|
||||
|
||||
for (int i = 0; i < allTiles.Length; ++i)
|
||||
if (i == 0 || allTiles[i].m_Flags != 0)
|
||||
for (var i = 0; i < allTiles.Length; ++i)
|
||||
if (i == 0 || allTiles[i].Flags != 0)
|
||||
{
|
||||
int xOffset = allTiles[i].m_OffsetX + Center.m_X;
|
||||
int yOffset = allTiles[i].m_OffsetY + Center.m_Y;
|
||||
int itemID = ((allTiles[i].m_ItemID & TileData.MaxItemValue) | 0x10000);
|
||||
var xOffset = allTiles[i].OffsetX + Center.m_X;
|
||||
var yOffset = allTiles[i].OffsetY + Center.m_Y;
|
||||
var itemID = (allTiles[i].ItemId & TileData.MaxItemValue) | 0x10000;
|
||||
|
||||
tiles[xOffset][yOffset].Add((ushort)itemID, (sbyte)allTiles[i].m_OffsetZ);
|
||||
tiles[xOffset][yOffset].Add((ushort)itemID, (sbyte)allTiles[i].OffsetZ);
|
||||
}
|
||||
|
||||
for (int x = 0; x < Width; ++x)
|
||||
for (int y = 0; y < Height; ++y)
|
||||
Tiles[x][y] = tiles[x][y].ToArray();
|
||||
for (var x = 0; x < Width; ++x)
|
||||
for (var y = 0; y < Height; ++y)
|
||||
Tiles[x][y] = tiles[x][y].ToArray();
|
||||
}
|
||||
|
||||
private MultiComponentList()
|
||||
{
|
||||
Tiles = new StaticTile[0][][];
|
||||
List = new MultiTileEntry[0];
|
||||
Tiles = Array.Empty<StaticTile[][]>();
|
||||
List = Array.Empty<MultiTileEntry>();
|
||||
}
|
||||
|
||||
public static bool PostHSFormat{ get; set; }
|
||||
public static bool PostHSFormat { get; set; }
|
||||
|
||||
public Point2D Min => m_Min;
|
||||
public Point2D Max => m_Max;
|
||||
|
||||
public Point2D Center{ get; }
|
||||
public Point2D Center { get; }
|
||||
|
||||
public int Width{ get; private set; }
|
||||
public int Width { get; private set; }
|
||||
|
||||
public int Height{ get; private set; }
|
||||
public int Height { get; private set; }
|
||||
|
||||
public StaticTile[][][] Tiles{ get; private set; }
|
||||
public StaticTile[][][] Tiles { get; private set; }
|
||||
|
||||
public MultiTileEntry[] List{ get; private set; }
|
||||
public MultiTileEntry[] List { get; private set; }
|
||||
|
||||
public void Add(int itemID, int x, int y, int z)
|
||||
{
|
||||
int vx = x + Center.m_X;
|
||||
int vy = y + Center.m_Y;
|
||||
var vx = x + Center.m_X;
|
||||
var vy = y + Center.m_Y;
|
||||
|
||||
if (vx >= 0 && vx < Width && vy >= 0 && vy < Height)
|
||||
{
|
||||
StaticTile[] oldTiles = Tiles[vx][vy];
|
||||
var oldTiles = Tiles[vx][vy];
|
||||
|
||||
for (int i = oldTiles.Length - 1; i >= 0; --i)
|
||||
for (var i = oldTiles.Length - 1; i >= 0; --i)
|
||||
{
|
||||
ItemData data = TileData.ItemTable[itemID & TileData.MaxItemValue];
|
||||
var data = TileData.ItemTable[itemID & TileData.MaxItemValue];
|
||||
|
||||
if (oldTiles[i].Z == z && oldTiles[i].Height > 0 == data.Height > 0)
|
||||
{
|
||||
bool newIsRoof = (data.Flags & TileFlag.Roof) != 0;
|
||||
bool oldIsRoof =
|
||||
var newIsRoof = (data.Flags & TileFlag.Roof) != 0;
|
||||
var oldIsRoof =
|
||||
(TileData.ItemTable[oldTiles[i].ID & TileData.MaxItemValue].Flags & TileFlag.Roof) != 0;
|
||||
|
||||
if (newIsRoof == oldIsRoof)
|
||||
|
|
@ -523,19 +527,19 @@ namespace Server
|
|||
|
||||
oldTiles = Tiles[vx][vy];
|
||||
|
||||
StaticTile[] newTiles = new StaticTile[oldTiles.Length + 1];
|
||||
var newTiles = new StaticTile[oldTiles.Length + 1];
|
||||
|
||||
for (int i = 0; i < oldTiles.Length; ++i)
|
||||
for (var i = 0; i < oldTiles.Length; ++i)
|
||||
newTiles[i] = oldTiles[i];
|
||||
|
||||
newTiles[oldTiles.Length] = new StaticTile((ushort)itemID, (sbyte)z);
|
||||
|
||||
Tiles[vx][vy] = newTiles;
|
||||
|
||||
MultiTileEntry[] oldList = List;
|
||||
MultiTileEntry[] newList = new MultiTileEntry[oldList.Length + 1];
|
||||
var oldList = List;
|
||||
var newList = new MultiTileEntry[oldList.Length + 1];
|
||||
|
||||
for (int i = 0; i < oldList.Length; ++i)
|
||||
for (var i = 0; i < oldList.Length; ++i)
|
||||
newList[i] = oldList[i];
|
||||
|
||||
newList[oldList.Length] = new MultiTileEntry((ushort)itemID, (short)x, (short)y, (short)z, TileFlag.Background);
|
||||
|
|
@ -558,25 +562,25 @@ namespace Server
|
|||
|
||||
public void RemoveXYZH(int x, int y, int z, int minHeight)
|
||||
{
|
||||
int vx = x + Center.m_X;
|
||||
int vy = y + Center.m_Y;
|
||||
var vx = x + Center.m_X;
|
||||
var vy = y + Center.m_Y;
|
||||
|
||||
if (vx >= 0 && vx < Width && vy >= 0 && vy < Height)
|
||||
{
|
||||
StaticTile[] oldTiles = Tiles[vx][vy];
|
||||
var oldTiles = Tiles[vx][vy];
|
||||
|
||||
for (int i = 0; i < oldTiles.Length; ++i)
|
||||
for (var i = 0; i < oldTiles.Length; ++i)
|
||||
{
|
||||
StaticTile tile = oldTiles[i];
|
||||
var tile = oldTiles[i];
|
||||
|
||||
if (tile.Z == z && tile.Height >= minHeight)
|
||||
{
|
||||
StaticTile[] newTiles = new StaticTile[oldTiles.Length - 1];
|
||||
var newTiles = new StaticTile[oldTiles.Length - 1];
|
||||
|
||||
for (int j = 0; j < i; ++j)
|
||||
for (var j = 0; j < i; ++j)
|
||||
newTiles[j] = oldTiles[j];
|
||||
|
||||
for (int j = i + 1; j < oldTiles.Length; ++j)
|
||||
for (var j = i + 1; j < oldTiles.Length; ++j)
|
||||
newTiles[j - 1] = oldTiles[j];
|
||||
|
||||
Tiles[vx][vy] = newTiles;
|
||||
|
|
@ -585,21 +589,21 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
MultiTileEntry[] oldList = List;
|
||||
var oldList = List;
|
||||
|
||||
for (int i = 0; i < oldList.Length; ++i)
|
||||
for (var i = 0; i < oldList.Length; ++i)
|
||||
{
|
||||
MultiTileEntry tile = oldList[i];
|
||||
var tile = oldList[i];
|
||||
|
||||
if (tile.m_OffsetX == (short)x && tile.m_OffsetY == (short)y && tile.m_OffsetZ == (short)z &&
|
||||
TileData.ItemTable[tile.m_ItemID & TileData.MaxItemValue].Height >= minHeight)
|
||||
if (tile.OffsetX == (short)x && tile.OffsetY == (short)y && tile.OffsetZ == (short)z &&
|
||||
TileData.ItemTable[tile.ItemId & TileData.MaxItemValue].Height >= minHeight)
|
||||
{
|
||||
MultiTileEntry[] newList = new MultiTileEntry[oldList.Length - 1];
|
||||
var newList = new MultiTileEntry[oldList.Length - 1];
|
||||
|
||||
for (int j = 0; j < i; ++j)
|
||||
for (var j = 0; j < i; ++j)
|
||||
newList[j] = oldList[j];
|
||||
|
||||
for (int j = i + 1; j < oldList.Length; ++j)
|
||||
for (var j = i + 1; j < oldList.Length; ++j)
|
||||
newList[j - 1] = oldList[j];
|
||||
|
||||
List = newList;
|
||||
|
|
@ -612,25 +616,25 @@ namespace Server
|
|||
|
||||
public void Remove(int itemID, int x, int y, int z)
|
||||
{
|
||||
int vx = x + Center.m_X;
|
||||
int vy = y + Center.m_Y;
|
||||
var vx = x + Center.m_X;
|
||||
var vy = y + Center.m_Y;
|
||||
|
||||
if (vx >= 0 && vx < Width && vy >= 0 && vy < Height)
|
||||
{
|
||||
StaticTile[] oldTiles = Tiles[vx][vy];
|
||||
var oldTiles = Tiles[vx][vy];
|
||||
|
||||
for (int i = 0; i < oldTiles.Length; ++i)
|
||||
for (var i = 0; i < oldTiles.Length; ++i)
|
||||
{
|
||||
StaticTile tile = oldTiles[i];
|
||||
var tile = oldTiles[i];
|
||||
|
||||
if (tile.ID == itemID && tile.Z == z)
|
||||
{
|
||||
StaticTile[] newTiles = new StaticTile[oldTiles.Length - 1];
|
||||
var newTiles = new StaticTile[oldTiles.Length - 1];
|
||||
|
||||
for (int j = 0; j < i; ++j)
|
||||
for (var j = 0; j < i; ++j)
|
||||
newTiles[j] = oldTiles[j];
|
||||
|
||||
for (int j = i + 1; j < oldTiles.Length; ++j)
|
||||
for (var j = i + 1; j < oldTiles.Length; ++j)
|
||||
newTiles[j - 1] = oldTiles[j];
|
||||
|
||||
Tiles[vx][vy] = newTiles;
|
||||
|
|
@ -639,21 +643,21 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
MultiTileEntry[] oldList = List;
|
||||
var oldList = List;
|
||||
|
||||
for (int i = 0; i < oldList.Length; ++i)
|
||||
for (var i = 0; i < oldList.Length; ++i)
|
||||
{
|
||||
MultiTileEntry tile = oldList[i];
|
||||
var tile = oldList[i];
|
||||
|
||||
if (tile.m_ItemID == itemID && tile.m_OffsetX == (short)x && tile.m_OffsetY == (short)y &&
|
||||
tile.m_OffsetZ == (short)z)
|
||||
if (tile.ItemId == itemID && tile.OffsetX == (short)x && tile.OffsetY == (short)y &&
|
||||
tile.OffsetZ == (short)z)
|
||||
{
|
||||
MultiTileEntry[] newList = new MultiTileEntry[oldList.Length - 1];
|
||||
var newList = new MultiTileEntry[oldList.Length - 1];
|
||||
|
||||
for (int j = 0; j < i; ++j)
|
||||
for (var j = 0; j < i; ++j)
|
||||
newList[j] = oldList[j];
|
||||
|
||||
for (int j = i + 1; j < oldList.Length; ++j)
|
||||
for (var j = i + 1; j < oldList.Length; ++j)
|
||||
newList[j - 1] = oldList[j];
|
||||
|
||||
List = newList;
|
||||
|
|
@ -667,22 +671,22 @@ namespace Server
|
|||
public void Resize(int newWidth, int newHeight)
|
||||
{
|
||||
int oldWidth = Width, oldHeight = Height;
|
||||
StaticTile[][][] oldTiles = Tiles;
|
||||
var oldTiles = Tiles;
|
||||
|
||||
int totalLength = 0;
|
||||
var totalLength = 0;
|
||||
|
||||
StaticTile[][][] newTiles = new StaticTile[newWidth][][];
|
||||
var newTiles = new StaticTile[newWidth][][];
|
||||
|
||||
for (int x = 0; x < newWidth; ++x)
|
||||
for (var x = 0; x < newWidth; ++x)
|
||||
{
|
||||
newTiles[x] = new StaticTile[newHeight][];
|
||||
|
||||
for (int y = 0; y < newHeight; ++y)
|
||||
for (var y = 0; y < newHeight; ++y)
|
||||
{
|
||||
if (x < oldWidth && y < oldHeight)
|
||||
newTiles[x][y] = oldTiles[x][y];
|
||||
else
|
||||
newTiles[x][y] = new StaticTile[0];
|
||||
newTiles[x][y] = Array.Empty<StaticTile>();
|
||||
|
||||
totalLength += newTiles[x][y].Length;
|
||||
}
|
||||
|
|
@ -696,35 +700,35 @@ namespace Server
|
|||
m_Min = Point2D.Zero;
|
||||
m_Max = Point2D.Zero;
|
||||
|
||||
int index = 0;
|
||||
var index = 0;
|
||||
|
||||
for (int x = 0; x < newWidth; ++x)
|
||||
for (int y = 0; y < newHeight; ++y)
|
||||
{
|
||||
StaticTile[] tiles = newTiles[x][y];
|
||||
|
||||
for (int i = 0; i < tiles.Length; ++i)
|
||||
for (var x = 0; x < newWidth; ++x)
|
||||
for (var y = 0; y < newHeight; ++y)
|
||||
{
|
||||
StaticTile tile = tiles[i];
|
||||
var tiles = newTiles[x][y];
|
||||
|
||||
int vx = x - Center.X;
|
||||
int vy = y - Center.Y;
|
||||
for (var i = 0; i < tiles.Length; ++i)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
|
||||
if (vx < m_Min.m_X)
|
||||
m_Min.m_X = vx;
|
||||
var vx = x - Center.X;
|
||||
var vy = y - Center.Y;
|
||||
|
||||
if (vy < m_Min.m_Y)
|
||||
m_Min.m_Y = vy;
|
||||
if (vx < m_Min.m_X)
|
||||
m_Min.m_X = vx;
|
||||
|
||||
if (vx > m_Max.m_X)
|
||||
m_Max.m_X = vx;
|
||||
if (vy < m_Min.m_Y)
|
||||
m_Min.m_Y = vy;
|
||||
|
||||
if (vy > m_Max.m_Y)
|
||||
m_Max.m_Y = vy;
|
||||
if (vx > m_Max.m_X)
|
||||
m_Max.m_X = vx;
|
||||
|
||||
List[index++] = new MultiTileEntry((ushort)tile.ID, (short)vx, (short)vy, (short)tile.Z, TileFlag.Background);
|
||||
if (vy > m_Max.m_Y)
|
||||
m_Max.m_Y = vy;
|
||||
|
||||
List[index++] = new MultiTileEntry((ushort)tile.ID, (short)vx, (short)vy, (short)tile.Z, TileFlag.Background);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(IGenericWriter writer)
|
||||
|
|
@ -740,15 +744,15 @@ namespace Server
|
|||
|
||||
writer.Write(List.Length);
|
||||
|
||||
for (int i = 0; i < List.Length; ++i)
|
||||
for (var i = 0; i < List.Length; ++i)
|
||||
{
|
||||
MultiTileEntry ent = List[i];
|
||||
var ent = List[i];
|
||||
|
||||
writer.Write(ent.m_ItemID);
|
||||
writer.Write(ent.m_OffsetX);
|
||||
writer.Write(ent.m_OffsetY);
|
||||
writer.Write(ent.m_OffsetZ);
|
||||
writer.Write((int)ent.m_Flags);
|
||||
writer.Write(ent.ItemId);
|
||||
writer.Write(ent.OffsetX);
|
||||
writer.Write(ent.OffsetY);
|
||||
writer.Write(ent.OffsetZ);
|
||||
writer.Write((int)ent.Flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -761,18 +765,18 @@ namespace Server
|
|||
|
||||
chunkIds = new Dictionary<ulong, int>();
|
||||
|
||||
for (int i = 0; i < maxId; ++i)
|
||||
for (var i = 0; i < maxId; ++i)
|
||||
chunkIds[HashLittle2($"build/multicollection/{i:000000}.bin")] = i;
|
||||
}
|
||||
|
||||
private static ulong HashLittle2(string s)
|
||||
{
|
||||
int length = s.Length;
|
||||
var length = s.Length;
|
||||
|
||||
uint b, c;
|
||||
uint a = b = c = 0xDEADBEEF + (uint)length;
|
||||
var a = b = c = 0xDEADBEEF + (uint)length;
|
||||
|
||||
int k = 0;
|
||||
var k = 0;
|
||||
|
||||
while (length > 12)
|
||||
{
|
||||
|
|
@ -789,12 +793,24 @@ namespace Server
|
|||
c += (uint)s[k + 10] << 16;
|
||||
c += (uint)s[k + 11] << 24;
|
||||
|
||||
a -= c; a ^= (c << 4) | (c >> 28); c += b;
|
||||
b -= a; b ^= (a << 6) | (a >> 26); a += c;
|
||||
c -= b; c ^= (b << 8) | (b >> 24); b += a;
|
||||
a -= c; a ^= (c << 16) | (c >> 16); c += b;
|
||||
b -= a; b ^= (a << 19) | (a >> 13); a += c;
|
||||
c -= b; c ^= (b << 4) | (b >> 28); b += a;
|
||||
a -= c;
|
||||
a ^= (c << 4) | (c >> 28);
|
||||
c += b;
|
||||
b -= a;
|
||||
b ^= (a << 6) | (a >> 26);
|
||||
a += c;
|
||||
c -= b;
|
||||
c ^= (b << 8) | (b >> 24);
|
||||
b += a;
|
||||
a -= c;
|
||||
a ^= (c << 16) | (c >> 16);
|
||||
c += b;
|
||||
b -= a;
|
||||
b ^= (a << 19) | (a >> 13);
|
||||
a += c;
|
||||
c -= b;
|
||||
c ^= (b << 4) | (b >> 28);
|
||||
b += a;
|
||||
|
||||
length -= 12;
|
||||
k += 12;
|
||||
|
|
@ -804,27 +820,58 @@ namespace Server
|
|||
{
|
||||
switch (length)
|
||||
{
|
||||
case 12: c += (uint)s[k + 11] << 24; goto case 11;
|
||||
case 11: c += (uint)s[k + 10] << 16; goto case 10;
|
||||
case 10: c += (uint)s[k + 9] << 8; goto case 9;
|
||||
case 9: c += s[k + 8]; goto case 8;
|
||||
case 8: b += (uint)s[k + 7] << 24; goto case 7;
|
||||
case 7: b += (uint)s[k + 6] << 16; goto case 6;
|
||||
case 6: b += (uint)s[k + 5] << 8; goto case 5;
|
||||
case 5: b += s[k + 4]; goto case 4;
|
||||
case 4: a += (uint)s[k + 3] << 24; goto case 3;
|
||||
case 3: a += (uint)s[k + 2] << 16; goto case 2;
|
||||
case 2: a += (uint)s[k + 1] << 8; goto case 1;
|
||||
case 1: a += s[k]; break;
|
||||
case 12:
|
||||
c += (uint)s[k + 11] << 24;
|
||||
goto case 11;
|
||||
case 11:
|
||||
c += (uint)s[k + 10] << 16;
|
||||
goto case 10;
|
||||
case 10:
|
||||
c += (uint)s[k + 9] << 8;
|
||||
goto case 9;
|
||||
case 9:
|
||||
c += s[k + 8];
|
||||
goto case 8;
|
||||
case 8:
|
||||
b += (uint)s[k + 7] << 24;
|
||||
goto case 7;
|
||||
case 7:
|
||||
b += (uint)s[k + 6] << 16;
|
||||
goto case 6;
|
||||
case 6:
|
||||
b += (uint)s[k + 5] << 8;
|
||||
goto case 5;
|
||||
case 5:
|
||||
b += s[k + 4];
|
||||
goto case 4;
|
||||
case 4:
|
||||
a += (uint)s[k + 3] << 24;
|
||||
goto case 3;
|
||||
case 3:
|
||||
a += (uint)s[k + 2] << 16;
|
||||
goto case 2;
|
||||
case 2:
|
||||
a += (uint)s[k + 1] << 8;
|
||||
goto case 1;
|
||||
case 1:
|
||||
a += s[k];
|
||||
break;
|
||||
}
|
||||
|
||||
c ^= b; c -= (b << 14) | (b >> 18);
|
||||
a ^= c; a -= (c << 11) | (c >> 21);
|
||||
b ^= a; b -= (a << 25) | (a >> 7);
|
||||
c ^= b; c -= (b << 16) | (b >> 16);
|
||||
a ^= c; a -= (c << 4) | (c >> 28);
|
||||
b ^= a; b -= (a << 14) | (a >> 18);
|
||||
c ^= b; c -= (b << 24) | (b >> 8);
|
||||
c ^= b;
|
||||
c -= (b << 14) | (b >> 18);
|
||||
a ^= c;
|
||||
a -= (c << 11) | (c >> 21);
|
||||
b ^= a;
|
||||
b -= (a << 25) | (a >> 7);
|
||||
c ^= b;
|
||||
c -= (b << 16) | (b >> 16);
|
||||
a ^= c;
|
||||
a -= (c << 4) | (c >> 28);
|
||||
b ^= a;
|
||||
b -= (a << 14) | (a >> 18);
|
||||
c ^= b;
|
||||
c -= (b << 24) | (b >> 8);
|
||||
}
|
||||
|
||||
return ((ulong)b << 32) | c;
|
||||
|
|
|
|||
|
|
@ -36,23 +36,23 @@ namespace Server
|
|||
m_NativeReader = new NativeReaderWin32();
|
||||
}
|
||||
|
||||
public static unsafe void Read(IntPtr ptr, void* buffer, int length)
|
||||
public static unsafe void Read(IntPtr p, void* buffer, int length)
|
||||
{
|
||||
m_NativeReader.Read(ptr, buffer, length);
|
||||
m_NativeReader.Read(p, buffer, length);
|
||||
}
|
||||
}
|
||||
|
||||
public interface INativeReader
|
||||
{
|
||||
unsafe void Read(IntPtr ptr, void* buffer, int length);
|
||||
unsafe void Read(IntPtr p, void* buffer, int length);
|
||||
}
|
||||
|
||||
public sealed class NativeReaderWin32 : INativeReader
|
||||
{
|
||||
public unsafe void Read(IntPtr ptr, void* buffer, int length)
|
||||
public unsafe void Read(IntPtr p, void* buffer, int length)
|
||||
{
|
||||
uint lpNumberOfBytesRead = 0;
|
||||
UnsafeNativeMethods.ReadFile(ptr, buffer, (uint)length, ref lpNumberOfBytesRead, null);
|
||||
UnsafeNativeMethods.ReadFile(p, buffer, (uint)length, ref lpNumberOfBytesRead, null);
|
||||
}
|
||||
|
||||
internal static class UnsafeNativeMethods
|
||||
|
|
@ -68,15 +68,15 @@ namespace Server
|
|||
|
||||
public sealed class NativeReaderUnix : INativeReader
|
||||
{
|
||||
public unsafe void Read(IntPtr ptr, void* buffer, int length)
|
||||
public unsafe void Read(IntPtr p, void* buffer, int length)
|
||||
{
|
||||
UnsafeNativeMethods.read(ptr, buffer, length);
|
||||
_ = UnsafeNativeMethods.read(p, buffer, length);
|
||||
}
|
||||
|
||||
internal static class UnsafeNativeMethods
|
||||
{
|
||||
[DllImport("libc")]
|
||||
internal static extern unsafe int read(IntPtr ptr, void* buffer, int length);
|
||||
internal static extern unsafe int read(IntPtr p, void* buffer, int length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ namespace Server.Network
|
|||
OnReceive = onReceive;
|
||||
}
|
||||
|
||||
public int PacketID{ get; }
|
||||
public int PacketID { get; }
|
||||
|
||||
public OnEncodedPacketReceive OnReceive{ get; }
|
||||
public OnEncodedPacketReceive OnReceive { get; }
|
||||
|
||||
public bool Ingame{ get; }
|
||||
public bool Ingame { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@ namespace Server.Network
|
|||
|
||||
public int ReadInt32() => m_Reader.ReadByte() != 0 ? 0 : m_Reader.ReadInt32();
|
||||
|
||||
public Point3D ReadPoint3D() => m_Reader.ReadByte() != 3 ? Point3D.Zero :
|
||||
new Point3D(m_Reader.ReadInt16(), m_Reader.ReadInt16(), m_Reader.ReadByte());
|
||||
public Point3D ReadPoint3D() => m_Reader.ReadByte() != 3
|
||||
? Point3D.Zero
|
||||
: new Point3D(m_Reader.ReadInt16(), m_Reader.ReadInt16(), m_Reader.ReadByte());
|
||||
|
||||
public string ReadUnicodeStringSafe() => m_Reader.ReadByte() != 2 ? string.Empty :
|
||||
m_Reader.ReadUnicodeStringSafe(m_Reader.ReadUInt16());
|
||||
public string ReadUnicodeStringSafe() =>
|
||||
m_Reader.ReadByte() != 2 ? string.Empty : m_Reader.ReadUnicodeStringSafe(m_Reader.ReadUInt16());
|
||||
|
||||
public string ReadUnicodeString() => m_Reader.ReadByte() != 2 ? string.Empty :
|
||||
m_Reader.ReadUnicodeString(m_Reader.ReadUInt16());
|
||||
public string ReadUnicodeString() =>
|
||||
m_Reader.ReadByte() != 2 ? string.Empty : m_Reader.ReadUnicodeString(m_Reader.ReadUInt16());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: MessagePumpService.cs *
|
||||
* Created: 2020/04/12 - Updated: 2020/04/12 *
|
||||
|
|
@ -42,10 +42,10 @@ namespace Server.Network
|
|||
|
||||
public void DoWork()
|
||||
{
|
||||
int count = 0;
|
||||
var count = 0;
|
||||
while (!m_WorkQueue.IsEmpty && count++ < 250)
|
||||
{
|
||||
if (!m_WorkQueue.TryDequeue(out Work work))
|
||||
if (!m_WorkQueue.TryDequeue(out var work))
|
||||
break;
|
||||
|
||||
work.OnReceive(work.State, new PacketReader(new ReadOnlySequence<byte>(work.MemoryOwner.Memory)));
|
||||
|
|
@ -56,6 +56,7 @@ namespace Server.Network
|
|||
private class Work
|
||||
{
|
||||
public readonly NetState State;
|
||||
|
||||
// TODO: Force dispose?
|
||||
public readonly IMemoryOwner<byte> MemoryOwner;
|
||||
public readonly OnPacketReceive OnReceive;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ using System;
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Pipelines;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
|
@ -202,11 +201,11 @@ namespace Server.Network
|
|||
|
||||
public void ValidateAllTrades()
|
||||
{
|
||||
for (int i = Trades.Count - 1; i >= 0; --i)
|
||||
for (var i = Trades.Count - 1; i >= 0; --i)
|
||||
{
|
||||
if (i >= Trades.Count) continue;
|
||||
|
||||
SecureTrade trade = Trades[i];
|
||||
var trade = Trades[i];
|
||||
|
||||
if (trade.From.Mobile.Deleted || trade.To.Mobile.Deleted || !trade.From.Mobile.Alive ||
|
||||
!trade.To.Mobile.Alive || !trade.From.Mobile.InRange(trade.To.Mobile, 2) ||
|
||||
|
|
@ -216,7 +215,7 @@ namespace Server.Network
|
|||
|
||||
public void CancelAllTrades()
|
||||
{
|
||||
for (int i = Trades.Count - 1; i >= 0; --i)
|
||||
for (var i = Trades.Count - 1; i >= 0; --i)
|
||||
if (i < Trades.Count)
|
||||
Trades[i].Cancel();
|
||||
}
|
||||
|
|
@ -228,9 +227,9 @@ namespace Server.Network
|
|||
|
||||
public SecureTrade FindTrade(Mobile m)
|
||||
{
|
||||
for (int i = 0; i < Trades.Count; ++i)
|
||||
for (var i = 0; i < Trades.Count; ++i)
|
||||
{
|
||||
SecureTrade trade = Trades[i];
|
||||
var trade = Trades[i];
|
||||
|
||||
if (trade.From.Mobile == m || trade.To.Mobile == m) return trade;
|
||||
}
|
||||
|
|
@ -240,12 +239,12 @@ namespace Server.Network
|
|||
|
||||
public SecureTradeContainer FindTradeContainer(Mobile m)
|
||||
{
|
||||
for (int i = 0; i < Trades.Count; ++i)
|
||||
for (var i = 0; i < Trades.Count; ++i)
|
||||
{
|
||||
SecureTrade trade = Trades[i];
|
||||
var trade = Trades[i];
|
||||
|
||||
SecureTradeInfo from = trade.From;
|
||||
SecureTradeInfo to = trade.To;
|
||||
var from = trade.From;
|
||||
var to = trade.To;
|
||||
|
||||
if (from.Mobile == Mobile && to.Mobile == m) return from.Container;
|
||||
|
||||
|
|
@ -257,7 +256,7 @@ namespace Server.Network
|
|||
|
||||
public SecureTradeContainer AddTrade(NetState state)
|
||||
{
|
||||
SecureTrade newTrade = new SecureTrade(Mobile, state.Mobile);
|
||||
var newTrade = new SecureTrade(Mobile, state.Mobile);
|
||||
|
||||
Trades.Add(newTrade);
|
||||
state.Trades.Add(newTrade);
|
||||
|
|
@ -300,7 +299,9 @@ namespace Server.Network
|
|||
Menus ??= new List<IMenu>();
|
||||
|
||||
if (Menus.Count < MenuCap)
|
||||
{
|
||||
Menus.Add(menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteConsole("Exceeded menu cap, disconnecting...");
|
||||
|
|
@ -328,7 +329,9 @@ namespace Server.Network
|
|||
HuePickers ??= new List<HuePicker>();
|
||||
|
||||
if (HuePickers.Count < HuePickerCap)
|
||||
{
|
||||
HuePickers.Add(huePicker);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteConsole("Exceeded hue picker cap, disconnecting...");
|
||||
|
|
@ -356,7 +359,9 @@ namespace Server.Network
|
|||
Gumps ??= new List<Gump>();
|
||||
|
||||
if (Gumps.Count < GumpCap)
|
||||
{
|
||||
Gumps.Add(gump);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteConsole("Exceeded gump cap, disconnecting...");
|
||||
|
|
@ -394,8 +399,8 @@ namespace Server.Network
|
|||
public IAccount Account { get; set; }
|
||||
|
||||
public override string ToString() => m_ToString;
|
||||
public NetState(ConnectionContext connection)
|
||||
|
||||
public NetState(ConnectionContext connection)
|
||||
{
|
||||
Connection = connection;
|
||||
Seeded = false;
|
||||
|
|
@ -443,13 +448,13 @@ namespace Server.Network
|
|||
|
||||
try
|
||||
{
|
||||
//TODO: Rented memory
|
||||
ReadOnlyMemory<byte> buffer = p.Compile(CompressionEnabled, out int length);
|
||||
// TODO: Rented memory
|
||||
ReadOnlyMemory<byte> buffer = p.Compile(CompressionEnabled, out var length);
|
||||
|
||||
if (buffer.Length > 0 && length > 0)
|
||||
try
|
||||
{
|
||||
FlushResult result = await outPipe.WriteAsync(buffer.Slice(0, length));
|
||||
var result = await outPipe.WriteAsync(buffer.Slice(0, length));
|
||||
|
||||
if (result.IsCanceled || result.IsCompleted)
|
||||
{
|
||||
|
|
@ -491,8 +496,7 @@ namespace Server.Network
|
|||
}
|
||||
|
||||
public PacketHandler GetHandler(int packetID) =>
|
||||
ContainerGridLines ? PacketHandlers.Get6017Handler(packetID) :
|
||||
PacketHandlers.GetHandler(packetID);
|
||||
ContainerGridLines ? PacketHandlers.Get6017Handler(packetID) : PacketHandlers.GetHandler(packetID);
|
||||
|
||||
public static void TraceException(Exception ex)
|
||||
{
|
||||
|
|
@ -501,7 +505,7 @@ namespace Server.Network
|
|||
|
||||
try
|
||||
{
|
||||
using StreamWriter op = new StreamWriter("network-errors.log", true);
|
||||
using var op = new StreamWriter("network-errors.log", true);
|
||||
op.WriteLine("# {0}", DateTime.UtcNow);
|
||||
|
||||
op.WriteLine(ex);
|
||||
|
|
@ -523,7 +527,7 @@ namespace Server.Network
|
|||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
int disposing = Interlocked.Exchange(ref m_Disposing, 1);
|
||||
var disposing = Interlocked.Exchange(ref m_Disposing, 1);
|
||||
if (disposing == 1)
|
||||
return;
|
||||
|
||||
|
|
@ -545,15 +549,15 @@ namespace Server.Network
|
|||
|
||||
public static void ProcessDisposedQueue()
|
||||
{
|
||||
int breakout = 0;
|
||||
var breakout = 0;
|
||||
|
||||
while (breakout++ < 200)
|
||||
{
|
||||
if (!m_Disposed.TryDequeue(out NetState ns))
|
||||
if (!m_Disposed.TryDequeue(out var ns))
|
||||
break;
|
||||
|
||||
Mobile m = ns.Mobile;
|
||||
IAccount a = ns.Account;
|
||||
var m = ns.Mobile;
|
||||
var a = ns.Account;
|
||||
|
||||
if (m != null)
|
||||
{
|
||||
|
|
@ -579,11 +583,11 @@ namespace Server.Network
|
|||
{
|
||||
get
|
||||
{
|
||||
for (int i = ExpansionInfo.Table.Length - 1; i >= 0; i--)
|
||||
for (var i = ExpansionInfo.Table.Length - 1; i >= 0; i--)
|
||||
{
|
||||
ExpansionInfo info = ExpansionInfo.Table[i];
|
||||
var info = ExpansionInfo.Table[i];
|
||||
|
||||
if (info.RequiredClient != null && Version >= info.RequiredClient || (Flags & info.ClientFlags) != 0)
|
||||
if ((info.RequiredClient != null && Version >= info.RequiredClient) || (Flags & info.ClientFlags) != 0)
|
||||
return info;
|
||||
}
|
||||
|
||||
|
|
@ -597,13 +601,14 @@ namespace Server.Network
|
|||
|
||||
public bool SupportsExpansion(ExpansionInfo info, bool checkCoreExpansion = true)
|
||||
{
|
||||
if (info == null || checkCoreExpansion && (int)Core.Expansion < info.ID)
|
||||
if (info == null || (checkCoreExpansion && (int)Core.Expansion < info.ID))
|
||||
return false;
|
||||
|
||||
return info.RequiredClient != null ? Version >= info.RequiredClient : (Flags & info.ClientFlags) != 0;
|
||||
}
|
||||
|
||||
public bool SupportsExpansion(Expansion ex, bool checkCoreExpansion = true) => SupportsExpansion(ExpansionInfo.GetInfo(ex), checkCoreExpansion);
|
||||
public bool SupportsExpansion(Expansion ex, bool checkCoreExpansion = true) =>
|
||||
SupportsExpansion(ExpansionInfo.GetInfo(ex), checkCoreExpansion);
|
||||
|
||||
public int CompareTo(NetState other) => other == null ? 1 : m_ToString.CompareTo(other.m_ToString);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Server.Network
|
|||
/// <summary>
|
||||
/// Handles outgoing packet compression for the network.
|
||||
/// </summary>
|
||||
public static class Compression
|
||||
public static class NetworkCompression
|
||||
{
|
||||
private const int CountIndex = 0;
|
||||
private const int ValueIndex = 1;
|
||||
|
|
@ -48,7 +48,8 @@ namespace Server.Network
|
|||
// If our input exceeds this length, we may potentially overflow the buffer
|
||||
private const int PossibleOverflow = (BufferSize * 8 - TerminalCodeLength) / MaximalCodeLength;
|
||||
|
||||
private static readonly int[] _huffmanTable = {
|
||||
private static readonly int[] _huffmanTable =
|
||||
{
|
||||
0x2, 0x000, 0x5, 0x01F, 0x6, 0x022, 0x7, 0x034, 0x7, 0x075, 0x6, 0x028, 0x6, 0x03B, 0x7, 0x032,
|
||||
0x8, 0x0E0, 0x8, 0x062, 0x7, 0x056, 0x8, 0x079, 0x9, 0x19D, 0x8, 0x097, 0x6, 0x02A, 0x7, 0x057,
|
||||
0x8, 0x071, 0x8, 0x05B, 0x9, 0x1CC, 0x8, 0x0A7, 0x7, 0x025, 0x7, 0x04F, 0x8, 0x066, 0x8, 0x07D,
|
||||
|
|
@ -86,7 +87,7 @@ namespace Server.Network
|
|||
|
||||
public static readonly ICompressor Compressor;
|
||||
|
||||
static Compression()
|
||||
static NetworkCompression()
|
||||
{
|
||||
if (Core.Unix)
|
||||
Compressor = new UnixCompressor();
|
||||
|
|
@ -100,14 +101,14 @@ namespace Server.Network
|
|||
|
||||
if (offset < 0 || offset >= input.Length) throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
if (count < 0 || count > input.Length) throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if (input.Length - offset < count) throw new ArgumentException();
|
||||
if (input.Length - offset < count) throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
|
||||
length = 0;
|
||||
|
||||
if (count > DefiniteOverflow) return;
|
||||
|
||||
int bitCount = 0;
|
||||
int bitValue = 0;
|
||||
var bitCount = 0;
|
||||
var bitValue = 0;
|
||||
|
||||
fixed (int* pTable = _huffmanTable)
|
||||
{
|
||||
|
|
@ -185,10 +186,11 @@ namespace Server.Network
|
|||
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength)
|
||||
{
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
var destLengthLong = (ulong)destLength;
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
ZLibError e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr), (ulong)sourceLength);
|
||||
var e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
|
||||
(ulong)sourceLength);
|
||||
destLength = (int)destLengthLong;
|
||||
return e;
|
||||
}
|
||||
|
|
@ -196,21 +198,24 @@ namespace Server.Network
|
|||
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, ZLibQuality quality)
|
||||
{
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
var destLengthLong = (ulong)destLength;
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
ZLibError e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr), (ulong)source.Length, quality);
|
||||
var e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
|
||||
(ulong)source.Length, quality);
|
||||
destLength = (int)destLengthLong;
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength, ZLibQuality quality)
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength,
|
||||
ZLibQuality quality)
|
||||
{
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
var destLengthLong = (ulong)destLength;
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
ZLibError e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr), (ulong)sourceLength, quality);
|
||||
var e = Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
|
||||
(ulong)sourceLength, quality);
|
||||
destLength = (int)destLengthLong;
|
||||
return e;
|
||||
}
|
||||
|
|
@ -218,10 +223,11 @@ namespace Server.Network
|
|||
|
||||
public static unsafe ZLibError Unpack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength)
|
||||
{
|
||||
ulong destLengthLong = (ulong)destLength;
|
||||
var destLengthLong = (ulong)destLength;
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
ZLibError e = Compressor.Decompress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr), (ulong)sourceLength);
|
||||
var e = Compressor.Decompress(Unsafe.AsRef<int>(dPtr), ref destLengthLong, Unsafe.AsRef<int>(sPtr),
|
||||
(ulong)sourceLength);
|
||||
destLength = (int)destLengthLong;
|
||||
return e;
|
||||
}
|
||||
|
|
@ -231,26 +237,38 @@ namespace Server.Network
|
|||
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source, ulong sourceLength)
|
||||
{
|
||||
fixed(byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
return Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), sourceLength);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source, ZLibQuality quality)
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source,
|
||||
ZLibQuality quality)
|
||||
{
|
||||
fixed(byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
return Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), (ulong)source.Length, quality);
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
return Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), (ulong)source.Length,
|
||||
quality);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source, ulong sourceLength, ZLibQuality quality)
|
||||
public static unsafe ZLibError Pack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source, ulong sourceLength,
|
||||
ZLibQuality quality)
|
||||
{
|
||||
fixed(byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
return Compressor.Compress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), sourceLength, quality);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe ZLibError Unpack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source, ulong sourceLength)
|
||||
public static unsafe ZLibError Unpack(Span<byte> dest, ref ulong destLength, ReadOnlySpan<byte> source,
|
||||
ulong sourceLength)
|
||||
{
|
||||
fixed(byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
fixed (byte* dPtr = &MemoryMarshal.GetReference(dest), sPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
return Compressor.Decompress(Unsafe.AsRef<int>(dPtr), ref destLength, Unsafe.AsRef<int>(sPtr), sourceLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -265,66 +283,72 @@ namespace Server.Network
|
|||
|
||||
public class Compressor : ICompressor
|
||||
{
|
||||
public string Version => zlibVersion();
|
||||
public string Version => SafeNativeMethods.zlibVersion();
|
||||
|
||||
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
|
||||
compress(dest, ref destLength, source, sourceLength);
|
||||
SafeNativeMethods.compress(dest, ref destLength, source, sourceLength);
|
||||
|
||||
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength,
|
||||
ZLibQuality quality) => compress2(dest, ref destLength, source, sourceLength, quality);
|
||||
ZLibQuality quality) => SafeNativeMethods.compress2(dest, ref destLength, source, sourceLength, quality);
|
||||
|
||||
public ZLibError Decompress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
|
||||
uncompress(dest, ref destLength, source, sourceLength);
|
||||
SafeNativeMethods.uncompress(dest, ref destLength, source, sourceLength);
|
||||
|
||||
public ulong CompressBound(ulong sourceLength) => compressBound(sourceLength);
|
||||
public ulong CompressBound(ulong sourceLength) => SafeNativeMethods.compressBound(sourceLength);
|
||||
|
||||
[DllImport("zlib")]
|
||||
private static extern string zlibVersion();
|
||||
private static class SafeNativeMethods
|
||||
{
|
||||
[DllImport("zlib", CharSet = CharSet.Unicode)]
|
||||
internal static extern string zlibVersion();
|
||||
|
||||
[DllImport("zlib")]
|
||||
private static extern ZLibError compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
[DllImport("zlib")]
|
||||
internal static extern ZLibError compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
|
||||
[DllImport("zlib")]
|
||||
private static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
|
||||
ZLibQuality quality);
|
||||
[DllImport("zlib")]
|
||||
internal static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
|
||||
ZLibQuality quality);
|
||||
|
||||
[DllImport("zlib")]
|
||||
private static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
[DllImport("zlib")]
|
||||
internal static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
|
||||
[DllImport("zlib")]
|
||||
private static extern ulong compressBound(ulong sourceLen);
|
||||
[DllImport("zlib")]
|
||||
internal static extern ulong compressBound(ulong sourceLen);
|
||||
}
|
||||
}
|
||||
|
||||
public class UnixCompressor : ICompressor
|
||||
{
|
||||
public string Version => zlibVersion();
|
||||
public string Version => SafeNativeMethods.zlibVersion();
|
||||
|
||||
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
|
||||
compress(dest, ref destLength, source, sourceLength);
|
||||
SafeNativeMethods.compress(dest, ref destLength, source, sourceLength);
|
||||
|
||||
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength,
|
||||
ZLibQuality quality) => compress2(dest, ref destLength, source, sourceLength, quality);
|
||||
ZLibQuality quality) => SafeNativeMethods.compress2(dest, ref destLength, source, sourceLength, quality);
|
||||
|
||||
public ZLibError Decompress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
|
||||
uncompress(dest, ref destLength, source, sourceLength);
|
||||
SafeNativeMethods.uncompress(dest, ref destLength, source, sourceLength);
|
||||
|
||||
public ulong CompressBound(ulong sourceLength) => compressBound(sourceLength);
|
||||
public ulong CompressBound(ulong sourceLength) => SafeNativeMethods.compressBound(sourceLength);
|
||||
|
||||
[DllImport("libz")]
|
||||
private static extern string zlibVersion();
|
||||
internal static class SafeNativeMethods
|
||||
{
|
||||
[DllImport("libz", CharSet = CharSet.Unicode)]
|
||||
internal static extern string zlibVersion();
|
||||
|
||||
[DllImport("libz")]
|
||||
private static extern ZLibError compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
|
||||
[DllImport("libz")]
|
||||
private static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
|
||||
ZLibQuality quality);
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
|
||||
ZLibQuality quality);
|
||||
|
||||
[DllImport("libz")]
|
||||
private static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
[DllImport("libz")]
|
||||
internal static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
|
||||
|
||||
[DllImport("libz")]
|
||||
private static extern ulong compressBound(ulong sourceLen);
|
||||
[DllImport("libz")]
|
||||
internal static extern ulong compressBound(ulong sourceLen);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ZLibError
|
||||
|
|
@ -18,11 +18,11 @@
|
|||
*
|
||||
***************************************************************************/
|
||||
|
||||
using Server.Diagnostics;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Server.Diagnostics;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
|
|
@ -37,15 +37,13 @@ namespace Server.Network
|
|||
private readonly int m_Length;
|
||||
private State m_State;
|
||||
|
||||
protected PacketWriter m_Stream;
|
||||
|
||||
protected Packet(int packetID)
|
||||
{
|
||||
PacketID = packetID;
|
||||
|
||||
if (Core.Profiling)
|
||||
{
|
||||
PacketSendProfile prof = PacketSendProfile.Acquire(GetType());
|
||||
var prof = PacketSendProfile.Acquire(GetType());
|
||||
prof.Increment();
|
||||
}
|
||||
}
|
||||
|
|
@ -55,25 +53,25 @@ namespace Server.Network
|
|||
PacketID = packetID;
|
||||
m_Length = length;
|
||||
|
||||
m_Stream = PacketWriter.CreateInstance(length); // new PacketWriter( length );
|
||||
m_Stream.Write((byte)packetID);
|
||||
Stream = PacketWriter.CreateInstance(length); // new PacketWriter( length );
|
||||
Stream.Write((byte)packetID);
|
||||
|
||||
if (Core.Profiling)
|
||||
{
|
||||
PacketSendProfile prof = PacketSendProfile.Acquire(GetType());
|
||||
var prof = PacketSendProfile.Acquire(GetType());
|
||||
prof.Increment();
|
||||
}
|
||||
}
|
||||
|
||||
public int PacketID { get; }
|
||||
|
||||
public PacketWriter UnderlyingStream => m_Stream;
|
||||
public PacketWriter Stream { get; protected set; }
|
||||
|
||||
public void EnsureCapacity(int length)
|
||||
{
|
||||
m_Stream = PacketWriter.CreateInstance(length); // new PacketWriter( length );
|
||||
m_Stream.Write((byte)PacketID);
|
||||
m_Stream.Write((short)0);
|
||||
Stream = PacketWriter.CreateInstance(length); // new PacketWriter( length );
|
||||
Stream.Write((byte)PacketID);
|
||||
Stream.Write((short)0);
|
||||
}
|
||||
|
||||
public static Packet SetStatic(Packet p)
|
||||
|
|
@ -154,7 +152,7 @@ namespace Server.Network
|
|||
|
||||
try
|
||||
{
|
||||
using StreamWriter op = new StreamWriter("net_opt.log", true);
|
||||
using var op = new StreamWriter("net_opt.log", true);
|
||||
op.WriteLine("Redundant compile for packet {0}, use Acquire() and Release()", GetType());
|
||||
op.WriteLine(new StackTrace());
|
||||
}
|
||||
|
|
@ -164,7 +162,7 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
|
||||
m_CompiledBuffer = new byte[0];
|
||||
m_CompiledBuffer = Array.Empty<byte>();
|
||||
m_CompiledLength = 0;
|
||||
|
||||
length = m_CompiledLength;
|
||||
|
|
@ -183,35 +181,35 @@ namespace Server.Network
|
|||
{
|
||||
if (m_Length == 0)
|
||||
{
|
||||
long streamLen = m_Stream.Length;
|
||||
var streamLen = Stream.Length;
|
||||
|
||||
m_Stream.Seek(1, SeekOrigin.Begin);
|
||||
m_Stream.Write((ushort)streamLen);
|
||||
Stream.Seek(1, SeekOrigin.Begin);
|
||||
Stream.Write((ushort)streamLen);
|
||||
}
|
||||
else if (m_Stream.Length != m_Length)
|
||||
else if (Stream.Length != m_Length)
|
||||
{
|
||||
int diff = (int)m_Stream.Length - m_Length;
|
||||
var diff = (int)Stream.Length - m_Length;
|
||||
|
||||
Console.WriteLine("Packet: 0x{0:X2}: Bad packet length! ({1}{2} bytes)", PacketID, diff >= 0 ? "+" : "",
|
||||
diff);
|
||||
}
|
||||
|
||||
MemoryStream ms = m_Stream.UnderlyingStream;
|
||||
var ms = Stream.UnderlyingStream;
|
||||
|
||||
m_CompiledBuffer = ms.GetBuffer();
|
||||
int length = (int)ms.Length;
|
||||
var length = (int)ms.Length;
|
||||
|
||||
if (compress)
|
||||
{
|
||||
byte[] buffer = ArrayPool<byte>.Shared.Rent(CompressorBufferSize);
|
||||
var buffer = ArrayPool<byte>.Shared.Rent(CompressorBufferSize);
|
||||
|
||||
Compression.Compress(m_CompiledBuffer, 0, length, buffer, out length);
|
||||
NetworkCompression.Compress(m_CompiledBuffer, 0, length, buffer, out length);
|
||||
|
||||
if (length <= 0)
|
||||
{
|
||||
Console.WriteLine("Warning: Compression buffer overflowed on packet 0x{0:X2} ('{1}') (length={2})",
|
||||
PacketID, GetType().Name, length);
|
||||
using StreamWriter op = new StreamWriter("compression_overflow.log", true);
|
||||
using var op = new StreamWriter("compression_overflow.log", true);
|
||||
op.WriteLine("{0} Warning: Compression buffer overflowed on packet 0x{1:X2} ('{2}') (length={3})",
|
||||
DateTime.UtcNow, PacketID, GetType().Name, length);
|
||||
op.WriteLine(new StackTrace());
|
||||
|
|
@ -235,11 +233,13 @@ namespace Server.Network
|
|||
}
|
||||
else if (length > 0)
|
||||
{
|
||||
byte[] old = m_CompiledBuffer;
|
||||
var old = m_CompiledBuffer;
|
||||
m_CompiledLength = length;
|
||||
|
||||
if ((m_State & State.Static) != 0)
|
||||
{
|
||||
m_CompiledBuffer = new byte[length];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CompiledBuffer = ArrayPool<byte>.Shared.Rent(length);
|
||||
|
|
@ -249,8 +249,8 @@ namespace Server.Network
|
|||
Buffer.BlockCopy(old, 0, m_CompiledBuffer, 0, length);
|
||||
}
|
||||
|
||||
PacketWriter.ReleaseInstance(m_Stream);
|
||||
m_Stream = null;
|
||||
PacketWriter.ReleaseInstance(Stream);
|
||||
Stream = null;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ namespace Server.Network
|
|||
OnReceive = onReceive;
|
||||
}
|
||||
|
||||
public int PacketID{ get; }
|
||||
public int PacketID { get; }
|
||||
|
||||
public int Length{ get; }
|
||||
public int Length { get; }
|
||||
|
||||
public OnPacketReceive OnReceive{ get; }
|
||||
public OnPacketReceive OnReceive { get; }
|
||||
|
||||
public ThrottlePacketCallback ThrottleCallback{ get; set; }
|
||||
public ThrottlePacketCallback ThrottleCallback { get; set; }
|
||||
|
||||
public bool Ingame{ get; }
|
||||
public bool Ingame { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -36,19 +36,19 @@ namespace Server.Network
|
|||
|
||||
public PacketReader(ReadOnlySequence<byte> seq) => m_Reader = new SequenceReader<byte>(seq);
|
||||
|
||||
public byte Peek() => m_Reader.TryPeek(out byte value) ? value : (byte)0;
|
||||
public byte Peek() => m_Reader.TryPeek(out var value) ? value : (byte)0;
|
||||
|
||||
public void Trace(NetState state)
|
||||
{
|
||||
try
|
||||
{
|
||||
using StreamWriter sw = new StreamWriter("Packets.log", true);
|
||||
byte[] buffer = m_Reader.Sequence.ToArray();
|
||||
using var sw = new StreamWriter("Packets.log", true);
|
||||
var buffer = m_Reader.Sequence.ToArray();
|
||||
|
||||
if (buffer.Length > 0)
|
||||
sw.WriteLine("Client: {0}: Unhandled packet 0x{1:X2}", state, buffer[0]);
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(buffer))
|
||||
using (var ms = new MemoryStream(buffer))
|
||||
{
|
||||
Utility.FormatBuffer(sw, ms, buffer.Length);
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ namespace Server.Network
|
|||
m_Reader.Advance(Math.Min(m_Reader.Remaining, offset));
|
||||
break;
|
||||
case SeekOrigin.End:
|
||||
long count = m_Reader.Remaining - offset;
|
||||
var count = m_Reader.Remaining - offset;
|
||||
if (count < 0)
|
||||
m_Reader.Rewind(count * -1);
|
||||
else if (count > 0)
|
||||
|
|
@ -96,7 +96,7 @@ namespace Server.Network
|
|||
|
||||
public short ReadInt16() => m_Reader.TryReadBigEndian(out short value) ? value : (short)0;
|
||||
|
||||
public byte ReadByte() => m_Reader.TryRead(out byte value) ? value : (byte)0;
|
||||
public byte ReadByte() => m_Reader.TryRead(out var value) ? value : (byte)0;
|
||||
|
||||
public uint ReadUInt32() => (uint)ReadInt32();
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeStringLE()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (m_Reader.TryReadLittleEndian(out short c) && c != 0)
|
||||
sb.Append((char)c);
|
||||
|
|
@ -118,7 +118,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeStringLE(int fixedLength)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (fixedLength-- > 0 && m_Reader.TryReadLittleEndian(out short c) && c != 0)
|
||||
sb.Append((char)c);
|
||||
|
|
@ -131,7 +131,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeStringLESafe(int fixedLength)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (fixedLength-- > 0 && m_Reader.TryReadLittleEndian(out short c) && c != 0)
|
||||
if (IsSafeChar(c))
|
||||
|
|
@ -145,7 +145,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeStringLESafe()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (m_Reader.TryReadLittleEndian(out short c) && c != 0)
|
||||
if (IsSafeChar(c))
|
||||
|
|
@ -156,7 +156,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeStringSafe()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (m_Reader.TryReadBigEndian(out short c) && c != 0)
|
||||
if (IsSafeChar(c))
|
||||
|
|
@ -167,7 +167,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (m_Reader.TryReadBigEndian(out short c) && c != 0)
|
||||
sb.Append((char)c);
|
||||
|
|
@ -182,17 +182,19 @@ namespace Server.Network
|
|||
string s;
|
||||
|
||||
if (m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0'))
|
||||
{
|
||||
s = Utility.UTF8.GetString(span.Length > fixedLength ? span.Slice(0, fixedLength) : span);
|
||||
}
|
||||
else
|
||||
{
|
||||
long size = Math.Min(m_Reader.Remaining, fixedLength);
|
||||
var size = Math.Min(m_Reader.Remaining, fixedLength);
|
||||
s = Utility.UTF8.GetString(m_Reader.Sequence.Slice(m_Reader.Position, size).ToArray());
|
||||
m_Reader.Advance(size);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(s.Length);
|
||||
var sb = new StringBuilder(s.Length);
|
||||
|
||||
for (int i = 0; i < s.Length; ++i)
|
||||
for (var i = 0; i < s.Length; ++i)
|
||||
if (IsSafeChar(s[i]))
|
||||
sb.Append(s[i]);
|
||||
|
||||
|
|
@ -204,16 +206,18 @@ namespace Server.Network
|
|||
string s;
|
||||
|
||||
if (m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0'))
|
||||
{
|
||||
s = Utility.UTF8.GetString(span);
|
||||
}
|
||||
else
|
||||
{
|
||||
s = Utility.UTF8.GetString(m_Reader.Sequence.Slice(m_Reader.Position, m_Reader.Remaining).ToArray());
|
||||
m_Reader.Advance(m_Reader.Remaining);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(s.Length);
|
||||
var sb = new StringBuilder(s.Length);
|
||||
|
||||
for (int i = 0; i < s.Length; ++i)
|
||||
for (var i = 0; i < s.Length; ++i)
|
||||
if (IsSafeChar(s[i]))
|
||||
sb.Append(s[i]);
|
||||
|
||||
|
|
@ -222,15 +226,15 @@ namespace Server.Network
|
|||
|
||||
public string ReadUTF8String() =>
|
||||
Utility.UTF8.GetString(
|
||||
m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0') ? span :
|
||||
m_Reader.Sequence.Slice(m_Reader.Position, m_Reader.Remaining).ToArray()
|
||||
);
|
||||
m_Reader.TryReadTo(out ReadOnlySpan<byte> span, (byte)'\0')
|
||||
? span
|
||||
: m_Reader.Sequence.Slice(m_Reader.Position, m_Reader.Remaining).ToArray());
|
||||
|
||||
public string ReadString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (m_Reader.TryRead(out byte c))
|
||||
while (m_Reader.TryRead(out var c))
|
||||
sb.Append((char)c);
|
||||
|
||||
return sb.ToString();
|
||||
|
|
@ -238,9 +242,9 @@ namespace Server.Network
|
|||
|
||||
public string ReadStringSafe()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (m_Reader.TryRead(out byte c))
|
||||
while (m_Reader.TryRead(out var c))
|
||||
if (IsSafeChar(c))
|
||||
sb.Append((char)c);
|
||||
|
||||
|
|
@ -249,7 +253,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeStringSafe(int fixedLength)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (fixedLength-- > 0 && m_Reader.TryReadBigEndian(out short c) && c != 0)
|
||||
if (IsSafeChar(c))
|
||||
|
|
@ -263,7 +267,7 @@ namespace Server.Network
|
|||
|
||||
public string ReadUnicodeString(int fixedLength)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (fixedLength-- > 0 && m_Reader.TryReadBigEndian(out short c) && c != 0)
|
||||
sb.Append((char)c);
|
||||
|
|
@ -276,9 +280,9 @@ namespace Server.Network
|
|||
|
||||
public string ReadStringSafe(int fixedLength)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (fixedLength-- > 0 && m_Reader.TryRead(out byte c) && c != 0)
|
||||
while (fixedLength-- > 0 && m_Reader.TryRead(out var c) && c != 0)
|
||||
if (IsSafeChar(c))
|
||||
sb.Append((char)c);
|
||||
|
||||
|
|
@ -290,9 +294,9 @@ namespace Server.Network
|
|||
|
||||
public string ReadString(int fixedLength)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
while (fixedLength-- > 0 && m_Reader.TryRead(out byte c) && c != 0)
|
||||
while (fixedLength-- > 0 && m_Reader.TryRead(out var c) && c != 0)
|
||||
sb.Append((char)c);
|
||||
|
||||
if (fixedLength > 0)
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace Server.Network
|
|||
|
||||
public static PacketWriter CreateInstance(int capacity = 32)
|
||||
{
|
||||
if (m_Pool.TryDequeue(out PacketWriter pw))
|
||||
if (m_Pool.TryDequeue(out var pw))
|
||||
{
|
||||
pw.m_Capacity = capacity;
|
||||
pw.UnderlyingStream.SetLength(0);
|
||||
|
|
@ -177,7 +177,7 @@ namespace Server.Network
|
|||
value = string.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
var length = value.Length;
|
||||
|
||||
UnderlyingStream.SetLength(UnderlyingStream.Length + size);
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ namespace Server.Network
|
|||
value = string.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
var length = value.Length;
|
||||
|
||||
UnderlyingStream.SetLength(UnderlyingStream.Length + length + 1);
|
||||
|
||||
|
|
@ -223,11 +223,12 @@ namespace Server.Network
|
|||
value = string.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
var length = value.Length;
|
||||
|
||||
UnderlyingStream.SetLength(UnderlyingStream.Length + (length + 1) * 2);
|
||||
|
||||
UnderlyingStream.Position += Encoding.Unicode.GetBytes(value, 0, length, UnderlyingStream.GetBuffer(), (int)UnderlyingStream.Position);
|
||||
UnderlyingStream.Position +=
|
||||
Encoding.Unicode.GetBytes(value, 0, length, UnderlyingStream.GetBuffer(), (int)UnderlyingStream.Position);
|
||||
UnderlyingStream.Position += 2;
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +244,7 @@ namespace Server.Network
|
|||
value = string.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
var length = value.Length;
|
||||
size *= 2;
|
||||
|
||||
UnderlyingStream.SetLength(UnderlyingStream.Length + size);
|
||||
|
|
@ -271,7 +272,7 @@ namespace Server.Network
|
|||
value = string.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
var length = value.Length;
|
||||
|
||||
UnderlyingStream.SetLength(UnderlyingStream.Length + (length + 1) * 2);
|
||||
|
||||
|
|
@ -292,15 +293,16 @@ namespace Server.Network
|
|||
value = string.Empty;
|
||||
}
|
||||
|
||||
int length = value.Length;
|
||||
var length = value.Length;
|
||||
size *= 2;
|
||||
|
||||
UnderlyingStream.SetLength(UnderlyingStream.Length + size);
|
||||
|
||||
if (length * 2 >= size )
|
||||
if (length * 2 >= size)
|
||||
{
|
||||
UnderlyingStream.Position +=
|
||||
Encoding.BigEndianUnicode.GetBytes(value, 0, size / 2, UnderlyingStream.GetBuffer(), (int)UnderlyingStream.Position);
|
||||
Encoding.BigEndianUnicode.GetBytes(value, 0, size / 2, UnderlyingStream.GetBuffer(),
|
||||
(int)UnderlyingStream.Position);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ServerConnectionHandler.cs *
|
||||
* Created: 2020/04/12 - Updated: 2020/04/12 *
|
||||
|
|
@ -20,8 +20,6 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO.Pipelines;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -35,8 +33,7 @@ namespace Server.Network
|
|||
|
||||
public ServerConnectionHandler(
|
||||
IMessagePumpService messagePumpService,
|
||||
ILogger<ServerConnectionHandler> logger
|
||||
)
|
||||
ILogger<ServerConnectionHandler> logger)
|
||||
{
|
||||
_messagePumpService = messagePumpService;
|
||||
_logger = logger;
|
||||
|
|
@ -50,13 +47,13 @@ namespace Server.Network
|
|||
return;
|
||||
}
|
||||
|
||||
NetState ns = new NetState(connection);
|
||||
var ns = new NetState(connection);
|
||||
TcpServer.Instances.Add(ns);
|
||||
_logger.LogInformation($"Client: {ns}: Connected. [{TcpServer.Instances.Count} Online]");
|
||||
|
||||
connection.ConnectionClosed.Register(() => { TcpServer.Instances.Remove(ns); });
|
||||
|
||||
await ProcessIncoming(ns);
|
||||
await ProcessIncoming(ns).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task ProcessIncoming(NetState ns)
|
||||
|
|
@ -70,16 +67,16 @@ namespace Server.Network
|
|||
|
||||
try
|
||||
{
|
||||
ReadResult result = await inPipe.ReadAsync();
|
||||
var result = await inPipe.ReadAsync();
|
||||
if (result.IsCanceled || result.IsCompleted)
|
||||
return;
|
||||
|
||||
ReadOnlySequence<byte> seq = result.Buffer;
|
||||
var seq = result.Buffer;
|
||||
|
||||
if (seq.IsEmpty)
|
||||
break;
|
||||
|
||||
int pos = PacketHandlers.ProcessPacket(_messagePumpService, ns, seq);
|
||||
var pos = PacketHandlers.ProcessPacket(_messagePumpService, ns, seq);
|
||||
|
||||
if (pos <= 0)
|
||||
break;
|
||||
|
|
@ -99,7 +96,7 @@ namespace Server.Network
|
|||
{
|
||||
try
|
||||
{
|
||||
SocketConnectEventArgs args = new SocketConnectEventArgs(connection);
|
||||
var args = new SocketConnectEventArgs(connection);
|
||||
|
||||
EventSink.InvokeSocketConnect(args);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ServerStartup.cs *
|
||||
* Created: 2020/04/12 - Updated: 2020/04/12 *
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: StaticPacketHandlers.cs *
|
||||
* Created: 2019/03/15 - Updated: 2019/12/24 *
|
||||
|
|
@ -25,18 +25,26 @@ namespace Server.Network
|
|||
{
|
||||
public static class StaticPacketHandlers
|
||||
{
|
||||
private static readonly ConcurrentDictionary<IPropertyListObject,OPLInfo> OPLInfoPackets = new ConcurrentDictionary<IPropertyListObject,OPLInfo>();
|
||||
private static readonly ConcurrentDictionary<IEntity,RemoveEntity> RemoveEntityPackets = new ConcurrentDictionary<IEntity,RemoveEntity>();
|
||||
private static readonly ConcurrentDictionary<IPropertyListObject, OPLInfo> OPLInfoPackets =
|
||||
new ConcurrentDictionary<IPropertyListObject, OPLInfo>();
|
||||
|
||||
private static readonly ConcurrentDictionary<Item,WorldItem> WorldItemPackets = new ConcurrentDictionary<Item,WorldItem>();
|
||||
private static readonly ConcurrentDictionary<Item,WorldItemSA> WorldItemSAPackets = new ConcurrentDictionary<Item,WorldItemSA>();
|
||||
private static readonly ConcurrentDictionary<Item,WorldItemHS> WorldItemHSPackets = new ConcurrentDictionary<Item,WorldItemHS>();
|
||||
private static readonly ConcurrentDictionary<IEntity, RemoveEntity> RemoveEntityPackets =
|
||||
new ConcurrentDictionary<IEntity, RemoveEntity>();
|
||||
|
||||
private static readonly ConcurrentDictionary<Item, WorldItem> WorldItemPackets =
|
||||
new ConcurrentDictionary<Item, WorldItem>();
|
||||
|
||||
private static readonly ConcurrentDictionary<Item, WorldItemSA> WorldItemSAPackets =
|
||||
new ConcurrentDictionary<Item, WorldItemSA>();
|
||||
|
||||
private static readonly ConcurrentDictionary<Item, WorldItemHS> WorldItemHSPackets =
|
||||
new ConcurrentDictionary<Item, WorldItemHS>();
|
||||
|
||||
public static OPLInfo GetOPLInfoPacket(IPropertyListObject obj)
|
||||
{
|
||||
return OPLInfoPackets.GetOrAdd(obj, value =>
|
||||
{
|
||||
OPLInfo packet = new OPLInfo(value.PropertyList.Entity.Serial, value.PropertyList.Hash);
|
||||
var packet = new OPLInfo(value.PropertyList.Entity.Serial, value.PropertyList.Hash);
|
||||
packet.SetStatic();
|
||||
return packet;
|
||||
});
|
||||
|
|
@ -44,7 +52,7 @@ namespace Server.Network
|
|||
|
||||
public static OPLInfo FreeOPLInfoPacket(IPropertyListObject obj)
|
||||
{
|
||||
if (OPLInfoPackets.TryRemove(obj, out OPLInfo p))
|
||||
if (OPLInfoPackets.TryRemove(obj, out var p))
|
||||
Packet.Release(p);
|
||||
|
||||
return p;
|
||||
|
|
@ -54,7 +62,7 @@ namespace Server.Network
|
|||
{
|
||||
return RemoveEntityPackets.GetOrAdd(entity, value =>
|
||||
{
|
||||
RemoveEntity packet = new RemoveEntity(value);
|
||||
var packet = new RemoveEntity(value);
|
||||
packet.SetStatic();
|
||||
return packet;
|
||||
});
|
||||
|
|
@ -62,7 +70,7 @@ namespace Server.Network
|
|||
|
||||
public static void FreeRemoveItemPacket(IEntity entity)
|
||||
{
|
||||
if (RemoveEntityPackets.TryRemove(entity, out RemoveEntity p))
|
||||
if (RemoveEntityPackets.TryRemove(entity, out var p))
|
||||
Packet.Release(p);
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +78,7 @@ namespace Server.Network
|
|||
{
|
||||
return WorldItemPackets.GetOrAdd(item, value =>
|
||||
{
|
||||
WorldItem packet = new WorldItem(value);
|
||||
var packet = new WorldItem(value);
|
||||
packet.SetStatic();
|
||||
return packet;
|
||||
});
|
||||
|
|
@ -80,7 +88,7 @@ namespace Server.Network
|
|||
{
|
||||
return WorldItemSAPackets.GetOrAdd(item, value =>
|
||||
{
|
||||
WorldItemSA packet = new WorldItemSA(value);
|
||||
var packet = new WorldItemSA(value);
|
||||
packet.SetStatic();
|
||||
return packet;
|
||||
});
|
||||
|
|
@ -90,7 +98,7 @@ namespace Server.Network
|
|||
{
|
||||
return WorldItemHSPackets.GetOrAdd(item, value =>
|
||||
{
|
||||
WorldItemHS packet = new WorldItemHS(value);
|
||||
var packet = new WorldItemHS(value);
|
||||
packet.SetStatic();
|
||||
return packet;
|
||||
});
|
||||
|
|
@ -98,13 +106,13 @@ namespace Server.Network
|
|||
|
||||
public static void FreeWorldItemPackets(Item item)
|
||||
{
|
||||
if (WorldItemPackets.TryRemove(item, out WorldItem wi))
|
||||
if (WorldItemPackets.TryRemove(item, out var wi))
|
||||
Packet.Release(wi);
|
||||
|
||||
if (WorldItemSAPackets.TryRemove(item, out WorldItemSA wisa))
|
||||
if (WorldItemSAPackets.TryRemove(item, out var wisa))
|
||||
Packet.Release(wisa);
|
||||
|
||||
if (WorldItemHSPackets.TryRemove(item, out WorldItemHS wihs))
|
||||
if (WorldItemHSPackets.TryRemove(item, out var wihs))
|
||||
Packet.Release(wihs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: TcpServer.cs *
|
||||
* Created: 2020/04/12 - Updated: 2020/04/12 *
|
||||
|
|
@ -30,19 +30,17 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class TcpServer
|
||||
public static class TcpServer
|
||||
{
|
||||
public static List<IPEndPoint> Listeners { get; } = new List<IPEndPoint>();
|
||||
|
||||
// Make this thread safe
|
||||
public static List<NetState> Instances { get; } = new List<NetState>();
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args = null) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseSetting(WebHostDefaults.SuppressStatusMessagesKey, "True")
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSingleton<IMessagePumpService>(new MessagePumpService());
|
||||
})
|
||||
.ConfigureServices(services => { services.AddSingleton<IMessagePumpService>(new MessagePumpService()); })
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
foreach (var ipep in Listeners)
|
||||
|
|
@ -60,17 +58,19 @@ namespace Server.Network
|
|||
{
|
||||
if (ipep.Address.Equals(IPAddress.Any) || ipep.Address.Equals(IPAddress.IPv6Any))
|
||||
{
|
||||
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
|
||||
foreach (NetworkInterface adapter in adapters)
|
||||
var adapters = NetworkInterface.GetAllNetworkInterfaces();
|
||||
foreach (var adapter in adapters)
|
||||
{
|
||||
IPInterfaceProperties properties = adapter.GetIPProperties();
|
||||
foreach (UnicastIPAddressInformation unicast in properties.UnicastAddresses)
|
||||
var properties = adapter.GetIPProperties();
|
||||
foreach (var unicast in properties.UnicastAddresses)
|
||||
if (ipep.AddressFamily == unicast.Address.AddressFamily)
|
||||
Console.WriteLine("Listening: {0}:{1}", unicast.Address, ipep.Port);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Listening: {0}:{1}", ipep.Address, ipep.Port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ namespace Server
|
|||
public const int Murderer = 6;
|
||||
public const int Invulnerable = 7;
|
||||
|
||||
public static NotorietyHandler Handler{ get; set; }
|
||||
public static NotorietyHandler Handler { get; set; }
|
||||
|
||||
public static int[] Hues{ get; set; } =
|
||||
public static int[] Hues { get; set; } =
|
||||
{
|
||||
0x000,
|
||||
0x059,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Server
|
|||
public interface IPropertyListObject : IEntity
|
||||
{
|
||||
ObjectPropertyList PropertyList { get; }
|
||||
OPLInfo OPLPacket { get; }
|
||||
OPLInfo OPLPacket { get; }
|
||||
|
||||
void GetProperties(ObjectPropertyList list);
|
||||
}
|
||||
|
|
@ -53,22 +53,22 @@ namespace Server
|
|||
|
||||
Entity = e;
|
||||
|
||||
m_Stream.Write((short)1);
|
||||
m_Stream.Write(e.Serial);
|
||||
m_Stream.Write((byte)0);
|
||||
m_Stream.Write((byte)0);
|
||||
m_Stream.Write(e.Serial);
|
||||
Stream.Write((short)1);
|
||||
Stream.Write(e.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write(e.Serial);
|
||||
}
|
||||
|
||||
public IEntity Entity{ get; }
|
||||
public IEntity Entity { get; }
|
||||
|
||||
public int Hash => 0x40000000 + m_Hash;
|
||||
|
||||
public int Header{ get; set; }
|
||||
public int Header { get; set; }
|
||||
|
||||
public string HeaderArgs{ get; set; }
|
||||
public string HeaderArgs { get; set; }
|
||||
|
||||
public static bool Enabled{ get; set; }
|
||||
public static bool Enabled { get; set; }
|
||||
|
||||
public void Add(int number)
|
||||
{
|
||||
|
|
@ -83,22 +83,22 @@ namespace Server
|
|||
HeaderArgs = "";
|
||||
}
|
||||
|
||||
m_Stream.Write(number);
|
||||
m_Stream.Write((short)0);
|
||||
Stream.Write(number);
|
||||
Stream.Write((short)0);
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
m_Stream.Write(0);
|
||||
Stream.Write(0);
|
||||
|
||||
m_Stream.Seek(11, SeekOrigin.Begin);
|
||||
m_Stream.Write(m_Hash);
|
||||
Stream.Seek(11, SeekOrigin.Begin);
|
||||
Stream.Write(m_Hash);
|
||||
}
|
||||
|
||||
public void AddHash(int val)
|
||||
{
|
||||
m_Hash ^= val & 0x3FFFFFF;
|
||||
m_Hash ^= val >> 26 & 0x3F;
|
||||
m_Hash ^= (val >> 26) & 0x3F;
|
||||
}
|
||||
|
||||
public void Add(int number, string arguments)
|
||||
|
|
@ -117,17 +117,17 @@ namespace Server
|
|||
AddHash(number);
|
||||
AddHash(arguments.GetHashCode());
|
||||
|
||||
m_Stream.Write(number);
|
||||
Stream.Write(number);
|
||||
|
||||
int byteCount = m_Encoding.GetByteCount(arguments);
|
||||
var byteCount = m_Encoding.GetByteCount(arguments);
|
||||
|
||||
if (byteCount > m_Buffer.Length)
|
||||
m_Buffer = new byte[byteCount];
|
||||
|
||||
byteCount = m_Encoding.GetBytes(arguments, 0, arguments.Length, m_Buffer, 0);
|
||||
|
||||
m_Stream.Write((short)byteCount);
|
||||
m_Stream.Write(m_Buffer, 0, byteCount);
|
||||
Stream.Write((short)byteCount);
|
||||
Stream.Write(m_Buffer, 0, byteCount);
|
||||
}
|
||||
|
||||
public void Add(int number, string format, object arg0)
|
||||
|
|
@ -191,8 +191,8 @@ namespace Server
|
|||
|
||||
public OPLInfo(Serial serial, int hash) : base(0xDC, 9)
|
||||
{
|
||||
m_Stream.Write(serial);
|
||||
m_Stream.Write(hash);
|
||||
Stream.Write(serial);
|
||||
Stream.Write(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Server
|
|||
{
|
||||
public abstract class PartyCommands
|
||||
{
|
||||
public static PartyCommands Handler{ get; set; }
|
||||
public static PartyCommands Handler { get; set; }
|
||||
|
||||
public abstract void OnAdd(Mobile from);
|
||||
public abstract void OnRemove(Mobile from, Mobile target);
|
||||
|
|
@ -32,4 +32,4 @@ namespace Server
|
|||
public abstract void OnAccept(Mobile from, Mobile leader);
|
||||
public abstract void OnDecline(Mobile from, Mobile leader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@ namespace Server
|
|||
|
||||
protected override int BufferSize => 512;
|
||||
|
||||
public int CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile, int typeCode, uint serial)
|
||||
public int CommitTo(SequentialFileWriterStream dataFile, SequentialFileWriterStream indexFile, int typeCode, uint serial)
|
||||
{
|
||||
Flush();
|
||||
|
||||
byte[] buffer = stream.GetBuffer();
|
||||
int length = (int)stream.Length;
|
||||
var buffer = stream.GetBuffer();
|
||||
var length = (int)stream.Length;
|
||||
|
||||
long position = dataFile.Position;
|
||||
var position = dataFile.Position;
|
||||
|
||||
dataFile.Write(buffer, 0, length);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Server
|
|||
{
|
||||
PermitBackgroundWrite = permitBackgroundWrite;
|
||||
|
||||
Thread saveThread = new Thread(delegate() { SaveItems(); });
|
||||
var saveThread = new Thread(SaveItems);
|
||||
|
||||
saveThread.Name = "Item Save Subset";
|
||||
saveThread.Start();
|
||||
|
|
@ -40,9 +40,8 @@ namespace Server
|
|||
|
||||
saveThread.Join();
|
||||
|
||||
if (permitBackgroundWrite && UseSequentialWriters
|
||||
) //If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
if (permitBackgroundWrite && UseSequentialWriters) // If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
World.NotifyDiskWriteComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -30,14 +29,14 @@ namespace Server
|
|||
public sealed class DynamicSaveStrategy : SaveStrategy
|
||||
{
|
||||
private readonly ConcurrentBag<Item> _decayBag;
|
||||
private SequentialFileWriter _guildData, _guildIndex;
|
||||
private SequentialFileWriterStream _guildData, _guildIndex;
|
||||
private readonly BlockingCollection<QueuedMemoryWriter> _guildThreadWriters;
|
||||
|
||||
private SequentialFileWriter _itemData, _itemIndex;
|
||||
private SequentialFileWriterStream _itemData, _itemIndex;
|
||||
|
||||
private readonly BlockingCollection<QueuedMemoryWriter> _itemThreadWriters;
|
||||
|
||||
private SequentialFileWriter _mobileData, _mobileIndex;
|
||||
private SequentialFileWriterStream _mobileData, _mobileIndex;
|
||||
private readonly BlockingCollection<QueuedMemoryWriter> _mobileThreadWriters;
|
||||
|
||||
public DynamicSaveStrategy()
|
||||
|
|
@ -54,7 +53,7 @@ namespace Server
|
|||
{
|
||||
OpenFiles();
|
||||
|
||||
Task[] saveTasks = new Task[3];
|
||||
var saveTasks = new Task[3];
|
||||
|
||||
saveTasks[0] = SaveItems();
|
||||
saveTasks[1] = SaveMobiles();
|
||||
|
|
@ -64,25 +63,28 @@ namespace Server
|
|||
|
||||
if (permitBackgroundWrite)
|
||||
{
|
||||
//This option makes it finish the writing to disk in the background, continuing even after Save() returns.
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
// This option makes it finish the writing to disk in the background, continuing even after Save() returns.
|
||||
Task.Factory.ContinueWhenAll(saveTasks, _ =>
|
||||
{
|
||||
CloseFiles();
|
||||
|
||||
World.NotifyDiskWriteComplete();
|
||||
});
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.WaitAll(saveTasks); //Waits for the completion of all of the tasks(committing to disk)
|
||||
Task.WaitAll(saveTasks); // Waits for the completion of all of the tasks(committing to disk)
|
||||
CloseFiles();
|
||||
}
|
||||
}
|
||||
|
||||
private Task StartCommitTask(BlockingCollection<QueuedMemoryWriter> threadWriter, SequentialFileWriter data,
|
||||
SequentialFileWriter index)
|
||||
private Task StartCommitTask(BlockingCollection<QueuedMemoryWriter> threadWriter, SequentialFileWriterStream data,
|
||||
SequentialFileWriterStream index)
|
||||
{
|
||||
Task commitTask = Task.Factory.StartNew(() =>
|
||||
#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
var commitTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (!threadWriter.IsCompleted)
|
||||
{
|
||||
|
|
@ -94,33 +96,34 @@ namespace Server
|
|||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
//Per MSDN, it's fine if we're here, successful completion of adding can rarely put us into this state.
|
||||
// Per MSDN, it's fine if we're here, successful completion of adding can rarely put us into this state.
|
||||
break;
|
||||
}
|
||||
|
||||
writer.CommitTo(data, index);
|
||||
}
|
||||
});
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
private Task SaveItems()
|
||||
{
|
||||
//Start the blocking consumer; this runs in background.
|
||||
Task commitTask = StartCommitTask(_itemThreadWriters, _itemData, _itemIndex);
|
||||
// Start the blocking consumer; this runs in background.
|
||||
var commitTask = StartCommitTask(_itemThreadWriters, _itemData, _itemIndex);
|
||||
|
||||
IEnumerable<Item> items = World.Items.Values;
|
||||
|
||||
//Start the producer.
|
||||
// Start the producer.
|
||||
Parallel.ForEach(items, () => new QueuedMemoryWriter(),
|
||||
(item, state, writer) =>
|
||||
{
|
||||
long startPosition = writer.Position;
|
||||
var startPosition = writer.Position;
|
||||
|
||||
item.Serialize(writer);
|
||||
|
||||
int size = (int)(writer.Position - startPosition);
|
||||
var size = (int)(writer.Position - startPosition);
|
||||
|
||||
writer.QueueForIndex(item, size);
|
||||
|
||||
|
|
@ -136,27 +139,27 @@ namespace Server
|
|||
_itemThreadWriters.Add(writer);
|
||||
});
|
||||
|
||||
_itemThreadWriters.CompleteAdding(); //We only get here after the Parallel.ForEach completes. Lets our task
|
||||
_itemThreadWriters.CompleteAdding(); // We only get here after the Parallel.ForEach completes. Lets our task
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
private Task SaveMobiles()
|
||||
{
|
||||
//Start the blocking consumer; this runs in background.
|
||||
Task commitTask = StartCommitTask(_mobileThreadWriters, _mobileData, _mobileIndex);
|
||||
// Start the blocking consumer; this runs in background.
|
||||
var commitTask = StartCommitTask(_mobileThreadWriters, _mobileData, _mobileIndex);
|
||||
|
||||
IEnumerable<Mobile> mobiles = World.Mobiles.Values;
|
||||
|
||||
//Start the producer.
|
||||
// Start the producer.
|
||||
Parallel.ForEach(mobiles, () => new QueuedMemoryWriter(),
|
||||
(mobile, state, writer) =>
|
||||
{
|
||||
long startPosition = writer.Position;
|
||||
var startPosition = writer.Position;
|
||||
|
||||
mobile.Serialize(writer);
|
||||
|
||||
int size = (int)(writer.Position - startPosition);
|
||||
var size = (int)(writer.Position - startPosition);
|
||||
|
||||
writer.QueueForIndex(mobile, size);
|
||||
|
||||
|
|
@ -170,27 +173,27 @@ namespace Server
|
|||
});
|
||||
|
||||
_mobileThreadWriters
|
||||
.CompleteAdding(); //We only get here after the Parallel.ForEach completes. Lets our task tell the consumer that we're done
|
||||
.CompleteAdding(); // We only get here after the Parallel.ForEach completes. Lets our task tell the consumer that we're done
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
private Task SaveGuilds()
|
||||
{
|
||||
//Start the blocking consumer; this runs in background.
|
||||
Task commitTask = StartCommitTask(_guildThreadWriters, _guildData, _guildIndex);
|
||||
// Start the blocking consumer; this runs in background.
|
||||
var commitTask = StartCommitTask(_guildThreadWriters, _guildData, _guildIndex);
|
||||
|
||||
IEnumerable<BaseGuild> guilds = BaseGuild.List.Values;
|
||||
|
||||
//Start the producer.
|
||||
// Start the producer.
|
||||
Parallel.ForEach(guilds, () => new QueuedMemoryWriter(),
|
||||
(guild, state, writer) =>
|
||||
{
|
||||
long startPosition = writer.Position;
|
||||
var startPosition = writer.Position;
|
||||
|
||||
guild.Serialize(writer);
|
||||
|
||||
int size = (int)(writer.Position - startPosition);
|
||||
var size = (int)(writer.Position - startPosition);
|
||||
|
||||
writer.QueueForIndex(guild, size);
|
||||
|
||||
|
|
@ -203,28 +206,28 @@ namespace Server
|
|||
_guildThreadWriters.Add(writer);
|
||||
});
|
||||
|
||||
_guildThreadWriters.CompleteAdding(); //We only get here after the Parallel.ForEach completes. Lets our task
|
||||
_guildThreadWriters.CompleteAdding(); // We only get here after the Parallel.ForEach completes. Lets our task
|
||||
|
||||
return commitTask;
|
||||
}
|
||||
|
||||
public override void ProcessDecay()
|
||||
{
|
||||
while (_decayBag.TryTake(out Item item))
|
||||
while (_decayBag.TryTake(out var item))
|
||||
if (item.OnDecay())
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
private void OpenFiles()
|
||||
{
|
||||
_itemData = new SequentialFileWriter(World.ItemDataPath);
|
||||
_itemIndex = new SequentialFileWriter(World.ItemIndexPath);
|
||||
_itemData = new SequentialFileWriterStream(World.ItemDataPath);
|
||||
_itemIndex = new SequentialFileWriterStream(World.ItemIndexPath);
|
||||
|
||||
_mobileData = new SequentialFileWriter(World.MobileDataPath);
|
||||
_mobileIndex = new SequentialFileWriter(World.MobileIndexPath);
|
||||
_mobileData = new SequentialFileWriterStream(World.MobileDataPath);
|
||||
_mobileIndex = new SequentialFileWriterStream(World.MobileIndexPath);
|
||||
|
||||
_guildData = new SequentialFileWriter(World.GuildDataPath);
|
||||
_guildIndex = new SequentialFileWriter(World.GuildIndexPath);
|
||||
_guildData = new SequentialFileWriterStream(World.GuildDataPath);
|
||||
_guildIndex = new SequentialFileWriterStream(World.GuildIndexPath);
|
||||
|
||||
WriteCount(_itemIndex, World.Items.Count);
|
||||
WriteCount(_mobileIndex, World.Mobiles.Count);
|
||||
|
|
@ -243,10 +246,10 @@ namespace Server
|
|||
_guildIndex.Close();
|
||||
}
|
||||
|
||||
private void WriteCount(SequentialFileWriter indexFile, int count)
|
||||
private void WriteCount(SequentialFileWriterStream indexFile, int count)
|
||||
{
|
||||
//Equiv to GenericWriter.Write( (int)count );
|
||||
byte[] buffer = new byte[4];
|
||||
// Equiv to GenericWriter.Write( (int)count );
|
||||
var buffer = new byte[4];
|
||||
|
||||
buffer[0] = (byte)count;
|
||||
buffer[1] = (byte)(count >> 8);
|
||||
|
|
@ -264,15 +267,15 @@ namespace Server
|
|||
|
||||
private void SaveTypeDatabase(string path, List<Type> types)
|
||||
{
|
||||
BinaryFileWriter bfw = new BinaryFileWriter(path, false);
|
||||
var bfw = new BinaryFileWriter(path, false);
|
||||
|
||||
bfw.Write(types.Count);
|
||||
|
||||
foreach (Type type in types) bfw.Write(type.FullName);
|
||||
foreach (var type in types) bfw.Write(type.FullName);
|
||||
|
||||
bfw.Flush();
|
||||
|
||||
bfw.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
#if !MONO
|
||||
|
|
@ -34,11 +33,11 @@ namespace Server
|
|||
public const int KB = 1024;
|
||||
public const int MB = 1024 * KB;
|
||||
|
||||
public static int BufferSize{ get; set; } = 1 * MB;
|
||||
public static int BufferSize { get; set; } = 1 * MB;
|
||||
|
||||
public static int Concurrency{ get; set; } = 1;
|
||||
public static int Concurrency { get; set; } = 1;
|
||||
|
||||
public static bool Unbuffered{ get; set; } = true;
|
||||
public static bool Unbuffered { get; set; } = true;
|
||||
|
||||
public static bool AreSynchronous => Concurrency < 1;
|
||||
|
||||
|
|
@ -46,7 +45,7 @@ namespace Server
|
|||
|
||||
public static FileStream OpenSequentialStream(string path, FileMode mode, FileAccess access, FileShare share)
|
||||
{
|
||||
FileOptions options = FileOptions.SequentialScan;
|
||||
var options = FileOptions.SequentialScan;
|
||||
|
||||
if (Concurrency > 0)
|
||||
options |= FileOptions.Asynchronous;
|
||||
|
|
@ -59,7 +58,7 @@ namespace Server
|
|||
else
|
||||
return new FileStream(path, mode, access, share, BufferSize, options);
|
||||
|
||||
SafeFileHandle fileHandle =
|
||||
var fileHandle =
|
||||
UnsafeNativeMethods.CreateFile(path, (int)access, share, IntPtr.Zero, mode, (int)options, IntPtr.Zero);
|
||||
|
||||
if (fileHandle.IsInvalid) throw new IOException();
|
||||
|
|
|
|||
|
|
@ -47,10 +47,12 @@ namespace Server
|
|||
|
||||
public FileQueue(int concurrentWrites, FileCommitCallback callback)
|
||||
{
|
||||
if (concurrentWrites < 1) throw new ArgumentOutOfRangeException("concurrentWrites");
|
||||
if (concurrentWrites < 1) throw new ArgumentOutOfRangeException(nameof(concurrentWrites));
|
||||
|
||||
if (bufferSize < 1)
|
||||
throw new ArgumentOutOfRangeException("bufferSize");
|
||||
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
|
||||
throw new ArgumentOutOfRangeException(nameof(FileOperations.BufferSize));
|
||||
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
|
||||
|
||||
syncRoot = new object();
|
||||
|
||||
|
|
@ -62,7 +64,7 @@ namespace Server
|
|||
idle = new ManualResetEvent(true);
|
||||
}
|
||||
|
||||
public long Position{ get; private set; }
|
||||
public long Position { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
@ -81,7 +83,7 @@ namespace Server
|
|||
|
||||
++activeCount;
|
||||
|
||||
for (int slot = 0; slot < active.Length; ++slot)
|
||||
for (var slot = 0; slot < active.Length; ++slot)
|
||||
if (active[slot] == null)
|
||||
{
|
||||
active[slot] = new Chunk(this, slot, page.buffer, 0, page.length);
|
||||
|
|
@ -106,12 +108,12 @@ namespace Server
|
|||
}
|
||||
|
||||
/*lock ( syncRoot ) {
|
||||
if ( pending.Count > 0 ) {
|
||||
if (pending.Count > 0 ) {
|
||||
idle.Reset();
|
||||
}
|
||||
|
||||
for ( int slot = 0; slot < active.Length && pending.Count > 0; ++slot ) {
|
||||
if ( active[slot] == null ) {
|
||||
if (active[slot] == null ) {
|
||||
Page page = pending.Dequeue();
|
||||
|
||||
active[slot] = new Chunk( this, slot, page.buffer, 0, page.length );
|
||||
|
|
@ -128,17 +130,17 @@ namespace Server
|
|||
|
||||
private void Commit(Chunk chunk, int slot)
|
||||
{
|
||||
if (slot < 0 || slot >= active.Length) throw new ArgumentOutOfRangeException("slot");
|
||||
if (slot < 0 || slot >= active.Length) throw new ArgumentOutOfRangeException(nameof(slot));
|
||||
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (active[slot] != chunk) throw new ArgumentException();
|
||||
if (active[slot] != chunk) throw new ArgumentException("active slot is not the current chunk");
|
||||
|
||||
ArrayPool<byte>.Shared.Return(chunk.Buffer);
|
||||
|
||||
if (pending.Count > 0)
|
||||
{
|
||||
Page page = pending.Dequeue();
|
||||
var page = pending.Dequeue();
|
||||
|
||||
active[slot] = new Chunk(this, slot, page.buffer, 0, page.length);
|
||||
|
||||
|
|
@ -157,11 +159,11 @@ namespace Server
|
|||
|
||||
public void Enqueue(byte[] buffer, int offset, int size)
|
||||
{
|
||||
if (buffer == null) throw new ArgumentNullException("buffer");
|
||||
if (buffer == null) throw new ArgumentNullException(nameof(buffer));
|
||||
|
||||
if (offset < 0) throw new ArgumentOutOfRangeException("offset");
|
||||
if (size < 0) throw new ArgumentOutOfRangeException("size");
|
||||
if (buffer.Length - offset < size) throw new ArgumentException();
|
||||
if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
if (size < 0) throw new ArgumentOutOfRangeException(nameof(size));
|
||||
if (buffer.Length - offset < size) throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
|
||||
Position += size;
|
||||
|
||||
|
|
@ -169,9 +171,9 @@ namespace Server
|
|||
{
|
||||
buffered.buffer ??= ArrayPool<byte>.Shared.Rent(bufferSize);
|
||||
|
||||
byte[] page = buffered.buffer; // buffer page
|
||||
int pageSpace = page.Length - buffered.length; // available bytes in page
|
||||
int byteCount = size > pageSpace ? pageSpace : size; // how many bytes we can copy over
|
||||
var page = buffered.buffer; // buffer page
|
||||
var pageSpace = page.Length - buffered.length; // available bytes in page
|
||||
var byteCount = size > pageSpace ? pageSpace : size; // how many bytes we can copy over
|
||||
|
||||
Buffer.BlockCopy(buffer, offset, page, buffered.length, byteCount);
|
||||
|
||||
|
|
@ -192,29 +194,28 @@ namespace Server
|
|||
|
||||
public sealed class Chunk
|
||||
{
|
||||
private int offset;
|
||||
private readonly FileQueue owner;
|
||||
private readonly int slot;
|
||||
private readonly FileQueue m_Owner;
|
||||
private readonly int m_Slot;
|
||||
|
||||
public Chunk(FileQueue owner, int slot, byte[] buffer, int offset, int size)
|
||||
{
|
||||
this.owner = owner;
|
||||
this.slot = slot;
|
||||
m_Owner = owner;
|
||||
m_Slot = slot;
|
||||
|
||||
Buffer = buffer;
|
||||
this.offset = offset;
|
||||
Offset = offset;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public byte[] Buffer{ get; }
|
||||
public byte[] Buffer { get; }
|
||||
|
||||
public int Offset => 0;
|
||||
public int Offset { get; }
|
||||
|
||||
public int Size{ get; }
|
||||
public int Size { get; }
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
owner.Commit(this, slot);
|
||||
m_Owner.Commit(this, m_Slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ using Server.Guilds;
|
|||
|
||||
namespace Server
|
||||
{
|
||||
public sealed class ParallelSaveStrategy : SaveStrategy
|
||||
public sealed class ParallelSaveStrategy : SaveStrategy, IDisposable
|
||||
{
|
||||
private readonly Queue<Item> _decayQueue;
|
||||
|
||||
|
|
@ -34,11 +34,11 @@ namespace Server
|
|||
private int cycle;
|
||||
|
||||
private bool finished;
|
||||
private SequentialFileWriter guildData, guildIndex;
|
||||
private SequentialFileWriterStream guildData, guildIndex;
|
||||
|
||||
private SequentialFileWriter itemData, itemIndex;
|
||||
private SequentialFileWriterStream itemData, itemIndex;
|
||||
|
||||
private SequentialFileWriter mobileData, mobileIndex;
|
||||
private SequentialFileWriterStream mobileData, mobileIndex;
|
||||
|
||||
private readonly int processorCount;
|
||||
|
||||
|
|
@ -59,11 +59,11 @@ namespace Server
|
|||
|
||||
consumers = new Consumer[GetThreadCount()];
|
||||
|
||||
for (int i = 0; i < consumers.Length; ++i) consumers[i] = new Consumer(this, 256);
|
||||
for (var i = 0; i < consumers.Length; ++i) consumers[i] = new Consumer(this, 256);
|
||||
|
||||
IEnumerable<ISerializable> collection = new Producer();
|
||||
|
||||
foreach (ISerializable value in collection)
|
||||
foreach (var value in collection)
|
||||
while (!Enqueue(value))
|
||||
if (!Commit())
|
||||
Thread.Sleep(0);
|
||||
|
|
@ -75,9 +75,7 @@ namespace Server
|
|||
WaitHandle.WaitAll(
|
||||
Array.ConvertAll<Consumer, WaitHandle>(
|
||||
consumers,
|
||||
input => input.completionEvent
|
||||
)
|
||||
);
|
||||
input => input.completionEvent));
|
||||
|
||||
Commit();
|
||||
|
||||
|
|
@ -88,7 +86,7 @@ namespace Server
|
|||
{
|
||||
while (_decayQueue.Count > 0)
|
||||
{
|
||||
Item item = _decayQueue.Dequeue();
|
||||
var item = _decayQueue.Dequeue();
|
||||
|
||||
if (item.OnDecay()) item.Delete();
|
||||
}
|
||||
|
|
@ -102,11 +100,11 @@ namespace Server
|
|||
|
||||
private void SaveTypeDatabase(string path, List<Type> types)
|
||||
{
|
||||
BinaryFileWriter bfw = new BinaryFileWriter(path, false);
|
||||
var bfw = new BinaryFileWriter(path, false);
|
||||
|
||||
bfw.Write(types.Count);
|
||||
|
||||
foreach (Type type in types) bfw.Write(type.FullName);
|
||||
foreach (var type in types) bfw.Write(type.FullName);
|
||||
|
||||
bfw.Flush();
|
||||
|
||||
|
|
@ -115,23 +113,23 @@ namespace Server
|
|||
|
||||
private void OpenFiles()
|
||||
{
|
||||
itemData = new SequentialFileWriter(World.ItemDataPath);
|
||||
itemIndex = new SequentialFileWriter(World.ItemIndexPath);
|
||||
itemData = new SequentialFileWriterStream(World.ItemDataPath);
|
||||
itemIndex = new SequentialFileWriterStream(World.ItemIndexPath);
|
||||
|
||||
mobileData = new SequentialFileWriter(World.MobileDataPath);
|
||||
mobileIndex = new SequentialFileWriter(World.MobileIndexPath);
|
||||
mobileData = new SequentialFileWriterStream(World.MobileDataPath);
|
||||
mobileIndex = new SequentialFileWriterStream(World.MobileIndexPath);
|
||||
|
||||
guildData = new SequentialFileWriter(World.GuildDataPath);
|
||||
guildIndex = new SequentialFileWriter(World.GuildIndexPath);
|
||||
guildData = new SequentialFileWriterStream(World.GuildDataPath);
|
||||
guildIndex = new SequentialFileWriterStream(World.GuildIndexPath);
|
||||
|
||||
WriteCount(itemIndex, World.Items.Count);
|
||||
WriteCount(mobileIndex, World.Mobiles.Count);
|
||||
WriteCount(guildIndex, BaseGuild.List.Count);
|
||||
}
|
||||
|
||||
private void WriteCount(SequentialFileWriter indexFile, int count)
|
||||
private void WriteCount(SequentialFileWriterStream indexFile, int count)
|
||||
{
|
||||
byte[] buffer = new byte[4];
|
||||
var buffer = new byte[4];
|
||||
|
||||
buffer[0] = (byte)count;
|
||||
buffer[1] = (byte)(count >> 8);
|
||||
|
|
@ -157,8 +155,8 @@ namespace Server
|
|||
|
||||
private void OnSerialized(ConsumableEntry entry)
|
||||
{
|
||||
ISerializable value = entry.value;
|
||||
BinaryMemoryWriter writer = entry.writer;
|
||||
var value = entry.value;
|
||||
var writer = entry.writer;
|
||||
|
||||
if (value is Item item)
|
||||
Save(item, writer);
|
||||
|
|
@ -170,7 +168,7 @@ namespace Server
|
|||
|
||||
private void Save(Item item, BinaryMemoryWriter writer)
|
||||
{
|
||||
writer.CommitTo(itemData, itemIndex, item.m_TypeRef, item.Serial);
|
||||
writer.CommitTo(itemData, itemIndex, item.TypeRef, item.Serial);
|
||||
|
||||
if (item.Decays && item.Parent == null && item.Map != Map.Internal &&
|
||||
DateTime.UtcNow > item.LastMoved + item.DecayTime) _decayQueue.Enqueue(item);
|
||||
|
|
@ -178,19 +176,19 @@ namespace Server
|
|||
|
||||
private void Save(Mobile mob, BinaryMemoryWriter writer)
|
||||
{
|
||||
writer.CommitTo(mobileData, mobileIndex, mob.m_TypeRef, mob.Serial);
|
||||
writer.CommitTo(mobileData, mobileIndex, mob.TypeRef, mob.Serial);
|
||||
}
|
||||
|
||||
private void Save(BaseGuild guild, BinaryMemoryWriter writer)
|
||||
{
|
||||
writer.CommitTo(guildData, guildIndex, 0, guild.Id);
|
||||
writer.CommitTo(guildData, guildIndex, 0, guild.Serial);
|
||||
}
|
||||
|
||||
private bool Enqueue(ISerializable value)
|
||||
{
|
||||
for (int i = 0; i < consumers.Length; ++i)
|
||||
for (var i = 0; i < consumers.Length; ++i)
|
||||
{
|
||||
Consumer consumer = consumers[cycle++ % consumers.Length];
|
||||
var consumer = consumers[cycle++ % consumers.Length];
|
||||
|
||||
if (consumer.tail - consumer.head < consumer.buffer.Length)
|
||||
{
|
||||
|
|
@ -206,11 +204,11 @@ namespace Server
|
|||
|
||||
private bool Commit()
|
||||
{
|
||||
bool committed = false;
|
||||
var committed = false;
|
||||
|
||||
for (int i = 0; i < consumers.Length; ++i)
|
||||
for (var i = 0; i < consumers.Length; ++i)
|
||||
{
|
||||
Consumer consumer = consumers[i];
|
||||
var consumer = consumers[i];
|
||||
|
||||
while (consumer.head < consumer.done)
|
||||
{
|
||||
|
|
@ -239,11 +237,11 @@ namespace Server
|
|||
|
||||
public IEnumerator<ISerializable> GetEnumerator()
|
||||
{
|
||||
foreach (Item item in items) yield return item;
|
||||
foreach (var item in items) yield return item;
|
||||
|
||||
foreach (Mobile mob in mobiles) yield return mob;
|
||||
foreach (var mob in mobiles) yield return mob;
|
||||
|
||||
foreach (BaseGuild guild in guilds) yield return guild;
|
||||
foreach (var guild in guilds) yield return guild;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
|
||||
|
|
@ -271,7 +269,7 @@ namespace Server
|
|||
|
||||
buffer = new ConsumableEntry[bufferSize];
|
||||
|
||||
for (int i = 0; i < buffer.Length; ++i) buffer[i].writer = new BinaryMemoryWriter();
|
||||
for (var i = 0; i < buffer.Length; ++i) buffer[i].writer = new BinaryMemoryWriter();
|
||||
|
||||
completionEvent = new ManualResetEvent(false);
|
||||
|
||||
|
|
@ -316,5 +314,39 @@ namespace Server
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool disposedValue = false; // To detect redundant calls
|
||||
|
||||
public void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// TODO: dispose managed state (managed objects).
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
|
||||
// TODO: set large fields to null.
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
|
||||
// ~ParallelSaveStrategy()
|
||||
// {
|
||||
// // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
// Dispose(false);
|
||||
// }
|
||||
|
||||
// This code added to correctly implement the disposable pattern.
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
Dispose(true);
|
||||
// TODO: uncomment the following line if the finalizer is overridden above.
|
||||
// GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
#region References
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class Persistence
|
||||
|
|
@ -25,8 +21,8 @@ namespace Server
|
|||
|
||||
file.Refresh();
|
||||
|
||||
using FileStream fs = file.OpenWrite();
|
||||
BinaryFileWriter writer = new BinaryFileWriter(fs, true);
|
||||
using var fs = file.OpenWrite();
|
||||
var writer = new BinaryFileWriter(fs, true);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -79,8 +75,8 @@ namespace Server
|
|||
|
||||
file.Refresh();
|
||||
|
||||
using FileStream fs = file.OpenRead();
|
||||
BinaryFileReader reader = new BinaryFileReader(new BinaryReader(fs));
|
||||
using var fs = file.OpenRead();
|
||||
var reader = new BinaryFileReader(new BinaryReader(fs));
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/***************************************************************************
|
||||
/***************************************************************************
|
||||
* QueuedMemoryWriter.cs
|
||||
* -------------------
|
||||
* begin : December 16, 2010
|
||||
|
|
@ -40,36 +40,36 @@ namespace Server
|
|||
|
||||
info.size = size;
|
||||
|
||||
info.typeCode = serializable.TypeReference; //For guilds, this will automagically be zero.
|
||||
info.serial = serializable.SerialIdentity;
|
||||
info.typeCode = serializable.TypeRef; // For guilds, this will automagically be zero.
|
||||
info.serial = serializable.Serial;
|
||||
|
||||
_orderedIndexInfo.Add(info);
|
||||
}
|
||||
|
||||
public void CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile)
|
||||
public void CommitTo(SequentialFileWriterStream dataFile, SequentialFileWriterStream indexFile)
|
||||
{
|
||||
Flush();
|
||||
|
||||
int memLength = (int)_memStream.Position;
|
||||
var memLength = (int)_memStream.Position;
|
||||
|
||||
if (memLength > 0)
|
||||
{
|
||||
byte[] memBuffer = _memStream.GetBuffer();
|
||||
var memBuffer = _memStream.GetBuffer();
|
||||
|
||||
long actualPosition = dataFile.Position;
|
||||
var actualPosition = dataFile.Position;
|
||||
|
||||
dataFile.Write(memBuffer, 0, memLength); //The buffer contains the data from many items.
|
||||
dataFile.Write(memBuffer, 0, memLength); // The buffer contains the data from many items.
|
||||
|
||||
//Console.WriteLine("Writing {0} bytes starting at {1}, with {2} things", memLength, actualPosition, _orderedIndexInfo.Count);
|
||||
// Console.WriteLine("Writing {0} bytes starting at {1}, with {2} things", memLength, actualPosition, _orderedIndexInfo.Count);
|
||||
|
||||
byte[] indexBuffer = new byte[20];
|
||||
var indexBuffer = new byte[20];
|
||||
|
||||
//int indexWritten = _orderedIndexInfo.Count * indexBuffer.Length;
|
||||
//int totalWritten = memLength + indexWritten
|
||||
// int indexWritten = _orderedIndexInfo.Count * indexBuffer.Length;
|
||||
// int totalWritten = memLength + indexWritten
|
||||
|
||||
for (int i = 0; i < _orderedIndexInfo.Count; i++)
|
||||
for (var i = 0; i < _orderedIndexInfo.Count; i++)
|
||||
{
|
||||
IndexInfo info = _orderedIndexInfo[i];
|
||||
var info = _orderedIndexInfo[i];
|
||||
|
||||
indexBuffer[0] = (byte)info.typeCode;
|
||||
indexBuffer[1] = (byte)(info.typeCode >> 8);
|
||||
|
|
@ -101,7 +101,7 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
Close(); //We're done with this writer.
|
||||
Close(); // We're done with this writer.
|
||||
}
|
||||
|
||||
private struct IndexInfo
|
||||
|
|
@ -111,4 +111,4 @@ namespace Server
|
|||
public uint serial;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ namespace Server
|
|||
{
|
||||
public abstract class SaveStrategy
|
||||
{
|
||||
public abstract string Name{ get; }
|
||||
public abstract string Name { get; }
|
||||
|
||||
public static SaveStrategy Acquire()
|
||||
{
|
||||
if (Core.MultiProcessor)
|
||||
{
|
||||
int processorCount = Core.ProcessorCount;
|
||||
var processorCount = Core.ProcessorCount;
|
||||
|
||||
if (processorCount > 2)
|
||||
return
|
||||
|
|
@ -44,4 +44,4 @@ namespace Server
|
|||
|
||||
public abstract void ProcessDecay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,23 +23,22 @@ using System.IO;
|
|||
|
||||
namespace Server
|
||||
{
|
||||
public sealed class SequentialFileWriter : Stream
|
||||
public sealed class SequentialFileWriterStream : Stream
|
||||
{
|
||||
private FileQueue fileQueue;
|
||||
private FileStream fileStream;
|
||||
|
||||
private AsyncCallback writeCallback;
|
||||
|
||||
public SequentialFileWriter(string path)
|
||||
public SequentialFileWriterStream(string path)
|
||||
{
|
||||
if (path == null) throw new ArgumentNullException("path");
|
||||
if (path == null) throw new ArgumentNullException(nameof(path));
|
||||
|
||||
fileStream = FileOperations.OpenSequentialStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
|
||||
fileQueue = new FileQueue(
|
||||
Math.Max(1, FileOperations.Concurrency),
|
||||
FileCallback
|
||||
);
|
||||
FileCallback);
|
||||
}
|
||||
|
||||
public override long Position
|
||||
|
|
@ -74,7 +73,7 @@ namespace Server
|
|||
|
||||
private void OnWrite(IAsyncResult asyncResult)
|
||||
{
|
||||
FileQueue.Chunk chunk = asyncResult.AsyncState as FileQueue.Chunk;
|
||||
var chunk = asyncResult.AsyncState as FileQueue.Chunk;
|
||||
|
||||
fileStream.EndWrite(asyncResult);
|
||||
|
||||
|
|
@ -33,7 +33,8 @@ namespace Server
|
|||
Threaded
|
||||
}
|
||||
|
||||
public static SaveOption SaveType = SaveOption.Normal;
|
||||
// TODO: Move to configuration
|
||||
public static SaveOption SaveType => SaveOption.Normal;
|
||||
|
||||
private readonly Queue<Item> _decayQueue;
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ namespace Server
|
|||
|
||||
public override string Name => "Standard";
|
||||
|
||||
protected bool PermitBackgroundWrite{ get; set; }
|
||||
protected bool PermitBackgroundWrite { get; set; }
|
||||
|
||||
protected bool UseSequentialWriters => SaveType == SaveOption.Normal || !PermitBackgroundWrite;
|
||||
|
||||
|
|
@ -49,16 +50,17 @@ namespace Server
|
|||
{
|
||||
PermitBackgroundWrite = permitBackgroundWrite;
|
||||
|
||||
#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
Task.WaitAll(Task.Factory.StartNew(SaveMobiles), Task.Factory.StartNew(SaveItems), Task.Factory.StartNew(SaveGuilds));
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
|
||||
if (permitBackgroundWrite && UseSequentialWriters
|
||||
) //If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
if (permitBackgroundWrite && UseSequentialWriters) // If we're permitted to write in the background, but we don't anyways, then notify.
|
||||
World.NotifyDiskWriteComplete();
|
||||
}
|
||||
|
||||
protected void SaveMobiles()
|
||||
{
|
||||
Dictionary<Serial, Mobile> mobiles = World.Mobiles;
|
||||
var mobiles = World.Mobiles;
|
||||
|
||||
IGenericWriter idx;
|
||||
IGenericWriter tdb;
|
||||
|
|
@ -76,27 +78,28 @@ namespace Server
|
|||
tdb = new AsyncWriter(World.MobileTypesPath, false);
|
||||
bin = new AsyncWriter(World.MobileDataPath, true);
|
||||
}
|
||||
|
||||
#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
tdb.Write(World.m_MobileTypes.Count);
|
||||
|
||||
for (int i = 0; i < World.m_MobileTypes.Count; ++i)
|
||||
for (var i = 0; i < World.m_MobileTypes.Count; ++i)
|
||||
tdb.Write(World.m_MobileTypes[i].FullName);
|
||||
|
||||
tdb.Close();
|
||||
});
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
|
||||
Parallel.ForEach(mobiles.Values, mobile => mobile.Serialize());
|
||||
|
||||
#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
idx.Write(mobiles.Count);
|
||||
foreach (Mobile m in mobiles.Values)
|
||||
foreach (var m in mobiles.Values)
|
||||
{
|
||||
long start = bin.Position;
|
||||
var start = bin.Position;
|
||||
|
||||
idx.Write(m.m_TypeRef);
|
||||
idx.Write(m.TypeRef);
|
||||
idx.Write(m.Serial);
|
||||
idx.Write(start);
|
||||
idx.Write((int)m.SaveBuffer.Position);
|
||||
|
|
@ -108,11 +111,12 @@ namespace Server
|
|||
idx.Close();
|
||||
bin.Close();
|
||||
});
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
}
|
||||
|
||||
protected void SaveItems()
|
||||
{
|
||||
Dictionary<Serial, Item> items = World.Items;
|
||||
var items = World.Items;
|
||||
|
||||
IGenericWriter idx;
|
||||
IGenericWriter tdb;
|
||||
|
|
@ -131,24 +135,27 @@ namespace Server
|
|||
bin = new AsyncWriter(World.ItemDataPath, true);
|
||||
}
|
||||
|
||||
#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
tdb.Write(World.m_ItemTypes.Count);
|
||||
|
||||
for (int i = 0; i < World.m_ItemTypes.Count; ++i)
|
||||
for (var i = 0; i < World.m_ItemTypes.Count; ++i)
|
||||
tdb.Write(World.m_ItemTypes[i].FullName);
|
||||
|
||||
tdb.Close();
|
||||
});
|
||||
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
Parallel.ForEach(items.Values, item => item.Serialize());
|
||||
|
||||
idx.Write(items.Count);
|
||||
|
||||
DateTime n = DateTime.UtcNow;
|
||||
var n = DateTime.UtcNow;
|
||||
|
||||
Task.Factory.StartNew(() => {
|
||||
foreach (Item item in items.Values)
|
||||
#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
foreach (var item in items.Values)
|
||||
{
|
||||
if (item.Decays && item.Parent == null && item.Map != Map.Internal && item.LastMoved + item.DecayTime <= n)
|
||||
{
|
||||
|
|
@ -156,9 +163,9 @@ namespace Server
|
|||
_decayQueue.Enqueue(item);
|
||||
}
|
||||
|
||||
long start = bin.Position;
|
||||
var start = bin.Position;
|
||||
|
||||
idx.Write(item.m_TypeRef);
|
||||
idx.Write(item.TypeRef);
|
||||
idx.Write(item.Serial);
|
||||
idx.Write(start);
|
||||
idx.Write((int)item.SaveBuffer.Position);
|
||||
|
|
@ -170,7 +177,9 @@ namespace Server
|
|||
idx.Close();
|
||||
bin.Close();
|
||||
});
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
}
|
||||
|
||||
protected void SaveGuilds()
|
||||
{
|
||||
IGenericWriter idx;
|
||||
|
|
@ -190,15 +199,15 @@ namespace Server
|
|||
Parallel.ForEach(BaseGuild.List.Values, guild => guild.Serialize());
|
||||
|
||||
idx.Write(BaseGuild.List.Count);
|
||||
|
||||
#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
foreach (BaseGuild guild in BaseGuild.List.Values)
|
||||
foreach (var guild in BaseGuild.List.Values)
|
||||
{
|
||||
long start = bin.Position;
|
||||
var start = bin.Position;
|
||||
|
||||
idx.Write(0); //guilds have no typeid
|
||||
idx.Write(guild.Id);
|
||||
idx.Write(0); // guilds have no typeid
|
||||
idx.Write(guild.Serial);
|
||||
idx.Write(start);
|
||||
idx.Write((int)guild.SaveBuffer.Position);
|
||||
|
||||
|
|
@ -208,13 +217,14 @@ namespace Server
|
|||
idx.Close();
|
||||
bin.Close();
|
||||
});
|
||||
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler *
|
||||
}
|
||||
|
||||
public override void ProcessDecay()
|
||||
{
|
||||
while (_decayQueue.Count > 0)
|
||||
{
|
||||
Item item = _decayQueue.Dequeue();
|
||||
var item = _decayQueue.Dequeue();
|
||||
|
||||
if (item.OnDecay())
|
||||
item.Delete();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Server
|
|||
{
|
||||
public class Point3DList
|
||||
{
|
||||
private static readonly Point3D[] m_EmptyList = new Point3D[0];
|
||||
private static readonly Point3D[] m_EmptyList = System.Array.Empty<Point3D>();
|
||||
private Point3D[] m_List;
|
||||
|
||||
public Point3DList()
|
||||
|
|
@ -31,7 +31,7 @@ namespace Server
|
|||
Count = 0;
|
||||
}
|
||||
|
||||
public int Count{ get; private set; }
|
||||
public int Count { get; private set; }
|
||||
|
||||
public Point3D Last => m_List[Count - 1];
|
||||
|
||||
|
|
@ -46,10 +46,10 @@ namespace Server
|
|||
{
|
||||
if (Count + 1 > m_List.Length)
|
||||
{
|
||||
Point3D[] old = m_List;
|
||||
var old = m_List;
|
||||
m_List = new Point3D[old.Length * 2];
|
||||
|
||||
for (int i = 0; i < old.Length; ++i)
|
||||
for (var i = 0; i < old.Length; ++i)
|
||||
m_List[i] = old[i];
|
||||
}
|
||||
|
||||
|
|
@ -63,10 +63,10 @@ namespace Server
|
|||
{
|
||||
if (Count + 1 > m_List.Length)
|
||||
{
|
||||
Point3D[] old = m_List;
|
||||
var old = m_List;
|
||||
m_List = new Point3D[old.Length * 2];
|
||||
|
||||
for (int i = 0; i < old.Length; ++i)
|
||||
for (var i = 0; i < old.Length; ++i)
|
||||
m_List[i] = old[i];
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +81,9 @@ namespace Server
|
|||
if (Count == 0)
|
||||
return m_EmptyList;
|
||||
|
||||
Point3D[] list = new Point3D[Count];
|
||||
var list = new Point3D[Count];
|
||||
|
||||
for (int i = 0; i < Count; ++i)
|
||||
for (var i = 0; i < Count; ++i)
|
||||
list[i] = m_List[i];
|
||||
|
||||
Count = 0;
|
||||
|
|
@ -91,4 +91,4 @@ namespace Server
|
|||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace Server
|
|||
{
|
||||
/*public abstract TimeSpan Interval{ get; }
|
||||
public abstract TimeSpan Duration{ get; }*/
|
||||
public abstract string Name{ get; }
|
||||
public abstract int Level{ get; }
|
||||
public abstract string Name { get; }
|
||||
public abstract int Level { get; }
|
||||
|
||||
public static Poison Lesser => GetPoison("Lesser");
|
||||
public static Poison Regular => GetPoison("Regular");
|
||||
|
|
@ -37,19 +37,18 @@ namespace Server
|
|||
public static Poison Deadly => GetPoison("Deadly");
|
||||
public static Poison Lethal => GetPoison("Lethal");
|
||||
|
||||
public static List<Poison> Poisons{ get; } = new List<Poison>();
|
||||
public static List<Poison> Poisons { get; } = new List<Poison>();
|
||||
|
||||
public abstract Timer ConstructTimer(Mobile m);
|
||||
/*public abstract void OnDamage( Mobile m, ref object state );*/
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
|
||||
public static void Register(Poison reg)
|
||||
{
|
||||
string regName = reg.Name.ToLower();
|
||||
var regName = reg.Name.ToLower();
|
||||
|
||||
for (int i = 0; i < Poisons.Count; i++)
|
||||
for (var i = 0; i < Poisons.Count; i++)
|
||||
{
|
||||
if (reg.Level == Poisons[i].Level)
|
||||
throw new Exception("A poison with that level already exists.");
|
||||
|
|
@ -60,13 +59,14 @@ namespace Server
|
|||
Poisons.Add(reg);
|
||||
}
|
||||
|
||||
public static Poison Parse(string value) => (int.TryParse(value, out int plevel) ? GetPoison(plevel) : null) ?? GetPoison(value);
|
||||
public static Poison Parse(string value) =>
|
||||
(int.TryParse(value, out var plevel) ? GetPoison(plevel) : null) ?? GetPoison(value);
|
||||
|
||||
public static Poison GetPoison(int level)
|
||||
{
|
||||
for (int i = 0; i < Poisons.Count; ++i)
|
||||
for (var i = 0; i < Poisons.Count; ++i)
|
||||
{
|
||||
Poison p = Poisons[i];
|
||||
var p = Poisons[i];
|
||||
|
||||
if (p.Level == level)
|
||||
return p;
|
||||
|
|
@ -77,9 +77,9 @@ namespace Server
|
|||
|
||||
public static Poison GetPoison(string name)
|
||||
{
|
||||
for (int i = 0; i < Poisons.Count; ++i)
|
||||
for (var i = 0; i < Poisons.Count; ++i)
|
||||
{
|
||||
Poison p = Poisons[i];
|
||||
var p = Poisons[i];
|
||||
|
||||
if (Utility.InsensitiveCompare(p.Name, name) == 0)
|
||||
return p;
|
||||
|
|
@ -107,7 +107,7 @@ namespace Server
|
|||
{
|
||||
case 1: return GetPoison(reader.ReadByte());
|
||||
case 2:
|
||||
//no longer used, safe to remove?
|
||||
// no longer used, safe to remove?
|
||||
reader.ReadInt();
|
||||
reader.ReadDouble();
|
||||
reader.ReadInt();
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue