/// <summary> /// Initialises a new instance of the <see cref="IRCMarshal"/> class. /// </summary> /// <param name="connection">The connection to marshal data to and from.</param> /// <param name="tabHost">The TabControl that hosts the server and channel tabs.</param> /// <param name="autoCommands">A queue of commands to automatically execute once a connection is fully established.</param> /// <param name="parent">The owning form.</param> public IRCMarshal(Connection connection, TabControl tabHost, List<string> autoCommands, MainForm parent) { this.tabHost = tabHost; this.parent = parent; this.previousNickName = connection.Nickname; this.AwaitingModeMessage = true; this.AwaitingUserHostMessage = true; this.connection = connection; this.SetupConnectionEventHandlers(); this.channels = new List<IRCChannel>(); this.messageQueue = new Queue<Message>(15); this.channelBrowser = new ChannelBrowser(this); if (autoCommands != null) { this.autoCommands = autoCommands; } else { this.autoCommands = new List<string>(); } this.queueResetEvent = new AutoResetEvent(false); this.queueProcessingThread = new Thread(this.ProcessQueue); this.queueProcessingThread.Start(); }
/// <summary> /// Processes a connection request and creates marshals and tabs were needed. /// </summary> /// <param name="input">The raw connection command.</param> /// <param name="server">The associated server, null if not applicable.</param> private void ProcessConnectionRequest(string input, Server server) { Connection connection = new Connection(); ParseResult result = connection.Parse(input); Action<IRCTabPage> connectAction = (t) => { IRCTabPage serverTab; if (t == null) { serverTab = new IRCTabPage(this, connection.ToString(), server == null ? connection.Server : server.Alias, IRCTabType.Server); serverTab.Connection = connection; serverTab.Connection.UserName = server == null ? GlobalSettings.Instance.UserName : server.UserName; serverTab.Connection.RealName = server == null ? GlobalSettings.Instance.RealName : server.RealName; serverTab.Connection.Nickname = server == null ? GlobalSettings.Instance.NickName : server.NickName; serverTab.Connection.Mode = server == null ? GlobalSettings.Instance.Mode : server.Mode; List<string> commands = null; if (server != null) { commands = server.Commands; } IRCMarshal marshal = new IRCMarshal(connection, this.channelsTabControl, commands, this); marshal.ChannelCreated += new IRCMarshal.ChannelCreatedHandler(this.ChannelCreated); marshal.NetworkRegistered += (s, e) => this.InvokeAction(() => this.UpdateStatusBarText()); serverTab.Marshal = marshal; marshal.ServerTab = serverTab; channelsTabControl.TabPages.Add(serverTab); this.ConfigureNewIRCMarshal(this, marshal); } else { serverTab = t; } channelsTabControl.SelectedTab = serverTab; serverTab.Connection.Connect(); }; if (result.Success) { if (this.channelsTabControl.TabPages.ContainsKey(connection.ToString())) { IRCTabPage tabPage = this.channelsTabControl.TabPages[connection.ToString()] as IRCTabPage; if (tabPage.Marshal.IsConnected) { this.channelsTabControl.SelectedTab = tabPage; } else { connectAction.Invoke(tabPage); } } else { connectAction.Invoke(null); } } }
/// <summary> /// Initialises a new instance of the <see cref="IRCChannel"/> class. /// </summary> /// <param name="marshal">The network marshal for the channel.</param> /// <param name="connection">The connection the channel operates on.</param> public IRCChannel(IRCMarshal marshal, Connection connection) { this.marshal = marshal; this.connection = connection; this.users = new List<IRCUser>(); this.expectingNamesMessage = true; }