using System.Reflection;
using Lidgren.Network;
using StardewValley.Network;
namespace StardewModdingAPI.Framework.Networking
{
/// A multiplayer server used to connect to an incoming player. This is an implementation of that adds support for SMAPI's metadata context exchange.
internal class SLidgrenServer : LidgrenServer
{
/*********
** Properties
*********/
/// A method which sends a message through a specific connection.
private readonly MethodInfo SendMessageToConnectionMethod;
/*********
** Public methods
*********/
/// Construct an instance.
/// The underlying game server.
public SLidgrenServer(IGameServer gameServer)
: base(gameServer)
{
this.SendMessageToConnectionMethod = typeof(LidgrenServer).GetMethod(nameof(LidgrenServer.sendMessage), BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(NetConnection), typeof(OutgoingMessage) }, null);
}
/// Send a message to a remote server.
/// The network connection.
/// The message to send.
public void SendMessage(NetConnection connection, OutgoingMessage message)
{
this.SendMessageToConnectionMethod.Invoke(this, new object[] { connection, message });
}
}
}