public ActionResult <Response <Player> > JoinGame(JoinGameRequest request) { try { //Create the player object who will be joining the game Player playerToJoin = new Player(request.nickname, request.imgUrl, request.contact); Game gameToJoin = new Game(request.gameCode); //Generate a verification code int verificationCode = Player.GenerateVerificationCode(); //Call the data access layer to add the player to the database Response <Player> response = new PlayerDAL().JoinGame(gameToJoin, playerToJoin, verificationCode); //If the response was successful, send the verification code to the player and update the lobby list if (response.IsSuccessful()) { string message = "Your CamTag verification code is: " + verificationCode; string subject = "CamTag Verification Code"; response.Data.ReceiveMessage(message, subject); //Call the hub interface to invoke client methods to update the clients that another player has joined HubInterface hubInterface = new HubInterface(_hubContext); hubInterface.UpdatePlayerJoinedGame(response.Data); //Compress the player data before sending back over the network response.Data.Compress(true, true, true); } return(response); } //Catch any error associated with invalid model data catch (InvalidModelException e) { return(new Response <Player>(e.Msg, e.Code)); } //Catch any unhandled / unexpected server errrors catch { return(StatusCode(500)); } }
public ActionResult <Response> VerifyPlayer([FromForm] string verificationCode, [FromHeader] int playerID) { try { Player playerToVerify = new Player(playerID); //Confirm the verification code is valid and return an error response if the verification code is invalid int code = Player.ValidateVerificationCode(verificationCode); if (code == -1) { return(new Response("The verification code is invalid. Must be an INT between 10000 and 99999.", ErrorCodes.DATA_INVALID)); } //Call the data access layer to confirm the verification code is correct. Response <Player> response = new PlayerDAL().ValidateVerificationCode(code, playerToVerify); //If the player was successfully verified, updated all the clients about a joined player. if (response.IsSuccessful()) { HubInterface hubInterface = new HubInterface(_hubContext); hubInterface.UpdatePlayerJoinedGame(response.Data); } return(response); } //Catch any error associated with invalid model data catch (InvalidModelException e) { return(new Response(e.Msg, e.Code)); } //Catch any unhandled / unexpected server errrors catch { return(StatusCode(500)); } }