fix: Adds text command to throttle. Fixes throttle itself. (#1743)
This commit is contained in:
parent
bb7bc57e42
commit
c4fbc6b88e
2 changed files with 8 additions and 16 deletions
|
|
@ -845,7 +845,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
|
||||||
{
|
{
|
||||||
if (!throttler(packetId, this, out bool drop))
|
if (!throttler(packetId, this, out bool drop))
|
||||||
{
|
{
|
||||||
return drop ? ParserState.AwaitingNextPacket : ParserState.Throttled;
|
return drop ? ParserState.Throttled : ParserState.AwaitingNextPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPacketTime(packetId);
|
SetPacketTime(packetId);
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ namespace Server.Network
|
||||||
{
|
{
|
||||||
Delays[0x03] = 25; // Speech
|
Delays[0x03] = 25; // Speech
|
||||||
Delays[0xAD] = 25; // Speech
|
Delays[0xAD] = 25; // Speech
|
||||||
|
Delays[0x12] = 25; // Text Commands
|
||||||
Delays[0x75] = 500; // Rename request
|
Delays[0x75] = 500; // Rename request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,10 +108,12 @@ namespace Server.Network
|
||||||
if (oldDelay == 0 && delay > 0)
|
if (oldDelay == 0 && delay > 0)
|
||||||
{
|
{
|
||||||
IncomingPackets.RegisterThrottler(packetID, &Throttle);
|
IncomingPackets.RegisterThrottler(packetID, &Throttle);
|
||||||
|
e.Mobile.SendMessage($"Set throttle for packet 0x{packetID:X2} to {delay}ms.");
|
||||||
}
|
}
|
||||||
else if (oldDelay > 0 && delay == 0)
|
else if (oldDelay > 0 && delay == 0)
|
||||||
{
|
{
|
||||||
IncomingPackets.RegisterThrottler(packetID, null);
|
IncomingPackets.RegisterThrottler(packetID, null);
|
||||||
|
e.Mobile.SendMessage($"Removed throttle for packet 0x{packetID:X2}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Delays[packetID] = delay;
|
Delays[packetID] = delay;
|
||||||
|
|
@ -130,27 +133,16 @@ namespace Server.Network
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var configPath = ThrottlesConfiguration;
|
var path = Path.Join(Core.BaseDirectory, ThrottlesConfiguration);
|
||||||
var path = Path.Join(Core.BaseDirectory, configPath);
|
|
||||||
JsonConfig.Serialize(path, table);
|
JsonConfig.Serialize(path, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Throttle(int packetID, NetState ns, out bool drop)
|
public static bool Throttle(int packetID, NetState ns, out bool drop)
|
||||||
{
|
{
|
||||||
if (ns.Mobile is not PlayerMobile player || player.AccessLevel >= AccessLevel.Counselor)
|
drop = ns.Mobile is PlayerMobile { AccessLevel: < AccessLevel.Counselor }
|
||||||
{
|
&& Core.TickCount - ns.GetPacketTime(packetID) < Delays[packetID];
|
||||||
drop = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Core.TickCount - ns.GetPacketTime(packetID) < Delays[packetID])
|
return !drop;
|
||||||
{
|
|
||||||
drop = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
drop = false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue