public override void OnGameCreated(GameSession game)
 {
     dynamic clients = _connectionManagerFactory().GetClients<GamesRoom>();
     clients[LoggedInUsersGroupName].gameCreated(game);
     var groupManager = (IGroupManager)clients;
     groupManager.AddToGroup(game.Owner.Id, game.Id);
     clients[game.Owner.Id].youCreatedGame();
 }
        public override void OnGameJoined(GameSession game)
        {
            AddGameEvent(game.Id, GameEventTypes.OpponentJoinedGame, game.Opponent.Id);
            AddGameEvent(game.Id, GameEventTypes.GameStarted, game.Opponent.Id);
            AddPlayerAction(game.Opponent.Id, PlayerActionTypes.PlayerJoinedGame, game.Id);
            _dbContextFactory().Games.Find(game.Id).Opponent = _dbContextFactory().Players.Find(game.Opponent.Id);

            _dbContextFactory().SaveChanges();
        }
 public override void OnGameEnded(GameSession game)
 {
     dynamic clients = _connectionManagerFactory().GetClients<GamesRoom>();
     clients[LoggedInUsersGroupName].gameEnded(game);
     clients[game.Id].yourGameIsOver(game);
     var groupManager = (IGroupManager)clients;
     lock (Locker)
     {//to prevent raise conditions
         groupManager.RemoveFromGroup(game.Owner.Id, game.Id);
         groupManager.RemoveFromGroup(game.Opponent.Id, game.Id);
     }
 }
        public override void OnGameCreated(GameSession game)
        {
            _dbContextFactory().Games.Add(new Game
            {
                Id = game.Id,
                Owner = _dbContextFactory().Players.Find(game.Owner.Id),
                CreationDate = DateTime.UtcNow
            });
            AddPlayerAction(game.Owner.Id, PlayerActionTypes.PlayerCreatedGame, game.Id);
            AddGameEvent(game.Id, GameEventTypes.GameCreated, game.Owner.Id);

            _dbContextFactory().SaveChanges();
        }
 public override void OnGameEnded(GameSession game)
 {
     if (!game.IsDraw)
     {
         var mailMessage = new MailMessage
         {
             Subject = "You won in Tic Tac Toe Online",
             Body = "Congratulations you won in Tic Tac Toe against" + game.Looser.NickName
         };
         mailMessage.To.Add(game.Winner.Email);
         mailMessage.Send(); //uncomment to really send mails
     }
 }
        public override void OnGameEnded(GameSession game)
        {
            AddGameEvent(game.Id, GameEventTypes.GameEnded);
            if (game.IsDraw)
            {
                AddPlayerAction(game.Owner.Id, PlayerActionTypes.PlayerPlayedInADraw, game.Id);
                AddPlayerAction(game.Opponent.Id, PlayerActionTypes.PlayerPlayedInADraw, game.Id);
                _dbContextFactory().Games.Find(game.Id).Draw = true;
            }
            else
            {
                AddPlayerAction(game.Winner.Id, PlayerActionTypes.PlayerWon, game.Id);
                _dbContextFactory().Games.Find(game.Id).Winner = _dbContextFactory().Players.Find(game.Winner.Id);

                AddPlayerAction(game.Looser.Id, PlayerActionTypes.PlayerLost, game.Id);
                _dbContextFactory().Games.Find(game.Id).Looser = _dbContextFactory().Players.Find(game.Looser.Id);
            }

            _dbContextFactory().SaveChanges();
        }
 public virtual void OnGameJoined(GameSession game)
 {
 }
 public virtual void OnGameEnded(GameSession game)
 {
 }
 public virtual void OnGameCreated(GameSession game)
 {
 }