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.
This commit is contained in:
parent
783b223d19
commit
6e6bf612dc
|
@ -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<String> banList;
|
||||
private final Session hibernateSession;
|
||||
private final Provider<Boolean> includeInactiveCardsetsProvider;
|
||||
|
||||
@Inject
|
||||
public FirstLoadHandler(final Session hibernateSession,
|
||||
public FirstLoadHandler(final Session hibernateSession, @BanList final Set<String> banList,
|
||||
@IncludeInactiveCardsets final Provider<Boolean> includeInactiveCardsetsProvider) {
|
||||
this.banList = banList;
|
||||
this.hibernateSession = hibernateSession;
|
||||
this.includeInactiveCardsetsProvider = includeInactiveCardsetsProvider;
|
||||
}
|
||||
|
@ -73,6 +80,12 @@ public class FirstLoadHandler extends Handler {
|
|||
final HttpSession session) {
|
||||
final HashMap<ReturnableData, Object> ret = new HashMap<ReturnableData, Object>();
|
||||
|
||||
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);
|
||||
|
|
|
@ -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<ReturnableData, Object> data = new HashMap<ReturnableData, Object>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue