From e3ac81705e643d3c46f72d0b9ea4c56fc8198230 Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Sun, 29 Jan 2012 17:14:17 -0800 Subject: [PATCH] false-start of doing admin via ajax, would require a lot more work on the admin client to actually do it this way --- WebContent/js/cah.constants.js | 3 +++ src/net/socialgamer/cah/Constants.java | 2 ++ .../socialgamer/cah/UpdateHandlerList.java | 4 +-- .../cah/handlers/AdminHandler.java | 25 +++++++++++++++++++ .../cah/handlers/AdminSetVerboseLog.java | 20 +++++++++++++++ .../socialgamer/cah/handlers/Handlers.java | 1 + 6 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/net/socialgamer/cah/handlers/AdminHandler.java create mode 100644 src/net/socialgamer/cah/handlers/AdminSetVerboseLog.java diff --git a/WebContent/js/cah.constants.js b/WebContent/js/cah.constants.js index e14cdab..e901c49 100644 --- a/WebContent/js/cah.constants.js +++ b/WebContent/js/cah.constants.js @@ -14,6 +14,7 @@ cah.$.AjaxOperation.GAME_LIST = "games"; cah.$.AjaxOperation.GET_GAME_INFO = "get_game_info"; cah.$.AjaxOperation.PLAY_CARD = "play_card"; cah.$.AjaxOperation.CREATE_GAME = "create_game"; +cah.$.AjaxOperation.ADMIN_SET_VERBOSE_LOG = "set_verbose_log"; cah.$.AjaxOperation.GET_CARDS = "get_cards"; cah.$.AjaxOperation.JOIN_GAME = "join_game"; cah.$.AjaxOperation.REGISTER = "register"; @@ -76,6 +77,7 @@ cah.$.ErrorCode = function() { cah.$.ErrorCode.prototype.dummyForAutocomplete = undefined; cah.$.ErrorCode.TOO_MANY_GAMES = "too_many_games"; cah.$.ErrorCode.NO_CARD_SPECIFIED = "no_card_spec"; +cah.$.ErrorCode.ACCESS_DENIED = "access_denied"; cah.$.ErrorCode.NOT_GAME_HOST = "not_game_host"; cah.$.ErrorCode.CANNOT_JOIN_ANOTHER_GAME = "cannot_join_another_game"; cah.$.ErrorCode.INVALID_CARD = "invalid_card"; @@ -120,6 +122,7 @@ cah.$.ErrorCode_msg['not_in_that_game'] = "You are not in that game."; cah.$.ErrorCode_msg['msg_too_long'] = "Messages cannot be longer than 200 characters."; cah.$.ErrorCode_msg['do_not_have_card'] = "You don't have that card."; cah.$.ErrorCode_msg['no_game_spec'] = "No game specified."; +cah.$.ErrorCode_msg['access_denied'] = "Access denied."; cah.$.ErrorCode_msg['invalid_nick'] = "Nickname must contain only upper and lower case letters, numbers, or underscores, must be 3 to 30 characters long, and must not start with a number."; cah.$.ErrorCode_msg['no_nick_spec'] = "No nickname specified."; cah.$.ErrorCode_msg['nick_in_use'] = "Nickname is already in use."; diff --git a/src/net/socialgamer/cah/Constants.java b/src/net/socialgamer/cah/Constants.java index ac9c847..c6d7ad6 100644 --- a/src/net/socialgamer/cah/Constants.java +++ b/src/net/socialgamer/cah/Constants.java @@ -63,6 +63,7 @@ public class Constants { } public enum AjaxOperation { + ADMIN_SET_VERBOSE_LOG("set_verbose_log"), CHAT("chat"), CREATE_GAME("create_game"), FIRST_LOAD("firstload"), @@ -141,6 +142,7 @@ public class Constants { } public enum ErrorCode implements Localizable { + ACCESS_DENIED("access_denied", "Access denied."), ALREADY_STARTED("already_started", "The game has already started."), BAD_OP("bad_op", "Invalid operation."), BAD_REQUEST("bad_req", "Bad request."), diff --git a/src/net/socialgamer/cah/UpdateHandlerList.java b/src/net/socialgamer/cah/UpdateHandlerList.java index 33a90b5..755678e 100644 --- a/src/net/socialgamer/cah/UpdateHandlerList.java +++ b/src/net/socialgamer/cah/UpdateHandlerList.java @@ -8,8 +8,8 @@ import java.util.List; public class UpdateHandlerList { - private static final List EXCLUDE = Arrays.asList("GameHandler", "GameWithPlayerHandler", - "Handler", "Handlers"); + private static final List EXCLUDE = Arrays.asList("AdminHandler", "GameHandler", + "GameWithPlayerHandler", "Handler", "Handlers"); /** * @param args diff --git a/src/net/socialgamer/cah/handlers/AdminHandler.java b/src/net/socialgamer/cah/handlers/AdminHandler.java new file mode 100644 index 0000000..ba2229f --- /dev/null +++ b/src/net/socialgamer/cah/handlers/AdminHandler.java @@ -0,0 +1,25 @@ +package net.socialgamer.cah.handlers; + +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import net.socialgamer.cah.Constants.ErrorCode; +import net.socialgamer.cah.Constants.ReturnableData; +import net.socialgamer.cah.RequestWrapper; + + +public abstract class AdminHandler extends Handler { + + @Override + public Map handle(final RequestWrapper request, final HttpSession session) { + final String remoteAddr = request.getRemoteAddr(); + if (!(remoteAddr.equals("0:0:0:0:0:0:0:1") || remoteAddr.equals("127.0.0.1"))) { + return error(ErrorCode.ACCESS_DENIED); + } + + return handle(request); + } + + public abstract Map handle(RequestWrapper request); +} diff --git a/src/net/socialgamer/cah/handlers/AdminSetVerboseLog.java b/src/net/socialgamer/cah/handlers/AdminSetVerboseLog.java new file mode 100644 index 0000000..483ec5e --- /dev/null +++ b/src/net/socialgamer/cah/handlers/AdminSetVerboseLog.java @@ -0,0 +1,20 @@ +package net.socialgamer.cah.handlers; + +import java.util.Map; + +import net.socialgamer.cah.Constants.AjaxOperation; +import net.socialgamer.cah.Constants.ReturnableData; +import net.socialgamer.cah.RequestWrapper; + + +public class AdminSetVerboseLog extends AdminHandler { + + public static final String OP = AjaxOperation.ADMIN_SET_VERBOSE_LOG.toString(); + + @Override + public Map handle(final RequestWrapper request) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/net/socialgamer/cah/handlers/Handlers.java b/src/net/socialgamer/cah/handlers/Handlers.java index 56d221a..968ddfc 100644 --- a/src/net/socialgamer/cah/handlers/Handlers.java +++ b/src/net/socialgamer/cah/handlers/Handlers.java @@ -10,6 +10,7 @@ public class Handlers { static { LIST = new HashMap>(); + LIST.put(AdminSetVerboseLog.OP, AdminSetVerboseLog.class); LIST.put(ChatHandler.OP, ChatHandler.class); LIST.put(CreateGameHandler.OP, CreateGameHandler.class); LIST.put(FirstLoadHandler.OP, FirstLoadHandler.class);