mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-08 15:56:23 +02:00
Prevent adding own host to host list
This commit is contained in:
@@ -155,7 +155,14 @@ public class HostCommands
|
|||||||
newHosts++;
|
newHosts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiManager.SendNotificationMessageNewLine($"Success! Added {newHosts} new host(s).", NotificationMessageType.Success);
|
if (newHosts > 0)
|
||||||
|
{
|
||||||
|
ApiManager.SendNotificationMessageNewLine($"Added {newHosts} new host(s).", NotificationMessageType.Success);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ApiManager.SendNotificationMessageNewLine($"No new hosts added.", NotificationMessageType.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ public class HostsManager
|
|||||||
|
|
||||||
public bool Add(NetworkSocket host)
|
public bool Add(NetworkSocket host)
|
||||||
{
|
{
|
||||||
if (!Contains(host))
|
if (!Contains(host) && !host.Equals(ApiManager.GetLocalSocket()))
|
||||||
{
|
{
|
||||||
hosts.Add(host);
|
hosts.Add(host);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveHosts();
|
SaveHosts();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -12,4 +12,19 @@ public class NetworkSocket
|
|||||||
Port = port;
|
Port = port;
|
||||||
LastActive = lastActive;
|
LastActive = lastActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is not NetworkSocket networkSocket)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return networkSocket.IPAddress == IPAddress && networkSocket.Port == Port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return HashCode.Combine(IPAddress, Port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user