Enabled/disable custom decks + added entry in stats.jsp
This commit is contained in:
parent
5810e85039
commit
a092739b9e
|
@ -53,4 +53,5 @@ out.println("METRICS_GAME_ENABLED " + props.get("pyx.metrics.game.enabled"));
|
|||
out.println("METRICS_ROUND_ENABLED " + props.get("pyx.metrics.round.enabled"));
|
||||
out.println("METRICS_SESSION_ENABLED " + props.get("pyx.metrics.session.enabled"));
|
||||
out.println("METRICS_USER_ENABLED " + props.get("pyx.metrics.user.enabled"));
|
||||
out.println("CUSTOM_DECKS_ENABLED " + props.get("pyx.server.custom_decks_enabled"));
|
||||
%>
|
||||
|
|
|
@ -16,6 +16,8 @@ pyx.id_code_salt=
|
|||
pyx.admin_addrs=127.0.0.1,0:0:0:0:0:0:0:1
|
||||
# comma-separated list of strings banned from appearing in nicks.
|
||||
pyx.banned_nicks=xyzzy
|
||||
# whether the custom decks functionality is enabled
|
||||
pyx.custom_decks_enabled=true
|
||||
# comma-separated list of url patterns to allow custom decks
|
||||
pyx.allowed_custom_decks_urls=*
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
pyx.client.cookie_domain=${pyx.cookie_domain}
|
||||
pyx.server.custom_decks_enabled=${pyx.custom_decks_enabled}
|
||||
pyx.server.allowed_custom_decks_urls=${pyx.allowed_custom_decks_urls}
|
||||
pyx.server.include_inactive_cardsets=${pyx.include_inactive_cardsets}
|
||||
pyx.server.max_users=${pyx.max_users}
|
||||
|
|
|
@ -307,6 +307,14 @@ public class CahModule extends AbstractModule {
|
|||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@CustomDecksEnabled
|
||||
Boolean provideCustomDecksEnabled() {
|
||||
synchronized (properties) {
|
||||
return Boolean.valueOf(properties.getProperty("pyx.server.custom_decks_enabled", "true"));
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@CustomDecksAllowedUrls
|
||||
List<String> provideAllowedCustomDecksUrls() {
|
||||
|
@ -315,6 +323,11 @@ public class CahModule extends AbstractModule {
|
|||
}
|
||||
}
|
||||
|
||||
@BindingAnnotation
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CustomDecksEnabled {
|
||||
}
|
||||
|
||||
@BindingAnnotation
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CustomDecksAllowedUrls {
|
||||
|
|
|
@ -28,7 +28,9 @@ import com.google.common.base.Charsets;
|
|||
import com.google.common.io.ByteSource;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import net.socialgamer.cah.CahModule;
|
||||
import net.socialgamer.cah.CahModule.CustomDecksAllowedUrls;
|
||||
import net.socialgamer.cah.CahModule.CustomDecksEnabled;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -73,10 +75,12 @@ public class CustomCardsService {
|
|||
private static final AtomicInteger deckIdCounter = new AtomicInteger(0);
|
||||
|
||||
private final Bencode bencode = new Bencode();
|
||||
private final Provider<Boolean> enabledProvider;
|
||||
private final Provider<List<String>> allowedUrlsProvider;
|
||||
|
||||
@Inject
|
||||
public CustomCardsService(@CustomDecksAllowedUrls Provider<List<String>> allowedUrlsProvider) {
|
||||
public CustomCardsService(@CustomDecksEnabled Provider<Boolean> enabledProvider, @CustomDecksAllowedUrls Provider<List<String>> allowedUrlsProvider) {
|
||||
this.enabledProvider = enabledProvider;
|
||||
this.allowedUrlsProvider = allowedUrlsProvider;
|
||||
}
|
||||
|
||||
|
@ -98,12 +102,18 @@ public class CustomCardsService {
|
|||
}
|
||||
|
||||
public CustomDeck loadSet(int customDeckId) {
|
||||
if (!enabledProvider.get())
|
||||
return null;
|
||||
|
||||
CacheEntry entry = checkCacheId(customDeckId);
|
||||
if (checkCacheValid(entry, "id", String.valueOf(customDeckId))) return entry.deck;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public CustomDeck loadSetFromUrl(String url) {
|
||||
if (!enabledProvider.get())
|
||||
return null;
|
||||
|
||||
CacheEntry entry = checkCacheUrl(url);
|
||||
if (checkCacheValid(entry, "url", url))
|
||||
return entry.deck;
|
||||
|
@ -125,6 +135,9 @@ public class CustomCardsService {
|
|||
}
|
||||
|
||||
public CustomDeck loadSetFromJson(String jsonStr, String url) {
|
||||
if (!enabledProvider.get())
|
||||
return null;
|
||||
|
||||
JSONObject obj;
|
||||
String hash;
|
||||
try {
|
||||
|
|
|
@ -152,6 +152,12 @@ public class GameManagerTest {
|
|||
return "1";
|
||||
}
|
||||
|
||||
@Provides
|
||||
@CustomDecksEnabled
|
||||
Boolean provideCustomDecksEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@CustomDecksAllowedUrls
|
||||
List<String> provideAllowedCustomDecksUrls() {
|
||||
|
|
Loading…
Reference in New Issue