Esempio n. 1
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);
				});
		}
Esempio n. 2
0
        public ChannelWindow(ChatControl control)
        {
            InitializeComponent();
            this.DataContext = this;

            this.Control = control;

            control.SetValue(Grid.RowProperty, 1);
            control.SetValue(Grid.ColumnSpanProperty, 2);
            grdRoot.Children.Add(control);
            control.Session.StateChanged += new EventHandler<EventArgs>(Session_StateChanged);
        }
Esempio n. 3
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);
            });
        }
Esempio n. 4
0
		private void Session_SelfJoined(object sender, IrcJoinEventArgs e)
		{
			var page = new ChatControl(ChatPageType.Chat, (IrcSession)sender, e.Channel);
			var state = App.Settings.Current.Windows.States[page.Id];
			if (state.IsDetached)
			{
				var window = new ChannelWindow(page);
				window.Show();
			}
			else
			{
				this.AddPage(page, true);
			}
		}
Esempio n. 5
0
        private void Session_SelfJoined(object sender, IrcJoinEventArgs e)
        {
            var page  = new ChatControl(ChatPageType.Chat, (IrcSession)sender, e.Channel);
            var state = App.Settings.Current.Windows.States[page.Id];

            if (state.IsDetached)
            {
                var window = new ChannelWindow(page);
                window.Show();
            }
            else
            {
                this.AddPage(page, true);
            }
        }
 private string[] Split(string command, string args, int minArgs, int maxArgs, bool isChannelRequired)
 {
     string[] parts = ChatControl.Split(args, maxArgs);
     if (isChannelRequired && (parts.Length < 1 || !IrcTarget.IsChannelName(parts[0])))
     {
         if (!this.IsChannel)
         {
             throw new CommandException("Not on a channel.");
         }
         parts = new[] { this.Target.Name }.Union(ChatControl.Split(args, maxArgs - 1)).ToArray();
     }
     if (parts.Length < minArgs)
     {
         throw new CommandException(string.Format("{0} requires {1} parameters.", command, minArgs));
     }
     return(parts);
 }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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;
		}
Esempio n. 9
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;
			}
		}
Esempio n. 10
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);
        }