Пример #1
0
        /// <summary>
        /// Crée l'utilisateur en fonction des informations fournies.
        /// </summary>
        /// <param name="info"></param>
        /// <returns>True si créé avec succès. False autrement.</returns>
        public bool CreateUser(Models.CreateUserInfo info)
        {
            try
            {
                using (MilleBornesEntities context = new MilleBornesEntities())
                {
                    // Vérification basiques.
                    if (info.Email.Trim() == "" || !info.Email.Contains("@"))
                        return false;

                    if (info.Username.Trim().Length < 2 || info.Password.Length < 3)
                        return false;

                    User user = new User();
                    user.Name = info.Username.Trim();
                    user.PasswordHash = GetSHA1HashString(info.Password);
                    user.EmailAddress = info.Email.Trim();

                    // Si l'utilisateur est déjà présent, soit email soit name.
                    if (context.User.Where(p => p.Name == user.Name
                        || user.EmailAddress == p.EmailAddress).Count() > 0)
                    {
                        return false;
                    }


                    context.User.Add(user);
                    context.SaveChanges();
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }
Пример #2
0
        private void DrawCard(Game game, User user, int cardId)
        {
            game.GameEvent.Add(new DrawCardEvent()
            {
                ServerEvent = true,
                Date = DateTime.UtcNow,
                Type = GameEventType.DRAW_CARD,

                CardIndex = cardId,
                Token = Guid.NewGuid(),
                User = user
            });
        }
Пример #3
0
        private void DrawNewCardToPlayer(Game game, User user)
        {
            var remainingDeck = GetRemainingCards(game);

            if (remainingDeck.Length <= 0)
            {
                return;
            }

            Random random = new Random();
            int listIndex = random.Next(remainingDeck.Length);
            DrawCard(game, user, remainingDeck[listIndex]);
        }