Add /me command to support emotes.

This commit is contained in:
uecasm 2013-10-03 00:28:16 +13:00
parent d03dac9db7
commit 2a6b81e4dd
7 changed files with 41 additions and 4 deletions

View File

@ -199,6 +199,17 @@ cah.ajax.Builder.prototype.withWall = function(wall) {
return this;
};
/**
* @param {boolean}
* emote Whether or not this is an emote
* @returns {cah.ajax.Builder} This object.
*/
cah.ajax.Builder.prototype.withEmote = function(emote) {
this.assertNotExecuted_();
this.data[cah.$.AjaxRequest.EMOTE] = emote;
return this;
};
/**
* Assert that the request from this builder has not already run. Throws an exception if it has.
*

View File

@ -146,13 +146,22 @@ function chatsubmit_click(game_id, parent_element) {
// TODO support an /ignore command
case '':
if (game_id !== null) {
ajax = cah.Ajax.build(cah.$.AjaxOperation.GAME_CHAT).withGameId(game_id);
ajax = cah.Ajax.build(cah.$.AjaxOperation.GAME_CHAT).withGameId(game_id).withEmote(false);
} else {
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT);
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT).withEmote(false);
}
ajax = ajax.withMessage(text);
cah.log.status_with_game(game_id, "<" + cah.nickname + "> " + text);
break;
case 'me':
if (game_id !== null) {
ajax = cah.Ajax.build(cah.$.AjaxOperation.GAME_CHAT).withGameId(game_id).withEmote(true);
} else {
ajax = cah.Ajax.build(cah.$.AjaxOperation.CHAT).withEmote(true);
}
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;

View File

@ -35,6 +35,7 @@ cah.$.AjaxRequest.MESSAGE = "m";
cah.$.AjaxRequest.CARD_ID = "cid";
cah.$.AjaxRequest.USE_TIMER = "ut";
cah.$.AjaxRequest.GAME_ID = "gid";
cah.$.AjaxRequest.EMOTE = "me";
cah.$.AjaxRequest.CARD_SETS = "css";
cah.$.AjaxRequest.SERIAL = "s";
cah.$.AjaxRequest.PLAYER_LIMIT = "pL";
@ -269,6 +270,7 @@ cah.$.LongPollResponse.WALL = "wall";
cah.$.LongPollResponse.WHITE_CARDS = "wc";
cah.$.LongPollResponse.REASON = "qr";
cah.$.LongPollResponse.GAME_ID = "gid";
cah.$.LongPollResponse.EMOTE = "me";
cah.$.LongPollResponse.HAND = "h";
cah.$.LongPollResponse.INTERMISSION = "i";
cah.$.LongPollResponse.PLAYER_INFO = "pi";

View File

@ -107,8 +107,12 @@ cah.longpoll.EventHandlers[cah.$.LongPollEvent.CHAT] = function(data) {
// 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);
var message = data[cah.$.LongPollResponse.MESSAGE];
if (data[cah.$.LongPollResponse.EMOTE]) {
cah.log.status_with_game(game, "* " + from + " " + message, clazz);
} else {
cah.log.status_with_game(game, "<" + from + "> " + message, clazz);
}
}
}
};

View File

@ -202,6 +202,7 @@ public class Constants {
public enum AjaxRequest {
CARD_ID("cid"),
CARD_SETS("css"),
EMOTE("me"),
GAME_ID("gid"),
MESSAGE("m"),
NICKNAME("n"),
@ -410,6 +411,8 @@ public class Constants {
@DuplicationAllowed
BLACK_CARD(AjaxResponse.BLACK_CARD),
@DuplicationAllowed
EMOTE(AjaxRequest.EMOTE),
@DuplicationAllowed
ERROR(AjaxResponse.ERROR),
@DuplicationAllowed
ERROR_CODE(AjaxResponse.ERROR_CODE),

View File

@ -69,6 +69,8 @@ public class ChatHandler extends Handler {
assert (user != null);
final boolean wall = request.getParameter(AjaxRequest.WALL) != null
&& Boolean.valueOf(request.getParameter(AjaxRequest.WALL));
final boolean emote = request.getParameter(AjaxRequest.EMOTE) != null
&& Boolean.valueOf(request.getParameter(AjaxRequest.EMOTE));
if (request.getParameter(AjaxRequest.MESSAGE) == null) {
return error(ErrorCode.NO_MSG_SPECIFIED);
@ -103,6 +105,9 @@ public class ChatHandler extends Handler {
if (wall) {
broadcastData.put(LongPollResponse.WALL, true);
}
if (emote) {
broadcastData.put(LongPollResponse.EMOTE, true);
}
users.broadcastToAll(MessageType.CHAT, broadcastData);
}
}

View File

@ -62,6 +62,8 @@ public class GameChatHandler extends GameWithPlayerHandler {
public Map<ReturnableData, Object> handleWithUserInGame(final RequestWrapper request,
final HttpSession session, final User user, final Game game) {
final Map<ReturnableData, Object> data = new HashMap<ReturnableData, Object>();
final boolean emote = request.getParameter(AjaxRequest.EMOTE) != null
&& Boolean.valueOf(request.getParameter(AjaxRequest.EMOTE));
if (request.getParameter(AjaxRequest.MESSAGE) == null) {
return error(ErrorCode.NO_MSG_SPECIFIED);
@ -90,6 +92,7 @@ public class GameChatHandler extends GameWithPlayerHandler {
broadcastData.put(LongPollResponse.MESSAGE, message);
broadcastData.put(LongPollResponse.FROM_ADMIN, user.isAdmin());
broadcastData.put(LongPollResponse.GAME_ID, game.getId());
broadcastData.put(LongPollResponse.EMOTE, emote);
game.broadcastToPlayers(MessageType.CHAT, broadcastData);
}
}