Esempio n. 1
0
        /// <summary>
        /// Convert bytes into IrcPackets
        /// </summary>
        public IrcPacket[] ExtractPackets(ByteBuffer partialResponse)
        {
            var str      = partialResponse.GetString(encoding);
            var response = lastResponsePart + str;
            var ss       = new StringStream(response);
            var packets  = new List <IrcPacket>(3);

            while (ss.HasNext)
            {
                var content = ss.NextWord(PacketTerminator);
                if (!ss.HasNext && !response.EndsWith(PacketTerminator))
                {
                    lastResponsePart = content;
                }
                else
                {
                    try
                    {
                        var packet = CreatePacket(content);
                        packets.Add(packet);
                        if (!ss.HasNext)
                        {
                            lastResponsePart = "";
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Unable to parse packet: " + content, e);
                    }
                }
            }
            return(packets.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Build a packet from a new line of content from the server.
        /// Do as much parsing as possible here before the packet-handler
        /// will then work with the gathered information.
        /// </summary>
        public IrcPacket CreatePacket(string content)
        {
            var line = new StringStream(content.Trim());

            string prefix;

            if (content[0] == ':')
            {
                prefix = line.NextWord().Substring(1);
            }
            else
            {
                prefix = line.NextWord();
            }

            var action = line.NextWord();
            var packet = new IrcPacket(irc, prefix, action, new StringStream(line.Remainder.Trim()), line.String)
            {
                protHandler = this
            };

            return(packet);
        }
        /// <summary>
        /// Build a packet from a new line of content from the server.
        /// Do as much parsing as possible here before the packet-handler
        /// will then work with the gathered information.
        /// </summary>
        public IrcPacket CreatePacket(string content)
        {
            var line = new StringStream(content.Trim());

            string prefix;
            if (content[0] == ':')
            {
                prefix = line.NextWord().Substring(1);
            }
            else
            {
                prefix = line.NextWord();
            }

            var action = line.NextWord();
            var packet = new IrcPacket(irc, prefix, action, new StringStream(line.Remainder.Trim()), line.String)
            {
                protHandler = this
            };

            return packet;
        }
        /// <summary>
        /// Convert bytes into IrcPackets
        /// </summary>
        public IrcPacket[] ExtractPackets(ByteBuffer partialResponse)
        {
            var str = partialResponse.GetString(encoding);
            var response = lastResponsePart + str;
            var ss = new StringStream(response);
            var packets = new List<IrcPacket>(3);

            while (ss.HasNext)
            {
                var content = ss.NextWord(PacketTerminator);
                if (!ss.HasNext && !response.EndsWith(PacketTerminator))
                {
                    lastResponsePart = content;
                }
                else
                {
                    try
                    {
                        var packet = CreatePacket(content);
                        packets.Add(packet);
                        if (!ss.HasNext)
                        {
                            lastResponsePart = "";
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Unable to parse packet: " + content, e);
                    }
                }
            }
            return packets.ToArray();
        }