コード例 #1
0
        public TelnetSymbol(TelnetCommands myCommand, TelnetOptions myOption)
        {
            _Command = myCommand;
            _Option  = myOption;

            _TelnetSymbolType = TelnetSymbolTypes.Command;
        }
コード例 #2
0
ファイル: TelnetSymbol.cs プロジェクト: anukat2015/sones
        public TelnetSymbol(TelnetCommands myCommand, TelnetOptions myOption)
        {
            _Command = myCommand;
            _Option = myOption;

            _TelnetSymbolType = TelnetSymbolTypes.Command;
        }
コード例 #3
0
        public static TelnetCommands ToTelnetCommand(this byte b)
        {
            foreach (FieldInfo fi in typeof(TelnetCommands).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                TelnetCommands command = (TelnetCommands)fi.GetValue(null);
                if ((byte)command == b)
                {
                    return(command);
                }
            }

            return(TelnetCommands.IAC);
        }
コード例 #4
0
        public static bool IsTelnetCommand(this byte b)
        {
            foreach (FieldInfo fi in typeof(TelnetCommands).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                TelnetCommands command = (TelnetCommands)fi.GetValue(null);
                if ((byte)command == b)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
ファイル: SocketHelper.cs プロジェクト: retslig/ANDP
        /// <summary> Once connected to the server this is the logic needed to process the DO request from the server.</summary>
        /// <param name="myTelnetOption"> This is specific Telnet Option received from the server.</param>
        protected virtual byte[] HandleDORequest(byte myTelnetOption)
        {
            #warning "May need to implement this more at some point."
            // For every command we're asked to process, tell the sender that we will not process it.
            TelnetCommands myTelnetCommand = TelnetCommands.WONT;

            if (_connInfo.ShowTelentCodes)
            {
                _receivedData += "{Snd-IAC-" + myTelnetCommand + "-" + InterpretTelnetOption(myTelnetOption) + "}" + Environment.NewLine;
            }

            //Creating our reply buffer.  First IAC, then WONT, then the option that server sent.
            return(new[] { (byte)TelnetCommands.IAC, (byte)myTelnetCommand, myTelnetOption });
        }
コード例 #6
0
ファイル: SocketHelper.cs プロジェクト: retslig/ANDP
        /// <summary> This method is if you want to send specific telenet options to the server.</summary>
        /// <param name="telnetCommand"> This is the TelnetCommand you want to send.</param>
        /// <param name="telnetOption"> This is the TelnetOption you want to send.</param>
        /// <param name="data"> This is data you want to send along.  If you do not want to send any data set as null.</param>
        public void TransmitTelnetCommand(TelnetCommands telnetCommand, TelnetOptions telnetOption, byte[] data)
        {
            if (!_socket.Connected)
            {
                throw new Exception("Socket is no longer connected." + Environment.NewLine);
            }

            var wholeRequestList = new List <byte> {
                (byte)TelnetCommands.IAC, (byte)telnetCommand, (byte)telnetOption
            };

            if (data != null)
            {
                if (data.Length > 0)
                {
                    wholeRequestList.AddRange(data);
                }
            }
            TransmitByteArray(wholeRequestList.ToArray());
        }
コード例 #7
0
ファイル: TelnetParser.cs プロジェクト: TheByte/sones
 private void SendOption(TelnetCommands myCommand, TelnetOptions myOption)
 {
     Byte[] data = new Byte[] { (Byte)TelnetCommands.Iac, (Byte)myCommand, (Byte)myOption };
     HandleDataToSend(data);
 }
コード例 #8
0
 public TelnetSymbol(TelnetCommands myCommand)
 {
     _Command          = myCommand;
     _TelnetSymbolType = TelnetSymbolTypes.Command;
 }
コード例 #9
0
 public static byte Translate(this TelnetCommands command)
 {
     return((byte)command);
 }
コード例 #10
0
ファイル: TelnetParser.cs プロジェクト: zhouweiaccp/sones
 private void SendOption(TelnetCommands myCommand, TelnetOptions myOption)
 {
     Byte[] data = new Byte[] { (Byte)TelnetCommands.Iac, (Byte)myCommand, (Byte)myOption };
     HandleDataToSend(data);
 }
コード例 #11
0
ファイル: TelnetSymbol.cs プロジェクト: anukat2015/sones
 public TelnetSymbol(TelnetCommands myCommand)
 {
     _Command = myCommand;
     _TelnetSymbolType = TelnetSymbolTypes.Command;
 }
コード例 #12
0
        void ParseResponse()
        {
            // track the current color that should be applied to the text
            Color currentColor = Colors.Cyan;//Color.FromArgb(0xFF, 0x0, 0x0, 0x0);

            do
            {
                // wait for input
                _writeLock.WaitOne();

                // reset the lock
                _writeLock.Reset();

                // create an array to hold the bytes
                byte[] data = new byte[_overflow.Length];

                // copy any overflow bytes into the array
                Array.Copy(_overflow, data, _overflow.Length);

                // clear the overflow
                _overflow = new byte[0];

                // lock the buffer to keep additional data entry
                lock (_buffer)
                {
                    // append each block in the buffer to the data array
                    while (_buffer.Count > 0)
                    {
                        byte[] next = _buffer.Dequeue();
                        Array.Resize <byte>(ref data, data.Length + next.Length);
                        Array.Copy(next, 0, data, data.Length - next.Length, next.Length);
                    }
                }

                // begin processing the bytes

                // check if consumer supports ansi
                bool ansi = _flags.Contains(TelnetOptionFlags.ANSI);

                // create a list to hold the segments
                List <IFormattedTextSegment> segments = new List <IFormattedTextSegment>();

                // create a string builder to construct segments
                StringBuilder segment = new StringBuilder();

                // create a byte array to store any response to server requests
                byte[] response = new byte[0];

                // process the entire byte stream
                for (int i = 0; i < data.Length; ++i)
                {
                    if (data[i] == ESC) // ansi escape
                    {
                        Color background = Colors.Black;
                        int   row = 0, col = 0;

                        if (segment.Length > 0)
                        {
                            segments.Add(new DisplayText()
                            {
                                Text = segment.ToString(), TextColor = currentColor
                            });
                            segment.Clear();
                        }

                        int processed = AnsiProcessor.ReadCommand(data, i, ref row, ref col, ref background, ref currentColor);

                        if (processed < 0) // fragment
                        {
                            _overflow = new byte[data.Length - i];
                            Array.Copy(data, i, _overflow, 0, _overflow.Length);
                            break;
                        }


                        i += processed; // advance past the command

                        continue;
                    }
                    else if (data[i] == TelnetCommands.IAC.Translate()) // process the telnet command
                    {
                        TelnetCommands command = data[++i].ToTelnetCommand();

                        // subnegotiation so there will be more data
                        if (command == TelnetCommands.Subnegotation)
                        {
                        }
                        // delete a character
                        else if (command == TelnetCommands.EraseCharacter)
                        {
                        }
                        // delete the line
                        else if (command == TelnetCommands.EraseLine)
                        {
                        }
                        else
                        {
                            // regular negotiation
                            TelnetOptions option = data[++i].ToTelnetOption();

                            Array.Resize <byte>(ref response, response.Length + 3);
                            response[response.Length - 3] = TelnetCommands.IAC.Translate();

                            // check to see if that option is supported
                            if (_flags.Contains(option.ToFlag()))
                            {
                                if (command == TelnetCommands.Will || command == TelnetCommands.Do)
                                {
                                    response[response.Length - 2] = TelnetCommands.Will.Translate();
                                }
                                else
                                {
                                    response[response.Length - 2] = TelnetCommands.Wont.Translate();
                                }

                                if (option == TelnetOptions.NAWS && (command == TelnetCommands.Will))
                                {
                                    _nawsEnabled = true;
                                }
                            }
                            else // tell the server not to support this
                            {
                                if (command == TelnetCommands.Will)
                                {
                                    response[response.Length - 2] = TelnetCommands.Dont.Translate();
                                }
                                else
                                {
                                    response[response.Length - 2] = TelnetCommands.Wont.Translate();
                                }
                            }

                            response[response.Length - 1] = option.Translate();

                            _negotiated |= option.ToFlag();
                        }
                        continue;
                    }

                    // append the data to the segment
                    char c = (char)data[i];
                    if (c == '\b')
                    {
                        if (segment.Length > 0)
                        {
                            segment.Remove(segment.Length - 1, 1);
                        }
                    }
                    else
                    {
                        segment.Append(c);
                    }
                }

                // check for server negotiation
                if (response.Length > 0)
                {
                    // add any additional flags that haven't been negotiated
                    foreach (TelnetOptionFlags option in _flags.ParseOptions())
                    {
                        // this has already been negotiated
                        if (_negotiated.Contains(option))
                        {
                            continue;
                        }

                        // request the ones that we are comfortable with so far
                        switch (option)
                        {
                        case TelnetOptionFlags.SupressGoAhead: goto case TelnetOptionFlags.NAWS;

                        case TelnetOptionFlags.Echo: goto case TelnetOptionFlags.NAWS;

                        case TelnetOptionFlags.NAWS:
                            Array.Resize <byte>(ref response, response.Length + 3);

                            response[response.Length - 3] = TelnetCommands.IAC.Translate();
                            response[response.Length - 2] = TelnetCommands.Do.Translate();
                            response[response.Length - 1] = option.Translate().Translate();

                            break;
                        }

                        _negotiated |= option;
                    }

                    // create the socket event args
                    SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                    args.UserToken      = _socket;
                    args.RemoteEndPoint = _address;
                    args.Completed     += new EventHandler <SocketAsyncEventArgs>(AsyncCompletedHandler);

                    // put the response in the buffer
                    args.SetBuffer(response, 0, response.Length);

                    // send the response to the server
                    _socket.SendAsync(args);
                }

                // notify any listeners
                if (MessageRecieved != null)
                {
                    segments.Add(new DisplayText()
                    {
                        Text = segment.ToString(), TextColor = currentColor
                    });
                    MessageRecieved(this, new MessageRecievedEventArgs()
                    {
                        Segments = segments.ToArray()
                    });
                }

                // end byte processing
            } while (_socket.Connected);
        }