Added unban & unbanip commands (see #868)

This commit is contained in:
Joonas Rikkonen
2018-12-10 14:39:38 +02:00
parent b1b443143f
commit ed37345317
7 changed files with 112 additions and 6 deletions
@@ -41,6 +41,16 @@ namespace Barotrauma.Networking
private List<BannedPlayer> bannedPlayers;
public IEnumerable<string> BannedNames
{
get { return bannedPlayers.Select(bp => bp.Name); }
}
public IEnumerable<string> BannedIPs
{
get { return bannedPlayers.Select(bp => bp.IP); }
}
public BanList()
{
bannedPlayers = new List<BannedPlayer>();
@@ -106,6 +116,36 @@ namespace Barotrauma.Networking
Save();
}
public void UnbanPlayer(string name)
{
var player = bannedPlayers.Find(bp => bp.Name == name);
if (player == null)
{
DebugConsole.Log("Could not unban player \""+name+"\". Matching player not found.");
}
else
{
DebugConsole.Log("Unbanned \"" + name + ".");
bannedPlayers.Remove(player);
Save();
}
}
public void UnbanIP(string ip)
{
var player = bannedPlayers.Find(bp => bp.IP == ip);
if (player == null)
{
DebugConsole.Log("Could not unban IP \"" + ip + "\". Matching player not found.");
}
else
{
DebugConsole.Log("Unbanned \"" + ip + ".");
bannedPlayers.Remove(player);
Save();
}
}
public bool IsBanned(string IP)
{
bannedPlayers.RemoveAll(bp => bp.ExpirationTime.HasValue && DateTime.Now > bp.ExpirationTime.Value);
@@ -16,16 +16,18 @@ namespace Barotrauma.Networking
Kick = 2,
[Description("Ban")]
Ban = 4,
[Description("Revoke Ban")]
Unban = 8,
[Description("Select submarine")]
SelectSub = 8,
SelectSub = 16,
[Description("Select game mode")]
SelectMode = 16,
SelectMode = 32,
[Description("Manage campaign")]
ManageCampaign = 32,
ManageCampaign = 64,
[Description("Console commands")]
ConsoleCommands = 64,
ConsoleCommands = 128,
[Description("Access server log")]
ServerLog = 128
ServerLog = 256
}
class PermissionPreset
@@ -872,6 +872,12 @@ namespace Barotrauma.Networking
}
}
break;
case ClientPermissions.Unban:
string unbannedName = inc.ReadString().ToLowerInvariant();
string unbannedIP = inc.ReadString();
UnbanPlayer(unbannedIP, unbannedIP);
break;
case ClientPermissions.EndRound:
if (gameStarted)
{
@@ -1662,7 +1668,20 @@ namespace Barotrauma.Networking
BanClient(client, reason, range, duration);
}
public override void UnbanPlayer(string playerName, string playerIP)
{
playerName = playerName.ToLowerInvariant();
if (!string.IsNullOrEmpty(playerIP))
{
banList.UnbanIP(playerIP);
}
else if (!string.IsNullOrEmpty(playerName))
{
banList.UnbanPlayer(playerName);
}
}
public void BanClient(Client client, string reason, bool range = false, TimeSpan? duration = null)
{
if (client == null) return;
@@ -216,6 +216,8 @@ namespace Barotrauma.Networking
public virtual void BanPlayer(string kickedName, string reason, bool range = false, TimeSpan? duration = null) { }
public virtual void UnbanPlayer(string playerName, string playerIP) { }
public virtual void Update(float deltaTime)
{
#if CLIENT