From 7be74010a6988f886e830e62584b89fda349476c Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Sat, 30 Nov 2013 22:09:55 -0800 Subject: [PATCH] properties file support for game and player limits. add this information to stats.jsp --- WebContent/WEB-INF/pyx.properties | 2 ++ WebContent/admin.jsp | 9 +++++++- WebContent/stats.jsp | 4 ++++ src/net/socialgamer/cah/CahModule.java | 26 ++++++++++++++++++++--- src/net/socialgamer/cah/StartupUtils.java | 17 +++++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 WebContent/WEB-INF/pyx.properties diff --git a/WebContent/WEB-INF/pyx.properties b/WebContent/WEB-INF/pyx.properties new file mode 100644 index 0000000..d8b7cb0 --- /dev/null +++ b/WebContent/WEB-INF/pyx.properties @@ -0,0 +1,2 @@ +pyx.server.max_users=800 +pyx.server.max_games=200 diff --git a/WebContent/admin.jsp b/WebContent/admin.jsp index 058850a..84c42ea 100644 --- a/WebContent/admin.jsp +++ b/WebContent/admin.jsp @@ -37,7 +37,6 @@ Administration tools. <%@ page import="net.socialgamer.cah.Constants.LongPollEvent" %> <%@ page import="net.socialgamer.cah.Constants.LongPollResponse" %> <%@ page import="net.socialgamer.cah.Constants.ReturnableData" %> -<%@ page import="net.socialgamer.cah.StartupUtils" %> <%@ page import="net.socialgamer.cah.data.ConnectedUsers" %> <%@ page import="net.socialgamer.cah.data.QueuedMessage" %> <%@ page import="net.socialgamer.cah.data.QueuedMessage.MessageType" %> @@ -122,6 +121,11 @@ if ("true".equals(reloadLog4j)) { StartupUtils.reconfigureLogging(this.getServletContext()); } +String reloadProps = request.getParameter("reloadProps"); +if ("true".equals(reloadProps)) { + StartupUtils.reloadProperties(this.getServletContext()); +} + %> @@ -235,6 +239,9 @@ boolean verboseDebug = verboseDebugObj != null ? verboseDebugObj.booleanValue()

Reload log4j.properties.

+

+ Reload pyx.properties. +

diff --git a/WebContent/stats.jsp b/WebContent/stats.jsp index fabf776..f8cf414 100644 --- a/WebContent/stats.jsp +++ b/WebContent/stats.jsp @@ -28,6 +28,7 @@ most useful graph if it is only updated every 15 minutes, but it is still nice t @author Andy Janata (ajanata@socialgamer.net) --%> <%@ page language="java" contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8" %> +<%@ page import="java.util.Properties" %> <%@ page import="com.google.inject.Injector" %> <%@ page import="net.socialgamer.cah.data.ConnectedUsers" %> <%@ page import="net.socialgamer.cah.data.GameManager" %> @@ -38,8 +39,11 @@ Injector injector = (Injector) servletContext.getAttribute(StartupUtils.INJECTOR ConnectedUsers users = injector.getInstance(ConnectedUsers.class); GameManager games = injector.getInstance(GameManager.class); +Properties props = injector.getInstance(Properties.class); out.clear(); out.println("USERS " + users.getUsers().size()); out.println("GAMES " + games.getGameList().size()); +out.println("MAX_USERS " + props.get("pyx.server.max_users")); +out.println("MAX_GAMES " + props.get("pyx.server.max_games")); %> diff --git a/src/net/socialgamer/cah/CahModule.java b/src/net/socialgamer/cah/CahModule.java index 8f76ba6..4884265 100644 --- a/src/net/socialgamer/cah/CahModule.java +++ b/src/net/socialgamer/cah/CahModule.java @@ -27,6 +27,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Collections; import java.util.HashSet; +import java.util.Properties; import java.util.Set; import net.socialgamer.cah.data.GameManager; @@ -53,14 +54,26 @@ public class CahModule extends AbstractModule { } /** - * TODO Provide a configuration option for this instead of hard-coding it. - * * @return The maximum number of games allowed on this server. */ @Provides @MaxGames Integer provideMaxGames() { - return 250; + return Integer.valueOf((String) properties.get("pyx.server.max_games")); + } + + /** + * @return The maximum number of users allowed to connect to this server. + */ + @Provides + @MaxUsers + Integer provideMaxUsers() { + return Integer.valueOf((String) properties.get("pyx.server.max_users")); + } + + @BindingAnnotation + @Retention(RetentionPolicy.RUNTIME) + public @interface MaxUsers { } /** @@ -88,4 +101,11 @@ public class CahModule extends AbstractModule { @Retention(RetentionPolicy.RUNTIME) public @interface BanList { } + + private final static Properties properties = new Properties(); + + @Provides + Properties provideProperties() { + return properties; + } } diff --git a/src/net/socialgamer/cah/StartupUtils.java b/src/net/socialgamer/cah/StartupUtils.java index b5b1f24..98563d3 100644 --- a/src/net/socialgamer/cah/StartupUtils.java +++ b/src/net/socialgamer/cah/StartupUtils.java @@ -23,7 +23,10 @@ package net.socialgamer.cah; +import java.io.File; +import java.io.FileReader; import java.util.Date; +import java.util.Properties; import java.util.Timer; import javax.servlet.ServletContext; @@ -106,6 +109,20 @@ public class StartupUtils extends GuiceServletContextListener { context.setAttribute(DATE_NAME, serverStarted); reconfigureLogging(contextEvent.getServletContext()); + reloadProperties(contextEvent.getServletContext()); + } + + public static void reloadProperties(final ServletContext context) { + final Injector injector = (Injector) context.getAttribute(INJECTOR); + final Properties props = injector.getInstance(Properties.class); + final File propsFile = new File(context.getRealPath("/WEB-INF/pyx.properties")); + try { + props.clear(); + props.load(new FileReader(propsFile)); + } catch (final Exception e) { + // we should probably do something? + e.printStackTrace(); + } } public static void reconfigureLogging(final ServletContext context) {