Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nick"></param>
        /// <param name="server"></param>
        /// <param name="chan"></param>
        /// <param name="game"></param>
        /// <param name="mainWin"></param>
        /// <param name="identify"></param>
        /// <param name="pass">used to indetify with NickServ</param>
        /// <param name="bot">Name of NickServ bot</param>
        public SChatClient(String nick, String server, String chan, int game, MainWindow mainWin, bool identify, string pass, string bot)
        {
            mw                 = mainWin;
            this.nick          = nick;
            this.server        = server;
            this.chan          = chan;
            clientId           = game;
            identifyToNickServ = identify;
            userpass           = pass;
            nickservbot        = bot;
            ini                = new IniFile(System.IO.Path.Combine(Environment.CurrentDirectory, @"config.ini"));
            rnd                = new Random();

            users = new List <User>();
            try
            {
                firstRun = (Boolean.Parse(ini.IniReadValue("Settings", "firstrun")));
            }
            catch (FormatException e)
            {
                firstRun = false;
            }
            try
            {
                secondRun = (Boolean.Parse(ini.IniReadValue("Settings", "2ndrun")));
            }
            catch (FormatException e)
            {
                secondRun = false;
            }
            try
            {
                elnotif = (Boolean.Parse(ini.IniReadValue("Settings", "enterleave")));
            }
            catch (FormatException e)
            {
                elnotif = false;
            }
            cw = new SChatWindow(nick, chan, mw, this);
            sw = new SSettingsWindow(cw, this);
            sm = new SpawnMaster(nick, server, chan, cw.getBanner());
            DoConnect();
            if (firstRun)
            {
                cw.AddToChatWindow(8, null, sm.clientMsg[0]);
                ini.IniWriteValue("Settings", "2ndrun", true.ToString());
                ini.IniWriteValue("Settings", "firstrun", false.ToString());
            }
            if (secondRun)
            {
                cw.AddToChatWindow(8, null, sm.clientMsg[1]);
                ini.IniWriteValue("Settings", "2ndrun", false.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send messages and parse commands
        /// </summary>
        /// <param name="content"></param>
        public void Send(String content)
        {
            if (client != null && client.Connected && !String.IsNullOrEmpty(content))
            {
                /*
                 * COMMANDS
                 **/
                if (content.StartsWith("/"))
                {
                    /*
                     * EMOTE
                     **/
                    if ((content.StartsWith("/me ")) || (content.StartsWith("/emote ")))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        cw.AddToChatWindow(1, client.Nick, tempStrArray[1]);
                        if (chan != "The Void")
                        {
                            client.Emote(chan, tempStrArray[1]);
                        }
                        if (channelIsEmpty())
                        {
                            cw.AddToChatWindow(3, null, sm.clientMsg[5]);
                        }
                    }

                    /*
                     * WHISPER
                     **/
                    else if ((content.StartsWith("/w ")) || (content.StartsWith("/whisper ")) || (content.StartsWith("/msg ")) || (content.StartsWith("/m ")))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 3);
                        client.SendMessage(tempStrArray[1], tempStrArray[2]);
                        cw.AddToChatWindow(5, tempStrArray[1], tempStrArray[2]);
                    }

                    /*
                     * REPLY
                     **/
                    else if ((content.StartsWith("/r ")) || (content.StartsWith("/reply ")))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        client.SendMessage(lastWhisperer, tempStrArray[2]);
                        cw.AddToChatWindow(5, lastWhisperer, tempStrArray[2]);
                    }

                    /*
                     * JOIN
                     **/
                    else if ((content.StartsWith("/j ")) || (content.StartsWith("/join ")))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        content      = tempStrArray[1];
                        if (content.Equals("The Void", StringComparison.InvariantCultureIgnoreCase))
                        {
                            joinTheVoid(false);
                        }
                        else
                        {
                            joinChannel(content);
                        }
                    }

                    /*
                     * SQUELCH
                     **/
                    else if (content.StartsWith("/squelch ") || content.StartsWith("/ignore "))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        squelchUser(tempStrArray[1]);
                    }

                    /*
                     * UNSQUELCH
                     **/
                    else if (content.StartsWith("/unsquelch ") || content.StartsWith("/unignore "))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        unsquelchUser(tempStrArray[1]);
                    }

                    /*
                     * WHOIS
                     **/
                    else if (content.StartsWith("/whois ") || content.StartsWith("/where ") || content.StartsWith("/whereis "))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        client.SendRaw("WHOIS " + tempStrArray[1]);
                    }

                    /*
                     * WHOAMI
                     **/
                    else if (content.Equals("/whoami"))
                    {
                        client.SendRaw("WHOIS " + nick);
                    }

                    /*
                     * TIME
                     **/
                    else if (content.Equals("/time"))
                    {
                        client.SendRaw("TIME");
                        cw.AddToChatWindow(3, null, "Your local time: " + System.DateTime.Now.ToLocalTime());
                    }

                    /*
                     * WHO (Not Implemented)
                     *
                     * else if (content.StartsWith("/who "))
                     * {
                     *  tempStrArray = content.Split((new Char[] { ' ' }), 2);
                     *  client.SendRaw("NAMES " + tempStrArray[1]);
                     * }**/
                    /*
                     * USERS
                     **/
                    else if (content.Equals("/users"))
                    {
                        client.SendRaw("LUSERS");
                    }

                    /*
                     * AWAY
                     **/
                    else if (content.StartsWith("/away"))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        if (tempStrArray.Length > 1)
                        {
                            client.SendRaw("AWAY " + tempStrArray[1]);
                        }
                        else
                        {
                            client.SendRaw("AWAY");
                        }
                    }

                    /*
                     * DND
                     **/
                    else if (content.StartsWith("/dnd"))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 2);
                        if (tempStrArray.Length > 1)
                        {
                            dnd = true;
                            client.SendRaw("AWAY " + tempStrArray[1]);
                        }
                        else
                        {
                            dnd = false;
                            client.SendRaw("AWAY");
                        }
                    }

                    /*
                     * NICK
                     **/
                    else if (content.StartsWith("/nick "))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 3);
                        if (tempStrArray[1].Length > 15)
                        {
                            tempStrArray[1] = tempStrArray[1].Substring(0, 15);
                        }
                        client.SendRaw("NICK " + tempStrArray[1]);
                        client.Nick = tempStrArray[1];
                        nick        = tempStrArray[1];
                        sm.nick     = tempStrArray[1];
                        cw.nick     = tempStrArray[1];
                    }

                    /**
                     * REJOIN
                     **/
                    else if (content.StartsWith("/rejoin"))
                    {
                        join(chan.Substring(1));
                    }

                    /*
                     * KICK
                     **/
                    else if (content.StartsWith("/kick ") || content.StartsWith("/ban "))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 3);
                        if (validateOpAction(tempStrArray[1]))
                        {
                            if (content.StartsWith("/ban "))
                            {
                                client.SendRaw("MODE " + chan + " +b " + tempStrArray[1]);
                                suppresskickmsg = true;
                            }
                            else
                            {
                                suppresskickmsg = false;
                            }
                            if (tempStrArray.Length > 2)     //kick message provided
                            {
                                client.Kick(chan, tempStrArray[1], tempStrArray[2]);
                            }
                            else
                            {
                                client.Kick(chan, tempStrArray[1], null);
                            }
                        }
                    }

                    /*
                     * UNBAN
                     **/
                    else if (content.StartsWith("/unban "))
                    {
                        tempStrArray = content.Split((new Char[] { ' ' }), 3);
                        client.SendRaw("MODE " + chan + " -b " + tempStrArray[1]);
                    }

                    /*
                     * IGNOREPERSIST
                     **/
                    else if (content.StartsWith("/ignorepersist"))
                    {
                        sm.toggleIgnore();
                        cw.AddToChatWindow(3, null, sm.clientMsg[13]);
                    }

                    /*
                     * DISCONNECT
                     **/
                    else if (content.StartsWith("/disconnect") || content.StartsWith("/dc"))
                    {
                        DoDisconnect();
                        cw.AddToChatWindow(3, null, "Connection closed.");
                    }

                    /*
                     * RECONNECT
                     **/
                    else if (content.StartsWith("/reconnect") || content.StartsWith("/rc"))
                    {
                        DoDisconnect();
                        DoConnect();
                    }

                    /*
                     * ANYTHING ELSE
                     **/
                    else
                    {
                        cw.AddToChatWindow(7, null, sm.clientMsg[12]);
                    }
                }
                else //Regular message
                {
                    cw.AddToChatWindow(4, client.Nick, content);
                    if (chan != "The Void")
                    {
                        client.SendMessage(chan, content);

                        if (channelIsEmpty())
                        {
                            cw.AddToChatWindow(3, null, sm.clientMsg[5]);
                        }
                    }
                }
            }
            else if ((client == null || !client.Connected) && !String.IsNullOrEmpty(content))
            {
                /*
                 * RECONNECT
                 **/
                if (content.StartsWith("/reconnect") || content.StartsWith("/rc"))
                {
                    DoDisconnect();
                    DoConnect();
                }
                else
                {
                    cw.AddToChatWindow(7, null, "You are not connected.");
                }
            }
        }