mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 05:56:58 +01:00
Properly clean up the channel DD side. We don't any rogue exceptions
This commit is contained in:
@@ -62,15 +62,23 @@ namespace TGServiceInterface
|
||||
/// Returns the requested server component interface. This does not guarantee a successful connection
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the component to retrieve</typeparam>
|
||||
/// <returns></returns>
|
||||
/// <returns>The correct component</returns>
|
||||
public static T GetComponent<T>()
|
||||
{
|
||||
return GetComponentAndChannel<T>(out ChannelFactory<T> ignored);
|
||||
}
|
||||
|
||||
public static T GetComponentAndChannel<T>(out ChannelFactory<T> outChannel)
|
||||
{
|
||||
var ToT = typeof(T);
|
||||
if (!ValidInterfaces.Contains(ToT))
|
||||
throw new Exception("Invalid type!");
|
||||
var InterfaceName = typeof(T).Name;
|
||||
if (HTTPSURL == null)
|
||||
return new ChannelFactory<T>(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))).CreateChannel();
|
||||
{
|
||||
outChannel = new ChannelFactory<T>(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName)));
|
||||
return outChannel.CreateChannel();
|
||||
}
|
||||
|
||||
//okay we're going over
|
||||
var binding = new WSHttpBinding();
|
||||
@@ -78,17 +86,17 @@ namespace TGServiceInterface
|
||||
binding.Security.Mode = requireAuth ? SecurityMode.TransportWithMessageCredential : SecurityMode.Transport; //do not require auth for a connectivity check
|
||||
binding.Security.Message.ClientCredentialType = requireAuth ? MessageCredentialType.UserName : MessageCredentialType.None;
|
||||
var address = new EndpointAddress(String.Format("https://{0}:{1}/{2}/{3}", HTTPSURL, HTTPSPort, MasterInterfaceName, InterfaceName));
|
||||
var cf = new ChannelFactory<T>(binding, address);
|
||||
outChannel = new ChannelFactory<T>(binding, address);
|
||||
if (requireAuth)
|
||||
{
|
||||
cf.Credentials.UserName.UserName = HTTPSUsername;
|
||||
cf.Credentials.UserName.Password = HTTPSPassword;
|
||||
outChannel.Credentials.UserName.UserName = HTTPSUsername;
|
||||
outChannel.Credentials.UserName.Password = HTTPSPassword;
|
||||
}
|
||||
#if DEBUG
|
||||
//allow self signed certs in debug mode
|
||||
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true;
|
||||
#endif
|
||||
return cf.CreateChannel();
|
||||
return outChannel.CreateChannel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -36,7 +36,17 @@ namespace TGServiceInterface
|
||||
{
|
||||
try
|
||||
{
|
||||
Server.GetComponent<ITGServiceBridge>().InteropMessage(String.Join(" ", args));
|
||||
ChannelFactory<ITGServiceBridge> channel = null;
|
||||
try
|
||||
{
|
||||
Server.GetComponentAndChannel(out channel).InteropMessage(String.Join(" ", args));
|
||||
channel.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
if(channel != null)
|
||||
channel.Abort();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user