tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ServerPortProivder.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3
4using Microsoft.Extensions.Configuration;
5using Microsoft.Extensions.Logging;
6using Microsoft.Extensions.Options;
7
9
11{
14 {
17
22
30 IOptions<GeneralConfiguration> generalConfigurationOptions,
31 IConfiguration configuration,
32 ILogger<ServerPortProivder> logger)
33 {
34 generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
35 ArgumentNullException.ThrowIfNull(configuration);
36
37 var usingDefaultPort = generalConfiguration.ApiPort == default;
38 if (!usingDefaultPort)
39 return;
40
41 var httpEndpoint = configuration
42 .GetSection("Kestrel")
43 .GetSection("EndPoints")
44 .GetSection("Http")
45 .GetSection("Url")
46 .Value
47 ?? throw new InvalidOperationException("Missing required configuration option General:ApiPort!");
48
49 logger.LogWarning("The \"Kestrel\" configuration section is deprecated! Please set your API port using the \"General:ApiPort\" configuration option!");
50
51 var splits = httpEndpoint.Split(":", StringSplitOptions.RemoveEmptyEntries);
52 var portString = splits.Last();
53 portString = portString.TrimEnd('/');
54
55 if (!UInt16.TryParse(portString, out var result))
56 throw new InvalidOperationException($"Failed to parse HTTP EndPoint port: {httpEndpoint}");
57
58 generalConfiguration.ApiPort = result;
59 }
60 }
61}
readonly GeneralConfiguration generalConfiguration
The GeneralConfiguration for the ServerPortProivder.
ushort HttpApiPort
The port the server listens on.
ServerPortProivder(IOptions< GeneralConfiguration > generalConfigurationOptions, IConfiguration configuration, ILogger< ServerPortProivder > logger)
Initializes a new instance of the ServerPortProivder class.
Provides access to the server's HttpApiPort.