admins can send chat to all connected users
This commit is contained in:
parent
a768677eaf
commit
c662bf954d
|
@ -177,6 +177,17 @@ cah.ajax.Builder.prototype.withPassword = function(password) {
|
|||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean}
|
||||
* wall Whether or not this is a warn-all ("wall").
|
||||
* @returns {cah.ajax.Builder} This object.
|
||||
*/
|
||||
cah.ajax.Builder.prototype.withWall = function(wall) {
|
||||
this.assertNotExecuted_();
|
||||
this.data[cah.$.AjaxRequest.WALL] = wall;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert that the request from this builder has not already run. Throws an exception if it has.
|
||||
*
|
||||
|
|
|
@ -134,7 +134,7 @@ function chatsubmit_click(game_id, parent_element) {
|
|||
switch (cmd) {
|
||||
// TODO support an /ignore command
|
||||
case '':
|
||||
if (game_id != undefined) {
|
||||
if (game_id !== null) {
|
||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.GAME_CHAT).withGameId(game_id);
|
||||
} else {
|
||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT);
|
||||
|
@ -142,6 +142,9 @@ function chatsubmit_click(game_id, parent_element) {
|
|||
ajax = ajax.withMessage(text);
|
||||
cah.log.status_with_game(game_id, "<" + cah.nickname + "> " + text);
|
||||
break;
|
||||
case 'wall':
|
||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT).withWall(true).withMessage(text);
|
||||
break;
|
||||
case 'kick':
|
||||
ajax = cah.Ajax.build(cah.$.AjaxOperation.KICK).withNickname(text.split(' ')[0]);
|
||||
break;
|
||||
|
@ -153,12 +156,10 @@ function chatsubmit_click(game_id, parent_element) {
|
|||
ajax = cah.Ajax.build(cah.$.AjaxOperation.NAMES);
|
||||
break;
|
||||
default:
|
||||
cah.log.error("Invalid command.");
|
||||
}
|
||||
|
||||
if (ajax) {
|
||||
if (game_id !== null) {
|
||||
ajax.withGameId(game_id);
|
||||
}
|
||||
ajax.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ cah.$.AjaxRequest = function() {
|
|||
// Dummy constructor to make Eclipse auto-complete.
|
||||
};
|
||||
cah.$.AjaxRequest.prototype.dummyForAutocomplete = undefined;
|
||||
cah.$.AjaxRequest.WALL = "wall";
|
||||
cah.$.AjaxRequest.MESSAGE = "m";
|
||||
cah.$.AjaxRequest.CARD_ID = "cid";
|
||||
cah.$.AjaxRequest.GAME_ID = "gid";
|
||||
|
@ -163,7 +164,7 @@ cah.$.ErrorCode_msg['na'] = "You are not an administrator.";
|
|||
cah.$.ErrorCode_msg['niu'] = "Nickname is already in use.";
|
||||
cah.$.ErrorCode_msg['B&'] = "Banned.";
|
||||
cah.$.ErrorCode_msg['ad'] = "Access denied.";
|
||||
cah.$.ErrorCode_msg['nj'] = "You aren't the judge.";
|
||||
cah.$.ErrorCode_msg['nj'] = "You are not the judge.";
|
||||
|
||||
cah.$.GameInfo = function() {
|
||||
// Dummy constructor to make Eclipse auto-complete.
|
||||
|
@ -259,6 +260,7 @@ cah.$.LongPollResponse = function() {
|
|||
// Dummy constructor to make Eclipse auto-complete.
|
||||
};
|
||||
cah.$.LongPollResponse.prototype.dummyForAutocomplete = undefined;
|
||||
cah.$.LongPollResponse.WALL = "wall";
|
||||
cah.$.LongPollResponse.WHITE_CARDS = "wc";
|
||||
cah.$.LongPollResponse.REASON = "qr";
|
||||
cah.$.LongPollResponse.GAME_ID = "gid";
|
||||
|
|
|
@ -100,19 +100,31 @@ cah.log.status_with_game = function(game_or_id, text, opt_class) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Log a message for the user to see, always, as an error message.
|
||||
* Log a message for the user to see, always, in every tab, as an error message.
|
||||
*
|
||||
* @param {string}
|
||||
* text Text to display for this message. Text is added as a TextNode, so HTML is properly
|
||||
* escaped automatically.
|
||||
*/
|
||||
cah.log.error = function(text) {
|
||||
cah.log.status("Error: " + text, "error");
|
||||
cah.log.everyWindow("Error: " + text, "error");
|
||||
};
|
||||
|
||||
/**
|
||||
* Log a message for the user to see, always, in every tab.
|
||||
*
|
||||
* @param {string}
|
||||
* text Text to display for this message. Text is added as a TextNode, so HTML is properly
|
||||
* escaped automatically.
|
||||
* @param {string}
|
||||
* opt_class Optional CSS class to use for this message.
|
||||
*/
|
||||
cah.log.everyWindow = function(text, opt_class) {
|
||||
cah.log.status(text, opt_class);
|
||||
|
||||
// Log errors in all windows.
|
||||
for (game_id in cah.currentGames) {
|
||||
if (cah.currentGames.hasOwnProperty(game_id)) {
|
||||
cah.log.status_with_game(game_id, "Error: " + text, "error");
|
||||
cah.log.status_with_game(game_id, text, opt_class);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -88,7 +88,6 @@ cah.longpoll.EventHandlers[cah.$.LongPollEvent.BANNED] = function() {
|
|||
};
|
||||
|
||||
cah.longpoll.EventHandlers[cah.$.LongPollEvent.CHAT] = function(data) {
|
||||
// TODO deal with multiple channels eventually
|
||||
var clazz = undefined;
|
||||
var from = data[cah.$.LongPollResponse.FROM];
|
||||
var show = !cah.ignoreList[from];
|
||||
|
@ -97,14 +96,20 @@ cah.longpoll.EventHandlers[cah.$.LongPollEvent.CHAT] = function(data) {
|
|||
clazz = "admin";
|
||||
show = true;
|
||||
}
|
||||
if (cah.$.LongPollResponse.GAME_ID in data) {
|
||||
game = data[cah.$.LongPollResponse.GAME_ID];
|
||||
}
|
||||
if (data[cah.$.LongPollResponse.WALL]) {
|
||||
// treat these specially
|
||||
cah.log.everyWindow(
|
||||
"Global message from " + from + ": " + data[cah.$.LongPollResponse.MESSAGE], clazz);
|
||||
} else {
|
||||
if (cah.$.LongPollResponse.GAME_ID in data) {
|
||||
game = data[cah.$.LongPollResponse.GAME_ID];
|
||||
}
|
||||
|
||||
// don't display our own chat
|
||||
if (from != cah.nickname && show) {
|
||||
cah.log.status_with_game(game, "<" + data[cah.$.LongPollResponse.FROM] + "> "
|
||||
+ data[cah.$.LongPollResponse.MESSAGE], clazz);
|
||||
// don't display our own chat
|
||||
if (from != cah.nickname && show) {
|
||||
cah.log.status_with_game(game, "<" + data[cah.$.LongPollResponse.FROM] + "> "
|
||||
+ data[cah.$.LongPollResponse.MESSAGE], clazz);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -209,7 +209,8 @@ public class Constants {
|
|||
PASSWORD("pw"),
|
||||
PLAYER_LIMIT("pL"),
|
||||
SCORE_LIMIT("sl"),
|
||||
SERIAL("s");
|
||||
SERIAL("s"),
|
||||
WALL("wall");
|
||||
|
||||
private final String field;
|
||||
|
||||
|
@ -309,7 +310,7 @@ public class Constants {
|
|||
NOT_ENOUGH_PLAYERS("nep", "There are not enough players to start the game."),
|
||||
NOT_GAME_HOST("ngh", "Only the game host can do that."),
|
||||
NOT_IN_THAT_GAME("nitg", "You are not in that game."),
|
||||
NOT_JUDGE("nj", "You aren't the judge."),
|
||||
NOT_JUDGE("nj", "You are not the judge."),
|
||||
NOT_REGISTERED("nr", "Not registered. Refresh the page."),
|
||||
NOT_YOUR_TURN("nyt", "It is not your turn to play a card."),
|
||||
OP_NOT_SPECIFIED("ons", "Operation not specified."),
|
||||
|
@ -444,6 +445,8 @@ public class Constants {
|
|||
ROUND_WINNER("rw"),
|
||||
TIMESTAMP("ts"),
|
||||
@DuplicationAllowed
|
||||
WALL(AjaxRequest.WALL),
|
||||
@DuplicationAllowed
|
||||
WHITE_CARDS(AjaxResponse.WHITE_CARDS),
|
||||
WINNING_CARD("WC");
|
||||
|
||||
|
|
|
@ -67,9 +67,13 @@ public class ChatHandler extends Handler {
|
|||
|
||||
final User user = (User) session.getAttribute(SessionAttribute.USER);
|
||||
assert (user != null);
|
||||
final boolean wall = request.getParameter(AjaxRequest.WALL) != null
|
||||
&& Boolean.valueOf(request.getParameter(AjaxRequest.WALL));
|
||||
|
||||
if (request.getParameter(AjaxRequest.MESSAGE) == null) {
|
||||
return error(ErrorCode.NO_MSG_SPECIFIED);
|
||||
} else if (wall && !user.isAdmin()) {
|
||||
return error(ErrorCode.NOT_ADMIN);
|
||||
} else {
|
||||
final String message = request.getParameter(AjaxRequest.MESSAGE).trim();
|
||||
|
||||
|
@ -93,8 +97,12 @@ public class ChatHandler extends Handler {
|
|||
broadcastData.put(LongPollResponse.EVENT, LongPollEvent.CHAT.toString());
|
||||
broadcastData.put(LongPollResponse.FROM, user.getNickname());
|
||||
broadcastData.put(LongPollResponse.MESSAGE, message);
|
||||
broadcastData.put(LongPollResponse.FROM_ADMIN, user.isAdmin());
|
||||
// broadcastData.put(LongPollResponse.GAME_ID, -1);
|
||||
if (user.isAdmin()) {
|
||||
broadcastData.put(LongPollResponse.FROM_ADMIN, true);
|
||||
}
|
||||
if (wall) {
|
||||
broadcastData.put(LongPollResponse.WALL, true);
|
||||
}
|
||||
users.broadcastToAll(MessageType.CHAT, broadcastData);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue