Fix output of add host command

This commit is contained in:
Stone_Red
2023-12-12 12:25:51 +01:00
parent 8ec9a7964a
commit a5983e427c
2 changed files with 21 additions and 6 deletions
@@ -148,9 +148,14 @@ public class HostCommands
if (recivedHosts is not null)
{
ApiManager.SendNotificationMessageNewLine($"Success! Added {recivedHosts.Count} new host(s).", NotificationMessageType.Success);
hostsManager.AddRange(recivedHosts);
hostsManager.Add(new NetworkSocket(ipAddress.ToString(), port, DateTime.Now));
int newHosts = hostsManager.AddRange(recivedHosts);
if (hostsManager.Add(new NetworkSocket(ipAddress.ToString(), port, DateTime.Now)))
{
newHosts++;
}
ApiManager.SendNotificationMessageNewLine($"Success! Added {newHosts} new host(s).", NotificationMessageType.Success);
}
else
{
@@ -10,23 +10,33 @@ public class HostsManager
private List<NetworkSocket> hosts = new List<NetworkSocket>();
public int Count => hosts.Count;
public void AddRange(IEnumerable<NetworkSocket> hosts)
public int AddRange(IEnumerable<NetworkSocket> hosts)
{
int newHosts = 0;
foreach (NetworkSocket host in hosts)
{
Add(host);
if (Add(host))
{
newHosts++;
}
}
SaveHosts();
return newHosts;
}
public void Add(NetworkSocket host)
public bool Add(NetworkSocket host)
{
if (!Contains(host))
{
hosts.Add(host);
return true;
}
SaveHosts();
return false;
}
public void Remove(NetworkSocket host, bool forceRemove = false)