Improve rejection message and code duplication in OnPlayerBuff
There is now a local function `Reject` that will handle logging, rejecting, and (optionally) re-syncing upon a rejected packet. Alongside this, the debug message has been improved to include the sender index, buff type, receiver index, and the time in ticks (and the existing reason for rejection.)
This commit is contained in:
parent
71a480af6b
commit
51de32387a
1 changed files with 49 additions and 28 deletions
|
|
@ -1879,41 +1879,57 @@ namespace TShockAPI
|
||||||
int type = args.Type;
|
int type = args.Type;
|
||||||
int time = args.Time;
|
int time = args.Time;
|
||||||
|
|
||||||
|
void Reject(bool shouldResync = true)
|
||||||
|
{
|
||||||
|
args.Handled = true;
|
||||||
|
|
||||||
|
if (shouldResync)
|
||||||
|
args.Player.SendData(PacketTypes.PlayerBuff, number: id);
|
||||||
|
}
|
||||||
|
|
||||||
if (id >= Main.maxPlayers)
|
if (id >= Main.maxPlayers)
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected player cap from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Handled = true;
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: target ID out of bounds",
|
||||||
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TShock.Players[id] == null)
|
if (TShock.Players[id] == null)
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected null check from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Handled = true;
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: target is null", args.Player.Name,
|
||||||
|
args.Player.Index, type, id, time));
|
||||||
|
Reject(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type >= Terraria.ID.BuffID.Count)
|
if (type >= Terraria.ID.BuffID.Count)
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected invalid buff type {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: invalid buff type", args.Player.Name,
|
||||||
args.Handled = true;
|
args.Player.Index, type, id, time));
|
||||||
|
Reject(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Player.IsBeingDisabled())
|
if (args.Player.IsBeingDisabled())
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected disabled from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: sender is being disabled",
|
||||||
args.Handled = true;
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Player.IsBouncerThrottled())
|
if (args.Player.IsBouncerThrottled())
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected throttled from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: sender is being throttled",
|
||||||
args.Handled = true;
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1922,41 +1938,46 @@ namespace TShockAPI
|
||||||
|
|
||||||
if (!args.Player.IsInRange(targetPlayer.TileX, targetPlayer.TileY, 50))
|
if (!args.Player.IsInRange(targetPlayer.TileX, targetPlayer.TileY, 50))
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected range check from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: sender is not in range of target",
|
||||||
args.Handled = true;
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffLimit == null)
|
if (buffLimit == null)
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected non-whitelisted buff {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: buff is not whitelisted",
|
||||||
args.Handled = true;
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffLimit.CanOnlyBeAppliedToSender && id != args.Player.Index)
|
if (buffLimit.CanOnlyBeAppliedToSender && id != args.Player.Index)
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected applied to non-sender from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: buff cannot be applied to non-senders",
|
||||||
args.Handled = true;
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buffLimit.CanBeAddedWithoutHostile && !targetPlayer.TPlayer.hostile)
|
if (!buffLimit.CanBeAddedWithoutHostile && !targetPlayer.TPlayer.hostile)
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected hostile/pvp from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: buff cannot be applied without pvp",
|
||||||
args.Handled = true;
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time <= 0 || time > buffLimit.MaxTicks)
|
if (time <= 0 || time > buffLimit.MaxTicks)
|
||||||
{
|
{
|
||||||
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerBuff rejected time too long from {0}", args.Player.Name));
|
TShock.Log.ConsoleDebug(GetString(
|
||||||
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
|
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: buff cannot be applied for that long",
|
||||||
args.Handled = true;
|
args.Player.Name, args.Player.Index, type, id, time));
|
||||||
|
Reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue