Beispiel #1
0
            public static IrcResponse[] Handle(string[] args, IrcSession session)
            {
                if (args.Length != 1)
                {
                    session.Open = false;
                    return(new IrcResponse[] { new NoticeResponse(session, "Invalid NICK") });
                }

                if (session.Pass == null)
                {
                    session.Open = false;
                    return(new IrcResponse[] { new NoticeResponse(session, "Error logging in") });
                }

                session.Nick = args[0];

                List <IrcResponse> responses = new List <IrcResponse>();

                foreach (Tuple <IrcResponseCode, string> line in Config.WelcomeText)
                {
                    responses.Add(new IrcResponse(line.Item1, session, line.Item2));
                }

                return(responses.ToArray());
            }
Beispiel #2
0
        public static void Create(IrcSession session, ChatPage page, bool makeActive)
        {
            if (App.Settings.Current.Windows.States.Exists(page.Id) ?
                App.Settings.Current.Windows.States[page.Id].IsDetached : App.Settings.Current.Windows.DefaultQueryDetached)
            {
                var newWin = new ChannelWindow(page);
                if (!makeActive)
                {
                    newWin.ShowActivated = false;
                    newWin.WindowState   = WindowState.Minimized;
                }
                newWin.Show();

                if (makeActive)
                {
                    newWin.Activate();
                }
                else
                {
                    Interop.WindowHelper.FlashWindow(newWin);
                }
            }
            else
            {
                var window = App.Current.MainWindow as ChatWindow;
                window.AddPage(page, makeActive);
                if (!window.IsActive)
                {
                    Interop.WindowHelper.FlashWindow(window);
                }
            }
        }
Beispiel #3
0
 public EvaluateCommand(IrcSession s, string channel)
 {
     sent    = 0;
     calls   = 0;
     Session = s;
     Channel = channel;
     //eval.SetCodeFinishedHandler((o,output)=>{Session.Msg(Channel,output);sent++;});
 }
Beispiel #4
0
 public FileControl(IrcSession session, IrcTarget target, DccMethod method)
     : base(ChatPageType.DccFile, session, target, "DCC")
 {
     this.DccMethod = method;
     InitializeComponent();
     this.Id     = "dcc-file";
     this.Header = this.Title = string.Format("{0} [DCC]", target.Name);
 }
		public FileControl(IrcSession session, IrcTarget target, DccMethod method)
			: base(ChatPageType.DccFile, session, target, "DCC")
		{
			this.DccMethod = method;
			InitializeComponent();
			this.Id = "dcc-file";
			this.Header = this.Title = string.Format("{0} [DCC]", target.Name);
		}
Beispiel #6
0
 public void UnsubscribeEvents(IrcSession session)
 {
     session.Joined -= new EventHandler<IrcChannelEventArgs>(Session_Joined);
     session.Parted -= new EventHandler<IrcChannelEventArgs>(Session_Parted);
     session.Kicked -= new EventHandler<IrcKickEventArgs>(Session_Kicked);
     session.StateChanged -= new EventHandler<EventArgs>(Session_StateChanged);
     session.CtcpCommandReceived -= new EventHandler<CtcpEventArgs>(Session_CtcpCommandReceived);
     session.RawMessageReceived -= new EventHandler<IrcEventArgs>(session_RawMessageReceived);
 }
Beispiel #7
0
 public ChatPage(ChatPageType type, IrcSession session, IrcTarget target, string id)
     : this()
 {
     this.Type        = type;
     this.Session     = session;
     this.Target      = target;
     this.Id          = id;
     this.IsCloseable = true;
 }
Beispiel #8
0
 public ChatPage(ChatPageType type, IrcSession session, IrcTarget target, string id)
     : this()
 {
     this.Type = type;
     this.Session = session;
     this.Target = target;
     this.Id = id;
     this.IsCloseable = true;
 }
 public UIServerConversation(IrcSession session, IrcConversationProvider provider)
 {
     _conversationProvider = provider;
     _session = session;
     _serverConversation = _session.ServerConversation;
     _serverConversation.Messages.CollectionChanged += new NotifyCollectionChangedEventHandler(Messages_CollectionChanged);
     _session.Channels.CollectionChanged += new NotifyCollectionChangedEventHandler(SessionChannels_CollectionChanged);
     _session.Conversations.CollectionChanged += new NotifyCollectionChangedEventHandler(Conversations_CollectionChanged);
 }
 public void UnsubscribeEvents(IrcSession session)
 {
     session.SelfJoined -= new EventHandler<IrcJoinEventArgs>(Session_SelfJoined);
     session.SelfParted -= new EventHandler<IrcPartEventArgs>(Session_SelfParted);
     session.SelfKicked -= new EventHandler<IrcKickEventArgs>(Session_SelfKicked);
     session.StateChanged -= new EventHandler<EventArgs>(Session_StateChanged);
     session.CtcpCommandReceived -= new EventHandler<CtcpEventArgs>(Session_CtcpCommandReceived);
     session.RawMessageReceived -= new EventHandler<IrcEventArgs>(session_RawMessageReceived);
     session.InfoReceived -= new EventHandler<IrcInfoEventArgs>(session_InfoReceived);
 }
Beispiel #11
0
 public void UnsubscribeEvents(IrcSession session)
 {
     session.SelfJoined          -= new EventHandler <IrcJoinEventArgs>(Session_SelfJoined);
     session.SelfParted          -= new EventHandler <IrcPartEventArgs>(Session_SelfParted);
     session.SelfKicked          -= new EventHandler <IrcKickEventArgs>(Session_SelfKicked);
     session.StateChanged        -= new EventHandler <EventArgs>(Session_StateChanged);
     session.CtcpCommandReceived -= new EventHandler <CtcpEventArgs>(Session_CtcpCommandReceived);
     session.RawMessageReceived  -= new EventHandler <IrcEventArgs>(session_RawMessageReceived);
     session.InfoReceived        -= new EventHandler <IrcInfoEventArgs>(session_InfoReceived);
 }
Beispiel #12
0
		public void DccChat(IrcSession session, IrcTarget target)
		{
			var page = new ChatControl(ChatPageType.DccChat, session, target);
			App.Create(session, page, true);
			page.StartListen((port) =>
				{
					session.SendCtcp(target, new CtcpCommand("DCC", "CHAT", "chat",
						ConvertIPAddressToString(session.ExternalAddress),
						port.ToString()), false);
				});
		}
Beispiel #13
0
            public static IrcResponse[] Handle(string[] args, IrcSession session)
            {
                if (args.Length != 1)
                {
                    session.Open = false;
                    return(new IrcResponse[] {});
                }

                session.Pass = args[0];
                return(new IrcResponse[] {});
            }
Beispiel #14
0
            public static IrcResponse[] Handle(string[] args, IrcSession session)
            {
                if (args.Length != 1)
                {
                    session.Open = false;
                    return new IrcResponse[] {};
                }

                session.Pass = args[0];
                return new IrcResponse[] {};
            }
Beispiel #15
0
        public void DccChat(IrcSession session, IrcTarget target)
        {
            var page = new ChatControl(ChatPageType.DccChat, session, target);

            App.Create(session, page, true);
            page.StartListen((port) =>
            {
                session.SendCtcp(target, new CtcpCommand("DCC", "CHAT", "chat",
                                                         ConvertIPAddressToString(session.ExternalAddress),
                                                         port.ToString()), false);
            });
        }
Beispiel #16
0
 public VoiceControl(IrcSession session, IrcTarget target, NicknameList nickList)
 {
     _session = session;
     _target = target;
     _nickList = nickList;
     _peers = new Dictionary<IPEndPoint, VoicePeer>();
     InitializeComponent();
     this.DataContext = this;
     if (nickList.Contains(_session.Nickname))
     {
         _self = nickList[_session.Nickname];
     }
 }
Beispiel #17
0
		public void DccSend(IrcSession session, IrcTarget target, FileInfo file)
		{
			var page = new FileControl(session, target, DccMethod.Send);
			App.Create(session, page, true);
			page.StartSend(file, (port) =>
			{
				if (port > 0)
				{
					session.SendCtcp(target, new CtcpCommand("DCC", "SEND", file.Name,
						ConvertIPAddressToString(session.ExternalAddress),
						port.ToString(), file.Length.ToString(), "T"), false);
				}
			});
		}
Beispiel #18
0
        public void Run()
        {
            //I had been using hardcoded user information in this file but since it's about to go up
            //on github i've hastily taken that out and put in this ugly Console based transaction

            string userName  = "******";
            string nickNames = "kerbcalc kerbcalc1 kerbcalc2";
            string password  = "******";

            if (!File.Exists("password"))
            {
                FileStream   fs = File.OpenWrite("password");
                StreamWriter sw = new StreamWriter(fs);
                Console.WriteLine("enter password");
                sw.WriteLine(Console.ReadLine());
                sw.Close();
                sw.Dispose();
            }
            StreamReader sr = new StreamReader(File.OpenRead("password"));

            password = sr.ReadLine().Trim();
            sr.Close();
            sr.Dispose();

            IrcNetworkInfo mynet = new IrcNetworkInfo("bleh");

            mynet.AddServer("irc.freenode.net", 6667, password);
            IrcUser me = new IrcUser("A. Realname", userName, nickNames.Split(" ".ToCharArray()));

            mySession = new IrcSession(me, mynet, new MessageHandler(channel));
            mySession.Connect();
            if (mySession.Connected == true)
            {
                Console.WriteLine("Connected");
            }
            else
            {
                Console.WriteLine("Connection Failed!!");
                return;
            }
            mySession.JoinChannel(channel, null);



            while (true)
            {
                string bleh = Console.ReadLine();
                HandleLocalInput(bleh);
            }
        }
Beispiel #19
0
        public override void OnChatMessage(IrcSession s, IrcUser sender, string target, string text)
        {
            char[] trimOut = new Char[1];
            string cmd     = null;
            string key;

            trimOut[0] = '\x0001';

            if (CList == null)
            {
                CList = new CommandList();
                CList.AddLocalCommand(new EvaluateCommand(s, Channel), 2);
                CList.AddLocalCommand(new CallCommand("!whatis", new CommandDelegate((o, a) => Fun.WhatIs(a[1]))), 2);
                CList.AddLocalCommand(new BasicCommand("!ping", "PONG!"), 2);
                CList.AddLocalCommand(new CallCommand("!help", new CommandDelegate((o, a) => {
                    StringBuilder sb = new StringBuilder("Available commands: ");
                    foreach (string st in CList.GetCommands(2))
                    {
                        sb.Append(st);
                        sb.Append(' ');
                    }
                    return(sb.ToString());
                })), 2);
            }
            if (text[0] == 1 && text[text.Length - 1] == 1)
            {
                text = text.Trim(trimOut);
                cmd  = text.Split(' ')[0];

                text = text.Remove(0, cmd.Length);
                text = text.Trim();
            }
            key = text.Split(' ')[0];
            if (cmd != null && cmd == "ACTION")
            {
                Console.WriteLine("*{0} {1}*", sender.CurrentNick, text);
            }
            else
            {
                Console.WriteLine("<{0}> {1}", sender.CurrentNick, text);
            }
            if (target.ToLower() == Channel.ToLower())
            {
                string outp = CList.Parse(2, text);
                if (outp != null)
                {
                    s.Msg(Channel, CList.Parse(2, text));
                }
            }
        }
Beispiel #20
0
        public void DccSend(IrcSession session, IrcTarget target, FileInfo file)
        {
            var page = new FileControl(session, target, DccMethod.Send);

            App.Create(session, page, true);
            page.StartSend(file, (port) =>
            {
                if (port > 0)
                {
                    session.SendCtcp(target, new CtcpCommand("DCC", "SEND", file.Name,
                                                             ConvertIPAddressToString(session.ExternalAddress),
                                                             port.ToString(), file.Length.ToString(), "T"), false);
                }
            });
        }
Beispiel #21
0
        public ListControl(IrcSession session)
            : base(ChatPageType.ChannelList, session, null, "chan-list")
        {
            _channels = new List <ChannelItem>();
            InitializeComponent();
            this.Header                = "Channel List";
            this.Title                 = string.Format("{0} - {1} - {2} Channel List", App.Product, this.Session.Nickname, this.Session.NetworkName);
            this.IsCloseable           = false;
            this.Session.InfoReceived += new EventHandler <IrcInfoEventArgs>(Session_InfoReceived);

            var menu = this.Resources["cmChannels"] as ContextMenu;

            if (menu != null)
            {
                NameScope.SetNameScope(menu, NameScope.GetNameScope(this));
            }
        }
Beispiel #22
0
 public static IrcResponse[] HandleCommand(string req, IrcSession session)
 {
     string[] parts = req.Split(' ');
     string cmd = parts[0].ToUpper();
     string[] args = parts.Skip(1).ToArray();
     switch (cmd)
     {
         case "PASS":
             return Pass.Handle(args, session);
         case "NICK":
             return Nick.Handle(args, session);
         case "JOIN":
             return Join.Handle(args, session);
         case "QUIT":
             return Quit.Handle(session);
         default:
             return new IrcResponse[] {new UnknownCommandResponse(session, cmd)};
     }
 }
Beispiel #23
0
            public static IrcResponse[] Handle(string[] args, IrcSession session)
            {
                if (args.Length != 1)
                {
                    return new IrcResponse[] {};
                }

                if (!IrcChannel.Channels.ContainsKey(args[0]))
                {
                    IrcChannel.Channels.Add(args[0], new IrcChannel(args[0]));
                }

                IrcChannel.Channels[args[0]].Users.Add(session);
                session.CurrentChannel = args[0];

                return new IrcResponse[]
                {
                    new EchoResponse(session, "JOIN " + args[0]),
                    new CustomResponse(session, $":{session.Nick}.{Config.Hostname} 353 {session.Nick} = {args[0]} :{session.Nick}"),
                    new CustomResponse(session, $":{session.Nick}.{Config.Hostname} 366 {session.Nick} {args[0]} :End of /NAMES list"),
                };
            }
Beispiel #24
0
            public static IrcResponse[] Handle(string[] args, IrcSession session)
            {
                if (args.Length != 1)
                {
                    return(new IrcResponse[] {});
                }

                if (!IrcChannel.Channels.ContainsKey(args[0]))
                {
                    IrcChannel.Channels.Add(args[0], new IrcChannel(args[0]));
                }

                IrcChannel.Channels[args[0]].Users.Add(session);
                session.CurrentChannel = args[0];

                return(new IrcResponse[]
                {
                    new EchoResponse(session, "JOIN " + args[0]),
                    new CustomResponse(session, $":{session.Nick}.{Config.Hostname} 353 {session.Nick} = {args[0]} :{session.Nick}"),
                    new CustomResponse(session, $":{session.Nick}.{Config.Hostname} 366 {session.Nick} {args[0]} :End of /NAMES list"),
                });
            }
Beispiel #25
0
        public static bool Create(IrcSession session, IrcTarget target, bool makeActive)
        {
            var detached = App.Current.Windows.OfType <ChannelWindow>().Where((cw) => cw.Page.Session == session &&
                                                                              target.Equals(cw.Page.Target) && cw.Page.Type == ChatPageType.Chat).FirstOrDefault();

            if (detached != null)
            {
                if (makeActive)
                {
                    detached.Activate();
                }
                return(false);
            }

            var window = App.ChatWindow;
            var page   = window.FindPage(ChatPageType.Chat, session, target);

            if (page != null)
            {
                if (makeActive)
                {
                    window.Show();
                    if (window.WindowState == WindowState.Minimized)
                    {
                        window.WindowState = WindowState.Normal;
                    }
                    window.Activate();
                    window.SwitchToPage(page);
                }
                return(false);
            }
            else
            {
                page = new ChatControl(target == null ? ChatPageType.Server : ChatPageType.Chat, session, target);
                Create(session, page, makeActive);
                return(true);
            }
        }
Beispiel #26
0
            public static IrcResponse[] HandleCommand(string req, IrcSession session)
            {
                string[] parts = req.Split(' ');
                string   cmd   = parts[0].ToUpper();

                string[] args = parts.Skip(1).ToArray();
                switch (cmd)
                {
                case "PASS":
                    return(Pass.Handle(args, session));

                case "NICK":
                    return(Nick.Handle(args, session));

                case "JOIN":
                    return(Join.Handle(args, session));

                case "QUIT":
                    return(Quit.Handle(session));

                default:
                    return(new IrcResponse[] { new UnknownCommandResponse(session, cmd) });
                }
            }
Beispiel #27
0
            public static IrcResponse[] Handle(string[] args, IrcSession session)
            {
                if(args.Length != 1)
                {
                    session.Open = false;
                    return new IrcResponse[] {new NoticeResponse(session, "Invalid NICK")};
                }

                if (session.Pass == null)
                {
                    session.Open = false;
                    return new IrcResponse[] {new NoticeResponse(session, "Error logging in")};
                }

                session.Nick = args[0];

                List<IrcResponse> responses = new List<IrcResponse>();
                foreach (Tuple<IrcResponseCode, string> line in Config.WelcomeText)
                {
                    responses.Add(new IrcResponse(line.Item1, session, line.Item2));
                }

                return responses.ToArray();
            }
 public void IrcChannel_TopicNull()
 {
     var session = new IrcSession();
     var channel = new IrcChannel(session, String.Empty, null);
 }
 public void IrcChannel_NameWithSpace()
 {
     var session = new IrcSession();
     var channel = new IrcChannel(session, "Test space", "");
     Assert.AreEqual("Test", channel.Name);
 }
Beispiel #30
0
 public override void OnChannelModeChanged(IrcSession s, string channel, IrcUser user, string message)
 {
     Console.WriteLine("{0} set mode to {1}", user, message);
 }
Beispiel #31
0
 public int ExtractData(NetworkTcpSession tcpSession, NetworkHost sourceHost, NetworkHost destinationHost, IEnumerable <PacketParser.Packets.AbstractPacket> packetList)
 {
     Packets.IrcPacket ircPacket = null;
     Packets.TcpPacket tcpPacket = null;
     foreach (Packets.AbstractPacket p in packetList)
     {
         if (p.GetType() == typeof(Packets.TcpPacket))
         {
             tcpPacket = (Packets.TcpPacket)p;
         }
         else if (p.GetType() == typeof(Packets.IrcPacket))
         {
             ircPacket = (Packets.IrcPacket)p;
         }
     }
     if (ircPacket != null && tcpPacket != null)
     {
         System.Collections.Specialized.NameValueCollection tmpCol = new System.Collections.Specialized.NameValueCollection();
         foreach (Packets.IrcPacket.Message m in ircPacket.Messages)
         {
             tmpCol.Add(m.Command, m.ToString());
             if (m.Command.Equals("USER", StringComparison.InvariantCultureIgnoreCase))
             {
                 //the first parameter is the username
                 List <string> parameters = new List <string>();
                 foreach (string s in m.Parameters)
                 {
                     parameters.Add(s);
                 }
                 if (parameters.Count > 0)
                 {
                     string     ircUser = parameters[0];
                     IrcSession ircSession;
                     if (this.ircSessionList.ContainsKey(tcpSession))
                     {
                         ircSession = ircSessionList[tcpSession];
                     }
                     else
                     {
                         ircSession = new IrcSession();
                         this.ircSessionList.Add(tcpSession, ircSession);
                     }
                     ircSession.User = ircUser;
                     sourceHost.AddNumberedExtraDetail("IRC Username", ircUser);
                     //NetworkCredential ircUserCredential = new NetworkCredential(sourceHost, destinationHost, "IRC", ircUser, "N/A (only IRC Username)", ircPacket.ParentFrame.Timestamp);
                     this.MainPacketHandler.AddCredential(ircSession.GetCredential(sourceHost, destinationHost, ircPacket.ParentFrame.Timestamp));
                 }
                 if (parameters.Count > 1)
                 {
                     sourceHost.AddHostName(parameters[1]);
                 }
                 if (parameters.Count > 2)
                 {
                     destinationHost.AddHostName(parameters[2]);
                 }
             }
             else if (m.Command.Equals("NICK", StringComparison.InvariantCultureIgnoreCase))
             {
                 IEnumerator <string> enumerator = m.Parameters.GetEnumerator();
                 if (enumerator.MoveNext())  //move to the first position
                 {
                     string     ircNick = enumerator.Current;
                     IrcSession ircSession;
                     if (this.ircSessionList.ContainsKey(tcpSession))
                     {
                         ircSession = ircSessionList[tcpSession];
                     }
                     else
                     {
                         ircSession = new IrcSession();
                         this.ircSessionList.Add(tcpSession, ircSession);
                     }
                     ircSession.Nick = ircNick;
                     sourceHost.AddNumberedExtraDetail("IRC Nick", ircNick);
                     //NetworkCredential ircNicCredential = new NetworkCredential(sourceHost, destinationHost, "IRC", enumerator.Current, "N/A (only IRC Nick)", ircPacket.ParentFrame.Timestamp);
                     this.MainPacketHandler.AddCredential(ircSession.GetCredential(sourceHost, destinationHost, ircPacket.ParentFrame.Timestamp));
                 }
             }
             else if (m.Command.Equals("PASS", StringComparison.InvariantCultureIgnoreCase))
             {
                 IEnumerator <string> enumerator = m.Parameters.GetEnumerator();
                 if (enumerator.MoveNext())  //move to the first position
                 {
                     string     ircPass = enumerator.Current;
                     IrcSession ircSession;
                     if (this.ircSessionList.ContainsKey(tcpSession))
                     {
                         ircSession = ircSessionList[tcpSession];
                     }
                     else
                     {
                         ircSession = new IrcSession();
                         this.ircSessionList.Add(tcpSession, ircSession);
                     }
                     ircSession.Pass = ircPass;
                     this.MainPacketHandler.AddCredential(ircSession.GetCredential(sourceHost, destinationHost, ircPacket.ParentFrame.Timestamp));
                 }
             }
             else if (m.Command.Equals("PRIVMSG", StringComparison.InvariantCultureIgnoreCase))
             {
                 //first parameter is recipient, second is message
                 List <string> parameters = new List <string>();
                 foreach (string s in m.Parameters)
                 {
                     parameters.Add(s);
                 }
                 if (parameters.Count >= 2)
                 {
                     System.Collections.Specialized.NameValueCollection attributes = new System.Collections.Specialized.NameValueCollection();
                     attributes.Add("Command", m.Command);
                     string from = "";
                     if (m.Prefix != null && m.Prefix.Length > 0)
                     {
                         attributes.Add("Prefix", m.Prefix);
                         from = m.Prefix;
                     }
                     for (int i = 0; i < parameters.Count; i++)
                     {
                         attributes.Add("Parameter " + (i + 1), parameters[i]);
                     }
                     base.MainPacketHandler.OnMessageDetected(new PacketParser.Events.MessageEventArgs(ApplicationLayerProtocol.Irc, sourceHost, destinationHost, ircPacket.ParentFrame.FrameNumber, ircPacket.ParentFrame.Timestamp, from, parameters[0], parameters[1], parameters[1], attributes));
                 }
             }
         }
         if (tmpCol.Count > 0)
         {
             base.MainPacketHandler.OnParametersDetected(new PacketParser.Events.ParametersEventArgs(ircPacket.ParentFrame.FrameNumber, sourceHost, destinationHost, "TCP " + tcpPacket.SourcePort, "TCP " + tcpPacket.DestinationPort, tmpCol, tcpPacket.ParentFrame.Timestamp, "IRC packet"));
             return(ircPacket.ParsedBytesCount);
         }
     }
     return(0);
 }
			public EchoResponse(IrcSession user, string command) : base(IrcResponseCode.Null, user, "")
			{
				Command = command;
			}
 public UnknownCommandResponse(IrcSession user, string cmd) : base(IrcResponseCode.ErrorUnknownCommand, user, "")
 {
     Command = cmd;
 }
Beispiel #34
0
 public override void OnUserQuit(IrcSession s, string[] affectedChannels, IrcUser user, string message)
 {
     Console.WriteLine("{0} quit [{1}]", user.CurrentNick, message);
 }
Beispiel #35
0
 public ChatContext(IrcSession ircSession, IrcTarget target)
 {
     this.Session = ircSession;
     this.Target = target;
 }
