final GameEngine engine) throws GameException {
try{
playerRole = PlayerRole.valueOf(request.getParameter("role"));
}catch(Exception ex){
throw new GameException("playing role is not recognized");
}
String gameId = request.getParameter("gameId");
if(gameId==null){
throw new GameException("gameId is null");
}
game = engine.getLobby().getGame(gameId);
if(game==null){
throw new GameException("game is not found");
}
user = (User)engine.getUsers().get(getSessionId());
if(user==null){
throw new GameException("user is null");
}
if(game.hasPlayer(user.getEmail()))
{
throw new GameException("you are already playing a game");
}
if(playerRole==PlayerRole.MrX && game.getMrX()!=null){
throw new GameException("MrX player has been taken by someone else");
}
else if(playerRole==PlayerRole.Detective && game.getDetectives().size()>=GameEngine.MIXIMUM_NUMBER_OF_DETECTIVES){
throw new GameException("Sorry, this game is full. try to create another game and play with someone else");
}
final Player player;
if(playerRole==PlayerRole.MrX){