// Decompiled with JetBrains decompiler
// Type: Meebey.SmartIrc4net.DccConnection
// Assembly: svchost, Version=3.2.4.0, Culture=neutral, PublicKeyToken=null
// MVID: 8F51F928-E1DB-4815-857F-7D580385B815
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Backdoor.MSIL.IrcBot.lp-4dd7df88cffbf85a5894bc1b38660fa613c24b0e6c004ac00b2b119c03a35d3f.exe

using System;
using System.Net;
using System.Net.Sockets;

namespace Meebey.SmartIrc4net
{
  public class DccConnection
  {
    protected IrcFeatures Irc;
    protected TcpListener DccServer;
    protected TcpClient Connection;
    protected IPEndPoint LocalEndPoint;
    protected IPEndPoint RemoteEndPoint;
    protected IPAddress ExternalIPAdress;
    protected DateTime Timeout;
    protected string User;
    protected bool isConnected;
    protected bool isValid = true;
    protected bool reject;
    protected long session;

    public bool Connected => this.isConnected;

    public bool Valid
    {
      get
      {
        if (!this.isValid)
          return false;
        return this.isConnected || DateTime.Now < this.Timeout;
      }
    }

    public string Nick => this.User;

    public event DccConnectionHandler OnDccChatRequestEvent;

    protected virtual void DccChatRequestEvent(DccEventArgs e)
    {
      if (this.OnDccChatRequestEvent != null)
        this.OnDccChatRequestEvent((object) this, e);
      this.Irc.DccChatRequestEvent(e);
    }

    public event DccSendRequestHandler OnDccSendRequestEvent;

    protected virtual void DccSendRequestEvent(DccSendRequestEventArgs e)
    {
      if (this.OnDccSendRequestEvent != null)
        this.OnDccSendRequestEvent((object) this, e);
      this.Irc.DccSendRequestEvent(e);
    }

    public event DccConnectionHandler OnDccChatStartEvent;

    protected virtual void DccChatStartEvent(DccEventArgs e)
    {
      if (this.OnDccChatStartEvent != null)
        this.OnDccChatStartEvent((object) this, e);
      this.Irc.DccChatStartEvent(e);
    }

    public event DccConnectionHandler OnDccSendStartEvent;

    protected virtual void DccSendStartEvent(DccEventArgs e)
    {
      if (this.OnDccSendStartEvent != null)
        this.OnDccSendStartEvent((object) this, e);
      this.Irc.DccSendStartEvent(e);
    }

    public event DccChatLineHandler OnDccChatReceiveLineEvent;

    protected virtual void DccChatReceiveLineEvent(DccChatEventArgs e)
    {
      if (this.OnDccChatReceiveLineEvent != null)
        this.OnDccChatReceiveLineEvent((object) this, e);
      this.Irc.DccChatReceiveLineEvent(e);
    }

    public event DccSendPacketHandler OnDccSendReceiveBlockEvent;

    protected virtual void DccSendReceiveBlockEvent(DccSendEventArgs e)
    {
      if (this.OnDccSendReceiveBlockEvent != null)
        this.OnDccSendReceiveBlockEvent((object) this, e);
      this.Irc.DccSendReceiveBlockEvent(e);
    }

    public event DccChatLineHandler OnDccChatSentLineEvent;

    protected virtual void DccChatSentLineEvent(DccChatEventArgs e)
    {
      if (this.OnDccChatSentLineEvent != null)
        this.OnDccChatSentLineEvent((object) this, e);
      this.Irc.DccChatSentLineEvent(e);
    }

    public event DccSendPacketHandler OnDccSendSentBlockEvent;

    protected virtual void DccSendSentBlockEvent(DccSendEventArgs e)
    {
      if (this.OnDccSendSentBlockEvent != null)
        this.OnDccSendSentBlockEvent((object) this, e);
      this.Irc.DccSendSentBlockEvent(e);
    }

    public event DccConnectionHandler OnDccChatStopEvent;

    protected virtual void DccChatStopEvent(DccEventArgs e)
    {
      if (this.OnDccChatStopEvent != null)
        this.OnDccChatStopEvent((object) this, e);
      this.Irc.DccChatStopEvent(e);
    }

    public event DccConnectionHandler OnDccSendStopEvent;

    protected virtual void DccSendStopEvent(DccEventArgs e)
    {
      if (this.OnDccSendStopEvent != null)
        this.OnDccSendStopEvent((object) this, e);
      this.Irc.DccSendStopEvent(e);
    }

    internal DccConnection()
    {
      this.session = DccConnection.Session.Next;
      this.Timeout = DateTime.Now.AddSeconds(120.0);
    }

    internal virtual void InitWork(object stateInfo) => throw new NotSupportedException();

    internal bool isSession(long session) => session == this.session;

    public void RejectRequest()
    {
      this.Irc.SendMessage(SendType.CtcpReply, this.User, "ERRMSG DCC Rejected");
      this.reject = true;
      this.isValid = false;
    }

    public void Disconnect()
    {
      this.isConnected = false;
      this.isValid = false;
    }

    public override string ToString() => "DCC Session " + (object) this.session + " of " + this.GetType().ToString() + " is " + (this.isConnected ? (object) ("connected to " + this.RemoteEndPoint.Address.ToString()) : (object) "not connected") + "[" + this.User + "]";

    protected long HostToDccInt(IPAddress ip) => (ip.Address & (long) byte.MaxValue) << 24 | (ip.Address & 65280L) << 8 | ip.Address >> 8 & 65280L | ip.Address >> 24 & (long) byte.MaxValue;

    protected string DccIntToHost(long ip)
    {
      IPEndPoint ipEndPoint = new IPEndPoint(ip, 80);
      char[] chArray = new char[1]{ '.' };
      string[] strArray = ipEndPoint.Address.ToString().Split(chArray);
      return strArray[3] + "." + strArray[2] + "." + strArray[1] + "." + strArray[0];
    }

    protected byte[] getAck(long SentBytes) => new byte[4]
    {
      (byte) ((ulong) (SentBytes >> 24) % 256UL),
      (byte) ((ulong) (SentBytes >> 16) % 256UL),
      (byte) ((ulong) (SentBytes >> 8) % 256UL),
      (byte) ((ulong) SentBytes % 256UL)
    };

    protected string FilterMarker(string msg)
    {
      string str = "";
      foreach (char ch in msg)
      {
        if (ch != '\u0001')
          str += (string) (object) ch;
      }
      return str;
    }

    private class Session
    {
      private static long next;

      internal static long Next => ++DccConnection.Session.next;
    }
  }
}
