示例#1
0
        public bool CloseChannel(string identify, string name)
        {
            if (!this.channel1.RemoveChannel(identify, name))
            {
                return(false);
            }

            if (name.IndexOf("#") == 0)
            {
                IrcConection connection = this.GetConnection(identify);
                connection.SendLine("PART " + name);
                connection.Flush();

                if (this.ScriptClient.HasProperty("onSelfPart"))
                {
                    EcmaHeadObject callable = this.ScriptClient.Get("onSelfPart").ToObject(this.Client.State);
                    if (callable is ICallable)
                    {
                        (callable as ICallable).Call(this.ScriptClient, new EcmaValue[]
                        {
                            EcmaValue.String(identify),
                            EcmaValue.String(name)
                        });
                    }
                }
            }

            foreach (TreeNode n in this.Nodes[identify].Nodes)
            {
                if (n.Text == name)
                {
                    n.Remove();
                    break;
                }
            }


            if (this.channel1.SelectedServer == identify && this.channel1.SelectedChannel == name)
            {
                this.channel1.Select(this.channel1.SelectedServer, this.channel1.GetTopChannel(identify));
            }
            return(true);
        }
示例#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"));
                }
            }
        }