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 }));
}
}