예제 #1
0
 internal IrcMessage(IrcTags tags, IrcPrefix prefix, string command, params string[] parameters)
 {
     this.Tags       = tags;
     this.From       = prefix;
     this.Command    = command;
     this.Parameters = parameters;
     this.Received   = DateTime.Now;
 }
예제 #2
0
        internal static IrcTags Parse(string tagstring)
        {
            IrcTags tags = new IrcTags();

            if (!string.IsNullOrEmpty(tagstring))
            {
                string[] split = tagstring.Split(new char[] { ';' });

                foreach (string s in split)
                {
                    string[] kv    = s.Split(new char[] { '=' }, 2);
                    string   key   = kv[0];
                    string   value = "";
                    if (kv.Length >= 2)
                    {
                        value = kv[1];
                    }

                    tags[key] = value;
                }
            }

            return(tags);
        }
예제 #3
0
        internal static IrcMessage Parse(string data)
        {
            StringBuilder sb   = new StringBuilder();
            List <string> para = new List <string>();

            //int size = data.Length > 512 ? 512 : data.Length;
            //Char[] c = data.ToCharArray(0, size);
            Char[] c         = data.ToCharArray();
            int    pos       = 0;
            string tagstring = null;
            string prefix    = null;
            string command   = null;

            if (c[pos] == '@')
            {
                for (pos++; pos < c.Length; pos++)
                {
                    if (c[pos] == ' ')
                    {
                        break;
                    }

                    sb.Append(c[pos]);
                }
                tagstring = sb.ToString();
                sb.Length = 0;
                pos++;
            }

            if (c[pos] == ':')
            {
                for (pos++; pos < c.Length; pos++)
                {
                    if (c[pos] == ' ')
                    {
                        break;
                    }

                    sb.Append(c[pos]);
                }
                prefix    = sb.ToString();
                sb.Length = 0;
                pos++;
            }

            for (; pos < c.Length; pos++)
            {
                if (c[pos] == ' ')
                {
                    break;
                }
                sb.Append(c[pos]);
            }
            command   = sb.ToString();
            sb.Length = 0;
            pos++;

            bool trailing = false;

            while (pos < c.Length)
            {
                if (c[pos] == ':')
                {
                    trailing = true;
                    pos++;
                }

                for (; pos < c.Length; pos++)
                {
                    if (c[pos] == ' ' && !trailing)
                    {
                        break;
                    }
                    sb.Append(c[pos]);
                }
                para.Add(sb.ToString());
                sb.Length = 0;
                pos++;
            }

            return(new IrcMessage(IrcTags.Parse(tagstring), IrcPrefix.Parse(prefix), command, para.ToArray()));
        }