- Ban duration can be set in the UI prompt.

- Ban reasons & durations are listed in the banlist menu.
- Clients tell the server the reason when kicking/banning another client.
- Added GUINumberInput GUIComponent.
- Ban duration saving/loading fixes.
This commit is contained in:
Joonas Rikkonen
2017-07-02 21:36:17 +03:00
parent df0bdb64d6
commit 8ae2fb225c
8 changed files with 193 additions and 27 deletions
@@ -67,8 +67,8 @@ namespace Barotrauma.Networking
string name = separatedLine[0];
string ip = separatedLine[1];
DateTime? expirationTime = DateTime.Now;
if (separatedLine.Length > 2)
DateTime? expirationTime = null;
if (separatedLine.Length > 2 && !string.IsNullOrEmpty(separatedLine[2]))
{
DateTime parsedTime;
if (DateTime.TryParse(separatedLine[2], out parsedTime))
@@ -78,7 +78,7 @@ namespace Barotrauma.Networking
}
string reason = separatedLine.Length > 3 ? string.Join(",", separatedLine.Skip(3)) : "";
if (expirationTime.HasValue && expirationTime.Value > DateTime.Now) continue;
if (expirationTime.HasValue && DateTime.Now > expirationTime.Value) continue;
bannedPlayers.Add(new BannedPlayer(name, ip, reason, expirationTime));
}
@@ -91,7 +91,11 @@ namespace Barotrauma.Networking
System.Diagnostics.Debug.Assert(!name.Contains(','));
DebugConsole.Log("Banned " + name);
string logMsg = "Banned " + name;
if (!string.IsNullOrEmpty(reason)) logMsg += ", reason: " + reason;
if (duration.HasValue) logMsg += ", duration: " + duration.Value.ToString();
DebugConsole.Log(logMsg);
DateTime? expirationTime = null;
if (duration.HasValue)
@@ -158,7 +162,7 @@ namespace Barotrauma.Networking
foreach (BannedPlayer banned in bannedPlayers)
{
string line = banned.Name + "," + banned.IP;
if (banned.ExpirationTime.HasValue) line += "," + banned.ExpirationTime.Value.ToString();
line += "," + (banned.ExpirationTime.HasValue ? banned.ExpirationTime.Value.ToString() : "");
if (!string.IsNullOrWhiteSpace(banned.Reason)) line += "," + banned.Reason;
lines.Add(line);
@@ -754,21 +754,23 @@ namespace Barotrauma.Networking
switch (command)
{
case ClientPermissions.Kick:
string kickedName = inc.ReadString();
var kickedClient = connectedClients.Find(cl => cl != sender && cl.name == kickedName);
string kickedName = inc.ReadString().ToLowerInvariant();
string kickReason = inc.ReadString();
var kickedClient = connectedClients.Find(cl => cl != sender && cl.name.ToLowerInvariant() == kickedName);
if (kickedClient != null)
{
Log("Client \"" + sender.name + "\" kicked \"" + kickedClient.name + "\".", ServerLog.MessageType.ServerMessage);
KickClient(kickedClient, "Kicked by " + sender.name);
KickClient(kickedClient, string.IsNullOrEmpty(kickReason) ? "Kicked by " + sender.name : kickReason);
}
break;
case ClientPermissions.Ban:
string bannedName = inc.ReadString();
var bannedClient = connectedClients.Find(cl => cl != sender && cl.name == bannedName);
string bannedName = inc.ReadString().ToLowerInvariant();
string banReason = inc.ReadString();
var bannedClient = connectedClients.Find(cl => cl != sender && cl.name.ToLowerInvariant() == bannedName);
if (bannedClient != null)
{
Log("Client \"" + sender.name + "\" banned \"" + bannedClient.name + "\".", ServerLog.MessageType.ServerMessage);
BanClient(bannedClient, "Banned by " + sender.name, false);
BanClient(bannedClient, string.IsNullOrEmpty(banReason) ? "Banned by " + sender.name : banReason, false);
}
break;
case ClientPermissions.EndRound: