Let global chat enablement be configured via the properties file. Can be adjusted on the fly, though clients are not notified of the change (which doesn't affect the client's operation anyway).
This commit is contained in:
parent
e2960eef7d
commit
cb0f2689c6
|
@ -96,7 +96,9 @@ cah.ajax.after_registered = function() {
|
||||||
$("#bottom").removeClass("hide");
|
$("#bottom").removeClass("hide");
|
||||||
// TODO once there are channels, this needs to specify the global channel
|
// TODO once there are channels, this needs to specify the global channel
|
||||||
cah.Ajax.build(cah.$.AjaxOperation.NAMES).run();
|
cah.Ajax.build(cah.$.AjaxOperation.NAMES).run();
|
||||||
cah.log.error("IMPORTANT: Global chat has been disabled.");
|
if (!cah.GLOBAL_CHAT_ENABLED) {
|
||||||
|
cah.log.error("IMPORTANT: Global chat has been disabled.");
|
||||||
|
}
|
||||||
cah.GameList.instance.show();
|
cah.GameList.instance.show();
|
||||||
cah.GameList.instance.update();
|
cah.GameList.instance.update();
|
||||||
cah.longpoll.longPoll();
|
cah.longpoll.longPoll();
|
||||||
|
|
|
@ -3,6 +3,7 @@ pyx.max_users=100
|
||||||
pyx.max_games=25
|
pyx.max_games=25
|
||||||
pyx.include_inactive_cardsets=true
|
pyx.include_inactive_cardsets=true
|
||||||
pyx.broadcast_connects_and_disconnects=true
|
pyx.broadcast_connects_and_disconnects=true
|
||||||
|
pyx.global_chat_enabled=true
|
||||||
|
|
||||||
# for production use, use postgres
|
# for production use, use postgres
|
||||||
#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
|
|
|
@ -3,6 +3,7 @@ pyx.server.include_inactive_cardsets=${pyx.include_inactive_cardsets}
|
||||||
pyx.server.max_users=${pyx.max_users}
|
pyx.server.max_users=${pyx.max_users}
|
||||||
pyx.server.max_games=${pyx.max_games}
|
pyx.server.max_games=${pyx.max_games}
|
||||||
pyx.server.broadcast_connects_and_disconnects=${pyx.broadcast_connects_and_disconnects}
|
pyx.server.broadcast_connects_and_disconnects=${pyx.broadcast_connects_and_disconnects}
|
||||||
|
pyx.server.global_chat_enabled=${pyx.global_chat_enabled}
|
||||||
pyx.build=${buildNumber}
|
pyx.build=${buildNumber}
|
||||||
|
|
||||||
# this is NOT allowed to be changed during a reload, as metrics depend on previous events
|
# this is NOT allowed to be changed during a reload, as metrics depend on previous events
|
||||||
|
|
|
@ -159,6 +159,15 @@ public class CahModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@GlobalChatEnabled
|
||||||
|
Boolean provideGlobalChatEnabled() {
|
||||||
|
synchronized (properties) {
|
||||||
|
return Boolean.valueOf(properties.getProperty(
|
||||||
|
"pyx.server.global_chat_enabled", "true"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@CookieDomain
|
@CookieDomain
|
||||||
String getCookieDomain() {
|
String getCookieDomain() {
|
||||||
|
@ -204,6 +213,11 @@ public class CahModule extends AbstractModule {
|
||||||
public @interface BroadcastConnectsAndDisconnects {
|
public @interface BroadcastConnectsAndDisconnects {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BindingAnnotation
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface GlobalChatEnabled {
|
||||||
|
}
|
||||||
|
|
||||||
@BindingAnnotation
|
@BindingAnnotation
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CookieDomain {
|
public @interface CookieDomain {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2012, Andy Janata
|
* Copyright (c) 2012-2018, Andy Janata
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||||
|
@ -28,6 +28,9 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import net.socialgamer.cah.CahModule.GlobalChatEnabled;
|
||||||
import net.socialgamer.cah.Constants;
|
import net.socialgamer.cah.Constants;
|
||||||
import net.socialgamer.cah.Constants.AjaxOperation;
|
import net.socialgamer.cah.Constants.AjaxOperation;
|
||||||
import net.socialgamer.cah.Constants.AjaxRequest;
|
import net.socialgamer.cah.Constants.AjaxRequest;
|
||||||
|
@ -41,8 +44,6 @@ import net.socialgamer.cah.data.ConnectedUsers;
|
||||||
import net.socialgamer.cah.data.QueuedMessage.MessageType;
|
import net.socialgamer.cah.data.QueuedMessage.MessageType;
|
||||||
import net.socialgamer.cah.data.User;
|
import net.socialgamer.cah.data.User;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for chat messages.
|
* Handler for chat messages.
|
||||||
|
@ -54,10 +55,13 @@ public class ChatHandler extends Handler {
|
||||||
public static final String OP = AjaxOperation.CHAT.toString();
|
public static final String OP = AjaxOperation.CHAT.toString();
|
||||||
|
|
||||||
private final ConnectedUsers users;
|
private final ConnectedUsers users;
|
||||||
|
private final boolean globalChatEnabled;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ChatHandler(final ConnectedUsers users) {
|
public ChatHandler(final ConnectedUsers users,
|
||||||
|
@GlobalChatEnabled final boolean globalChatEnabled) {
|
||||||
this.users = users;
|
this.users = users;
|
||||||
|
this.globalChatEnabled = globalChatEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,8 +78,10 @@ public class ChatHandler extends Handler {
|
||||||
|
|
||||||
if (request.getParameter(AjaxRequest.MESSAGE) == null) {
|
if (request.getParameter(AjaxRequest.MESSAGE) == null) {
|
||||||
return error(ErrorCode.NO_MSG_SPECIFIED);
|
return error(ErrorCode.NO_MSG_SPECIFIED);
|
||||||
} else if (/* wall && */!user.isAdmin()) {
|
} else if (wall && !user.isAdmin()) {
|
||||||
// Making global chat admin-only because it's hopeless
|
return error(ErrorCode.NOT_ADMIN);
|
||||||
|
} else if (!globalChatEnabled && !user.isAdmin()) {
|
||||||
|
// global chat can be turned off in the properties file
|
||||||
return error(ErrorCode.NOT_ADMIN);
|
return error(ErrorCode.NOT_ADMIN);
|
||||||
} else {
|
} else {
|
||||||
final String message = request.getParameter(AjaxRequest.MESSAGE).trim();
|
final String message = request.getParameter(AjaxRequest.MESSAGE).trim();
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2012-2018, Andy Janata
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||||
|
* provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||||
|
* and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer in the documentation and/or other materials provided
|
||||||
|
* with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
package net.socialgamer.cah.servlets;
|
package net.socialgamer.cah.servlets;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -10,12 +33,13 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import net.socialgamer.cah.CahModule.CookieDomain;
|
|
||||||
import net.socialgamer.cah.StartupUtils;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
|
||||||
|
import net.socialgamer.cah.CahModule.CookieDomain;
|
||||||
|
import net.socialgamer.cah.CahModule.GlobalChatEnabled;
|
||||||
|
import net.socialgamer.cah.StartupUtils;
|
||||||
|
|
||||||
|
|
||||||
@WebServlet("/js/cah.config.js")
|
@WebServlet("/js/cah.config.js")
|
||||||
public class JavascriptConfigServlet extends HttpServlet {
|
public class JavascriptConfigServlet extends HttpServlet {
|
||||||
|
@ -47,16 +71,18 @@ public class JavascriptConfigServlet extends HttpServlet {
|
||||||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
// We have to do this every time since it comes from the properties file and that can change...
|
// We have to do this every time since these come from the properties file and that can change...
|
||||||
final StringBuilder builder = new StringBuilder(256);
|
final StringBuilder builder = new StringBuilder(256).append(configString);
|
||||||
// Ideally we'd figure out how to make this Servlet itself injectable but I don't have time.
|
// Ideally we'd figure out how to make this Servlet itself injectable but I don't have time.
|
||||||
final Injector injector = (Injector) getServletContext().getAttribute(StartupUtils.INJECTOR);
|
final Injector injector = (Injector) getServletContext().getAttribute(StartupUtils.INJECTOR);
|
||||||
final String cookieDomain = injector.getInstance(Key.get(String.class, CookieDomain.class));
|
final String cookieDomain = injector.getInstance(Key.get(String.class, CookieDomain.class));
|
||||||
|
final Boolean globalChatEnabled = injector.getInstance(Key.get(Boolean.class, GlobalChatEnabled.class));
|
||||||
builder.append(String.format("cah.COOKIE_DOMAIN = '%s';\n", cookieDomain));
|
builder.append(String.format("cah.COOKIE_DOMAIN = '%s';\n", cookieDomain));
|
||||||
|
builder.append(String.format("cah.GLOBAL_CHAT_ENABLED = %b;\n", globalChatEnabled));
|
||||||
|
|
||||||
resp.setContentType("text/javascript");
|
resp.setContentType("text/javascript");
|
||||||
final PrintWriter out = resp.getWriter();
|
final PrintWriter out = resp.getWriter();
|
||||||
out.println(configString + builder.toString());
|
out.println(builder.toString());
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue