Пример #1
0
        // TODO: OnDisconnected
        /*
        public override void OnDisconnected(Peer client)
        {
            ConnectedClient c = Clients.Where(x => x.Connection == client).SingleOrDefault();
            if (c != null)
            {
                OnClientDisconnected?.Invoke(c.ClientID);
                Clients.Remove(c);
            }
            base.OnDisconnected(client);
        }
        */
        // TOOD: ConnectTimeout
        /*
        public override void ConnectTimeout()
        {
            base.ConnectTimeout();
            OnMasterConnectionError?.Invoke();
        }
        */
        public override void OnCommandReceived(IPEndPoint source, RDCCommand cmd)
        {
            base.OnCommandReceived(source, cmd);
            switch (cmd.Command)
            {
                case RDCCommandType.MASTER_AUTH:
                    Client.SendCommand(source, new RDCCommand()
                    {
                        Command = RDCCommandType.MASTER_AUTH_HOST,
                        Data = Fingerprint
                    });
                    break;

                case RDCCommandType.MASTER_AUTH_HOST_OK:
                    RDCCommandPackets.IntroducerPacket outsideEndpoint = cmd.CastDataAs<RDCCommandPackets.IntroducerPacket>();
                    HostID = outsideEndpoint.HostID;
                    Listen(outsideEndpoint.Address, outsideEndpoint.Port);
                    OnMasterConnected?.Invoke(HostID);
                    break;

                case RDCCommandType.MASTER_NOTICE:
                    OnMasterNotice?.Invoke((string)cmd.Data);
                    break;

                case RDCCommandType.HOST_CONNECT:
                    string clientId = cmd.SourceID;
                    string pass = (string)cmd.Data;
                    if (pass == Password)
                    {
                        OnClientConnected?.Invoke();
                        Server.SendCommand(source, new RDCCommand()
                        {
                            Command = RDCCommandType.HOST_CONNECT_OK
                        });
                        lock(_mutex)
                        {
                            if (Clients.Where(x => x.ClientID == clientId).SingleOrDefault() == null)
                                Clients.Add(new ConnectedClient()
                                {
                                    ClientID = clientId,
                                    Connection = source
                                });
                        }
                    }
                    else
                        Server.SendCommand(source, new RDCCommand()
                        {
                            Command = RDCCommandType.HOST_CONNECT_ERROR
                        });
                    break;

                case RDCCommandType.HOST_GETINFO:
                    if (!ValidateClient(cmd.SourceID, source))
                        return;
                    Server.SendCommand(source, new RDCCommand()
                    {
                        Command = RDCCommandType.HOST_NEWINFO,
                        SourceID = HostID,
                        Data = new RDCCommandPackets.HostInfoPacket()
                        {
                            ScreenWidth = Screen.PrimaryScreen.Bounds.Width,
                            ScreenHeight = Screen.PrimaryScreen.Bounds.Height,
                        }
                    });
                    break;

                case RDCCommandType.HOST_SCREEN_REFRESH:
                    if (!ValidateClient(cmd.SourceID, source))
                        return;
                    MemoryStream ms = _screencap.Capture3();
                    Server.SendCommand(source, new RDCCommand()
                    {
                        Command = RDCCommandType.HOST_SCREEN_REFRESH_OK,
                        SourceID = HostID,
                        Buffer = ms.ToArray()
                    });
                    break;

                case RDCCommandType.HOST_MOUSE_MOVE:
                    if (!ValidateClient(cmd.SourceID, source))
                        return;
                    RDCCommandPackets.HostMouseEvent mouseEvent = cmd.CastDataAs<RDCCommandPackets.HostMouseEvent>();
                    RDCRemoteMouse.Move(mouseEvent.MouseX, mouseEvent.MouseY);
                    break;

                case RDCCommandType.HOST_MOUSE_DOWN:
                    if (!ValidateClient(cmd.SourceID, source))
                        return;
                    mouseEvent = mouseEvent = cmd.CastDataAs<RDCCommandPackets.HostMouseEvent>();
                    RDCRemoteMouse.Down(mouseEvent.MouseX, mouseEvent.MouseY, mouseEvent.Buttons);
                    break;

                case RDCCommandType.HOST_MOUSE_UP:
                    if (!ValidateClient(cmd.SourceID, source))
                        return;
                    mouseEvent = mouseEvent = cmd.CastDataAs<RDCCommandPackets.HostMouseEvent>();
                    RDCRemoteMouse.Up(mouseEvent.MouseX, mouseEvent.MouseY, mouseEvent.Buttons);
                    break;

                case RDCCommandType.HOST_KEY_DOWN:
                    if (!ValidateClient(cmd.SourceID, source))
                        return;
                    RDCCommandPackets.HostKeyEvent keyEvent = cmd.CastDataAs<RDCCommandPackets.HostKeyEvent>();
                    RDCRemoteKeyboard.Down((short)keyEvent.KeyCode, keyEvent.Shift);
                    break;

                case RDCCommandType.HOST_KEY_UP:
                    if (!ValidateClient(cmd.SourceID, source))
                        return;
                    keyEvent = cmd.CastDataAs<RDCCommandPackets.HostKeyEvent>();
                    RDCRemoteKeyboard.Up((short)keyEvent.KeyCode, keyEvent.Shift);
                    break;
            }
        }
