Esempio n. 1
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            if (Irc.ChannelList.ServerLog == null)
            {
                await Irc.AddChannel("Server");
            }

            if (parsedLine.PrefixMessage.IsUser && parsedLine.PrefixMessage.Nickname == Irc.Nickname)
            {
                Irc.Server.Username = parsedLine.TrailMessage.HasTrail ? parsedLine.TrailMessage.TrailingContent : Irc.Nickname;
            }
            else if (parsedLine.PrefixMessage.IsUser && parsedLine.TrailMessage.HasTrail)
            {
                var username = parsedLine.PrefixMessage.Nickname;
                foreach (var channel in Irc.ChannelList)
                {
                    var users = channel.Store;
                    if (users.HasUser(username))
                    {
                        var msg = new Message
                        {
                            Type = MessageType.JoinPart,
                            User = parsedLine.PrefixMessage.Nickname,
                            Text = string.Format("({0}) {1} {2}", parsedLine.PrefixMessage.Prefix, "changed nick to", parsedLine.TrailMessage.TrailingContent)
                        };
                        Irc.AddMessage(channel.Name, msg);

                        users.RemoveUser(username);
                        users.AddUser(parsedLine.TrailMessage.TrailingContent);
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        public override Task<bool> HandleLine(IrcMessage parsedLine)
        {
            var channel = parsedLine.TrailMessage.TrailingContent;
            if (parsedLine.PrefixMessage.Nickname == Irc.Server.Username)
            {
                Irc.RemoveChannel(channel);
            }
            else
            {
                if (parsedLine.CommandMessage.Parameters.Count > 0)
                {
                    channel = parsedLine.CommandMessage.Parameters[0];
                }

                var msg = new Message
                {
                    Type = MessageType.JoinPart,
                    User = parsedLine.PrefixMessage.Nickname,
                    Text = string.Format("({0}) {1}", parsedLine.PrefixMessage.Prefix, "left the channel")
                };

                Irc.AddMessage(channel, msg);

                Irc.ChannelList[channel].Store.RemoveUser(parsedLine.PrefixMessage.Nickname);
            }
            return Task.FromResult(true);
        }
Esempio n. 3
0
        public override Task <bool> HandleLine(IrcMessage parsedLine)
        {
            var cmd = parsedLine.CommandMessage.Command;

            if (cmd == "375")
            {
                _currentMOTD = parsedLine.TrailMessage.TrailingContent + "\r\n";
            }

            if (cmd == "372")
            {
                _currentMOTD += parsedLine.TrailMessage.TrailingContent + "\r\n";
            }

            if (cmd == "376" || cmd == "422")
            {
                _currentMOTD += parsedLine.TrailMessage.TrailingContent;

                var msg = new Message
                {
                    Text = _currentMOTD,
                    Type = MessageType.MOTD
                };
                Irc.AddMessage("", msg);

                Irc.MOTD     = _currentMOTD;
                _currentMOTD = "";
            }

            return(Task.FromResult(true));
        }
Esempio n. 4
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            // handle messages to this irc client
            var destination = parsedLine.CommandMessage.Parameters[0];
            var reciever    = parsedLine.CommandMessage.Parameters[1];
            var content     = parsedLine.TrailMessage.TrailingContent;

            if (!Irc.ChannelList.Contains(destination))
            {
                await Irc.AddChannel(destination);
            }

            var msg = new Message();

            msg.Type = MessageType.Info;

            if (reciever == Irc.Server.Username)
            {
                msg.User = parsedLine.PrefixMessage.Nickname;
                msg.Text = "kicked you from the channel: " + content;
            }
            else
            {
                msg.User = parsedLine.PrefixMessage.Nickname;
                msg.Text = string.Format("kicked {0} from the channel: {1}", reciever, content);
            }

            Irc.AddMessage(destination, msg);

            return(true);
        }
Esempio n. 5
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            var channel = parsedLine.TrailMessage.TrailingContent;

            if (parsedLine.PrefixMessage.Nickname == Irc.Server.Username)
            {
                await Irc.AddChannel(channel);
            }

            if (parsedLine.CommandMessage.Parameters != null)
            {
                channel = parsedLine.CommandMessage.Parameters[0];
            }

            var msg = new Message
            {
                Type = MessageType.JoinPart,
                User = parsedLine.PrefixMessage.Nickname,
                Text = string.Format("({0}) {1}", parsedLine.PrefixMessage.Prefix, "joined the channel")
            };

            Irc.AddMessage(channel, msg);

            Irc.ChannelList[channel].Store.AddUser(parsedLine.PrefixMessage.Nickname);
            return(true);
        }
Esempio n. 6
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            // handle topic recieved
            var topic      = parsedLine.TrailMessage.TrailingContent;
            var channelPos = (parsedLine.CommandMessage.Command == "332") ? 1 : 0;
            var channel    = parsedLine.CommandMessage.Parameters[channelPos];

            if (!Irc.ChannelList.Contains(channel))
            {
                await Irc.AddChannel(channel);
            }

            var msg = new Message();

            msg.Type = MessageType.Info;

            msg.User = "";
            msg.Text = string.Format("Topic for channel {0}: {1}", channel, topic);
            Irc.AddMessage(channel, msg);
            Irc.ChannelList[channel].Store.Topic = topic;
            return(true);
        }
Esempio n. 7
0
        public override Task <bool> HandleLine(IrcMessage parsedLine)
        {
            var cmd = parsedLine.CommandMessage.Command;

            if (_currentWhois == "")
            {
                _currentWhois += "Whois for " + parsedLine.CommandMessage.Parameters[1] + ": \r\n";
            }

            var whoisLine = "";

            if (cmd == "330")
            {
                whoisLine     += parsedLine.CommandMessage.Parameters[1] + " " + parsedLine.TrailMessage.TrailingContent + " " + parsedLine.CommandMessage.Parameters[2] + " ";
                _currentWhois += whoisLine + "\r\n";
            }
            else
            {
                for (var i = 2; i < parsedLine.CommandMessage.Parameters.Count; i++)
                {
                    whoisLine += parsedLine.CommandMessage.Command + " " + parsedLine.CommandMessage.Parameters[i] + " ";
                }
                _currentWhois += whoisLine + parsedLine.TrailMessage.TrailingContent + "\r\n";
            }

            if (cmd == "318")
            {
                var msg = new Message();
                msg.Text = _currentWhois;
                msg.Type = MessageType.Info;
                Irc.AddMessage(Irc.WhoisDestination, msg);

                _currentWhois        = "";
                Irc.WhoisDestination = "";
            }

            return(Task.FromResult(true));
        }
Esempio n. 8
0
        public override Task <bool> HandleLine(IrcMessage parsedLine)
        {
            var username = parsedLine.PrefixMessage.Nickname;

            foreach (var channel in Irc.ChannelList)
            {
                var users = channel.Store;
                if (users.HasUser(username))
                {
                    var msg = new Message
                    {
                        Type = MessageType.JoinPart,
                        User = parsedLine.PrefixMessage.Nickname,
                        Text = string.Format("({0}) {1}: {2}", parsedLine.PrefixMessage.Prefix, "quit the server",
                                             parsedLine.TrailMessage.TrailingContent)
                    };
                    Irc.AddMessage(channel.Name, msg);

                    users.RemoveUser(username);
                }
            }

            return(Task.FromResult(true));
        }
Esempio n. 9
0
        public override async Task <bool> HandleLine(IrcMessage parsedLine)
        {
            // handle messages to this irc client
            var destination = parsedLine.CommandMessage.Parameters[0];
            var content     = parsedLine.TrailMessage.TrailingContent;

            if (content == "")
            {
                content = parsedLine.CommandMessage.Parameters.Last();
            }

            if (destination == Irc.Server.Username)
            {
                destination = parsedLine.PrefixMessage.Nickname;
            }

            var msg = new Message();

            msg.Channel = destination;
            msg.Type    = Type;
            msg.User    = parsedLine.PrefixMessage.Nickname ?? parsedLine.PrefixMessage.Prefix;

            if (destination.StartsWith("@#"))
            {
                msg.OpOnlyMessage = true;
                msg.Channel       = destination = destination.Substring(1);
            }

            if (msg.User == null)
            {
                msg.User = "";
            }

            if (parsedLine.Metadata.ContainsKey(IrcMessage.Time))
            {
                var time = DateTime.Parse(parsedLine.Metadata[IrcMessage.Time]);
                msg.Date = time;
            }

            if (parsedLine.Metadata.ContainsKey(IrcMessage.Id))
            {
                msg.MessageId = parsedLine.Metadata[IrcMessage.Id];
            }

            if (parsedLine.Metadata.ContainsKey(IrcMessage.Reply))
            {
                msg.ReplyTo = parsedLine.Metadata[IrcMessage.Reply];
            }

            if (content.Contains("ACTION"))
            {
                msg.Text = content.Replace("ACTION ", "");
                msg.Type = MessageType.Action;
            }
            else
            {
                msg.Text = content;
            }

            if ((parsedLine.TrailMessage.TrailingContent.Contains(Irc.Server.Username) || parsedLine.CommandMessage.Parameters[0] == Irc.Server.Username))
            {
                msg.Mention = true;
                Irc.AddMention(msg);
            }

            if (destination == "*")
            {
                Irc.ChannelList.ServerLog?.Buffers.Add(msg);
            }
            else
            {
                if (!Irc.ChannelList.Contains(destination))
                {
                    await Irc.AddChannel(destination);
                }

                Irc.AddMessage(destination, msg);

                if (Type == MessageType.Notice)
                {
                    Irc.InfoBuffer.Add(msg);
                }
            }
            return(true);
        }