Package scotlandyard.servlets.games

Source Code of scotlandyard.servlets.games.start_game_json

package scotlandyard.servlets.games;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import scotlandyard.engine.impl.Engine;
import scotlandyard.engine.impl.Game;
import scotlandyard.engine.spec.IPlayer;
/**
* starts a game and make it ready to be playable
* @author Hussain Al-Mutawa
* @version 3.0
*/
public class start_game_json extends HttpServlet {
 
  private static final long serialVersionUID = -4174251720731087374L;

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final PrintWriter out = response.getWriter();
      try{
        response.setHeader("Content-Type", "text/plain");
          final String xhash = request.getParameter("xhash");
          if(xhash==null || "".equals(xhash)){throw new Exception("Unknown HASH");}

          final String gameId  = request.getParameter("selected_game");
          if(gameId==null || "".equals(gameId)){throw new Exception("Game Id is unknown");}

          final Game game = Engine.instance().games.get(gameId);
          if(game==null){throw new Exception("Game is unknown");}

          final IPlayer player = game.getPlayer(xhash);
          if(player==null){throw new Exception("player is unknown");}

          game.start(player);

          out.print("{\"msg\" : \""+Game.getStatusDefinition(game.getStatus())+"\"}");

      }catch(Exception e){
        out.print("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");
      }
  }

}
TOP

Related Classes of scotlandyard.servlets.games.start_game_json

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.