Modify Interface to accept instance switching. Add ITGInstance

This commit is contained in:
Cyberboss
2017-10-31 13:14:28 -04:00
parent da7814e3d9
commit 8672a9d5c6
10 changed files with 102 additions and 19 deletions
+44 -2
View File
@@ -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>