示例#1
0
        public override void OnCommandReceived(IPEndPoint source, RDCCommand cmd)
        {
            base.OnCommandReceived(source, cmd);
            switch(cmd.Command)
            {
                case RDCCommandType.MASTER_AUTH_HOST:
                    MasterCore.ConnectedHost host = master.AddHost(source, (string)cmd.Data);
                    Server.SendCommand(source, new RDCCommand()
                    {
                        Command = RDCCommandType.MASTER_AUTH_HOST_OK,
                        Data = new RDCCommandPackets.IntroducerPacket()
                        {
                            HostID = host.HostID,
                            Address = source.Address.ToString(),
                            Port = source.Port
                        }
                    });
                    break;

                case RDCCommandType.MASTER_AUTH_CLIENT:
                    MasterCore.ConnectedClient client = master.AddClient(source, (string)cmd.Data);
                    Server.SendCommand(source, new RDCCommand()
                    {
                        Command = RDCCommandType.MASTER_AUTH_CLIENT_OK,
                        Data = client.ClientID
                    });
                    break;

                case RDCCommandType.MASTER_CLIENT_CONNECT:
                    IPEndPoint holeHost = master.FindHostByID(cmd.DestinationID);
                    IPEndPoint holeClient = master.FindClientByID(cmd.SourceID);
                    if (holeHost != null && holeClient != null)
                    {
                        // TODO: Master should send host client ID requesting to authenticate.
                        // Host should store ID and then mark it as an allowed client.
                        if (master.FindClientByConnection(holeClient) == cmd.SourceID) // Avoid impersonation
                            Server.SendCommand(holeClient, new RDCCommand()
                            {
                                Command = RDCCommandType.MASTER_CLIENT_CONNECT_OK,
                                SourceID = cmd.DestinationID,
                                Data = new RDCCommandPackets.IntroducerPacket()
                                {
                                    HostID = cmd.DestinationID,
                                    Address = holeHost.Address.ToString(),
                                    Port = holeHost.Port
                                }
                            });
                        else
                            Server.SendCommand(source, new RDCCommand()
                            {
                                Command = RDCCommandType.MASTER_CLIENT_CONNECT_ERROR,
                                SourceID = cmd.DestinationID,
                                Data = "Unknown host"
                            });
                    }
                    else
                        Server.SendCommand(source, new RDCCommand()
                        {
                            Command = RDCCommandType.MASTER_CLIENT_CONNECT_ERROR,
                            SourceID = cmd.DestinationID,
                            Data = "Unknown host"
                        });
                    break;
            }
        }
示例#2
0
 public void SetNotice(string notice)
 {
     RDCCommand cmdNotice = new RDCCommand()
     {
         Command = RDCCommandType.MASTER_NOTICE,
         Data = notice
     };
     Parallel.ForEach(hosts, (x) => { masterService.Server.SendCommand(x.Connection, cmdNotice); });
     Parallel.ForEach(clients, (x) => { masterService.Server.SendCommand(x.Connection, cmdNotice); });
 }
示例#3
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;

            }
        }
示例#4
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;
            }
        }
示例#5
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;
            }
        }
示例#6
0
 public virtual void OnCommandReceived(IPEndPoint source, RDCCommand cmd)
 {
 }
示例#7
0
 public void SendCommand(IPEndPoint destination, RDCCommand cmd)
 {
     Console.WriteLine("SEND -> " + _js.Serialize(cmd));
     Send(destination, RUDPPacketType.DAT, RUDPPacketFlags.NUL, Encoding.UTF8.GetBytes(_js.Serialize(cmd)));
 }