Ejemplo n.º 1
0
        public void RefreshGameView(Int32 gameID, Entities.Enums.ConnectionType connectionType)
        {
            Join(gameID, connectionType);

            AS.GameRound.Base.ISelect          _selectGameRound  = BusinessLogic.UnityConfig.Container.Resolve <AS.GameRound.Base.ISelect>();
            AS.Game.Base.ISelect               _selectGame       = BusinessLogic.UnityConfig.Container.Resolve <AS.Game.Base.ISelect>();
            AS.GamePlayerKickVote.Base.ISelect _selectVotes      = BusinessLogic.UnityConfig.Container.Resolve <AS.GamePlayerKickVote.Base.ISelect>();
            AS.ActiveConnection.Base.ISelect   _selectConnection = BusinessLogic.UnityConfig.Container.Resolve <AS.ActiveConnection.Base.ISelect>();

            Int32 currentUserId = Authentication.Security.CurrentUserId;

            Entities.ActiveConnection connection = _selectConnection.Execute(new Entities.Filters.ActiveConnection.Select(Context.ConnectionId, currentUserId));

            Entities.Filters.GamePlayerKickVote.SelectForGame kickVoteFilter = new Entities.Filters.GamePlayerKickVote.SelectForGame();
            kickVoteFilter.GameID = gameID;

            List <Entities.GamePlayerKickVote> votes = _selectVotes.Execute(kickVoteFilter);
            IEnumerable <IGrouping <Int32, Entities.GamePlayerKickVote> > grouped = votes.GroupBy(x => x.KickUserId);

            Entities.Models.Game.Board.VoteToKick kickModel = null;

            List <Entities.Models.Game.Board.VoteToKick> votesToKick = new List <Entities.Models.Game.Board.VoteToKick>();

            foreach (IGrouping <Int32, Entities.GamePlayerKickVote> group in grouped)
            {
                if (group.FirstOrDefault(x => x.VotedUserId == currentUserId) == null)
                {
                    kickModel = new Entities.Models.Game.Board.VoteToKick(group.First().KickUser,
                                                                          group.Count(x => x.Vote),
                                                                          group.Count(x => !x.Vote));

                    votesToKick.Add(kickModel);
                }
            }

            List <Entities.GameRound> completedRounds = _selectGameRound.Execute(new Entities.Filters.GameRound.SelectCompleted(gameID));

            Entities.Game game = _selectGame.Execute(new Entities.Filters.Game.Select
            {
                GameID       = gameID,
                DataToSelect = Entities.Enums.Game.Select.GamePlayerCards | Entities.Enums.Game.Select.Rounds
            });

            Entities.Enums.GamePlayerType playerType = (connection != null && connection.ConnectionType == Entities.Enums.ConnectionType.GamePlayer) ?
                                                       Entities.Enums.GamePlayerType.Player :
                                                       Entities.Enums.GamePlayerType.Spectator;

            Entities.Models.Game.Board.GameBoard model =
                new Entities.Models.Game.Board.GameBoard(game,
                                                         currentUserId,
                                                         playerType,
                                                         votesToKick,
                                                         completedRounds);

            Clients.Client(Context.ConnectionId).UpdateGameView(model, model.LobbyViewModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Alert the users a vote to kick has been placed
        /// </summary>
        /// <param name="gameID">The game ID</param>
        /// <param name="kickedUser">The user that was being voted on</param>
        /// <param name="votesToKick">The number of votes to kick</param>
        /// <param name="votesNotToKick">The number votes not to kick</param>
        /// <param name="alreadyVoted">UserIds for users that have already voted</param>
        public void Voted(Int32 gameID, Entities.User kickedUser, Int32 votesToKick, Int32 votesNotToKick, List <Int32> alreadyVoted)
        {
            List <Entities.ActiveConnection> connections = GetConnections(gameID, alreadyVoted);

            foreach (Entities.ActiveConnection connection in connections.Where(x => x.ConnectionType == Entities.Enums.ConnectionType.GamePlayer))
            {
                Entities.Models.Game.Board.VoteToKick model = new Entities.Models.Game.Board.VoteToKick(kickedUser, votesToKick, votesNotToKick);

                _hub.Clients.Client(connection.ActiveConnectionID).AlertUsersVote(model);
            }
        }
Ejemplo n.º 3
0
        public void RefreshGameView(Int32 gameID, Entities.Enums.ConnectionType connectionType)
        {
            Join(gameID, connectionType);

            AS.GameRound.Base.ISelect _selectGameRound = BusinessLogic.UnityConfig.Container.Resolve<AS.GameRound.Base.ISelect>();
            AS.Game.Base.ISelect _selectGame = BusinessLogic.UnityConfig.Container.Resolve<AS.Game.Base.ISelect>();
            AS.GamePlayerKickVote.Base.ISelect _selectVotes = BusinessLogic.UnityConfig.Container.Resolve<AS.GamePlayerKickVote.Base.ISelect>();
            AS.ActiveConnection.Base.ISelect _selectConnection = BusinessLogic.UnityConfig.Container.Resolve<AS.ActiveConnection.Base.ISelect>();

            Int32 currentUserId = Authentication.Security.CurrentUserId;
            Entities.ActiveConnection connection = _selectConnection.Execute(new Entities.Filters.ActiveConnection.Select(Context.ConnectionId, currentUserId));

            Entities.Filters.GamePlayerKickVote.SelectForGame kickVoteFilter = new Entities.Filters.GamePlayerKickVote.SelectForGame();
            kickVoteFilter.GameID = gameID;

            List<Entities.GamePlayerKickVote> votes = _selectVotes.Execute(kickVoteFilter);
            IEnumerable<IGrouping<Int32, Entities.GamePlayerKickVote>> grouped = votes.GroupBy(x => x.KickUserId);

            Entities.Models.Game.Board.VoteToKick kickModel = null;

            List<Entities.Models.Game.Board.VoteToKick> votesToKick = new List<Entities.Models.Game.Board.VoteToKick>();

            foreach (IGrouping<Int32, Entities.GamePlayerKickVote> group in grouped)
            {
                if (group.FirstOrDefault(x => x.VotedUserId == currentUserId) == null)
                {
                    kickModel = new Entities.Models.Game.Board.VoteToKick(group.First().KickUser,
                                                                 group.Count(x => x.Vote),
                                                                 group.Count(x => !x.Vote));

                    votesToKick.Add(kickModel);
                }
            }

            List<Entities.GameRound> completedRounds = _selectGameRound.Execute(new Entities.Filters.GameRound.SelectCompleted(gameID));

            Entities.Game game = _selectGame.Execute(new Entities.Filters.Game.Select
            {
                GameID = gameID,
                DataToSelect = Entities.Enums.Game.Select.GamePlayerCards | Entities.Enums.Game.Select.Rounds
            });

            Entities.Enums.GamePlayerType playerType = (connection != null && connection.ConnectionType == Entities.Enums.ConnectionType.GamePlayer) ?
                Entities.Enums.GamePlayerType.Player :
                Entities.Enums.GamePlayerType.Spectator;

            Entities.Models.Game.Board.GameBoard model =
                new Entities.Models.Game.Board.GameBoard(game,
                                                         currentUserId,
                                                         playerType,
                                                         votesToKick,
                                                         completedRounds);

            Clients.Client(Context.ConnectionId).UpdateGameView(model, model.LobbyViewModel);
        }
Ejemplo n.º 4
0
        public ActionResult Index(Int32 id)
        {
            String key = String.Format("Game_{0}_Passphrase", id);
            String leaveGameJobIdKey = String.Format("LeaveGame_{0}_JobId", id);
            String passphrase        = String.Empty;
            String jobId             = String.Empty;
            Int32  currentUserId     = Authentication.Security.CurrentUserId;

            if (Session[key] != null)
            {
                passphrase = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[key] as Byte[]), Session.SessionID));
            }

            if (Session[leaveGameJobIdKey] != null)
            {
                jobId = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[leaveGameJobIdKey] as Byte[]), Session.SessionID));

                BackgroundJob.Delete(jobId);

                Session.Remove(leaveGameJobIdKey);
            }

            Entities.User user = _selectUser.Execute(currentUserId);

            Entities.JoinResponse response = _joinGame.Execute(id, user, passphrase, Entities.Enums.GamePlayerType.Player);

            if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.GameOver))
            {
                return(Redirect("/GameListing"));
            }

            if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.BadPassphrase) == false &&
                response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.FullGame) == false)
            {
                Entities.Filters.GamePlayerKickVote.SelectForGame kickVoteFilter = new Entities.Filters.GamePlayerKickVote.SelectForGame();
                kickVoteFilter.GameID = id;

                List <Entities.GamePlayerKickVote> votes = _selectKickVotes.Execute(kickVoteFilter);
                IEnumerable <IGrouping <Int32, Entities.GamePlayerKickVote> > grouped = votes.GroupBy(x => x.KickUserId);

                Entities.Models.Game.Board.VoteToKick kickModel = null;

                List <Entities.Models.Game.Board.VoteToKick> votesToKick = new List <Entities.Models.Game.Board.VoteToKick>();

                foreach (IGrouping <Int32, Entities.GamePlayerKickVote> group in grouped)
                {
                    if (group.FirstOrDefault(x => x.VotedUserId == currentUserId) == null)
                    {
                        kickModel = new Entities.Models.Game.Board.VoteToKick(group.First().KickUser,
                                                                              group.Count(x => x.Vote),
                                                                              group.Count(x => !x.Vote));

                        votesToKick.Add(kickModel);
                    }
                }

                List <Entities.GameRound> completedRounds = _selectGameRounds.Execute(new Entities.Filters.GameRound.SelectCompleted(id));

                Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(response.Game, currentUserId,
                                                                                                      Entities.Enums.GamePlayerType.Player,
                                                                                                      votesToKick,
                                                                                                      completedRounds);

                return(View("~/Views/Game/Board/Index.cshtml", model));
            }
            else
            {
                return(Redirect(Url.Action("Index", "GameListing", new { id = id })));
            }
        }
Ejemplo n.º 5
0
        public ActionResult Index(Int32 id)
        {
            String key = String.Format("Game_{0}_Passphrase", id);
            String leaveGameJobIdKey = String.Format("LeaveGame_{0}_JobId", id);
            String passphrase = String.Empty;
            String jobId = String.Empty;
            Int32 currentUserId = Authentication.Security.CurrentUserId;

            if (Session[key] != null)
            {
                passphrase = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[key] as Byte[]), Session.SessionID));
            }

            if (Session[leaveGameJobIdKey] != null)
            {
                jobId = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[leaveGameJobIdKey] as Byte[]), Session.SessionID));

                BackgroundJob.Delete(jobId);

                Session.Remove(leaveGameJobIdKey);
            }

            Entities.User user = _selectUser.Execute(currentUserId);

            Entities.JoinResponse response = _joinGame.Execute(id, user, passphrase, Entities.Enums.GamePlayerType.Player);

            if(response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.GameOver))
            {
                return Redirect("/GameListing");
            }

            if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.BadPassphrase) == false &&
                response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.FullGame) == false)
            {
                Entities.Filters.GamePlayerKickVote.SelectForGame kickVoteFilter = new Entities.Filters.GamePlayerKickVote.SelectForGame();
                kickVoteFilter.GameID = id;

                List<Entities.GamePlayerKickVote> votes = _selectKickVotes.Execute(kickVoteFilter);
                IEnumerable<IGrouping<Int32, Entities.GamePlayerKickVote>> grouped = votes.GroupBy(x => x.KickUserId);

                Entities.Models.Game.Board.VoteToKick kickModel = null;

                List<Entities.Models.Game.Board.VoteToKick> votesToKick = new List<Entities.Models.Game.Board.VoteToKick>();

                foreach (IGrouping<Int32, Entities.GamePlayerKickVote> group in grouped)
                {
                    if (group.FirstOrDefault(x => x.VotedUserId == currentUserId) == null)
                    {
                        kickModel = new Entities.Models.Game.Board.VoteToKick(group.First().KickUser,
                                                                     group.Count(x => x.Vote),
                                                                     group.Count(x => !x.Vote));

                        votesToKick.Add(kickModel);
                    }
                }

                List<Entities.GameRound> completedRounds = _selectGameRounds.Execute(new Entities.Filters.GameRound.SelectCompleted(id));

                Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(response.Game, currentUserId,
                                                                                                        Entities.Enums.GamePlayerType.Player,
                                                                                                        votesToKick,
                                                                                                        completedRounds);

                return View("~/Views/Game/Board/Index.cshtml", model);
            }
            else
            {
                return Redirect(Url.Action("Index", "GameListing", new { id = id }));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Alert the users a vote to kick has been placed
        /// </summary>
        /// <param name="gameID">The game ID</param>
        /// <param name="kickedUser">The user that was being voted on</param>
        /// <param name="votesToKick">The number of votes to kick</param>
        /// <param name="votesNotToKick">The number votes not to kick</param>
        /// <param name="alreadyVoted">UserIds for users that have already voted</param>
        public void Voted(Int32 gameID, Entities.User kickedUser, Int32 votesToKick, Int32 votesNotToKick, List<Int32> alreadyVoted)
        {
            List<Entities.ActiveConnection> connections = GetConnections(gameID, alreadyVoted);

            foreach (Entities.ActiveConnection connection in connections.Where(x => x.ConnectionType == Entities.Enums.ConnectionType.GamePlayer))
            {
                Entities.Models.Game.Board.VoteToKick model = new Entities.Models.Game.Board.VoteToKick(kickedUser, votesToKick, votesNotToKick);

                _hub.Clients.Client(connection.ActiveConnectionID).AlertUsersVote(model);
            }
        }