- Add host expiration check to the HostManager.Remove method

This commit is contained in:
Stone_Red
2022-01-27 23:46:59 +01:00
parent b1014a7c9a
commit b758fa3dd5
2 changed files with 7 additions and 3 deletions
@@ -34,9 +34,12 @@ internal class HostsManager
SaveHosts(); SaveHosts();
} }
public void Remove(NetworkSocket host) public void Remove(NetworkSocket host, bool forceRemove = false)
{ {
hosts.RemoveAll(x => x.IPAddress == host.IPAddress && x.Port == host.Port); if (DateTime.Now - host.LastActive >= new TimeSpan(24, 0, 0) || forceRemove)
{
hosts.RemoveAll(x => x.IPAddress == host.IPAddress && x.Port == host.Port);
}
SaveHosts(); SaveHosts();
} }
@@ -194,7 +194,7 @@ internal class InputHandler
if (!validIpAdress) if (!validIpAdress)
{ {
hostsManager.Remove(host); hostsManager.Remove(host, true);
continue; continue;
} }
@@ -210,6 +210,7 @@ internal class InputHandler
{ {
Console.CursorLeft = 0; Console.CursorLeft = 0;
ConsoleExt.WriteLine($"{host.IPAddress}:{host.Port} > Inactive", ConsoleColor.Red); ConsoleExt.WriteLine($"{host.IPAddress}:{host.Port} > Inactive", ConsoleColor.Red);
hostsManager.Remove(host); hostsManager.Remove(host);
continue; continue;
} }