Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)
This commit is contained in:
parent
e748af4430
commit
513e54f70e
1094 changed files with 15913 additions and 21892 deletions
|
|
@ -35,11 +35,7 @@ namespace Server.Network
|
|||
private Queue<Socket> m_Accepted;
|
||||
private object m_AcceptedSyncRoot;
|
||||
|
||||
#if NewAsyncSockets
|
||||
private SocketAsyncEventArgs m_EventArgs;
|
||||
#else
|
||||
private AsyncCallback m_OnAccept;
|
||||
#endif
|
||||
|
||||
private static Socket[] m_EmptySockets = new Socket[0];
|
||||
|
||||
|
|
@ -57,19 +53,9 @@ namespace Server.Network
|
|||
|
||||
DisplayListener();
|
||||
|
||||
#if NewAsyncSockets
|
||||
m_EventArgs = new SocketAsyncEventArgs();
|
||||
m_EventArgs.Completed += Accept_Completion;
|
||||
Accept_Start();
|
||||
#else
|
||||
m_OnAccept = new AsyncCallback( OnAccept );
|
||||
try {
|
||||
IAsyncResult res = m_Listener.BeginAccept( m_OnAccept, m_Listener );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
} catch ( ObjectDisposedException ) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private Socket Bind(IPEndPoint ipep)
|
||||
|
|
@ -144,10 +130,9 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
|
||||
#if NewAsyncSockets
|
||||
private void Accept_Start()
|
||||
{
|
||||
bool result = false;
|
||||
bool result;
|
||||
|
||||
do
|
||||
{
|
||||
|
|
@ -187,36 +172,6 @@ namespace Server.Network
|
|||
e.AcceptSocket = null;
|
||||
}
|
||||
|
||||
#else
|
||||
private void OnAccept( IAsyncResult asyncResult ) {
|
||||
Socket listener = (Socket) asyncResult.AsyncState;
|
||||
|
||||
Socket accepted = null;
|
||||
|
||||
try {
|
||||
accepted = listener.EndAccept( asyncResult );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
} catch ( ObjectDisposedException ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( accepted != null ) {
|
||||
if ( VerifySocket( accepted ) ) {
|
||||
Enqueue( accepted );
|
||||
} else {
|
||||
Release( accepted );
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
listener.BeginAccept( m_OnAccept, listener );
|
||||
} catch ( SocketException ex ) {
|
||||
NetState.TraceException( ex );
|
||||
} catch ( ObjectDisposedException ) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private bool VerifySocket(Socket socket)
|
||||
{
|
||||
|
|
@ -299,4 +254,4 @@ namespace Server.Network
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ namespace Server.Network
|
|||
|
||||
ThrottlePacketCallback throttler = handler.ThrottleCallback;
|
||||
|
||||
if (throttler != null && !throttler(ns))
|
||||
if (throttler?.Invoke(ns) == false)
|
||||
{
|
||||
m_Throttled.Enqueue(ns);
|
||||
return;
|
||||
|
|
@ -260,7 +260,8 @@ namespace Server.Network
|
|||
|
||||
PacketReceiveProfile prof = null;
|
||||
|
||||
if (Core.Profiling) prof = PacketReceiveProfile.Acquire(packetID);
|
||||
if (Core.Profiling)
|
||||
prof = PacketReceiveProfile.Acquire(packetID);
|
||||
|
||||
prof?.Start();
|
||||
|
||||
|
|
@ -286,4 +287,4 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,11 +48,8 @@ namespace Server.Network
|
|||
private byte[] m_RecvBuffer;
|
||||
private SendQueue m_SendQueue;
|
||||
|
||||
#if NewAsyncSockets
|
||||
private SocketAsyncEventArgs m_ReceiveEventArgs, m_SendEventArgs;
|
||||
#else
|
||||
private AsyncCallback m_OnReceive, m_OnSend;
|
||||
#endif
|
||||
private SocketAsyncEventArgs m_ReceiveEventArgs;
|
||||
private SocketAsyncEventArgs m_SendEventArgs;
|
||||
|
||||
private MessagePump m_MessagePump;
|
||||
private string m_ToString;
|
||||
|
|
@ -451,62 +448,7 @@ namespace Server.Network
|
|||
|
||||
byte[] buffer = p.Compile(CompressionEnabled, out int length);
|
||||
|
||||
if (buffer != null)
|
||||
{
|
||||
if (buffer.Length <= 0 || length <= 0)
|
||||
{
|
||||
p.OnSend();
|
||||
return;
|
||||
}
|
||||
|
||||
PacketSendProfile prof = null;
|
||||
|
||||
if (Core.Profiling) prof = PacketSendProfile.Acquire(p.GetType());
|
||||
|
||||
prof?.Start();
|
||||
|
||||
PacketEncoder?.EncodeOutgoingPacket(this, ref buffer, ref length);
|
||||
|
||||
try
|
||||
{
|
||||
SendQueue.Gram gram;
|
||||
|
||||
lock (_sendL)
|
||||
{
|
||||
lock (m_SendQueue)
|
||||
{
|
||||
gram = m_SendQueue.Enqueue(buffer, length);
|
||||
}
|
||||
|
||||
if (gram != null && !_sending)
|
||||
{
|
||||
_sending = true;
|
||||
#if NewAsyncSockets
|
||||
m_SendEventArgs.SetBuffer(gram.Buffer, 0, gram.Length);
|
||||
Send_Start();
|
||||
#else
|
||||
try {
|
||||
m_Socket.BeginSend(gram.Buffer, 0, gram.Length, SocketFlags.None, m_OnSend, m_Socket);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
TraceException(ex);
|
||||
Dispose(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CapacityExceededException)
|
||||
{
|
||||
Console.WriteLine("Client: {0}: Too much data pending, disconnecting...", this);
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
p.OnSend();
|
||||
|
||||
prof?.Finish(length);
|
||||
}
|
||||
else
|
||||
if (buffer == null)
|
||||
{
|
||||
Console.WriteLine("Client: {0}: null buffer send, disconnecting...", this);
|
||||
using (StreamWriter op = new StreamWriter("null_send.log", true))
|
||||
|
|
@ -516,10 +458,53 @@ namespace Server.Network
|
|||
}
|
||||
|
||||
Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer.Length <= 0 || length <= 0)
|
||||
{
|
||||
p.OnSend();
|
||||
return;
|
||||
}
|
||||
|
||||
PacketSendProfile prof = null;
|
||||
|
||||
if (Core.Profiling)
|
||||
prof = PacketSendProfile.Acquire(p.GetType());
|
||||
|
||||
prof?.Start();
|
||||
|
||||
PacketEncoder?.EncodeOutgoingPacket(this, ref buffer, ref length);
|
||||
|
||||
try
|
||||
{
|
||||
lock (_sendL)
|
||||
{
|
||||
SendQueue.Gram gram;
|
||||
lock (m_SendQueue)
|
||||
{
|
||||
gram = m_SendQueue.Enqueue(buffer, length);
|
||||
}
|
||||
|
||||
if (gram != null && !_sending)
|
||||
{
|
||||
_sending = true;
|
||||
m_SendEventArgs.SetBuffer(gram.Buffer, 0, gram.Length);
|
||||
Send_Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CapacityExceededException)
|
||||
{
|
||||
Console.WriteLine("Client: {0}: Too much data pending, disconnecting...", this);
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
p.OnSend();
|
||||
|
||||
prof?.Finish(length);
|
||||
}
|
||||
|
||||
#if NewAsyncSockets
|
||||
public void Start()
|
||||
{
|
||||
m_ReceiveEventArgs = new SocketAsyncEventArgs();
|
||||
|
|
@ -582,7 +567,8 @@ namespace Server.Network
|
|||
return;
|
||||
}
|
||||
|
||||
if (IsDisposing) return;
|
||||
if (IsDisposing)
|
||||
return;
|
||||
|
||||
m_NextCheckActivity = Core.TickCount + 90000;
|
||||
|
||||
|
|
@ -607,7 +593,7 @@ namespace Server.Network
|
|||
{
|
||||
try
|
||||
{
|
||||
bool result = false;
|
||||
bool result;
|
||||
|
||||
do
|
||||
{
|
||||
|
|
@ -736,190 +722,10 @@ namespace Server.Network
|
|||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
public void Start() {
|
||||
m_OnReceive = new AsyncCallback( OnReceive );
|
||||
m_OnSend = new AsyncCallback( OnSend );
|
||||
|
||||
m_Running = true;
|
||||
|
||||
if ( m_Socket == null || m_Paused ) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
lock ( m_AsyncLock ) {
|
||||
if ( ( m_AsyncState & ( AsyncState.Pending | AsyncState.Paused ) ) == 0 ) {
|
||||
InternalBeginReceive();
|
||||
}
|
||||
}
|
||||
} catch ( Exception ex ) {
|
||||
TraceException( ex );
|
||||
Dispose( false );
|
||||
}
|
||||
}
|
||||
|
||||
private void InternalBeginReceive() {
|
||||
m_AsyncState |= AsyncState.Pending;
|
||||
|
||||
m_Socket.BeginReceive( m_RecvBuffer, 0, m_RecvBuffer.Length, SocketFlags.None, m_OnReceive, m_Socket );
|
||||
}
|
||||
|
||||
private void OnReceive( IAsyncResult asyncResult ) {
|
||||
Socket s = (Socket)asyncResult.AsyncState;
|
||||
|
||||
try {
|
||||
int byteCount = s.EndReceive( asyncResult );
|
||||
|
||||
if ( byteCount > 0 ) {
|
||||
m_NextCheckActivity = Core.TickCount + 90000;
|
||||
|
||||
byte[] buffer = m_RecvBuffer;
|
||||
|
||||
if ( m_Encoder != null )
|
||||
m_Encoder.DecodeIncomingPacket( this, ref buffer, ref byteCount );
|
||||
|
||||
lock ( m_Buffer )
|
||||
m_Buffer.Enqueue( buffer, 0, byteCount );
|
||||
|
||||
m_MessagePump.OnReceive( this );
|
||||
|
||||
lock ( m_AsyncLock ) {
|
||||
m_AsyncState &= ~AsyncState.Pending;
|
||||
|
||||
if ( ( m_AsyncState & AsyncState.Paused ) == 0 ) {
|
||||
try {
|
||||
InternalBeginReceive();
|
||||
} catch ( Exception ex ) {
|
||||
TraceException( ex );
|
||||
Dispose( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Dispose( false );
|
||||
}
|
||||
} catch {
|
||||
Dispose( false );
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSend( IAsyncResult asyncResult ) {
|
||||
Socket s = (Socket)asyncResult.AsyncState;
|
||||
|
||||
try {
|
||||
int bytes = s.EndSend( asyncResult );
|
||||
|
||||
if ( bytes <= 0 ) {
|
||||
Dispose( false );
|
||||
return;
|
||||
}
|
||||
|
||||
m_NextCheckActivity = Core.TickCount + 90000;
|
||||
|
||||
if (m_CoalesceSleep >= 0) {
|
||||
Thread.Sleep(m_CoalesceSleep);
|
||||
}
|
||||
|
||||
SendQueue.Gram gram;
|
||||
|
||||
lock (m_SendQueue) {
|
||||
gram = m_SendQueue.Dequeue();
|
||||
|
||||
if (gram == null && m_SendQueue.IsFlushReady)
|
||||
gram = m_SendQueue.CheckFlushReady();
|
||||
}
|
||||
|
||||
if (gram != null) {
|
||||
try {
|
||||
s.BeginSend(gram.Buffer, 0, gram.Length, SocketFlags.None, m_OnSend, s);
|
||||
} catch (Exception ex) {
|
||||
TraceException(ex);
|
||||
Dispose(false);
|
||||
}
|
||||
} else {
|
||||
lock (_sendL)
|
||||
_sending = false;
|
||||
}
|
||||
} catch ( Exception ){
|
||||
Dispose( false );
|
||||
}
|
||||
}
|
||||
|
||||
public static void Pause() {
|
||||
m_Paused = true;
|
||||
|
||||
for ( int i = 0; i < m_Instances.Count; ++i ) {
|
||||
NetState ns = m_Instances[i];
|
||||
|
||||
lock ( ns.m_AsyncLock ) {
|
||||
ns.m_AsyncState |= AsyncState.Paused;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Resume() {
|
||||
m_Paused = false;
|
||||
|
||||
for ( int i = 0; i < m_Instances.Count; ++i ) {
|
||||
NetState ns = m_Instances[i];
|
||||
|
||||
if ( ns.m_Socket == null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lock ( ns.m_AsyncLock ) {
|
||||
ns.m_AsyncState &= ~AsyncState.Paused;
|
||||
|
||||
try {
|
||||
if ( ( ns.m_AsyncState & AsyncState.Pending ) == 0 )
|
||||
ns.InternalBeginReceive();
|
||||
} catch ( Exception ex ) {
|
||||
TraceException( ex );
|
||||
ns.Dispose( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Flush() {
|
||||
if (m_Socket == null)
|
||||
return false;
|
||||
|
||||
lock (_sendL) {
|
||||
if (_sending)
|
||||
return false;
|
||||
|
||||
SendQueue.Gram gram;
|
||||
|
||||
lock (m_SendQueue) {
|
||||
if (!m_SendQueue.IsFlushReady)
|
||||
return false;
|
||||
|
||||
gram = m_SendQueue.CheckFlushReady();
|
||||
}
|
||||
|
||||
if (gram != null) {
|
||||
try {
|
||||
_sending = true;
|
||||
m_Socket.BeginSend(gram.Buffer, 0, gram.Length, SocketFlags.None, m_OnSend, m_Socket);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
TraceException(ex);
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
public PacketHandler GetHandler(int packetID)
|
||||
{
|
||||
if (ContainerGridLines)
|
||||
return PacketHandlers.Get6017Handler(packetID);
|
||||
return PacketHandlers.GetHandler(packetID);
|
||||
return ContainerGridLines ? PacketHandlers.Get6017Handler(packetID) :
|
||||
PacketHandlers.GetHandler(packetID);
|
||||
}
|
||||
|
||||
public static void FlushAll()
|
||||
|
|
@ -937,13 +743,10 @@ namespace Server.Network
|
|||
|
||||
public void CheckAlive(long curTicks)
|
||||
{
|
||||
if (Socket == null)
|
||||
if (Socket == null || m_NextCheckActivity - curTicks >= 0)
|
||||
return;
|
||||
|
||||
if (m_NextCheckActivity - curTicks >= 0) return;
|
||||
|
||||
Console.WriteLine("Client: {0}: Disconnecting due to inactivity...", this);
|
||||
|
||||
Dispose();
|
||||
}
|
||||
|
||||
|
|
@ -966,6 +769,7 @@ namespace Server.Network
|
|||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
try
|
||||
|
|
@ -974,19 +778,16 @@ namespace Server.Network
|
|||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDisposing{ get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
public virtual void Dispose(bool flush = true)
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
public virtual void Dispose(bool flush)
|
||||
{
|
||||
if (Socket == null || IsDisposing) return;
|
||||
if (Socket == null || IsDisposing)
|
||||
return;
|
||||
|
||||
IsDisposing = true;
|
||||
|
||||
|
|
@ -1022,13 +823,8 @@ namespace Server.Network
|
|||
Buffer = null;
|
||||
m_RecvBuffer = null;
|
||||
|
||||
#if NewAsyncSockets
|
||||
m_ReceiveEventArgs = null;
|
||||
m_SendEventArgs = null;
|
||||
#else
|
||||
m_OnReceive = null;
|
||||
m_OnSend = null;
|
||||
#endif
|
||||
|
||||
Running = false;
|
||||
|
||||
|
|
@ -1132,38 +928,22 @@ namespace Server.Network
|
|||
|
||||
public Expansion Expansion => (Expansion)ExpansionInfo.ID;
|
||||
|
||||
public bool SupportsExpansion(ExpansionInfo info, bool checkCoreExpansion)
|
||||
public bool SupportsExpansion(ExpansionInfo info, bool checkCoreExpansion = true)
|
||||
{
|
||||
if (info == null || checkCoreExpansion && (int)Core.Expansion < info.ID)
|
||||
return false;
|
||||
|
||||
if (info.RequiredClient != null)
|
||||
return Version >= info.RequiredClient;
|
||||
|
||||
return (Flags & info.ClientFlags) != 0;
|
||||
return info.RequiredClient != null ? Version >= info.RequiredClient : (Flags & info.ClientFlags) != 0;
|
||||
}
|
||||
|
||||
public bool SupportsExpansion(Expansion ex, bool checkCoreExpansion)
|
||||
public bool SupportsExpansion(Expansion ex, bool checkCoreExpansion = true)
|
||||
{
|
||||
return SupportsExpansion(ExpansionInfo.GetInfo(ex), checkCoreExpansion);
|
||||
}
|
||||
|
||||
public bool SupportsExpansion(Expansion ex)
|
||||
{
|
||||
return SupportsExpansion(ex, true);
|
||||
}
|
||||
|
||||
public bool SupportsExpansion(ExpansionInfo info)
|
||||
{
|
||||
return SupportsExpansion(info, true);
|
||||
}
|
||||
|
||||
public int CompareTo(NetState other)
|
||||
{
|
||||
if (other == null)
|
||||
return 1;
|
||||
|
||||
return m_ToString.CompareTo(other.m_ToString);
|
||||
return other == null ? 1 : m_ToString.CompareTo(other.m_ToString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -801,6 +801,7 @@ namespace Server.Network
|
|||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -1025,10 +1026,7 @@ namespace Server.Network
|
|||
if (!valid) return;
|
||||
|
||||
pvSrc.Seek(5, SeekOrigin.Current);
|
||||
Mobile to = World.FindMobile(pvSrc.ReadUInt32());
|
||||
|
||||
if (to == null)
|
||||
to = from;
|
||||
Mobile to = World.FindMobile(pvSrc.ReadUInt32()) ?? from;
|
||||
|
||||
if (!to.AllowEquipFrom(from) || !to.EquipItem(item))
|
||||
item.Bounce(from);
|
||||
|
|
@ -1478,14 +1476,14 @@ namespace Server.Network
|
|||
{
|
||||
Mobile m = World.FindMobile(s);
|
||||
|
||||
if (m != null && !m.Deleted)
|
||||
if (m?.Deleted == false)
|
||||
from.Use(m);
|
||||
}
|
||||
else if (s.IsItem)
|
||||
{
|
||||
Item item = World.FindItem(s);
|
||||
|
||||
if (item != null && !item.Deleted)
|
||||
if (item?.Deleted == false)
|
||||
from.Use(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -1525,7 +1523,7 @@ namespace Server.Network
|
|||
{
|
||||
Item item = World.FindItem(s);
|
||||
|
||||
if (item != null && !item.Deleted && from.CanSee(item) &&
|
||||
if (item?.Deleted == false && from.CanSee(item) &&
|
||||
Utility.InUpdateRange(from.Location, item.GetWorldLocation()))
|
||||
{
|
||||
if (SingleClickProps)
|
||||
|
|
@ -1705,7 +1703,7 @@ namespace Server.Network
|
|||
{
|
||||
Item item = World.FindItem(s);
|
||||
|
||||
if (item != null && !item.Deleted && from.CanSee(item) &&
|
||||
if (item?.Deleted == false && from.CanSee(item) &&
|
||||
Utility.InUpdateRange(from.Location, item.GetWorldLocation()))
|
||||
item.SendPropertiesTo(from);
|
||||
}
|
||||
|
|
@ -1732,7 +1730,7 @@ namespace Server.Network
|
|||
{
|
||||
Item item = World.FindItem(s);
|
||||
|
||||
if (item != null && !item.Deleted && from.CanSee(item) &&
|
||||
if (item?.Deleted == false && from.CanSee(item) &&
|
||||
Utility.InUpdateRange(from.Location, item.GetWorldLocation()))
|
||||
item.SendPropertiesTo(from);
|
||||
}
|
||||
|
|
@ -2374,13 +2372,10 @@ namespace Server.Network
|
|||
|
||||
bool female = genderRace % 2 != 0;
|
||||
|
||||
Race race = null;
|
||||
Race race;
|
||||
|
||||
byte raceID = (byte)(genderRace < 4 ? 0 : genderRace / 2 - 1);
|
||||
race = Race.Races[raceID];
|
||||
|
||||
if (race == null)
|
||||
race = Race.DefaultRace;
|
||||
race = Race.Races[raceID] ?? Race.DefaultRace;
|
||||
|
||||
CityInfo[] info = state.CityInfo;
|
||||
IAccount a = state.Account;
|
||||
|
|
|
|||
|
|
@ -44,18 +44,11 @@ namespace Server.Network
|
|||
/// </summary>
|
||||
private MemoryStream m_Stream;
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new PacketWriter instance with the default capacity of 4 bytes.
|
||||
/// </summary>
|
||||
public PacketWriter() : this(32)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a new PacketWriter instance with a given capacity.
|
||||
/// </summary>
|
||||
/// <param name="capacity">Initial capacity for the internal stream.</param>
|
||||
public PacketWriter(int capacity)
|
||||
public PacketWriter(int capacity = 32)
|
||||
{
|
||||
m_Stream = new MemoryStream(capacity);
|
||||
m_Capacity = capacity;
|
||||
|
|
@ -103,10 +96,7 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
|
||||
if (pw == null)
|
||||
pw = new PacketWriter(capacity);
|
||||
|
||||
return pw;
|
||||
return pw ?? new PacketWriter(capacity);
|
||||
}
|
||||
|
||||
public static void ReleaseInstance(PacketWriter pw)
|
||||
|
|
@ -456,4 +446,4 @@ namespace Server.Network
|
|||
return m_Stream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -382,10 +382,7 @@ namespace Server.Network
|
|||
|
||||
m_Stream.Write(bis.Price);
|
||||
|
||||
string desc = bis.Description;
|
||||
|
||||
if (desc == null)
|
||||
desc = "";
|
||||
string desc = bis.Description ?? "";
|
||||
|
||||
m_Stream.Write((byte)(desc.Length + 1));
|
||||
m_Stream.WriteAsciiNull(desc);
|
||||
|
|
@ -466,11 +463,7 @@ namespace Server.Network
|
|||
m_Stream.Write(m.Serial);
|
||||
m_Stream.Write((byte)0);
|
||||
|
||||
int lockBits = 0;
|
||||
|
||||
lockBits |= (int)m.StrLock << 4;
|
||||
lockBits |= (int)m.DexLock << 2;
|
||||
lockBits |= (int)m.IntLock;
|
||||
int lockBits = (int)m.StrLock << 4 | (int)m.DexLock << 2 | (int)m.IntLock;
|
||||
|
||||
m_Stream.Write((byte)lockBits);
|
||||
}
|
||||
|
|
@ -478,11 +471,7 @@ namespace Server.Network
|
|||
|
||||
public class EquipInfoAttribute
|
||||
{
|
||||
public EquipInfoAttribute(int number) : this(number, -1)
|
||||
{
|
||||
}
|
||||
|
||||
public EquipInfoAttribute(int number, int charges)
|
||||
public EquipInfoAttribute(int number, int charges = -1)
|
||||
{
|
||||
Number = number;
|
||||
Charges = charges;
|
||||
|
|
@ -1070,7 +1059,7 @@ namespace Server.Network
|
|||
// +2 - Hue
|
||||
// +1 - Flags
|
||||
|
||||
uint serial = (uint)item.Serial.Value;
|
||||
uint serial = item.Serial.Value;
|
||||
int itemID = item.ItemID & 0x3FFF;
|
||||
int amount = item.Amount;
|
||||
Point3D loc = item.Location;
|
||||
|
|
@ -2441,10 +2430,7 @@ namespace Server.Network
|
|||
|
||||
for (int i = 0; i < strings.Count; ++i)
|
||||
{
|
||||
string v = strings[i];
|
||||
|
||||
if (v == null)
|
||||
v = string.Empty;
|
||||
string v = strings[i] ?? "";
|
||||
|
||||
m_Strings.Write((ushort)v.Length);
|
||||
m_Strings.WriteBigUniFixed(v, v.Length);
|
||||
|
|
@ -2603,10 +2589,7 @@ namespace Server.Network
|
|||
|
||||
for (int i = 0; i < text.Count; ++i)
|
||||
{
|
||||
string v = text[i];
|
||||
|
||||
if (v == null)
|
||||
v = string.Empty;
|
||||
string v = text[i] ?? "";
|
||||
|
||||
int length = (ushort)v.Length;
|
||||
|
||||
|
|
@ -2639,13 +2622,11 @@ namespace Server.Network
|
|||
|
||||
for (int i = 0; i < text.Length; ++i)
|
||||
{
|
||||
string v = text[i];
|
||||
string v = text[i] ?? "";
|
||||
|
||||
if (v == null) v = "";
|
||||
ushort length = (ushort)v.Length;
|
||||
|
||||
int length = (ushort)v.Length;
|
||||
|
||||
m_Stream.Write((ushort)length);
|
||||
m_Stream.Write(length);
|
||||
m_Stream.WriteBigUniFixed(v, length);
|
||||
}
|
||||
}
|
||||
|
|
@ -2774,11 +2755,7 @@ namespace Server.Network
|
|||
new SeasonChange[2]
|
||||
};
|
||||
|
||||
public SeasonChange(int season) : this(season, true)
|
||||
{
|
||||
}
|
||||
|
||||
public SeasonChange(int season, bool playSound) : base(0xBC, 3)
|
||||
public SeasonChange(int season, bool playSound = true) : base(0xBC, 3)
|
||||
{
|
||||
m_Stream.Write((byte)season);
|
||||
m_Stream.Write(playSound);
|
||||
|
|
@ -2979,14 +2956,10 @@ namespace Server.Network
|
|||
{
|
||||
public MobileName(Mobile m) : base(0x98)
|
||||
{
|
||||
string name = m.Name;
|
||||
|
||||
if (name == null) name = "";
|
||||
|
||||
EnsureCapacity(37);
|
||||
|
||||
m_Stream.Write(m.Serial);
|
||||
m_Stream.WriteAsciiFixed(name, 30);
|
||||
m_Stream.WriteAsciiFixed(m.Name ?? "", 30);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3020,13 +2993,10 @@ namespace Server.Network
|
|||
{
|
||||
public MobileStatusCompact(bool canBeRenamed, Mobile m) : base(0x11)
|
||||
{
|
||||
string name = m.Name;
|
||||
if (name == null) name = "";
|
||||
|
||||
EnsureCapacity(43);
|
||||
|
||||
m_Stream.Write(m.Serial);
|
||||
m_Stream.WriteAsciiFixed(name, 30);
|
||||
m_Stream.WriteAsciiFixed(m.Name ?? "", 30);
|
||||
|
||||
AttributeNormalizer.WriteReverse(m_Stream, m.Hits, m.HitsMax);
|
||||
|
||||
|
|
@ -3044,17 +3014,16 @@ namespace Server.Network
|
|||
|
||||
public MobileStatusExtended(Mobile m, NetState ns) : base(0x11)
|
||||
{
|
||||
string name = m.Name;
|
||||
if (name == null) name = "";
|
||||
string name = m.Name ?? "";
|
||||
|
||||
int type;
|
||||
|
||||
if (Core.HS && ns != null && ns.ExtendedStatus)
|
||||
if (Core.HS && ns?.ExtendedStatus == true)
|
||||
{
|
||||
type = 6;
|
||||
EnsureCapacity(121);
|
||||
}
|
||||
else if (Core.ML && ns != null && ns.SupportsExpansion(Expansion.ML))
|
||||
else if (Core.ML && ns?.SupportsExpansion(Expansion.ML) == true)
|
||||
{
|
||||
type = 5;
|
||||
EnsureCapacity(91);
|
||||
|
|
@ -3141,8 +3110,7 @@ namespace Server.Network
|
|||
|
||||
public MobileStatus(Mobile beholder, Mobile beheld, NetState ns) : base(0x11)
|
||||
{
|
||||
string name = beheld.Name;
|
||||
if (name == null) name = "";
|
||||
string name = beheld.Name ?? "";
|
||||
|
||||
int type;
|
||||
|
||||
|
|
@ -3151,12 +3119,12 @@ namespace Server.Network
|
|||
type = 0;
|
||||
EnsureCapacity(43);
|
||||
}
|
||||
else if (Core.HS && ns != null && ns.ExtendedStatus)
|
||||
else if (Core.HS && ns?.ExtendedStatus == true)
|
||||
{
|
||||
type = 6;
|
||||
EnsureCapacity(121);
|
||||
}
|
||||
else if (Core.ML && ns != null && ns.SupportsExpansion(Expansion.ML))
|
||||
else if (Core.ML && ns?.SupportsExpansion(Expansion.ML) == true)
|
||||
{
|
||||
type = 5;
|
||||
EnsureCapacity(91);
|
||||
|
|
@ -3180,61 +3148,61 @@ namespace Server.Network
|
|||
|
||||
m_Stream.Write((byte)type);
|
||||
|
||||
if (type > 0)
|
||||
if (type <= 0)
|
||||
return;
|
||||
|
||||
m_Stream.Write(beheld.Female);
|
||||
|
||||
m_Stream.Write((short)beheld.Str);
|
||||
m_Stream.Write((short)beheld.Dex);
|
||||
m_Stream.Write((short)beheld.Int);
|
||||
|
||||
WriteAttr(beheld.Stam, beheld.StamMax);
|
||||
WriteAttr(beheld.Mana, beheld.ManaMax);
|
||||
|
||||
m_Stream.Write(beheld.TotalGold);
|
||||
m_Stream.Write((short)(Core.AOS ? beheld.PhysicalResistance : (int)(beheld.ArmorRating + 0.5)));
|
||||
m_Stream.Write((short)(Mobile.BodyWeight + beheld.TotalWeight));
|
||||
|
||||
if (type >= 5)
|
||||
{
|
||||
m_Stream.Write(beheld.Female);
|
||||
|
||||
m_Stream.Write((short)beheld.Str);
|
||||
m_Stream.Write((short)beheld.Dex);
|
||||
m_Stream.Write((short)beheld.Int);
|
||||
|
||||
WriteAttr(beheld.Stam, beheld.StamMax);
|
||||
WriteAttr(beheld.Mana, beheld.ManaMax);
|
||||
|
||||
m_Stream.Write(beheld.TotalGold);
|
||||
m_Stream.Write((short)(Core.AOS ? beheld.PhysicalResistance : (int)(beheld.ArmorRating + 0.5)));
|
||||
m_Stream.Write((short)(Mobile.BodyWeight + beheld.TotalWeight));
|
||||
|
||||
if (type >= 5)
|
||||
{
|
||||
m_Stream.Write((short)beheld.MaxWeight);
|
||||
m_Stream.Write((byte)(beheld.Race.RaceID + 1)); // Would be 0x00 if it's a non-ML enabled account but...
|
||||
}
|
||||
|
||||
m_Stream.Write((short)beheld.StatCap);
|
||||
|
||||
m_Stream.Write((byte)beheld.Followers);
|
||||
m_Stream.Write((byte)beheld.FollowersMax);
|
||||
|
||||
if (type >= 4)
|
||||
{
|
||||
m_Stream.Write((short)beheld.FireResistance); // Fire
|
||||
m_Stream.Write((short)beheld.ColdResistance); // Cold
|
||||
m_Stream.Write((short)beheld.PoisonResistance); // Poison
|
||||
m_Stream.Write((short)beheld.EnergyResistance); // Energy
|
||||
m_Stream.Write((short)beheld.Luck); // Luck
|
||||
|
||||
IWeapon weapon = beheld.Weapon;
|
||||
|
||||
if (weapon != null)
|
||||
{
|
||||
weapon.GetStatusDamage(beheld, out int min, out int max);
|
||||
m_Stream.Write((short)min); // Damage min
|
||||
m_Stream.Write((short)max); // Damage max
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Stream.Write((short)0); // Damage min
|
||||
m_Stream.Write((short)0); // Damage max
|
||||
}
|
||||
|
||||
m_Stream.Write(beheld.TithingPoints);
|
||||
}
|
||||
|
||||
if (type >= 6)
|
||||
for (int i = 0; i < 15; ++i)
|
||||
m_Stream.Write((short)beheld.GetAOSStatus(i));
|
||||
m_Stream.Write((short)beheld.MaxWeight);
|
||||
m_Stream.Write((byte)(beheld.Race.RaceID + 1)); // Would be 0x00 if it's a non-ML enabled account but...
|
||||
}
|
||||
|
||||
m_Stream.Write((short)beheld.StatCap);
|
||||
|
||||
m_Stream.Write((byte)beheld.Followers);
|
||||
m_Stream.Write((byte)beheld.FollowersMax);
|
||||
|
||||
if (type >= 4)
|
||||
{
|
||||
m_Stream.Write((short)beheld.FireResistance); // Fire
|
||||
m_Stream.Write((short)beheld.ColdResistance); // Cold
|
||||
m_Stream.Write((short)beheld.PoisonResistance); // Poison
|
||||
m_Stream.Write((short)beheld.EnergyResistance); // Energy
|
||||
m_Stream.Write((short)beheld.Luck); // Luck
|
||||
|
||||
IWeapon weapon = beheld.Weapon;
|
||||
|
||||
if (weapon != null)
|
||||
{
|
||||
weapon.GetStatusDamage(beheld, out int min, out int max);
|
||||
m_Stream.Write((short)min); // Damage min
|
||||
m_Stream.Write((short)max); // Damage max
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Stream.Write((short)0); // Damage min
|
||||
m_Stream.Write((short)0); // Damage max
|
||||
}
|
||||
|
||||
m_Stream.Write(beheld.TithingPoints);
|
||||
}
|
||||
|
||||
if (type >= 6)
|
||||
for (int i = 0; i < 15; ++i)
|
||||
m_Stream.Write((short)beheld.GetAOSStatus(i));
|
||||
}
|
||||
|
||||
private void WriteAttr(int current, int maximum)
|
||||
|
|
@ -4501,6 +4469,7 @@ namespace Server.Network
|
|||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue