Exemple #1
0
        public byte[] GetNegotiationResponsePacket(OptionNegotiationType RequestType)
        {
            byte[] ResponsePacket = null;

            switch (RequestType)
            {
            case OptionNegotiationType.WILL:
                if (RespondedWillWont == false)
                {
                    if (_bWILL)
                    {
                        ResponsePacket = TelnetOption.GetNegotiationResponseDo(OptionCode);
                    }
                    else
                    {
                        ResponsePacket = TelnetOption.GetNegotiationResponseDont(OptionCode);
                    }
                    RespondedDoDont = true;
                }
                break;

            case OptionNegotiationType.WONT:
                if (RespondedWillWont == false)
                {
                    _bWILL          = false;
                    ResponsePacket  = TelnetOption.GetNegotiationResponseDont(OptionCode);
                    RespondedDoDont = true;
                }
                break;

            case OptionNegotiationType.DO:
                if (RespondedDoDont == false)
                {
                    if (_bDO)
                    {
                        ResponsePacket = TelnetOption.GetNegotiationResponseWill(OptionCode);
                    }
                    else
                    {
                        ResponsePacket = TelnetOption.GetNegotiationResponseWont(OptionCode);
                    }
                    RespondedWillWont = true;
                }
                break;

            case OptionNegotiationType.DONT:
                if (RespondedDoDont == false)
                {
                    _bDO              = false;
                    ResponsePacket    = TelnetOption.GetNegotiationResponseWont(OptionCode);
                    RespondedWillWont = true;
                }
                break;

            default:
                break;
            }

            return(ResponsePacket);
        }
Exemple #2
0
        public byte[] GetNegotiationPacket()
        {
            byte[] ResponsePacket = null;

            if (SendDoDont)
            {
                if (_bDO)
                {
                    ResponsePacket = TelnetOption.GetNegotiationResponseDo(OptionCode);
                }
                else
                {
                    ResponsePacket = TelnetOption.GetNegotiationResponseDont(OptionCode);
                }
            }
            else if (SendWillWont)
            {
                if (_bWILL)
                {
                    ResponsePacket = TelnetOption.GetNegotiationResponseWill(OptionCode);
                }
                else
                {
                    ResponsePacket = TelnetOption.GetNegotiationResponseWont(OptionCode);
                }
            }

            return(ResponsePacket);
        }
Exemple #3
0
        public bool SetOption(byte OptionCode, TelnetOption Option)
        {
            if (Option == null)
            {
                return(false);
            }

            if (_Options.ContainsKey(OptionCode))
            {
                return(true);
            }

            _Options.Add(OptionCode, Option);
            Option.OnSendData += new TelnetOption.OnSendDataHandler(Option_OnSendData);
            return(true);
        }
Exemple #4
0
 protected void _ProcessDontCommand(byte Option)
 {
     if (_Options.ContainsKey(Option) == false)
     {
         _LogDebug("(DONT?)OptionCode: " + Option.ToString() + "(0x" + Option.ToString("X") + ") not supported.");
         SendToNetwork(TelnetOption.GetNegotiationResponseWont(Option));
         return;
     }
     if (!_Options[Option].IsNegotiatedSuccessfully())
     {
         _LogDebug("(DONT?)OptionCode: " + Option.ToString() + "(0x" + Option.ToString("X") + ") negotiated OK.");
         byte[] Response = _Options[Option].GetNegotiationResponsePacket(TelnetOption.OptionNegotiationType.DONT);
         if (Response != null)
         {
             SendToNetwork(Response);
         }
     }
 }
Exemple #5
0
        protected void _ProcessWillCommand(byte Option)
        {
            if (_Options.ContainsKey(Option) == false)
            {
                _LogDebug("(WILL?)OptionCode: " + Option.ToString() + "(0x" + Option.ToString("X") + ") not supported.");
                SendToNetwork(TelnetOption.GetNegotiationResponseDont(Option));
                return;
            }
            if (!_Options[Option].IsNegotiatedSuccessfully())
            {
                _LogDebug("(WILL?)OptionCode: " + Option.ToString() + "(0x" + Option.ToString("X") + ") negotiated OK.");
                byte[] Response = _Options[Option].GetNegotiationResponsePacket(TelnetOption.OptionNegotiationType.WILL);
                if (Response != null)
                {
                    SendToNetwork(Response);
                }
            }

            if (_Options[Option].IsNegotiatedSuccessfully() && !_Options[Option].IsOptionInitializationSent)
            {
                OptionNegotiated(Option);
                _Options[Option].SendOptionInitailization();
            }
        }