Пример #2
0
        public override void OnCommandReceived(IPEndPoint source, RDCCommand cmd)
        {
            base.OnCommandReceived(source, cmd);
            switch(cmd.Command)
            {
                case RDCCommandType.HOST_CONNECT_OK:
                    OnHostConnected?.Invoke(HostID);
                    break;

                case RDCCommandType.HOST_CONNECT_ERROR:
                    OnHostError?.Invoke(HostID);
                    break;

                case RDCCommandType.HOST_NEWINFO:
                    RDCCommandPackets.HostInfoPacket info = cmd.CastDataAs<RDCCommandPackets.HostInfoPacket>();
                    OnHostInfo?.Invoke(info.ScreenWidth, info.ScreenHeight);
                    break;

                case RDCCommandType.HOST_SCREEN_REFRESH_OK:
                    OnHostScreenRefresh?.Invoke(cmd.Buffer);
                    break;

            }
        }
Пример #3
0
        public override void OnCommandReceived(IPEndPoint source, RDCCommand cmd)
        {
            base.OnCommandReceived(source, cmd);
            switch (cmd.Command)
            {
                case RDCCommandType.MASTER_AUTH:
                    Client.SendCommand(Connection, new RDCCommand()
                    {
                        Command = RDCCommandType.MASTER_AUTH_CLIENT
                    });
                    break;

                case RDCCommandType.MASTER_AUTH_CLIENT_OK:
                    ClientID = (string)cmd.Data;
                    OnConnectedToMaster?.Invoke();
                    break;

                case RDCCommandType.MASTER_CLIENT_CONNECT_OK:
                    RDCCommandPackets.IntroducerPacket ipData = cmd.CastDataAs<RDCCommandPackets.IntroducerPacket>();
                    HostConnection h = new HostConnection(ClientID, ipData.HostID);
                    if (OnHostConnecting != null) h.OnHostConnecting += OnHostConnecting;
                    if (OnHostConnected != null) h.OnHostConnected += OnHostConnected;
                    if (OnHostError != null) h.OnHostError += OnHostError;
                    lock (_mutex)
                    {
                        HostConnections.Add(h);
                        h = HostConnections.Last();
                    }
                    h.Connect(ipData.Address, ipData.Port, ConnectionPassword);
                    ConnectionPassword = string.Empty;
                    break;

                case RDCCommandType.MASTER_CLIENT_CONNECT_ERROR:
                    OnHostConnectionError?.Invoke((string)cmd.Data);
                    break;

                case RDCCommandType.MASTER_NOTICE:
                    OnMasterNotice?.Invoke((string)cmd.Data);
                    break;
            }
        }