예제 #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();
                    }));
                }
            }
        }
예제 #2
0
        public override void HandlePacket(object sender, string packet_raw)
        {
            Packet packet = Packet.Deserialize(packet_raw);

            if (packet.Type == "ConnectPipePacket")
            {
                ConnectPipePacket_PacketProcessor connectPipePacket_PacketProcessor
                    = new ConnectPipePacket_PacketProcessor(Connection, ConnectPipePacket.Deserialize(packet_raw),
                                                            new Dictionary <Guid, Client> {
                    { SlaveGlobalData.LocalClient.UniqueId, SlaveGlobalData.LocalClient }
                });

                connectPipePacket_PacketProcessor.Process();
                return;
            }
            if (packet.Type == "DisconnectPipePacket")
            {
                DisconnectPipePacket_PacketProcessor disconnectPipePacket_PacketProcessor
                    = new DisconnectPipePacket_PacketProcessor(Connection, DisconnectPipePacket.Deserialize(packet_raw),
                                                               new Dictionary <Guid, Client> {
                    { SlaveGlobalData.LocalClient.UniqueId, SlaveGlobalData.LocalClient }
                });

                disconnectPipePacket_PacketProcessor.Process();
                return;
            }
            if (packet.Type == "ConnectShellPacket")
            {
                ConnectShellPacket_PacketProcessor connectShellPacket_PacketProcessor
                    = new ConnectShellPacket_PacketProcessor(Connection, ConnectShellPacket.Deserialize(packet_raw),
                                                             new Dictionary <Guid, Client> {
                    { SlaveGlobalData.LocalClient.UniqueId, SlaveGlobalData.LocalClient }
                },
                                                             SlaveGlobalData.MasterServerInfo.RemoteServer);

                Shell shell = connectShellPacket_PacketProcessor.Process();
                if (shell == null)
                {
                    return;                // fuckup
                }
                SlaveGlobalData.ShellListenerLoop = new PacketListenerLoop(shell.Connection, new Shell_PacketHandler(shell.Connection, SlaveGlobalData.LocalClient, shell));
                SlaveGlobalData.ShellInstance     = shell;

                SlaveGlobalData.ShellOutputChangedHandler = (s, e) =>
                {
                    Shell_IO_ChangedPacket shell_IO_Changed = new Shell_IO_ChangedPacket(ChangeType.Output, e.Change);
                    shell.Connection.SendPacket(shell_IO_Changed);
                };

                shell.ShellOutputChanged += SlaveGlobalData.ShellOutputChangedHandler;

                Task.Run(() => SlaveGlobalData.ShellListenerLoop.Run());
            }
        }
예제 #3
0
        public void SendPacket(Packet packet)
        {
            Write(packet.Serialize());
            Console.WriteLine($"Sent packet of type {packet.Type}");

            if (packet.Type == "Shell_IO_ChangedPacket")
            {
                Shell_IO_ChangedPacket packet__ = packet as Shell_IO_ChangedPacket;
                //Console.WriteLine($"ChangeType: {packet__.ChangeType}; Change: {packet__.Change}");
            }
        }
예제 #4
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);
        }
예제 #5
0
 public void Clock_Tick()
 {
     while (true)
     {
         Thread.Sleep(Buffer_Timeout);
         if (!ResetClock)
         {
             if (Buffer.Length == 0)
             {
                 continue;
             }
             // Send buffer contents to the remote shell
             Shell_IO_ChangedPacket shell_IO_Changed = new Shell_IO_ChangedPacket(ChangeType.Input, Buffer.ToString());
             Shell_Connection.SendPacket(shell_IO_Changed);
             Buffer.Clear();
         }
         else
         {
             ResetClock = false;
         }
     }
 }
        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);
            }
        }