@Override
	public void process(HttpServletRequest request,
			HttpServletResponse response, String mobileHash,
			List<String> message) throws Exception {
		EntityManager manager = EMF.get().createEntityManager();
		try {
			String user = mobileHash; // manager.find(ChessUser.class,
										// mobileHash).getMobileHash();
			String opponent = getOpponent(manager, message.get(0));
			int color = message.get(1).equalsIgnoreCase("white") ? 1 : 0;
			if ("ai".equalsIgnoreCase(opponent)) {
				int level = Integer.parseInt(message.get(2));
				if (level > 6)
					{level = 6;}
				if (level <= 0) {
					level = 3;
				}
				ChessBoard board = ChessBoard.getNewInstance();
				Game game = new Game(board, color == 1 ? mobileHash : "ai-"
						+ level, color == 0 ? mobileHash : "ai-" + level);
				if (TxtChessUtil.isAI_Move(game)) {
					// manager.persist(game);
					String move = Service.getService().getServiceSoap()
							.getNextMove(board.getFEN(), "", level);
					board.performMove(Move.getMove(board, move));
					game.init(board);
				}
				EntityTransaction transaction = manager.getTransaction();
				try {
					transaction.begin();
					manager.persist(game);
					transaction.commit();
				} catch (Exception e) {
					try {
						transaction.rollback();
					} catch (Exception ex) {
						ex.printStackTrace();
					}
					throw new Exception(
							"Unable to create Game with Computer(Internal Error) , Please Try Again",e);
				}
				request.setAttribute("gameId", game.getId());
				setJspPath("/showGame");
				return;
			}
			
			
			if (user.equals(opponent)) {
				throw new Exception("You can't challenge yourself");
			}

			int minRating = (opponent != null) || message.get(2).equals("*") ? 0
					: Integer.parseInt(message.get(2));
			int maxRating = (opponent != null) || message.get(3).equals("*") ? 4000
					: Integer.parseInt(message.get(3));
			Challenge challenge = new Challenge(user, opponent, color,
					minRating, maxRating, new Date(Calendar.getInstance()
							.getTime().getTime()));
			EntityTransaction transaction = manager.getTransaction();
			try {
				transaction.begin();
				manager.persist(challenge);
				transaction.commit();
			} catch (Exception e) {
				try {
					transaction.rollback();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
				throw new Exception(
						"Unable to create challenge (Internal Error)",e);
			}
			
			if(opponent!=null)
			{
				ChessUser currentUser=manager.find(ChessUser.class, user);
				//TxtWebApiUtil.pushMessage(opponent, 
				//	TxtChessUtil.createMoveNotificationMessage("You have been challenged by "+currentUser.getUserName()+" ("+currentUser.getRating() +")",
					//		"Your color is "+challenge.getOpponentColor(), "<br/><br/><a href='/acceptChallenge?challengeId="+challenge.getId()+"'>Accept Challenge</a><br/>" +
						//			"<a href='/acceptChallenge?challengeId="+challenge.getId()+"&txtweb-message=reject'>Reject Challenge</a>"));
				TxtWebApiUtil.pushMessage(opponent, 
							TxtChessUtil.createMoveNotificationMessage("You have been challenged by "+currentUser.getUserName()+" ("+currentUser.getRating() +")",
							"Your color is "+challenge.getOpponentColor(), "<br/><br/>"+("Please send '@chezz.challenges' to see accept or reject the challenge")));
				
			}
			
			request.setAttribute("__message", "Challenge is created, You will be notified if challenge is accepted");
			setJspPath("/jsp/common/MessageHandler.jsp");
		}
		/*
		 * catch(Exception e) { setJspPath("/jsp/common/InputHandler.jsp");
		 * request.setAttribute("__endPoint", getServiceEndPoint());
		 * request.setAttribute("__paramName", "User Name");
		 * request.setAttribute( "__message", e.getMessage()+
		 * "<br/> Please provide other UserName or all for open challenge or ai to play with computer"
		 * );
		 * 
		 * }
		 */
		finally {
			manager.close();
		}
	}