Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion TShockAPI/GetDataHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public static void InitGetDataHandler()
{ PacketTypes.SyncCavernMonsterType, HandleSyncCavernMonsterType },
{ PacketTypes.SyncLoadout, HandleSyncLoadout },
{ PacketTypes.TeamChangeFromUI, HandlePlayerTeam }, // Same packet as PlayerTeam
{ PacketTypes.TEDeadCellsDisplayJar, HandleDisplayJar }
{ PacketTypes.TEDeadCellsDisplayJar, HandleDisplayJar },
{ PacketTypes.SyncChestSize, HandleChestSizeSync }
};
}

Expand Down Expand Up @@ -4980,6 +4981,60 @@ private static bool HandleDisplayJar(GetDataHandlerArgs args)
return false;
}

private static bool HandleChestSizeSync(GetDataHandlerArgs args)
{
short id = args.Data.ReadInt16();
short newSize = args.Data.ReadInt16();

if (id is < 0 or >= Main.maxChests) // chest is invalid
return true;

Chest chest = Main.chest[id];

if (chest == null)
{
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleChestSizeSync rejected from null chest {0}", args.Player.Name));
return true;
}

if (args.Player.IsBeingDisabled())
{
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleChestSizeSync rejected from disabled {0}", args.Player.Name));
args.Player.SendData(PacketTypes.SyncChestSize, "", id, chest.maxItems);
return true;
}

if (args.Player.IsBouncerThrottled())
{
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleChestSizeSync rejected from throttled {0}", args.Player.Name));
args.Player.SendData(PacketTypes.SyncChestSize, "", id, chest.maxItems);
return true;
}

if (!args.Player.HasPermission(Permissions.resizechests))
{
Comment thread
ACaiCat marked this conversation as resolved.
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleChestSizeSync rejected from no permission {0}", args.Player.Name));
args.Player.Kick(GetString("Exploit attempt detected!"), true);
return true;
}

if (!args.Player.HasBuildPermission(chest.x, chest.y))
{
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleChestSizeSync rejected from build {0}", args.Player.Name));
args.Player.SendData(PacketTypes.SyncChestSize, "", id, chest.maxItems);
return true;
}

if (newSize < 0) // size is invalid
{
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleChestSizeSync rejected from invalid size {0}", args.Player.Name));
args.Player.SendData(PacketTypes.SyncChestSize, "", id, chest.maxItems);
return true;
}
Comment thread
ACaiCat marked this conversation as resolved.

return false;
}


public enum DoorAction
{
Expand Down
4 changes: 4 additions & 0 deletions TShockAPI/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public static class Permissions

[Description("Prevents you from being disabled by abnormal MP.")]
public static readonly string ignoremp = "tshock.ignore.mp";


[Description("Player can resize chests. Warning: Dangerous permission to grant, very easy to abuse.")]
public static readonly string resizechests = "tshock.ignore.resizechests";
#endregion

#region tshock.item nodes
Expand Down
Loading