Skip to content

Commit

Permalink
fix: Adds text command to throttle. Fixes throttle itself. (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman authored Apr 27, 2024
1 parent bb7bc57 commit c4fbc6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Projects/Server/Network/NetState/NetState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ private unsafe ParserState HandlePacket(SpanReader packetReader, byte packetId,
{
if (!throttler(packetId, this, out bool drop))
{
return drop ? ParserState.AwaitingNextPacket : ParserState.Throttled;
return drop ? ParserState.Throttled : ParserState.AwaitingNextPacket;
}

SetPacketTime(packetId);
Expand Down
22 changes: 7 additions & 15 deletions Projects/UOContent/Misc/PacketThrottles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static unsafe void Initialize()
{
Delays[0x03] = 25; // Speech
Delays[0xAD] = 25; // Speech
Delays[0x12] = 25; // Text Commands
Delays[0x75] = 500; // Rename request
}

Expand Down Expand Up @@ -107,10 +108,12 @@ public static unsafe void SetThrottle(CommandEventArgs e)
if (oldDelay == 0 && delay > 0)
{
IncomingPackets.RegisterThrottler(packetID, &Throttle);
e.Mobile.SendMessage($"Set throttle for packet 0x{packetID:X2} to {delay}ms.");
}
else if (oldDelay > 0 && delay == 0)
{
IncomingPackets.RegisterThrottler(packetID, null);
e.Mobile.SendMessage($"Removed throttle for packet 0x{packetID:X2}");
}

Delays[packetID] = delay;
Expand All @@ -130,27 +133,16 @@ private static void SaveDelays()
}
}

var configPath = ThrottlesConfiguration;
var path = Path.Join(Core.BaseDirectory, configPath);
var path = Path.Join(Core.BaseDirectory, ThrottlesConfiguration);
JsonConfig.Serialize(path, table);
}

public static bool Throttle(int packetID, NetState ns, out bool drop)
{
if (ns.Mobile is not PlayerMobile player || player.AccessLevel >= AccessLevel.Counselor)
{
drop = false;
return true;
}

if (Core.TickCount - ns.GetPacketTime(packetID) < Delays[packetID])
{
drop = true;
return false;
}
drop = ns.Mobile is PlayerMobile { AccessLevel: < AccessLevel.Counselor }
&& Core.TickCount - ns.GetPacketTime(packetID) < Delays[packetID];

drop = false;
return true;
return !drop;
}
}
}

0 comments on commit c4fbc6b

Please sign in to comment.