Add option to disable fill-in-the-blank cards entirely.

This commit is contained in:
Andy Janata 2018-07-28 09:50:31 -07:00
parent 5d05f2e85b
commit c40c2d194b
7 changed files with 52 additions and 18 deletions

View File

@ -28,12 +28,22 @@ created for the user now.
@author Andy Janata (ajanata@socialgamer.net)
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.google.inject.Injector" %>
<%@ page import="com.google.inject.Key" %>
<%@ page import="com.google.inject.TypeLiteral" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page import="net.socialgamer.cah.CahModule.AllowBlankCards" %>
<%@ page import="net.socialgamer.cah.RequestWrapper" %>
<%@ page import="net.socialgamer.cah.StartupUtils" %>
<%@ page import="net.socialgamer.cah.data.GameOptions" %>
<%
// Ensure a session exists for the user.
@SuppressWarnings("unused")
HttpSession hSession = request.getSession(true);
RequestWrapper wrapper = new RequestWrapper(request);
ServletContext servletContext = pageContext.getServletContext();
Injector injector = (Injector) servletContext.getAttribute(StartupUtils.INJECTOR);
boolean allowBlankCards = injector.getInstance(Key.get(new TypeLiteral<Boolean>(){}, AllowBlankCards.class));
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -507,16 +517,18 @@ HttpSession hSession = request.getSession(true);
<span class="base_card_sets"></span>
<span class="extra_card_sets"></span>
</fieldset>
<br/>
<label id="blanks_limit_label" title="Blank cards allow a player to type in their own answer.">
Also include <select id="blanks_limit_template" class="blanks_limit">
<%
for (int i = GameOptions.MIN_BLANK_CARD_LIMIT; i <= GameOptions.MAX_BLANK_CARD_LIMIT; i++) {
%>
<option <%= i == GameOptions.DEFAULT_BLANK_CARD_LIMIT ? "selected='selected' " : "" %>value="<%= i %>"><%= i %></option>
<% } %>
</select> blank white cards.
</label>
<% if (allowBlankCards) { %>
<br/>
<label id="blanks_limit_label" title="Blank cards allow a player to type in their own answer.">
Also include <select id="blanks_limit_template" class="blanks_limit">
<%
for (int i = GameOptions.MIN_BLANK_CARD_LIMIT; i <= GameOptions.MAX_BLANK_CARD_LIMIT; i++) {
%>
<option <%= i == GameOptions.DEFAULT_BLANK_CARD_LIMIT ? "selected='selected' " : "" %>value="<%= i %>"><%= i %></option>
<% } %>
</select> blank white cards.
</label>
<% } %>
<br/>
<label id="game_password_template_label" for="game_password_template">Game password:</label>
<input type="text" id="game_password_template" class="game_password"

View File

@ -4,6 +4,8 @@ pyx.max_games=25
pyx.include_inactive_cardsets=true
pyx.broadcast_connects_and_disconnects=true
pyx.global_chat_enabled=true
# allow fill-in-the-blank cards at all. Limits are set via constants in GameOptions.
pyx.allow_blank_cards=true
# allow identification codes to be used without HTTPS
pyx.insecure_id_allowed=true
# set this to some secure random value, and never change it, unless you want to break all codes

View File

@ -4,6 +4,7 @@ pyx.server.max_users=${pyx.max_users}
pyx.server.max_games=${pyx.max_games}
pyx.server.broadcast_connects_and_disconnects=${pyx.broadcast_connects_and_disconnects}
pyx.server.global_chat_enabled=${pyx.global_chat_enabled}
pyx.server.allow_blank_cards=${pyx.allow_blank_cards}
pyx.server.id_code_salt=${pyx.id_code_salt}
pyx.server.admin_addrs=${pyx.admin_addrs}
# changing this at runtime has no effect

View File

