diff --git a/WebContent/WEB-INF/pyx.properties b/WebContent/WEB-INF/pyx.properties index 86079be..2b1eeb2 100644 --- a/WebContent/WEB-INF/pyx.properties +++ b/WebContent/WEB-INF/pyx.properties @@ -1,3 +1,4 @@ -pyx.cookie_domain=*.socialgamer.net +pyx.client.cookie_domain=*.socialgamer.net +pyx.server.include_inactive_cardsets=false pyx.server.max_users=800 pyx.server.max_games=200 diff --git a/WebContent/viewcards.jsp b/WebContent/viewcards.jsp index cdc43bd..b6f19a1 100644 --- a/WebContent/viewcards.jsp +++ b/WebContent/viewcards.jsp @@ -31,9 +31,12 @@ Interface to view and search all existing cards and card sets. <%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashSet" %> <%@ page import="java.util.List" %> +<%@ page import="java.util.Properties" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.Set" %> +<%@ page import="com.google.inject.Injector" %> <%@ page import="net.socialgamer.cah.HibernateUtil" %> +<%@ page import="net.socialgamer.cah.StartupUtils" %> <%@ page import="net.socialgamer.cah.db.BlackCard" %> <%@ page import="net.socialgamer.cah.db.CardSet" %> <%@ page import="net.socialgamer.cah.db.WhiteCard" %> @@ -42,12 +45,16 @@ Interface to view and search all existing cards and card sets. <% Session hibernateSession = HibernateUtil.instance.sessionFactory.openSession(); +ServletContext servletContext = pageContext.getServletContext(); +Injector injector = (Injector) servletContext.getAttribute(StartupUtils.INJECTOR); +Properties props = injector.getInstance(Properties.class); + // cheap way to make sure we can close the hibernate session at the end of the page try { - // load from db + // load from db @SuppressWarnings("unchecked") List cardSets = hibernateSession - .createQuery("from CardSet where active = true order by weight, id") + .createQuery(CardSet.getCardsetQuery(props)) .setReadOnly(true) .list(); diff --git a/src/net/socialgamer/cah/db/CardSet.java b/src/net/socialgamer/cah/db/CardSet.java index 05c778c..7e77b99 100644 --- a/src/net/socialgamer/cah/db/CardSet.java +++ b/src/net/socialgamer/cah/db/CardSet.java @@ -3,6 +3,7 @@ package net.socialgamer.cah.db; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Properties; import java.util.Set; import javax.persistence.Entity; @@ -122,4 +123,12 @@ public class CardSet { "CardSet[name=%s, base=%b, id=%d, active=%b, weight=%d, black=%d, white=%d]", name, base_deck, id, active, weight, blackCards.size(), whiteCards.size()); } + + public static String getCardsetQuery(final Properties properties) { + if (Boolean.valueOf(properties.getProperty("pyx.server.include_inactive_cardsets"))) { + return "from CardSet order by weight, id"; + } else { + return "from CardSet where active = true order by weight, id"; + } + } } diff --git a/src/net/socialgamer/cah/handlers/FirstLoadHandler.java b/src/net/socialgamer/cah/handlers/FirstLoadHandler.java index 1cd26d5..4056c43 100644 --- a/src/net/socialgamer/cah/handlers/FirstLoadHandler.java +++ b/src/net/socialgamer/cah/handlers/FirstLoadHandler.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import javax.servlet.http.HttpSession; @@ -57,10 +58,12 @@ public class FirstLoadHandler extends Handler { public static final String OP = AjaxOperation.FIRST_LOAD.toString(); private final Session hibernateSession; + private final Properties properties; @Inject - public FirstLoadHandler(final Session hibernateSession) { + public FirstLoadHandler(final Session hibernateSession, final Properties properties) { this.hibernateSession = hibernateSession; + this.properties = properties; } @Override @@ -91,7 +94,8 @@ public class FirstLoadHandler extends Handler { final Transaction transaction = hibernateSession.beginTransaction(); @SuppressWarnings("unchecked") final List cardSets = hibernateSession - .createQuery("from CardSet where active = true order by weight, id").setReadOnly(true) + .createQuery(CardSet.getCardsetQuery(properties)) + .setReadOnly(true) .list(); final List> cardSetsData = new ArrayList>( cardSets.size()); diff --git a/src/net/socialgamer/cah/servlets/JavascriptConfigServlet.java b/src/net/socialgamer/cah/servlets/JavascriptConfigServlet.java index f77dade..6655225 100644 --- a/src/net/socialgamer/cah/servlets/JavascriptConfigServlet.java +++ b/src/net/socialgamer/cah/servlets/JavascriptConfigServlet.java @@ -50,7 +50,7 @@ public class JavascriptConfigServlet extends HttpServlet { final StringBuilder builder = new StringBuilder(256); final Injector injector = (Injector) getServletContext().getAttribute(StartupUtils.INJECTOR); final String cookieDomain = (String) injector.getInstance(Properties.class).get( - "pyx.cookie_domain"); + "pyx.client.cookie_domain"); builder.append(String.format("cah.COOKIE_DOMAIN = '%s';\n", cookieDomain)); resp.setContentType("text/javascript");