Add config option to use inactive cardsets. Rename cookie domain config option to be more consistent.
This commit is contained in:
parent
ef4c172fca
commit
495683c206
|
@ -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
|
||||
|
|
|
@ -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<CardSet> cardSets = hibernateSession
|
||||
.createQuery("from CardSet where active = true order by weight, id")
|
||||
.createQuery(CardSet.getCardsetQuery(props))
|
||||
.setReadOnly(true)
|
||||
.list();
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<CardSet> cardSets = hibernateSession
|
||||
.createQuery("from CardSet where active = true order by weight, id").setReadOnly(true)
|
||||
.createQuery(CardSet.getCardsetQuery(properties))
|
||||
.setReadOnly(true)
|
||||
.list();
|
||||
final List<Map<CardSetData, Object>> cardSetsData = new ArrayList<Map<CardSetData, Object>>(
|
||||
cardSets.size());
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue