示例#1
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];
     }
 }
示例#2
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();
        }