@ -297,6 +297,14 @@ public class CahModule extends AbstractModule {
}
}
@Provides
@AllowBlankCards
Boolean provideAllowBlankCards() {
synchronized (properties) {
return Boolean.valueOf(properties.getProperty("pyx.server.allow_blank_cards", "true"));
}
}
@BindingAnnotation
@Retention(RetentionPolicy.RUNTIME)
public @interface BanList {
@ -401,4 +409,9 @@ public class CahModule extends AbstractModule {
@Retention(RetentionPolicy.RUNTIME)
public @interface BannedNicks {
}
@BindingAnnotation
@Retention(RetentionPolicy.RUNTIME)
public @interface AllowBlankCards {
}
}

View File

@ -48,6 +48,7 @@ import org.hibernate.Session;
import com.google.inject.Inject;
import com.google.inject.Provider;
import net.socialgamer.cah.CahModule.AllowBlankCards;
import net.socialgamer.cah.CahModule.GamePermalinkUrlFormat;
import net.socialgamer.cah.CahModule.RoundPermalinkUrlFormat;
import net.socialgamer.cah.CahModule.ShowGamePermalink;
@ -121,6 +122,7 @@ public class Game {
private final Provider<String> gamePermalinkFormatProvider;
private final Provider<Boolean> showRoundLinkProvider;
private final Provider<String> roundPermalinkFormatProvider;
private final Provider<Boolean> allowBlankCardsProvider;
private final long created = System.currentTimeMillis();
private int judgeIndex = 0;
@ -216,7 +218,8 @@ public class Game {
final Metrics metrics, @ShowRoundPermalink final Provider<Boolean> showRoundLinkProvider,
@RoundPermalinkUrlFormat final Provider<String> roundPermalinkFormatProvider,
@ShowGamePermalink final Provider<Boolean> showGameLinkProvider,
@GamePermalinkUrlFormat final Provider<String> gamePermalinkFormatProvider) {
@GamePermalinkUrlFormat final Provider<String> gamePermalinkFormatProvider,
@AllowBlankCards final Provider<Boolean> allowBlankCardsProvider) {
this.id = id;
this.connectedUsers = connectedUsers;
this.gameManager = gameManager;
@ -229,6 +232,7 @@ public class Game {
this.roundPermalinkFormatProvider = roundPermalinkFormatProvider;
this.showGameLinkProvider = showGameLinkProvider;
this.gamePermalinkFormatProvider = gamePermalinkFormatProvider;
this.allowBlankCardsProvider = allowBlankCardsProvider;
state = GameState.LOBBY;
}
@ -787,7 +791,7 @@ public class Game {
}
public WhiteDeck loadWhiteDeck(final List<CardSet> cardSets) {
return new WhiteDeck(cardSets, options.blanksInDeck);
return new WhiteDeck(cardSets, allowBlankCardsProvider.get() ? options.blanksInDeck : 0);
}
public int getRequiredWhiteCardCount() {

View File

@ -50,6 +50,7 @@ import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.Provides;
import net.socialgamer.cah.CahModule.AllowBlankCards;
import net.socialgamer.cah.CahModule.GamePermalinkUrlFormat;
import net.socialgamer.cah.CahModule.RoundPermalinkUrlFormat;
import net.socialgamer.cah.CahModule.ShowGamePermalink;
@ -121,6 +122,7 @@ public class GameManagerTest {
bind(String.class).annotatedWith(RoundPermalinkUrlFormat.class).toProvider(formatProvider);
bind(Boolean.class).annotatedWith(ShowGamePermalink.class).toProvider(falseProvider);
bind(String.class).annotatedWith(GamePermalinkUrlFormat.class).toProvider(formatProvider);
bind(Boolean.class).annotatedWith(AllowBlankCards.class).toProvider(falseProvider);
}
@Provides
@ -171,15 +173,15 @@ public class GameManagerTest {
assertEquals(0, gameManager.get().intValue());
gameManager.getGames().put(0,
new Game(0, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider,
formatProvider, falseProvider, formatProvider));
formatProvider, falseProvider, formatProvider, falseProvider));
assertEquals(1, gameManager.get().intValue());
gameManager.getGames().put(1,
new Game(1, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider,
formatProvider, falseProvider, formatProvider));
formatProvider, falseProvider, formatProvider, falseProvider));
assertEquals(2, gameManager.get().intValue());
gameManager.getGames().put(2,
new Game(2, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider,
formatProvider, falseProvider, formatProvider));
formatProvider, falseProvider, formatProvider, falseProvider));
// make sure it says it can't make any more
assertEquals(-1, gameManager.get().intValue());
@ -189,7 +191,7 @@ public class GameManagerTest {
assertEquals(1, gameManager.get().intValue());
gameManager.getGames().put(1,
new Game(1, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider,
formatProvider, falseProvider, formatProvider));
formatProvider, falseProvider, formatProvider, falseProvider));
assertEquals(-1, gameManager.get().intValue());
// remove game 1 out from under it, to make sure it'll fix itself
@ -197,7 +199,7 @@ public class GameManagerTest {
assertEquals(1, gameManager.get().intValue());
gameManager.getGames().put(1,
new Game(1, cuMock, gameManager, timer, null, null, null, metricsMock, falseProvider,
formatProvider, falseProvider, formatProvider));
formatProvider, falseProvider, formatProvider, falseProvider));
assertEquals(-1, gameManager.get().intValue());
gameManager.destroyGame(2);

View File

@ -79,7 +79,7 @@ public class GameTest {
gmMock = createMock(GameManager.class);
metricsMock = createMock(Metrics.class);
game = new Game(0, cuMock, gmMock, timer, null, null, null, metricsMock, falseProvider,
formatProvider, falseProvider, formatProvider);
formatProvider, falseProvider, formatProvider, falseProvider);
}
@SuppressWarnings("unchecked")