Ejemplo n.º 1
0
        public void JoinGameAsSpectator(User userToJoin, IGame gameToJoin)
        {
            var properties = gameToJoin.GetProperties();

            if (gameToJoin.GetProperties().IsClosed)
            {
                var msg = "The game " + properties.GameIdentifier + " to join was closed!";
                ErrorLogger.Error(msg);
                throw new InvalidExpressionException(msg);
            }
            var userState = userToJoin.GetPlayerState();

            if (userState == PlayerState.InLobby)
            {
                JoinGame(userToJoin, gameToJoin);
                userToJoin.ChangePlayerState(PlayerState.Spectator);
                gameToJoin.AddSpectator(userToJoin);
            }
            else
            {
                var msg = "User " + userToJoin.PlayerName + "[" + userState + "] can't join the game: " + gameToJoin.GetProperties().GameIdentifier;
                ErrorLogger.Error(msg);
                throw new InvalidOperationException(msg);
            }
        }
Ejemplo n.º 2
0
 public static bool IsAdministrator(User u)
 {
     RoleManagementService roleManagementService = new RoleManagementService(RoleManagementService.Application);
     IEnumerable<Role> userRoles = roleManagementService.FindRoles(u.Id);
     Role adminRole = userRoles.FirstOrDefault(r => r.Name == Settings.Default.AdministratorRoleName);
     return adminRole != null;
 }
Ejemplo n.º 3
0
        public void CreazioneUtente()
        {
            string message;
            string name        = "gigi";
            string surname     = "zonu";
            string country     = "cagliari";
            string street      = "roma";
            string number      = "1";
            string password    = "******";
            string email       = "*****@*****.**";
            string email1      = "*****@*****.**";
            string passwors_n1 = "111Acbmm";
            string email2      = "*****@*****.**";
            string password_n2 = "111Acbmm";

            List <UserManagement.User> people;

            UserManagement.Address address = new UserManagement.Address(country, street, number);

            UserManagement.User.NewUser(name, surname, password, email, address, out message);

            UserManagement.User user = UserManagement.User.FindByEmail(email, out message);

            //Check fields
            Assert.IsNotNull(user);
            Assert.AreEqual(name, user.Name);
            Assert.AreEqual(surname, user.Surname);


            //Check count
            people = UserManagement.User.FindByName(name, surname, out message);

            Assert.IsTrue(people.Count == 1);

            //Add second user
            User.NewUser(name, surname, passwors_n1, email1, address, out message);

            User utente = UserManagement.User.FindByEmail(email1, out message);

            //Check fields
            Assert.IsNotNull(utente);
            Assert.AreEqual(name, utente.Name);
            Assert.AreEqual(surname, utente.Surname);


            //Check count
            people = User.FindByName(name, surname, out message);

            Assert.IsTrue(people.Count == 2);

            //Add third user
            User.NewUser(name, surname, password_n2, email2, address, out message);
            //creo tre utenti con lo stesso nome e cognome, poi effettuo una ricerca utilizzando nome e cognome, infine controllo il
            //numero di risultati trovati che deve essere uguale a 3

            people = UserManagement.User.FindByName(name, surname, out message);

            //check count list
            Assert.IsTrue(people.Count == 3);
        }
Ejemplo n.º 4
0
        public void ModificaUtente()
        {
            //creo un nuovo utente, effettuo il login, modifico il nome
            //e verifico che il nome sia effetivamente cambiato
            string message;
            string name     = "gigi";
            string surname  = "zonu";
            string luogo    = "cagliari";
            string street   = "nazionale";
            string number   = "1";
            string password = "******";
            string email    = "*****@*****.**";

            System.Console.WriteLine("welcome");

            UserManagement.Address address = new UserManagement.Address(luogo, street, number);

            UserManagement.User.NewUser(name, surname, password, email, address, out message);
            UserManagement.User utente = UserManagement.User.Authenticate(email, password, out message);

            string newName    = "ale";
            string newSurname = "zonu";

            utente.ModifiedData(newName, newSurname, out message);
            UserManagement.User userfind = UserManagement.User.FindByEmail(email, out message);


            System.Console.WriteLine(message);
            //Check fields
            Assert.IsNotNull(userfind);
            Assert.AreEqual(newName, userfind.Name);
            Assert.AreEqual(newSurname, userfind.Surname);
        }
Ejemplo n.º 5
0
        private bool IsHighestRankingUser(User user)
        {
            lock (_serverLock)
            {
                var userLeague    = _usersLeagues[user];
                var highestLeague = _leaguesByType.Last().Value;
                var highestUser   = highestLeague.GetMaxRankedUser();

                return(userLeague != null && userLeague.Type >= highestLeague.Type &&
                       user.GetRank() >= highestUser.GetRank());
            }
        }
Ejemplo n.º 6
0
        public bool IsUserInLeague(LeagueType leagueType, User userTosearch)
        {
            var league = _leaguesByType[leagueType];

            if (!_usersLeagues.ContainsKey(userTosearch))
            {
                return(false);
            }

            var foundLeague = _usersLeagues[userTosearch];

            return(foundLeague.Type == league.Type);
        }
Ejemplo n.º 7
0
 public void AddUserToLeague(LeagueType leagueType, User userToAdd)
 {
     lock (_serverLock)
     {
         var league = _leaguesByType[leagueType];
         if (!league.CanBeInLeague(userToAdd))
         {
             return;
         }
         league.AddUserToLeague(userToAdd);
         _usersLeagues.Add(userToAdd, league);
     }
 }
Ejemplo n.º 8
0
        public void UpdateUserRank(User player, GameProperties gameProperties)
        {
            var hands    = gameProperties.HighestHand;
            var handRank =
                (from hand in hands where hand.Value.Equals(player) select(int) hands.Max().Key - (int)hand.Key)
                .FirstOrDefault();

            var bets    = gameProperties.HighestBet;
            var betRank =
                (from bet in bets where bet.Value.Equals(player) select bets.Max().Key - bet.Key)
                .FirstOrDefault();

            player.SetRank(player.GetRank() + handRank + betRank);
        }
Ejemplo n.º 9
0
 private void JoinGame(User userToJoin, IGame gameToJoin)
 {
     lock (_serverLock)
     {
         if (_usersInActiveGame.ContainsKey(userToJoin))
         {
             _usersInActiveGame[userToJoin].Add(gameToJoin);
         }
         else
         {
             _usersInActiveGame.Add(userToJoin, new List <IGame> {
                 gameToJoin
             });
         }
     }
 }
Ejemplo n.º 10
0
        public void LeaveGame(User userToLeave, IGame game)
        {
            game.DeleteUser(userToLeave);
            lock (_serverLock)
            {
                if (!_usersInActiveGame.ContainsKey(userToLeave))
                {
                    return;
                }

                if (_usersInActiveGame[userToLeave].Contains(game))
                {
                    _usersInActiveGame[userToLeave].Remove(game);
                }
                else
                {
                    const string msg = "The game is not registered with the user.";
                    ErrorLogger.Warn(msg);
                    throw new InvalidExpressionException(msg);
                }
            }

            UpdateUserRank(userToLeave, game.GetProperties());
        }
Ejemplo n.º 11
0
 public void SetDefaultLeagueType(User setter, LeagueType defaultType)
 {
     _defaultLeagueType = defaultType;
 }
Ejemplo n.º 12
0
        private static void SyncUserWithExternalDirectory(UserManagementMembershipUser membershipUser, ref User u)
        {
            // if the user is null, create it
            u = u ?? UserManagementService.CreateUser(membershipUser.UserName, membershipUser.Email, null);

            // if anything has changed since the last time this user logged in, update our copy
            if (u.Email != membershipUser.Email)
            {
                u.Email = membershipUser.Email;
                UserManagementService.UpdateUser(u, u);
            }

            if (u.Name != membershipUser.Name)
            {
                u.Name = membershipUser.Name;
                UserManagementService.UpdateUser(u, u);
            }
        }