if(parameters.get("game")!=null){
gameId = parameters.get("game");
}
if(gameId==null || "".equals(gameId)){throw new Exception("Game Id is unknown");}
final IGame game = Engine.instance().games.get(gameId);
if(game==null){throw new Exception("Game is unknown");}
final IPlayer thisPlayer = game.getPlayer(xhash);
if(thisPlayer==null){throw new Exception("Player is unknown");}
final StringBuffer sb1 = new StringBuffer();
final StringBuffer sb2 = new StringBuffer();
final StringBuffer sb3 = new StringBuffer();
final StringBuffer sb4 = new StringBuffer();
//3, 8, 13 and 18 are the times where MrX is exposed
final int round = game.getRound();
final boolean exposeMRX = game.isRoundExposingMrX(round);
for(final IPlayer player:game.getPlayers()){
if(player.equals(thisPlayer)||(!player.isMrx() || exposeMRX)){
sb1.append(",\""+player.getName()+"\"");
sb2.append(",\""+player.getPosition()+"\"");
sb3.append(",\""+player.getIcon()+"\"");
sb4.append(",\""+player.getName()+"\"");
}
}
sb1.append(" ");sb2.append(" ");sb3.append(" ");
final String players_list = sb1.toString().substring(1);
final String positions_list = sb2.toString().substring(1);
final String icons_list = sb3.toString().substring(1);
final String players_names = sb4.toString().substring(1);
sb.append("{");
sb.append(" \"players\" : ["+players_list+"],");
sb.append(" \"positions\" : ["+positions_list+"],");
sb.append(" \"icons\" : ["+icons_list+"],");
sb.append(" \"round\" : "+round+"," );
sb.append(" \"gameStatus\" : \""+game.getStatus()+"\"," );
sb.append(" \"msg\" : \"OK\"," );
sb.append(" \"mrxFace\" : \""+(game.getStatus()=='F'?game.getMrX().getIcon():"-")+"\", ");
sb.append(" \"mrxName\" : \""+(game.getStatus()=='F'?game.getMrX().getName():"")+"\", ");
sb.append(" \"playersNames\" : ["+players_names+"]," );
sb.append(" \"whosTurn\" : \""+game.getPlayers().get(game.getCurrentTurn()).getName()+"\"" );
sb.append("}");
}catch(Exception e){
sb.setLength(0);
sb.append("{\"msg\" : \"EXCEPTION : "+(e.getMessage()+"").replace("\"", "'")+"\", \"className\" : \""+getClass().getName()+"\"}");