Beispiel #36
0
 public override void OnUserPartedChannel(IrcSession s, string channel, IrcUser user, string message)
 {
     Console.WriteLine("{0} parted {1} [{2}]({3})", user.CurrentNick, channel, message, s.GetChannelUsers(channel).Count);
 }
Beispiel #37
0
 public override void OnUserNickChanged(IrcSession s, string[] affectdChannels, string oldNick, string newNick)
 {
     Console.WriteLine("{0} has changed their nick to {1}", oldNick, newNick);
 }
Beispiel #38
0
 public override void OnUserKicked(IrcSession s, string channel, string kicker, string kickee, string message)
 {
     Console.WriteLine("{0} kicked by {1} [{2}]", kickee, kicker, message);
 }
Beispiel #39
0
 public override void OnNotice(IrcSession s, IrcUser User, string Target, string Text)
 {
     Console.WriteLine("-*{0}*- {1}", User.CurrentNick, Text);
 }
			public CustomResponse(IrcSession user, string message) : base(IrcResponseCode.Null, user, message)
			{
			}
 public void IrcChannel_TopicEmpty()
 {
     var session = new IrcSession();
     var channel = new IrcChannel(session, String.Empty, String.Empty);
     Assert.AreEqual(String.Empty, channel.Topic);
 }
Beispiel #42
0
 public static IrcResponse[] Handle(IrcSession session)
 {
     session.Open = false;
     return(new IrcResponse[] {});
 }
			public UnknownCommandResponse(IrcSession user, string cmd) : base(IrcResponseCode.ErrorUnknownCommand, user, "")
			{
				Command = cmd;
			}
Beispiel #44
0
 public static IrcResponse[] Handle(IrcSession session)
 {
     session.Open = false;
     return new IrcResponse[]{};
 }
			public NoticeResponse(IrcSession user, string message) : base(IrcResponseCode.Null, user, message)
			{
			}
Beispiel #46
0
		public static void Create(IrcSession session, ChatPage page, bool makeActive)
		{
			if (App.Settings.Current.Windows.States.Exists(page.Id) ?
				App.Settings.Current.Windows.States[page.Id].IsDetached : App.Settings.Current.Windows.DefaultQueryDetached)
			{
				var newWin = new ChannelWindow(page);
				if (!makeActive)
				{
					newWin.ShowActivated = false;
					newWin.WindowState = WindowState.Minimized;
				}
				newWin.Show();

				if (makeActive)
				{
					newWin.Activate();
				}
				else
				{
					Interop.WindowHelper.FlashWindow(newWin);
				}
			}
			else
			{
				var window = App.Current.MainWindow as ChatWindow;
				window.AddPage(page, makeActive);
				if (!window.IsActive)
				{
					Interop.WindowHelper.FlashWindow(window);
				}
			}
		}
Beispiel #47
0
		public static bool Create(IrcSession session, IrcTarget target, bool makeActive)
		{
			var detached = App.Current.Windows.OfType<ChannelWindow>().Where((cw) => cw.Page.Session == session
				&& target.Equals(cw.Page.Target) && cw.Page.Type == ChatPageType.Chat).FirstOrDefault();
			if (detached != null)
			{
				if (makeActive)
				{
					detached.Activate();
				}
				return false;
			}

			var window = App.ChatWindow;
			var page = window.FindPage(ChatPageType.Chat, session, target);
			if (page != null)
			{
				if (makeActive)
				{
					window.Show();
					if (window.WindowState == WindowState.Minimized)
					{
						window.WindowState = WindowState.Normal;
					}
					window.Activate();
					window.SwitchToPage(page);
				}
				return false;
			}
			else
			{
				page = new ChatControl(target == null ? ChatPageType.Server : ChatPageType.Chat, session, target);
				Create(session, page, makeActive);
				return true;
			}
		}
Beispiel #48
0
        public ChatControl(ChatPageType type, IrcSession session, IrcTarget target)
            : base(type, session, target, type == ChatPageType.Server ? "server" :
                   (type == ChatPageType.DccChat ? "dcc-chat" : string.Format("{0}.{1}", session.NetworkName, target.Name).ToLowerInvariant()))
        {
            _history       = new LinkedList <string>();
            this.Nicknames = new ObservableCollection <NicknameItem>();

            InitializeComponent();

            var state = App.Settings.Current.Windows.States[this.Id];

            if (this.Type == ChatPageType.DccChat)
            {
                this.Header = string.Format("[CHAT] {0}", this.Target.Name);
            }
            else if (this.Type == ChatPageType.Chat || this.Type == ChatPageType.Server)
            {
                this.Header = this.Target == null ? "Server" : this.Target.ToString();
                this.SubscribeEvents();

                if (!this.IsServer)
                {
                    _logFile = App.OpenLogFile(this.Id);
                    var logLines = new List <ChatLine>();
                    while (_logFile.Buffer.Count > 0)
                    {
                        var cl = _logFile.Buffer.Dequeue();
                        cl.Marker = _logFile.Buffer.Count == 0 ? ChatMarker.OldMarker : ChatMarker.None;
                        logLines.Add(cl);
                    }
                    boxOutput.AppendBulkLines(logLines);
                }

                if (this.IsChannel)
                {
                    colNickList.MinWidth = MinNickListWidth;
                    colNickList.Width    = new GridLength(state.NickListWidth);

                    this.Write("Join", string.Format("Now talking on {0}", this.Target.Name));
                    this.Session.AddHandler(new IrcCodeHandler((e) =>
                    {
                        if (e.Message.Parameters.Count > 2 &&
                            this.Target.Equals(new IrcTarget(e.Message.Parameters[1])))
                        {
                            _channelModes = e.Message.Parameters[2].ToCharArray().Where((c) => c != '+').ToArray();
                            this.SetTitle();
                        }
                        e.Handled = true;
                        return(true);
                    }, IrcCode.RPL_CHANNELMODEIS));
                    this.Session.Mode(this.Target);
                    splitter.IsEnabled = true;

                    var nameHandler = new IrcCodeHandler((e) =>
                    {
                        if (e.Message.Parameters.Count >= 3)
                        {
                            var to = new IrcTarget(e.Message.Parameters[e.Message.Parameters.Count - 2]);
                            if (this.Target.Equals(to))
                            {
                                foreach (var nick in e.Message.Parameters[e.Message.Parameters.Count - 1].Split(' '))
                                {
                                    this.AddNick(nick);
                                }
                            }
                        }
                        e.Handled = true;
                        return(false);
                    }, IrcCode.RPL_NAMEREPLY);
                    this.Session.AddHandler(nameHandler);
                    this.Session.AddHandler(new IrcCodeHandler((e) =>
                    {
                        this.Session.RemoveHandler(nameHandler);
                        e.Handled = true;
                        return(true);
                    }, IrcCode.RPL_ENDOFNAMES));
                }
                else if (this.IsNickname)
                {
                    _prefix = this.Target.Name;
                }
            }
            else
            {
                throw new ArgumentException("Page type is not supported.");
            }

            boxOutput.ColumnWidth = state.ColumnWidth;

            this.Loaded   += new RoutedEventHandler(ChatControl_Loaded);
            this.Unloaded += new RoutedEventHandler(ChatControl_Unloaded);
            this.PrepareContextMenus();
            boxOutput.ContextMenu = this.GetDefaultContextMenu();
        }
Beispiel #49
0
 public override void OnUserModeChanged(IrcSession s, IrcUser user, string change)
 {
     Console.WriteLine("User mode set to: [{0}]", change);
 }
Beispiel #50
0
        public ChatControl(ChatPageType type, IrcSession session, IrcTarget target)
            : base(type, session, target, type == ChatPageType.Server ? "server" : 
			(type == ChatPageType.DccChat ? "dcc-chat" : string.Format("{0}.{1}", session.NetworkName, target.Name).ToLowerInvariant()))
        {
            _history = new LinkedList<string>();
            _nickList = new NicknameList();

            InitializeComponent();

            var state = App.Settings.Current.Windows.States[this.Id];
            if (this.Type == ChatPageType.DccChat)
            {
                this.Header = string.Format("[CHAT] {0}", this.Target.Name);
            }
            else if (this.Type == ChatPageType.Chat || this.Type == ChatPageType.Server)
            {
                this.Header = this.Target == null ? "Server" : this.Target.ToString();
                this.SubscribeEvents();

                if (!this.IsServer)
                {
                    _logFile = App.OpenLogFile(this.Id);
                    var logLines = new List<ChatLine>();
                    while (_logFile.Buffer.Count > 0)
                    {
                        var cl = _logFile.Buffer.Dequeue();
                        cl.Marker = _logFile.Buffer.Count == 0 ? ChatMarker.OldMarker : ChatMarker.None;
                        logLines.Add(cl);
                    }
                    boxOutput.AppendBulkLines(logLines);
                }

                if (this.IsChannel)
                {
                    colNickList.MinWidth = MinNickListWidth;
                    colNickList.Width = new GridLength(state.NickListWidth);

                    this.Write("Join", string.Format("Now talking on {0}", this.Target.Name));
                    this.Session.AddHandler(new IrcCodeHandler((e) =>
                        {
                            if (e.Message.Parameters.Count > 2 &&
                                this.Target.Equals(new IrcTarget(e.Message.Parameters[1])))
                            {
                                _channelModes = e.Message.Parameters[2].ToCharArray().Where((c) => c != '+').ToArray();
                                this.SetTitle();
                            }
                            e.Handled = true;
                            return true;
                        }, IrcCode.RPL_CHANNELMODEIS));
                    this.Session.Mode(this.Target);
                    splitter.IsEnabled = true;

                    var nameHandler = new IrcCodeHandler((e) =>
                        {
                            if (e.Message.Parameters.Count >= 3)
                            {
                                var to = new IrcTarget(e.Message.Parameters[e.Message.Parameters.Count - 2]);
                                if (this.Target.Equals(to))
                                {
                                    _nickList.AddRange(e.Message.Parameters[e.Message.Parameters.Count - 1].Split(' ').
                                        Where((n) => n.Length > 0));
                                }
                            }
                            e.Handled = true;
                            return false;
                        }, IrcCode.RPL_NAMEREPLY);
                    this.Session.AddHandler(nameHandler);
                    this.Session.AddHandler(new IrcCodeHandler((e) =>
                        {
                            this.Session.RemoveHandler(nameHandler);
                            e.Handled = true;
                            return true;
                        }, IrcCode.RPL_ENDOFNAMES));
                }
                else if (this.IsNickname)
                {
                    _prefix = this.Target.Name;
                }
            }
            else
            {
                throw new ArgumentException("Page type is not supported.");
            }

            boxOutput.ColumnWidth = state.ColumnWidth;

            this.Loaded += new RoutedEventHandler(ChatControl_Loaded);
            this.Unloaded += new RoutedEventHandler(ChatControl_Unloaded);
            this.PrepareContextMenus();
            boxOutput.ContextMenu = this.GetDefaultContextMenu();
        }
Beispiel #51
0
 public NoticeResponse(IrcSession user, string message) : base(IrcResponseCode.Null, user, message)
 {
 }
Beispiel #52
0
 public override void OnServerReply(IrcSession s, short code, string data)
 {
     Console.WriteLine("{1}Server: {0}", data, code);
 }
 public void IrcChannel_Topic()
 {
     var session = new IrcSession();
     var channel = new IrcChannel(session, String.Empty, ":Test topic");
     Assert.AreEqual("Test topic", channel.Topic);
 }
Beispiel #54
0
		private bool HandleDcc(IrcSession session, IrcTarget target, string[] args)
		{
			if (args.Length < 1)
			{
				return false;
			}

			string type = args[0].ToUpperInvariant();
			IPAddress addr;
			int port;

			switch (type)
			{
				case "CHAT":
					{
						if (args.Length < 4 ||
							args[1].ToUpperInvariant() != "CHAT" ||
							!IPAddress.TryParse(args[2], out addr) ||
							!int.TryParse(args[3], out port))
						{
							session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", "CHAT", "unavailable"), true);
							return true;
						}

						var page = new ChatControl(ChatPageType.DccChat, session, target);
						page.StartAccept(addr, port);
						page.NotifyState = NotifyState.Alert;
						App.Create(session, page, false);
						App.Alert(Window.GetWindow(page), string.Format("{0} wants to chat with you.", target.Name));
					}
					break;

				case "XMIT":
					{
						if (args.Length < 5 ||
							string.Compare(args[1], "CLEAR", StringComparison.OrdinalIgnoreCase) != 0 ||
							!IPAddress.TryParse(args[2], out addr) ||
							!int.TryParse(args[3], out port))
						{
							session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", "XMIT", "unavailable"), true);
							return true;
						}

						string name = args[4];
						long size = 0;
						if (args.Length > 5)
						{
							long.TryParse(args[5], out size);
						}

						var page = new FileControl(session, target, DccMethod.Xmit);
						page.StartReceive(addr, port, name, size);
						page.NotifyState = NotifyState.Alert;
						App.Create(session, page, false);
						App.Alert(Window.GetWindow(page), string.Format("{0} wants to send you a file.", target.Name));
					}
					break;

				case "SEND":
					{
						if (args.Length < 4 ||
							!IPAddress.TryParse(args[2], out addr) ||
							!int.TryParse(args[3], out port))
						{
							session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", "SEND", "unavailable"), true);
							return true;
						}

						string name = args[1];
						long size = 0;
						if (args.Length > 4)
						{
							long.TryParse(args[4], out size);
						}

						var page = new FileControl(session, target, DccMethod.Send);
						page.StartReceive(addr, port, name, size);
						page.NotifyState = NotifyState.Alert;
						App.Create(session, page, false);
						App.Alert(Window.GetWindow(page), string.Format("{0} wants to send you a file.", target.Name));
					}
					break;

				default:
					session.SendCtcp(target, new CtcpCommand("ERRMSG", "DCC", args[0], "unavailable"), true);
					break;
			}
			return true;
		}
Beispiel #55
0
 public override void OnDisconnect(IrcSession s)
 {
     Environment.Exit(0);
 }
Beispiel #56
0
		public ChatPage FindPage(ChatPageType type, IrcSession session, IrcTarget target)
		{
			return this.Items.Where((i) => i.Page.Type == type && i.Page.Session == session && i.Page.Target != null &&
				i.Page.Target.Equals(target)).Select((i) => i.Page).FirstOrDefault();
		}
Beispiel #57
0
 public override void OnUserJoinedChannel(IrcSession s, string channel, IrcUser user)
 {
     Console.WriteLine("{0} joined {1} ({2})", user.CurrentNick, channel, s.GetChannelUsers(channel).Count);
 }