Beispiel #1
0
 public Player(User user)
     : this()
 {
     UserId = user.Id;
     IsConfirmed = false;
     GamesPlayed = user.GamesPlayed;
 }
        public ActionResult AuthenticationCallback()
        {
            var result = OAuthWebSecurity.VerifyAuthentication();
            if (result.IsSuccessful)
            {
                int uniqueUserID = int.Parse(result.ProviderUserId);
                if (Users.GetUserByVkId(uniqueUserID) == null)
                {
                    User newUser = new User();
                    newUser.PasswordHash = null;
                    newUser.Email = result.ExtraData["email"];
                    newUser.LastActivity = DateTime.Now;
                    newUser.Nickname = result.UserName;
                    newUser.VkId = uniqueUserID;
                    newUser.VkAccessToken = result.ExtraData["accessToken"];
                    if (Users.Add(newUser) == false)
                    {
                        NotificationManager.Instance.Add("Can't add user data to DB, perhaps, we already have user with this e-mail", NotificationType.Error);
                        return RedirectToAction("Index", "Home");
                    }
                }

                if (Auth.Login(uniqueUserID, result.ExtraData["email"]) == null)
                {
                    NotificationManager.Instance.Add("Can't authenticate user with provided data", NotificationType.Error);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    return RedirectToAction("Index", "Home");
                }
            }
            NotificationManager.Instance.Add("Can't complete VK authentication", NotificationType.Error);
            return RedirectToAction("Index", "Home");
        }
Beispiel #3
0
 public void Init(string email, UserRepository repository)
 {
     if (!string.IsNullOrEmpty(email))
     {
         User = repository.GetUser(email);
         User.LastActivity = DateTime.Now;
         repository.ForceSaveChanges();
     }
 }
Beispiel #4
0
 public void PushMessageToUser(User User, AsyncMessage asyncMessage)
 {
     lock (_lock)
     {
         var clientState = _clientStateList.FirstOrDefault(x => x.User.Id == User.Id);
         if (clientState != null)
         {
             clientState.Push(asyncMessage);
         }
     }
 }
Beispiel #5
0
 public bool Add(User instance)
 {
     var user = GetUser(instance.Email);
     if (user != null)
         return false;
     try
     {
         instance.Id = Guid.NewGuid();
         instance.PasswordHash = PasswordCryptor.Crypt(instance.PasswordHash);
         DB.Users.Add(instance);
         DB.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
Beispiel #6
0
 public List<UserFriendData> GetPotentialFriendListByNickname(string nicknamePart, User sender)
 {
     var result = DB.Users.Where(p => p.Nickname.Contains(nicknamePart) && p.Id != sender.Id)
                     .Select(f => new UserFriendData
                     {
                         ID = f.Id,
                         Nickname = f.Nickname,
                         GamesPlayed = f.GamesPlayed,
                         GamesWon = f.GamesWon,
                     }).ToList();
     foreach (var friend in result)
     {
         friend.FriendAlready = sender.Friends.Any(f => f.Id == friend.ID);
     }
     return result;
 }
 public ActionResult Register(RegisterModel reg)
 {
     if (CurrentUser == null)
     {
         if (ModelState.IsValid)
         {
             var user = new User();
             user.Email = reg.Email;
             user.Nickname = reg.Nickname;
             user.PasswordHash = reg.Password;
             user.LastActivity = DateTime.Now;
             if (Users.Add(user) == false)
                 return View(reg);
             else
                 return RedirectToAction("Index", "Home");
         }
         else
             return View(reg);
     }
     else
         return RedirectToAction("Index", "Home");
 }
Beispiel #8
0
        public void UserJoinLobby(User user, Guid? lobbyId)
        {
            if (!lobbyId.HasValue)
                throw new WrongLobbyIdException();

            Match match = MatchManager.Instance.FindMatchByParticipantID(user.Id);
            if (match != null)
                throw new AlreadyInMatchException();

            match = MatchManager.Instance.Matches.Where(m => m.Id == lobbyId).FirstOrDefault();
            if (match == null)
                throw new WrongLobbyIdException();

            if (match.Players.Count > 3)
                throw new LobbyIsFullException();

            Matchmaking.Instance.Players.RemoveAll(p => p.UserId == user.Id);

            match.SendMessageToPlayers(new AsyncMessage(MessageType.LobbyUpdate));
            match.Players.Add(new Player(user));
        }
Beispiel #9
0
        public bool KickUserFromLobby(User invitingUser, Guid userToInviteId)
        {
            Match lobby = MatchManager.Instance.FindMatchByParticipantID(invitingUser.Id, true);
            if (lobby == null)
                return false;

            UserLeaveFromLobby(userToInviteId);
            return true;
        }
Beispiel #10
0
        public MatchInvite InviteUserToLobby(User invitingUser, Guid userToInviteId)
        {
            Match lobby = MatchManager.Instance.FindMatchByParticipantID(invitingUser.Id, true);
            if (lobby == null)
                return null;

            MatchInvite invite = new MatchInvite(lobby.Id, invitingUser, userToInviteId);
            MatchManager.Instance.MatchInvites.Add(invite);
            return invite;
        }
Beispiel #11
0
        public Match GetOrCreateNewMatchForUser(User user)
        {
            Match match = FindMatchByParticipantID(user.Id);
            if (match == null)
            {
                match = CreateMatch();

                match.State = Munchkin_Online.Core.Game.State.Lobby;
                match.Creator = new Player(user);
                match.Players.Add(new Player(user));
            }

            return match;
        }