public void AddAuthenticatedUser(Client client, UInt32 id, string username)
 {
     joinedClients.Remove(client);
     User user;
     user.receiverId = id;
     user.receiverUsername = username;
     authenticatedClients.Add(client, user);
 }
        public Boolean Authenticate(Client client, UInt32 sessionId, string username, string password)
        {
            Boolean isAuthenticated = (this.sessionPassword == password);
            if(isAuthenticated)
            {
                this.AddAuthenticatedUser(client, sessionId, username);
            }

            return isAuthenticated;
        }
 public ScreencastingSession(char[] sessionKey, UInt32 senderId, string senderUsername, string sessionPassword, Client senderClient)
 {
     this.sessionKey = sessionKey;
     this.senderId = senderId;
     this.senderUsername = senderUsername;
     this.sessionPassword = sessionPassword;
     this.senderClient = senderClient;
     this.remoteController = null;
     this.joinedClients = new ConcurrentDictionary<Client, UInt32>();
     this.authenticatedClients = new ConcurrentDictionary<Client, User>();
     this.remoteControlRequestClients = new ConcurrentDictionary<string, Client>();
 }
        public void OnSessionCreateRequested(Client client, string username, string password, ref UInt32 sessionId, ref char[] sessionKey)
        {
            Console.WriteLine("ScreenSessions.OnSessionCreateRequested");
            Console.WriteLine("username:{0} password:{1}", username, password);

            sessionId = GenerateUniqueId();
            sessionKey = GenerateUniqueKey();
            string sessionKeyString = new string(sessionKey);

            ScreencastingSession screencastSession = new ScreencastingSession(sessionKey, sessionId, username, password);

            sessions.Add(sessionKeyString, screencastSession);
            screencastSession.AddAuthenticatedUser(client, sessionId, username);
        }
        public void OnSessionAuthenticationRequested(Client client, UInt32 sessionId, char[] sessionKey, string username, string password, ref UInt32 sessionStatus)
        {
            Console.WriteLine("ScreenSessions.OnSessionAuthenticationRequested");
            Console.WriteLine("sessionId:{0} username:{1} password:{2}", sessionId, username, password);

            string sessionKeyString = new string(sessionKey);

            if(isSessionAlive(sessionKeyString))
            {
                ScreencastingSession screencastSession = sessions[sessionKeyString];
                if(screencastSession.Authenticate(client, sessionId, username, password))
                {
                    OnSessionPartipantListUpdated(screencastSession.sessionKey);
                    sessionStatus = 0;
                    return;
                }
            }

            sessionStatus = 1;
        }
        public void OnSessionLeaveRequested(Client client, UInt32 sessionId, char[] sessionKey, ref UInt32 sessionStatus)
        {
            Console.WriteLine("ScreenSessions.OnSessionLeaveRequested");

            string sessionKeyString = new string(sessionKey);
            Console.WriteLine("sessionId:{0} sessionKey:{1} ", sessionId, sessionKeyString);

            if(isSessionAlive(sessionKeyString))
            {
                ScreencastingSession screencastSession = sessions[sessionKeyString];
                if(screencastSession.authenticatedClients.ContainsKey(client))
                {
                    screencastSession.RemoveAuthenticatedUser(client);
                    OnSessionPartipantListUpdated(screencastSession.sessionKey);
                    sessionStatus = 0;
                    return;
                }
            }

            sessionStatus = 1;
        }
 public void RemoveAuthenticatedUser(Client client)
 {
     User user;
     UInt32 sessionId;
     authenticatedClients.TryRemove(client, out user);
     joinedClients.TryRemove(client, out sessionId);
     UpdateNotifications("left", user.username);
 }
 public void DenyRemoteAccess(Client senderClient, string receiverUsername)
 {
     if(this.senderClient == senderClient)
     {
         Client receiverClient = null;
         remoteControlRequestClients.TryRemove(receiverUsername, out receiverClient);
         receiverClient.OnSessionNotificationUpdate("been denied control of", receiverUsername);
     }
 }
 public void AddRemoteAccessRequest(Client requestingClient, string username)
 {
     if(authenticatedClients.ContainsKey(requestingClient))
     {
         /*if another receiver has control, deny*/
         if(remoteController != this.senderClient)
         {
             remoteControlRequestClients.TryAdd(username, requestingClient);
             DenyRemoteAccess(this.senderClient, username);
         }
         /*if sender has control, add requester to list and inform sender*/
         else
         {
             remoteControlRequestClients.TryAdd(username, requestingClient);
             senderClient.OnSessionRemoteAccessRequested(username);
         }
     }
 }
 public void AddFirstUser(Client client, UInt32 id, string username)
 {
     User user;
     user.sessionId = id;
     user.username = username;
     remoteController = client;
     authenticatedClients.TryAdd(client, user);
     senderClient = client;
 }
Beispiel #11
0
        public void OnSurfaceCommand(Client client, UInt32 sessionId, byte[] surfaceCommand)
        {
            ScreencastingSession session = GetSessionBySenderId(sessionId);

            if (session == null)
                return;

            if (isSessionAlive(session.sessionKey))
            {
                foreach (Client receiver in session.authenticatedClients.Keys)
                {
                    UInt32 receiverSessionId = session.authenticatedClients[receiver].sessionId;

                    if (receiverSessionId != sessionId)
                    {
                        try
                        {
                            receiver.OnSendSurfaceCommand(receiverSessionId, surfaceCommand);
                        }
                        catch (TransportException e)
                        {
                            Console.WriteLine("Caught Transport Exception: " + e.Message);
                            session.RemoveAuthenticatedUser(receiver);
                        }
                    }
                }
            }
        }
 public void RemoveAuthenticatedUser(Client client)
 {
     authenticatedClients.Remove(client);
 }
Beispiel #13
0
 public void OnAcceptClient(TransportClient transportClient)
 {
     Console.WriteLine("Broadcaster.OnAcceptClient");
     Client client = new Client(transportClient, SessionManager.Instance);
     clients.TryAdd(transportClient, client);
 }
        public void OnSessionTerminationRequested(Client client, UInt32 sessionId, char[] sessionKey, ref UInt32 sessionStatus)
        {
            Console.WriteLine("ScreenSessions.OnSessionTerminationRequested");
            string sessionKeyString = new string(sessionKey);
            Console.WriteLine("SessionId:{0}, SessionStatus:{1}, SessionKey:{2}", sessionId, sessionStatus, sessionKeyString);

            if(isSessionAlive(sessionKeyString))
            {
                /*Only the sender can terminate a session*/
                ScreencastingSession screencastSession = sessions[sessionKeyString];
                if(screencastSession.senderId == sessionId)
                {
                    sessions.Remove(sessionKeyString);
                    screencastSession.authenticatedClients.Clear();
                    sessionStatus = 0;
                    return;
                }
            }

            sessionStatus = 1;
        }
Beispiel #15
0
        public void OnSessionTerminationRequested(Client client, UInt32 sessionId, char[] sessionKey, ref UInt32 sessionStatus)
        {
            if (isSessionAlive(sessionKey))
            {
                ScreencastingSession screencastSession = getSessionByKey(sessionKey);

                /* Only the sender can terminate a session */
                if (screencastSession.senderId == sessionId)
                {
                    sessionStatus = 0;
                    foreach(Client authenticatedClient in screencastSession.authenticatedClients.Keys)
                    {
                        UInt32 clientSessionId = screencastSession.authenticatedClients[authenticatedClient].sessionId;

                        try
                        {
                            authenticatedClient.OnSessionTermination(clientSessionId, sessionKey, sessionStatus);
                        }
                        catch (TransportException e)
                        {
                            Console.WriteLine("Caught Transport Exception: " + e.Message);
                            screencastSession.RemoveAuthenticatedUser(authenticatedClient);
                        }
                    }
                    screencastSession.authenticatedClients.Clear();
                    sessions.TryRemove(new string(sessionKey), out screencastSession);
                    return;
                }
            }

            sessionStatus = 1;
        }
Beispiel #16
0
        public void OnRecvMouseEvent(Client client, UInt32 sessionId, char[] sessionKey, ref UInt32 sessionStatus, UInt16 pointerFlags, int x, int y)
        {
            if (isSessionAlive(sessionKey))
            {
                ScreencastingSession screencastSession = getSessionByKey(sessionKey);
                screencastSession.SendMouseEventToSender(pointerFlags, x, y);
                return;
            }

            sessionStatus = 1;
        }
Beispiel #17
0
 public void OnSessionTermRemoteAccessRequested(Client client, char[] sessionKey, string username)
 {
     ScreencastingSession screencastSession = getSessionByKey(sessionKey);
     screencastSession.TermRemoteAccessRequested(username);
 }
Beispiel #18
0
        public void OnSessionAuthenticationRequested(Client client, UInt32 sessionId, char[] sessionKey, string username, string password, ref UInt32 sessionStatus)
        {
            if (isSessionAlive(sessionKey))
            {
                ScreencastingSession screencastSession = getSessionByKey(sessionKey);

                if (screencastSession.Authenticate(client, sessionId, username, password))
                {
                    OnSessionParticipantListUpdated(screencastSession.sessionKey);
                    screencastSession.UpdateNotifications("joined",username);
                    sessionStatus = 0;
                    return;
                }
            }

            sessionStatus = 1;
        }
Beispiel #19
0
        public void OnRecvKeyboardEvent(Client client, UInt32 sessionId, char[] sessionKey, ref UInt32 sessionStatus, UInt16 pointerFlag, UInt16 keyCode)
        {
            Console.WriteLine("SessionManager.OnRecvKeyboardEvent sessionKey: {0} keyCode: {1}",
                              new string(sessionKey), keyCode);

            if (isSessionAlive(sessionKey))
            {
                ScreencastingSession screencastSession = getSessionByKey(sessionKey);
                screencastSession.SendKeyboardEventToSender(pointerFlag, keyCode);
                return;
            }

            sessionStatus = 1;
        }
Beispiel #20
0
        public void OnSessionCreateRequested(Client client, string username, string password, ref UInt32 sessionId, ref char[] sessionKey)
        {
            sessionId = GenerateUniqueSessionId();
            sessionKey = GenerateUniqueSessionKey();

            ScreencastingSession screencastSession = new ScreencastingSession(sessionKey, sessionId, username, password, client);

            sessions.TryAdd(new string(sessionKey), screencastSession);
            screencastSession.AddFirstUser(client, sessionId, username);
        }
 public void AddJoinedUser(Client client, UInt32 id)
 {
     joinedClients.TryAdd(client, id);
 }
Beispiel #22
0
        public void OnSessionJoinRequested(Client client, char[] sessionKey, ref UInt32 sessionId, ref UInt32 sessionStatus, ref byte sessionFlags)
        {
            if (isSessionAlive(sessionKey))
            {
                ScreencastingSession screencastSession = getSessionByKey(sessionKey);
                sessionId = GenerateUniqueSessionId();
                screencastSession.AddJoinedUser(client, sessionId);
                sessionStatus = 0;

                if (screencastSession.isPasswordProtected())
                    sessionFlags = SESSION_FLAGS_PASSWORD_PROTECTED;
                else
                    sessionFlags = SESSION_FLAGS_NON_PASSWORD_PROTECTED;

                return;
            }

            sessionStatus = 1;
        }
        public bool Authenticate(Client client, UInt32 sessionId, string username, string password)
        {
            bool isAuthenticated = (this.sessionPassword.Equals(password) && isUsernameUnique(username));

            if (isAuthenticated)
            {
                this.AddAuthenticatedUser(client, sessionId, username);
            }

            return isAuthenticated;
        }
Beispiel #24
0
        public void OnSessionLeaveRequested(Client client, UInt32 sessionId, char[] sessionKey, ref UInt32 sessionStatus, string username)
        {
            if (isSessionAlive(sessionKey))
            {
                ScreencastingSession screencastSession = getSessionByKey(sessionKey);

                if (screencastSession.authenticatedClients.ContainsKey(client))
                {
                    screencastSession.RemoveAuthenticatedUser(client, username, sessionId);
                    OnSessionParticipantListUpdated(screencastSession.sessionKey);
                    sessionStatus = 0;

                    return;
                }
            }

            sessionStatus = 1;
        }
        public void GrantRemoteAccess(Client senderClient, string receiverUsername)
        {
            string potentialSenderUsername = authenticatedClients[senderClient].username;

            if(senderUsername.Equals(potentialSenderUsername))
            {
                Client receiverClient = remoteControlRequestClients[receiverUsername];

                if(receiverClient != null)
                {
                    remoteControlRequestClients.TryRemove(receiverUsername, out receiverClient);
                    remoteController = receiverClient;
                    UpdateNotifications("control of", receiverUsername);
                }
            }
        }
Beispiel #26
0
 public void OnSessionRemoteAccessPermissionSet(Client client, char[] sessionKey, string username, Boolean permission)
 {
     ScreencastingSession screencastSession = getSessionByKey(sessionKey);
     if(permission)
     {
         screencastSession.GrantRemoteAccess(client, username);
     }
     else
     {
         screencastSession.DenyRemoteAccess(client, username);
     }
 }
 public void TermRemoteAccessRequested(string username)
 {
     remoteController = this.senderClient;
     remoteControlRequestClients.Clear();
     UpdateNotifications("control of", this.senderUsername);
 }
Beispiel #28
0
 public void OnSessionRemoteAccessRequested(Client receiverClient, char[] sessionKey, string username)
 {
     ScreencastingSession screencastSession = getSessionByKey(sessionKey);
     screencastSession.AddRemoteAccessRequest(receiverClient, username);
 }
        public void AddAuthenticatedUser(Client client, UInt32 id, string username)
        {
            Boolean done = false;

            while (!done)
            {
                User user;
                user.sessionId = id;
                user.username = username;
                authenticatedClients.TryAdd(client, user);
                done = true;
            }

            UpdateFirstNotifications("joined",username, senderUsername);
        }
        public void OnSessionJoinRequested(Client client, char[] sessionKey, ref UInt32 sessionId, ref UInt32 sessionStatus, ref byte sessionFlags)
        {
            Console.WriteLine("ScreenSessions.OnSessionJoinRequested");

            string sessionKeyString = new string(sessionKey);
            Console.WriteLine("SessionKey:{0}", sessionKeyString);

            if(isSessionAlive(sessionKeyString))
            {
                ScreencastingSession screencastSession = sessions[sessionKeyString];
                sessionId = GenerateUniqueId();
                screencastSession.AddJoinedUser(client, sessionId);
                sessionStatus = 0;
                return;
            }

            sessionStatus = 1;
        }