Ejemplo n.º 1
0
        // Methods

        internal static SignupUser FilterSignupUser(SignupUser user)
        {
            string username = user.Username.Trim();

            username = username[0].ToString().ToUpper() + username.Substring(1);
            if (!IsUsernameValid(username))
            {
                return(null);
            }

            int id = new Random().Next(9999, 99999);

            while (DBSupport.IsSignupIdExist(id))
            {
                id = new Random().Next(9999, 99999);
            }

            return(new SignupUser
            {
                Id = id,
                Username = username,
                Password = user.Password,
                Gender = !string.IsNullOrEmpty(user.Gender) ? user.Gender : string.Empty,
                Age = user.Age,
            });
        }
Ejemplo n.º 2
0
        internal static ChatUser FilterUser(User user, string photoWebPath)
        {
            // In case if user type admin as nick
            if (user.Username.Equals("admin", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            string username = user.Username.Trim();

            username = username[0].ToString().ToUpper() + username.Substring(1);
            if (!IsUsernameValid(username))
            {
                return(null);
            }

            int id = new Random().Next(9999, 99999);

            while (DBSupport.IsIdExist(id))
            {
                id = new Random().Next(9999, 99999);
            }

            return(new ChatUser
            {
                Id = id,
                Username = username,
                Gender = !string.IsNullOrEmpty(user.Gender) ? user.Gender : null,
                Age = user.Age,
                IsMod = 0,
                Photo = photoWebPath
            });
        }
Ejemplo n.º 3
0
        internal static string[] ExceptUsers(ChatUser chatClient)
        {
            List <string> blockedUsersOfClient = chatClient.Blocks.Split(';').ToList();

            blockedUsersOfClient.Remove("");
            string[] blockedUsers          = DBSupport.GetUsers().Where(x => blockedUsersOfClient.Any(y => y.Equals(x.Username))).Select(x => x.ConnectionId).ToArray();
            string[] usersWhoBlockedClient = DBSupport.GetUsers().Where(x => x.Blocks.Contains(chatClient.Username)).Select(x => x.ConnectionId).ToArray();
            string[] client = new string[1] {
                chatClient.ConnectionId
            };
            string[] exceptUsers = blockedUsers.Concat(usersWhoBlockedClient).Concat(client).Distinct().ToArray();
            return(exceptUsers);
        }
Ejemplo n.º 4
0
        public static void DeleteSignedOffUsers(Object source, System.Timers.ElapsedEventArgs e)
        {
            IEnumerable <ChatUser> users = GetUsers();

            List <string> bots = new List <string>()
            {
                "AaShQii", "Aliza", "AmirJoya", "Ayaan", "Baazigarr", "BholaBacha", "Blood_Seeker", "Diyyaa",
                "Eman", "FireCracker", "GreeN-Eyes", "Hamza26", "Iffi", "James", "Jazib", "JDee", "JohnSnow",
                "Khanaa", "Khoobsoorat", "King_of_Hrtzz", "LalaGujjar", "MamooJaan", "Manal", "Mubeen", "Mystic",
                "Namaloom", "Neha", "Peshawar_Man", "RaffatKhan", "Sara", "SarfarazJutt", "StevePapp", "Zain",
                "Uzair", "GaNdA_BaChA", "Dewana", "Bilal25", "Sehrish", "SpiderBoy", "Shahzad_akram"
            };

            if (users != null)
            {
                foreach (var item in users)
                {
                    if (bots.Where(x => x == item.Username).Count() == 0 && item.ConnectTime < DateTime.UtcNow.AddHours(5).AddMinutes(-20))
                    {
                        if (DeleteUser(item.Username))
                        {
                            if (!string.IsNullOrEmpty(item.Photo))
                            {
                                string image = SharedSupport.GetImageFolderPath() + item.Username + item.Photo.Substring(item.Photo.LastIndexOf("."));
                                if (System.IO.File.Exists(image))
                                {
                                    System.IO.File.Delete(image);
                                }
                            }

                            IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <Chat>();
                            hubContext.Clients.AllExcept(item.ConnectionId).userLeft(item.Username);
                            hubContext.Clients.All.totalUsers(DBSupport.GetUsersCount());
                            hubContext.Clients.Client(item.ConnectionId).forceDisconnect();
                            hubContext.Clients.All.dcUserSessions(item.Username);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void SignOff(object user)
        {
            ChatUser botUser = new ChatUser();

            foreach (System.Reflection.PropertyInfo pInfo in user.GetType().GetProperties())
            {
                string pName = pInfo.Name;
                foreach (System.Reflection.PropertyInfo pbInfo in botUser.GetType().GetProperties())
                {
                    if (pName.Equals(pbInfo.Name))
                    {
                        pbInfo.SetValue(botUser, pInfo.GetValue(user, null));
                        break;
                    }
                }
            }

            DBSupport.DeleteUser(botUser.Username);
            IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <Chat>();

            hubContext.Clients.All.userLeft(botUser.Username);
            hubContext.Clients.All.totalUsers(DBSupport.GetUsersCount());
        }