chore: Use var everywhere (#2294)

This commit is contained in:
Kamron Batman 2025-12-27 16:47:28 -08:00 • committed by GitHub
parent 0b34cc4417
commit ebaf104935
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
267 changed files with 873 additions and 873 deletions

View file

@ -52,7 +52,7 @@ public class CidrFirewallEntry : BaseFirewallEntry
private static IPAddress ParseIPAddress(ReadOnlySpan<char> ipString, out int prefixLength)
{
int slashIndex = ipString.IndexOf('/');
var slashIndex = ipString.IndexOf('/');
var ipAddress = IPAddress.Parse(slashIndex > -1 ? ipString[..slashIndex] : ipString);
var maxPrefixLength = ipAddress.AddressFamily == AddressFamily.InterNetworkV6 ? 128 : 32;

View file

@ -136,10 +136,10 @@ public class IPRateLimiter
{
await _cleanupSignal.WaitAsync(_cts.Token);
int maxToProcess = Math.Min(_cleanupQueue.Count, 500);
var maxToProcess = Math.Min(_cleanupQueue.Count, 500);
var nowTicks = Core.TickCount;
for (int i = 0; i < maxToProcess; i++)
for (var i = 0; i < maxToProcess; i++)
{
if (!_cts.IsCancellationRequested)
{

View file

@ -42,9 +42,9 @@ public static class MovementThrottle
return false;
}
long now = Core.TickCount;
long credit = ns._movementCredit;
long nextMove = ns._nextMovementTime;
var now = Core.TickCount;
var credit = ns._movementCredit;
var nextMove = ns._nextMovementTime;
// Reset system if idle for more than 1 second
if (now - nextMove + _movementThrottleReset > 0)
@ -54,7 +54,7 @@ public static class MovementThrottle
return false;
}
long cost = nextMove - now;
var cost = nextMove - now;
if (credit < cost)
{

View file

@ -278,9 +278,9 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
return 0;
}
for (int i = 0; i < _packetCounts.Length; i++)
for (var i = 0; i < _packetCounts.Length; i++)
{
long count = _packetCounts[i];
var count = _packetCounts[i];
_packetCounts[i] = 0;
if (count > PacketPerSecondThreshold)
@ -583,7 +583,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
var packetReader = new SpanReader(buffer);
var packetId = packetReader.ReadByte();
int packetLength = length;
var packetLength = length;
// These can arrive at any time and are only informational
if (_protocolState != ProtocolState.AwaitingSeed && IncomingPackets.IsInfoPacket(packetId))
@ -608,7 +608,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
}
else if (length >= 4)
{
int newSeed = (packetId << 24) | (packetReader.ReadByte() << 16) | (packetReader.ReadByte() << 8) | packetReader.ReadByte();
var newSeed = (packetId << 24) | (packetReader.ReadByte() << 16) | (packetReader.ReadByte() << 8) | packetReader.ReadByte();
if (newSeed == 0)
{
@ -763,8 +763,8 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
*/
private unsafe ParserState HandlePacket(SpanReader packetReader, byte packetId, out int packetLength)
{
PacketHandler handler = IncomingPackets.GetHandler(packetId);
int length = packetReader.Length;
var handler = IncomingPackets.GetHandler(packetId);
var length = packetReader.Length;
if (handler == null)
{
@ -999,7 +999,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
if (count > 0)
{
for (int i = 0; i < count; i++)
for (var i = 0; i < count; i++)
{
(_polledStates[i].Target as NetState)?.HandleReceive();
_polledStates[i] = default;
@ -1050,7 +1050,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
{
try
{
long curTicks = Core.TickCount;
var curTicks = Core.TickCount;
foreach (var ns in Instances)
{

View file

@ -67,15 +67,15 @@ public static class NetworkCompression
return 0;
}
int bitCount = 0;
int bitValue = 0;
var bitCount = 0;
var bitValue = 0;
int inputIdx = 0;
int outputIdx = 0;
var inputIdx = 0;
var outputIdx = 0;
while (inputIdx < input.Length)
{
int i = input[inputIdx++] << 1;
var i = input[inputIdx++] << 1;
bitCount += _huffmanTable[i];
bitValue = (bitValue << _huffmanTable[i]) | _huffmanTable[i + 1];

View file

@ -74,7 +74,7 @@ public static class OutgoingAccountPackets
writer.Write((ushort)length);
writer.Write((ushort)0); // Count & Placeholder
int count = 0;
var count = 0;
for (var i = 0; i < a.Length; ++i)
{
@ -265,7 +265,7 @@ public static class OutgoingAccountPackets
writer.Write((byte)count);
for (int i = 0; i < count; i++)
for (var i = 0; i < count; i++)
{
var m = a[i];
@ -330,7 +330,7 @@ public static class OutgoingAccountPackets
writer.Write((ushort)length);
writer.Write((byte)count); // TODO: It is probably more proper to use count.
for (int i = 0; i < count; i++)
for (var i = 0; i < count; i++)
{
var m = acct[i];
@ -348,7 +348,7 @@ public static class OutgoingAccountPackets
writer.Write((byte)cityInfo.Length);
for (int i = 0; i < cityInfo.Length; ++i)
for (var i = 0; i < cityInfo.Length; ++i)
{
var ci = cityInfo[i];

View file

@ -32,7 +32,7 @@ public static class OutgoingEffectPackets
return;
}
Span<byte> buffer = stackalloc byte[SoundPacketLength].InitializePacket();
var buffer = stackalloc byte[SoundPacketLength].InitializePacket();
CreateSoundEffect(buffer, soundID, target);
ns.Send(buffer);

View file

@ -54,7 +54,7 @@ public static class OutgoingEntityPackets
return;
}
Span<byte> buffer = stackalloc byte[OPLPacketLength].InitializePacket();
var buffer = stackalloc byte[OPLPacketLength].InitializePacket();
CreateOPLInfo(buffer, serial, hash);
ns.Send(buffer);
@ -79,7 +79,7 @@ public static class OutgoingEntityPackets
return;
}
Span<byte> buffer = stackalloc byte[RemoveEntityLength].InitializePacket();
var buffer = stackalloc byte[RemoveEntityLength].InitializePacket();
CreateRemoveEntity(buffer, serial);
ns.Send(buffer);
@ -96,12 +96,12 @@ public static class OutgoingEntityPackets
writer.Write((byte)0xF3); // Packet ID
writer.Write((short)0x1); // command
int type = 0;
int gfx = 0;
int amount = 1;
int hue = 0;
var type = 0;
var gfx = 0;
var amount = 1;
var hue = 0;
byte light = 0;
int flags = 0;
var flags = 0;
if (entity is BaseMulti multi)
{

View file

@ -88,7 +88,7 @@ public static class OutgoingItemPackets
return;
}
Span<byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();
var buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();
var length = ns.StygianAbyss ?
OutgoingEntityPackets.CreateWorldEntity(buffer, item, ns.HighSeas) :

View file

@ -37,7 +37,7 @@ public static class OutgoingMapPackets
writer.Write((ushort)0x18); // Subpacket
writer.Write(4);
for (int i = 0; i < 4; i++)
for (var i = 0; i < 4; i++)
{
var map = Map.Maps[i];

View file

@ -47,7 +47,7 @@ public static class OutgoingMenuPackets
int entriesLength = (byte)entries.Length;
var maxLength = 11 + questionLength;
for (int i = 0; i < entriesLength; i++)
for (var i = 0; i < entriesLength; i++)
{
maxLength += 5 + entries[i].Name?.Length ?? 0; // could be trimmed
}
@ -106,7 +106,7 @@ public static class OutgoingMenuPackets
int answersLength = (byte)answers.Length;
var maxLength = 11 + questionLength;
for (int i = 0; i < answersLength; i++)
for (var i = 0; i < answersLength; i++)
{
maxLength += 5 + answers[i]?.Length ?? 0; // could be trimmed
}

View file

@ -41,7 +41,7 @@ public static class OutgoingMessagePackets
return;
}
Span<byte> buffer = stackalloc byte[GetMaxMessageLocalizedLength(args)].InitializePacket();
var buffer = stackalloc byte[GetMaxMessageLocalizedLength(args)].InitializePacket();
var length = CreateMessageLocalized(
buffer, serial, graphic, type, hue, font, number, name, args
);
@ -97,7 +97,7 @@ public static class OutgoingMessagePackets
return;
}
Span<byte> buffer = stackalloc byte[GetMaxMessageLocalizedAffixLength(affix, args)].InitializePacket();
var buffer = stackalloc byte[GetMaxMessageLocalizedAffixLength(affix, args)].InitializePacket();
var length = CreateMessageLocalizedAffix(
buffer, serial, graphic, type, hue, font, number, name, affixType, affix, args
);
@ -157,7 +157,7 @@ public static class OutgoingMessagePackets
return;
}
Span<byte> buffer = stackalloc byte[GetMaxMessageLength(text)].InitializePacket();
var buffer = stackalloc byte[GetMaxMessageLength(text)].InitializePacket();
var length = CreateMessage(
buffer,
serial,

View file

@ -96,7 +96,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[DeathAnimationPacketLength].InitializePacket();
var span = stackalloc byte[DeathAnimationPacketLength].InitializePacket();
CreateDeathAnimation(span, killed, corpse);
ns.Send(span);
}
@ -134,7 +134,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> buffer = stackalloc byte[MobileMovingPacketLength].InitializePacket();
var buffer = stackalloc byte[MobileMovingPacketLength].InitializePacket();
var packetFlags = (byte)target.GetPacketFlags(ns.StygianAbyss);
CreateMobileMoving(buffer, target, noto, packetFlags);
ns.Send(buffer);
@ -202,7 +202,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[MobileAttributePacketLength].InitializePacket();
var span = stackalloc byte[MobileAttributePacketLength].InitializePacket();
CreateMobileHits(span, m, normalize);
ns.Send(span);
}
@ -227,7 +227,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[MobileAttributePacketLength].InitializePacket();
var span = stackalloc byte[MobileAttributePacketLength].InitializePacket();
CreateMobileMana(span, m, normalize);
ns.Send(span);
}
@ -252,7 +252,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[MobileAttributePacketLength].InitializePacket();
var span = stackalloc byte[MobileAttributePacketLength].InitializePacket();
CreateMobileStam(span, m, normalize);
ns.Send(span);
}
@ -277,7 +277,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[MobileAttributesPacketLength].InitializePacket();
var span = stackalloc byte[MobileAttributesPacketLength].InitializePacket();
CreateMobileAttributes(span, m, normalize);
ns.Send(span);
}
@ -346,7 +346,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[MobileAnimationPacketLength].InitializePacket();
var span = stackalloc byte[MobileAnimationPacketLength].InitializePacket();
CreateMobileAnimation(span, mobile, action, frameCount, repeatCount, forward, repeat, delay);
ns.Send(span);
}
@ -371,7 +371,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[NewMobileAnimationPacketLength].InitializePacket();
var span = stackalloc byte[NewMobileAnimationPacketLength].InitializePacket();
CreateNewMobileAnimation(span, mobile, action, frameCount, delay);
ns.Send(span);
}
@ -383,7 +383,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> span = stackalloc byte[MobileHealthbarPacketLength].InitializePacket();
var span = stackalloc byte[MobileHealthbarPacketLength].InitializePacket();
CreateMobileHealthbar(span, m, healthbar);
ns.Send(span);
}
@ -438,7 +438,7 @@ public static class OutgoingMobilePackets
return;
}
Span<byte> buffer = stackalloc byte[MobileStatusCompactLength].InitializePacket();
var buffer = stackalloc byte[MobileStatusCompactLength].InitializePacket();
CreateMobileStatusCompact(buffer, m, canBeRenamed);
ns.Send(buffer);
@ -489,7 +489,7 @@ public static class OutgoingMobilePackets
}
}
Span<byte> buffer = stackalloc byte[length].InitializePacket();
var buffer = stackalloc byte[length].InitializePacket();
CreateMobileStatus(buffer, beheld, version, beheld.CanBeRenamedBy(beholder));
ns.Send(buffer);
}

