From d603f7f25b9afa0d8af6d9059572802bdb040665 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 5 Sep 2021 12:35:17 -0500 Subject: bump Soulseek.NET --- src/slskd/slskd.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 55b58928..f2cde33f 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -68,7 +68,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- cgit v1.2.3 From abe489187e0ef051a535ec25431a5306ccf07e98 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 5 Sep 2021 12:35:29 -0500 Subject: add Rooms to options --- src/slskd/Options.cs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index aac43c0a..c9edece4 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -193,6 +193,14 @@ namespace slskd [Validate] public FiltersOptions Filters { get; private set; } = new FiltersOptions(); + /// + /// Gets a list of rooms to automatically join upon connection. + /// + [Argument(default, "rooms")] + [EnvironmentVariable("ROOMS")] + [Description("a list of rooms to automatically join")] + public string[] Rooms { get; private set; } = Array.Empty(); + /// /// Gets options for the web UI. /// -- cgit v1.2.3 From b2b4343a9fa973d16e9de14dd467737fc0b0a706 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 5 Sep 2021 12:37:06 -0500 Subject: automatically join configured rooms on connect --- src/slskd/Application/Application.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs index 3e054dc8..f7488ef3 100644 --- a/src/slskd/Application/Application.cs +++ b/src/slskd/Application/Application.cs @@ -425,6 +425,17 @@ namespace slskd // send whatever counts we have currently. we'll probably connect before the cache is primed, // so these will be zero initially, but we'll update them when the cache is filled. _ = SoulseekClient.SetSharedCountsAsync(State.SharedFileCache.Directories, State.SharedFileCache.Files); + _ = AutoJoinRooms(OptionsMonitor.CurrentValue.Rooms); + } + + private Task AutoJoinRooms(string[] rooms) + { + Logger.Information("Joining rooms {Rooms}", string.Join(", ", OptionsMonitor.CurrentValue.Rooms)); + + var tasks = rooms.Select(room => SoulseekClient.JoinRoomAsync(room) + .ContinueWith(task => Logger.Warning("Failed to join room {Room}: {Message}", room, task.Exception.InnerExceptions.First().Message), TaskContinuationOptions.OnlyOnFaulted)); + + return Task.WhenAll(tasks); } private async void Client_Disconnected(object sender, SoulseekClientDisconnectedEventArgs args) -- cgit v1.2.3 From ab99deace640229c91c4b8e4581cd9351e542eb2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 5 Sep 2021 12:42:12 -0500 Subject: detect room config changes and auto-join --- src/slskd/Application/Application.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs index f7488ef3..d5c0dcff 100644 --- a/src/slskd/Application/Application.cs +++ b/src/slskd/Application/Application.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -248,6 +248,13 @@ namespace slskd Logger.Information("File filter configuration changed. Shares must be re-scanned for changes to take effect."); } + if (PreviousOptions.Rooms.Except(newOptions.Rooms).Any() + || newOptions.Rooms.Except(PreviousOptions.Rooms).Any()) + { + Logger.Information("Room configuration changed. Joining any newly added rooms."); + _ = AutoJoinRooms(newOptions.Rooms); + } + // determine whether any Soulseek options changed. if so, we need to construct a patch // and invoke ReconfigureOptionsAsync(). var slskDiff = PreviousOptions.Soulseek.DiffWith(newOptions.Soulseek); -- cgit v1.2.3 From c5d98fd57c05229b0783e205778fa660c4e7e43c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 5 Sep 2021 12:42:39 -0500 Subject: don't try to join tracked rooms --- src/slskd/Application/Application.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs index d5c0dcff..8695bbb0 100644 --- a/src/slskd/Application/Application.cs +++ b/src/slskd/Application/Application.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -439,7 +439,11 @@ namespace slskd { Logger.Information("Joining rooms {Rooms}", string.Join(", ", OptionsMonitor.CurrentValue.Rooms)); - var tasks = rooms.Select(room => SoulseekClient.JoinRoomAsync(room) + // don't try to join rooms that we've already joined. the server returns no response in this case + // and the client believes the request has timed out. + var unjoined = rooms.Where(room => !RoomTracker.Rooms.ContainsKey(room)); + + var tasks = unjoined.Select(room => SoulseekClient.JoinRoomAsync(room) .ContinueWith(task => Logger.Warning("Failed to join room {Room}: {Message}", room, task.Exception.InnerExceptions.First().Message), TaskContinuationOptions.OnlyOnFaulted)); return Task.WhenAll(tasks); -- cgit v1.2.3 From 77d046ebde73896d3d35b6790aed50a8a0086c2c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 5 Sep 2021 13:39:31 -0500 Subject: rejoin previously tracked rooms on reconnect --- src/slskd/Application/Application.cs | 53 ++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs index 8695bbb0..59abcaaf 100644 --- a/src/slskd/Application/Application.cs +++ b/src/slskd/Application/Application.cs @@ -19,6 +19,7 @@ namespace slskd { using System; using System.Collections.Concurrent; + using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; @@ -252,7 +253,7 @@ namespace slskd || newOptions.Rooms.Except(PreviousOptions.Rooms).Any()) { Logger.Information("Room configuration changed. Joining any newly added rooms."); - _ = AutoJoinRooms(newOptions.Rooms); + _ = AutoJoinRoomsAsync(newOptions.Rooms); } // determine whether any Soulseek options changed. if so, we need to construct a patch @@ -425,28 +426,62 @@ namespace slskd Logger.Information("Connected to the Soulseek server"); } - private void Client_LoggedIn(object sender, EventArgs e) + private async void Client_LoggedIn(object sender, EventArgs e) { Logger.Information("Logged in to the Soulseek server as {Username}", Client.Username); // send whatever counts we have currently. we'll probably connect before the cache is primed, // so these will be zero initially, but we'll update them when the cache is filled. _ = SoulseekClient.SetSharedCountsAsync(State.SharedFileCache.Directories, State.SharedFileCache.Files); - _ = AutoJoinRooms(OptionsMonitor.CurrentValue.Rooms); + + // rejoin any rooms that we might have been in during the previous session + await JoinRoomsAsync(RoomTracker.Rooms.Keys); + + // join the rooms configured for autojoin. always do this after rejoining has completed. + await AutoJoinRoomsAsync(OptionsMonitor.CurrentValue.Rooms); } - private Task AutoJoinRooms(string[] rooms) + private Task AutoJoinRoomsAsync(string[] rooms) { - Logger.Information("Joining rooms {Rooms}", string.Join(", ", OptionsMonitor.CurrentValue.Rooms)); - // don't try to join rooms that we've already joined. the server returns no response in this case // and the client believes the request has timed out. var unjoined = rooms.Where(room => !RoomTracker.Rooms.ContainsKey(room)); + return JoinRoomsAsync(unjoined); + } + + private async Task JoinRoomsAsync(IEnumerable roomNames) + { + var tasks = new List(); + + foreach (var room in roomNames) + { + tasks.Add(JoinRoomAsync(room)); + } + + try + { + await Task.WhenAll(tasks); + } + catch (Exception ex) + { + Logger.Debug(ex, "Caught Exception in JoinRoomsAsync"); + } + } - var tasks = unjoined.Select(room => SoulseekClient.JoinRoomAsync(room) - .ContinueWith(task => Logger.Warning("Failed to join room {Room}: {Message}", room, task.Exception.InnerExceptions.First().Message), TaskContinuationOptions.OnlyOnFaulted)); + private async Task JoinRoomAsync(string roomName) + { + Logger.Debug("Joining room {Room}", roomName); - return Task.WhenAll(tasks); + try + { + var data = await SoulseekClient.JoinRoomAsync(roomName); + Logger.Information("Joined room {Room}", roomName); + Logger.Debug("Room data for {Room}: {Info}", roomName, data.ToJson()); + } + catch (Exception ex) + { + Logger.Warning("Failed to join room {Room}: {Message}", roomName, ex.Message); + } } private async void Client_Disconnected(object sender, SoulseekClientDisconnectedEventArgs args) -- cgit v1.2.3