diff --git a/src/Tgstation.Server.Api/ApiHeaders.cs b/src/Tgstation.Server.Api/ApiHeaders.cs index 1160e258ca..bf1c1cbb08 100644 --- a/src/Tgstation.Server.Api/ApiHeaders.cs +++ b/src/Tgstation.Server.Api/ApiHeaders.cs @@ -63,7 +63,7 @@ namespace Tgstation.Server.Api /// /// The client's user agent /// - public ProductHeaderValue UserAgent { get; } + public ProductHeaderValue UserAgent { get; } /// /// The client's API version @@ -102,13 +102,13 @@ namespace Tgstation.Server.Api /// /// The value of /// The value of - public ApiHeaders(ProductHeaderValue userAgent, string token) : this(userAgent, token, null, null) - { - if (userAgent == null) - throw new ArgumentNullException(nameof(userAgent)); - if (token == null) - throw new ArgumentNullException(nameof(token)); - } + public ApiHeaders(ProductHeaderValue userAgent, string token) : this(userAgent, token, null, null) + { + if (userAgent == null) + throw new ArgumentNullException(nameof(userAgent)); + if (token == null) + throw new ArgumentNullException(nameof(token)); + } /// /// Construct for password authentication @@ -117,21 +117,21 @@ namespace Tgstation.Server.Api /// The value of /// The value of public ApiHeaders(ProductHeaderValue userAgent, string username, string password) : this(userAgent, null, username, password) - { - if (userAgent == null) - throw new ArgumentNullException(nameof(userAgent)); - if (username == null) - throw new ArgumentNullException(nameof(username)); - if (password == null) - throw new ArgumentNullException(nameof(password)); - } + { + if (userAgent == null) + throw new ArgumentNullException(nameof(userAgent)); + if (username == null) + throw new ArgumentNullException(nameof(username)); + if (password == null) + throw new ArgumentNullException(nameof(password)); + } /// /// Construct and validates from a set of /// /// The containing the public ApiHeaders(RequestHeaders requestHeaders) - { + { var jsonAccept = new Microsoft.Net.Http.Headers.MediaTypeHeaderValue(ApplicationJson); if (!requestHeaders.Accept.Any(x => x.MediaType == jsonAccept.MediaType)) throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Client does not accept {0}!", ApplicationJson)); @@ -142,7 +142,7 @@ namespace Tgstation.Server.Api //assure the client user agent has a name and version if (String.IsNullOrWhiteSpace(clientUserAgent.Product.Name) || !Version.TryParse(clientUserAgent.Product.Version, out var clientVersion)) throw new InvalidOperationException("Malformed client user agent!"); - + //make sure the api header matches ours if (!requestHeaders.Headers.TryGetValue(ApiVersionHeader, out var apiUserAgentHeaderValues) || !ProductInfoHeaderValue.TryParse(apiUserAgentHeaderValues.FirstOrDefault(), out var apiUserAgent) || apiUserAgent.Product.Name != assemblyName.Name) throw new InvalidOperationException("Missing API version!"); @@ -166,7 +166,7 @@ namespace Tgstation.Server.Api if (String.IsNullOrEmpty(parameter)) throw new InvalidOperationException("Missing authentication parameter!"); - if(requestHeaders.Headers.TryGetValue(instanceIdHeader, out var instanceIdValues)) + if (requestHeaders.Headers.TryGetValue(instanceIdHeader, out var instanceIdValues)) { var instanceIdString = instanceIdValues.FirstOrDefault(); if (instanceIdString != default && Int64.TryParse(instanceIdString, out var instanceId)) @@ -243,5 +243,5 @@ namespace Tgstation.Server.Api if (instanceId.HasValue) headers.Add(instanceIdHeader, instanceId.ToString()); } - } + } } diff --git a/src/Tgstation.Server.Api/Models/DreamMaker.cs b/src/Tgstation.Server.Api/Models/DreamMaker.cs index ca4d092f7d..93c44bf71e 100644 --- a/src/Tgstation.Server.Api/Models/DreamMaker.cs +++ b/src/Tgstation.Server.Api/Models/DreamMaker.cs @@ -2,10 +2,10 @@ namespace Tgstation.Server.Api.Models { - /// - /// Represents the state of the DreamMaker compiler. Create action starts a new compile. Delete action cancels the current compile - /// - public sealed class DreamMaker : DreamMakerSettings + /// + /// Represents the state of the DreamMaker compiler. Create action starts a new compile. Delete action cancels the current compile + /// + public sealed class DreamMaker : DreamMakerSettings { /// /// The of the compiler diff --git a/src/Tgstation.Server.Api/Models/UserUpdate.cs b/src/Tgstation.Server.Api/Models/UserUpdate.cs index 4203beed1b..0d46e3ae42 100644 --- a/src/Tgstation.Server.Api/Models/UserUpdate.cs +++ b/src/Tgstation.Server.Api/Models/UserUpdate.cs @@ -3,11 +3,11 @@ /// /// For editing a given . Will never be returned by the API /// - public sealed class UserUpdate : User + public sealed class UserUpdate : User { /// /// Cleartext password of the /// public string Password { get; set; } - } + } } diff --git a/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs b/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs index 8016731376..841e39fa64 100644 --- a/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs +++ b/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs @@ -12,13 +12,13 @@ namespace Tgstation.Server.Api.Rights /// User has no rights /// None = 0, - /// - /// Allow read access to for the - /// - ReadUsers = 1, - /// - /// Allow write access to for the - /// - WriteUsers = 2 - } + /// + /// Allow read access to for the + /// + ReadUsers = 1, + /// + /// Allow write access to for the + /// + WriteUsers = 2 + } } diff --git a/src/Tgstation.Server.Api/Rights/RightsHelper.cs b/src/Tgstation.Server.Api/Rights/RightsHelper.cs index 7c4a9cfa5a..bf062d81e7 100644 --- a/src/Tgstation.Server.Api/Rights/RightsHelper.cs +++ b/src/Tgstation.Server.Api/Rights/RightsHelper.cs @@ -39,7 +39,7 @@ namespace Tgstation.Server.Api.Rights /// The /// The /// A representing the claim role name - public static string RoleNames(TRight right) where TRight: Enum + public static string RoleNames(TRight right) where TRight : Enum { var flags = new List(); IEnumerable GetRoleNames() diff --git a/src/Tgstation.Server.Client/ApiConflictException.cs b/src/Tgstation.Server.Client/ApiConflictException.cs index 189fd92009..b1070bcab2 100644 --- a/src/Tgstation.Server.Client/ApiConflictException.cs +++ b/src/Tgstation.Server.Client/ApiConflictException.cs @@ -18,7 +18,8 @@ namespace Tgstation.Server.Client { Message = "An unknown API error occurred!", SeverApiVersion = null - }, statusCode) { } + }, statusCode) + { } /// /// Construct an diff --git a/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs b/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs index fa202a8e18..dd18119024 100644 --- a/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs +++ b/src/Tgstation.Server.Client/Components/IDreamMakerClient.cs @@ -7,7 +7,7 @@ namespace Tgstation.Server.Client.Components /// /// For managing the compiler /// - public interface IDreamMakerClient + public interface IDreamMakerClient { /// /// Get the information diff --git a/src/Tgstation.Server.Client/Components/IInstanceClient.cs b/src/Tgstation.Server.Client/Components/IInstanceClient.cs index 3806edff94..21bad43280 100644 --- a/src/Tgstation.Server.Client/Components/IInstanceClient.cs +++ b/src/Tgstation.Server.Client/Components/IInstanceClient.cs @@ -52,5 +52,5 @@ namespace Tgstation.Server.Client.Components /// Access the /// IJobsClient Jobs { get; } - } + } } \ No newline at end of file diff --git a/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs b/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs index 9d32f8bb1a..5d73e4f2ee 100644 --- a/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs +++ b/src/Tgstation.Server.Client/Components/IInstanceUserClient.cs @@ -5,10 +5,10 @@ using Tgstation.Server.Api.Models; namespace Tgstation.Server.Client.Components { - /// - /// For managing s - /// - public interface IInstanceUserClient + /// + /// For managing s + /// + public interface IInstanceUserClient { /// /// Get the associated with the logged on user diff --git a/src/Tgstation.Server.Client/Components/IJobsClient.cs b/src/Tgstation.Server.Client/Components/IJobsClient.cs index 151dcfc33e..0b659841e9 100644 --- a/src/Tgstation.Server.Client/Components/IJobsClient.cs +++ b/src/Tgstation.Server.Client/Components/IJobsClient.cs @@ -9,8 +9,8 @@ namespace Tgstation.Server.Client.Components /// /// Access to running jobs /// - public interface IJobsClient - { + public interface IJobsClient + { /// /// List the s in the /// diff --git a/src/Tgstation.Server.Client/Components/InstanceUserClient.cs b/src/Tgstation.Server.Client/Components/InstanceUserClient.cs index 75d95a91bf..a45453a1fd 100644 --- a/src/Tgstation.Server.Client/Components/InstanceUserClient.cs +++ b/src/Tgstation.Server.Client/Components/InstanceUserClient.cs @@ -27,7 +27,7 @@ namespace Tgstation.Server.Client.Components public InstanceUserClient(IApiClient apiClient, Instance instance) { this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient)); - this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); + this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); } /// diff --git a/src/Tgstation.Server.Client/Components/JobsClient.cs b/src/Tgstation.Server.Client/Components/JobsClient.cs index 359be4887b..c4f08dca91 100644 --- a/src/Tgstation.Server.Client/Components/JobsClient.cs +++ b/src/Tgstation.Server.Client/Components/JobsClient.cs @@ -50,7 +50,7 @@ namespace Tgstation.Server.Client.Components { await Task.Delay(requeryRate, cancellationToken).ConfigureAwait(false); job = await Read(job, cancellationToken).ConfigureAwait(false); - if(job.Progress.HasValue && job.Progress != lastProgress) + if (job.Progress.HasValue && job.Progress != lastProgress) { progressCallback(job.Progress.Value); lastProgress = job.Progress; diff --git a/src/Tgstation.Server.Client/ConflictException.cs b/src/Tgstation.Server.Client/ConflictException.cs index f6f361b611..efa2744837 100644 --- a/src/Tgstation.Server.Client/ConflictException.cs +++ b/src/Tgstation.Server.Client/ConflictException.cs @@ -16,7 +16,7 @@ namespace Tgstation.Server.Client /// The for the public ConflictException(ErrorMessage errorMessage, HttpStatusCode statusCode) : base(errorMessage, statusCode) { } - + /// /// Construct a /// diff --git a/src/Tgstation.Server.Client/IUsersClient.cs b/src/Tgstation.Server.Client/IUsersClient.cs index 6ea5e5fe31..b0260c3174 100644 --- a/src/Tgstation.Server.Client/IUsersClient.cs +++ b/src/Tgstation.Server.Client/IUsersClient.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; @@ -13,9 +14,24 @@ namespace Tgstation.Server.Client /// Read the current user's information and general rights /// /// The for the operation - /// + /// A resulting in the current Task Read(CancellationToken cancellationToken); + /// + /// Get a specific + /// + /// The to get + /// The for the operation + /// A resulting in the requested + Task GetId(User user, CancellationToken cancellationToken); + + /// + /// List all s + /// + /// The for the operation + /// A resulting in a of all s + Task> List(CancellationToken cancellationToken); + /// /// Create a new /// diff --git a/src/Tgstation.Server.Client/ServerClient.cs b/src/Tgstation.Server.Client/ServerClient.cs index 502b2ca800..de049e6aa5 100644 --- a/src/Tgstation.Server.Client/ServerClient.cs +++ b/src/Tgstation.Server.Client/ServerClient.cs @@ -30,7 +30,7 @@ namespace Tgstation.Server.Client /// public IUsersClient Users { get; } - + /// /// The for the /// diff --git a/src/Tgstation.Server.Client/ServerClientFactory.cs b/src/Tgstation.Server.Client/ServerClientFactory.cs index bf44e1754f..9e7286d1a7 100644 --- a/src/Tgstation.Server.Client/ServerClientFactory.cs +++ b/src/Tgstation.Server.Client/ServerClientFactory.cs @@ -28,7 +28,7 @@ namespace Tgstation.Server.Client { this.productHeaderValue = productHeaderValue ?? throw new ArgumentNullException(nameof(productHeaderValue)); } - + /// public async Task CreateServerClient(Uri host, string username, string password, TimeSpan timeout, CancellationToken cancellationToken) { diff --git a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj index 5f6749d65c..b3b5b2063c 100644 --- a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj +++ b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj @@ -3,7 +3,7 @@ netstandard2.0 Full - 4.0.0.0-preview3 + 4.0.0.0-preview4 true Cyberboss /tg/station 13 diff --git a/src/Tgstation.Server.Client/UsersClient.cs b/src/Tgstation.Server.Client/UsersClient.cs index 39d1b68646..3578731509 100644 --- a/src/Tgstation.Server.Client/UsersClient.cs +++ b/src/Tgstation.Server.Client/UsersClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api; @@ -26,6 +27,12 @@ namespace Tgstation.Server.Client /// public Task Create(UserUpdate user, CancellationToken cancellationToken) => apiClient.Create(Routes.User, user, cancellationToken); + /// + public Task GetId(User user, CancellationToken cancellationToken) => apiClient.Read(Routes.SetID(Routes.User, user.Id), cancellationToken); + + /// + public Task> List(CancellationToken cancellationToken) => apiClient.Read>(Routes.List(Routes.User), cancellationToken); + /// public Task Read(CancellationToken cancellationToken) => apiClient.Read(Routes.User, cancellationToken); diff --git a/src/Tgstation.Server.Host.Console/Program.cs b/src/Tgstation.Server.Host.Console/Program.cs index 0a62b2ed4e..12da56b3b3 100644 --- a/src/Tgstation.Server.Host.Console/Program.cs +++ b/src/Tgstation.Server.Host.Console/Program.cs @@ -29,7 +29,7 @@ namespace Tgstation.Server.Host.Console var arguments = new List(args); var trace = arguments.Remove("--trace-host-watchdog"); var debug = arguments.Remove("--debug-host-watchdog"); - + loggerFactory.AddConsole(trace ? LogLevel.Trace : debug ? LogLevel.Debug : LogLevel.Information, true); if (trace && debug) diff --git a/src/Tgstation.Server.Host.Service/ServerService.cs b/src/Tgstation.Server.Host.Service/ServerService.cs index 97ff6944ea..58c923afe2 100644 --- a/src/Tgstation.Server.Host.Service/ServerService.cs +++ b/src/Tgstation.Server.Host.Service/ServerService.cs @@ -45,7 +45,7 @@ namespace Tgstation.Server.Host.Service { if (watchdogFactory == null) throw new ArgumentNullException(nameof(watchdogFactory)); - if(loggerFactory == null) + if (loggerFactory == null) throw new ArgumentNullException(nameof(loggerFactory)); loggerFactory.AddEventLog(new EventLogSettings @@ -59,7 +59,7 @@ namespace Tgstation.Server.Host.Service /// public int MaxMessageSize => (int)EventLog.MaximumKilobytes * 1024; - + /// public void WriteEntry(string message, EventLogEntryType type, int eventID, short category) => EventLog.WriteEntry(message, type, eventID, category); diff --git a/src/Tgstation.Server.Host.Watchdog/IWatchdog.cs b/src/Tgstation.Server.Host.Watchdog/IWatchdog.cs index 834ab78820..5ebd252dab 100644 --- a/src/Tgstation.Server.Host.Watchdog/IWatchdog.cs +++ b/src/Tgstation.Server.Host.Watchdog/IWatchdog.cs @@ -3,17 +3,17 @@ using System.Threading.Tasks; namespace Tgstation.Server.Host.Watchdog { - /// - /// The watchdog for a - /// + /// + /// The watchdog for a + /// public interface IWatchdog { - /// - /// Run the - /// - /// The arguments for the - /// The for the operation - /// A representing the running operation - Task RunAsync(string[] args, CancellationToken cancellationToken); + /// + /// Run the + /// + /// The arguments for the + /// The for the operation + /// A representing the running operation + Task RunAsync(string[] args, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs index eb38f98a17..bc81c91573 100644 --- a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs @@ -52,13 +52,14 @@ namespace Tgstation.Server.Host.Watchdog enumerator = enumerator.Select(x => Path.Combine(x, exeName)); var dotnetPath = enumerator - .Where(x => { + .Where(x => + { logger.LogTrace("Checking for dotnet at {0}", x); return File.Exists(x); - }) + }) .FirstOrDefault(); - if(dotnetPath == default) + if (dotnetPath == default) { logger.LogCritical("Unable to locate dotnet executable in PATH! Please ensure the .NET Core runtime is installed and is in your PATH!"); return; @@ -77,7 +78,7 @@ namespace Tgstation.Server.Host.Watchdog var sourcePath = "../../../../Tgstation.Server.Host/bin/Debug/netcoreapp2.0"; foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) Directory.CreateDirectory(dirPath.Replace(sourcePath, defaultAssemblyPath)); - + foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) File.Copy(newPath, newPath.Replace(sourcePath, defaultAssemblyPath), true); @@ -251,7 +252,7 @@ namespace Tgstation.Server.Host.Watchdog logger.LogInformation("Revert successful!"); } } - catch(Exception e) + catch (Exception e) { logger.LogWarning("Failed to move out active host assembly! Exception: {0}", e); } diff --git a/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs b/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs index 05934ba491..7fc431afc7 100644 --- a/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs +++ b/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; namespace Tgstation.Server.Host.Watchdog { - /// - public sealed class WatchdogFactory : IWatchdogFactory - { - /// - [ExcludeFromCodeCoverage] - public IWatchdog CreateWatchdog(ILoggerFactory loggerFactory) => new Watchdog(loggerFactory?.CreateLogger() ?? throw new ArgumentNullException(nameof(loggerFactory))); - } + /// + public sealed class WatchdogFactory : IWatchdogFactory + { + /// + [ExcludeFromCodeCoverage] + public IWatchdog CreateWatchdog(ILoggerFactory loggerFactory) => new Watchdog(loggerFactory?.CreateLogger() ?? throw new ArgumentNullException(nameof(loggerFactory))); + } } diff --git a/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs b/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs index 69c02c4b6f..baf93605a3 100644 --- a/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs +++ b/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs @@ -96,7 +96,7 @@ namespace Tgstation.Server.Host.Components.Byond if (!installed) installedVersions.Add(versionKey, ourTcs.Task); } - if(installed) + if (installed) using (cancellationToken.Register(() => ourTcs.SetCanceled())) { await Task.WhenAny(ourTcs.Task, inProgressTask).ConfigureAwait(false); @@ -140,7 +140,7 @@ namespace Tgstation.Server.Host.Components.Byond //make sure to do this last because this is what tells us we have a valid version in the future await ioManager.WriteAllBytes(ioManager.ConcatPath(versionKey, VersionFileName), Encoding.UTF8.GetBytes(version.ToString()), cancellationToken).ConfigureAwait(false); } - catch(OperationCanceledException) + catch (OperationCanceledException) { throw; } @@ -152,7 +152,7 @@ namespace Tgstation.Server.Host.Components.Byond ourTcs.SetResult(null); } - catch(Exception e) + catch (Exception e) { lock (installedVersions) installedVersions.Remove(versionKey); diff --git a/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs b/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs index 8c2e742b30..b0526707b9 100644 --- a/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs @@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Components.Byond /// Get the file name of the DreamDaemon executable /// string DreamDaemonName { get; } - + /// /// Get the file name of the DreamMaker executable /// diff --git a/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs b/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs index 4bbcc351a2..4210e111bb 100644 --- a/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs @@ -20,7 +20,7 @@ namespace Tgstation.Server.Host.Components.Byond /// /// Path to the BYOND cache /// - const string ByondCachePath = "~/.byond"; //TODO: Verify this is correct!!!!! + const string ByondCachePath = "~/.byond"; //TODO: Verify this is correct!!!!! /// public string DreamDaemonName => "DreamDaemon"; diff --git a/src/Tgstation.Server.Host/Components/Chat/Channel.cs b/src/Tgstation.Server.Host/Components/Chat/Channel.cs index 0e3c4afe65..131ce67962 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Channel.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Channel.cs @@ -7,7 +7,7 @@ namespace Tgstation.Server.Host.Components.Chat /// /// Represents a channel /// - public sealed class Channel + public sealed class Channel { /// /// Backing field for . Represented as a to avoid BYOND percision loss diff --git a/src/Tgstation.Server.Host/Components/Chat/Chat.cs b/src/Tgstation.Server.Host/Components/Chat/Chat.cs index 1a48978243..e5653dc5e0 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Chat.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Chat.cs @@ -67,7 +67,7 @@ namespace Tgstation.Server.Host.Components.Chat /// The initial for the /// readonly List initialChatBots; - + /// /// The for the /// @@ -228,7 +228,7 @@ namespace Tgstation.Server.Host.Components.Chat var command = splits[0].ToUpperInvariant(); splits.RemoveAt(0); var arguments = String.Join(" ", splits); - + try { async Task GetCommand(string commandName) @@ -282,7 +282,7 @@ namespace Tgstation.Server.Host.Components.Chat } var result = await commandHandler.Invoke(arguments, message.User, cancellationToken).ConfigureAwait(false); - if(result != null) + if (result != null) await SendMessage(result, new List { message.User.Channel.RealId }, cancellationToken).ConfigureAwait(false); } catch (Exception e) @@ -318,7 +318,7 @@ namespace Tgstation.Server.Host.Components.Chat if (I.Value.Connected && !messageTasks.ContainsKey(I.Value)) messageTasks.Add(I.Value, I.Value.NextMessage(cancellationToken)); - if(messageTasks.Count == 0) + if (messageTasks.Count == 0) { await Task.Delay(1000, cancellationToken).ConfigureAwait(false); continue; @@ -326,7 +326,7 @@ namespace Tgstation.Server.Host.Components.Chat //wait for a message await Task.WhenAny(updatedTask, Task.WhenAny(messageTasks.Select(x => x.Value))).ConfigureAwait(false); - + //process completed ones foreach (var I in messageTasks.Where(x => x.Value.IsCompleted).ToList()) { @@ -339,7 +339,7 @@ namespace Tgstation.Server.Host.Components.Chat } } catch (OperationCanceledException) { } - catch(Exception e) + catch (Exception e) { logger.LogError("Message monitor crashed!: Exception: {0}", e); } @@ -438,7 +438,7 @@ namespace Tgstation.Server.Host.Components.Chat { if (newSettings.Enabled.Value) await provider.Connect(cancellationToken).ConfigureAwait(false); - lock(this) + lock (this) { //same thread shennanigans var oldOne = connectionsUpdated; @@ -459,7 +459,7 @@ namespace Tgstation.Server.Host.Components.Chat return Task.WhenAll(channelIds.Select(x => { ChannelMapping channelMapping; - lock(mappedChannels) + lock (mappedChannels) if (!mappedChannels.TryGetValue(x, out channelMapping)) return Task.CompletedTask; IProvider provider; diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs b/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs index 8e4ab3407b..4fc1329766 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs @@ -13,7 +13,7 @@ namespace Tgstation.Server.Host.Components.Chat /// The for the /// readonly IIOManager ioManager; - + /// /// The for the /// diff --git a/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs b/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs index ae9633671d..928e64f387 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ProviderFactory.cs @@ -56,7 +56,7 @@ namespace Tgstation.Server.Host.Components.Chat IrcPasswordType? passwordType = null; string password = null; - if(splits.Length > 4) + if (splits.Length > 4) { if (splits.Length < 6) throw new InvalidOperationException("Invalid connection string!"); diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs index fe4ade8202..3ee2e682ad 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs @@ -38,7 +38,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers /// The for the /// readonly DiscordSocketClient client; - + /// /// The token used for connecting to discord /// @@ -83,7 +83,8 @@ namespace Tgstation.Server.Host.Components.Chat.Providers if (!pm && !mappedChannels.Contains(e.Channel.Id)) return e.MentionedUsers.Any(x => x.Id == client.CurrentUser.Id) ? SendMessage(e.Channel.Id, "I do not respond to this channel!", default) : Task.CompletedTask; - var result = new Message { + var result = new Message + { Content = e.Content, User = new User { @@ -132,7 +133,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers logger.LogWarning("Error connecting to Discord: {0}", e); return false; } - + return true; } diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs index 72af093b06..f8f6197396 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs @@ -105,7 +105,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers if (passwordType.HasValue && password == null) throw new ArgumentNullException(nameof(password)); - if(password != null && !passwordType.HasValue) + if (password != null && !passwordType.HasValue) throw new ArgumentNullException(nameof(passwordType)); this.password = password; @@ -308,7 +308,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers logger.LogWarning("Unable to connect to IRC: {0}", e); } return true; - }, cancellationToken,TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); /// public override async Task Disconnect(CancellationToken cancellationToken) @@ -357,7 +357,8 @@ namespace Tgstation.Server.Host.Components.Chat.Providers foreach (var I in hs) client.RfcJoin(I); - return (IReadOnlyList)channels.Select(x => { + return (IReadOnlyList)channels.Select(x => + { var id = channelIdCounter; if (!channelIdMap.Any(y => { @@ -378,11 +379,11 @@ namespace Tgstation.Server.Host.Components.Chat.Providers FriendlyName = channelIdMap[id], IsPrivate = false, Tag = x.Tag - }; + }; }).ToList(); } }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); - + /// public override Task SendMessage(ulong channelId, string message, CancellationToken cancellationToken) => Task.Factory.StartNew(() => { @@ -399,7 +400,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers { client.SendMessage(sendType, channelName, message); } - catch(Exception e) + catch (Exception e) { logger.LogWarning("Unable to send to channel: {0}", e); } diff --git a/src/Tgstation.Server.Host/Components/Compiler/DreamMaker.cs b/src/Tgstation.Server.Host/Components/Compiler/DreamMaker.cs index 514b574631..1088833d24 100644 --- a/src/Tgstation.Server.Host/Components/Compiler/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/Compiler/DreamMaker.cs @@ -77,10 +77,14 @@ namespace Tgstation.Server.Host.Components.Compiler /// readonly IProcessExecutor processExecutor; /// + /// The for + /// + readonly IWatchdog watchdog; + /// /// The for /// readonly ILogger logger; - + /// /// Construct /// @@ -93,8 +97,9 @@ namespace Tgstation.Server.Host.Components.Compiler /// The value of /// The value of /// The value of + /// The value of /// The value of - public DreamMaker(IByondManager byond, IIOManager ioManager, StaticFiles.IConfiguration configuration, ISessionControllerFactory sessionControllerFactory, ICompileJobConsumer compileJobConsumer, IApplication application, IEventConsumer eventConsumer, IChat chat, IProcessExecutor processExecutor, ILogger logger) + public DreamMaker(IByondManager byond, IIOManager ioManager, StaticFiles.IConfiguration configuration, ISessionControllerFactory sessionControllerFactory, ICompileJobConsumer compileJobConsumer, IApplication application, IEventConsumer eventConsumer, IChat chat, IProcessExecutor processExecutor, IWatchdog watchdog, ILogger logger) { this.byond = byond; this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); @@ -105,6 +110,7 @@ namespace Tgstation.Server.Host.Components.Compiler this.eventConsumer = eventConsumer ?? throw new ArgumentNullException(nameof(eventConsumer)); this.chat = chat ?? throw new ArgumentNullException(nameof(chat)); this.processExecutor = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor)); + this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); } @@ -120,7 +126,7 @@ namespace Tgstation.Server.Host.Components.Compiler /// A resulting in if the DMAPI was successfully validated, otherwise async Task VerifyApi(uint timeout, DreamDaemonSecurity securityLevel, Models.CompileJob job, IByondExecutableLock byondLock, ushort portToUse, CancellationToken cancellationToken) { - logger.LogTrace("Verifying DMAPI..."); + logger.LogTrace("Verifying DMAPI..."); var launchParameters = new DreamDaemonLaunchParameters { AllowWebClient = false, @@ -267,7 +273,7 @@ namespace Tgstation.Server.Host.Components.Compiler Status = CompilerStatus.Copying; } - + try { var commitInsert = revisionInformation.CommitSha.Substring(0, 7); @@ -386,7 +392,7 @@ namespace Tgstation.Server.Host.Components.Compiler await Task.WhenAll(symATask, symBTask).ConfigureAwait(false); - await chat.SendUpdateMessage("Deployment complete! Changes will be applied on next server reboot.", cancellationToken).ConfigureAwait(false); + await chat.SendUpdateMessage(String.Format(CultureInfo.InvariantCulture, "Deployment complete!{0}", watchdog.Running ? " Changes will be applied on next server reboot." : String.Empty), cancellationToken).ConfigureAwait(false); logger.LogDebug("Compile complete!"); return job; diff --git a/src/Tgstation.Server.Host/Components/EventType.cs b/src/Tgstation.Server.Host/Components/EventType.cs index e60a1661a5..add5b3c21a 100644 --- a/src/Tgstation.Server.Host/Components/EventType.cs +++ b/src/Tgstation.Server.Host/Components/EventType.cs @@ -54,7 +54,7 @@ /// Parameters: Game directory path /// CompileComplete = 11, - + /// /// Parameters: Exit code /// diff --git a/src/Tgstation.Server.Host/Components/IEventConsumer.cs b/src/Tgstation.Server.Host/Components/IEventConsumer.cs index 55945548c2..aa30d18827 100644 --- a/src/Tgstation.Server.Host/Components/IEventConsumer.cs +++ b/src/Tgstation.Server.Host/Components/IEventConsumer.cs @@ -7,8 +7,8 @@ namespace Tgstation.Server.Host.Components /// /// Consumes s and takes the appropriate actions /// - public interface IEventConsumer - { + public interface IEventConsumer + { /// /// Handle a given /// @@ -17,5 +17,5 @@ namespace Tgstation.Server.Host.Components /// The for the operation /// A resulting in if more should run, otherwise Task HandleEvent(EventType eventType, IEnumerable parameters, CancellationToken cancellationToken); - } + } } diff --git a/src/Tgstation.Server.Host/Components/IInstanceFactory.cs b/src/Tgstation.Server.Host/Components/IInstanceFactory.cs index afe123e5fc..e2595ec183 100644 --- a/src/Tgstation.Server.Host/Components/IInstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/IInstanceFactory.cs @@ -1,7 +1,4 @@ -using Tgstation.Server.Host.Components.Watchdog; -using Tgstation.Server.Host.Core; - -namespace Tgstation.Server.Host.Components +namespace Tgstation.Server.Host.Components { /// /// Factory for creating s diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 3d136dd405..2098055031 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -152,7 +152,7 @@ namespace Tgstation.Server.Host.Components commandFactory.SetWatchdog(watchdog); try { - var dreamMaker = new DreamMaker(byond, gameIoManager, configuration, sessionControllerFactory, dmbFactory, application, eventConsumer, chat, processExecutor, loggerFactory.CreateLogger()); + var dreamMaker = new DreamMaker(byond, gameIoManager, configuration, sessionControllerFactory, dmbFactory, application, eventConsumer, chat, processExecutor, watchdog, loggerFactory.CreateLogger()); return new Instance(metadata.CloneMetadata(), repoManager, byond, dreamMaker, watchdog, chat, configuration, dmbFactory, databaseContextFactory, dmbFactory, loggerFactory.CreateLogger()); } diff --git a/src/Tgstation.Server.Host/Components/Interop/CommContext.cs b/src/Tgstation.Server.Host/Components/Interop/CommContext.cs index d8582afe93..d3f6b67caa 100644 --- a/src/Tgstation.Server.Host/Components/Interop/CommContext.cs +++ b/src/Tgstation.Server.Host/Components/Interop/CommContext.cs @@ -95,7 +95,7 @@ namespace Tgstation.Server.Host.Components.Interop /// /// The sender of the event /// The - async void HandleWrite(object sender, FileSystemEventArgs e) //this is what async void was made for + async void HandleWrite(object sender, FileSystemEventArgs e) //this is what async void was made for { try { @@ -113,11 +113,11 @@ namespace Tgstation.Server.Host.Components.Interop }; } catch (JsonSerializationException ex) - { + { //file not fully written yet logger.LogDebug("Suppressing json convert exception for command file write: {0}", ex); return; - } + } await (handler?.HandleInterop(command, cancellationToken) ?? Task.CompletedTask).ConfigureAwait(false); } diff --git a/src/Tgstation.Server.Host/Components/Interop/Constants.cs b/src/Tgstation.Server.Host/Components/Interop/Constants.cs index 55b7ff5b73..834a43063f 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Constants.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Constants.cs @@ -1,6 +1,6 @@ namespace Tgstation.Server.Host.Components.Interop { - static class Constants + static class Constants { //interop values, match them up with the appropriate api.dm diff --git a/src/Tgstation.Server.Host/Components/Interop/JsonFile.cs b/src/Tgstation.Server.Host/Components/Interop/JsonFile.cs index 861cb8cebb..4c318c21c3 100644 --- a/src/Tgstation.Server.Host/Components/Interop/JsonFile.cs +++ b/src/Tgstation.Server.Host/Components/Interop/JsonFile.cs @@ -22,7 +22,7 @@ namespace Tgstation.Server.Host.Components.Interop /// The of the owner at the time of launch /// public string InstanceName { get; set; } - + /// /// JSON file name that contains current active chat channel information /// diff --git a/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs b/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs index 0c8510bd75..de9f8c19ce 100644 --- a/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs +++ b/src/Tgstation.Server.Host/Components/ReattachInfoHandler.cs @@ -10,7 +10,7 @@ using Tgstation.Server.Host.Core; namespace Tgstation.Server.Host.Components { /// - sealed class ReattachInfoHandler: IReattachInfoHandler + sealed class ReattachInfoHandler : IReattachInfoHandler { /// /// The for the diff --git a/src/Tgstation.Server.Host/Components/Repository/IRepositoryManager.cs b/src/Tgstation.Server.Host/Components/Repository/IRepositoryManager.cs index ab5fcc0deb..5f249a6330 100644 --- a/src/Tgstation.Server.Host/Components/Repository/IRepositoryManager.cs +++ b/src/Tgstation.Server.Host/Components/Repository/IRepositoryManager.cs @@ -7,7 +7,7 @@ namespace Tgstation.Server.Host.Components.Repository /// /// Factory for creating and loading s /// - public interface IRepositoryManager : IDisposable + public interface IRepositoryManager : IDisposable { /// /// If a operation is in progress @@ -39,5 +39,5 @@ namespace Tgstation.Server.Host.Components.Repository /// The for the operation /// A representing the running operation Task DeleteRepository(CancellationToken cancellationToken); - } + } } diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index a792cfa9bc..b7fa727904 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -140,7 +140,7 @@ namespace Tgstation.Server.Host.Components.Repository var prBranchName = String.Format(CultureInfo.InvariantCulture, "pr-{0}", testMergeParameters.Number); var localBranchName = String.Format(CultureInfo.InvariantCulture, "pull/{0}/headrefs/heads/{1}", testMergeParameters.Number, prBranchName); - + var Refspec = new List { String.Format(CultureInfo.InvariantCulture, "pull/{0}/head:{1}", testMergeParameters.Number, prBranchName) }; var logMessage = String.Format(CultureInfo.InvariantCulture, "Merge remote pull request #{0}", testMergeParameters.Number); @@ -177,7 +177,7 @@ namespace Tgstation.Server.Host.Components.Repository catch (UserCancelledException) { } cancellationToken.ThrowIfCancellationRequested(); - + testMergeParameters.PullRequestRevision = repository.Lookup(testMergeParameters.PullRequestRevision ?? localBranchName).Sha; cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Tgstation.Server.Host/Components/Repository/RepositoryManager.cs b/src/Tgstation.Server.Host/Components/Repository/RepositoryManager.cs index b69e3d303b..7f3619e073 100644 --- a/src/Tgstation.Server.Host/Components/Repository/RepositoryManager.cs +++ b/src/Tgstation.Server.Host/Components/Repository/RepositoryManager.cs @@ -117,7 +117,7 @@ namespace Tgstation.Server.Host.Components.Repository /// public async Task LoadRepository(CancellationToken cancellationToken) { - lock(this) + lock (this) if (CloneInProgress) throw new InvalidOperationException("The repository is being cloned!"); await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index 0f431bea96..f62bf504ba 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -195,7 +195,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles var path = ValidateConfigRelativePath(configurationRelativePath); ConfigurationFile result = null; - + void ReadImpl() { lock (this) diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/IPostWriteHandler.cs b/src/Tgstation.Server.Host/Components/StaticFiles/IPostWriteHandler.cs index e406cfa665..a1db4b8d37 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/IPostWriteHandler.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/IPostWriteHandler.cs @@ -1,11 +1,11 @@ namespace Tgstation.Server.Host.Components.StaticFiles { - interface IPostWriteHandler - { + interface IPostWriteHandler + { /// /// For handling system specific necessities after a write /// /// The full path to the file that was written void HandleWrite(string filePath); - } + } } diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/PosixPostWriteHandler.cs b/src/Tgstation.Server.Host/Components/StaticFiles/PosixPostWriteHandler.cs index 90541a5174..a028fe1c03 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/PosixPostWriteHandler.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/PosixPostWriteHandler.cs @@ -18,7 +18,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles if (stat.st_mode.HasFlag(FilePermissions.S_IXUSR)) return; - if(Syscall.chmod(filePath, stat.st_mode | FilePermissions.S_IXUSR) != 0) + if (Syscall.chmod(filePath, stat.st_mode | FilePermissions.S_IXUSR) != 0) throw new UnixIOException(Stdlib.GetLastError()); } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/ISessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/ISessionControllerFactory.cs index 35f423adc3..645af10171 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/ISessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/ISessionControllerFactory.cs @@ -8,8 +8,8 @@ namespace Tgstation.Server.Host.Components.Watchdog /// /// Factory for s /// - interface ISessionControllerFactory - { + interface ISessionControllerFactory + { /// /// Create a from a freshly launch DreamDaemon instance /// @@ -30,5 +30,5 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The for the operation /// A resulting in a new Task Reattach(ReattachInformation reattachInformation, CancellationToken cancellationToken); - } + } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs b/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs index a4cd7172cd..cb2264c96f 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/MonitorState.cs @@ -5,8 +5,8 @@ namespace Tgstation.Server.Host.Components.Watchdog /// /// The (absolute) state of the /// - sealed class MonitorState - { + sealed class MonitorState + { /// /// If the inactive server is being rebooted /// @@ -38,5 +38,5 @@ namespace Tgstation.Server.Host.Components.Watchdog /// [JsonIgnore] public ISessionController InactiveServer { get; set; } - } + } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs b/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs index 6890df7bab..70b4dac3f5 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/RebootState.cs @@ -3,8 +3,8 @@ /// /// Represents the action to take when /world/Reboot() is called /// - public enum RebootState : int - { + public enum RebootState : int + { /// /// Run DreamDaemon's normal reboot process /// @@ -17,5 +17,5 @@ /// Restart the DreamDaemon process /// Restart = 2 - } + } } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs index e38b92b9bb..20b1115531 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs @@ -134,7 +134,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The port to assign DreamDaemon when it queries for it /// ushort? nextPort; - + /// /// The that completes when DD tells us about a reboot /// @@ -285,12 +285,13 @@ namespace Tgstation.Server.Host.Components.Watchdog case Constants.DMCommandNewPort: lock (this) { - if (!query.TryGetValue(Constants.DMParameterData, out var stringPort) || !UInt16.TryParse(stringPort, out var currentPort)) { + if (!query.TryGetValue(Constants.DMParameterData, out var stringPort) || !UInt16.TryParse(stringPort, out var currentPort)) + { /////UHHHH logger.LogWarning("DreamDaemon sent new port command without providing it's own!"); break; } - + if (!nextPort.HasValue) //not ready yet, so what we'll do is accept the random port DD opened on for now and change it later when we decide to reattachInformation.Port = currentPort; @@ -301,7 +302,7 @@ namespace Tgstation.Server.Host.Components.Watchdog content = new Dictionary { { Constants.DMParameterData, nextPort.Value } }; reattachInformation.Port = nextPort.Value; nextPort = null; - + //we'll also get here from SetPort so complete that task var tmpTcs = portAssignmentTcs; portAssignmentTcs = null; diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs index fd7209bb41..d4ce1cdc68 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs @@ -233,7 +233,7 @@ namespace Tgstation.Server.Host.Components.Watchdog { if (reattachInformation == null) throw new ArgumentNullException(nameof(reattachInformation)); - + var basePath = reattachInformation.IsPrimary ? reattachInformation.Dmb.PrimaryDirectory : reattachInformation.Dmb.SecondaryDirectory; var chatJsonTrackingContext = await chat.TrackJsons(basePath, reattachInformation.ChatChannelsJson, reattachInformation.ChatCommandsJson, cancellationToken).ConfigureAwait(false); try diff --git a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs index ee7dc6e07c..e0f82236a9 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs @@ -190,7 +190,7 @@ namespace Tgstation.Server.Host.Components.Watchdog bravoServer = null; Running = false; } - + /// /// Implementation of . Does not lock /// @@ -288,8 +288,8 @@ namespace Tgstation.Server.Host.Components.Watchdog { var dmbBackup = await dmbFactory.FromCompileJob(monitorState.ActiveServer.Dmb.CompileJob, cancellationToken).ConfigureAwait(false); - if (dmbBackup == null) //NANI!? - //just give up, if THAT compile job is failing then the ActiveServer is gonna crash soon too or already has + if (dmbBackup == null) //NANI!? + //just give up, if THAT compile job is failing then the ActiveServer is gonna crash soon too or already has throw new JobException("Creating backup DMB provider failed!"); monitorState.InactiveServer = await sessionControllerFactory.LaunchNew(ActiveLaunchParameters, dmbBackup, null, false, !monitorState.ActiveServer.IsPrimary, false, cancellationToken).ConfigureAwait(false); @@ -328,7 +328,7 @@ namespace Tgstation.Server.Host.Components.Watchdog { monitorState.ActiveServer.ClosePortOnReboot = false; if (monitorState.InactiveServerHasStagedDmb && !usedLatestDmb) - monitorState.InactiveServerHasStagedDmb = false; //don't try to load it again though + monitorState.InactiveServerHasStagedDmb = false; //don't try to load it again though } }; @@ -338,7 +338,7 @@ namespace Tgstation.Server.Host.Components.Watchdog switch (activationReason) { case MonitorActivationReason.ActiveServerCrashed: - if(monitorState.ActiveServer.RebootState == Components.Watchdog.RebootState.Shutdown) + if (monitorState.ActiveServer.RebootState == Components.Watchdog.RebootState.Shutdown) { await chat.SendWatchdogMessage(String.Format(CultureInfo.InvariantCulture, "Active server {0}! Exiting due to graceful termination request...", ExitWord(monitorState.ActiveServer)), cancellationToken).ConfigureAwait(false); monitorState.NextAction = MonitorAction.Exit; @@ -368,7 +368,7 @@ namespace Tgstation.Server.Host.Components.Watchdog //what matters here is the RebootState bool restartOnceSwapped = false; var rebootState = monitorState.ActiveServer.RebootState; - monitorState.ActiveServer.ResetRebootState(); //the DMAPI has already done this internally + monitorState.ActiveServer.ResetRebootState(); //the DMAPI has already done this internally switch (rebootState) { @@ -411,7 +411,7 @@ namespace Tgstation.Server.Host.Components.Watchdog } if (restartOnceSwapped) //for one reason or another - await UpdateAndRestartInactiveServer(true).ConfigureAwait(false); //break because worse case, active server is still booting + await UpdateAndRestartInactiveServer(true).ConfigureAwait(false); //break because worse case, active server is still booting else { monitorState.InactiveServer.ClosePortOnReboot = false; @@ -432,7 +432,7 @@ namespace Tgstation.Server.Host.Components.Watchdog break; case MonitorActivationReason.NewDmbAvailable: monitorState.InactiveServerHasStagedDmb = true; - await UpdateAndRestartInactiveServer(true).ConfigureAwait(false); //next case does same thing + await UpdateAndRestartInactiveServer(true).ConfigureAwait(false); //next case does same thing break; case MonitorActivationReason.ActiveLaunchParametersUpdated: await UpdateAndRestartInactiveServer(false).ConfigureAwait(false); @@ -449,18 +449,18 @@ namespace Tgstation.Server.Host.Components.Watchdog { logger.LogTrace("Entered MonitorLifetimes"); var iteration = 1; - for(var monitorState = new MonitorState(); monitorState.NextAction != MonitorAction.Exit; ++iteration) + for (var monitorState = new MonitorState(); monitorState.NextAction != MonitorAction.Exit; ++iteration) { monitorState.NextAction = MonitorAction.Continue; logger.LogDebug("Iteration {0} of monitor loop", iteration); try { - if(AlphaIsActive) + if (AlphaIsActive) logger.LogDebug("Alpha is the active server"); else logger.LogDebug("Bravo is the active server"); - if(monitorState.InactiveServerHasStagedDmb) + if (monitorState.InactiveServerHasStagedDmb) logger.LogDebug("Inactive server has staged .dmb"); if (monitorState.RebootingInactiveServer) logger.LogDebug("Inactive server is rebooting"); @@ -496,7 +496,7 @@ namespace Tgstation.Server.Host.Components.Watchdog { MonitorActivationReason activationReason = default; //multiple things may have happened, handle them one at a time - for (var moreActivationsToProcess = true; moreActivationsToProcess && monitorState.NextAction == MonitorAction.Continue; ) + for (var moreActivationsToProcess = true; moreActivationsToProcess && monitorState.NextAction == MonitorAction.Continue;) { if (activeServerLifetime?.IsCompleted == true) { @@ -528,7 +528,7 @@ namespace Tgstation.Server.Host.Components.Watchdog activationReason = MonitorActivationReason.NewDmbAvailable; newDmbAvailable = null; } - else if(activeLaunchParametersChanged?.IsCompleted == true) + else if (activeLaunchParametersChanged?.IsCompleted == true) { activationReason = MonitorActivationReason.ActiveLaunchParametersUpdated; activeLaunchParametersChanged = null; @@ -536,7 +536,7 @@ namespace Tgstation.Server.Host.Components.Watchdog else moreActivationsToProcess = false; - if(moreActivationsToProcess) + if (moreActivationsToProcess) await HandlerMonitorWakeup(activationReason, monitorState, cancellationToken).ConfigureAwait(false); } @@ -624,7 +624,7 @@ namespace Tgstation.Server.Host.Components.Watchdog logger.LogTrace("Aborted due to already running!"); return null; } - + Task chatTask; //this is necessary, the monitor could be in it's sleep loop trying to restart if (startMonitor && await StopMonitor().ConfigureAwait(false)) @@ -719,7 +719,7 @@ namespace Tgstation.Server.Host.Components.Watchdog if (!doesntNeedNewDmb && (alphaServer == null && bravoServer == null)) { dmbToUse.Dispose(); //guaranteed to not be null here - dmbToUse.Dispose(); //yes, dispose it twice. See the definition of IDmbFactory.LockNextDmb(), we called it with 2 locks + dmbToUse.Dispose(); //yes, dispose it twice. See the definition of IDmbFactory.LockNextDmb(), we called it with 2 locks } DisposeAndNullControllers(); throw; @@ -773,7 +773,7 @@ namespace Tgstation.Server.Host.Components.Watchdog { if (!await toReboot.SetRebootState(Components.Watchdog.RebootState.Restart, cancellationToken).ConfigureAwait(false)) logger.LogWarning("Unable to send reboot state change event!"); - + } return null; } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogReattachInformation.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogReattachInformation.cs index 5f7542e68d..f340a4cd8b 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogReattachInformation.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogReattachInformation.cs @@ -28,7 +28,7 @@ namespace Tgstation.Server.Host.Components.Watchdog /// The to copy information from /// The used to build /// The used to build - public WatchdogReattachInformation(Models.WatchdogReattachInformation copy, IDmbProvider dmbAlpha, IDmbProvider dmbBravo): base(copy) + public WatchdogReattachInformation(Models.WatchdogReattachInformation copy, IDmbProvider dmbAlpha, IDmbProvider dmbBravo) : base(copy) { if (copy.Alpha != null) Alpha = new ReattachInformation(copy.Alpha, dmbAlpha); diff --git a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs index 24ace9d9b9..e15aa4e1f8 100644 --- a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs +++ b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs @@ -74,7 +74,7 @@ namespace Tgstation.Server.Host.Controllers this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); updatesConfiguration = updatesConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(updatesConfigurationOptions)); } - + StatusCodeResult RateLimit(RateLimitExceededException exception) { Logger.LogWarning("Exceeded GitHub rate limit!"); @@ -157,13 +157,13 @@ namespace Tgstation.Server.Host.Controllers return UnprocessableEntity(new ErrorMessage { Message = RestartNotSupportedException - }); //unprocessable entity + }); //unprocessable entity } catch (InvalidOperationException) { return StatusCode((int)HttpStatusCode.ServiceUnavailable); //we were beat to the punch, really shouldn't happen but heat death of the universe and what not } - return Accepted(); //gtfo of here before all the cancellation tokens fire + return Accepted(); //gtfo of here before all the cancellation tokens fire } return StatusCode((int)HttpStatusCode.Gone); @@ -172,7 +172,8 @@ namespace Tgstation.Server.Host.Controllers /// [HttpDelete] [TgsAuthorize(AdministrationRights.RestartHost)] - public Task Delete() { + public Task Delete() + { try { return Task.FromResult(serverUpdater.Restart() ? (IActionResult)Ok() : UnprocessableEntity(new ErrorMessage diff --git a/src/Tgstation.Server.Host/Controllers/ApiController.cs b/src/Tgstation.Server.Host/Controllers/ApiController.cs index faf1cad40e..9d89a62b52 100644 --- a/src/Tgstation.Server.Host/Controllers/ApiController.cs +++ b/src/Tgstation.Server.Host/Controllers/ApiController.cs @@ -81,7 +81,7 @@ namespace Tgstation.Server.Host.Controllers { throw new InvalidOperationException("Failed to parse user ID!", e); } - + ApiHeaders apiHeaders; try { @@ -132,7 +132,7 @@ namespace Tgstation.Server.Host.Controllers Instance = AuthenticationContext?.InstanceUser?.Instance; this.requireInstance = requireInstance; } - + /// public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { @@ -151,7 +151,7 @@ namespace Tgstation.Server.Host.Controllers { ApiHeaders = new ApiHeaders(Request.GetTypedHeaders()); - if(!ApiHeaders.Compatible()) + if (!ApiHeaders.Compatible()) { await StatusCode((int)HttpStatusCode.UpgradeRequired, new ErrorMessage { @@ -162,7 +162,7 @@ namespace Tgstation.Server.Host.Controllers if (requireInstance) { - if(!ApiHeaders.InstanceId.HasValue) + if (!ApiHeaders.InstanceId.HasValue) { await BadRequest(new ErrorMessage { Message = "Missing Instance header!" }).ExecuteResultAsync(context).ConfigureAwait(false); return; @@ -181,7 +181,7 @@ namespace Tgstation.Server.Host.Controllers return; } - if(ModelState?.IsValid == false) + if (ModelState?.IsValid == false) { var errorMessages = ModelState.SelectMany(x => x.Value.Errors).Select(x => x.ErrorMessage).ToList(); //do some fuckery to remove RequiredAttribute errors diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 6e3ebc0477..40c1aa5ec2 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -84,7 +84,7 @@ namespace Tgstation.Server.Host.Controllers if (!model.Enabled.HasValue) return BadRequest(new ErrorMessage { Message = "enabled cannot be null!" }); - if(!model.ValidateProviderChannelTypes()) + if (!model.ValidateProviderChannelTypes()) return BadRequest(new ErrorMessage { Message = "One or more of channels aren't formatted correctly for the given provider!" }); //try to update das db first @@ -93,7 +93,7 @@ namespace Tgstation.Server.Host.Controllers Name = model.Name, ConnectionString = model.ConnectionString, Enabled = model.Enabled, - Channels = model.Channels?.Select(x => ConvertApiChatChannel(x)).ToList() ?? new List(), //important that this isn't null + Channels = model.Channels?.Select(x => ConvertApiChatChannel(x)).ToList() ?? new List(), //important that this isn't null InstanceId = Instance.Id, Provider = model.Provider, }; @@ -159,7 +159,7 @@ namespace Tgstation.Server.Host.Controllers [TgsAuthorize(ChatBotRights.Read)] public override async Task GetId(long id, CancellationToken cancellationToken) { - var query = DatabaseContext.ChatBots.Where(x => x.Id == id).Include(x => x.Channels); + var query = DatabaseContext.ChatBots.Where(x => x.Id == id).Include(x => x.Channels); var results = await query.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); if (results == default) diff --git a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs index 8823ee4de5..c362107fb5 100644 --- a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs +++ b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs @@ -60,7 +60,7 @@ namespace Tgstation.Server.Host.Controllers return model.LastReadHash == null ? (IActionResult)StatusCode((int)HttpStatusCode.Created, newFile) : Json(newFile); } - catch(NotImplementedException) + catch (NotImplementedException) { return StatusCode((int)HttpStatusCode.NotImplemented); } diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index c61672848f..7f7a8281c6 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -66,7 +66,7 @@ namespace Tgstation.Server.Host.Controllers Instance = Instance, StartedBy = AuthenticationContext.User }; - await jobManager.RegisterOperation(job, + await jobManager.RegisterOperation(job, async (paramJob, serviceProvider, progressHandler, innerCt) => { var result = await instance.Watchdog.Launch(innerCt).ConfigureAwait(false); @@ -88,7 +88,7 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation /// A resulting in the of the operation async Task ReadImpl(DreamDaemonSettings settings, CancellationToken cancellationToken) - { + { var instance = instanceManager.GetInstance(Instance); var dd = instance.Watchdog; @@ -98,7 +98,7 @@ namespace Tgstation.Server.Host.Controllers if (settings == null) settings = await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).Select(x => x.DreamDaemonSettings).FirstAsync(cancellationToken).ConfigureAwait(false); var result = new DreamDaemon(); - if(metadata) + if (metadata) { var alphaActive = dd.AlphaIsActive; var llp = dd.LastLaunchParameters; @@ -179,7 +179,7 @@ namespace Tgstation.Server.Host.Controllers if (current.SecurityLevel == DreamDaemonSecurity.Ultrasafe) return BadRequest(new ErrorMessage { Message = "This version of TGS does not support the ultrasafe DreamDaemon configuration!" }); - + var wd = instanceManager.GetInstance(Instance).Watchdog; //run these in parallel because they are equally as important diff --git a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs index bcabfd014e..c77d3a458d 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs @@ -19,7 +19,7 @@ namespace Tgstation.Server.Host.Controllers /// Controller for managing the compiler /// [Route(Routes.DreamMaker)] - public sealed class DreamMakerController : ModelController + public sealed class DreamMakerController : ModelController { /// /// The for the @@ -141,7 +141,8 @@ namespace Tgstation.Server.Host.Controllers var instanceManager = serviceProvider.GetRequiredService(); var databaseContext = serviceProvider.GetRequiredService(); - var ddSettingsTask = databaseContext.DreamDaemonSettings.Where(x => x.InstanceId == instanceModel.Id).Select(x => new DreamDaemonSettings{ + var ddSettingsTask = databaseContext.DreamDaemonSettings.Where(x => x.InstanceId == instanceModel.Id).Select(x => new DreamDaemonSettings + { StartupTimeout = x.StartupTimeout, SecurityLevel = x.SecurityLevel }).FirstAsync(cancellationToken); diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index ca67ed2d09..0597bdefb9 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -66,7 +66,8 @@ namespace Tgstation.Server.Host.Controllers /// [TgsAuthorize] [HttpGet] - public JsonResult Home() => Json(new Api.Models.ServerInformation { + public JsonResult Home() => Json(new Api.Models.ServerInformation + { Version = application.Version, ApiVersion = ApiHeaders.Version }); diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index d9dbae9001..af4e9807ec 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -106,7 +106,7 @@ namespace Tgstation.Server.Host.Controllers if (String.IsNullOrWhiteSpace(model.Name)) return BadRequest(new ErrorMessage { Message = "name must not be empty!" }); - if(model.Path == null) + if (model.Path == null) return BadRequest(new ErrorMessage { Message = "path must not be empty!" }); NormalizeModelPath(model, out var rawPath); @@ -175,13 +175,13 @@ namespace Tgstation.Server.Host.Controllers throw; } } - catch(IOException e) + catch (IOException e) { return Conflict(new ErrorMessage { Message = e.Message }); } catch (DbUpdateException e) { - return Conflict(new ErrorMessage{ Message = e.Message }); + return Conflict(new ErrorMessage { Message = e.Message }); } Logger.LogInformation("{0} {1} instance {2}: {3} ({4})", AuthenticationContext.User.Name, attached ? "attached" : "created", newInstance.Name, newInstance.Id, newInstance.Path); @@ -327,7 +327,8 @@ namespace Tgstation.Server.Host.Controllers StartedBy = AuthenticationContext.User }; - await jobManager.RegisterOperation(job, async (paramJob, serviceProvider, progressHandler, ct) => { + await jobManager.RegisterOperation(job, async (paramJob, serviceProvider, progressHandler, ct) => + { try { await instanceManager.MoveInstance(Instance, rawPath, ct).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 91b1a36a7c..3cdf397055 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -84,7 +84,7 @@ namespace Tgstation.Server.Host.Controllers ActiveTestMerges = new List() //non null vals for api returns }; - lock (databaseContext) //cleaner this way + lock (databaseContext) //cleaner this way databaseContext.RevisionInformations.Add(revisionInfo); } revisionInfo.OriginCommitSha = revisionInfo.OriginCommitSha ?? lastOriginCommitSha ?? repository.Head; @@ -249,10 +249,10 @@ namespace Tgstation.Server.Host.Controllers if (model.Origin != null) return BadRequest(new ErrorMessage { Message = "origin cannot be modified without deleting the repository!" }); - if(model.NewTestMerges?.Any(x => !x.Number.HasValue) == true) + if (model.NewTestMerges?.Any(x => !x.Number.HasValue) == true) return BadRequest(new ErrorMessage { Message = "All new test merges must provide a number!" }); - if(model.NewTestMerges?.Any(x => model.NewTestMerges.Any(y => x != y && x.Number == y.Number)) == true) + if (model.NewTestMerges?.Any(x => model.NewTestMerges.Any(y => x != y && x.Number == y.Number)) == true) return BadRequest(new ErrorMessage { Message = "Cannot test merge the same PR twice in one job!" }); var newTestMerges = model.NewTestMerges != null && model.NewTestMerges.Count > 0; @@ -374,7 +374,7 @@ namespace Tgstation.Server.Host.Controllers } } } - + //checkout/hard reset if (modelHasShaOrReference) { @@ -511,7 +511,7 @@ namespace Tgstation.Server.Host.Controllers lastRevisionInfo = revInfoWereLookingFor; } - if(needToApplyRemainingPrs) + if (needToApplyRemainingPrs) { var contextUser = new Models.User { @@ -576,7 +576,7 @@ namespace Tgstation.Server.Host.Controllers } } } - + if (startSha != repo.Head) { await repo.Sychronize(currentModel.AccessUser, currentModel.AccessToken, false, ct).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Controllers/UserController.cs b/src/Tgstation.Server.Host/Controllers/UserController.cs index 96ceaf0c2f..7a389b3b1d 100644 --- a/src/Tgstation.Server.Host/Controllers/UserController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserController.cs @@ -133,7 +133,7 @@ namespace Tgstation.Server.Host.Controllers var originalUser = passwordEditOnly ? AuthenticationContext.User : await DatabaseContext.Users.Where(x => x.Id == model.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); if (originalUser == default) return StatusCode((int)HttpStatusCode.Gone); - + if (passwordEditOnly && (model.Id != originalUser.Id || model.InstanceManagerRights.HasValue || model.AdministrationRights.HasValue || model.Enabled.HasValue || model.SystemIdentifier != null || model.Name != null)) return Forbid(); @@ -143,7 +143,7 @@ namespace Tgstation.Server.Host.Controllers return BadRequest(new ErrorMessage { Message = "Cannot convert a system user to a password user!" }); cryptographySuite.SetUserPassword(originalUser, model.Password); } - else if(model.SystemIdentifier != null && model.SystemIdentifier != originalUser.SystemIdentifier) + else if (model.SystemIdentifier != null && model.SystemIdentifier != originalUser.SystemIdentifier) return BadRequest(new ErrorMessage { Message = "Cannot change a user's system identifier!" }); if (model.Name != null && model.Name.ToUpperInvariant() != originalUser.CanonicalName) @@ -172,9 +172,15 @@ namespace Tgstation.Server.Host.Controllers } /// - [TgsAuthorize(AdministrationRights.EditUsers)] + [TgsAuthorize] public override async Task GetId(long id, CancellationToken cancellationToken) { + if (id == AuthenticationContext.User.Id) + return await Read(cancellationToken).ConfigureAwait(false); + + if (!((AdministrationRights)AuthenticationContext.GetRight(RightsType.Administration)).HasFlag(AdministrationRights.EditUsers)) + return Forbid(); + var user = await DatabaseContext.Users.Where(x => x.Id == id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); if (user == default) return NotFound(); diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index ec3564aa4d..743ed7b490 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -94,7 +94,7 @@ namespace Tgstation.Server.Host.Core if (generalConfiguration?.DisableFileLogging != true) { - var logPath = !String.IsNullOrEmpty(generalConfiguration?.LogFileDirectory) ? generalConfiguration.LogFileDirectory : ioManager.ConcatPath(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), VersionPrefix, "Logs"); + var logPath = !String.IsNullOrEmpty(generalConfiguration?.LogFileDirectory) ? generalConfiguration.LogFileDirectory : ioManager.ConcatPath(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), VersionPrefix, "Logs"); services.AddLogging(builder => builder.AddFile(ioManager.ConcatPath(logPath, "tgs-{Date}.log"))); } @@ -166,7 +166,7 @@ namespace Tgstation.Server.Host.Core default: throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Invalid {0}!", nameof(DatabaseType))); } - + services.AddScoped(); services.AddSingleton(); @@ -207,7 +207,7 @@ namespace Tgstation.Server.Host.Core services.AddSingleton(); services.AddSingleton(x => x.GetRequiredService()); services.AddSingleton(x => x.GetRequiredService()); - + services.AddSingleton(); services.AddSingleton(ioManager); @@ -231,8 +231,8 @@ namespace Tgstation.Server.Host.Core throw new ArgumentNullException(nameof(logger)); logger.LogInformation(VersionString); - - applicationBuilder.UseDeveloperExceptionPage(); //it is not worth it to limit this, you should only ever get it if you're an authorized user + + applicationBuilder.UseDeveloperExceptionPage(); //it is not worth it to limit this, you should only ever get it if you're an authorized user applicationBuilder.UseAsyncInitialization(async cancellationToken => { diff --git a/src/Tgstation.Server.Host/Core/IJobManager.cs b/src/Tgstation.Server.Host/Core/IJobManager.cs index beaa6010eb..51d9a2b999 100644 --- a/src/Tgstation.Server.Host/Core/IJobManager.cs +++ b/src/Tgstation.Server.Host/Core/IJobManager.cs @@ -10,7 +10,7 @@ namespace Tgstation.Server.Host.Core /// /// Manages the runtime of s /// - public interface IJobManager : IHostedService + public interface IJobManager : IHostedService { /// /// Get the for a job @@ -34,5 +34,5 @@ namespace Tgstation.Server.Host.Core /// The for the operation /// A representing a running operation Task CancelJob(Job job, User user, CancellationToken cancellationToken); - } + } } diff --git a/src/Tgstation.Server.Host/Core/IServerControl.cs b/src/Tgstation.Server.Host/Core/IServerControl.cs index 377b7d4a9c..dc97c4bb56 100644 --- a/src/Tgstation.Server.Host/Core/IServerControl.cs +++ b/src/Tgstation.Server.Host/Core/IServerControl.cs @@ -8,8 +8,8 @@ namespace Tgstation.Server.Host.Core /// /// Represents a service that may take an updated assembly and run it, stopping the current assembly in the process /// - public interface IServerControl - { + public interface IServerControl + { /// /// Run a new assembly and stop the current one. This will likely trigger all active s /// @@ -30,5 +30,5 @@ namespace Tgstation.Server.Host.Core /// /// if live restarts are supported, otherwise bool Restart(); - } + } } diff --git a/src/Tgstation.Server.Host/Core/JobManager.cs b/src/Tgstation.Server.Host/Core/JobManager.cs index 27980f3805..bb0e37939a 100644 --- a/src/Tgstation.Server.Host/Core/JobManager.cs +++ b/src/Tgstation.Server.Host/Core/JobManager.cs @@ -136,7 +136,7 @@ namespace Tgstation.Server.Host.Core databaseContext.Jobs.Add(job); await databaseContext.Save(cancellationToken).ConfigureAwait(false); logger.LogDebug("Starting job {0}: {1}...", job.Id, job.Description); - var jobHandler = JobHandler.Create(x => RunJob(job, (jobParam, serviceProvider, ct) => + var jobHandler = JobHandler.Create(x => RunJob(job, (jobParam, serviceProvider, ct) => operation(jobParam, serviceProvider, y => { lock (this) @@ -192,7 +192,7 @@ namespace Tgstation.Server.Host.Core throw new ArgumentNullException(nameof(job)); if (user == null) throw new ArgumentNullException(nameof(user)); - CheckGetJob(job).Cancel(); //this will ensure the db update is only done once + CheckGetJob(job).Cancel(); //this will ensure the db update is only done once using (var scope = serviceProvider.CreateScope()) { var databaseContext = scope.ServiceProvider.GetRequiredService(); diff --git a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs index 95a512d017..58ddb2c8e2 100644 --- a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs +++ b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs @@ -84,7 +84,7 @@ namespace Tgstation.Server.Host.IO async Task CopyThisDirectory() { if (!atLeastOneSubDir) - await CreateDirectory(dest, cancellationToken).ConfigureAwait(false); //save on createdir calls + await CreateDirectory(dest, cancellationToken).ConfigureAwait(false); //save on createdir calls var tasks = new List(); @@ -108,7 +108,7 @@ namespace Tgstation.Server.Host.IO throw new ArgumentNullException(nameof(src)); if (dest == null) throw new ArgumentNullException(nameof(src)); - + src = ResolvePath(src); dest = ResolvePath(dest); foreach (var directoryCopy in CopyDirectoryImpl(src, dest, ignore, cancellationToken)) @@ -292,11 +292,11 @@ namespace Tgstation.Server.Host.IO wc.DownloadDataAsync(url); using (cancellationToken.Register(() => { - wc.CancelAsync(); //cancelasync alone doesnt do it either! who wrote this!! + wc.CancelAsync(); //cancelasync alone doesnt do it either! who wrote this!! tcs.SetCanceled(); })) return await tcs.Task.ConfigureAwait(false); - } //ITS STILL FUCKING DOWNLOADING!!! + } //ITS STILL FUCKING DOWNLOADING!!! } /// diff --git a/src/Tgstation.Server.Host/IO/ResolvingIOManager.cs b/src/Tgstation.Server.Host/IO/ResolvingIOManager.cs index c10ac40b6c..b00ee71b98 100644 --- a/src/Tgstation.Server.Host/IO/ResolvingIOManager.cs +++ b/src/Tgstation.Server.Host/IO/ResolvingIOManager.cs @@ -20,7 +20,7 @@ namespace Tgstation.Server.Host.IO /// The value of public ResolvingIOManager(IIOManager parent, string _subdirectory) { - if(parent == null) + if (parent == null) throw new ArgumentNullException(nameof(parent)); if (_subdirectory == null) throw new ArgumentNullException(nameof(_subdirectory)); diff --git a/src/Tgstation.Server.Host/IServerFactory.cs b/src/Tgstation.Server.Host/IServerFactory.cs index f907c3be5b..3d69dfae9f 100644 --- a/src/Tgstation.Server.Host/IServerFactory.cs +++ b/src/Tgstation.Server.Host/IServerFactory.cs @@ -5,12 +5,12 @@ /// public interface IServerFactory { - /// - /// Create a - /// - /// The arguments for the + /// + /// Create a + /// + /// The arguments for the /// The directory in which to install server updates - /// A new - IServer CreateServer(string[] args, string updatePath); + /// A new + IServer CreateServer(string[] args, string updatePath); } } diff --git a/src/Tgstation.Server.Host/Models/ChatBot.cs b/src/Tgstation.Server.Host/Models/ChatBot.cs index d07a61b80e..7d7d2c24d6 100644 --- a/src/Tgstation.Server.Host/Models/ChatBot.cs +++ b/src/Tgstation.Server.Host/Models/ChatBot.cs @@ -6,7 +6,7 @@ namespace Tgstation.Server.Host.Models { /// public sealed class ChatBot : Api.Models.Internal.ChatBot - { + { /// /// The /// diff --git a/src/Tgstation.Server.Host/Models/DreamDaemonSettings.cs b/src/Tgstation.Server.Host/Models/DreamDaemonSettings.cs index e83fa2795e..126e640b94 100644 --- a/src/Tgstation.Server.Host/Models/DreamDaemonSettings.cs +++ b/src/Tgstation.Server.Host/Models/DreamDaemonSettings.cs @@ -3,8 +3,8 @@ namespace Tgstation.Server.Host.Models { /// - public sealed class DreamDaemonSettings : Api.Models.Internal.DreamDaemonSettings - { + public sealed class DreamDaemonSettings : Api.Models.Internal.DreamDaemonSettings + { /// /// The row Id /// @@ -19,7 +19,7 @@ namespace Tgstation.Server.Host.Models /// The access token used for communication with DD /// public string AccessToken { get; set; } - + /// /// The /// diff --git a/src/Tgstation.Server.Host/Models/DreamMakerSettings.cs b/src/Tgstation.Server.Host/Models/DreamMakerSettings.cs index f2dacbfc64..81f8312926 100644 --- a/src/Tgstation.Server.Host/Models/DreamMakerSettings.cs +++ b/src/Tgstation.Server.Host/Models/DreamMakerSettings.cs @@ -9,7 +9,7 @@ namespace Tgstation.Server.Host.Models /// The row Id /// public long Id { get; set; } - + /// /// The /// diff --git a/src/Tgstation.Server.Host/Models/IDatabaseSeeder.cs b/src/Tgstation.Server.Host/Models/IDatabaseSeeder.cs index 354b3eee7b..291f6be3fa 100644 --- a/src/Tgstation.Server.Host/Models/IDatabaseSeeder.cs +++ b/src/Tgstation.Server.Host/Models/IDatabaseSeeder.cs @@ -6,7 +6,7 @@ namespace Tgstation.Server.Host.Models /// /// For initially seeding a database /// - interface IDatabaseSeeder + interface IDatabaseSeeder { /// /// Initially seed a given diff --git a/src/Tgstation.Server.Host/Models/Instance.cs b/src/Tgstation.Server.Host/Models/Instance.cs index 89662f952b..d7a1c285c3 100644 --- a/src/Tgstation.Server.Host/Models/Instance.cs +++ b/src/Tgstation.Server.Host/Models/Instance.cs @@ -12,7 +12,7 @@ namespace Tgstation.Server.Host.Models /// The for the /// public DreamMakerSettings DreamMakerSettings { get; set; } - + /// /// The for the /// @@ -42,12 +42,12 @@ namespace Tgstation.Server.Host.Models /// The s in the /// public List RevisionInformations { get; set; } - + /// /// The in the /// public List Jobs { get; set; } - + /// /// Convert the to it's API form /// diff --git a/src/Tgstation.Server.Host/Models/ReattachInformation.cs b/src/Tgstation.Server.Host/Models/ReattachInformation.cs index 90587941e7..acabe246ce 100644 --- a/src/Tgstation.Server.Host/Models/ReattachInformation.cs +++ b/src/Tgstation.Server.Host/Models/ReattachInformation.cs @@ -3,8 +3,8 @@ /// /// Database representation of /// - public sealed class ReattachInformation : ReattachInformationBase - { + public sealed class ReattachInformation : ReattachInformationBase + { /// /// The row Id /// diff --git a/src/Tgstation.Server.Host/Models/RevisionInformation.cs b/src/Tgstation.Server.Host/Models/RevisionInformation.cs index 3f2fda9492..896615150f 100644 --- a/src/Tgstation.Server.Host/Models/RevisionInformation.cs +++ b/src/Tgstation.Server.Host/Models/RevisionInformation.cs @@ -45,7 +45,7 @@ namespace Tgstation.Server.Host.Models ActiveTestMerges = ActiveTestMerges.Select(x => x.TestMerge.ToApi()).ToList(), CompileJobs = CompileJobs.Select(x => new Api.Models.CompileJob { - Id = x.Id //anti recursion measure + Id = x.Id //anti recursion measure }).ToList() }; } diff --git a/src/Tgstation.Server.Host/Models/TestMerge.cs b/src/Tgstation.Server.Host/Models/TestMerge.cs index 94a13aa767..bbab03bea0 100644 --- a/src/Tgstation.Server.Host/Models/TestMerge.cs +++ b/src/Tgstation.Server.Host/Models/TestMerge.cs @@ -11,7 +11,7 @@ namespace Tgstation.Server.Host.Models /// [Required] public User MergedBy { get; set; } - + /// /// The initial the was merged with /// @@ -40,7 +40,7 @@ namespace Tgstation.Server.Host.Models Comment = Comment, Id = Id, MergedBy = MergedBy.ToApi(false), - Number =Number, + Number = Number, PullRequestRevision = PullRequestRevision, Url = Url }; diff --git a/src/Tgstation.Server.Host/Program.cs b/src/Tgstation.Server.Host/Program.cs index 65f5199f40..03dbd4d2cb 100644 --- a/src/Tgstation.Server.Host/Program.cs +++ b/src/Tgstation.Server.Host/Program.cs @@ -10,7 +10,7 @@ namespace Tgstation.Server.Host /// /// Entrypoint for the /// - static class Program + static class Program { /// /// The to use diff --git a/src/Tgstation.Server.Host/Security/AuthenticationContext.cs b/src/Tgstation.Server.Host/Security/AuthenticationContext.cs index d98d36c10f..1a2c489812 100644 --- a/src/Tgstation.Server.Host/Security/AuthenticationContext.cs +++ b/src/Tgstation.Server.Host/Security/AuthenticationContext.cs @@ -78,7 +78,7 @@ namespace Tgstation.Server.Host.Security var prop = typeToCheck.GetProperties().Where(x => x.PropertyType == nullableRightsType).First(); var right = prop.GetMethod.Invoke(isInstance ? (object)InstanceUser : User, Array.Empty()); - + if (right == null) throw new InvalidOperationException("A user right was null!"); return (ulong)right; diff --git a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs index 258bf0dd3d..6e64008820 100644 --- a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs +++ b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs @@ -37,7 +37,7 @@ namespace Tgstation.Server.Host.Security public AuthenticationContextFactory(ISystemIdentityFactory systemIdentityFactory, IDatabaseContext databaseContext, IIdentityCache identityCache) { this.systemIdentityFactory = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory)); - this.databaseContext = databaseContext?? throw new ArgumentNullException(nameof(databaseContext)); + this.databaseContext = databaseContext ?? throw new ArgumentNullException(nameof(databaseContext)); this.identityCache = identityCache ?? throw new ArgumentNullException(nameof(identityCache)); } diff --git a/src/Tgstation.Server.Host/Security/CryptographySuite.cs b/src/Tgstation.Server.Host/Security/CryptographySuite.cs index f2b99a7ea0..557170cf75 100644 --- a/src/Tgstation.Server.Host/Security/CryptographySuite.cs +++ b/src/Tgstation.Server.Host/Security/CryptographySuite.cs @@ -47,7 +47,7 @@ namespace Tgstation.Server.Host.Security /// public bool CheckUserPassword(User user, string password) { - switch(passwordHasher.VerifyHashedPassword(user, user.PasswordHash, password)) + switch (passwordHasher.VerifyHashedPassword(user, user.PasswordHash, password)) { case PasswordVerificationResult.Failed: return false; diff --git a/src/Tgstation.Server.Host/Security/IIdentityCache.cs b/src/Tgstation.Server.Host/Security/IIdentityCache.cs index 7d6b2def11..b5a9fed42c 100644 --- a/src/Tgstation.Server.Host/Security/IIdentityCache.cs +++ b/src/Tgstation.Server.Host/Security/IIdentityCache.cs @@ -6,7 +6,7 @@ namespace Tgstation.Server.Host.Security /// /// For caching s /// - public interface IIdentityCache + public interface IIdentityCache { /// /// Keep a 's alive until an time diff --git a/src/Tgstation.Server.Host/Security/ISystemIdentity.cs b/src/Tgstation.Server.Host/Security/ISystemIdentity.cs index fecf36a60a..ffa55706e5 100644 --- a/src/Tgstation.Server.Host/Security/ISystemIdentity.cs +++ b/src/Tgstation.Server.Host/Security/ISystemIdentity.cs @@ -24,7 +24,7 @@ namespace Tgstation.Server.Host.Security /// Clone the creating another copy that must have called on it /// /// A new mirroring the current one - ISystemIdentity Clone(); + ISystemIdentity Clone(); /// /// Runs a given in the context of the @@ -33,5 +33,5 @@ namespace Tgstation.Server.Host.Security /// The for the operation /// A representing the running operation Task RunImpersonated(Action action, CancellationToken cancellationToken); - } + } } \ No newline at end of file diff --git a/src/Tgstation.Server.Host/Security/IdentityCache.cs b/src/Tgstation.Server.Host/Security/IdentityCache.cs index 1d1f19a681..81850ab4f2 100644 --- a/src/Tgstation.Server.Host/Security/IdentityCache.cs +++ b/src/Tgstation.Server.Host/Security/IdentityCache.cs @@ -31,7 +31,7 @@ namespace Tgstation.Server.Host.Security lock (cachedIdentities) { if (cachedIdentities.TryGetValue(user.Id, out var identCache)) - identCache.Dispose(); //also clears it out + identCache.Dispose(); //also clears it out identCache = new IdentityCacheObject(systemIdentity.Clone(), () => { lock (cachedIdentities) diff --git a/src/Tgstation.Server.Host/Security/IdentityCacheObject.cs b/src/Tgstation.Server.Host/Security/IdentityCacheObject.cs index 1e9ae6c7ca..02ea54ed04 100644 --- a/src/Tgstation.Server.Host/Security/IdentityCacheObject.cs +++ b/src/Tgstation.Server.Host/Security/IdentityCacheObject.cs @@ -41,7 +41,7 @@ namespace Tgstation.Server.Host.Security cancellationTokenSource = new CancellationTokenSource(); - async Task DisposeOnExipiry(CancellationToken cancellationToken) + async Task DisposeOnExipiry(CancellationToken cancellationToken) { using (SystemIdentity) try diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs index 17db165520..d05fe40e91 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs @@ -61,7 +61,7 @@ namespace Tgstation.Server.Host.Security if (!res) return null; - using (var handle = new SafeAccessTokenHandle(token)) //checked internally, windows identity always duplicates the handle when constructed with a userToken + using (var handle = new SafeAccessTokenHandle(token)) //checked internally, windows identity always duplicates the handle when constructed with a userToken return (ISystemIdentity)new WindowsSystemIdentity(new WindowsIdentity(handle.DangerousGetHandle())); //https://github.com/dotnet/corefx/blob/6ed61acebe3214fcf79b4274f2bb9b55c0604a4d/src/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs#L271 }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); } diff --git a/src/Tgstation.Server.Host/Server.cs b/src/Tgstation.Server.Host/Server.cs index f24dc3b4e9..7bc3192638 100644 --- a/src/Tgstation.Server.Host/Server.cs +++ b/src/Tgstation.Server.Host/Server.cs @@ -35,7 +35,7 @@ namespace Tgstation.Server.Host /// If a server update has been applied /// bool updated; - + /// /// The for the /// @@ -60,7 +60,7 @@ namespace Tgstation.Server.Host public void Dispose() => semaphore.Dispose(); /// - [ExcludeFromCodeCoverage] + [ExcludeFromCodeCoverage] public async Task RunAsync(CancellationToken cancellationToken) { using (cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) @@ -121,10 +121,11 @@ namespace Tgstation.Server.Host throw new ArgumentNullException(nameof(action)); if (cancellationTokenSource == null) throw new InvalidOperationException("Tried to register an update action on a non-running Server!"); - cancellationTokenSource.Token.Register(() => { + cancellationTokenSource.Token.Register(() => + { if (RestartRequested) action(); - }); + }); } /// diff --git a/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs b/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs index f4127014b5..87c48c6ae8 100644 --- a/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs +++ b/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs @@ -40,7 +40,7 @@ namespace Tgstation.Server.Host.Service.Tests var mockLoggerFactory = new LoggerFactory(); mockWatchdogFactory.Setup(x => x.CreateWatchdog(mockLoggerFactory)).Returns(mockWatchdog.Object).Verifiable(); - using(var service = new ServerService(mockWatchdogFactory.Object, mockLoggerFactory)) + using (var service = new ServerService(mockWatchdogFactory.Object, mockLoggerFactory)) { onStart.Invoke(service, new object[] { args }); diff --git a/tests/Tgstation.Server.Tests/IntegrationTest.cs b/tests/Tgstation.Server.Tests/IntegrationTest.cs index e630207f2b..b9d7277265 100644 --- a/tests/Tgstation.Server.Tests/IntegrationTest.cs +++ b/tests/Tgstation.Server.Tests/IntegrationTest.cs @@ -15,7 +15,7 @@ namespace Tgstation.Server.Tests public sealed class IntegrationTest { readonly IServerClientFactory clientFactory = new ServerClientFactory(new ProductHeaderValue(Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Version.ToString())); - + [TestMethod] public async Task FullMonty() {