/// <summary> /// Sends a notification to the players in the game that a new player has joined the game. /// /// If the game is currently in the lobby or starting (GameState = IN LOBBY, STARTING) /// then no notification will be sent, the lobby list will be updated. /// /// If the game is currently playing (GameState = PLAYING) then a in game notification will be sent to /// the players connect to the hub / have the web app open. /// /// An out of game notification will be sent to the players contact (Email or phone) if the player is /// not currently connected to the application hub when GameState = STARTING, PLAYING. /// </summary> /// <param name="joinedPlayer">The player who joined the game.</param> public async void UpdatePlayerJoinedGame(Player joinedPlayer) { Console.WriteLine("HubInterface - UpdatePlayerJoinedGame"); //Get all the players currently in the game which are updateable GameDAL gameDAL = new GameDAL(); Response <Game> gameResponse = gameDAL.GetAllPlayersInGame(joinedPlayer.PlayerID, true, "UPDATEABLE", "AZ"); //If an error occurred while trying to get the list of players exit the method if (!gameResponse.IsSuccessful()) { return; } Game game = gameResponse.Data; //Create notifications of new player joining, if the game is playing and the player joining is verified if (game.IsPlaying() && joinedPlayer.IsVerified) { gameDAL.CreateJoinNotification(joinedPlayer); } //Loop through each of the players and update any player currently in the game. foreach (var player in game.Players) { //If the PlayerID is the playerID who joined skip this iteration if (player.PlayerID == joinedPlayer.PlayerID) { continue; } //Update players in game when connected to the hub / have the web app open if (player.IsConnected) { //If the game is IN LOBBY or STARTING update the lobby list for both verfied and unverified players joining if (game.IsInLobby() || game.IsStarting()) { Console.WriteLine("Invoking UpdateGameLobbyList on :" + player.Nickname); await _hubContext.Clients.Client(player.ConnectionID).SendAsync("UpdateGameLobbyList"); } //Otherwise, update the players notifications and the scoreboard because they are currently playing the game else if (game.IsPlaying() && joinedPlayer.IsVerified) { Console.WriteLine("Invoking UpdateNotifications and UpdateScoreboard on :" + player.Nickname); await _hubContext.Clients.Client(player.ConnectionID).SendAsync("UpdateNotifications"); await _hubContext.Clients.Client(player.ConnectionID).SendAsync("UpdateScoreboard"); } } //Otherwise, the player is out of the app and not a BR player who is eliminated, send them a text message or email. else if (!player.IsEliminated) { //Only send a notification when the game is playing or starting string message = joinedPlayer.Nickname + " has joined your game of CamTag."; string subject = "New Player Joined Your Game"; if ((game.IsPlaying() || game.IsStarting()) && joinedPlayer.IsVerified) { Console.WriteLine("Sending new player joined SMS or Email to:" + player.Nickname); player.ReceiveMessage(message, subject); } } } }