Breaks out NetState (#275)
This commit is contained in:
parent
ae523fe158
commit
a87d0e2d70
4 changed files with 213 additions and 190 deletions
25
Projects/Server/Network/IPacketEncoder.cs
Normal file
25
Projects/Server/Network/IPacketEncoder.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: IPacketEncoder.cs *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public interface IPacketEncoder
|
||||
{
|
||||
void EncodeOutgoingPacket(NetState to, ref Memory<byte> seq);
|
||||
void DecodeIncomingPacket(NetState from, ref Memory<byte> seq);
|
||||
}
|
||||
}
|
||||
129
Projects/Server/Network/NetState/NetState.ClientVersion.cs
Normal file
129
Projects/Server/Network/NetState/NetState.ClientVersion.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: NetState.ClientVersion.cs *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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.Runtime.CompilerServices;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public partial class NetState
|
||||
{
|
||||
private static readonly ClientVersion m_Version400a = new ClientVersion("4.0.0a");
|
||||
private static readonly ClientVersion m_Version407a = new ClientVersion("4.0.7a");
|
||||
private static readonly ClientVersion m_Version500a = new ClientVersion("5.0.0a");
|
||||
private static readonly ClientVersion m_Version502b = new ClientVersion("5.0.2b");
|
||||
private static readonly ClientVersion m_Version6000 = new ClientVersion("6.0.0.0");
|
||||
private static readonly ClientVersion m_Version6017 = new ClientVersion("6.0.1.7");
|
||||
private static readonly ClientVersion m_Version60142 = new ClientVersion("6.0.14.2");
|
||||
private static readonly ClientVersion m_Version7000 = new ClientVersion("7.0.0.0");
|
||||
private static readonly ClientVersion m_Version7090 = new ClientVersion("7.0.9.0");
|
||||
private static readonly ClientVersion m_Version70130 = new ClientVersion("7.0.13.0");
|
||||
private static readonly ClientVersion m_Version70160 = new ClientVersion("7.0.16.0");
|
||||
private static readonly ClientVersion m_Version70300 = new ClientVersion("7.0.30.0");
|
||||
private static readonly ClientVersion m_Version70331 = new ClientVersion("7.0.33.1");
|
||||
private static readonly ClientVersion m_Version704565 = new ClientVersion("7.0.45.65");
|
||||
private static readonly ClientVersion m_Version70500 = new ClientVersion("7.0.50.0");
|
||||
private static readonly ClientVersion m_Version70610 = new ClientVersion("7.0.61.0");
|
||||
|
||||
public ProtocolChanges ProtocolChanges { get; set; }
|
||||
public ClientFlags Flags { get; set; }
|
||||
|
||||
public ClientVersion Version
|
||||
{
|
||||
get => m_Version;
|
||||
set => ProtocolChanges = ProtocolChangesByVersion(m_Version = value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ProtocolChanges ProtocolChangesByVersion(ClientVersion version) =>
|
||||
version switch
|
||||
{
|
||||
var v when v >= m_Version70610 => ProtocolChanges.Version70610,
|
||||
var v when v >= m_Version70500 => ProtocolChanges.Version70500,
|
||||
var v when v >= m_Version704565 => ProtocolChanges.Version704565,
|
||||
var v when v >= m_Version70331 => ProtocolChanges.Version70331,
|
||||
var v when v >= m_Version70300 => ProtocolChanges.Version70300,
|
||||
var v when v >= m_Version70160 => ProtocolChanges.Version70160,
|
||||
var v when v >= m_Version70130 => ProtocolChanges.Version70130,
|
||||
var v when v >= m_Version7090 => ProtocolChanges.Version7090,
|
||||
var v when v >= m_Version7000 => ProtocolChanges.Version7000,
|
||||
var v when v >= m_Version60142 => ProtocolChanges.Version60142,
|
||||
var v when v >= m_Version6017 => ProtocolChanges.Version6017,
|
||||
var v when v >= m_Version6000 => ProtocolChanges.Version6000,
|
||||
var v when v >= m_Version502b => ProtocolChanges.Version502b,
|
||||
var v when v >= m_Version500a => ProtocolChanges.Version500a,
|
||||
var v when v >= m_Version407a => ProtocolChanges.Version407a,
|
||||
var v when v >= m_Version400a => ProtocolChanges.Version400a,
|
||||
_ => ProtocolChanges.None
|
||||
};
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool HasProtocolChanges(ProtocolChanges changes) => (ProtocolChanges & changes) != 0;
|
||||
|
||||
public bool NewSpellbook => HasProtocolChanges(ProtocolChanges.NewSpellbook);
|
||||
public bool DamagePacket => HasProtocolChanges(ProtocolChanges.DamagePacket);
|
||||
public bool Unpack => HasProtocolChanges(ProtocolChanges.Unpack);
|
||||
public bool BuffIcon => HasProtocolChanges(ProtocolChanges.BuffIcon);
|
||||
public bool NewHaven => HasProtocolChanges(ProtocolChanges.NewHaven);
|
||||
public bool ContainerGridLines => HasProtocolChanges(ProtocolChanges.ContainerGridLines);
|
||||
public bool ExtendedSupportedFeatures => HasProtocolChanges(ProtocolChanges.ExtendedSupportedFeatures);
|
||||
public bool StygianAbyss => HasProtocolChanges(ProtocolChanges.StygianAbyss);
|
||||
public bool HighSeas => HasProtocolChanges(ProtocolChanges.HighSeas);
|
||||
public bool NewCharacterList => HasProtocolChanges(ProtocolChanges.NewCharacterList);
|
||||
public bool NewCharacterCreation => HasProtocolChanges(ProtocolChanges.NewCharacterCreation);
|
||||
public bool ExtendedStatus => HasProtocolChanges(ProtocolChanges.ExtendedStatus);
|
||||
public bool NewMobileIncoming => HasProtocolChanges(ProtocolChanges.NewMobileIncoming);
|
||||
public bool NewSecureTrading => HasProtocolChanges(ProtocolChanges.NewSecureTrading);
|
||||
|
||||
public bool IsUOTDClient =>
|
||||
(Flags & ClientFlags.UOTD) != 0 || m_Version?.Type == ClientType.UOTD;
|
||||
|
||||
public bool IsSAClient => m_Version?.Type == ClientType.SA;
|
||||
|
||||
private ExpansionInfo m_Expansion;
|
||||
|
||||
public ExpansionInfo ExpansionInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Expansion != null)
|
||||
{
|
||||
for (var i = ExpansionInfo.Table.Length - 1; i >= 0; i--)
|
||||
{
|
||||
var info = ExpansionInfo.Table[i];
|
||||
|
||||
if (info.RequiredClient != null && Version >= info.RequiredClient || (Flags & info.ClientFlags) != 0)
|
||||
{
|
||||
m_Expansion = info;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Expansion == null)
|
||||
{
|
||||
ExpansionInfo.GetInfo(Expansion.None);
|
||||
}
|
||||
}
|
||||
|
||||
return m_Expansion;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SupportsExpansion(ExpansionInfo info, bool checkCoreExpansion = true) =>
|
||||
info != null && (!checkCoreExpansion || (int)Core.Expansion >= info.ID) && ExpansionInfo.ID >= info.ID;
|
||||
|
||||
public bool SupportsExpansion(Expansion ex, bool checkCoreExpansion = true) =>
|
||||
SupportsExpansion(ExpansionInfo.GetInfo(ex), checkCoreExpansion);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,82 +15,21 @@ using Server.Menus;
|
|||
|
||||
namespace Server.Network
|
||||
{
|
||||
public interface IPacketEncoder
|
||||
{
|
||||
void EncodeOutgoingPacket(NetState to, ref Memory<byte> seq);
|
||||
void DecodeIncomingPacket(NetState from, ref Memory<byte> seq);
|
||||
}
|
||||
|
||||
public delegate void NetStateCreatedCallback(NetState ns);
|
||||
|
||||
[Flags]
|
||||
public enum ProtocolChanges
|
||||
{
|
||||
NewSpellbook = 0x00000001,
|
||||
DamagePacket = 0x00000002,
|
||||
Unpack = 0x00000004,
|
||||
BuffIcon = 0x00000008,
|
||||
NewHaven = 0x00000010,
|
||||
ContainerGridLines = 0x00000020,
|
||||
ExtendedSupportedFeatures = 0x00000040,
|
||||
StygianAbyss = 0x00000080,
|
||||
HighSeas = 0x00000100,
|
||||
NewCharacterList = 0x00000200,
|
||||
NewCharacterCreation = 0x00000400,
|
||||
ExtendedStatus = 0x00000800,
|
||||
NewMobileIncoming = 0x00001000,
|
||||
NewSecureTrading = 0x00002000,
|
||||
UltimaStore = 0x00004000,
|
||||
EndlessJourney = 0x00008000,
|
||||
|
||||
Version400a = NewSpellbook,
|
||||
Version407a = Version400a | DamagePacket,
|
||||
Version500a = Version407a | Unpack,
|
||||
Version502b = Version500a | BuffIcon,
|
||||
Version6000 = Version502b | NewHaven,
|
||||
Version6017 = Version6000 | ContainerGridLines,
|
||||
Version60142 = Version6017 | ExtendedSupportedFeatures,
|
||||
Version7000 = Version60142 | StygianAbyss,
|
||||
Version7090 = Version7000 | HighSeas,
|
||||
Version70130 = Version7090 | NewCharacterList,
|
||||
Version70160 = Version70130 | NewCharacterCreation,
|
||||
Version70300 = Version70160 | ExtendedStatus,
|
||||
Version70331 = Version70300 | NewMobileIncoming,
|
||||
Version704565 = Version70331 | NewSecureTrading,
|
||||
Version70500 = Version704565 | UltimaStore,
|
||||
Version70610 = Version70500 | EndlessJourney
|
||||
}
|
||||
|
||||
public class AsyncState
|
||||
{
|
||||
public AsyncState(bool paused) => Paused = paused;
|
||||
public bool Paused { get; set; }
|
||||
}
|
||||
|
||||
public class NetState : IComparable<NetState>
|
||||
public partial class NetState : IComparable<NetState>
|
||||
{
|
||||
private static readonly AsyncState m_PauseState = new AsyncState(true);
|
||||
private static readonly AsyncState m_ResumeState = new AsyncState(false);
|
||||
|
||||
private static AsyncState m_AsyncState = m_ResumeState;
|
||||
|
||||
private static readonly ClientVersion m_Version400a = new ClientVersion("4.0.0a");
|
||||
private static readonly ClientVersion m_Version407a = new ClientVersion("4.0.7a");
|
||||
private static readonly ClientVersion m_Version500a = new ClientVersion("5.0.0a");
|
||||
private static readonly ClientVersion m_Version502b = new ClientVersion("5.0.2b");
|
||||
private static readonly ClientVersion m_Version6000 = new ClientVersion("6.0.0.0");
|
||||
private static readonly ClientVersion m_Version6017 = new ClientVersion("6.0.1.7");
|
||||
private static readonly ClientVersion m_Version60142 = new ClientVersion("6.0.14.2");
|
||||
private static readonly ClientVersion m_Version7000 = new ClientVersion("7.0.0.0");
|
||||
private static readonly ClientVersion m_Version7090 = new ClientVersion("7.0.9.0");
|
||||
private static readonly ClientVersion m_Version70130 = new ClientVersion("7.0.13.0");
|
||||
private static readonly ClientVersion m_Version70160 = new ClientVersion("7.0.16.0");
|
||||
private static readonly ClientVersion m_Version70300 = new ClientVersion("7.0.30.0");
|
||||
private static readonly ClientVersion m_Version70331 = new ClientVersion("7.0.33.1");
|
||||
private static readonly ClientVersion m_Version704565 = new ClientVersion("7.0.45.65");
|
||||
private static readonly ClientVersion m_Version70500 = new ClientVersion("7.0.50.0");
|
||||
private static readonly ClientVersion m_Version70610 = new ClientVersion("7.0.61.0");
|
||||
|
||||
private static readonly ConcurrentQueue<NetState> m_Disposed = new ConcurrentQueue<NetState>();
|
||||
private readonly string m_ToString;
|
||||
internal int m_AuthID;
|
||||
|
|
@ -151,104 +90,6 @@ namespace Server.Network
|
|||
|
||||
public bool BlockAllPackets { get; set; }
|
||||
|
||||
public ClientFlags Flags { get; set; }
|
||||
|
||||
public ClientVersion Version
|
||||
{
|
||||
get => m_Version;
|
||||
set
|
||||
{
|
||||
m_Version = value;
|
||||
|
||||
if (value >= m_Version70610)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version70610;
|
||||
}
|
||||
|
||||
if (value >= m_Version70500)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version70500;
|
||||
}
|
||||
|
||||
if (value >= m_Version704565)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version704565;
|
||||
}
|
||||
else if (value >= m_Version70331)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version70331;
|
||||
}
|
||||
else if (value >= m_Version70300)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version70300;
|
||||
}
|
||||
else if (value >= m_Version70160)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version70160;
|
||||
}
|
||||
else if (value >= m_Version70130)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version70130;
|
||||
}
|
||||
else if (value >= m_Version7090)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version7090;
|
||||
}
|
||||
else if (value >= m_Version7000)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version7000;
|
||||
}
|
||||
else if (value >= m_Version60142)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version60142;
|
||||
}
|
||||
else if (value >= m_Version6017)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version6017;
|
||||
}
|
||||
else if (value >= m_Version6000)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version6000;
|
||||
}
|
||||
else if (value >= m_Version502b)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version502b;
|
||||
}
|
||||
else if (value >= m_Version500a)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version500a;
|
||||
}
|
||||
else if (value >= m_Version407a)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version407a;
|
||||
}
|
||||
else if (value >= m_Version400a)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Version400a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NewSpellbook => (ProtocolChanges & ProtocolChanges.NewSpellbook) != 0;
|
||||
public bool DamagePacket => (ProtocolChanges & ProtocolChanges.DamagePacket) != 0;
|
||||
public bool Unpack => (ProtocolChanges & ProtocolChanges.Unpack) != 0;
|
||||
public bool BuffIcon => (ProtocolChanges & ProtocolChanges.BuffIcon) != 0;
|
||||
public bool NewHaven => (ProtocolChanges & ProtocolChanges.NewHaven) != 0;
|
||||
public bool ContainerGridLines => (ProtocolChanges & ProtocolChanges.ContainerGridLines) != 0;
|
||||
public bool ExtendedSupportedFeatures => (ProtocolChanges & ProtocolChanges.ExtendedSupportedFeatures) != 0;
|
||||
public bool StygianAbyss => (ProtocolChanges & ProtocolChanges.StygianAbyss) != 0;
|
||||
public bool HighSeas => (ProtocolChanges & ProtocolChanges.HighSeas) != 0;
|
||||
public bool NewCharacterList => (ProtocolChanges & ProtocolChanges.NewCharacterList) != 0;
|
||||
public bool NewCharacterCreation => (ProtocolChanges & ProtocolChanges.NewCharacterCreation) != 0;
|
||||
public bool ExtendedStatus => (ProtocolChanges & ProtocolChanges.ExtendedStatus) != 0;
|
||||
public bool NewMobileIncoming => (ProtocolChanges & ProtocolChanges.NewMobileIncoming) != 0;
|
||||
public bool NewSecureTrading => (ProtocolChanges & ProtocolChanges.NewSecureTrading) != 0;
|
||||
|
||||
public bool IsUOTDClient =>
|
||||
(Flags & ClientFlags.UOTD) != 0 || m_Version?.Type == ClientType.UOTD;
|
||||
|
||||
public bool IsSAClient => m_Version?.Type == ClientType.SA;
|
||||
|
||||
public List<SecureTrade> Trades { get; }
|
||||
|
||||
public bool Seeded { get; set; }
|
||||
|
|
@ -281,28 +122,6 @@ namespace Server.Network
|
|||
|
||||
public bool IsDisposing => m_Disposing != 0;
|
||||
|
||||
public ExpansionInfo ExpansionInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
for (var i = ExpansionInfo.Table.Length - 1; i >= 0; i--)
|
||||
{
|
||||
var info = ExpansionInfo.Table[i];
|
||||
|
||||
if (info.RequiredClient != null && Version >= info.RequiredClient || (Flags & info.ClientFlags) != 0)
|
||||
{
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
return ExpansionInfo.GetInfo(Expansion.None);
|
||||
}
|
||||
}
|
||||
|
||||
public Expansion Expansion => (Expansion)ExpansionInfo.ID;
|
||||
|
||||
public ProtocolChanges ProtocolChanges { get; set; }
|
||||
|
||||
public int CompareTo(NetState other) => other == null ? 1 : m_ToString.CompareTo(other.m_ToString);
|
||||
|
||||
public void ValidateAllTrades()
|
||||
|
|
@ -696,13 +515,5 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SupportsExpansion(ExpansionInfo info, bool checkCoreExpansion = true) =>
|
||||
info != null && (!checkCoreExpansion || (int)Core.Expansion >= info.ID) && (info.RequiredClient != null
|
||||
? Version >= info.RequiredClient
|
||||
: (Flags & info.ClientFlags) != 0);
|
||||
|
||||
public bool SupportsExpansion(Expansion ex, bool checkCoreExpansion = true) =>
|
||||
SupportsExpansion(ExpansionInfo.GetInfo(ex), checkCoreExpansion);
|
||||
}
|
||||
}
|
||||
58
Projects/Server/Network/NetState/ProtocolChanges.cs
Normal file
58
Projects/Server/Network/NetState/ProtocolChanges.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ProtocolChanges.cs *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
[Flags]
|
||||
public enum ProtocolChanges
|
||||
{
|
||||
None = 0x00000000,
|
||||
NewSpellbook = 0x00000001,
|
||||
DamagePacket = 0x00000002,
|
||||
Unpack = 0x00000004,
|
||||
BuffIcon = 0x00000008,
|
||||
NewHaven = 0x00000010,
|
||||
ContainerGridLines = 0x00000020,
|
||||
ExtendedSupportedFeatures = 0x00000040,
|
||||
StygianAbyss = 0x00000080,
|
||||
HighSeas = 0x00000100,
|
||||
NewCharacterList = 0x00000200,
|
||||
NewCharacterCreation = 0x00000400,
|
||||
ExtendedStatus = 0x00000800,
|
||||
NewMobileIncoming = 0x00001000,
|
||||
NewSecureTrading = 0x00002000,
|
||||
UltimaStore = 0x00004000,
|
||||
EndlessJourney = 0x00008000,
|
||||
|
||||
Version400a = NewSpellbook,
|
||||
Version407a = Version400a | DamagePacket,
|
||||
Version500a = Version407a | Unpack,
|
||||
Version502b = Version500a | BuffIcon,
|
||||
Version6000 = Version502b | NewHaven,
|
||||
Version6017 = Version6000 | ContainerGridLines,
|
||||
Version60142 = Version6017 | ExtendedSupportedFeatures,
|
||||
Version7000 = Version60142 | StygianAbyss,
|
||||
Version7090 = Version7000 | HighSeas,
|
||||
Version70130 = Version7090 | NewCharacterList,
|
||||
Version70160 = Version70130 | NewCharacterCreation,
|
||||
Version70300 = Version70160 | ExtendedStatus,
|
||||
Version70331 = Version70300 | NewMobileIncoming,
|
||||
Version704565 = Version70331 | NewSecureTrading,
|
||||
Version70500 = Version704565 | UltimaStore,
|
||||
Version70610 = Version70500 | EndlessJourney
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue