Пример #1
0
 /// <summary>
 ///     Sends client data to the module.
 /// </summary>
 /// <param name="dataToSend"></param>
 public void SendToModule(byte[] dataToSend)
 {
     foreach (var b in dataToSend)
     {
         DataFromClient.Add(b);
     }
 }
Пример #2
0
 private void InputThread()
 {
     while (SessionState != EnumSessionState.LoggedOff && _consoleInputThreadIsRunning)
     {
         DataFromClient.Add((byte)Console.ReadKey(true).KeyChar);
         ProcessDataFromClient();
     }
 }
Пример #3
0
        private void ProcessIncomingClientData(int bytesReceived)
        {
            if (bytesReceived == 0 || SessionState == EnumSessionState.LoggedOff)
            {
                return;
            }

            var(dataFromClient, length) = ProcessIncomingClientData(_socketReceiveBuffer, bytesReceived);

            //Enqueue the incoming bytes for processing
            for (var i = 0; i < length; i++)
            {
                DataFromClient.Add(dataFromClient[i]);
            }
        }
Пример #4
0
        private void ProcessIncomingClientData(int bytesReceived)
        {
            if (bytesReceived == 0 || SessionState == EnumSessionState.LoggedOff)
            {
                return;
            }

            //Process if it's an IAC command
            if (socketReceiveBuffer[0] == 0xFF)
            {
                ParseIAC(socketReceiveBuffer);
                return;
            }

            //Enqueue the incoming bytes for processing
            for (var i = 0; i < bytesReceived; i++)
            {
                DataFromClient.Add(socketReceiveBuffer[i]);
            }
        }
Пример #5
0
        /// <summary>
        ///     Thread to handle receiving data from the client
        /// </summary>
        private void ReceiveWorker()
        {
            while (SessionState != EnumSessionState.LoggedOff && _rloginConnection.IsConnected())
            {
                var bytesReceived = _rloginConnection.Receive(socketReceiveBuffer, SocketFlags.None, out var socketState);
                ValidateSocketState(socketState);

                if (bytesReceived == 0)
                {
                    continue;
                }

                //Parse RLogin Information
                if (SessionState == EnumSessionState.Negotiating && bytesReceived > 2 &&
                    socketReceiveBuffer[0] == 0x0)
                {
                    var usernameLength  = 0;
                    var startingOrdinal = 1;

                    if (socketReceiveBuffer[1] == 0)
                    {
                        startingOrdinal++;
                    }

                    ReadOnlySpan <byte> bufferSpan = socketReceiveBuffer;

                    //Find End of Username
                    for (var i = startingOrdinal; i < bytesReceived; i++)
                    {
                        if (socketReceiveBuffer[i] != 0x0)
                        {
                            continue;
                        }
                        usernameLength = i - startingOrdinal;
                        break;
                    }

                    //Send 0 byte to ACK
                    Send(new byte[] { 0x0 });
                    Username = Encoding.ASCII.GetString(bufferSpan.Slice(startingOrdinal, usernameLength));

                    _logger.Info($"Rlogin For User: {Username}");

                    if (!string.IsNullOrEmpty(ModuleIdentifier))
                    {
                        CurrentModule = _host.GetModule(ModuleIdentifier);
                        SessionState  = EnumSessionState.EnteringModule;
                    }
                    else
                    {
                        SessionState = EnumSessionState.MainMenuDisplay;
                    }

                    continue;
                }

                //Enqueue the incoming bytes for processing
                for (var i = 0; i < bytesReceived; i++)
                {
                    DataFromClient.Add(socketReceiveBuffer[i]);
                }

                Thread.Sleep(1);
            }

            //Cleanup if the connection was dropped
            SessionState = EnumSessionState.LoggedOff;

            //Dispose the socket connection
            _rloginConnection.Dispose();
        }