Beispiel #1
0
        public IRCMessage(string p_message)
        {
            rawMessage = p_message;

            if (rawMessage.StartsWith("PING "))
            {
                messageType   = "PING";
                messageString = rawMessage.Split(' ')[1].TrimStart(':');
            }
            else
            {
                messageList = rawMessage.Split(' ').ToList <string>();

                messageType = messageList[1];

                if (messageList[0].Contains('!'))
                {
                    string[] userArray = messageList[0].Split('!');
                    User.Name = userArray[0].TrimStart(':');
                    string[] userHostArray = userArray[1].Split('@');
                    User.User     = userHostArray[0];
                    User.Hostmask = userHostArray[1];
                }
                else
                {
                    User.Name     = messageList[0].TrimStart(':');
                    User.User     = "";
                    User.Hostmask = "";
                }

                if (messageType == "JOIN")
                {
                    TargetType = TargetTypes.CHANNEL;
                    replyTo    = messageList[2].TrimStart(':');
                }
                else if (messageType == "PRIVMSG" || messageType == "TOPIC")
                {
                    if (messageList[2].TrimStart(':').StartsWith("#"))
                    {
                        TargetType = TargetTypes.CHANNEL;
                        replyTo    = messageList[2].TrimStart(':').ToLowerInvariant();
                    }
                    else
                    {
                        TargetType = TargetTypes.USER;
                        replyTo    = User.Name.ToLowerInvariant();
                    }

                    messageString = String.Join(" ", messageList.ToArray(), 3, messageList.Count - 3);
                    if (messageString.StartsWith(":"))
                    {
                        messageString = messageString.Substring(1, messageString.Length - 1);
                    }

                    if (MessageString.StartsWith(Convert.ToChar((byte)1).ToString()))
                    {
                        int messageEnd = MessageString.IndexOf(Convert.ToChar((byte)1), 1);
                        if (messageEnd > 1)
                        {
                            ctcpString = MessageString.Substring(1, messageEnd - 1);
                            ctcp       = true;
                        }
                    }
                }
            }
        }