public void ParserSBTest()
        {
            Encoding encoding = Encoding.UTF8;
            Parser   parser   = new Parser();

            parser.Options.Support(TelnetOption.GMCP);
            parser.Options.Support(TelnetOption.MCCP2);
            byte[] sbCall = new byte[] { TelnetCommand.IAC, TelnetCommand.SB, TelnetOption.MCCP2, TelnetCommand.IAC, TelnetCommand.SE };
            byte[] input  = Utility.Enumerables.Concat(sbCall, encoding.GetBytes("This data would be compressed."));
            List <ITelnetEvent> events = parser.Receive(input);

            foreach (ITelnetEvent ev in events)
            {
                switch (ev.EventType)
                {
                case TelnetEventType.SubNegotiation:
                    TelnetSubNegotiationEvent sbEvent = ev as TelnetSubNegotiationEvent;
                    Console.WriteLine($"SB Event: {sbEvent.Option}\nSB Data: {encoding.GetString(sbEvent.Buffer)}");
                    break;

                case TelnetEventType.DecompressImmediate:
                    TelnetDecompressEvent dataEvent = ev as TelnetDecompressEvent;
                    Console.WriteLine($"Decompress IMMEDIATELY: {encoding.GetString(dataEvent.Buffer)}");
                    break;

                default:
                    Console.WriteLine($"Event not supposed to be here: {ev}");
                    break;
                }
            }
            ITelnetEvent[] evs = events.ToArray();
            Assert.AreEqual(2, evs.Length);
            Assert.AreEqual(true, evs[0] is TelnetSubNegotiationEvent);
            Assert.AreEqual(true, evs[1] is TelnetDecompressEvent);
        }
Beispiel #2
0
        public TelnetSendEvent SubNegotiation(byte option, string content)
        {
            var opt = Options.GetOption(option);

            if (opt.Local && opt.LocalState)
            {
                return(new TelnetSendEvent(TelnetSubNegotiationEvent.Build(option, content, TextEncoding).ToBytes()));
            }
            return(null);
        }
Beispiel #3
0
        public TelnetSendEvent SubNegotiation(byte option, byte[] data)
        {
            var opt = Options.GetOption(option);

            if (opt.Local && opt.LocalState)
            {
                return(new TelnetSendEvent(TelnetSubNegotiationEvent.Build(option, data).ToBytes()));
            }
            return(null);
        }