Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ban/unban: support for offline players using SteamID
  • Loading branch information
jimmble committed Sep 20, 2017
commit 0bbb8610b49d05e2a34be2cbaf9aaff6ab718606
33 changes: 23 additions & 10 deletions Essentials/Commands/PlayerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,43 @@ public void Kick(string playerName)
public void Ban(string playerName)
{
var player = Utilities.GetPlayerByNameOrId(playerName);
if (player != null)
var steamUserId = 0ul;
if (player == null)
{
Context.Torch.Multiplayer.BanPlayer(player.SteamUserId);
Context.Respond($"Player '{player.DisplayName}' banned.");
if (!ulong.TryParse(playerName, out steamUserId) || playerName.Length != 17)
{
Context.Respond("Player not found. Use !ban <steamID> to ban offline players.");
return;
}
}
else
steamUserId = player.SteamUserId;
if (Context.Torch.Multiplayer.BannedPlayers.Contains(steamUserId))
{
Context.Respond("Player not found.");
Context.Respond("Player is already banned.");
return;
}
Context.Torch.Multiplayer.BanPlayer(steamUserId);
Context.Respond($"Player '{player?.DisplayName ?? steamUserId.ToString()}' banned.");
}

[Command("unban", "Unban a player from the game.")]
[Permission(MyPromoteLevel.Moderator)]
public void Unban(string playerName)
public void Unban(string steamIdStr)
{
var player = Utilities.GetPlayerByNameOrId(Context.Args.FirstOrDefault());
if (player != null)
if (!ulong.TryParse(steamIdStr, out var steamUserId) || steamIdStr.Length != 17)
{
Context.Torch.Multiplayer.BanPlayer(player.SteamUserId, false);
Context.Respond($"Player '{player.DisplayName}' unbanned.");
Context.Respond($"Usage: !unban <steamID>");
return;
}
if (Context.Torch.Multiplayer.BannedPlayers.Contains(steamUserId))
{
Context.Torch.Multiplayer.BanPlayer(steamUserId, false);
Context.Respond($"Player '{steamUserId}' unbanned.");
}
else
{
Context.Respond("Player not found.");
Context.Respond("Player is not banned.");
}
}

Expand Down