From 1ad261a562ab469bc36cc8aa4bac1614ab4a72b2 Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 7 Jun 2011 14:36:59 +1000 Subject: [PATCH 1/7] All greif related checks now respect ignoregreifdetection and ban/kick greif flags. Refactored common ban/kick logic into helper method in tools. Added ForceKick for when wanting to disallow players to join when sever is full or name is too long or not on whitelist etc. Updated OnJoin to set e.Handled when players are force kicked during join. Logging all players that successfully join the server. --- TShockAPI/Commands.cs | 17 ++--- TShockAPI/TShock.cs | 156 +++++++++++------------------------------- TShockAPI/Tools.cs | 87 +++++++++++++++++++++-- 3 files changed, 127 insertions(+), 133 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index cd595f2e..bcadc1d4 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -184,13 +184,10 @@ namespace TShockAPI int player = Tools.FindPlayer(plStr); if (!(player == -1 || player == -2 || plStr == "")) { - if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetokick")) + if (!Tools.Kick(player, "Misbehaviour.")) { - Tools.Kick(player, "You were kicked."); - Tools.Broadcast(Tools.FindPlayer(player) + " was kicked by " + Tools.FindPlayer(ply)); - } - else Tools.SendMessage(ply, "You can't kick another admin!", new[] {255f, 0f, 0f}); + } } else if (Tools.FindPlayer(plStr) == -2) Tools.SendMessage(ply, "More than one player matched!", new[] {255f, 0f, 0f}); @@ -216,14 +213,10 @@ namespace TShockAPI int player = Tools.FindPlayer(plStr); if (!(player == -1 || player == -2 || plStr == "")) { - if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetoban")) + if (!Tools.Ban(player, banReason.Equals("") ? "Misbehaviour." : banReason, Tools.FindPlayer(adminplr))) { - TShock.Bans.AddBan(Tools.GetPlayerIP(player), Main.player[player].name); - Tools.Kick(player, "You were banned."); - Tools.Broadcast(Tools.FindPlayer(adminplr) + " banned " + Tools.FindPlayer(player) + "!"); - } - else Tools.SendMessage(adminplr, "You can't ban another admin!", new[] {255f, 0f, 0f}); + } } else if (Tools.FindPlayer(plStr) == -2) Tools.SendMessage(adminplr, "More than one player matched!", new[] {255f, 0f, 0f}); @@ -237,7 +230,7 @@ namespace TShockAPI { if (Main.player[player].active) { - Tools.Kick(player, "Server shutting down!"); + Tools.ForceKick(player, "Server shutting down!"); } } WorldGen.saveWorld(); diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index cf3562b7..05c8e455 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -203,13 +203,12 @@ namespace TShockAPI { if (players[e.Msg.whoAmI] == null) { - Tools.Kick(e.Msg.whoAmI, "Player doesn't exist"); + Tools.ForceKick(e.Msg.whoAmI, "Player doesn't exist"); e.Handled = true; } else if (players[e.Msg.whoAmI].receivedInfo) { - Tools.Kick(e.Msg.whoAmI, "Sent client info more than once"); - e.Handled = true; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Sent client info more than once"); } else { @@ -229,8 +228,7 @@ namespace TShockAPI int tileY = Math.Abs(y); if (size > 5 || Math.Abs(plyX - tileX) > 10 || Math.Abs(plyY - tileY) > 10) { - Ban(e.Msg.whoAmI, "Send Tile Square Abuse"); - e.Handled = true; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Send Tile Square Abuse"); } } } @@ -251,10 +249,7 @@ namespace TShockAPI if ((Math.Abs(plyX - tileX) > 6) || (Math.Abs(plyY - tileY) > 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; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Placing impossible to place blocks."); } } if (type == 0 || type == 1) @@ -298,25 +293,18 @@ namespace TShockAPI } else if (e.MsgID == 0x0A) //SendSection { - 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; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "SendSection abuse."); } 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; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Spawn NPC abuse"); } else if (e.MsgID == 0x0D) //Update Player { byte plr = e.Msg.readBuffer[e.Index]; if (plr != e.Msg.whoAmI) { - Tools.Kick(e.Msg.whoAmI, "Update Player abuse"); - e.Handled = true; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Update Player abuse"); } } else if (e.MsgID == 0x10) @@ -331,19 +319,7 @@ namespace TShockAPI { if (players[ply].syncHP) { - if (!players[ply].group.HasPermission("ignorecheatdetection")) - { - if (ConfigurationManager.banCheater || ConfigurationManager.kickCheater) - { - string playerName = Tools.FindPlayer(ply); - if (ConfigurationManager.banCheater) - Ban(ply, "Abnormal life increase"); - 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; - } - } + e.Handled = Tools.HandleCheater(ply, "Abnormal life increase"); } else { @@ -364,19 +340,7 @@ namespace TShockAPI { if (players[ply].syncMP) { - if (!players[ply].group.HasPermission("ignorecheatdetection")) - { - if (ConfigurationManager.banCheater || ConfigurationManager.kickCheater) - { - string playerName = Tools.FindPlayer(ply); - if (ConfigurationManager.banCheater) - Ban(ply, "Abnormal mana increase"); - 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; - } - } + e.Handled = Tools.HandleCheater(ply, "Abnormal mana increase"); } else { @@ -401,20 +365,7 @@ namespace TShockAPI if (type == 29 || type == 28 || type == 30) { - if (!players[e.Msg.whoAmI].group.HasPermission("ignoregriefdetection")) - { - if (ConfigurationManager.kickBoom || ConfigurationManager.banBoom) - { - int i = e.Msg.whoAmI; - if (ConfigurationManager.banBoom) - Ban(i, "Explosives"); - Tools.Kick(i, "Explosives were thrown."); - Tools.Broadcast(Main.player[i].name + " was " + - (ConfigurationManager.banBoom ? "banned" : "kicked") + - " for throwing an explosive device."); - e.Handled = true; - } - } + e.Handled = Tools.HandleExplosivesUser(e.Msg.whoAmI, "Throwing an explosive device."); } } } @@ -429,10 +380,7 @@ namespace TShockAPI if (id != e.Msg.whoAmI) { - 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; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Trying to execute KillMe on someone else."); } } } @@ -476,20 +424,15 @@ namespace TShockAPI if (lava && lavacount <= 0) { - TShock.Ban(e.Msg.whoAmI, "Placing lava they didn't have."); - e.Handled = true; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Placing lava they didn't have."); ; } else if (!lava && watercount <= 0) { - TShock.Ban(e.Msg.whoAmI, "Placing water they didn't have."); - e.Handled = true; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Placing water they didn't have."); } 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; + e.Handled = Tools.HandleGriefer(e.Msg.whoAmI, "Placing impossible to place liquid."); ; } if (ConfigurationManager.spawnProtect) @@ -519,17 +462,11 @@ namespace TShockAPI return; } int plr = who; //legacy support + Log.Info(Tools.FindPlayer(who) + " (" + Tools.GetPlayerIP(who) + ") from '" + players[who].group.GetName() + "' group joined."); Tools.ShowMOTD(who); - if (!players[who].group.HasPermission("ignorecheatdetection") && HackedHealth(who)) + if (HackedHealth(who)) { - if (ConfigurationManager.banCheater || ConfigurationManager.kickCheater) - { - string playerName = Tools.FindPlayer(who); - if (ConfigurationManager.banCheater) - Ban(who, "Hacked health."); - Tools.Kick(who, "Hacked health."); - Tools.Broadcast(playerName + " was " + (ConfigurationManager.banCheater ? "banned" : "kicked") + " for hacked health."); - } + Tools.HandleCheater(who, "Hacked health."); } if (ConfigurationManager.permaPvp) { @@ -551,9 +488,7 @@ namespace TShockAPI if (msg.whoAmI != ply) { - Log.Info(Tools.FindPlayer(msg.whoAmI) + " was kicked for trying to fake chat as someone else."); - Ban(ply, "Faking Chat"); - e.Handled = true; + e.Handled = Tools.HandleGriefer(ply, "Faking Chat"); ; } int x = (int)Main.player[ply].position.X; @@ -596,30 +531,34 @@ namespace TShockAPI } string ip = Tools.GetPlayerIP(ply); - ; + players[ply] = new TSPlayer(ply); players[ply].group = Tools.GetGroupForIP(ip); if (Tools.activePlayers() + 1 > ConfigurationManager.maxSlots && !players[ply].group.HasPermission("reservedslot")) { - Tools.Kick(ply, "Server is full"); - return; + Tools.ForceKick(ply, "Server is full"); + handler.Handled = true; } - - var ban = Bans.GetBanByIp(ip); - if (ban != null) + else { - Tools.Kick(ply, "You are banned: " + ban.Reason); - } - else if (Tools.FindPlayer(ply).Length > 32) - { - Tools.Kick(ply, "Your name was too long."); - Tools.Broadcast(ip + " was kicked because their name exceeded 32 characters."); - } - if (!FileTools.OnWhitelist(ip)) - { - Tools.Kick(ply, "Not on whitelist."); + var ban = Bans.GetBanByIp(ip); + if (ban != null) + { + Tools.ForceKick(ply, "You are banned: " + ban.Reason); + handler.Handled = true; + } + else if (Tools.FindPlayer(ply).Length > 32) + { + Tools.ForceKick(ply, "Your name was too long."); + handler.Handled = true; + } + else if (!FileTools.OnWhitelist(ip)) + { + Tools.ForceKick(ply, "Not on whitelist."); + handler.Handled = true; + } } } @@ -643,7 +582,7 @@ namespace TShockAPI FileTools.CreateFile(FileTools.SaveDir + "auth.lck"); } - ConfigurationManager.maxSlots = Main.maxPlayers - 1; + //ConfigurationManager.maxSlots = Main.maxPlayers - 1; } private void OnUpdate(GameTime time) @@ -662,14 +601,8 @@ namespace TShockAPI { if (Main.player[i] != null) { - if (ConfigurationManager.kickTnt || ConfigurationManager.banTnt) + if (Tools.HandleTntUser((int)i, "Kill tile abuse detected.")) { - if (ConfigurationManager.banTnt) - Ban((int)i, "Explosives"); - Tools.Kick((int)i, "Kill tile abuse detected."); - Tools.Broadcast(Main.player[i].name + " was " + - (ConfigurationManager.banTnt ? "banned" : "kicked") + - " for kill tile abuse."); RevertKillTile((int)i); } else if (players[i].tileThreshold > 0) @@ -873,15 +806,6 @@ namespace TShockAPI return true; } - public static void Ban(int plr, string reason = "") - { - if (!players[plr].group.HasPermission("immunetoban")) - { - Tools.Kick(plr, "Banned: " + reason); - Bans.AddBan(Tools.GetPlayerIP(plr), Main.player[plr].name, reason); - } - } - public class Position { public float X; diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 513e3961..81c60876 100644 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -208,19 +208,96 @@ namespace TShockAPI } } + /// + /// Kicks a player from the server without checking for immunetokick permission. + /// + /// int player + /// string reason + public static void ForceKick(int ply, string reason) + { + string ip = GetPlayerIP(ply); + NetMessage.SendData(0x2, ply, -1, reason, 0x0, 0f, 0f, 0f); + Log.Info(ip + " was force kicked for : " + reason); + } + /// /// Kicks a player from the server. /// /// int player /// string reason - public static void Kick(int ply, string reason) + public static bool Kick(int ply, string reason, string adminUserName = "") { - if (!TShock.players[ply].group.HasPermission("immunetokick") || reason.Contains("Banned: ")) + if (!TShock.players[ply].group.HasPermission("immunetokick")) { - string displayName = FindPlayer(ply).Equals("") ? GetPlayerIP(ply) : FindPlayer(ply); - NetMessage.SendData(0x2, ply, -1, reason, 0x0, 0f, 0f, 0f); - Log.Info("Kicked " + displayName + " for : " + reason); + string playerName = Main.player[ply].name; + NetMessage.SendData(0x2, ply, -1, "Kicked: " + reason, 0x0, 0f, 0f, 0f); + Log.Info("Kicked " + playerName + " for : " + reason); + if (adminUserName.Equals("")) + Broadcast(playerName + " was kicked for " + reason.ToLower()); + else + Tools.Broadcast(adminUserName + " kicked " + playerName + " for " + reason.ToLower()); + return true; } + return false; + } + + /// + /// Bans and kicks a player from the server. + /// + /// int player + /// string reason + public static bool Ban(int plr, string reason, string adminUserName = "") + { + if (!TShock.players[plr].group.HasPermission("immunetoban")) + { + string ip = GetPlayerIP(plr); + string playerName = Main.player[plr].name; + TShock.Bans.AddBan(ip, playerName, reason); + NetMessage.SendData(0x2, plr, -1, "Banned: " + reason, 0x0, 0f, 0f, 0f); + Log.Info("Banned " + playerName + " for : " + reason); + if (adminUserName.Equals("")) + Broadcast(playerName + " was banned for " + reason.ToLower()); + else + Tools.Broadcast(adminUserName + " banned " + playerName + " for " + reason.ToLower()); + return true; + } + return false; + } + + public static bool HandleCheater(int ply, string reason) + { + return HandleBadPlayer(ply, "ignorecheatdetection", ConfigurationManager.banCheater, ConfigurationManager.kickCheater, reason); + } + + public static bool HandleGriefer(int ply, string reason) + { + return HandleBadPlayer(ply, "ignoregriefdetection", ConfigurationManager.banGriefer, ConfigurationManager.kickGriefer, reason); + } + + public static bool HandleTntUser(int ply, string reason) + { + return HandleBadPlayer(ply, "ignoregriefdetection", ConfigurationManager.banTnt, ConfigurationManager.kickTnt, reason); + } + + public static bool HandleExplosivesUser(int ply, string reason) + { + return HandleBadPlayer(ply, "ignoregriefdetection", ConfigurationManager.banBoom, ConfigurationManager.kickBoom, reason); + } + + private static bool HandleBadPlayer(int ply, string overridePermission, bool ban, bool kick, string reason) + { + if (!TShock.players[ply].group.HasPermission(overridePermission)) + { + if (ban) + { + return Ban(ply, reason); + } + else if (kick) + { + return Kick(ply, reason); + } + } + return false; } /// From 78d0480512f096a73443526ab226c7f8dc9b0262 Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 7 Jun 2011 18:33:54 +1000 Subject: [PATCH 2/7] Fixed ban not working with quotes around player name. Kick now also supports reason --- TShockAPI/Commands.cs | 77 +++++++++++++++++++++++++++++-------------- TShockAPI/Tools.cs | 4 +-- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index bcadc1d4..636bca3f 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -179,49 +179,76 @@ namespace TShockAPI public static void Kick(CommandArgs args) { - string plStr = args.Message.Remove(0, 5).Trim().TrimEnd('"').TrimStart('"'); - int ply = args.PlayerID; - int player = Tools.FindPlayer(plStr); - if (!(player == -1 || player == -2 || plStr == "")) + string input = args.Message.Remove(0, 5).Trim(); + string plStr = ""; + string reason = ""; + int splitIndex = input.StartsWith("\"") ? splitIndex = input.IndexOf('"', 1) : splitIndex = input.IndexOf(' ', 0); + if (splitIndex == -1) { - if (!Tools.Kick(player, "Misbehaviour.")) + plStr = input; + } + else + { + plStr = input.Substring(0, splitIndex).Trim().TrimEnd('"').TrimStart('"'); + reason = input.Substring(splitIndex + 1).Trim().TrimEnd('"').TrimStart('"'); + } + Log.Debug("plStr : '" + plStr + "', reason : '" + reason + "'"); + int ply = args.PlayerID; + if (plStr.Length != 0) + { + int player = Tools.FindPlayer(plStr); + if (player == -1) + Tools.SendMessage(ply, "Invalid player!", new[] { 255f, 0f, 0f }); + else if (player == -2) + Tools.SendMessage(ply, "More than one player matched!", new[] { 255f, 0f, 0f }); + else { - Tools.SendMessage(ply, "You can't kick another admin!", new[] {255f, 0f, 0f}); + if (!Tools.Kick(player, reason.Length != 0 ? reason : "Misbehaviour.")) + { + Tools.SendMessage(ply, "You can't kick another admin!", new[] { 255f, 0f, 0f }); + } } } - else if (Tools.FindPlayer(plStr) == -2) - Tools.SendMessage(ply, "More than one player matched!", new[] {255f, 0f, 0f}); else - Tools.SendMessage(ply, "Invalid player!", new[] {255f, 0f, 0f}); + Tools.SendMessage(ply, "Invalid syntax! Proper syntax: /kick [reason]", + new[] { 255f, 0f, 0f }); } public static void Ban(CommandArgs args) { - 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++) + string input = args.Message.Remove(0, 4).Trim(); + string plStr = ""; + string reason = ""; + int splitIndex = input.StartsWith("\"") ? splitIndex = input.IndexOf('"', 1) : splitIndex = input.IndexOf(' ', 0); + if (splitIndex == -1) { - if (reason[i].Contains("\"")) - reason[i] = ""; + plStr = input; } - for (int i = 0; i < reason.Length; i++) + else { - banReason += reason[i]; + plStr = input.Substring(0, splitIndex).Trim().TrimEnd('"').TrimStart('"'); + reason = input.Substring(splitIndex + 1).Trim().TrimEnd('"').TrimStart('"'); } - int adminplr = args.PlayerID; - int player = Tools.FindPlayer(plStr); - if (!(player == -1 || player == -2 || plStr == "")) + Log.Debug("plStr : '" + plStr + "', reason : '" + reason + "'"); + int ply = args.PlayerID; + if (plStr.Length != 0) { - if (!Tools.Ban(player, banReason.Equals("") ? "Misbehaviour." : banReason, Tools.FindPlayer(adminplr))) + int player = Tools.FindPlayer(plStr); + if (player == -1) + Tools.SendMessage(ply, "Invalid player!", new[] { 255f, 0f, 0f }); + else if (player == -2) + Tools.SendMessage(ply, "More than one player matched!", new[] { 255f, 0f, 0f }); + else { - Tools.SendMessage(adminplr, "You can't ban another admin!", new[] {255f, 0f, 0f}); + if (!Tools.Ban(player, reason.Length != 0 ? reason : "Misbehaviour.")) + { + Tools.SendMessage(ply, "You can't ban another admin!", new[] { 255f, 0f, 0f }); + } } } - else if (Tools.FindPlayer(plStr) == -2) - Tools.SendMessage(adminplr, "More than one player matched!", new[] {255f, 0f, 0f}); else - Tools.SendMessage(adminplr, "Invalid player!", new[] {255f, 0f, 0f}); + Tools.SendMessage(ply, "Invalid syntax! Proper syntax: /ban [reason]", + new[] { 255f, 0f, 0f }); } public static void Off(CommandArgs args) diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 81c60876..ec4fccca 100644 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -232,7 +232,7 @@ namespace TShockAPI string playerName = Main.player[ply].name; NetMessage.SendData(0x2, ply, -1, "Kicked: " + reason, 0x0, 0f, 0f, 0f); Log.Info("Kicked " + playerName + " for : " + reason); - if (adminUserName.Equals("")) + if (adminUserName.Length == 0) Broadcast(playerName + " was kicked for " + reason.ToLower()); else Tools.Broadcast(adminUserName + " kicked " + playerName + " for " + reason.ToLower()); @@ -255,7 +255,7 @@ namespace TShockAPI TShock.Bans.AddBan(ip, playerName, reason); NetMessage.SendData(0x2, plr, -1, "Banned: " + reason, 0x0, 0f, 0f, 0f); Log.Info("Banned " + playerName + " for : " + reason); - if (adminUserName.Equals("")) + if (adminUserName.Length == 0) Broadcast(playerName + " was banned for " + reason.ToLower()); else Tools.Broadcast(adminUserName + " banned " + playerName + " for " + reason.ToLower()); From 0a494583024d734144c1a353aa346cfb7ee3f56b Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 7 Jun 2011 18:51:42 +1000 Subject: [PATCH 3/7] Removed debug logs used for testing kick/ban commands --- TShockAPI/Commands.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 16a56959..03e5a514 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -193,7 +193,6 @@ namespace TShockAPI plStr = input.Substring(0, splitIndex).Trim().TrimEnd('"').TrimStart('"'); reason = input.Substring(splitIndex + 1).Trim().TrimEnd('"').TrimStart('"'); } - Log.Debug("plStr : '" + plStr + "', reason : '" + reason + "'"); int ply = args.PlayerID; if (plStr.Length != 0) { @@ -230,7 +229,6 @@ namespace TShockAPI plStr = input.Substring(0, splitIndex).Trim().TrimEnd('"').TrimStart('"'); reason = input.Substring(splitIndex + 1).Trim().TrimEnd('"').TrimStart('"'); } - Log.Debug("plStr : '" + plStr + "', reason : '" + reason + "'"); int ply = args.PlayerID; if (plStr.Length != 0) { From 97e0b67cf8b671f5e2abb0a7a0b6995a1b608f03 Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 7 Jun 2011 18:56:54 +1000 Subject: [PATCH 4/7] Using ForceKick instead of imunity check based kick for name based ban check and too long name --- TShockAPI/TShock.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index ad31bdc7..f9636d85 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -204,13 +204,15 @@ namespace TShockAPI var ban = Bans.GetBanByName(Main.player[e.Msg.whoAmI].name); if (ban != null) { - Tools.Kick(e.Msg.whoAmI, "You are banned: " + ban.Reason); + Tools.ForceKick(e.Msg.whoAmI, "You are banned: " + ban.Reason); + e.Handled = true; } - if (Main.player[e.Msg.whoAmI].name.Length > 32) + else if (Main.player[e.Msg.whoAmI].name.Length > 32) { - Tools.Kick(e.Msg.whoAmI, "Name exceeded 32 characters."); + Tools.ForceKick(e.Msg.whoAmI, "Name exceeded 32 characters."); + e.Handled = true; } - if (players[e.Msg.whoAmI] == null) + else if (players[e.Msg.whoAmI] == null) { Tools.ForceKick(e.Msg.whoAmI, "Player doesn't exist"); e.Handled = true; From cfd4de2f32b22a001f19e712569742cf361e1673 Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 7 Jun 2011 20:34:15 +1000 Subject: [PATCH 5/7] Fixed errors from failed merge --- TShockAPI/Commands.cs | 2 -- TShockAPI/Tools.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 045e1d1a..38cc0ee4 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -246,8 +246,6 @@ namespace TShockAPI Tools.SendMessage(ply, "You can't ban another admin!", new[] { 255f, 0f, 0f }); } } - else - Tools.SendMessage(adminplr, "You can't ban another admin!", new[] { 255f, 0f, 0f }); } else Tools.SendMessage(ply, "Invalid syntax! Proper syntax: /ban [reason]", diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 9502ebda..8d04c9f1 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -227,7 +227,7 @@ namespace TShockAPI public static bool Kick(int ply, string reason, string adminUserName = "") { if (!Main.player[ply].active) - return; + return false; if (!TShock.players[ply].group.HasPermission("immunetokick")) { string playerName = Main.player[ply].name; From a87eeaffeb18e7d821a0bfe9bcd5b637f882432f Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 7 Jun 2011 20:45:09 +1000 Subject: [PATCH 6/7] Fixed ban to not kick inactive players as well. --- TShockAPI/Tools.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 8d04c9f1..28c5cb35 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -227,7 +227,7 @@ namespace TShockAPI public static bool Kick(int ply, string reason, string adminUserName = "") { if (!Main.player[ply].active) - return false; + return true; if (!TShock.players[ply].group.HasPermission("immunetokick")) { string playerName = Main.player[ply].name; @@ -254,7 +254,8 @@ namespace TShockAPI string ip = GetPlayerIP(plr); string playerName = Main.player[plr].name; TShock.Bans.AddBan(ip, playerName, reason); - NetMessage.SendData(0x2, plr, -1, "Banned: " + reason, 0x0, 0f, 0f, 0f); + if (!Main.player[plr].active) + NetMessage.SendData(0x2, plr, -1, "Banned: " + reason, 0x0, 0f, 0f, 0f); Log.Info("Banned " + playerName + " for : " + reason); if (adminUserName.Length == 0) Broadcast(playerName + " was banned for " + reason.ToLower()); From 0a3120b8c6ae335f68b01366c7a56061df8d865f Mon Sep 17 00:00:00 2001 From: ricky Date: Tue, 7 Jun 2011 23:09:37 +1000 Subject: [PATCH 7/7] Copy paste fail --- TShockAPI/Tools.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index a04c5126..b3610800 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -254,7 +254,7 @@ namespace TShockAPI string ip = GetPlayerIP(plr); string playerName = Main.player[plr].name; TShock.Bans.AddBan(ip, playerName, reason); - if (!Main.player[plr].active || Netplay.serverSock[ply].kill) + if (!Main.player[plr].active || Netplay.serverSock[plr].kill) NetMessage.SendData(0x2, plr, -1, "Banned: " + reason, 0x0, 0f, 0f, 0f); Log.Info("Banned " + playerName + " for : " + reason); if (adminUserName.Length == 0)