From 6e6bf612dc479f82281126e22dd1d78fbc38c87a Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Mon, 26 Mar 2018 09:56:58 -0700 Subject: [PATCH] Add logging to (FirstLoad|Register)Handler. Trying to figure out why some people can still get in while banned. I cannot reproduce this, and it does not make sense that it is possible as the admin page lists their current IP address in the ban list... and those are all trimmed, so it can't be spaces. Weird. --- .../cah/handlers/FirstLoadHandler.java | 29 ++++++++++++++----- .../cah/handlers/RegisterHandler.java | 4 +++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/socialgamer/cah/handlers/FirstLoadHandler.java b/src/main/java/net/socialgamer/cah/handlers/FirstLoadHandler.java index c0c2cff..0dccf72 100644 --- a/src/main/java/net/socialgamer/cah/handlers/FirstLoadHandler.java +++ b/src/main/java/net/socialgamer/cah/handlers/FirstLoadHandler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2012, Andy Janata + * Copyright (c) 2012-2018, Andy Janata * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted @@ -27,13 +27,23 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.servlet.http.HttpSession; +import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.hibernate.Transaction; + +import com.google.inject.Inject; +import com.google.inject.Provider; + +import net.socialgamer.cah.CahModule.BanList; import net.socialgamer.cah.CahModule.IncludeInactiveCardsets; import net.socialgamer.cah.Constants.AjaxOperation; import net.socialgamer.cah.Constants.AjaxResponse; import net.socialgamer.cah.Constants.CardSetData; +import net.socialgamer.cah.Constants.ErrorCode; import net.socialgamer.cah.Constants.ReconnectNextAction; import net.socialgamer.cah.Constants.ReturnableData; import net.socialgamer.cah.Constants.SessionAttribute; @@ -41,12 +51,6 @@ import net.socialgamer.cah.RequestWrapper; import net.socialgamer.cah.data.User; import net.socialgamer.cah.db.PyxCardSet; -import org.hibernate.Session; -import org.hibernate.Transaction; - -import com.google.inject.Inject; -import com.google.inject.Provider; - /** * Handler called for first invocation after a client loads. This can be used to restore a game in @@ -56,14 +60,17 @@ import com.google.inject.Provider; */ public class FirstLoadHandler extends Handler { + private static final Logger LOG = Logger.getLogger(FirstLoadHandler.class); public static final String OP = AjaxOperation.FIRST_LOAD.toString(); + private final Set banList; private final Session hibernateSession; private final Provider includeInactiveCardsetsProvider; @Inject - public FirstLoadHandler(final Session hibernateSession, + public FirstLoadHandler(final Session hibernateSession, @BanList final Set banList, @IncludeInactiveCardsets final Provider includeInactiveCardsetsProvider) { + this.banList = banList; this.hibernateSession = hibernateSession; this.includeInactiveCardsetsProvider = includeInactiveCardsetsProvider; } @@ -73,6 +80,12 @@ public class FirstLoadHandler extends Handler { final HttpSession session) { final HashMap ret = new HashMap(); + if (banList.contains(request.getRemoteAddr())) { + LOG.info(String.format("Rejecting user from %s because they are banned.", + request.getRemoteAddr())); + return error(ErrorCode.BANNED); + } + final User user = (User) session.getAttribute(SessionAttribute.USER); if (user == null) { ret.put(AjaxResponse.IN_PROGRESS, Boolean.FALSE); diff --git a/src/main/java/net/socialgamer/cah/handlers/RegisterHandler.java b/src/main/java/net/socialgamer/cah/handlers/RegisterHandler.java index 483f183..fbfc2da 100644 --- a/src/main/java/net/socialgamer/cah/handlers/RegisterHandler.java +++ b/src/main/java/net/socialgamer/cah/handlers/RegisterHandler.java @@ -32,6 +32,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpHeaders; +import org.apache.log4j.Logger; import com.google.inject.Inject; import com.google.inject.Provider; @@ -58,6 +59,7 @@ import net.socialgamer.cah.util.IdCodeMangler; */ public class RegisterHandler extends Handler { + private static final Logger LOG = Logger.getLogger(RegisterHandler.class); public static final String OP = AjaxOperation.REGISTER.toString(); private static final Pattern VALID_NAME = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]{2,29}"); @@ -90,6 +92,8 @@ public class RegisterHandler extends Handler { final Map data = new HashMap(); if (banList.contains(request.getRemoteAddr())) { + LOG.info(String.format("Rejecting user %s from %s because they are banned.", + request.getParameter(AjaxRequest.NICKNAME), request.getRemoteAddr())); return error(ErrorCode.BANNED); }