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.
This commit is contained in:
parent
bdce73f0dc
commit
1ad261a562
3 changed files with 127 additions and 133 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -208,19 +208,96 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kicks a player from the server without checking for immunetokick permission.
|
||||
/// </summary>
|
||||
/// <param name="ply">int player</param>
|
||||
/// <param name="reason">string reason</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kicks a player from the server.
|
||||
/// </summary>
|
||||
/// <param name="ply">int player</param>
|
||||
/// <param name="reason">string reason</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bans and kicks a player from the server.
|
||||
/// </summary>
|
||||
/// <param name="ply">int player</param>
|
||||
/// <param name="reason">string reason</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue