Example #1
0
 private void AddUserToChannel(UserSession userSession, int target)
 {
     var channel = channelSessions.FirstOrDefault(c => c.Channel.Id == target);
     if (channel == null)
     {
         // "Default Channel" configurable at a later time.
         // for now, just the first one.
         channelSessions[0].AddUser(userSession);
     }
     else
     {
         channel.AddUser(userSession);
         //channel.Users.Add(userInfo);
     }
 }
        private UserInfoViewModel RemoveUserFromChannels(UserSession userSession)
        {
            var user = FindUser(userSession.ConnectionId);
            if (user == null)
            {
                AddActivity("Unable to find user {0} from channel {1} in order to remove user", userSession.UserInfo.Username, userSession.ChannelId);
                return null;
            }

            foreach (var channel in ChannelTreeViewModel.Channels)
            {
                channel.Users.Remove(user);
            }

            return user;
        }
Example #3
0
 public UserInfoViewModel(UserSession userSession)
 {
     this.userSession = userSession;
 }
Example #4
0
        private void RemoveUserFromChannel(UserSession userSession)
        {
            if (userSession == null)
            {
                return;
            }

            var source = channelSessions.FirstOrDefault(ch => ch.Channel.Id == userSession.ChannelId);
            if (source == null)
            {
                Console.WriteLine("RemoveUserFromChannel: unable to find channel session id {0}", userSession.ChannelId);
                return;
            }
            var user = source.UserSessions.FirstOrDefault(u => u.ConnectionId == userSession.ConnectionId);
            source.RemoveUser(user);
        }
Example #5
0
        private void CredentialRequestHandlerSuccess(NetworkClient client, UserSession userSession)
        {
            userSession.ConnectionId = Guid.NewGuid();
            client.UserSession = userSession;
            AddUserToChannel(userSession, 0);

            var response = new UserCredentialResponse();
            response.UserSession = userSession;
            response.IsAuthenticated = true;
            response.Message = "Great success!";
            BroadcastAll(client, Message.Create(MessageType.UserConnected, userSession));
            client.WriteMessage(Message.Create(MessageType.CredentialResponse, response));
        }
Example #6
0
        private void CredentialRequestHandler(NetworkClient client, Message message)
        {
            try
            {
                var credential = message.GetData<UserInfo>();
                // Handle credential authorization
                if (string.IsNullOrWhiteSpace(credential.Username))
                {
                    var userSession = new UserSession();
                    userSession.UserInfo = new UserInfo() { Username = "******" + new Random().Next(10000) };
                    CredentialRequestHandlerSuccess(client, userSession);
                }

                if (userService.IsUserAuthenticated(credential.Username, credential.Password))
                {
                    var userSession = new UserSession();
                    userSession.UserInfo = userService.GetUserByUsername(credential.Username);
                    CredentialRequestHandlerSuccess(client, userSession);
                }

                CredentialRequestHandlerFail(client);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                CredentialRequestHandlerFail(client);
            }
        }
Example #7
0
 public void RemoveUser(UserSession userSession)
 {
     UserSessions.Remove(userSession);
     userSession.ChannelId = -1;
 }
Example #8
0
 public void AddUser(UserSession userSession)
 {
     // validation logic for adding user here
     UserSessions.Add(userSession);
     userSession.ChannelId = Channel.Id;
 }