Example #1
0
        public Server Create(ConnectionArgs args)
        {
            var newServer = new Server(args);
            ServerList.Add(newServer);

            ServerAdded.Fire(this, new ServerEventArgs(newServer));

            return newServer;
        }
Example #2
0
        public void Execute(Server context, string server, string port)
        {
            var args = new ConnectionArgs(Settings.Default.FirstNick, server, false);
            try
            {
                args.Port = int.Parse(port);
            }
            catch (Exception)
            {
                args.Port = 6667;
            }

            context.ChangeServer(args);
            context.Connect();
        }
Example #3
0
        /// <summary>
        /// Prepare a connection to an IRC server but do not open it. This sets the text Encoding to Default.
        /// </summary>
        /// <param name="args">The set of information need to connect to an IRC server</param>
        /// <param name="enableCtcp">True if this Connection should support CTCP.</param>
        /// <param name="enableDcc">True if this Connection should support DCC.</param>
        public Connection(ConnectionArgs args, bool enableCtcp, bool enableDcc)
        {
            _propertiesRegex = new Regex("([A-Z]+)=([^\\s]+)", RegexOptions.Compiled | RegexOptions.Singleline);
            Registered = false;
            HandleNickTaken = true;
            _connectionArgs = args;
            _parsers = new ArrayList();
            Sender = new Sender(this);
            Listener = new Listener();
            RegisterDelegates();
            _timeLastSent = DateTime.Now;
            EnableCtcp = enableCtcp;
            EnableDcc = enableDcc;
            TextEncoding = Encoding.Default;

            _lastTraffic = DateTime.Now;

            _activityTimer = new System.Timers.Timer { Interval = TimeSpan.FromSeconds(30).TotalMilliseconds };
            _activityTimer.Elapsed += activityTimer_Elapsed;
            _activityTimer.Start();
        }
Example #4
0
 public void Execute(Server context, char[] switches, string server, string port)
 {
     foreach (char c in switches)
     {
         switch (c)
         {
             case 'n': //New window and connect
                 var args = new ConnectionArgs(Settings.Default.FirstNick, server, false);
                 try
                 {
                     args.Port = int.Parse(port);
                 }
                 catch (Exception)
                 {
                     args.Port = 6667;
                 }
                 var svr = ServerManager.Instance.Create(args);
                 svr.Connect();
                 return;
         }
     }
 }
Example #5
0
        /// <summary>
        /// Prepare a connection to an IRC server but do not open it. This sets the text Encoding to Default.
        /// </summary>
        /// <param name="args">The set of information need to connect to an IRC server</param>
        /// <param name="enableCtcp">True if this Connection should support CTCP.</param>
        /// <param name="enableDcc">True if this Connection should support DCC.</param>
        public Connection(ConnectionArgs args, bool enableCtcp, bool enableDcc)
        {
            _propertiesRegex = new Regex("([A-Z]+)=([^\\s]+)", RegexOptions.Compiled | RegexOptions.Singleline);
            Registered       = false;
            HandleNickTaken  = true;
            _connectionArgs  = args;
            _parsers         = new ArrayList();
            Sender           = new Sender(this);
            Listener         = new Listener();
            RegisterDelegates();
            _timeLastSent = DateTime.Now;
            EnableCtcp    = enableCtcp;
            EnableDcc     = enableDcc;
            TextEncoding  = Encoding.Default;

            _lastTraffic = DateTime.Now;

            _activityTimer = new System.Timers.Timer {
                Interval = TimeSpan.FromSeconds(30).TotalMilliseconds
            };
            _activityTimer.Elapsed += activityTimer_Elapsed;
            _activityTimer.Start();
        }
Example #6
0
 public void Setup()
 {
     var args = new ConnectionArgs("test", "irc.fake.com", false);
     var connMock = A.Fake<Connection>(x => x.WithArgumentsForConstructor(() => new Connection(args, false, false)));
     _server = new Server(connMock);
 }
Example #7
0
        public void SetupConnection(ConnectionArgs args)
        {
            if (args.Nick == null)
                throw new ArgumentNullException("ConnectionArgs.Nick");

            Connection = new Connection(args, true, false) { HandleNickTaken = false };
        }
Example #8
0
 public Server(ConnectionArgs settings)
 {
     SetupConnection(settings);
     HookEvents();
 }
Example #9
0
        public void ChangeServer(ConnectionArgs args)
        {
            if (IsConnected)
            {
                Disconnect();
            }

            if (args.Nick == null)
            {
                args.Nick = Connection.ConnectionData.Nick;
            }

            UnhookEvents();
            SetupConnection(args);
            HookEvents();

            _serverChangeTime = DateTime.Now;
        }
Example #10
0
 /// <summary>
 /// The USER command is only used at the beginning of Connection to specify
 /// the username, hostname and realname of a new user.
 /// </summary>
 /// <param name="args">The user Connection data</param>
 internal void User(ConnectionArgs args)
 {
     lock (this)
     {
         Buffer.Append("USER");
         Buffer.Append(SPACE);
         Buffer.Append(args.UserName);
         Buffer.Append(SPACE);
         Buffer.Append(args.ModeMask);
         Buffer.Append(SPACE);
         Buffer.Append('*');
         Buffer.Append(SPACE);
         Buffer.Append(':');
         Buffer.Append(args.RealName);
         Connection.SendCommand(Buffer);
     }
 }
Example #11
0
 /// <summary>
 /// User registration consists of 3 commands:
 /// 1. PASS
 /// 2. NICK
 /// 3. USER
 /// Pass will rarely fail but the proposed Nick might already be taken in
 /// which case the client will have to register by manually calling Nick
 /// and User.
 /// </summary>
 internal void RegisterConnection(ConnectionArgs args)
 {
     Pass(args.ServerPassword);
     Nick(args.Nick);
     User(args);
 }
Example #12
0
 /// <summary>
 /// Prepare a connection to an IRC server but do not open it.
 /// </summary>
 /// <param name="args">The set of information need to connect to an IRC server</param>
 /// <param name="enableCtcp">True if this Connection should support CTCP.</param>
 /// <param name="enableDcc">True if this Connection should support DCC.</param>
 /// <param name="textEncoding">The text encoding for the incoming stream.</param>
 public Connection(Encoding textEncoding, ConnectionArgs args, bool enableCtcp, bool enableDcc)
     : this(args, enableCtcp, enableDcc)
 {
     TextEncoding = textEncoding;
 }
Example #13
0
 /// <summary>
 /// Used for internal test purposes only.
 /// </summary>
 internal Connection(ConnectionArgs args)
     : this(args, true, true)
 {
 }
Example #14
0
 /// <summary>
 /// Prepare a connection to an IRC server but do not open it.
 /// </summary>
 /// <param name="args">The set of information need to connect to an IRC server</param>
 /// <param name="enableCtcp">True if this Connection should support CTCP.</param>
 /// <param name="enableDcc">True if this Connection should support DCC.</param>
 /// <param name="textEncoding">The text encoding for the incoming stream.</param>
 public Connection(Encoding textEncoding, ConnectionArgs args, bool enableCtcp, bool enableDcc)
     : this(args, enableCtcp, enableDcc)
 {
     TextEncoding = textEncoding;
 }
Example #15
0
 /// <summary>
 /// Used for internal test purposes only.
 /// </summary>
 internal Connection(ConnectionArgs args)
     : this(args, true, true)
 {
 }