public ChatRoom(string chatRoomName, ChatUser user)
        {
            if (chatRoomName == null) 
                throw new Exception("Chat room name is null");
            _chatRoomName = chatRoomName;
            _usersList.Add(user.Username, user);

            _newMessages.Add(user.Username, "");

            _display = new RoomDisplay();
        }
Esempio n. 2
0
 public RequestStatus CreateRoom(string roomName, ChatUser user)
 {
     try
     {
         _chatRooms.Add(roomName, new ChatRoom(roomName, user));
         return RequestStatus.Success;
     }
     catch (Exception)
     {
         return RequestStatus.RoomAlreadyExists;
     }
 }
Esempio n. 3
0
 public RequestStatus CreateUser(string username)
 {
     var user = new ChatUser(username,new UserDisplay("NONE",username));
     try
     {
         _users.Add(username,user);
         return RequestStatus.Success;
     }
     catch (Exception)
     {
         return RequestStatus.UserAlreadyExists;
     }
 }
        public RequestStatus AddUser(ChatUser user)
        {
            if (!RoomHasSpace())
                return RequestStatus.RoomIsFull;

            try
            {
                _usersList.Add(user.Username, user);
                _newMessages.Add(user.Username, "");
            }
            catch (Exception)
            {
                return RequestStatus.UserAlreadyExists;
            }

            _display.Write(DisplayCommands.NewUserAdded(user.Username));

            return RequestStatus.Success;
        }
        public RequestStatus RemoveUser(ChatUser user)
        {
            RemoveUserFromListOfAllUsers(user);
            if (_usersList.Count <= 0)
            {
                RemoveRoomIfEmpty();
                return RequestStatus.RoomIsEmpty;
            }

            try
            {
                _usersList.Remove(user.Username);
                RemoveRoomIfEmpty();
                return RequestStatus.Success;
            }
            catch (Exception)
            {
                return RequestStatus.UserNotFound;
            }
        }
 private void RemoveUserFromListOfAllUsers(ChatUser user)
 {
     Singleton.GetServer.RemoveUser(user.Username);
 }