private void Network_Connected(IrcNetwork network, EventArgs args)
        {
            string nick     = this.NetworkInfo.GetActualNickname();
            string realName = this.NetworkInfo.GetActualRealName();

            this.Network.Authenticate(nick, realName, IrcUserLoginModes.None, this.NetworkInfo.Password ?? string.Empty);
        }
Exemplo n.º 2
0
 public void AddServer()
 {
     IrcNetwork network = new IrcNetwork(protocol, "bar");
     IrcServerEndPoint server = network.AddServer("test", "localhost:6667");
     Assert.NotNull(server);
     Assert.AreEqual("localhost", server.Address);
     Assert.AreEqual("test", server.Name);
     Assert.AreEqual(6667, server.Port);
     Assert.AreEqual(network["test"], server);
     Assert.AreEqual(1, network.ServerCount);
     network = new IrcNetwork(protocol, "bar");
     server = network.AddServer("foo", "www.google.de:6669");
     Assert.NotNull(server);
     Assert.AreEqual("www.google.de", server.Address);
     Assert.AreEqual("foo", server.Name);
     Assert.AreEqual(network["foo"], server);
     Assert.AreEqual(6669, server.Port);
     network.AddServer("test", "localhost:6667");
     Assert.AreEqual(2, network.ServerCount);
     try
     {
         network.AddServer("foo", "localhost:6669");
         Assert.Fail("Added a second server with the same name, as an already added one");
     }
     catch (ArgumentException)
     {
     }
 }
        private async void Network_ConnectionLost(IrcNetwork network, EventArgs args)
        {
            if (this._disposed)
            {
                return;
            }
            // Go back to the network info view, more practical to display stuff
            this.SelectedConversation = this._networkInfoViewModel;

            if (this._retryCount == ConnectionAttemptsCount)
            {
                this._retryCount = 0;
            }
            else
            {
                this._retryCount++;

                await Task.Delay(ConnectionRetryInterval);

                if (!this._disposed)
                {
                    this.Connect();
                }
            }
        }
        public void Initialize()
        {
            var tup = Initializer.GetAuthenticatedNetwork(Nickname, RealName);

            this._network = tup.Item1;
            this._wrapper = tup.Item2;
        }
Exemplo n.º 5
0
 public void Constructor()
 {
     IrcNetwork network = new IrcNetwork(protocol, "test");
     Assert.AreEqual("test", network.Name);
     network = new IrcNetwork(protocol, "foo");
     Assert.AreEqual("foo", network.Name);
 }
        public void Initialize()
        {
            var tup = Initializer.GetAuthenticatedNetwork("nick", "real");

            this._network = tup.Item1;
            this._wrapper = tup.Item2;
        }
