Package web.servlets

Source Code of web.servlets.LeaveGame

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package web.servlets;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.scotlandyard.engine.Game;
import org.scotlandyard.engine.GameException;
import org.scotlandyard.engine.json.JsonFactory;
import org.scotlandyard.impl.engine.GameEngine;

/**
* TODO add a description for this class
*
*
* @author Hussain Al-Mutawa
* @version 2.0
* @since Sun Sep 23, 2011
*/
public class LeaveGame extends AbstractServlet  implements IRequestProcessor{
  //TODO add documentation about the action performed by getting the output of this servlet
  @Override
   public Object getOutput(
         final HttpServletRequest request,
        final GameEngine engine) throws GameException {

    return (JsonFactory.toJson("done"));
  }

  @Override
  public void validateRequest(

             final HttpServletRequest request,
            final GameEngine engine) throws GameException {

    final String gameId = request.getParameter("gameId");

    if(gameId==null || "".equals(gameId)){
      throw new GameException("Game identifier has not been selected");
    }

    String playerEmail = GameEngine.instance().getUsers().get(getSessionId()).getEmail();


    final Game game =  engine.getLobby().getGame(gameId);
    if(!game.removePlayer(playerEmail)){
      throw new GameException("Player could not be removed");
    }

  }

}
TOP

Related Classes of web.servlets.LeaveGame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.