Update naming and add auto retry if hash is wrong

This commit is contained in:
Stone_Red
2022-04-21 07:35:52 +02:00
parent 69929fd58a
commit f906d4581c
9 changed files with 93 additions and 93 deletions
@@ -18,7 +18,7 @@ public class HostCommands
public void Discover(string _)
{
ApiManager.SendMessageNewLine("Running local discovery routine...", NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine("Running local discovery routine...", NotificationMessageType.Info);
BroadcastClient.Send(ApiConfiguration.BroadcastPort, ApiConfiguration.PrivatePort.ToString());
Thread.Sleep(3000);
}
@@ -28,13 +28,13 @@ public class HostCommands
int activeHostsCount = hostsManager.CheckHostsActivity();
if (activeHostsCount == 0)
{
ApiManager.SendMessageNewLine("No active hosts found!", NotificationMessageType.Error);
ApiManager.SendMessageNewLine("Use 'add host xxx.xxx.xxx.xxx:yyyy' to add a new host.", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("No active hosts found!", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Use 'add host xxx.xxx.xxx.xxx:yyyy' to add a new host.", NotificationMessageType.Error);
}
ApiManager.SendMessageNewLine(string.Empty, NotificationMessageType.Info);
ApiManager.SendMessageNewLine($"{hostsManager.Count} known host(s).", NotificationMessageType.Info);
ApiManager.SendMessageNewLine($"{activeHostsCount} active host(s).", NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine(string.Empty, NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine($"{hostsManager.Count} known host(s).", NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine($"{activeHostsCount} active host(s).", NotificationMessageType.Info);
}
public void ListHosts(string _)
@@ -44,16 +44,16 @@ public class HostCommands
if (hosts.Count == 0)
{
ApiManager.SendMessageNewLine("No known hosts", NotificationMessageType.Warning);
ApiManager.SendNotificationMessageNewLine("No known hosts", NotificationMessageType.Warning);
return;
}
foreach (NetworkSocket host in hosts)
{
index++;
ApiManager.SendMessageNewLine($"{index}) {host.IPAddress}:{host.Port}", NotificationMessageType.Info);
ApiManager.SendMessageNewLine($"Last active: {host.LastActive}", NotificationMessageType.Info);
ApiManager.SendMessageNewLine(string.Empty, NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine($"{index}) {host.IPAddress}:{host.Port}", NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine($"Last active: {host.LastActive}", NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine(string.Empty, NotificationMessageType.Info);
}
Console.CursorTop--;
}
@@ -64,7 +64,7 @@ public class HostCommands
if (parts.Length != 2)
{
ApiManager.SendMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
return;
}
@@ -74,13 +74,13 @@ public class HostCommands
_ = int.TryParse(portInput, out int port);
if (port < 1000 || port >= 6000)
{
ApiManager.SendMessageNewLine("Invalid port number!", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Invalid port number!", NotificationMessageType.Error);
return;
}
if (!IPAddress.TryParse(ipAddressInput, out IPAddress? ipAddress))
{
ApiManager.SendMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
return;
}
@@ -88,12 +88,12 @@ public class HostCommands
if (!hostsManager.Contains(hostToRemove))
{
ApiManager.SendMessageNewLine("Host not in list", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Host not in list", NotificationMessageType.Error);
return;
}
hostsManager.Remove(new NetworkSocket(ipAddress.ToString(), port, DateTime.MinValue), true);
ApiManager.SendMessageNewLine($"Successfully Removed host!", NotificationMessageType.Success);
ApiManager.SendNotificationMessageNewLine($"Successfully Removed host!", NotificationMessageType.Success);
}
public void AddHost(string args)
@@ -102,7 +102,7 @@ public class HostCommands
if (parts.Length != 2)
{
ApiManager.SendMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
return;
}
@@ -114,7 +114,7 @@ public class HostCommands
if (port < 1000 || port >= 6000)
{
ApiManager.SendMessageNewLine("Invalid port number!", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Invalid port number!", NotificationMessageType.Error);
return;
}
else if (!IPAddress.TryParse(ipAddressInput, out ipAddress))
@@ -131,33 +131,33 @@ public class HostCommands
if (ipAddress is null)
{
ApiManager.SendMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
return;
}
try
{
ApiManager.SendMessageNewLine("Waiting for response...", NotificationMessageType.Info);
ApiManager.SendNotificationMessageNewLine("Waiting for response...", NotificationMessageType.Info);
NetworkSocket? localSocket = ApiManager.GetLocalSocket() ?? new NetworkSocket("0.0.0.0", 0, DateTime.MinValue);
List<NetworkSocket>? recivedHosts = NetworkClient.Send<List<NetworkSocket>>(ipAddress, port, "GetHostsList", localSocket);
if (recivedHosts is not null)
{
ApiManager.SendMessageNewLine($"Success! Added {recivedHosts.Count} new host(s).", NotificationMessageType.Success);
ApiManager.SendNotificationMessageNewLine($"Success! Added {recivedHosts.Count} new host(s).", NotificationMessageType.Success);
hostsManager.AddRange(recivedHosts);
}
else
{
ApiManager.SendMessageNewLine($"Invalid response!", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine($"Invalid response!", NotificationMessageType.Error);
}
}
catch (SocketException ex)
{
ApiManager.SendMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
}
catch (IOException ex)
{
ApiManager.SendMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
ApiManager.SendNotificationMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
}
}
}