Exemplo n.º 7
0
 public void Irc_RealLife_BeginConnection()
 {
     this._wrapper = new TestTcpWrapper();
     this._network = new IrcNetwork(this._wrapper);
     this._network.ConnectAsync("Aethec", "Aethec", IrcUserLoginModes.None).Wait();
     this._wrapper.ReceiveLine(":main.smoothirc.net NOTICE Auth :*** Looking up your hostname...");
     this._wrapper.ReceiveLine(":main.smoothirc.net NOTICE Auth :*** Found your hostname (adsl-84-226-156-139.adslplus.ch) -- cached");
     this._wrapper.ReceiveLine(":main.smoothirc.net NOTICE Auth :Welcome to SmoothIRC!");
     this._wrapper.ReceiveLine(":main.smoothirc.net 001 Aethec :Welcome to the SmoothIRC IRC Network [email protected]");
     this._wrapper.ReceiveLine(":main.smoothirc.net 002 Aethec :Your host is main.smoothirc.net, running version InspIRCd-2.0");
     this._wrapper.ReceiveLine(":main.smoothirc.net 003 Aethec :This server was created 15:07:46 Dec 15 2012");
     this._wrapper.ReceiveLine(":main.smoothirc.net 004 Aethec main.smoothirc.net InspIRCd-2.0 BGHIRSWikorswx CFGMORSTabcefhijklmnopqrstuvz Fabefhjkloqv");
     this._wrapper.ReceiveLine(":main.smoothirc.net 005 Aethec AWAYLEN=201 :are supported by this server");
     this._wrapper.ReceiveLine(":main.smoothirc.net 042 Aethec 540AAACYH :your unique ID");
     this._wrapper.ReceiveLine(":main.smoothirc.net 375 Aethec :main.smoothirc.net message of the day");
     this._wrapper.ReceiveLine(":main.smoothirc.net 372 Aethec :- (MOTD cut)");
     this._wrapper.ReceiveLine(":main.smoothirc.net 372 Aethec :- (for brevity)");
     this._wrapper.ReceiveLine(":main.smoothirc.net 376 Aethec :End of message of the day.");
     this._wrapper.ReceiveLine(":main.smoothirc.net 251 Aethec :There are 42 users and 15 invisible on 4 servers");
     this._wrapper.ReceiveLine(":main.smoothirc.net 252 Aethec 10 :operator(s) online");
     this._wrapper.ReceiveLine(":main.smoothirc.net 254 Aethec 20 :channels formed");
     this._wrapper.ReceiveLine(":main.smoothirc.net 255 Aethec :I have 18 clients and 3 servers");
     this._wrapper.ReceiveLine(":main.smoothirc.net 265 Aethec :Current Local Users: 18  Max: 46");
     this._wrapper.ReceiveLine(":main.smoothirc.net 266 Aethec :Current Global Users: 57  Max: 69");
     this._wrapper.ReceiveLine(":main.smoothirc.net 396 Aethec Smooth-un4lig.adslplus.ch :is now your displayed host");
     this._wrapper.ReceiveLine(":[email protected] MODE Aethec +x");
 }
        private async void Network_Authenticated(IrcNetwork network, EventArgs args)
        {
            if (this.NetworkInfo.JoinCommand.HasText())
            {
                this.Send(this.NetworkInfo.JoinCommand);

                // Some bots *cough* freenode's NickServ *cough* are slow.
                // Sending the JOINs directly after the join command results in joining channels BEFORE authentication.
                await Task.Delay(ChannelsJoinDelay);

                if (this._disposed || this.Network.ConnectionStatus != ConnectionStatus.Authenticated)
                {
                    return; // connection loss or network closed by user
                }
            }

            foreach (var channel in this.NetworkInfo.FavoriteChannels)
            {
                this.JoinChannel(channel);
            }

            // Join the channels which we were on before a disconnection, if any
            foreach (var vm in this.Conversations.OfType <IrcChannelViewModel>()
                     .Where(c => c.IsVisible))
            {
                vm.Channel.Join();
            }
        }
        public void Initialize()
        {
            var tup = Initializer.GetAuthenticatedNetwork();

            this._network = tup.Item1;
            this._wrapper = tup.Item2;
            this._channel = this._network.GetChannel("#channel");
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new instance of the <see cref="IrcMessage"/> class.
        /// </summary>
        public IrcMessage(IrcNetwork network, MessageDirection direction, IrcUser sender, IrcMessageType type, string content, string target = null)
            : base(network, direction, sender)
        {
            this.Type    = type;
            this.Content = content;
            this.Target  = target;

            this._isImportantMessage = this.IsImportant();
        }
Exemplo n.º 11
0
        public static Tuple <IrcNetwork, TestTcpWrapper> GetAuthenticatedNetwork(string nick = "nick", string real = "real")
        {
            var wrapper = new TestTcpWrapper();
            var network = new IrcNetwork(wrapper);

            network.ConnectAsync(nick, real, IrcUserLoginModes.None).Wait();
            wrapper.EndAuthenticate();
            wrapper.LinesSent.Clear();
            return(Tuple.Create(network, wrapper));
        }
        private void Network_ErrorReceived(IrcNetwork network, InformationReceivedEventArgs args)
        {
            int replyCode;

            if (int.TryParse(args.Command, out replyCode) && IgnoredReplies.Contains(replyCode))
            {
                return;
            }

            var message = new IrcMessage(this.Network, MessageDirection.FromServer, null, IrcMessageType.Error, args.Message);

            this.SelectedConversation.AddMessage(message);
        }
Exemplo n.º 13
0
        public void Initialize()
        {
            this._translator = new TestTranslator();

            var wrapper = new TestTcpWrapper();

            this._network = IrcNetwork.Get(wrapper);
            this._network.Connect();
            wrapper.EndConnect();
            this._network.Authenticate("Test", "Test", IrcUserLoginModes.None);

            Locator.Register <ITranslationService>(this._translator);
        }
 private void Network_ChannelListReceived(IrcNetwork network, ChannelListReceivedEventArgs args)
 {
     if (args.Channels.Count == 0)
     {
         var errorText  = Locator.Get <ITranslationService>().Translate("ConversationErrors", "EmptyChannelList");
         var ircMessage = new IrcMessage(this.Network, MessageDirection.FromServer, null, IrcMessageType.Error, errorText);
         this.SelectedConversation.AddMessage(ircMessage);
     }
     else
     {
         var channels = args.Channels.OrderBy(c => c.Name).ToList();
         var message  = new ChannelListMessage(this.Network, channels);
         this.SelectedConversation.AddMessage(message);
     }
 }
        private void Network_NicknameCollision(IrcNetwork network, NicknameCollisionEventArgs args)
        {
            string text;

            if (this.Network.ConnectionStatus < ConnectionStatus.Connected)
            {
                text = Locator.Get <ITranslationService>().Translate("ConnectionErrors", "NicknameCollision", args.UsedNickname);
            }
            else
            {
                text = Locator.Get <ITranslationService>().Translate("ConversationErrors", "NicknameTaken", args.UsedNickname);
            }

            var message = new IrcMessage(this.Network, MessageDirection.FromServer, null, IrcMessageType.Error, text);

            this.SelectedConversation.AddMessage(message);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Loads the networks setinngs into a new IrcNetwork instance.
        /// </summary>
        /// <param name="settings">The settings to load.</param>
        /// <returns>The IrcNetwork instance as an INetwork.</returns>
        /// <exception cref="UnsupportedProtocolExteption">
        /// An UnsupportedProtocolExteption is thrown, if the given settings object is for
        /// another protocol.
        /// </exception>
        public IrcShark.Chatting.INetwork LoadNetwork(NetworkSettings settings)
        {
            if (!settings.Protocol.Equals(Protocol.Name))
            {
                throw new UnsupportedProtocolException();
            }

            IrcNetwork result = new IrcNetwork(IrcProtocol.GetInstance(), settings.Name);
            foreach (ServerSettings server in settings.Servers)
            {
                IrcServerEndPoint ircsrv = result.AddServer(server.Name, server.Address);
                if (server.Parameters.ContainsKey("password"))
                {
                    ircsrv.Password = server.Parameters["password"];
                }
            }

            return result;
        }
Exemplo n.º 17
0
        private static void HandleCommandMessage(IrcNetwork network, string targetName, string command, string text)
        {
            if (CommandAliases.ContainsKey(command))
            {
                command = CommandAliases[command];
            }

            var attrib = Processors.Keys.FirstOrDefault(p => p.Command == command);

            if (attrib == null)
            {
                network.Client.SendRawData(command + CommandSeparators[0] + text);
            }
            else
            {
                var message = GetMessage(network, text, targetName, attrib);
                if (CheckCommandMessage(message, attrib))
                {
                    Processors[attrib](network, message);
                }
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the IrcServerEndPoint class.
 /// </summary>
 /// <param name="network">The network, this IrcServerEndPoint belongs to.</param>
 /// <param name="name">
 /// The displayed name of the server.
 /// </param>
 /// <param name="address">
 /// The dns of the irc server as a <see cref="System.String"/>.
 /// </param>
 /// <param name="port">
 /// The port where the irc server is listening on.
 /// </param>
 public IrcServerEndPoint(IrcNetwork network, string name, string address, int port)
 {
     this.network = network;
     this.port = port;
     this.address = address;
     this.name = name;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the IrcServerEndPoint class.
 /// </summary>
 /// <param name="network">The network, this IrcServerEndPoint belongs to.</param>
 /// <param name="hostName">
 /// The dns of the irc server as a <see cref="System.String"/>.
 /// </param>
 public IrcServerEndPoint(IrcNetwork network, string hostName)
 {
     this.network = network;
     address = hostName;
     name = hostName;
     port = 6667;
 }
Exemplo n.º 20
0
 public void RemoveServer()
 {
     IrcNetwork network = new IrcNetwork(protocol, "test");
     network.AddServer("test", "localhost:6667");
     network.RemoveServer("test");
     Assert.AreEqual(0, network.ServerCount);
     network = new IrcNetwork(protocol, "test");
     network.AddServer("test1", "localhost:6667");
     network.AddServer("test2", "localhost:6667");
     Assert.IsTrue(network.RemoveServer("test2"));
     Assert.AreEqual(1, network.ServerCount);
     Assert.IsNull(network["test2"]);
     Assert.IsNotNull(network["test1"]);
     Assert.IsTrue(network.RemoveServer("test1"));
     Assert.AreEqual(0, network.ServerCount);
     Assert.IsNull(network["test1"]);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the IrcServerEndPoint class.
 /// </summary>
 /// <param name="network">The network, this IrcServerEndPoint belongs to.</param>
 /// <param name="hostName">
 /// The dns of the irc server as a <see cref="System.String"/>.
 /// </param>
 /// <param name="port">
 /// The port where the irc server is listening on.
 /// </param>
 public IrcServerEndPoint(IrcNetwork network, string hostName, int port)
 {
     this.port = port;
     this.network = network;
     address = hostName;
     name = hostName;
 }