Fixed ban not working with quotes around player name. Kick now also supports reason
This commit is contained in:
parent
cc92a38e40
commit
78d0480512
2 changed files with 54 additions and 27 deletions
|
|
@ -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 <player> [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 <player> [reason]",
|
||||
new[] { 255f, 0f, 0f });
|
||||
}
|
||||
|
||||
public static void Off(CommandArgs args)
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue