Package scotlandyard.servlets.users

Source Code of scotlandyard.servlets.users.change_icon

package scotlandyard.servlets.users;

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.spec.IGame;
import scotlandyard.engine.spec.IPlayer;
import scotlandyard.engine.spec.IUser;

/**
*changes the icon of a use
* @author Hussain Al-Mutawa
* @version 3.0
*/
public class change_icon extends HttpServlet {

  private static final long serialVersionUID = -239964143887943132L;

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final PrintWriter out = response.getWriter();
    response.setHeader("Content-Type", "text/plain");
    try{
      final Engine engine = Engine.instance();
      String icon = request.getParameter("icon");
      String hash = request.getParameter("xhash");

      final IUser user = engine.getUser(hash);

      if(user!=null){
        user.setIcon(icon);
        for(IGame game:engine.games.values()){
          for(IPlayer player:game.getPlayers()){
            if(user.getHash().equals(player.getHash())){
              player.setIcon(icon);
            }
          }
        }
      }
    }catch(Exception e){
      out.print("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");
    }
  }

}
TOP

Related Classes of scotlandyard.servlets.users.change_icon

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.