Пример #1
0
        private void OnEvents(IrcConection connection, IrcMessage message)
        {
            this.channel1.Write(connection.GetIdentify(), "*", "", message.Raw);
            string channel;

            switch (message.Type)
            {
            case "JOIN":
                //Let us se if this is us there join a channel or it is a user
                if (message.Nick == connection.GetNick())
                {
                    channel = message.ParamsMidle;
                    this.AppendChannel(connection.GetIdentify(), channel);
                }
                else if (message.ParamsMidle.IndexOf("#") == 0)
                {
                    this.channel1.Write(connection.GetIdentify(), message.ParamsMidle, "", IrcUntil.ColoeredText(9, 0, message.Nick + " came into this room"));
                    UserInfo info = new UserInfo();
                    info.Nick = message.Nick;
                    this.channel1.AppendUser(connection.GetIdentify(), message.ParamsMidle, info);
                }
                break;

            case "PART":
                if (message.ParamsMidle == "")
                {
                    return;
                }
                channel = message.ParamsMidle.Substring(1);
                this.channel1.Write(connection.GetIdentify(), channel, "", IrcUntil.ColoeredText(4, 0, message.Nick + " leaved this channel"));
                this.channel1.RemoveUser(connection.GetIdentify(), message.ParamsMidle.Substring(1), message.Nick);
                break;

            case "PRIVMSG":
                if (message.ParamsMidle == connection.GetNick())
                {
                    //this is a private message from user (channel start width #) so wee controle we have the channel.
                    if (!this.ChannelExists(connection.GetIdentify(), message.Nick))
                    {
                        this.AppendChannel(connection.GetIdentify(), message.Nick);
                        this.channel1.Select(connection.GetIdentify(), message.Nick);
                    }
                }
                if (message.ParamsTrailing.IndexOf('\x001'.ToString()) == 0)
                {
                    if (message.ParamsTrailing.IndexOf('\x001'.ToString() + "ACTION") == 0)
                    {
                        this.channel1.Write(connection.GetIdentify(), message.ParamsTrailing == connection.GetNick() ? message.Nick : message.ParamsMidle, null, IrcUntil.ColoeredText(6, 0, "* " + message.Nick + " " + message.ParamsTrailing.Substring(8)));
                        return;
                    }
                }
                this.channel1.Write(connection.GetIdentify(), message.ParamsMidle == connection.GetNick() ? message.Nick : message.ParamsMidle, message.Nick, message.ParamsTrailing);
                break;

            case "NICK":
                string n = message.ParamsTrailing;
                if (n == connection.GetNick())
                {
                    //this is my there will or foreced to chage nick name.
                    connection.SetNick(n);
                }
                this.channel1.UpdateNick(connection.GetIdentify(), message.Nick, n);
                break;
            }
        }
Пример #2
0
        public void GetSendMessage(string message)
        {
            IrcConection connection = GetConnection(this.channel1.SelectedServer);

            if (connection == null)
            {
                return;
            }

            if (message.TrimStart().IndexOf("/") == 0)
            {
                int    space = message.IndexOf(' ');
                string command;
                if (space == -1)
                {
                    command = message.Substring(1).Trim();
                }
                else
                {
                    command = message.Substring(1, Math.Max(0, space - 1)).ToLower().Trim();
                }
                string[] param = space == -1 ? new string[0] : message.Substring(space + 1).Split(' ');
                switch (command)
                {
                case "me":
                    connection.SendLine("PRIVMSG " + this.channel1.SelectedChannel + " :\x0001ACTION " + message.Substring(4) + "\x0001");
                    connection.Flush();
                    this.channel1.Write(
                        this.channel1.SelectedServer,
                        this.channel1.SelectedChannel,
                        "",
                        IrcUntil.ColoeredText(6, 0, "* " + this.GetConnection(this.channel1.SelectedServer).GetNick() + " " + message.Substring(4))
                        );
                    break;

                case "join":
                    foreach (string c in param)
                    {
                        if (c.IndexOf("#") == 0)
                        {
                            connection.SendLine("JOIN " + c);
                        }
                    }
                    connection.Flush();
                    break;

                case "leave":
                    if (this.channel1.SelectedChannel == "*")
                    {
                        this.CloseConnection(this.channel1.SelectedServer);
                    }
                    else if (this.channel1.SelectedChannel.IndexOf("#") == 0)
                    {
                        this.CloseChannel(this.channel1.SelectedServer, this.channel1.SelectedChannel);
                    }
                    break;

                case "nick":
                    if (param.Length == 0)
                    {
                        return;
                    }
                    connection.SendLine("NICK " + param[0]);
                    connection.Flush();
                    break;

                case "query":
                    if (param.Length > 0)
                    {
                        if (param[0][0] == '#')
                        {
                            this.channel1.Write(IrcUntil.ColoeredText(IrcColorPlate.Red, IrcColorPlate.White, "You an not query a channel. Use /join"));
                        }
                        else
                        {
                            if (param.Length == 1)
                            {
                                this.AppendChannel(this.channel1.SelectedServer, param[0]);
                            }
                            else
                            {
                                StringBuilder query = new StringBuilder();
                                query.Append(param[1]);
                                for (int i = 2; i < param.Length; i++)
                                {
                                    query.Append(" " + param[i]);
                                }
                                this.AppendChannel(this.channel1.SelectedServer, param[0]);
                                this.GetSendMessage(query.ToString());
                            }
                        }
                    }
                    else
                    {
                        this.channel1.Write(IrcUntil.ColoeredText(IrcColorPlate.Red, IrcColorPlate.White, "You need to write to who"));
                    }
                    break;

                default:
                    command = command.ToUpper();
                    StringBuilder p = new StringBuilder();
                    for (int i = 0; i < param.Length; i++)
                    {
                        p.Append(" " + param[i]);
                    }
                    connection.SendLine(command + p.ToString());
                    connection.Flush();
                    break;
                }
            }
            else
            {
                if (this.channel1.SelectedChannel != "*")
                {
                    connection.SendLine("PRIVMSG " + this.channel1.SelectedChannel + " :" + message);
                    connection.Flush();
                    this.channel1.Write(this.channel1.SelectedServer, this.channel1.SelectedChannel, connection.GetNick(), message);
                }
                else
                {
                    this.channel1.Write(this.channel1.SelectedServer, "*", "", IrcUntil.ColoeredText(4, 0, "You can not send message in server windo"));
                }
            }
        }