Add list files remote command

This commit is contained in:
Stone_Red
2023-12-14 00:03:42 +01:00
parent 6f8d15ec88
commit e20d133936
5 changed files with 106 additions and 2 deletions
@@ -103,7 +103,6 @@ public class ApiManager
}
SendNotificationMessageNewLine("Ports closed!", NotificationMessageType.Warning);
Environment.Exit(0);
}
public bool StartBroadcastListener()
@@ -130,6 +129,7 @@ public class ApiManager
networkClient.ListenTo<List<NetworkSocket>>("DiscoverAnswer", DiscoverAnswer);
networkClient.ListenTo<string>("Message", ReciveMessage);
networkClient.ListenTo<string>("HasFile", HasFile);
networkClient.ListenTo<string>("GetFilesList", GetFileList);
networkClient.StartListening(ApiConfiguration.PrivatePort);
}
catch (SocketException ex)
@@ -223,6 +223,13 @@ public class ApiManager
await recivedEventArgs.SendResponseAsync(FilesManager.Contains(recivedEventArgs.Data));
}
private async void GetFileList(object? sender, MessageRecivedEventArgs<string> recivedEventArgs)
{
SendNotificationMessageNewLine($"{recivedEventArgs.IpAddress} > Requesting file list", NotificationMessageType.Log);
await recivedEventArgs.SendResponseAsync(FilesManager.ToList().Select(f => new HyperFileDto(f)).ToList());
}
private void ReciveMessage(object? sender, MessageRecivedEventArgs<string> recivedEventArgs)
{
SendNotificationMessageNewLine($"Received \"{recivedEventArgs.Data}\" from {recivedEventArgs.IpAddress}.", NotificationMessageType.Info);