コード例 #1
0
ファイル: FormMain.cs プロジェクト: origins/ICEChat
        private void toolStripAway_Click(object sender, EventArgs e)
        {
            //check if away or not
            if (FormMain.Instance.InputPanel.CurrentConnection != null)
            {
                if (inputPanel.CurrentConnection.ServerSetting.Away)
                {
                    ParseOutGoingCommand(inputPanel.CurrentConnection, "/away");
                }
                else
                {
                    //ask for an away reason
                    InputBoxDialog i = new InputBoxDialog();
                    i.FormCaption = "Enter your away Reason";
                    i.FormPrompt = "Away Reason";

                    i.ShowDialog();
                    if (i.InputResponse.Length > 0)
                        ParseOutGoingCommand(inputPanel.CurrentConnection, "/away " + i.InputResponse);

                    i.Dispose();
                }
            }
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: origins/ICEChat
        /// <summary>
        /// Parse out $identifiers for outgoing commands
        /// </summary>
        /// <param name="connection">Which Connection it is for</param>
        /// <param name="data">The data to be parsed</param>
        /// <returns></returns>
        private string ParseIdentifiers(IRCConnection connection, string data, string dataPassed)
        {
            string[] changedData = null;

            try
            {

                //parse the initial identifiers
                data = ParseIdentifier(connection, data);

                //parse out the $1,$2.. identifiers
                data = ParseIdentifierValue(data, dataPassed);

                //$+ is a joiner identifier, great for joining 2 words together
                data = data.Replace(" $+ ", string.Empty);

                //split up the data into words
                string[] parsedData = data.Split(' ');

                //the data that was passed for parsing identifiers
                string[] passedData = dataPassed.Split(' ');

                //will hold the updates message/data after identifiers are parsed
                changedData = data.Split(' ');

                int count = -1;
                string extra = "";
                bool askExtra = false;

                foreach (string word in parsedData)
                {
                    count++;

                    if (word.StartsWith("//") && count == 0)
                        changedData[count] = word.Substring(1);

                    if (askExtra)
                    {
                        //continueing a $?=
                        extra += " " + word;
                        changedData[count] = null;
                        if (extra[extra.Length - 1] == extra[0])
                        {
                            askExtra = false;
                            //ask the question
                            InputBoxDialog i = new InputBoxDialog();
                            i.FormCaption = "Enter Value";
                            i.FormPrompt = extra.Substring(1,extra.Length-2);

                            i.ShowDialog();
                            if (i.InputResponse.Length > 0)
                                changedData[count] = i.InputResponse;
                            i.Dispose();
                        }
                    }

                    //parse out identifiers (start with a $)
                    if (word.StartsWith("$"))
                    {
                        switch (word)
                        {

                            default:
                                int result;

                                if (word.StartsWith("$?=") && word.Length > 5)
                                {
                                    //check for 2 quotes (single or double)
                                    string ask = word.Substring(3);
                                    //check what kind of a quote it is
                                    char quote = ask[0];
                                    if (quote == ask[ask.Length - 1])
                                    {
                                        //ask the question
                                        extra = ask;
                                        InputBoxDialog i = new InputBoxDialog();
                                        i.FormCaption = "Enter Value";
                                        i.FormPrompt = extra.Substring(1, extra.Length - 2);

                                        i.ShowDialog();
                                        if (i.InputResponse.Length > 0)
                                            changedData[count] = i.InputResponse;
                                        else
                                            changedData[count] = null;
                                        i.Dispose();
                                    }
                                    else
                                    {
                                        //go to the next word until we find a quote at the end
                                        extra = ask;
                                        askExtra = true;
                                        changedData[count] = null;
                                    }
                                }

                                if (word.StartsWith("$md5(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    string input = ReturnBracketValue(word);
                                    changedData[count] = MD5(input);
                                }

                                if (word.StartsWith("$read(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    string file = ReturnBracketValue(word);
                                    //check if we have passed a path or just a filename
                                    if (file.IndexOf(System.IO.Path.DirectorySeparatorChar) > -1)
                                    {
                                        //its a full folder
                                        if (File.Exists(file))
                                        {
                                            //count the number of lines in the file
                                            //load the file in and read a random line from it
                                            string[] lines = File.ReadAllLines(file);
                                            if (lines.Length > 0)
                                            {
                                                //pick a random line
                                                Random r = new Random();
                                                int line = r.Next(0, lines.Length - 1);
                                                changedData[count] = lines[line];
                                            }
                                            else
                                                changedData[count] = "$null";

                                        }
                                    }
                                    else
                                    {
                                        //just check in the Scripts Folder
                                        if (File.Exists(scriptsFolder + System.IO.Path.DirectorySeparatorChar + file))
                                        {
                                            //load the file in and read a random line from it
                                            string[] lines = File.ReadAllLines(scriptsFolder + System.IO.Path.DirectorySeparatorChar + file);
                                            if (lines.Length > 0)
                                            {
                                                //pick a random line
                                                Random r = new Random();
                                                int line = r.Next(0, lines.Length - 1);
                                                changedData[count] = lines[line];
                                            }
                                            else
                                                changedData[count] = "$null";
                                        }
                                    }
                                }

                                if (connection != null)
                                {
                                    if (word.StartsWith("$ial(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        string nick = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        InternalAddressList ial = (InternalAddressList)connection.ServerSetting.IAL[nick];
                                        if (ial != null)
                                        {
                                            if (prop.Length == 0)
                                                changedData[count] = ial.Nick;
                                            else
                                            {
                                                switch (prop.ToLower())
                                                {
                                                    case "nick":
                                                        changedData[count] = ial.Nick;
                                                        break;
                                                    case "host":
                                                        changedData[count] = ial.Host;
                                                        break;
                                                }
                                            }
                                        }
                                        else
                                            changedData[count] = "$null";
                                    }

                                    if (word.StartsWith("$nick(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //get the value between and after the brackets
                                        string values = ReturnBracketValue(word);
                                        if (values.Split(',').Length == 2)
                                        {
                                            string channel = values.Split(',')[0];
                                            string nickvalue = values.Split(',')[1];

                                            string prop = ReturnPropertyValue(word);

                                            // $nick(#,N)
                                            //find then channel
                                            IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
                                            if (t != null)
                                            {
                                                User u = null;
                                                if (Int32.TryParse(nickvalue, out result))
                                                {
                                                    if (Convert.ToInt32(nickvalue) == 0)
                                                        changedData[count] = t.Nicks.Count.ToString();
                                                    else
                                                        u = t.GetNick(Convert.ToInt32(nickvalue));
                                                }
                                                else
                                                {
                                                    u = t.GetNick(nickvalue);
                                                }

                                                if (prop.Length == 0 && u != null)
                                                {
                                                    changedData[count] = u.NickName;
                                                }
                                                else if (u != null)
                                                {
                                                    //$nick(#channel,1).op , .voice, .halfop, .admin,.owner.
                                                    //.mode, .host, .nick,.ident
                                                    InternalAddressList ial = (InternalAddressList)connection.ServerSetting.IAL[u.NickName];
                                                    switch (prop.ToLower())
                                                    {
                                                        case "host":
                                                            if (ial != null && ial.Host != null && ial.Host.Length > 0)
                                                                changedData[count] = ial.Host.Substring(ial.Host.IndexOf('@') + 1);
                                                            break;
                                                        case "ident":
                                                            if (ial != null && ial.Host != null && ial.Host.Length > 0)
                                                                changedData[count] = ial.Host.Substring(0,ial.Host.IndexOf('@'));
                                                            break;
                                                        case "nick":
                                                            changedData[count] = u.NickName;
                                                            break;
                                                        case "mode":
                                                            changedData[count] = u.ToString().Replace(u.NickName, "");
                                                            break;
                                                        case "op":
                                                            for (int i = 0; i < u.Level.Length; i++)
                                                            {
                                                                if (connection.ServerSetting.StatusModes[0][i] == 'o')
                                                                {
                                                                    if (u.Level[i] == true)
                                                                        changedData[count] = "$true";
                                                                    else
                                                                        changedData[count] = "$false";
                                                                }
                                                            }
                                                            break;
                                                        case "voice":
                                                            for (int i = 0; i < u.Level.Length; i++)
                                                            {
                                                                if (connection.ServerSetting.StatusModes[0][i] == 'v')
                                                                {
                                                                    if (u.Level[i] == true)
                                                                        changedData[count] = "$true";
                                                                    else
                                                                        changedData[count] = "$false";
                                                                }
                                                            }
                                                            break;
                                                    }
                                                    ial = null;
                                                }
                                            }
                                        }
                                    }

                                    if (word.StartsWith("$chan(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //get the value between and after the brackets
                                        string channel = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        //find then channel
                                        IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
                                        if (t != null)
                                        {
                                            if (prop.Length == 0)
                                            {
                                                //replace with channel name
                                                changedData[count] = t.TabCaption;
                                            }
                                            else
                                            {
                                                switch (prop.ToLower())
                                                {
                                                    case "mode":
                                                        changedData[count] = t.ChannelModes;
                                                        break;
                                                    case "count":
                                                        changedData[count] = t.Nicks.Count.ToString();
                                                        break;
                                                    default:
                                                        break;
                                                }
                                            }
                                        }
                                    }

                                    if (word.StartsWith("$timer(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //get the value between and after the brackets
                                        string timerid = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        //find the timer
                                        foreach (IrcTimer timer in connection.IRCTimers)
                                        {
                                            if (timer.TimerID == timerid)
                                            {
                                                if (prop.Length == 0)
                                                {
                                                    //replace with timer id
                                                    changedData[count] = timer.TimerID;
                                                }
                                                else
                                                {
                                                    switch (prop.ToLower())
                                                    {
                                                        case "id":
                                                            changedData[count] = timer.TimerID;
                                                            break;
                                                        case "reps":
                                                            changedData[count] = timer.TimerRepetitions.ToString();
                                                            break;
                                                        case "count":
                                                            changedData[count] = timer.TimerCounter.ToString();
                                                            break;
                                                        case "command":
                                                            changedData[count] = timer.TimerCommand;
                                                            break;
                                                        case "interval":
                                                            changedData[count] = timer.TimerInterval.ToString();
                                                            break;
                                                        default:
                                                            break;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (word.StartsWith("$mask(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //$mask($host,2)
                                        //get the value between and after the brackets
                                        string values = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        if (values.Split(',').Length == 2)
                                        {
                                            string full_host = values.Split(',')[0];
                                            string mask_value = values.Split(',')[1];

                                            if (full_host.Length == 0) break;
                                            if (mask_value.Length == 0) break;

                                            if (full_host.IndexOf("@") == -1) break;
                                            if (full_host.IndexOf("!") == -1) break;

                                            switch (mask_value)
                                            {
                                                case "0":   // *!user@host
                                                    changedData[count] = "*!" + full_host.Substring(full_host.IndexOf("!") + 1);
                                                    break;

                                                case "1":   // *!*user@host
                                                    changedData[count] = "*!*" + full_host.Substring(full_host.IndexOf("!") + 1);
                                                    break;

                                                case "2":   // *!*user@*.host
                                                    changedData[count] = "*!*" + full_host.Substring(full_host.IndexOf("@"));
                                                    break;

                                                case "3":   // *!*user@*.host
                                                    break;

                                                case "4":   // *!*@*.host
                                                    break;

                                                case "5":   // nick!user@host
                                                    changedData[count] = full_host;
                                                    break;

                                                case "6":   // nick!*user@host
                                                    break;

                                                case "7":   // nick!*@host
                                                    break;

                                                case "8":   // nick!*user@*.host
                                                    break;

                                                case "9":   // nick!*@*.host
                                                    break;

                                                case "10":  // nick!*@*
                                                    changedData[count] = full_host.Substring(0, full_host.IndexOf("!")) + "!*@*";
                                                    break;

                                                case "11":  // *!user@*
                                                    break;
                                            }

                                        }

                                    }

                                }
                                break;
                        }

                    }

                }
            }
            catch (Exception e)
            {
                WriteErrorFile(connection, "ParseIdentifiers" + data, e);
            }
            //return String.Join(" ", changedData);
            return JoinString(changedData);
        }
コード例 #3
0
ファイル: FormMain.cs プロジェクト: nicholatian/monody
        private void searchForNetworksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InputBoxDialog i = new InputBoxDialog();
            i.FormCaption = "Search IRC Networks";
            i.FormPrompt = "Enter the IRC Network to search for.";

            i.ShowDialog();
            if (i.InputResponse.Length > 0)
            {
                //output to an @search
                searchNetworks(i.InputResponse);
            }

            i.Dispose();
        }
コード例 #4
0
ファイル: FormMain.cs プロジェクト: nicholatian/monody
        // IRC Indexer Service
        private void searchForChannelsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //use ircindexer.net
            //http://ircindexer.net/indexerapi.php?search=

            InputBoxDialog i = new InputBoxDialog();
            i.FormCaption = "Search Channels";
            i.FormPrompt = "Enter the channel to search for.";

            i.ShowDialog();
            if (i.InputResponse.Length > 0)
            {
                //output to an @search
                searchChannels(i.InputResponse);
            }

            i.Dispose();
        }
コード例 #5
0
ファイル: FormMain.cs プロジェクト: nicholatian/monody
        /// <summary>
        /// Parse out $identifiers for outgoing commands
        /// </summary>
        /// <param name="connection">Which Connection it is for</param>
        /// <param name="data">The data to be parsed</param>
        /// <returns></returns>
        private string ParseIdentifiers(IRCConnection connection, string data, string dataPassed)
        {
            string[] changedData = null;

            try
            {
                //parse the initial identifiers
                data = ParseIdentifier(connection, data);

                //parse out the $1,$2.. identifiers
                data = ParseIdentifierValue(data, dataPassed);

                //$+ is a joiner identifier, great for joining 2 words together
                data = data.Replace(" $+ ", string.Empty);

                //parse out the current channel #
                if (CurrentWindowStyle == IceTabPage.WindowType.Channel)
                {
                    data = data.Replace(" # ", " " + CurrentWindow.TabCaption + " ");
                }

                //split up the data into words
                string[] parsedData = data.Split(' ');

                //the data that was passed for parsing identifiers
                string[] passedData = dataPassed.Split(' ');

                //will hold the updates message/data after identifiers are parsed
                changedData = data.Split(' ');

                int count = -1;
                string extra = "";
                bool askExtra = false;
                bool askSecure = false;

                foreach (string word in parsedData)
                {
                    count++;

                    if (word.StartsWith("//") && count == 0)
                        changedData[count] = word.Substring(1);

                    if (askExtra)
                    {
                        //continueing a $?=
                        extra += " " + word;
                        changedData[count] = null;
                        if (extra[extra.Length - 1] == extra[0])
                        {
                            askExtra = false;
                            //ask the question
                            InputBoxDialog i = new InputBoxDialog();
                            i.PasswordChar = askSecure;
                            i.FormCaption = "Enter Value";
                            i.FormPrompt = extra.Substring(1,extra.Length-2);

                            i.ShowDialog();
                            if (i.InputResponse.Length > 0)
                                changedData[count] = i.InputResponse;
                            i.Dispose();
                        }
                    }

                    //parse out identifiers (start with a $)
                    if (word.StartsWith("$"))
                    {
                        switch (word)
                        {

                            default:
                                int result;
                                if (word.StartsWith("$?=") && word.Length > 5)
                                {
                                    //check for 2 quotes (single or double)
                                    string ask = word.Substring(3);
                                    //check what kind of a quote it is
                                    char quote = ask[0];
                                    if (quote == ask[ask.Length - 1])
                                    {
                                        //ask the question
                                        extra = ask;
                                        InputBoxDialog i = new InputBoxDialog();
                                        i.FormCaption = "Enter Value";
                                        i.FormPrompt = extra.Substring(1, extra.Length - 2);

                                        i.ShowDialog();
                                        if (i.InputResponse.Length > 0)
                                            changedData[count] = i.InputResponse;
                                        else
                                            changedData[count] = null;
                                        i.Dispose();
                                    }
                                    else
                                    {
                                        //go to the next word until we find a quote at the end
                                        extra = ask;
                                        askExtra = true;
                                        changedData[count] = null;
                                    }
                                }

                                //check for $?*="" // password char
                                if (word.StartsWith("$?*=") && word.Length > 6)
                                {
                                    //check for 2 quotes (single or double)
                                    string ask = word.Substring(4);
                                    //check what kind of a quote it is
                                    char quote = ask[0];
                                    if (quote == ask[ask.Length - 1])
                                    {
                                        //ask the question
                                        extra = ask;
                                        InputBoxDialog i = new InputBoxDialog();
                                        i.PasswordChar = true;
                                        i.FormCaption = "Enter Value";
                                        i.FormPrompt = extra.Substring(1, extra.Length - 2);

                                        i.ShowDialog();
                                        if (i.InputResponse.Length > 0)
                                            changedData[count] = i.InputResponse;
                                        else
                                            changedData[count] = null;
                                        i.Dispose();
                                    }
                                    else
                                    {
                                        //go to the next word until we find a quote at the end
                                        extra = ask;
                                        askExtra = true;
                                        askSecure = true;
                                        changedData[count] = null;
                                    }
                                }

                                if (word.StartsWith("$md5(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    string input = ReturnBracketValue(word);
                                    changedData[count] = MD5(input);
                                }

                                if (word.StartsWith("$net(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    string input = ReturnBracketValue(word);
                                    try
                                    {
                                        // //echo $net(System.Environment.CurrentDirectory)
                                        string[] thevalue = input.Split('.');
                                        if (thevalue.Length > 1)
                                        {
                                            string Class = String.Join(".", thevalue, 0, thevalue.Length - 1);
                                            string value = input.Substring(Class.Length + 1);
                                            //System.Diagnostics.Debug.WriteLine(Class + "::" + value);
                                            if (Class.Length > 0)
                                            {
                                                //Type.GetType(string for the type).GetProperty(n ame of the property).GetValue(null)
                                                Type t = Type.GetType(Class);

                                                PropertyInfo info = t.GetProperty(value);
                                                if (info != null)
                                                {
                                                    //System.Diagnostics.Debug.WriteLine("name=" +info.Name + ":" + info.GetValue(t, null));
                                                    changedData[count] = info.GetValue(t, null).ToString();
                                                }
                                                else
                                                {
                                                    //System.Diagnostics.Debug.WriteLine("null info");
                                                    changedData[count] = "$null";
                                                }

                                                //System.Diagnostics.Debug.WriteLine(t.ToString());
                                            }
                                            else
                                                changedData[count] = "$null";
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        changedData[count] = "$null";
                                    }
                                }

                                if (word.StartsWith("$rand(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    string input = ReturnBracketValue(word);
                                    //look for a comma (,)
                                    if (input.Split(',').Length == 2)
                                    {
                                        string lownum = input.Split(',')[0];
                                        string hinum = input.Split(',')[1];

                                        int lowNum, hiNum;
                                        if (Int32.TryParse(lownum, out lowNum) && Int32.TryParse(hinum, out hiNum))
                                        {
                                            //valid numbers
                                            Random r = new Random();
                                            int randNumber = r.Next(lowNum, hiNum);

                                            changedData[count] = randNumber.ToString();
                                        }
                                        else
                                            changedData[count] = "$null";
                                        Variable v = new Variable();

                                    }
                                    else if (input.IndexOf(',') == -1)
                                    {
                                        //make it a value from 1 - value
                                        int hiNum;
                                        if (Int32.TryParse(input, out hiNum))
                                        {
                                            //valid number
                                            Random r = new Random();
                                            int randNumber = r.Next(1, hiNum);

                                            changedData[count]= randNumber.ToString();
                                        }
                                        else
                                            changedData[count] = "$null";

                                    }
                                    else
                                        changedData[count] = "$null";
                                }

                                if (word.StartsWith("$read(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    string file = ReturnBracketValue(word);
                                    //check if we have passed a path or just a filename
                                    if (file.IndexOf(System.IO.Path.DirectorySeparatorChar) > -1)
                                    {
                                        //its a full folder
                                        if (File.Exists(file))
                                        {
                                            //count the number of lines in the file
                                            //load the file in and read a random line from it
                                            string[] lines = File.ReadAllLines(file);
                                            if (lines.Length > 0)
                                            {
                                                //pick a random line
                                                Random r = new Random();
                                                int line = r.Next(0, lines.Length - 1);
                                                changedData[count] = lines[line];
                                            }
                                            else
                                                changedData[count] = "$null";

                                        }
                                        else
                                        {
                                            changedData[count] = "$null";
                                        }
                                    }
                                    else
                                    {
                                        //just check in the Scripts Folder
                                        if (File.Exists(scriptsFolder + System.IO.Path.DirectorySeparatorChar + file))
                                        {
                                            //load the file in and read a random line from it
                                            string[] lines = File.ReadAllLines(scriptsFolder + System.IO.Path.DirectorySeparatorChar + file);
                                            if (lines.Length > 0)
                                            {
                                                //pick a random line
                                                Random r = new Random();
                                                int line = r.Next(0, lines.Length - 1);
                                                changedData[count] = lines[line];
                                            }
                                            else
                                                changedData[count] = "$null";
                                        }
                                        else
                                        {
                                            changedData[count] = "$null";
                                        }
                                    }
                                }

                                if (word.StartsWith("$var(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    //get the value between and after the brackets
                                    string variable = ReturnBracketValue(word);
                                    string prop = ReturnPropertyValue(word);

                                    System.Diagnostics.Debug.WriteLine(variable);
                                    //check if we have a connection or not
                                    if (connection == null)
                                    {
                                        changedData[count] = _variables.ReturnValue(variable).ToString();

                                    }
                                }

                                if (word.StartsWith("$plugin(") && word.IndexOf(')') > word.IndexOf('('))
                                {
                                    //get the plugin information
                                    string pluginid = ReturnBracketValue(word);
                                    string prop = ReturnPropertyValue(word);

                                    //tryparse
                                    if (Int32.TryParse(pluginid, out result))
                                    {
                                        for (int i = 0; i < loadedPlugins.Count; i++)
                                        {
                                            if (i == result)
                                            {
                                                IPluginIceChat ipc = ((IceChatPlugin)loadedPlugins[i]).plugin;

                                                switch (prop.ToLower())
                                                {
                                                    case "id":
                                                        changedData[count] = i.ToString();
                                                        break;
                                                    case "name":
                                                        changedData[count] = ipc.Name;
                                                        break;
                                                    case "version":
                                                        changedData[count] = ipc.Version;
                                                        break;
                                                    case "author":
                                                        changedData[count] = ipc.Author;
                                                        break;
                                                    case "enabled":
                                                        changedData[count] = ipc.Enabled.ToString();
                                                        break;
                                                    case "filename":
                                                        changedData[count] = ipc.FileName;
                                                        break;
                                                    default:
                                                        changedData[count] = ipc.Name;
                                                        break;
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //go by plugin filename, not number
                                        for (int i = 0; i < loadedPlugins.Count; i++)
                                        {
                                            if (((IceChatPlugin)loadedPlugins[i]).plugin.FileName.ToLower() == pluginid.ToLower())
                                            {
                                                IPluginIceChat ipc = ((IceChatPlugin)loadedPlugins[i]).plugin;

                                                switch (prop.ToLower())
                                                {
                                                    case "id":
                                                        changedData[count] = i.ToString();
                                                        break;
                                                    case "name":
                                                        changedData[count] = ipc.Name;
                                                        break;
                                                    case "version":
                                                        changedData[count] = ipc.Version;
                                                        break;
                                                    case "author":
                                                        changedData[count] = ipc.Author;
                                                        break;
                                                    case "enabled":
                                                        changedData[count] = ipc.Enabled.ToString();
                                                        break;
                                                    case "filename":
                                                        changedData[count] = ipc.FileName;
                                                        break;
                                                    default:
                                                        changedData[count] = ipc.Name;
                                                        break;
                                                }
                                            }
                                        }
                                    }
                                }

                                if (connection != null)
                                {
                                    if (word.StartsWith("$ial(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        string nick = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        InternalAddressList ial = (InternalAddressList)connection.ServerSetting.IAL[nick];
                                        if (ial != null)
                                        {
                                            if (prop.Length == 0)
                                                changedData[count] = ial.Nick;
                                            else
                                            {
                                                switch (prop.ToLower())
                                                {
                                                    case "nick":
                                                        changedData[count] = ial.Nick;
                                                        break;
                                                    case "host":
                                                        changedData[count] = ial.Host;
                                                        break;
                                                }
                                            }
                                        }
                                        else
                                            changedData[count] = "$null";
                                    }

                                    if (word.StartsWith("$nick(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //get the value between and after the brackets
                                        string values = ReturnBracketValue(word);
                                        if (values.Split(',').Length == 2)
                                        {
                                            string channel = values.Split(',')[0];
                                            string nickvalue = values.Split(',')[1];

                                            string prop = ReturnPropertyValue(word);

                                            // $nick(#,N)
                                            //find then channel
                                            IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
                                            if (t != null)
                                            {
                                                User u = null;
                                                if (Int32.TryParse(nickvalue, out result))
                                                {
                                                    if (Convert.ToInt32(nickvalue) == 0)
                                                        changedData[count] = t.Nicks.Count.ToString();
                                                    else
                                                        u = t.GetNick(Convert.ToInt32(nickvalue));
                                                }
                                                else
                                                {
                                                    u = t.GetNick(nickvalue);
                                                }

                                                if (prop.Length == 0 && u != null)
                                                {
                                                    changedData[count] = u.NickName;
                                                }
                                                else if (u != null)
                                                {
                                                    //$nick(#channel,1).op , .voice, .halfop, .admin,.owner.
                                                    //.mode, .host, .nick,.ident
                                                    InternalAddressList ial = (InternalAddressList)connection.ServerSetting.IAL[u.NickName];
                                                    switch (prop.ToLower())
                                                    {
                                                        case "host":
                                                            if (ial != null && ial.Host != null && ial.Host.Length > 0)
                                                                changedData[count] = ial.Host.Substring(ial.Host.IndexOf('@') + 1);
                                                            break;
                                                        case "ident":
                                                            if (ial != null && ial.Host != null && ial.Host.Length > 0)
                                                                changedData[count] = ial.Host.Substring(0,ial.Host.IndexOf('@'));
                                                            break;
                                                        case "nick":
                                                            changedData[count] = u.NickName;
                                                            break;
                                                        case "mode":
                                                            changedData[count] = u.ToString().Replace(u.NickName, "");
                                                            break;
                                                        case "op":
                                                            for (int i = 0; i < u.Level.Length; i++)
                                                            {
                                                                if (connection.ServerSetting.StatusModes[0][i] == 'o')
                                                                {
                                                                    if (u.Level[i] == true)
                                                                        changedData[count] = "$true";
                                                                    else
                                                                        changedData[count] = "$false";
                                                                }
                                                            }
                                                            break;
                                                        case "halfop":
                                                            for (int i = 0; i < u.Level.Length; i++)
                                                            {
                                                                if (connection.ServerSetting.StatusModes[0][i] == 'h')
                                                                {
                                                                    if (u.Level[i] == true)
                                                                        changedData[count] = "$true";
                                                                    else
                                                                        changedData[count] = "$false";
                                                                }
                                                            }
                                                            break;
                                                        case "voice":
                                                            for (int i = 0; i < u.Level.Length; i++)
                                                            {
                                                                if (connection.ServerSetting.StatusModes[0][i] == 'v')
                                                                {
                                                                    if (u.Level[i] == true)
                                                                        changedData[count] = "$true";
                                                                    else
                                                                        changedData[count] = "$false";
                                                                }
                                                            }
                                                            break;
                                                    }
                                                    ial = null;
                                                }
                                            }
                                        }
                                    }

                                    if (word.StartsWith("$chan(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //get the value between and after the brackets
                                        string channel = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        //find then channel
                                        IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
                                        if (t != null)
                                        {
                                            if (prop.Length == 0)
                                            {
                                                //replace with channel name
                                                changedData[count] = t.TabCaption;
                                            }
                                            else
                                            {
                                                switch (prop.ToLower())
                                                {
                                                    case "mode":
                                                        changedData[count] = t.ChannelModes;
                                                        break;
                                                    case "count":
                                                        changedData[count] = t.Nicks.Count.ToString();
                                                        break;
                                                    case "nicks":
                                                        //return all the nicks seperated by a space
                                                        string nicks = "";
                                                        foreach (string n in t.Nicks.Keys)
                                                            nicks += n + " ";
                                                        changedData[count] = nicks.Trim();
                                                        break;
                                                    case "log":
                                                        changedData[count] = t.TextWindow.LogFileName;
                                                        break;
                                                    default:
                                                        break;
                                                }
                                            }
                                        }
                                    }
                                    if (word.StartsWith("$timer(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //get the value between and after the brackets
                                        string timerid = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        //find the timer
                                        foreach (IrcTimer timer in connection.IRCTimers)
                                        {
                                            if (timer.TimerID == timerid)
                                            {
                                                if (prop.Length == 0)
                                                {
                                                    //replace with timer id
                                                    changedData[count] = timer.TimerID;
                                                }
                                                else
                                                {
                                                    switch (prop.ToLower())
                                                    {
                                                        case "id":
                                                            changedData[count] = timer.TimerID;
                                                            break;
                                                        case "reps":
                                                            changedData[count] = timer.TimerRepetitions.ToString();
                                                            break;
                                                        case "count":
                                                            changedData[count] = timer.TimerCounter.ToString();
                                                            break;
                                                        case "command":
                                                            changedData[count] = timer.TimerCommand;
                                                            break;
                                                        case "interval":
                                                            changedData[count] = timer.TimerInterval.ToString();
                                                            break;
                                                        default:
                                                            break;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (word.StartsWith("$mask(") && word.IndexOf(')') > word.IndexOf('('))
                                    {
                                        //$mask($host,2)
                                        //get the value between and after the brackets
                                        string values = ReturnBracketValue(word);
                                        string prop = ReturnPropertyValue(word);

                                        if (values.Split(',').Length == 2)
                                        {
                                            string full_host = values.Split(',')[0];
                                            string mask_value = values.Split(',')[1];

                                            if (full_host.Length == 0) break;
                                            if (mask_value.Length == 0) break;

                                            if (full_host.IndexOf("@") == -1) break;
                                            if (full_host.IndexOf("!") == -1) break;

                                            switch (mask_value)
                                            {
                                                case "0":   // *!user@host
                                                    changedData[count] = "*!" + full_host.Substring(full_host.IndexOf("!") + 1);
                                                    break;

                                                case "1":   // *!*user@host
                                                    changedData[count] = "*!*" + full_host.Substring(full_host.IndexOf("!") + 1);
                                                    break;

                                                case "2":   // *!*user@*.host
                                                    changedData[count] = "*!*" + full_host.Substring(full_host.IndexOf("@"));
                                                    break;

                                                case "3":   // *!*user@*.host
                                                    break;

                                                case "4":   // *!*@*.host
                                                    break;

                                                case "5":   // nick!user@host
                                                    changedData[count] = full_host;
                                                    break;

                                                case "6":   // nick!*user@host
                                                    break;

                                                case "7":   // nick!*@host
                                                    break;

                                                case "8":   // nick!*user@*.host
                                                    break;

                                                case "9":   // nick!*@*.host
                                                    break;

                                                case "10":  // nick!*@*
                                                    changedData[count] = full_host.Substring(0, full_host.IndexOf("!")) + "!*@*";
                                                    break;

                                                case "11":  // *!user@*
                                                    break;
                                            }

                                        }

                                    }

                                }
                                break;
                        }

                    }

                }
            }
            catch (Exception e)
            {
                WriteErrorFile(connection, "ParseIdentifiers" + data, e);
            }
            //return String.Join(" ", changedData);
            return JoinString(changedData);
        }
コード例 #6
0
ファイル: FormMain.cs プロジェクト: nicholatian/monody
        public FormMain(string[] args, Form splash)
        {
            FormMain.Instance = this;

            System.Diagnostics.FileVersionInfo fv = System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
            BuildNumber = fv.FileVersion;

            if (StaticMethods.IsRunningOnMono())
                player = new System.Media.SoundPlayer();
            else
                mp3Player = new MP3Player();

            bool forceCurrentFolder = false;
            errorMessages = new List<string>();

            _variables = new Variables();
            _globalTimers = new List<IrcTimer>();

            if (args.Length > 0)
            {
                string prevArg = "";
                foreach (string arg in args)
                {
                    if (prevArg.Length == 0)
                    {
                        prevArg = arg;
                        if (arg.ToLower().StartsWith("irc://"))
                        {
                            //parse out the server name and channel name
                            string server = arg.Substring(6).TrimEnd();
                            if (server.IndexOf("/") != -1)
                            {
                                string host = server.Split('/')[0];
                                string channel = server.Split('/')[1];
                                if (channel.StartsWith("#"))
                                    autoStartCommand = "/joinserv " + host + " " + channel;
                                else
                                    autoStartCommand = "/joinserv " + host + " #" + channel;

                            }
                            else
                                autoStartCommand = "/server " + arg.Substring(6).TrimEnd();

                        }
                        if (arg.ToLower() == "-disableauto")
                        {
                            disableAutoStart = true;
                        }
                    }
                    else
                    {
                        switch (prevArg.ToLower())
                        {
                            case "-profile":
                                currentFolder = arg;
                                //check if the folder exists, ir not, create it
                                if (!Directory.Exists(currentFolder))
                                    Directory.CreateDirectory(currentFolder);

                                forceCurrentFolder = true;
                                break;
                            case "-disableauto":
                                disableAutoStart = true;
                                break;
                        }

                        prevArg = "";
                    }
                }
            }

            //mutex = new System.Threading.Mutex(true, "IceChatMutex");

            #region Settings Files

            //check if the xml settings files exist in current folder
            if (currentFolder == null)
                currentFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            //check for IceChatPackage.xml in Assembly Folder

            if (File.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPackage.xml"))
            {
                //read the package file
                //create the IceChatServer.xml file from the package, if it doesnt exist

                serversFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Settings" + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml";
                optionsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Settings" + System.IO.Path.DirectorySeparatorChar + "IceChatOptions.xml";

                if (!File.Exists(serversFile))
                {
                    if (!Directory.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "Settings"))
                        Directory.CreateDirectory(currentFolder + System.IO.Path.DirectorySeparatorChar + "Settings");

                    //ask for a Default Nickname
                    InputBoxDialog i = new InputBoxDialog();
                    i.FormCaption = "Enter Default Nickname";
                    i.FormPrompt = "Please enter your Nick name";

                    i.ShowDialog();
                    if (i.InputResponse.Length > 0)
                    {
                        //changedData[count] = i.InputResponse;

                        System.Diagnostics.Debug.WriteLine("Package Exists - Create Defaults");
                        XmlSerializer deserializer = new XmlSerializer(typeof(IceChatPackage));
                        TextReader textReader = new StreamReader(currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPackage.xml");
                        IceChatPackage package = (IceChatPackage)deserializer.Deserialize(textReader);
                        textReader.Close();
                        textReader.Dispose();

                        IceChatServers servers = new IceChatServers();
                        foreach (ServerSetting s in package.Servers)
                        {
                            s.NickName = i.InputResponse;
                            s.AltNickName = s.NickName + "_";
                            s.AwayNickName = s.NickName + "[A]";

                            servers.AddServer(s);
                        }

                        //save the server(s) to IceChatServer.xml
                        XmlSerializer serializer = new XmlSerializer(typeof(IceChatServers));
                        TextWriter textWriter = new StreamWriter(serversFile);
                        serializer.Serialize(textWriter, servers);
                        textWriter.Close();
                        textWriter.Dispose();

                        servers.listServers.Clear();
                        serializer = null;
                        textWriter = null;

                        //load the options and save
                        IceChatOptions options = package.Options;

                        serializer = new XmlSerializer(typeof(IceChatOptions));
                        textWriter = new StreamWriter(optionsFile);
                        serializer.Serialize(textWriter, options);
                        textWriter.Close();
                        textWriter.Dispose();

                        currentFolder += System.IO.Path.DirectorySeparatorChar + "Settings";

                    }
                    i.Dispose();

                    //change the currentFolder
                }
            }
            //check for Settings/IceChatServer.xml
            if (File.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "Settings" + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml"))
            {
                currentFolder += System.IO.Path.DirectorySeparatorChar + "Settings";
            }
            else if (!File.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml") && !forceCurrentFolder)
            {
                if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "Monody Networks" + Path.DirectorySeparatorChar + "Monody"))
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "Monody Networks" + Path.DirectorySeparatorChar + "Monody");

                currentFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "Monody Networks" + Path.DirectorySeparatorChar + "Monody";
            }

            //load all files from the Local AppData folder, unless it exist in the current folder
            serversFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml";
            optionsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatOptions.xml";
            messagesFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatMessages.xml";
            fontsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatFonts.xml";
            colorsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatColors.xml";
            soundsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatSounds.xml";
            favoriteChannelsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatChannels.xml";
            aliasesFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatAliases.xml";
            popupsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPopups.xml";
            pluginsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPlugins.xml";
            emoticonsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Emoticons" + System.IO.Path.DirectorySeparatorChar + "IceChatEmoticons.xml";
            channelSettingsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "ChannelSetting.xml";
            colorPaletteFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "ColorPalette.xml";

            //set a new logs folder
            logsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Logs";
            scriptsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Scripts";
            soundsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Sounds";
            picturesFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Pictures";

            pluginsFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + System.IO.Path.DirectorySeparatorChar + "Plugins";

            if (!Directory.Exists(pluginsFolder))
                Directory.CreateDirectory(pluginsFolder);

            if (!Directory.Exists(scriptsFolder))
                Directory.CreateDirectory(scriptsFolder);

            if (!Directory.Exists(soundsFolder))
                Directory.CreateDirectory(soundsFolder);

            if (!Directory.Exists(picturesFolder))
                Directory.CreateDirectory(picturesFolder);

            if (!Directory.Exists(currentFolder + Path.DirectorySeparatorChar + "Update"))
                Directory.CreateDirectory(currentFolder + Path.DirectorySeparatorChar + "Update");

            #endregion

            languageFiles = new List<LanguageItem>();

            DirectoryInfo languageDirectory = null;

            languageDirectory = new DirectoryInfo(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages");
            if (!Directory.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages"))
                Directory.CreateDirectory(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages");

            if (languageDirectory != null)
            {
                // scan the language directory for xml files and make LanguageItems for each file
                FileInfo[] langFiles = languageDirectory.GetFiles("*.xml");
                foreach (FileInfo fi in langFiles)
                {
                    string langFile = languageDirectory.FullName + System.IO.Path.DirectorySeparatorChar + fi.Name;
                    LanguageItem languageItem = LoadLanguageItem(langFile);
                    if (languageItem != null) languageFiles.Add(languageItem);
                }

                if (languageFiles.Count == 0)
                {
                    currentLanguageFile = new LanguageItem();
                    languageFiles.Add(currentLanguageFile);     // default language English
                }
            }

            //load the color palette
            LoadColorPalette();

            LoadOptions();
            LoadColors();
            LoadSounds();

            // use the language saved in options if available,
            // if not (e.g. user deleted xml file) default is used
            foreach (LanguageItem li in languageFiles)
            {
                if (li.LanguageName == iceChatOptions.Language)
                {
                    currentLanguageFile = li;
                    break;
                }
            }

            LoadLanguage(); // The language class MUST be loaded before any GUI component is created

            //set the new log folder
            if (iceChatOptions.LogFolder.Length > 0)
            {
                logsFolder = iceChatOptions.LogFolder;
            }
            else
            {
                iceChatOptions.LogFolder = logsFolder;
            }

            //check if we have any servers/settings saved, if not, load firstrun
            if (!File.Exists(serversFile))
            {
                FormFirstRun firstRun = new FormFirstRun(currentFolder);
                firstRun.SaveOptions += new FormFirstRun.SaveOptionsDelegate(FirstRunSaveOptions);
                firstRun.ShowDialog(this);
            }

            InitializeComponent();

            //load icons from Embedded Resources or Pictures Image
            this.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
            if (iceChatOptions.SystemTrayIcon == null || iceChatOptions.SystemTrayIcon.Trim().Length == 0)
            {
                this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
            }
            else
            {
                //make sure the image exists and is an ICO file
                if (File.Exists(iceChatOptions.SystemTrayIcon))
                    this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(iceChatOptions.SystemTrayIcon);
                else
                    this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
            }
            //this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
            this.notifyIcon.Visible = iceChatOptions.ShowSytemTrayIcon;

            //disable this by default
            this.toolStripUpdate.Visible = false;
            this.updateAvailableToolStripMenuItem1.Visible = false;

            serverListToolStripMenuItem.Checked = iceChatOptions.ShowServerTree;
            panelDockLeft.Visible = serverListToolStripMenuItem.Checked;
            splitterLeft.Visible = serverListToolStripMenuItem.Checked;

            nickListToolStripMenuItem.Checked = iceChatOptions.ShowNickList;
            panelDockRight.Visible = nickListToolStripMenuItem.Checked;
            panelDockRight.TabControl.Alignment = TabAlignment.Right;
            splitterRight.Visible = nickListToolStripMenuItem.Checked;

            statusBarToolStripMenuItem.Checked = iceChatOptions.ShowStatusBar;
            statusStripMain.Visible = statusBarToolStripMenuItem.Checked;

            toolBarToolStripMenuItem.Checked = iceChatOptions.ShowToolBar;
            toolStripMain.Visible = toolBarToolStripMenuItem.Checked;

            viewChannelBarToolStripMenuItem.Checked = iceChatOptions.ShowTabBar;
            mainChannelBar.Visible = iceChatOptions.ShowTabBar;
            mainChannelBar.SingleRow = iceChatOptions.SingleRowTabBar;

            this.Text = ProgramID + " " + VersionID;

            //this can be customized
            if (iceChatOptions.SystemTrayText == null || iceChatOptions.SystemTrayText.Trim().Length == 0)
                this.notifyIcon.Text = ProgramID + " " + VersionID;
            else
                this.notifyIcon.Text = iceChatOptions.SystemTrayText;

            if (!Directory.Exists(logsFolder))
                Directory.CreateDirectory(logsFolder);

            try
            {
                errorFile = new StreamWriter(logsFolder + System.IO.Path.DirectorySeparatorChar + "errors.log", true);
            }
            catch (IOException io)
            {
                System.Diagnostics.Debug.WriteLine("Can not create errors.log:" + io.Message);
            }
            catch (Exception eo)
            {
                System.Diagnostics.Debug.WriteLine("Can not create errors.log:" + eo.Message);
            }

            if (iceChatOptions.WindowSize != null)
            {
                if (iceChatOptions.WindowSize.Width > 100 && iceChatOptions.WindowSize.Height > 100)
                {
                    this.Size = iceChatOptions.WindowSize;
                    this.WindowState = iceChatOptions.WindowState;
                }
                else
                {
                    this.Width = Screen.PrimaryScreen.WorkingArea.Width;
                    this.Height = Screen.PrimaryScreen.WorkingArea.Height;
                }
            }
            else
            {
                this.Width = Screen.PrimaryScreen.WorkingArea.Width;
                this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            }

            if (iceChatOptions.WindowLocation != null)
            {
                //check if the location is valid, could try and place it on a 2nd screen that no longer exists
                if (Screen.AllScreens.Length == 1)
                {
                   if (Screen.PrimaryScreen.Bounds.Contains(iceChatOptions.WindowLocation))
                        this.Location = iceChatOptions.WindowLocation;

                }
                else
                {
                    //check if we are in the bounds of the screen location
                    foreach (Screen screen in Screen.AllScreens)
                        if (screen.Bounds.Contains(iceChatOptions.WindowLocation))
                            this.Location = iceChatOptions.WindowLocation;
                }
            }

            statusStripMain.Visible = iceChatOptions.ShowStatusBar;

            LoadAliases();
            LoadPopups();
            LoadEmoticons();
            LoadMessageFormat();
            LoadFonts();

            bool fileThemeFound = true;

            if (iceChatOptions.CurrentTheme == null)
            {
                iceChatOptions.CurrentTheme = "Default";
                defaultToolStripMenuItem.Checked = true;

                //reload all the theme files

            }
            else
            {
                //load in the new color theme, if it not Default
                if (iceChatOptions.CurrentTheme != "Default")
                {
                    string themeFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Colors-" + iceChatOptions.CurrentTheme + ".xml";
                    if (File.Exists(themeFile))
                    {
                        XmlSerializer deserializer = new XmlSerializer(typeof(IceChatColors));
                        TextReader textReader = new StreamReader(themeFile);
                        iceChatColors = (IceChatColors)deserializer.Deserialize(textReader);
                        textReader.Close();
                        textReader.Dispose();

                        colorsFile = themeFile;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Color Theme File not found:" + themeFile);
                        fileThemeFound = false;
                    }

                    themeFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Messages-" + iceChatOptions.CurrentTheme + ".xml";
                    if (File.Exists(themeFile))
                    {
                        XmlSerializer deserializer = new XmlSerializer(typeof(IceChatMessageFormat));
                        TextReader textReader = new StreamReader(themeFile);
                        iceChatMessages = (IceChatMessageFormat)deserializer.Deserialize(textReader);
                        textReader.Close();
                        textReader.Dispose();

                        messagesFile = themeFile;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Messages Theme File not found:" + themeFile);
                        fileThemeFound = false;
                    }
                }
                else
                    defaultToolStripMenuItem.Checked = true;

            }

            if (iceChatOptions.Theme == null)
            {
                defaultToolStripMenuItem.Checked = true;
                iceChatOptions.CurrentTheme = "Default";

                DirectoryInfo _currentFolder = new DirectoryInfo(currentFolder);
                FileInfo[] xmlFiles = _currentFolder.GetFiles("*.xml");

                int totalThemes = 1;
                foreach (FileInfo fi in xmlFiles)
                {
                    if (fi.Name.StartsWith("Colors-"))
                    {
                        totalThemes++;
                    }
                }

                iceChatOptions.Theme = new ThemeItem[totalThemes];

                iceChatOptions.Theme[0] = new ThemeItem();
                iceChatOptions.Theme[0].ThemeName = "Default";
                iceChatOptions.Theme[0].ThemeType = "XML";

                int t = 1;
                foreach (FileInfo fi in xmlFiles)
                {
                    if (fi.Name.StartsWith("Colors-"))
                    {
                        string themeName = fi.Name.Replace("Colors-", "").Replace(".xml", ""); ;
                        iceChatOptions.Theme[t] = new ThemeItem();
                        iceChatOptions.Theme[t].ThemeName = themeName;
                        iceChatOptions.Theme[t].ThemeType = "XML";
                        t++;
                    }
                }
            }

            channelList = new ChannelList(this);
            channelList.Dock = DockStyle.Fill;
            buddyList = new BuddyList(this);
            buddyList.Dock = DockStyle.Fill;

            toolStripMain.BackColor = IrcColor.colors[iceChatColors.ToolbarBackColor];
            statusStripMain.BackColor = IrcColor.colors[iceChatColors.StatusbarBackColor];
            toolStripStatus.ForeColor = IrcColor.colors[iceChatColors.StatusbarForeColor];
            menuMainStrip.BackColor = IrcColor.colors[iceChatColors.MenubarBackColor];

            inputPanel.SetInputBoxColors();
            channelList.SetListColors();
            buddyList.SetListColors();
            serverTree.SetListColors();
            nickList.SetListColors();

            this.nickList.Header = iceChatLanguage.consoleTabTitle;

            nickListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
            nickListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];

            serverListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
            serverListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];

            channelListTab = new TabPage("Favorite Channels");
            Panel channelPanel = new Panel();
            channelPanel.Dock = DockStyle.Fill;
            channelPanel.Controls.Add(channelList);
            channelListTab.Controls.Add(channelPanel);
            channelListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
            channelListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];

            buddyListTab = new TabPage("Buddy List");
            Panel buddyPanel = new Panel();
            buddyPanel.Dock = DockStyle.Fill;
            buddyPanel.Controls.Add(buddyList);
            buddyListTab.Controls.Add(buddyPanel);
            buddyListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
            buddyListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];

            panelDockLeft.Width = iceChatOptions.LeftPanelWidth;
            panelDockRight.Width = iceChatOptions.RightPanelWidth;

            //Load the panel items in order
            if (iceChatOptions.LeftPanels != null)
            {
                foreach (string arrayitem in iceChatOptions.LeftPanels)
                {
                    if (arrayitem == serverListTab.Text)
                        this.panelDockLeft.TabControl.TabPages.Add(serverListTab);
                    else if (arrayitem == channelListTab.Text)
                        this.panelDockLeft.TabControl.TabPages.Add(channelListTab);
                    else if (arrayitem == nickListTab.Text)
                        this.panelDockLeft.TabControl.TabPages.Add(nickListTab);
                    else if (arrayitem == buddyListTab.Text)
                        this.panelDockLeft.TabControl.TabPages.Add(buddyListTab);
                }
            }
            if (iceChatOptions.RightPanels != null)
            {
                foreach (string arrayitem in iceChatOptions.RightPanels)
                {
                    if (arrayitem == serverListTab.Text)
                        this.panelDockRight.TabControl.TabPages.Add(serverListTab);
                    else if (arrayitem == nickListTab.Text)
                        this.panelDockRight.TabControl.TabPages.Add(nickListTab);
                    else if (arrayitem == channelListTab.Text)
                        this.panelDockRight.TabControl.TabPages.Add(channelListTab);
                    else if (arrayitem == buddyListTab.Text)
                        this.panelDockRight.TabControl.TabPages.Add(buddyListTab);
                }
            }

            //If any panels are missing
            if (!panelDockLeft.TabControl.TabPages.Contains(serverListTab) && !panelDockRight.TabControl.TabPages.Contains(serverListTab))
                this.panelDockLeft.TabControl.TabPages.Add(serverListTab);
            if (!panelDockLeft.TabControl.TabPages.Contains(nickListTab) && !panelDockRight.TabControl.TabPages.Contains(nickListTab))
                this.panelDockRight.TabControl.TabPages.Add(nickListTab);
            if (!panelDockLeft.TabControl.TabPages.Contains(channelListTab) && !panelDockRight.TabControl.TabPages.Contains(channelListTab))
                this.panelDockRight.TabControl.TabPages.Add(channelListTab);
            if (!panelDockLeft.TabControl.TabPages.Contains(buddyListTab) && !panelDockRight.TabControl.TabPages.Contains(buddyListTab))
                this.panelDockRight.TabControl.TabPages.Add(buddyListTab);

            this.MinimumSize = new Size(panelDockLeft.Width + panelDockRight.Width + 300, 300);

            //hide the left or right panel if it is empty
            if (panelDockLeft.TabControl.TabPages.Count == 0)
            {
                this.splitterLeft.Visible = false;
                panelDockLeft.Visible = false;
                this.MinimumSize = new Size(panelDockRight.Width + 300, 300);
            }
            if (panelDockRight.TabControl.TabPages.Count == 0)
            {
                this.splitterRight.Visible = false;
                panelDockRight.Visible = false;
                if (panelDockLeft.Visible)
                    this.MinimumSize = new Size(panelDockLeft.Width + 300, 300);
                else
                    this.MinimumSize = new Size(300, 300);
            }

            if (iceChatOptions.LockWindowSize)
            {
                fixWindowSizeToolStripMenuItem.Checked = true;
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
            }

            nickList.Font = new Font(iceChatFonts.FontSettings[3].FontName, iceChatFonts.FontSettings[3].FontSize);
            serverTree.Font = new Font(iceChatFonts.FontSettings[4].FontName, iceChatFonts.FontSettings[4].FontSize);
            mainChannelBar.TabFont = new Font(iceChatFonts.FontSettings[8].FontName, iceChatFonts.FontSettings[8].FontSize);
            menuMainStrip.Font = new Font(iceChatFonts.FontSettings[7].FontName, iceChatFonts.FontSettings[7].FontSize);
            toolStripMain.Font = new Font(iceChatFonts.FontSettings[7].FontName, iceChatFonts.FontSettings[7].FontSize);

            inputPanel.OnCommand +=new InputPanel.OnCommandDelegate(inputPanel_OnCommand);
            inputPanel.InputBoxFont = new Font(iceChatFonts.FontSettings[5].FontName, iceChatFonts.FontSettings[5].FontSize);

            inputPanel.ShowColorPicker = iceChatOptions.ShowColorPicker;
            inputPanel.ShowEmoticonPicker = iceChatOptions.ShowEmoticonPicker;
            inputPanel.ShowBasicCommands = iceChatOptions.ShowBasicCommands;
            inputPanel.ShowSendButton = iceChatOptions.ShowSendButton;

            inputPanel.ShowWideTextPanel = iceChatOptions.ShowMultilineEditbox;

            if (iceChatOptions.ShowEmoticons == false)
                inputPanel.ShowEmoticonPicker = false;

            mainChannelBar.OnTabClosed += new ChannelBar.TabClosedDelegate(OnTabClosed);
            mainChannelBar.SelectedIndexChanged += new ChannelBar.TabEventHandler(OnTabSelectedIndexChanged);

            panelDockLeft.Initialize();
            panelDockRight.Initialize();

            if (iceChatOptions.DockLeftPanel == true)
                panelDockLeft.DockControl();

            if (iceChatOptions.DockRightPanel == true)
                panelDockRight.DockControl();

            LoadChannelSettings();

            CreateDefaultConsoleWindow();

            //****
            WindowMessage(null, "Console", "\x000304Data Folder: " + currentFolder, "", true);
            WindowMessage(null, "Console", "\x000304Plugins Folder: " + pluginsFolder, "", true);
            WindowMessage(null, "Console", "\x000304Logs Folder: " + logsFolder, "", true);

            serverTree.NewServerConnection += new NewServerConnectionDelegate(NewServerConnection);
            serverTree.SaveDefault += new ServerTree.SaveDefaultDelegate(OnDefaultServerSettings);

            loadedPluginThemes = new List<IThemeIceChat>();
            loadedPlugins = new List<Plugin>();

            //load the plugin settings file
            LoadPluginFiles();

            //load any plugin addons
            LoadPlugins();

            //****
            WindowMessage(null, "Console", "\x00034Using Theme - " + iceChatOptions.CurrentTheme, "", true);

            //set any plugins as disabled
            //add any items to the pluginsFile if they do not exist, or remove any that do not

            foreach (Plugin p in loadedPlugins)
            {
                IceChatPlugin ipc = p as IceChatPlugin;
                if (ipc != null)
                {
                    bool found = false;
                    for (int i = 0; i < iceChatPlugins.listPlugins.Count; i++)
                    {
                        if (iceChatPlugins.listPlugins[i].PluginFile.Equals(ipc.plugin.FileName))
                        {
                            found = true;

                            if (iceChatPlugins.listPlugins[i].Enabled == false)
                            {
                                WindowMessage(null, "Console", "\x000304Disabled Plugin - " + ipc.plugin.Name + " v" + ipc.plugin.Version, "", true);

                                foreach (ToolStripMenuItem t in pluginsToolStripMenuItem.DropDownItems)
                                    if (t.ToolTipText.ToLower() == ipc.plugin.FileName.ToLower())
                                        t.Image = StaticMethods.LoadResourceImage("CloseButton.png");

                                ipc.plugin.Enabled = false;
                            }

                        }
                    }
                    if (found == false)
                    {
                        //plugin file not found in plugin Items file, add it
                        PluginItem item = new PluginItem();
                        item.Enabled = true;
                        item.PluginFile = ipc.plugin.FileName;
                        iceChatPlugins.AddPlugin(item);
                        SavePluginFiles();
                    }
                }
            }

            if (iceChatPlugins.listPlugins.Count != loadedPlugins.Count)
            {
                //find the file that is missing
                List<int> removeItems = new List<int>();
                for (int i = 0; i < iceChatPlugins.listPlugins.Count; i++)
                {
                    bool found = false;
                    foreach (Plugin p in loadedPlugins)
                    {
                        IceChatPlugin ipc = p as IceChatPlugin;
                        if (ipc != null)
                        {

                            if (iceChatPlugins.listPlugins[i].PluginFile.Equals(ipc.plugin.FileName))
                                found = true;
                        }
                    }

                    if (found == false)
                        removeItems.Add(i);
                }

                if (removeItems.Count > 0)
                {
                    try
                    {
                        foreach (int i in removeItems)
                            iceChatPlugins.listPlugins.Remove(iceChatPlugins.listPlugins[i]);
                    }
                    catch { }

                    SavePluginFiles();
                }
            }

            //initialize each of the plugins on its own thread
            foreach (Plugin p in loadedPlugins)
            {
                IceChatPlugin ipc = p as IceChatPlugin;
                if (ipc != null)
                {
                    if (ipc.plugin.Enabled == true)
                    {
                        System.Threading.Thread initPlugin = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(InitializePlugin));
                        initPlugin.Start(ipc.plugin);
                    }
                }
            }

            foreach (string s in errorMessages)
            {
                WindowMessage(null, "Console", "\x000304Error: " + s,"", true);
            }
            errorMessages.Clear();

            pluginsToolStripMenuItem.DropDownOpening += new EventHandler(pluginsToolStripMenuItem_DropDownOpening);

            if (fileThemeFound == false)
            {
                //check for the Plugin File theme
                foreach (IThemeIceChat theme in IceChatPluginThemes)
                {
                    if (theme.Name == iceChatOptions.CurrentTheme)
                    {
                        //update, this is the match
                        iceChatColors.ChannelAdminColor = theme.ChannelAdminColor;
                        iceChatColors.ChannelBackColor = theme.ChannelBackColor;
                        iceChatColors.ChannelHalfOpColor = theme.ChannelHalfOpColor;
                        iceChatColors.ChannelJoinColorChange = theme.ChannelJoinColorChange;
                        iceChatColors.ChannelListBackColor = theme.ChannelListBackColor;
                        iceChatColors.ChannelListForeColor = theme.ChannelListForeColor;
                        iceChatColors.ChannelOpColor = theme.ChannelOpColor;
                        iceChatColors.ChannelOwnerColor = theme.ChannelOwnerColor;
                        iceChatColors.ChannelPartColorChange = theme.ChannelPartColorChange;
                        iceChatColors.ChannelRegularColor = theme.ChannelRegularColor;
                        iceChatColors.ChannelVoiceColor = theme.ChannelVoiceColor;
                        iceChatColors.ConsoleBackColor = theme.ConsoleBackColor;
                        iceChatColors.InputboxBackColor = theme.InputboxBackColor;
                        iceChatColors.InputboxForeColor = theme.InputboxForeColor;
                        iceChatColors.MenubarBackColor = theme.MenubarBackColor;
                        iceChatColors.NewMessageColorChange = theme.NewMessageColorChange;
                        iceChatColors.NickListBackColor = theme.NickListBackColor;
                        iceChatColors.OtherMessageColorChange = theme.OtherMessageColorChange;
                        iceChatColors.PanelHeaderBG1 = theme.PanelHeaderBG1;
                        iceChatColors.PanelHeaderBG2 = theme.PanelHeaderBG2;
                        iceChatColors.PanelHeaderForeColor = theme.PanelHeaderForeColor;
                        iceChatColors.QueryBackColor = theme.QueryBackColor;
                        iceChatColors.RandomizeNickColors = theme.RandomizeNickColors;
                        iceChatColors.ServerListBackColor = theme.ServerListBackColor;
                        iceChatColors.ServerMessageColorChange = theme.ServerMessageColorChange;
                        iceChatColors.ServerQuitColorChange = theme.ServerQuitColorChange;
                        iceChatColors.StatusbarBackColor = theme.StatusbarBackColor;
                        iceChatColors.StatusbarForeColor = theme.StatusbarForeColor;
                        iceChatColors.TabBarChannelJoin = theme.TabBarChannelJoin;
                        iceChatColors.TabBarChannelPart = theme.TabBarChannelPart;
                        iceChatColors.TabBarCurrent = theme.TabBarCurrent;
                        iceChatColors.TabBarDefault = theme.TabBarDefault;
                        iceChatColors.TabBarNewMessage = theme.TabBarNewMessage;
                        iceChatColors.TabBarOtherMessage = theme.TabBarOtherMessage;
                        iceChatColors.TabBarServerMessage = theme.TabBarServerMessage;
                        iceChatColors.TabBarServerQuit = theme.TabBarServerQuit;
                        iceChatColors.ToolbarBackColor = theme.ToolbarBackColor;
                        iceChatColors.UnreadTextMarkerColor = theme.UnreadTextMarkerColor;

                        inputPanel.SetInputBoxColors();

                        toolStripMain.BackColor = IrcColor.colors[iceChatColors.ToolbarBackColor];
                        menuMainStrip.BackColor = IrcColor.colors[iceChatColors.MenubarBackColor];
                        statusStripMain.BackColor = IrcColor.colors[iceChatColors.StatusbarBackColor];
                        toolStripStatus.ForeColor = IrcColor.colors[iceChatColors.StatusbarForeColor];

                        serverListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
                        serverListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
                        nickListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
                        nickListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
                        channelListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
                        channelListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
                        buddyListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
                        buddyListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];

                        inputPanel.SetInputBoxColors();
                        channelList.SetListColors();
                        buddyList.SetListColors();
                        nickList.SetListColors();
                        serverTree.SetListColors();

                        nickList.Invalidate();
                        mainChannelBar.Invalidate();
                        serverTree.Invalidate();
                    }
                }
            }

            //add the themes to the view menu
            if (iceChatOptions.Theme != null)
            {
                foreach (ThemeItem theme in iceChatOptions.Theme)
                {
                    if (!theme.ThemeName.Equals("Default"))
                    {
                        ToolStripMenuItem t = new ToolStripMenuItem(theme.ThemeName);
                        if (iceChatOptions.CurrentTheme == theme.ThemeName)
                            t.Checked = true;

                        t.Click += new EventHandler(themeChoice_Click);
                        themesToolStripMenuItem.DropDownItems.Add(t);
                    }
                }
            }

            this.FormClosing += new FormClosingEventHandler(FormMainClosing);
            this.Resize += new EventHandler(FormMainResize);

            if (iceChatOptions.IdentServer && !System.Diagnostics.Debugger.IsAttached)
                identServer = new IdentServer();

            if (iceChatLanguage.LanguageName != "English") ApplyLanguage(); // ApplyLanguage can first be called after all child controls are created

            //get a new router ip
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                if (iceChatOptions.DCCAutogetRouterIP == true)
                {
                    System.Threading.Thread dccThread = new System.Threading.Thread(getLocalIPAddress);
                    dccThread.Name = "DCCIPAutoUpdate";
                    dccThread.Start();
                }
            }

            splash.Close();
            splash.Dispose();

            this.Activated += new EventHandler(FormMainActivated);

            nickList.ShowNickButtons = iceChatOptions.ShowNickButtons;
            serverTree.ShowServerButtons = iceChatOptions.ShowServerButtons;

            showButtonsNickListToolStripMenuItem.Checked = iceChatOptions.ShowNickButtons;
            showButtonsServerTreeToolStripMenuItem1.Checked = iceChatOptions.ShowServerButtons;

            // check for background images for nicklist and server tree
            if (iceChatOptions.NickListImage != null && iceChatOptions.NickListImage.Length > 0)
            {
                if (File.Exists(picturesFolder + System.IO.Path.DirectorySeparatorChar + iceChatOptions.NickListImage))
                    this.nickList.BackGroundImage = picturesFolder + System.IO.Path.DirectorySeparatorChar + iceChatOptions.NickListImage;
                else if (File.Exists(iceChatOptions.NickListImage))
                    this.nickList.BackGroundImage = iceChatOptions.NickListImage;

            }
            if (iceChatOptions.ServerTreeImage != null && iceChatOptions.ServerTreeImage.Length > 0)
            {
                if (File.Exists(picturesFolder + System.IO.Path.DirectorySeparatorChar + iceChatOptions.ServerTreeImage))
                    this.serverTree.BackGroundImage = picturesFolder + System.IO.Path.DirectorySeparatorChar + iceChatOptions.ServerTreeImage;
                else if (File.Exists(iceChatOptions.NickListImage))
                    this.serverTree.BackGroundImage = iceChatOptions.ServerTreeImage;
            }

            this.flashTrayIconTimer = new System.Timers.Timer(2000);
            this.flashTrayIconTimer.Enabled = false;
            this.flashTrayIconTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTrayIconTimer_Elapsed);
            this.notifyIcon.Tag = "off";
            this.flashTrayCount = 0;

            this.flashTaskBarIconTimer = new System.Timers.Timer(2000);
            this.flashTaskBarIconTimer.Enabled = false;
            this.flashTaskBarIconTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTaskBarIconTimer_Elapsed);
            this.Tag = "off";
            this.flashTrayCount = 0;

            //new toolstrip renderer for the main menu strip
            menuMainStrip.RenderMode = ToolStripRenderMode.System;
            toolStripMain.RenderMode = ToolStripRenderMode.System;

            //setup windowed mode if saved
            if (iceChatOptions.WindowedMode)
            {
                resizeWindowToolStripMenuItem.PerformClick();
            }

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                //check for an update and setup DDE, if NOT in debugger
                System.Threading.Thread checkThread = new System.Threading.Thread(checkForUpdate);
                checkThread.Start();
            }

            System.Diagnostics.Debug.WriteLine(mainChannelBar.Height + ":" + mainChannelBar.Location.Y + ":" + mainChannelBar.Visible + ":" + mainChannelBar.Parent.Name);

            foreach (string s in args)
            {
                if (s.IndexOf(' ') > -1)
                    _args += " \"" + s + "\"";
                else
                    _args += " " + s;
            }
        }