Tell admins about filtered chat content.
Including chat in games that the admin isn't in.
This commit is contained in:
parent
612bd09978
commit
a505598c0d
|
@ -328,6 +328,7 @@ cah.$.LongPollEvent.HURRY_UP = "hu";
|
|||
cah.$.LongPollEvent.GAME_JUDGE_LEFT = "gjl";
|
||||
cah.$.LongPollEvent.KICKED = "k";
|
||||
cah.$.LongPollEvent.KICKED_FROM_GAME_IDLE = "kfgi";
|
||||
cah.$.LongPollEvent.FILTERED_CHAT = "FC";
|
||||
cah.$.LongPollEvent.GAME_STATE_CHANGE = "gsc";
|
||||
|
||||
cah.$.LongPollResponse = function() {
|
||||
|
|
|
@ -92,12 +92,22 @@ cah.longpoll.EventHandlers[cah.$.LongPollEvent.BANNED] = function() {
|
|||
};
|
||||
|
||||
cah.longpoll.EventHandlers[cah.$.LongPollEvent.CHAT] = function(data) {
|
||||
cah.longpoll.showChat_(data, false);
|
||||
};
|
||||
|
||||
cah.longpoll.EventHandlers[cah.$.LongPollEvent.FILTERED_CHAT] = function(data) {
|
||||
cah.longpoll.showChat_(data, true);
|
||||
};
|
||||
|
||||
cah.longpoll.showChat_ = function(data, wasFiltered) {
|
||||
var clazz = undefined;
|
||||
var idcode = data[cah.$.LongPollResponse.ID_CODE];
|
||||
var title = cah.log.getTitleForIdCode(idcode);
|
||||
var sigil = data[cah.$.LongPollResponse.SIGIL];
|
||||
var from = data[cah.$.LongPollResponse.FROM];
|
||||
var who = sigil + from;
|
||||
var show = !cah.ignoreList[from];
|
||||
var message = data[cah.$.LongPollResponse.MESSAGE];
|
||||
var game = null;
|
||||
if (sigil == cah.$.Sigil.ADMIN) {
|
||||
clazz = "admin";
|
||||
|
@ -105,20 +115,29 @@ cah.longpoll.EventHandlers[cah.$.LongPollEvent.CHAT] = function(data) {
|
|||
}
|
||||
if (data[cah.$.LongPollResponse.WALL]) {
|
||||
// treat these specially
|
||||
cah.log.everyWindow("Global message from " + sigil + from + ": "
|
||||
+ data[cah.$.LongPollResponse.MESSAGE], clazz, false, title);
|
||||
cah.log.everyWindow("Global message from " + who + ": " + message, clazz, false, title);
|
||||
} else {
|
||||
if (cah.$.LongPollResponse.GAME_ID in data) {
|
||||
game = data[cah.$.LongPollResponse.GAME_ID];
|
||||
}
|
||||
if (wasFiltered) {
|
||||
clazz = "error";
|
||||
show = true;
|
||||
// there might be a game id that we're not in
|
||||
if (cah.$.LongPollResponse.GAME_ID in data) {
|
||||
message = "(In game " + game + ") " + message;
|
||||
// always show this in global chat since we're probably not in that game.
|
||||
game = null;
|
||||
}
|
||||
message = "(Filtered) " + message;
|
||||
}
|
||||
|
||||
// don't display our own chat
|
||||
if (from != cah.nickname && show) {
|
||||
var message = data[cah.$.LongPollResponse.MESSAGE];
|
||||
if (data[cah.$.LongPollResponse.EMOTE]) {
|
||||
cah.log.status_with_game(game, "* " + sigil + from + " " + message, clazz, false, title);
|
||||
cah.log.status_with_game(game, "* " + who + " " + message, clazz, false, title);
|
||||
} else {
|
||||
cah.log.status_with_game(game, "<" + sigil + from + "> " + message, clazz, false, title);
|
||||
cah.log.status_with_game(game, "<" + who + "> " + message, clazz, false, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -448,6 +448,7 @@ public class Constants {
|
|||
CARDCAST_REMOVE_CARDSET(AjaxOperation.CARDCAST_REMOVE_CARDSET),
|
||||
@DuplicationAllowed
|
||||
CHAT(AjaxOperation.CHAT),
|
||||
FILTERED_CHAT("FC"),
|
||||
GAME_BLACK_RESHUFFLE("gbr"),
|
||||
GAME_JUDGE_LEFT("gjl"),
|
||||
GAME_JUDGE_SKIPPED("gjs"),
|
||||
|
|
|
@ -91,13 +91,16 @@ public class ChatHandler extends Handler {
|
|||
} else {
|
||||
final String message = request.getParameter(AjaxRequest.MESSAGE).trim();
|
||||
|
||||
LongPollEvent event = LongPollEvent.CHAT;
|
||||
final ChatFilter.Result filterResult = chatFilter.filterGlobal(user, message);
|
||||
switch (filterResult) {
|
||||
case CAPSLOCK:
|
||||
return error(ErrorCode.CAPSLOCK);
|
||||
case DROP_MESSAGE:
|
||||
// Don't tell the user we dropped it, and don't send it to everyone else...
|
||||
return data;
|
||||
// but let any online admins know about it
|
||||
event = LongPollEvent.FILTERED_CHAT;
|
||||
break;
|
||||
case NO_MESSAGE:
|
||||
return error(ErrorCode.NO_MSG_SPECIFIED);
|
||||
case NOT_ENOUGH_SPACES:
|
||||
|
@ -118,7 +121,7 @@ public class ChatHandler extends Handler {
|
|||
}
|
||||
|
||||
final HashMap<ReturnableData, Object> broadcastData = new HashMap<ReturnableData, Object>();
|
||||
broadcastData.put(LongPollResponse.EVENT, LongPollEvent.CHAT.toString());
|
||||
broadcastData.put(LongPollResponse.EVENT, event.toString());
|
||||
broadcastData.put(LongPollResponse.FROM, user.getNickname());
|
||||
broadcastData.put(LongPollResponse.MESSAGE, message);
|
||||
broadcastData.put(LongPollResponse.ID_CODE, user.getIdCode());
|
||||
|
@ -132,7 +135,11 @@ public class ChatHandler extends Handler {
|
|||
if (emote) {
|
||||
broadcastData.put(LongPollResponse.EMOTE, true);
|
||||
}
|
||||
users.broadcastToAll(MessageType.CHAT, broadcastData);
|
||||
if (LongPollEvent.CHAT == event) {
|
||||
users.broadcastToAll(MessageType.CHAT, broadcastData);
|
||||
} else {
|
||||
users.broadcastToList(users.getAdmins(), MessageType.CHAT, broadcastData);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
|
|
@ -39,6 +39,7 @@ import net.socialgamer.cah.Constants.LongPollEvent;
|
|||
import net.socialgamer.cah.Constants.LongPollResponse;
|
||||
import net.socialgamer.cah.Constants.ReturnableData;
|
||||
import net.socialgamer.cah.RequestWrapper;
|
||||
import net.socialgamer.cah.data.ConnectedUsers;
|
||||
import net.socialgamer.cah.data.Game;
|
||||
import net.socialgamer.cah.data.GameManager;
|
||||
import net.socialgamer.cah.data.QueuedMessage.MessageType;
|
||||
|
@ -57,11 +58,14 @@ public class GameChatHandler extends GameWithPlayerHandler {
|
|||
public static final String OP = AjaxOperation.GAME_CHAT.toString();
|
||||
|
||||
private final ChatFilter chatFilter;
|
||||
private final ConnectedUsers users;
|
||||
|
||||
@Inject
|
||||
public GameChatHandler(final GameManager gameManager, final ChatFilter chatFilter) {
|
||||
public GameChatHandler(final GameManager gameManager, final ChatFilter chatFilter,
|
||||
final ConnectedUsers users) {
|
||||
super(gameManager);
|
||||
this.chatFilter = chatFilter;
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,6 +75,7 @@ public class GameChatHandler extends GameWithPlayerHandler {
|
|||
final boolean emote = request.getParameter(AjaxRequest.EMOTE) != null
|
||||
&& Boolean.valueOf(request.getParameter(AjaxRequest.EMOTE));
|
||||
|
||||
LongPollEvent event = LongPollEvent.CHAT;
|
||||
if (request.getParameter(AjaxRequest.MESSAGE) == null) {
|
||||
return error(ErrorCode.NO_MSG_SPECIFIED);
|
||||
} else {
|
||||
|
@ -82,7 +87,9 @@ public class GameChatHandler extends GameWithPlayerHandler {
|
|||
return error(ErrorCode.CAPSLOCK);
|
||||
case DROP_MESSAGE:
|
||||
// Don't tell the user we dropped it, and don't send it to everyone else...
|
||||
return data;
|
||||
// but let any online admins know about it
|
||||
event = LongPollEvent.FILTERED_CHAT;
|
||||
break;
|
||||
case NO_MESSAGE:
|
||||
return error(ErrorCode.NO_MSG_SPECIFIED);
|
||||
case NOT_ENOUGH_SPACES:
|
||||
|
@ -103,7 +110,7 @@ public class GameChatHandler extends GameWithPlayerHandler {
|
|||
}
|
||||
|
||||
final HashMap<ReturnableData, Object> broadcastData = new HashMap<ReturnableData, Object>();
|
||||
broadcastData.put(LongPollResponse.EVENT, LongPollEvent.CHAT.toString());
|
||||
broadcastData.put(LongPollResponse.EVENT, event.toString());
|
||||
broadcastData.put(LongPollResponse.FROM, user.getNickname());
|
||||
broadcastData.put(LongPollResponse.MESSAGE, message);
|
||||
broadcastData.put(LongPollResponse.FROM_ADMIN, user.isAdmin());
|
||||
|
@ -111,7 +118,11 @@ public class GameChatHandler extends GameWithPlayerHandler {
|
|||
broadcastData.put(LongPollResponse.SIGIL, user.getSigil().toString());
|
||||
broadcastData.put(LongPollResponse.GAME_ID, game.getId());
|
||||
broadcastData.put(LongPollResponse.EMOTE, emote);
|
||||
game.broadcastToPlayers(MessageType.CHAT, broadcastData);
|
||||
if (LongPollEvent.CHAT == event) {
|
||||
game.broadcastToPlayers(MessageType.CHAT, broadcastData);
|
||||
} else {
|
||||
users.broadcastToList(users.getAdmins(), MessageType.CHAT, broadcastData);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
|
Loading…
Reference in New Issue