String json = "";
switch (action) {
case GET_BOARD: {
final Long boardId = getBoardId(parameters);
final ScriptableObject board;
if (boardId != null) {
board = getBoard(boardId);
} else {
board = getBoard();
}
json += "\"board\":";
json += stringify(board);
break;
}
case JOIN_BOARD:
if (user == null || user == "") {
// /login.html?return_to=hex%252Fapi%253Faction%253DJOIN_BOARD
final Long boardId = getBoardId(parameters);
try {
response.sendRedirect("/login.html?return_to=tend%252Fapi%253Faction%253DJOIN_BOARD%2526id%253D"
+ boardId);
return null;
} catch (IOException e1) {
e1.printStackTrace();
}
}
final Long boardId = getBoardId(parameters);
joinBoard(boardId, user);
try {
// Long id = (Long) board.get("id");
response.sendRedirect("/tend/#!" + boardId);
return null;
} catch (IOException e) {
e.printStackTrace();
}
break;
case COLLECT:
break;
case CREATE_BOARD:
break;
case FINISH_TURN: {
ScriptableObject board = getBoard(getBoardId(parameters));
endTurn(board, user);
json += "\"board\":";
json += stringify(board);
}
break;
case LIST_BOARDS:
json = "\"boards\":[";
HashMap<Object, HashMap<String, Object>> boards = ge.persistence
.getAll("Board");
for (Entry<Object, HashMap<String, Object>> board : boards
.entrySet()) {
String ad = ((Text) board.getValue().get("json")).getValue();
json += ad + ",";
}
json = json.substring(0, json.length() - 1);
json += "]";
break;
case RESET_COLLECTIONS:
break;
case RESET_SETTLEMENTS:
break;
case TRADE:
break;
case QUEUE_SETTLEMENT:
ScriptableObject board = getBoard(getBoardId(parameters));
String settlementPoint = getParameter("settlementPoint", parameters);
String settlementName = getParameter("settlementName", parameters);
String resources = getParameter("resources", parameters);
queueSettlement(board, user, settlementPoint, settlementName,
resources);