Formatting #2 (#59)

This commit is contained in:
Kamron Batman 2019-10-05 00:37:03 -07:00 committed by GitHub
parent 096d39609e
commit 8e9221bb5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
400 changed files with 3688 additions and 5969 deletions

View file

@ -90,9 +90,9 @@ namespace Server.Network
{
if (Core.Unix)
Compressor = new UnixCompressor();
else
else
Compressor = new Compressor();
}
}
public static unsafe void Compress(ReadOnlySpan<byte> input, int offset, int count, Span<byte> output, out int length)
{
@ -187,45 +187,45 @@ namespace Server.Network
{
ulong 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);
destLength = (int)destLengthLong;
return e;
}
}
}
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, ZLibQuality quality)
{
ulong 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);
destLength = (int)destLengthLong;
return e;
}
}
}
public static unsafe ZLibError Pack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength, ZLibQuality quality)
{
{
ulong 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);
destLength = (int)destLengthLong;
return e;
}
}
}
public static unsafe ZLibError Unpack(Span<byte> dest, ref int destLength, ReadOnlySpan<byte> source, int sourceLength)
{
ulong 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);
destLength = (int)destLengthLong;
return e;
}
}
}
public static ulong MaxPackSize(ulong sourceLength) => Compressor.CompressBound(sourceLength);
@ -264,7 +264,7 @@ namespace Server.Network
}
public class Compressor : ICompressor
{
{
public string Version => zlibVersion();
public ZLibError Compress(in int dest, ref ulong destLength, in int source, ulong sourceLength) =>
@ -286,7 +286,7 @@ namespace Server.Network
[DllImport("zlib")]
private static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
ZLibQuality quality);
ZLibQuality quality);
[DllImport("zlib")]
private static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
@ -310,20 +310,20 @@ namespace Server.Network
public ulong CompressBound(ulong sourceLength) => compressBound(sourceLength);
[DllImport("libz")]
[DllImport("libz")]
private static extern string zlibVersion();
[DllImport("libz")]
[DllImport("libz")]
private static extern ZLibError compress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
[DllImport("libz")]
[DllImport("libz")]
private static extern ZLibError compress2(in int dest, ref ulong destLength, in int source, ulong sourceLength,
ZLibQuality quality);
ZLibQuality quality);
[DllImport("libz")]
private static extern ZLibError uncompress(in int dest, ref ulong destLength, in int source, ulong sourceLength);
[DllImport("libz")]
[DllImport("libz")]
private static extern ulong compressBound(ulong sourceLen);
}
@ -347,4 +347,4 @@ namespace Server.Network
Speed = 1,
Size = 9
}
}
}

View file

@ -34,12 +34,12 @@ 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());
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());
m_Reader.ReadUnicodeStringSafe(m_Reader.ReadUInt16());
public string ReadUnicodeString() => m_Reader.ReadByte() != 2 ? string.Empty :
m_Reader.ReadUnicodeString(m_Reader.ReadUInt16());
m_Reader.ReadUnicodeString(m_Reader.ReadUInt16());
}
}

View file

@ -168,7 +168,7 @@ namespace Server.Network
public void Dispose()
{
Interlocked.Exchange<Socket>(ref m_Socket, null)?.Close();
Interlocked.Exchange(ref m_Socket, null)?.Close();
GC.SuppressFinalize(this);
}
}

View file

@ -22,7 +22,6 @@
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net;
namespace Server.Network

View file

