diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e18f284..ca6a4c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed erroneous kicks and bans when using `KickOnMediumcoreDeath` and `BanOnMediumcoreDeath` options. (@DankRank) * Removed `TSPlayer.InitSpawn` field. (@DankRank) * `OnPlayerSpawn`'s player ID field is now `PlayerId`. (@DankRank) +* Enabled banning unregistered users (@QuiCM) * Added filtering and validation on packet 96 (Teleport player through portal) (@QuiCM) ## TShock 4.3.25 diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index bf814190..840ee72e 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1309,16 +1309,20 @@ namespace TShockAPI // Effective ban target assignment List players = TSPlayer.FindByNameOrID(args.Parameters[1]); + + // Bad case: Players contains more than 1 person so we can't ban them + if (players.Count > 1) + { + //Fail fast + args.Player.SendMultipleMatchError(players.Select(p => p.Name)); + return; + } + UserAccount offlineUserAccount = TShock.UserAccounts.GetUserAccountByName(args.Parameters[1]); // Storage variable to determine if the command executor is the server console // If it is, we assume they have full control and let them override permission checks - bool callerIsServerConsole = false; - - if (args.Player is TSServerPlayer) - { - callerIsServerConsole = true; - } + bool callerIsServerConsole = args.Player is TSServerPlayer; // The ban reason the ban is going to have string banReason = "Unknown."; @@ -1331,16 +1335,18 @@ namespace TShockAPI if (args.Parameters.Count >= 3) { bool parsedOkay = false; - if (!(args.Parameters[2] == "0")) + if (args.Parameters[2] != "0") { parsedOkay = TShock.Utils.TryParseTime(args.Parameters[2], out banLengthInSeconds); - } else { + } + else + { parsedOkay = true; } if (!parsedOkay) { - args.Player.SendErrorMessage("Invalid time format. Example: 10d+5h+3m-2s."); + args.Player.SendErrorMessage("Invalid time format. Example: 10d 5h 3m 2s."); args.Player.SendErrorMessage("Use 0 (zero) for a permanent ban."); return; } @@ -1352,13 +1358,6 @@ namespace TShockAPI banReason = String.Join(" ", args.Parameters.Skip(3)); } - // Bad case: Players contains more than 1 person so we can't ban them - if (players.Count > 1) - { - args.Player.SendMultipleMatchError(players.Select(p => p.Name)); - return; - } - // Good case: Online ban for matching character. if (players.Count == 1) { @@ -1371,7 +1370,7 @@ namespace TShockAPI } targetGeneralizedName = target.Name; - success = TShock.Bans.AddBan(target.IP, target.Name, target.UUID, target.Account.Name, banReason, false, args.Player.Account.Name, + success = TShock.Bans.AddBan(target.IP, target.Name, target.UUID, target.Account?.Name ?? "", banReason, false, args.Player.Account.Name, banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s")); // Since this is an online ban, we need to dc the player and tell them now. @@ -1399,7 +1398,8 @@ namespace TShockAPI // If the target is a valid IP... string pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; Regex r = new Regex(pattern, RegexOptions.IgnoreCase); - if (r.IsMatch(args.Parameters[1])) { + if (r.IsMatch(args.Parameters[1])) + { targetGeneralizedName = "IP: " + args.Parameters[1]; success = TShock.Bans.AddBan(args.Parameters[1], "", "", "", banReason, false, args.Player.Account.Name, banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s")); @@ -1409,7 +1409,9 @@ namespace TShockAPI args.Player.SendErrorMessage("Note: An account named with this IP address also exists."); args.Player.SendErrorMessage("Note: It will also be banned."); } - } else { + } + else + { // Apparently there is no way to not IP ban someone // This means that where we would normally just ban a "character name" here // We can't because it requires some IP as a primary key.