Files
tgstation-server/TGServiceInterface/Interop.cs
T
2017-09-24 13:42:15 -04:00

53 lines
1.4 KiB
C#

using System;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.ServiceModel;
namespace TGServiceInterface
{
/// <summary>
/// Used by DD to access the interop API with call()()
/// </summary>
[ServiceContract]
public interface ITGInterop
{
/// <summary>
/// Called from /world/ExportService(command)
/// </summary>
/// <param name="command">The command to run</param>
/// <returns>true on success, false on failure</returns>
[OperationContract]
bool InteropMessage(string command);
}
/// <summary>
/// Holds the proc that DD calls to access <see cref="ITGServiceBridge"/>
/// </summary>
public class DDInteropCallHolder
{
/// <summary>
/// The proc that DD calls to access <see cref="ITGServiceBridge"/>
/// </summary>
/// <param name="args">The arguments passed</param>
/// <returns>0</returns>
[DllExport("DDEntryPoint", CallingConvention = CallingConvention.Cdecl)]
public static int DDEntryPoint(int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 0)]string[] args)
{
try
{
var channel = Server.CreateChannel<ITGInterop>();
try
{
channel.CreateChannel().InteropMessage(String.Join(" ", args));
}
catch { }
Server.CloseChannel(channel);
}
catch { }
return 0;
}
}
}