mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-28 07:27:18 +01:00
Modify Interface to accept instance switching. Add ITGInstance
This commit is contained in:
@@ -46,9 +46,9 @@ namespace TGServiceInterface
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The name of the current instance in use
|
||||
/// The name of the current instance in use. Defaults to <see langword="null"/>
|
||||
/// </summary>
|
||||
public static string InstanceName;
|
||||
public string InstanceName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// If this is set, we will try and connect to an HTTPS server running at this address
|
||||
@@ -112,6 +112,48 @@ namespace TGServiceInterface
|
||||
HTTPSPassword = password;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Targets <paramref name="instanceName"/> as the instance to use with <see cref="GetComponent{T}"/>. Closes all connections to any previous instance
|
||||
/// </summary>
|
||||
/// <param name="instanceName">The name of the instance to connect to</param>
|
||||
/// <returns>The apporopriate <see cref="InstanceConnectivity"/> value</returns>
|
||||
public InstanceConnectivity ConnectToInstance(string instanceName)
|
||||
{
|
||||
return ConnectToInstanceImpl(instanceName, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Targets <paramref name="instanceName"/> as the instance to use with <see cref="GetComponent{T}"/>. Closes all connections to any previous instance
|
||||
/// </summary>
|
||||
/// <param name="instanceName">The name of the instance to connect to</param>
|
||||
/// <param name="skipAuthChecks">If set to <see langword="true"/>, skips the connectivity and authentication checks and returns <see cref="InstanceConnectivity.Connected"/></param>
|
||||
/// <returns>The apporopriate <see cref="InstanceConnectivity"/> value</returns>
|
||||
internal InstanceConnectivity ConnectToInstanceImpl(string instanceName, bool skipAuthChecks) {
|
||||
if (VerifyConnection() != null)
|
||||
return InstanceConnectivity.None;
|
||||
var prevInstance = InstanceName;
|
||||
CloseAllChannels();
|
||||
InstanceName = instanceName;
|
||||
if (skipAuthChecks)
|
||||
return InstanceConnectivity.Connected;
|
||||
try
|
||||
{
|
||||
GetComponent<ITGConnectivity>().VerifyConnection();
|
||||
}
|
||||
catch
|
||||
{
|
||||
InstanceName = prevInstance;
|
||||
return InstanceConnectivity.None;
|
||||
}
|
||||
try
|
||||
{
|
||||
GetComponent<ITGInstance>().ServerDirectory();
|
||||
return InstanceConnectivity.Authenticated;
|
||||
} catch {
|
||||
return InstanceConnectivity.Connected;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the function called when a remote login fails due to the server having an invalid SSL cert
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user