From 5902aa7146df9736f5ee3d61a118e93e4a19f4a4 Mon Sep 17 00:00:00 2001 From: high Date: Tue, 7 Jun 2011 10:22:20 -0400 Subject: [PATCH 1/3] fixed /unban and /unbanip --- TShockAPI/Commands.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 12f4af78..589e74d6 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -236,7 +236,7 @@ namespace TShockAPI public static void UnBan(CommandArgs args) { - string plStr = args.Message.Remove(0, 4); + string plStr = args.Message.Remove(0, 6); int adminplr = args.PlayerID; var ban = TShock.Bans.GetBanByName(plStr); if (ban != null) @@ -252,7 +252,7 @@ namespace TShockAPI public static void UnBanIP(CommandArgs args) { - string plStr = args.Message.Remove(0, 4); + string plStr = args.Message.Remove(0, 8); int adminplr = args.PlayerID; var ban = TShock.Bans.GetBanByIp(plStr); if (ban != null) From 5ee04572d66a46417a965268c7298154dcbb9f76 Mon Sep 17 00:00:00 2001 From: high Date: Tue, 7 Jun 2011 10:40:04 -0400 Subject: [PATCH 2/3] GetData now blocks the server from handling packets from sockets set to die. --- TShockAPI/TShock.cs | 59 +++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 58f90d18..341b6fe8 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -200,27 +200,37 @@ namespace TShockAPI private void GetData(GetDataEventArgs e) { + e.Handled = HandleGetData(e); + } + + private bool HandleGetData(GetDataEventArgs e) + { + if (!Netplay.serverSock[e.Msg.whoAmI].active || Netplay.serverSock[e.Msg.whoAmI].kill) + return true; + if (e.MsgID == 4) { var ban = Bans.GetBanByName(Main.player[e.Msg.whoAmI].name); if (ban != null) { Tools.Kick(e.Msg.whoAmI, "You are banned: " + ban.Reason); + return true; } string name = Encoding.ASCII.GetString(e.Msg.readBuffer, e.Index + 23, (e.Length - (e.Index + 23)) + e.Index - 1); if (name.Length > 32) { Tools.Kick(e.Msg.whoAmI, "Name exceeded 32 characters."); + return true; } if (players[e.Msg.whoAmI] == null) { Tools.Kick(e.Msg.whoAmI, "Player doesn't exist"); - e.Handled = true; + return true; } else if (players[e.Msg.whoAmI].receivedInfo) { Tools.Kick(e.Msg.whoAmI, "Sent client info more than once"); - e.Handled = true; + return true; } else { @@ -241,7 +251,7 @@ namespace TShockAPI if (size > 5 || Math.Abs(plyX - tileX) > 10 || Math.Abs(plyY - tileY) > 10) { Ban(e.Msg.whoAmI, "Send Tile Square Abuse"); - e.Handled = true; + return true; } } } @@ -265,12 +275,13 @@ namespace TShockAPI 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; + return true; } } if (type == 0 || type == 1) - + { if (ConfigurationManager.spawnProtect) + { if (!players[e.Msg.whoAmI].group.HasPermission("editspawn")) { var flag = CheckSpawn(x, y); @@ -278,16 +289,17 @@ namespace TShockAPI { Tools.SendMessage(e.Msg.whoAmI, "Spawn protected from changes.", new[] { 255f, 0f, 0f }); - e.Handled = true; + return true; } } + } + } if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active) { players[e.Msg.whoAmI].tileThreshold++; players[e.Msg.whoAmI].tilesDestroyed.Add(new Position(x, y), Main.tile[x, y]); } - return; } } else if (e.MsgID == 0x1e) @@ -303,8 +315,7 @@ namespace TShockAPI if (ConfigurationManager.permaPvp) Main.player[e.Msg.whoAmI].hostile = true; NetMessage.SendData(30, -1, -1, "", e.Msg.whoAmI); - e.Handled = true; - return; + return true; } } else if (e.MsgID == 0x0A) //SendSection @@ -312,14 +323,14 @@ namespace TShockAPI Tools.Broadcast(string.Format("{0}({1}) attempted sending a section", Main.player[e.Msg.whoAmI].name, e.Msg.whoAmI)); Tools.Kick(e.Msg.whoAmI, "SendSection abuse."); - e.Handled = true; + return true; } else if (e.MsgID == 0x17) //Npc Data { Tools.Broadcast(string.Format("{0}({1}) attempted spawning an NPC", Main.player[e.Msg.whoAmI].name, e.Msg.whoAmI)); Tools.Kick(e.Msg.whoAmI, "Spawn NPC abuse"); - e.Handled = true; + return true; } else if (e.MsgID == 0x0D) //Update Player { @@ -327,7 +338,7 @@ namespace TShockAPI if (plr != e.Msg.whoAmI) { Tools.Kick(e.Msg.whoAmI, "Update Player abuse"); - e.Handled = true; + return true; } } else if (e.MsgID == 0x10) @@ -352,7 +363,7 @@ namespace TShockAPI Tools.Kick(ply, "Abnormal life increase"); Tools.Broadcast(playerName + " was " + (ConfigurationManager.banCheater ? "banned" : "kicked") + " because they gained an abnormal amount of health."); - e.Handled = true; + return true; } } } @@ -385,7 +396,7 @@ namespace TShockAPI Tools.Kick(ply, "Abnormal mana increase"); Tools.Broadcast(playerName + " was " + (ConfigurationManager.banCheater ? "banned" : "kicked") + " because they gained an abnormal amount of mana."); - e.Handled = true; + return true; } } } @@ -423,7 +434,7 @@ namespace TShockAPI Tools.Broadcast(Main.player[i].name + " was " + (ConfigurationManager.banBoom ? "banned" : "kicked") + " for throwing an explosive device."); - e.Handled = true; + return true; } } } @@ -443,7 +454,7 @@ namespace TShockAPI Ban(e.Msg.whoAmI, "Griefer"); Log.Info(Tools.FindPlayer(e.Msg.whoAmI) + " was kicked for trying to execute KillMe on someone else."); - e.Handled = true; + return true; } } } @@ -457,7 +468,7 @@ namespace TShockAPI byte pvp = br.ReadByte(); if (!Main.player[playerid].hostile) - e.Handled = true; + return true; } } else if (e.MsgID == 0x30) @@ -471,7 +482,7 @@ namespace TShockAPI //The liquid was picked up. if (liquid == 0) - return; + return false; int plyX = Math.Abs((int)Main.player[e.Msg.whoAmI].position.X / 16); int plyY = Math.Abs((int)Main.player[e.Msg.whoAmI].position.Y / 16); @@ -492,19 +503,19 @@ namespace TShockAPI if (lava && lavacount <= 0) { TShock.Ban(e.Msg.whoAmI, "Placing lava they didn't have."); - e.Handled = true; + return true; } else if (!lava && watercount <= 0) { TShock.Ban(e.Msg.whoAmI, "Placing water they didn't have."); - e.Handled = true; + return true; } if ((Math.Abs(plyX - tileX) > 6) || (Math.Abs(plyY - tileY) > 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; + return true; } if (ConfigurationManager.spawnProtect) @@ -515,7 +526,7 @@ namespace TShockAPI if (flag) { Tools.SendMessage(e.Msg.whoAmI, "The spawn is protected!", new[] { 255f, 0f, 0f }); - e.Handled = true; + return true; } } } @@ -523,8 +534,10 @@ 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. + return true; // Client only uses it for chests, but sends regular 17 as well. } + + return false; } private void OnGreetPlayer(int who, HandledEventArgs e) From f1c8be3e6080e3fe86d78d9d9fc91f883f29bea2 Mon Sep 17 00:00:00 2001 From: Shank Date: Tue, 7 Jun 2011 11:13:04 -0600 Subject: [PATCH 3/3] Added /banip --- TShockAPI/Commands.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 7dbaedc0..c0d2c4b4 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -78,6 +78,7 @@ namespace TShockAPI { commands.Add(new Command("kick", "kick", Kick)); commands.Add(new Command("ban", "ban", Ban)); + commands.Add(new Command("banip", "ban", BanIP)); commands.Add(new Command("off", "maintenance", Off)); commands.Add(new Command("reload", "cfg", Reload)); commands.Add(new Command("dropmeteor", "causeevents", DropMeteor)); @@ -199,6 +200,28 @@ namespace TShockAPI Tools.SendMessage(ply, "Invalid player!", new[] {255f, 0f, 0f}); } + public static void BanIP(CommandArgs args) + { + if (args.Message.Split(' ').Length == 2) + { + string ip = args.Message.Split(' ')[1]; + TShock.Bans.AddBan(ip, "", "Manually added IP address ban."); + } else if (args.Message.Split(' ').Length > 2) + { + string reason = ""; + for (int i = 2; i > args.Message.Split(' ').Length;i++) + { + reason += args.Message.Split(' ')[i]; + } + string ip = args.Message.Split(' ')[1]; + TShock.Bans.AddBan(ip, "", reason); + } + else + { + Tools.SendMessage(args.PlayerID, "Syntax: /banip "); + } + } + public static void Ban(CommandArgs args) { string plStr = args.Message.Remove(0, 4).Trim().TrimEnd('"').TrimStart('"').Split(' ')[0];