From 43b968e37f96e1c3d80a2c231c7cfb0c66552a1d Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 6 Jun 2011 16:38:41 -0600 Subject: [PATCH] Added ban for placing impossible to place tiles and liquids. Added ban for attempting to place non-existent liquids. --- TShockAPI/Commands.cs | 13 ++++++++++- TShockAPI/TSPlayer.cs | 3 ++- TShockAPI/TShock.cs | 54 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index a4ac94db..5994b86a 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -200,7 +200,18 @@ namespace TShockAPI public static void Ban(CommandArgs args) { - string plStr = args.Message.Remove(0, 4).Trim().TrimEnd('"').TrimStart('"'); + string plStr = args.Message.Remove(0, 4).Trim().TrimEnd('"').TrimStart('"').Split(' ')[0]; + string[] reason = plStr.Split(' '); + string banReason = ""; + for (int i = 0; i < reason.Length; i++) + { + if (reason[i].Contains("\"")) + reason[i] = ""; + } + for (int i = 0; i < reason.Length; i++) + { + banReason += reason[i]; + } int adminplr = args.PlayerID; int player = Tools.FindPlayer(plStr); if (!(player == -1 || player == -2 || plStr == "")) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 4f3540e3..679bc559 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -10,7 +10,8 @@ namespace TShockAPI public bool syncHP; public bool syncMP; public Group group; - + public int lavaCount = 0; + public int waterCount = 0; private int player; public TSPlayer(int ply) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index aaa8e3b5..88dbc37f 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -199,10 +199,6 @@ namespace TShockAPI private void GetData(GetDataEventArgs e) { - if (Main.netMode != 2) - { - return; - } if (e.MsgID == 17) { using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))) @@ -211,7 +207,20 @@ namespace TShockAPI int x = br.ReadInt32(); int y = br.ReadInt32(); byte typetile = br.ReadByte(); + if (type == 1 || type == 3) + { + int plyX = Math.Abs((int) Main.player[e.Msg.whoAmI].position.X); + int plyY = Math.Abs((int) Main.player[e.Msg.whoAmI].position.Y); + int realX = Math.Abs(x*16); + int realY = Math.Abs(y*16); + + if ((plyX - realX > 6) || (plyY - realY > 6)) + TShock.Ban(e.Msg.whoAmI, "Placing impossible to place blocks."); + Tools.Broadcast(Main.player[e.Msg.whoAmI].name + " was banned for placing impossible to place blocks."); + e.Handled = true; + } if (type == 0 || type == 1) + if (ConfigurationManager.spawnProtect) if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) { @@ -411,6 +420,34 @@ namespace TShockAPI byte liquid = br.ReadByte(); bool lava = br.ReadBoolean(); + int plyX = Math.Abs((int)Main.player[e.Msg.whoAmI].position.X); + int plyY = Math.Abs((int)Main.player[e.Msg.whoAmI].position.Y); + int realX = Math.Abs(x * 16); + int realY = Math.Abs(y * 16); + + for (int i = 0; i < 44; i++) + { + if (Main.player[e.Msg.whoAmI].inventory[i].name == "Lava Bucket") + TShock.players[e.Msg.whoAmI].lavaCount++; + else if (Main.player[e.Msg.whoAmI].inventory[i].name == "Water Bucket") + TShock.players[e.Msg.whoAmI].waterCount++; + } + + if (lava && TShock.players[e.Msg.whoAmI].lavaCount <= 0) + { + TShock.Ban(e.Msg.whoAmI, "Placing lava they didn't have."); + e.Handled = true; + } + else if (!lava && TShock.players[e.Msg.whoAmI].waterCount <= 0) + { + TShock.Ban(e.Msg.whoAmI, "Placing water they didn't have."); + e.Handled = true; + } + if ((plyX - realX > 6) || (plyY - realY > 6)) + TShock.Ban(e.Msg.whoAmI, "Placing impossible to place liquid."); + Tools.Broadcast(Main.player[e.Msg.whoAmI].name + " was banned for placing impossible to place liquid."); + e.Handled = true; + if (ConfigurationManager.spawnProtect) { if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) @@ -423,12 +460,12 @@ namespace TShockAPI } } } - else if (e.MsgID == 0x22) // Client only KillTile - { - e.Handled = true; // Client only uses it for chests, but sends regular 17 as well. - } } } + else if (e.MsgID == 0x22) // Client only KillTile + { + e.Handled = true; // Client only uses it for chests, but sends regular 17 as well. + } } private void OnGreetPlayer(int who, HandledEventArgs e) @@ -797,6 +834,7 @@ namespace TShockAPI public static void Ban(int plr, string reason = "") { + Tools.Kick(plr, reason); Bans.AddBan(Tools.GetPlayerIP(plr), Main.player[plr].name, reason); }