Esempio n. 1
0
        //playerguid can be null for spectators
        public ActionResult Game(int? gameId, Guid? playerGuid)
        {
            var game = GetGame(gameId);
            if (game == null)
            {
                return RedirectToAction("Index");
            }

            var viewModel = new GameModel(game, playerGuid);

            return View(viewModel);
        }
Esempio n. 2
0
        private void Update(bool force = false)
        {
            //loop through all connected players
            foreach (var connection in _userConnections)
            {
                var games = new List<GameModel>();
                foreach (var gameId in _gameCache.Keys)
                {
                    var game = _gameCache[gameId];
                    var gameModel = new GameModel(gameId, game, connection.Value);

                    //only send updates for games with recent actions, or when forced on initial connection (page refresh?)
                    if (force || game.LastActionTime > DateTimeOffset.Now.AddDays(-1))
                    {
                        games.Add(gameModel);
                    }
                }

                Clients.Client(connection.Key).Update(games.OrderBy(g => g.GameId).ToList());
            }
        }