@ -520,10 +520,9 @@ namespace Server.Network
private async Task ProcessSends()
{
while (true)
{
try
{
Packet p = await m_SendQueue?.DequeueAsync() ?? null;
Packet p = await m_SendQueue?.DequeueAsync();
if (p == null)
break;
@ -561,7 +560,6 @@ namespace Server.Network
{
Console.WriteLine(ex);
}
}
}
private async Task HandlePackets(MessagePump pump)

View file

@ -21,10 +21,8 @@
using Server.Diagnostics;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace Server.Network
{

View file

@ -22,7 +22,6 @@ using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipelines;
using Server.Accounting;
using Server.ContextMenus;
using Server.Diagnostics;
@ -30,13 +29,13 @@ using Server.Gumps;
using Server.HuePickers;
using Server.Items;
using Server.Menus;
using Server.Mobiles;
using Server.Prompts;
using Server.Targeting;
using CV = Server.ClientVersion;
namespace Server.Network
{
[Flags]
public enum MessageType
{
Regular = 0x00,
@ -92,14 +91,6 @@ namespace Server.Network
public static PlayCharCallback ThirdPartyAuthCallback = null, ThirdPartyHackedCallback = null;
private static byte[] m_ThirdPartyAuthKey =
{
0x9, 0x11, 0x83, (byte)'+', 0x4, 0x17, 0x83,
0x5, 0x24, 0x85,
0x7, 0x17, 0x87,
0x6, 0x19, 0x88
};
private static Dictionary<int, AuthIDPersistence> m_AuthIDWindow =
new Dictionary<int, AuthIDPersistence>(m_AuthIDWindowSize);
@ -320,7 +311,7 @@ namespace Server.Network
}
else
{
int seed = (packetId << 24) | (r.ReadByte() << 16) | (r.ReadByte() << 8) | r.ReadByte();
int seed = packetId << 24 | r.ReadByte() << 16 | r.ReadByte() << 8 | r.ReadByte();
if (seed == 0)
{
@ -2379,7 +2370,7 @@ namespace Server.Network
name, female, hue,
str, dex, intl,
info[cityIndex],
new SkillNameValue[3]
new SkillNameValue[]
{
new SkillNameValue((SkillName)is1, vs1),
new SkillNameValue((SkillName)is2, vs2),
@ -2496,7 +2487,7 @@ namespace Server.Network
name, female, hue,
str, dex, intl,
info[cityIndex],
new SkillNameValue[4]
new SkillNameValue[]
{
new SkillNameValue((SkillName)is1, vs1),
new SkillNameValue((SkillName)is2, vs2),

View file

@ -21,7 +21,6 @@
using System;
using System.Buffers;
using System.IO;
using System.IO.Pipelines;
using System.Text;
namespace Server.Network

View file

@ -21,22 +21,18 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Server.Accounting;
using Server.ContextMenus;
using Server.Diagnostics;
using Server.Gumps;
using Server.HuePickers;
using Server.Items;
using Server.Menus;
using Server.Menus.ItemLists;
using Server.Menus.Questions;
using Server.Mobiles;
using Server.Prompts;
using Server.Targeting;
@ -1745,7 +1741,7 @@ namespace Server.Network
m_Stream.Write((short)offset);
for (int i = 0; i < 8; ++i)
m_Stream.Write((byte)(content >> (i * 8)));
m_Stream.Write((byte)(content >> i * 8));
}
}
@ -2713,7 +2709,7 @@ namespace Server.Network
public sealed class SeasonChange : Packet
{
private static SeasonChange[][] m_Cache = new SeasonChange[5][]
private static SeasonChange[][] m_Cache = new SeasonChange[][]
{
new SeasonChange[2],
new SeasonChange[2],
@ -3802,7 +3798,7 @@ namespace Server.Network
[Flags]
public enum ThirdPartyFeature : ulong
{
FilterWeather = 1 << 0,
FilterWeather = 1,
FilterLight = 1 << 1,
SmartTarget = 1 << 2,
@ -4009,35 +4005,6 @@ namespace Server.Network
CharacterListFlags.OneCharacterSlot; // Limit Characters & One Character
m_Stream.Write((int)(flags | CharacterList.AdditionalFlags)); // Additional Flags
/* ThirdPartyFeature disabled = FeatureProtection.DisabledFeatures;
if (disabled != 0)
{
if (m_MD5Provider == null)
m_MD5Provider = new MD5CryptoServiceProvider();
m_Stream.UnderlyingStream.Flush();
byte[] hashCode = m_MD5Provider.ComputeHash(m_Stream.UnderlyingStream.GetBuffer(), 0,
(int)m_Stream.UnderlyingStream.Length);
byte[] buffer = new byte[28];
for (int i = 0; i < count; ++i)
{
Utility.RandomBytes(buffer);
m_Stream.Seek(35 + i * 60, SeekOrigin.Begin);
m_Stream.Write(buffer, 0, buffer.Length);
}
m_Stream.Seek(35, SeekOrigin.Begin);
m_Stream.Write((int)((long)disabled >> 32));
m_Stream.Write((int)disabled);
m_Stream.Seek(95, SeekOrigin.Begin);
m_Stream.Write(hashCode, 0, hashCode.Length);
}*/
}
}

View file

@ -27,10 +27,6 @@ namespace Server.Network
{
private BlockingCollection<T> m_Queue = new BlockingCollection<T>(new ConcurrentQueue<T>());
public SendQueue()
{
}
public void Enqueue(T t)
{
m_Queue.Add(t);