View file

@ -235,7 +235,7 @@ public static class OutgoingPlayerPackets
return;
}
Span<byte> buffer = stackalloc byte[DragEffectPacketLength].InitializePacket();
var buffer = stackalloc byte[DragEffectPacketLength].InitializePacket();
CreateDragEffect(buffer, srcSerial, srcLocation, trgSerial, trgLocation, itemID, hue, amount);
ns.Send(buffer);
}

View file

@ -82,7 +82,7 @@ public static class OutgoingVendorBuyPackets
}
var length = 8;
for (int i = 0; i < list.Count; i++)
for (var i = 0; i < list.Count; i++)
{
length += 6 + list[i].Description?.Length ?? 0;
}

View file

@ -89,11 +89,11 @@ public ref struct PacketContainerBuilder
private void Grow(int additionalCapacityBeyondPos)
{
var newLength = Math.Max(Length + additionalCapacityBeyondPos, _bytes.Length * 2);
byte[] poolArray = STArrayPool<byte>.Shared.Rent(newLength);
var poolArray = STArrayPool<byte>.Shared.Rent(newLength);
_bytes[..Length].CopyTo(poolArray);
byte[] toReturn = _arrayToReturnToPool;
var toReturn = _arrayToReturnToPool;
_bytes = _arrayToReturnToPool = poolArray;
if (toReturn != null)
{
@ -104,7 +104,7 @@ public ref struct PacketContainerBuilder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
byte[] toReturn = _arrayToReturnToPool;
var toReturn = _arrayToReturnToPool;
this = default; // for safety, to avoid using pooled array if this instance is erroneously appended to again
if (toReturn != null)
{