private void SendWinnerSelected(Entities.Game game, Entities.GameRound round, IEnumerable <Entities.ActiveConnection> connections, List <Entities.GamePlayer> users) { Entities.GamePlayer sendToPlayer = null; foreach (Entities.ActiveConnection connection in connections) { sendToPlayer = users.FirstOrDefault(player => player.User.UserId == connection.User_UserId); if (sendToPlayer != null) { Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game); Entities.Models.Game.Board.Answers answersModel = new Entities.Models.Game.Board.Answers(true, model.IsCommander, false, false, false, true, round.GroupedAnswers()); //The round history tab repurposed this to be the winner of the round when the page is loaded //so setting this here so that when pushed into the observable array it will look correct round.CardCommander = round.Winner(); _hub.Clients.Client(connection.ActiveConnectionID) .WinnerSelected(answersModel, model, game.IsWaiting(), game.HasWinner(), round); } } }
public ActionResult Spectate(Int32 id) { String key = String.Format("Game_{0}_Passphrase", id); String passphrase = String.Empty; Int32 currentUserId = Authentication.Security.CurrentUserId; if (Session[key] != null) { passphrase = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[key] as Byte[]), Session.SessionID)); } Entities.User user = _selectUser.Execute(currentUserId); Entities.JoinResponse response = _joinGame.Execute(id, user, passphrase, Entities.Enums.GamePlayerType.Spectator); 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.SpectatorsFull) == false) { Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(response.Game, currentUserId, Entities.Enums.GamePlayerType.Spectator); return(View("~/Views/Game/Board/Index.cshtml", model)); } else { return(Redirect(Url.Action("Index", "GameListing", new { id = id }))); } }
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); }
private void ExecuteAction(Entities.Game game, Entities.Enums.Hubs.Actions action, IEnumerable <Entities.ActiveConnection> connections, List <Entities.GamePlayer> users) { Entities.GamePlayer sendToPlayer = null; foreach (Entities.ActiveConnection connection in connections) { sendToPlayer = users.FirstOrDefault(player => player.User.UserId == connection.User_UserId); if (sendToPlayer != null) { if (action == Entities.Enums.Hubs.Actions.UpdateWaiting) { _hub.Clients.Client(connection.ActiveConnectionID) .UpdateWaiting(Entities.Models.Helpers.WaitingHeader.Build(game, connection.User_UserId, GetPlayerType(connection)), GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.UpdateGameView) { Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game); _hub.Clients.Client(connection.ActiveConnectionID) .UpdateGameView(model, GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.UpdateLobby) { _hub.Clients.Client(connection.ActiveConnectionID) .UpdateLobbyView(GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.CardPlayed) { Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(game, connection.User_UserId, GetPlayerType(connection)); _hub.Clients.Client(connection.ActiveConnectionID) .UpdateAnswers(model.AnswersViewModel, !model.ShowHand); } } } }
/// <summary> /// Alert the users that the round has been lost because the commander has left /// </summary> /// <param name="game">The game</param> /// <param name="commanderName">The commander's name</param> public void CommanderLeft(Entities.Game game, String commanderName) { Entities.Filters.ActiveConnection.SelectAll filter = new Entities.Filters.ActiveConnection.SelectAll(); filter.GroupName = String.Format("Game_{0}", game.GameID); List <Entities.ActiveConnection> connections = _selectActiveConnection.Execute(filter); Entities.GamePlayer sendToPlayer = null; foreach (Entities.ActiveConnection connection in connections) { sendToPlayer = game.Players.FirstOrDefault(player => player.User.UserId == connection.User_UserId); if (sendToPlayer != null) { Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game); _hub.Clients.Client(connection.ActiveConnectionID) .CommanderLeft(model, GetGameLobbyViewModel(connection, game), commanderName, game.IsWaiting()); } } }
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); }
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 }))); } }
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 })); } }
public ActionResult Spectate(Int32 id) { String key = String.Format("Game_{0}_Passphrase", id); String passphrase = String.Empty; Int32 currentUserId = Authentication.Security.CurrentUserId; if (Session[key] != null) { passphrase = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[key] as Byte[]), Session.SessionID)); } Entities.User user = _selectUser.Execute(currentUserId); Entities.JoinResponse response = _joinGame.Execute(id, user, passphrase, Entities.Enums.GamePlayerType.Spectator); 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.SpectatorsFull) == false) { Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(response.Game, currentUserId, Entities.Enums.GamePlayerType.Spectator); return View("~/Views/Game/Board/Index.cshtml", model); } else { return Redirect(Url.Action("Index", "GameListing", new { id = id })); } }
private void ExecuteAction(Entities.Game game, Entities.Enums.Hubs.Actions action, IEnumerable<Entities.ActiveConnection> connections, List<Entities.GamePlayer> users) { Entities.GamePlayer sendToPlayer = null; foreach (Entities.ActiveConnection connection in connections) { sendToPlayer = users.FirstOrDefault(player => player.User.UserId == connection.User_UserId); if (sendToPlayer != null) { if (action == Entities.Enums.Hubs.Actions.UpdateWaiting) { _hub.Clients.Client(connection.ActiveConnectionID) .UpdateWaiting(Entities.Models.Helpers.WaitingHeader.Build(game, connection.User_UserId, GetPlayerType(connection)), GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.UpdateGameView) { Entities.Models.Game.Board.GameBoard model = GetGameBoardModal(connection, game); _hub.Clients.Client(connection.ActiveConnectionID) .UpdateGameView(model, GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.UpdateLobby) { _hub.Clients.Client(connection.ActiveConnectionID) .UpdateLobbyView(GetGameLobbyViewModel(connection, game)); } else if (action == Entities.Enums.Hubs.Actions.CardPlayed) { Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(game, connection.User_UserId, GetPlayerType(connection)); _hub.Clients.Client(connection.ActiveConnectionID) .UpdateAnswers(model.AnswersViewModel, !model.ShowHand); } } } }