Пример #1
0
        public void AppendChannel(string identify, string channel)
        {
            this.channel1.CreateChannel(identify, channel);

            this.AppendNodeChannel(identify, channel);

            if (channel.IndexOf("#") == 0)
            {
                this.channel1.Write(identify, channel, "", "You joined the channel");
            }

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


            IrcConection connection = this.GetConnection(identify);

            if (connection.scriptAction.ContainsKey("channel.open"))
            {
                connection.DoAction("channel.open", EcmaValue.String(channel).ToObject(connection.script.State));
            }
        }
Пример #2
0
        private void OpenConnection(string identify, string host, int port, string nick, string[] channels)
        {
            IrcConection connection = new IrcConection(this, identify, host, port, nick, channels);

            connection.SetEventListener(OnEvents);
            this.channel1.CreateServer(identify, nick);
            this.treeView1.BeginUpdate();
            TreeNode node = this.treeView1.Nodes.Add(identify);

            this.Nodes.Add(identify, node);
            this.treeView1.EndUpdate();
            this.treeView1.SelectedNode = node;
            this.connections.Add(connection);
            connection.Connect();
        }
Пример #3
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);
        }
Пример #4
0
        public bool CloseConnection(string identify)
        {
            IrcConection connection = this.GetConnection(identify);

            if (connection == null)
            {
                return(false);
            }

            connection.Close();
            this.Nodes[identify].Remove();
            this.channel1.RemoveServer(identify);
            if (this.channel1.SelectedServer == identify)
            {
                string ns = this.channel1.GetTopServer();
                if (ns == null)
                {
                    //this.OpenNewServerDialog();
                    return(true);
                }
                this.channel1.Select(ns, "*");
            }
            return(true);
        }
Пример #5
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;
            }
        }
Пример #6
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"));
                }
            }
        }