Widened.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4662 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -57,25 +57,21 @@ import com.threerings.crowd.chat.data.UserMessage;
|
|||||||
import com.threerings.crowd.chat.data.UserSystemMessage;
|
import com.threerings.crowd.chat.data.UserSystemMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The chat director is the client side coordinator of all chat related
|
* The chat director is the client side coordinator of all chat related services. It handles both
|
||||||
* services. It handles both place constrained chat as well as direct
|
* place constrained chat as well as direct messaging.
|
||||||
* messaging.
|
|
||||||
*/
|
*/
|
||||||
public class ChatDirector extends BasicDirector
|
public class ChatDirector extends BasicDirector
|
||||||
implements LocationObserver, MessageListener
|
implements LocationObserver, MessageListener
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a chat director and initializes it with the supplied
|
* Creates a chat director and initializes it with the supplied context. The chat director will
|
||||||
* context. The chat director will register itself as a location
|
* register itself as a location observer so that it can automatically process place
|
||||||
* observer so that it can automatically process place constrained
|
* constrained chat.
|
||||||
* chat.
|
|
||||||
*
|
*
|
||||||
* @param msgmgr the message manager via which we do our translations.
|
* @param msgmgr the message manager via which we do our translations.
|
||||||
* @param bundle the message bundle from which we obtain our
|
* @param bundle the message bundle from which we obtain our chat-related translation strings.
|
||||||
* chat-related translation strings.
|
|
||||||
*/
|
*/
|
||||||
public function ChatDirector (
|
public function ChatDirector (ctx :CrowdContext, msgmgr :MessageManager, bundle :String)
|
||||||
ctx :CrowdContext, msgmgr :MessageManager, bundle :String)
|
|
||||||
{
|
{
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
|
||||||
@@ -88,8 +84,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
_cctx.getLocationDirector().addLocationObserver(this);
|
_cctx.getLocationDirector().addLocationObserver(this);
|
||||||
|
|
||||||
if (_bundle == null || _msgmgr == null) {
|
if (_bundle == null || _msgmgr == null) {
|
||||||
Log.getLog(this).warning(
|
Log.getLog(this).warning("Null bundle or message manager given to ChatDirector");
|
||||||
"Null bundle or message manager given to ChatDirector");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var msg :MessageBundle = _msgmgr.getBundle(_bundle);
|
var msg :MessageBundle = _msgmgr.getBundle(_bundle);
|
||||||
@@ -104,9 +99,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the supplied chat display to the front of the chat display list. It
|
* Adds the supplied chat display to the front of the chat display list. It will subsequently
|
||||||
* will subsequently be notified of incoming chat messages as well as tell
|
* be notified of incoming chat messages as well as tell responses.
|
||||||
* responses.
|
|
||||||
*/
|
*/
|
||||||
public function pushChatDisplay (display :ChatDisplay) :void
|
public function pushChatDisplay (display :ChatDisplay) :void
|
||||||
{
|
{
|
||||||
@@ -114,9 +108,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the supplied chat display to the chat display list. It will
|
* Adds the supplied chat display to the chat display list. It will subsequently be notified of
|
||||||
* subsequently be notified of incoming chat messages as well as tell
|
* incoming chat messages as well as tell responses.
|
||||||
* responses.
|
|
||||||
*/
|
*/
|
||||||
public function addChatDisplay (display :ChatDisplay) :void
|
public function addChatDisplay (display :ChatDisplay) :void
|
||||||
{
|
{
|
||||||
@@ -124,8 +117,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified chat display from the chat display list. The
|
* Removes the specified chat display from the chat display list. The display will no longer
|
||||||
* display will no longer receive chat related notifications.
|
* receive chat related notifications.
|
||||||
*/
|
*/
|
||||||
public function removeChatDisplay (display :ChatDisplay) :void
|
public function removeChatDisplay (display :ChatDisplay) :void
|
||||||
{
|
{
|
||||||
@@ -133,9 +126,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified chat filter to the list of filters. All
|
* Adds the specified chat filter to the list of filters. All chat requests and receipts will
|
||||||
* chat requests and receipts will be filtered with all filters
|
* be filtered with all filters before they being sent or dispatched locally.
|
||||||
* before they being sent or dispatched locally.
|
|
||||||
*/
|
*/
|
||||||
public function addChatFilter (filter :ChatFilter) :void
|
public function addChatFilter (filter :ChatFilter) :void
|
||||||
{
|
{
|
||||||
@@ -151,8 +143,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an observer that watches the chatters list, and updates it
|
* Adds an observer that watches the chatters list, and updates it immediately.
|
||||||
* immediately.
|
|
||||||
*/
|
*/
|
||||||
public function addChatterObserver (co :ChatterObserver) :void
|
public function addChatterObserver (co :ChatterObserver) :void
|
||||||
{
|
{
|
||||||
@@ -169,8 +160,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the validator that decides if a username is valid to be
|
* Sets the validator that decides if a username is valid to be added to the chatter list, or
|
||||||
* added to the chatter list, or null if no such filtering is desired.
|
* null if no such filtering is desired.
|
||||||
*/
|
*/
|
||||||
public function setChatterValidator (validator :ChatterValidator) :void
|
public function setChatterValidator (validator :ChatterValidator) :void
|
||||||
{
|
{
|
||||||
@@ -178,8 +169,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of the recent users with whom we've chatted. The most recent
|
* Get a list of the recent users with whom we've chatted. The most recent users will be listed
|
||||||
* users will be listed first.
|
* first.
|
||||||
*/
|
*/
|
||||||
public function getChatters () :Array
|
public function getChatters () :Array
|
||||||
{
|
{
|
||||||
@@ -187,16 +178,14 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a chatter to our list of recent chatters. This is normally done
|
* Adds a chatter to our list of recent chatters. This is normally done automatically by the
|
||||||
* automatically by the ChatDirector, but may be called to also to
|
* ChatDirector, but may be called to also to forcibly add a chatter. The ChatterValidator will
|
||||||
* forcibly add a chatter. The ChatterValidator will have to approve
|
* have to approve of the chatter.
|
||||||
* of the chatter.
|
|
||||||
*/
|
*/
|
||||||
public function addChatter (name :Name) :void
|
public function addChatter (name :Name) :void
|
||||||
{
|
{
|
||||||
// check to see if the chatter validator approves..
|
// check to see if the chatter validator approves..
|
||||||
if ((_chatterValidator != null) &&
|
if ((_chatterValidator != null) && (!_chatterValidator.isChatterValid(name))) {
|
||||||
(!_chatterValidator.isChatterValid(name))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,16 +205,15 @@ public class ChatDirector extends BasicDirector
|
|||||||
/**
|
/**
|
||||||
* Registers a chat command handler.
|
* Registers a chat command handler.
|
||||||
*
|
*
|
||||||
* @param msg the message bundle via which the slash command will be
|
* @param msg the message bundle via which the slash command will be translated (as
|
||||||
* translated (as <code>c.</code><i>command</i>). If no translation
|
* <code>c.</code><i>command</i>). If no translation exists the command will be
|
||||||
* exists the command will be <code>/</code><i>command</i>.
|
* <code>/</code><i>command</i>.
|
||||||
* @param command the name of the command that will be used to invoke
|
* @param command the name of the command that will be used to invoke this handler
|
||||||
* this handler (e.g. <code>tell</code> if the command will be invoked
|
* (e.g. <code>tell</code> if the command will be invoked as <code>/tell</code>).
|
||||||
* as <code>/tell</code>).
|
|
||||||
* @param handler the chat command handler itself.
|
* @param handler the chat command handler itself.
|
||||||
*/
|
*/
|
||||||
public function registerCommandHandler (
|
public function registerCommandHandler (
|
||||||
msg :MessageBundle, command :String, handler :CommandHandler) :void
|
msg :MessageBundle, command :String, handler :CommandHandler) :void
|
||||||
{
|
{
|
||||||
var key :String = "c." + command;
|
var key :String = "c." + command;
|
||||||
if (msg.exists(key)) {
|
if (msg.exists(key)) {
|
||||||
@@ -248,8 +236,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the chat history entry at the specified index,
|
* Get the chat history entry at the specified index, with 0 being the oldest.
|
||||||
* with 0 being the oldest.
|
|
||||||
*/
|
*/
|
||||||
public function getCommandHistory (index :int) :String
|
public function getCommandHistory (index :int) :String
|
||||||
{
|
{
|
||||||
@@ -277,11 +264,10 @@ public class ChatDirector extends BasicDirector
|
|||||||
/**
|
/**
|
||||||
* Display a system INFO message as if it had come from the server.
|
* Display a system INFO message as if it had come from the server.
|
||||||
*
|
*
|
||||||
* Info messages are sent when something happens that was neither
|
* Info messages are sent when something happens that was neither directly triggered by the
|
||||||
* directly triggered by the user, nor requires direct action.
|
* user, nor requires direct action.
|
||||||
*/
|
*/
|
||||||
public function displayInfo (
|
public function displayInfo (bundle :String, message :String, localtype :String = null) :void
|
||||||
bundle :String, message :String, localtype :String = null) :void
|
|
||||||
{
|
{
|
||||||
if (localtype == null) {
|
if (localtype == null) {
|
||||||
localtype = ChatCodes.PLACE_CHAT_TYPE;
|
localtype = ChatCodes.PLACE_CHAT_TYPE;
|
||||||
@@ -290,29 +276,27 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a system FEEDBACK message as if it had come from the server.
|
* Display a system FEEDBACK message as if it had come from the server. The localtype of the
|
||||||
* The localtype of the message will be PLACE_CHAT_TYPE.
|
* message will be PLACE_CHAT_TYPE.
|
||||||
*
|
*
|
||||||
* Feedback messages are sent in direct response to a user action,
|
* Feedback messages are sent in direct response to a user action, usually to indicate success
|
||||||
* usually to indicate success or failure of the user's action.
|
* or failure of the user's action.
|
||||||
*/
|
*/
|
||||||
public function displayFeedback (bundle :String, message :String) :void
|
public function displayFeedback (bundle :String, message :String) :void
|
||||||
{
|
{
|
||||||
displaySystem(
|
displaySystem(bundle, message, SystemMessage.FEEDBACK, ChatCodes.PLACE_CHAT_TYPE);
|
||||||
bundle, message, SystemMessage.FEEDBACK, ChatCodes.PLACE_CHAT_TYPE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a system ATTENTION message as if it had come from the server.
|
* Display a system ATTENTION message as if it had come from the server. The localtype of the
|
||||||
* The localtype of the message will be PLACE_CHAT_TYPE.
|
* message will be PLACE_CHAT_TYPE.
|
||||||
*
|
*
|
||||||
* Attention messages are sent when something requires user action
|
* Attention messages are sent when something requires user action that did not result from
|
||||||
* that did not result from direct action by the user.
|
* direct action by the user.
|
||||||
*/
|
*/
|
||||||
public function displayAttention (bundle :String, message :String) :void
|
public function displayAttention (bundle :String, message :String) :void
|
||||||
{
|
{
|
||||||
displaySystem(
|
displaySystem(bundle, message, SystemMessage.ATTENTION, ChatCodes.PLACE_CHAT_TYPE);
|
||||||
bundle, message, SystemMessage.ATTENTION, ChatCodes.PLACE_CHAT_TYPE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -329,21 +313,18 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses and delivers the supplied chat message. Slash command
|
* Parses and delivers the supplied chat message. Slash command processing and mogrification
|
||||||
* processing and mogrification are performed and the message is added
|
* are performed and the message is added to the chat history if appropriate.
|
||||||
* to the chat history if appropriate.
|
|
||||||
*
|
*
|
||||||
* @param speakSvc the SpeakService representing the target dobj of
|
* @param speakSvc the SpeakService representing the target dobj of the speak or null if we
|
||||||
* the speak or null if we should speak in the "default" way.
|
* should speak in the "default" way.
|
||||||
* @param text the text to be parsed and sent.
|
* @param text the text to be parsed and sent.
|
||||||
* @param record if text is a command, should it be added to the history?
|
* @param record if text is a command, should it be added to the history?
|
||||||
*
|
*
|
||||||
* @return <code>ChatCodes#SUCCESS</code> if the message was parsed
|
* @return <code>ChatCodes#SUCCESS</code> if the message was parsed and sent correctly, a
|
||||||
* and sent correctly, a translatable error string if there was some
|
* translatable error string if there was some problem.
|
||||||
* problem.
|
|
||||||
*/
|
*/
|
||||||
public function requestChat (
|
public function requestChat (speakSvc :SpeakService, text :String, record :Boolean) :String
|
||||||
speakSvc :SpeakService, text :String, record :Boolean) :String
|
|
||||||
{
|
{
|
||||||
if (text.indexOf("/") == 0) {
|
if (text.indexOf("/") == 0) {
|
||||||
// split the text up into a command and arguments
|
// split the text up into a command and arguments
|
||||||
@@ -359,15 +340,12 @@ public class ChatDirector extends BasicDirector
|
|||||||
var possibleCommands :Map = getCommandHandlers(command);
|
var possibleCommands :Map = getCommandHandlers(command);
|
||||||
switch (possibleCommands.size()) {
|
switch (possibleCommands.size()) {
|
||||||
case 0:
|
case 0:
|
||||||
return MessageBundle.tcompose(
|
return MessageBundle.tcompose("m.unknown_command", text.split(/\s/)[0]);
|
||||||
"m.unknown_command", text.split(/\s/)[0]);
|
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
var cmdName :String = possibleCommands.keys()[0];
|
var cmdName :String = possibleCommands.keys()[0];
|
||||||
var cmd :CommandHandler =
|
var cmd :CommandHandler = (possibleCommands.get(cmdName) as CommandHandler);
|
||||||
(possibleCommands.get(cmdName) as CommandHandler);
|
var result :String = cmd.handleCommand(_cctx, speakSvc, cmdName, args, hist);
|
||||||
var result :String =
|
|
||||||
cmd.handleCommand(_cctx, speakSvc, cmdName, args, hist);
|
|
||||||
if (result != ChatCodes.SUCCESS) {
|
if (result != ChatCodes.SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -376,8 +354,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
// get the final history-ready command string
|
// get the final history-ready command string
|
||||||
hist[0] = "/" + ((hist[0] == null) ? command : hist[0]);
|
hist[0] = "/" + ((hist[0] == null) ? command : hist[0]);
|
||||||
|
|
||||||
// remove from history if it was present and
|
// remove from history if it was present and add it to the end
|
||||||
// add it to the end
|
|
||||||
addToHistory(hist[0]);
|
addToHistory(hist[0]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -385,37 +362,32 @@ public class ChatDirector extends BasicDirector
|
|||||||
default:
|
default:
|
||||||
var cmds :Array = possibleCommands.keys();
|
var cmds :Array = possibleCommands.keys();
|
||||||
var alternativeCommands :String = "/" + cmds.join(", /");
|
var alternativeCommands :String = "/" + cmds.join(", /");
|
||||||
return MessageBundle.tcompose(
|
return MessageBundle.tcompose("m.unspecific_command", alternativeCommands);
|
||||||
"m.unspecific_command", alternativeCommands);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not a command then just speak
|
// if not a command then just speak
|
||||||
var message :String = StringUtil.trim(text);
|
var message :String = StringUtil.trim(text);
|
||||||
if (StringUtil.isBlank(message)) {
|
if (StringUtil.isBlank(message)) {
|
||||||
// report silent failure for now
|
return ChatCodes.SUCCESS; // report silent failure for now
|
||||||
return ChatCodes.SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return deliverChat(speakSvc, message, ChatCodes.DEFAULT_MODE);
|
return deliverChat(speakSvc, message, ChatCodes.DEFAULT_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that a speak message with the specified mode be generated
|
* Requests that a speak message with the specified mode be generated and delivered via the
|
||||||
* and delivered via the supplied speak service instance (which will
|
* supplied speak service instance (which will be associated with a particular "speak object").
|
||||||
* be associated with a particular "speak object"). The message will
|
* The message will first be validated by all registered {@link ChatFilter}s (and possibly
|
||||||
* first be validated by all registered {@link ChatFilter}s (and
|
* vetoed) before being dispatched.
|
||||||
* possibly vetoed) before being dispatched.
|
|
||||||
*
|
*
|
||||||
* @param speakService the speak service to use when generating the
|
* @param speakService the speak service to use when generating the speak request or null if we
|
||||||
* speak request or null if we should speak in the current "place".
|
* should speak in the current "place".
|
||||||
* @param message the contents of the speak message.
|
* @param message the contents of the speak message.
|
||||||
* @param mode a speech mode that will be interpreted by the {@link
|
* @param mode a speech mode that will be interpreted by the {@link ChatDisplay}
|
||||||
* ChatDisplay} implementations that eventually display this speak
|
* implementations that eventually display this speak message.
|
||||||
* message.
|
|
||||||
*/
|
*/
|
||||||
public function requestSpeak (
|
public function requestSpeak (speakService :SpeakService, message :String, mode :int) :void
|
||||||
speakService :SpeakService, message :String, mode :int) :void
|
|
||||||
{
|
{
|
||||||
if (speakService == null) {
|
if (speakService == null) {
|
||||||
if (_place == null) {
|
if (_place == null) {
|
||||||
@@ -443,33 +415,25 @@ public class ChatDirector extends BasicDirector
|
|||||||
{
|
{
|
||||||
message = filter(message, null, true);
|
message = filter(message, null, true);
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
displayFeedback(_bundle,
|
displayFeedback(_bundle, MessageBundle.compose("m.broadcast_failed", "m.filtered"));
|
||||||
MessageBundle.compose("m.broadcast_failed", "m.filtered"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var failure :Function = function (reason :String) :void
|
var failure :Function = function (reason :String) :void {
|
||||||
{
|
|
||||||
reason = MessageBundle.compose("m.broadcast_failed", reason);
|
reason = MessageBundle.compose("m.broadcast_failed", reason);
|
||||||
displayFeedback(_bundle, reason);
|
displayFeedback(_bundle, reason);
|
||||||
};
|
};
|
||||||
|
_cservice.broadcast(_cctx.getClient(), message, new InvocationAdapter(failure));
|
||||||
_cservice.broadcast(_cctx.getClient(), message,
|
|
||||||
new InvocationAdapter(failure));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that a tell message be delivered to the specified target
|
* Requests that a tell message be delivered to the specified target user.
|
||||||
* user.
|
|
||||||
*
|
*
|
||||||
* @param target the username of the user to which the tell message
|
* @param target the username of the user to which the tell message should be delivered.
|
||||||
* should be delivered.
|
|
||||||
* @param msg the contents of the tell message.
|
* @param msg the contents of the tell message.
|
||||||
* @param rl an optional result listener if you'd like to be notified
|
* @param rl an optional result listener if you'd like to be notified of success or failure.
|
||||||
* of success or failure.
|
|
||||||
*/
|
*/
|
||||||
public function requestTell (
|
public function requestTell (target :Name, msg :String, rl :ResultListener) :void
|
||||||
target :Name, msg :String, rl :ResultListener) :void
|
|
||||||
{
|
{
|
||||||
// make sure they can say what they want to say
|
// make sure they can say what they want to say
|
||||||
var message :String = filter(msg, target, true);
|
var message :String = filter(msg, target, true);
|
||||||
@@ -480,8 +444,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var failure :Function = function (reason :String) :void
|
var failure :Function = function (reason :String) :void {
|
||||||
{
|
|
||||||
var msg :String = MessageBundle.compose(
|
var msg :String = MessageBundle.compose(
|
||||||
"m.tell_failed", MessageBundle.taint(target), reason);
|
"m.tell_failed", MessageBundle.taint(target), reason);
|
||||||
displayFeedback(_bundle, msg);
|
displayFeedback(_bundle, msg);
|
||||||
@@ -489,9 +452,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
rl.requestFailed(null);
|
rl.requestFailed(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var success :Function = function (
|
var success :Function = function (idleTime :Long, awayMessage :String) :void {
|
||||||
idleTime :Long, awayMessage :String) :void
|
|
||||||
{
|
|
||||||
dispatchMessage(new TellFeedbackMessage(target, message));
|
dispatchMessage(new TellFeedbackMessage(target, message));
|
||||||
addChatter(target);
|
addChatter(target);
|
||||||
if (rl != null) {
|
if (rl != null) {
|
||||||
@@ -519,23 +480,19 @@ public class ChatDirector extends BasicDirector
|
|||||||
// displayFeedback(_bundle, msg);
|
// displayFeedback(_bundle, msg);
|
||||||
// }
|
// }
|
||||||
};
|
};
|
||||||
|
_cservice.tell(_cctx.getClient(), target, message, new TellAdapter(failure, success));
|
||||||
_cservice.tell(_cctx.getClient(), target, message,
|
|
||||||
new TellAdapter(failure, success));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures a message that will be automatically reported to anyone
|
* Configures a message that will be automatically reported to anyone that sends a tell message
|
||||||
* that sends a tell message to this client to indicate that we are
|
* to this client to indicate that we are busy or away from the keyboard.
|
||||||
* busy or away from the keyboard.
|
|
||||||
*/
|
*/
|
||||||
public function setAwayMessage (message :String) :void
|
public function setAwayMessage (message :String) :void
|
||||||
{
|
{
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
message = filter(message, null, true);
|
message = filter(message, null, true);
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
// they filtered away their own away message..
|
// they filtered away their own away message.. change it to something
|
||||||
// change it to something
|
|
||||||
message = "...";
|
message = "...";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,13 +501,12 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an additional object via which chat messages may arrive. The
|
* Adds an additional object via which chat messages may arrive. The chat director assumes the
|
||||||
* chat director assumes the caller will be managing the subscription
|
* caller will be managing the subscription to this object and will remain subscribed to it for
|
||||||
* to this object and will remain subscribed to it for as long as it
|
* as long as it remains in effect as an auxiliary chat source.
|
||||||
* remains in effect as an auxiliary chat source.
|
|
||||||
*
|
*
|
||||||
* @param localtype a type to be associated with all chat messages
|
* @param localtype a type to be associated with all chat messages that arrive on the specified
|
||||||
* that arrive on the specified DObject.
|
* DObject.
|
||||||
*/
|
*/
|
||||||
public function addAuxiliarySource (source :DObject, localtype :String) :void
|
public function addAuxiliarySource (source :DObject, localtype :String) :void
|
||||||
{
|
{
|
||||||
@@ -570,8 +526,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
/**
|
/**
|
||||||
* Run a message through all the currently registered filters.
|
* Run a message through all the currently registered filters.
|
||||||
*/
|
*/
|
||||||
public function filter (
|
public function filter (msg :String, otherUser :Name, outgoing :Boolean) :String
|
||||||
msg :String, otherUser :Name, outgoing :Boolean) :String
|
|
||||||
{
|
{
|
||||||
// TODO: needs testing
|
// TODO: needs testing
|
||||||
_filters.apply(function (observer :ChatFilter) :void {
|
_filters.apply(function (observer :ChatFilter) :void {
|
||||||
@@ -645,14 +600,12 @@ public class ChatDirector extends BasicDirector
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChatCodes.USER_CHAT_TYPE == localtype &&
|
if (ChatCodes.USER_CHAT_TYPE == localtype && mode == ChatCodes.DEFAULT_MODE) {
|
||||||
mode == ChatCodes.DEFAULT_MODE) {
|
|
||||||
// if it was a tell, add the speaker as a chatter
|
// if it was a tell, add the speaker as a chatter
|
||||||
addChatter(speaker);
|
addChatter(speaker);
|
||||||
|
|
||||||
// note whether or not we have an auto-response
|
// note whether or not we have an auto-response
|
||||||
var self :BodyObject =
|
var self :BodyObject = (_cctx.getClient().getClientObject() as BodyObject);
|
||||||
(_cctx.getClient().getClientObject() as BodyObject);
|
|
||||||
if (!StringUtil.isBlank(self.awayMessage)) {
|
if (!StringUtil.isBlank(self.awayMessage)) {
|
||||||
autoResponse = self.awayMessage;
|
autoResponse = self.awayMessage;
|
||||||
}
|
}
|
||||||
@@ -680,8 +633,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
super.clientDidLogon(event);
|
super.clientDidLogon(event);
|
||||||
|
|
||||||
// listen on the client object for tells
|
// listen on the client object for tells
|
||||||
addAuxiliarySource(_clobj = event.getClient().getClientObject(),
|
addAuxiliarySource(_clobj = event.getClient().getClientObject(), ChatCodes.USER_CHAT_TYPE);
|
||||||
ChatCodes.USER_CHAT_TYPE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -691,8 +643,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
|
|
||||||
// change what we're listening to for tells
|
// change what we're listening to for tells
|
||||||
removeAuxiliarySource(_clobj);
|
removeAuxiliarySource(_clobj);
|
||||||
addAuxiliarySource(_clobj = event.getClient().getClientObject(),
|
addAuxiliarySource(_clobj = event.getClient().getClientObject(), ChatCodes.USER_CHAT_TYPE);
|
||||||
ChatCodes.USER_CHAT_TYPE);
|
|
||||||
|
|
||||||
clearDisplays();
|
clearDisplays();
|
||||||
}
|
}
|
||||||
@@ -724,43 +675,38 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to determine whether we are permitted to post the supplied
|
* Called to determine whether we are permitted to post the supplied chat message. Derived
|
||||||
* chat message. Derived classes may wish to throttle chat or restrict
|
* classes may wish to throttle chat or restrict certain types in certain circumstances for
|
||||||
* certain types in certain circumstances for whatever reason.
|
* whatever reason.
|
||||||
*
|
*
|
||||||
* @return null if the chat is permitted, SUCCESS if the chat is permitted
|
* @return null if the chat is permitted, SUCCESS if the chat is permitted and has already been
|
||||||
* and has already been dealt with, or a translatable string
|
* dealt with, or a translatable string indicating the reason for rejection if not.
|
||||||
* indicating the reason for rejection if not.
|
|
||||||
*/
|
*/
|
||||||
protected function checkCanChat (
|
protected function checkCanChat (speakSvc :SpeakService , message :String, mode :int) :String
|
||||||
speakSvc :SpeakService , message :String, mode :int) :String
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delivers a plain chat message (not a slash command) on the
|
* Delivers a plain chat message (not a slash command) on the specified speak service in the
|
||||||
* specified speak service in the specified mode. The message will be
|
* specified mode. The message will be mogrified and filtered prior to delivery.
|
||||||
* mogrified and filtered prior to delivery.
|
|
||||||
*
|
*
|
||||||
* @return {@link ChatCodes#SUCCESS} if the message was delivered or a
|
* @return {@link ChatCodes#SUCCESS} if the message was delivered or a string indicating why it
|
||||||
* string indicating why it failed.
|
* failed.
|
||||||
*/
|
*/
|
||||||
internal function deliverChat (
|
internal function deliverChat (speakSvc :SpeakService, message :String, mode :int) :String
|
||||||
speakSvc :SpeakService, message :String, mode :int) :String
|
|
||||||
{
|
{
|
||||||
// run the message through our mogrification process
|
// run the message through our mogrification process
|
||||||
message = mogrifyChatImpl(message, true, mode != ChatCodes.EMOTE_MODE);
|
message = mogrifyChatImpl(message, true, mode != ChatCodes.EMOTE_MODE);
|
||||||
|
|
||||||
// mogrification may result in something being turned into a slash
|
// mogrification may result in something being turned into a slash command, in which case
|
||||||
// command, in which case we have to run everything through again
|
// we have to run everything through again from the start
|
||||||
// from the start
|
|
||||||
if (message.indexOf("/") == 0) {
|
if (message.indexOf("/") == 0) {
|
||||||
return requestChat(speakSvc, message, false);
|
return requestChat(speakSvc, message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure this client is not restricted from performing this
|
// make sure this client is not restricted from performing this chat message for some
|
||||||
// chat message for some reason or other
|
// reason or other
|
||||||
var errmsg :String = checkCanChat(speakSvc, message, mode);
|
var errmsg :String = checkCanChat(speakSvc, message, mode);
|
||||||
if (errmsg != null) {
|
if (errmsg != null) {
|
||||||
return errmsg;
|
return errmsg;
|
||||||
@@ -790,13 +736,12 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mogrify common literary crutches into more appealing chat or
|
* Mogrify common literary crutches into more appealing chat or commands.
|
||||||
* commands.
|
|
||||||
*
|
*
|
||||||
* @param transformsAllowed if true, the chat may transformed into a
|
* @param transformsAllowed if true, the chat may transformed into a different mode. (lol ->
|
||||||
* different mode. (lol -> /emote laughs)
|
* /emote laughs)
|
||||||
* @param capFirst if true, the first letter of the text is
|
* @param capFirst if true, the first letter of the text is capitalized. This is not desired if
|
||||||
* capitalized. This is not desired if the chat is already an emote.
|
* the chat is already an emote.
|
||||||
*/
|
*/
|
||||||
protected function mogrifyChatImpl (
|
protected function mogrifyChatImpl (
|
||||||
text :String, transformsAllowed :Boolean, capFirst :Boolean) :String
|
text :String, transformsAllowed :Boolean, capFirst :Boolean) :String
|
||||||
@@ -811,9 +756,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
var caps :int = 0;
|
var caps :int = 0;
|
||||||
for (var ii :int = 0; ii < tlen; ii++) {
|
for (var ii :int = 0; ii < tlen; ii++) {
|
||||||
var ch :String = text.charAt(ii);
|
var ch :String = text.charAt(ii);
|
||||||
// do a fucked-up test to see if it's uppercase
|
// do a fucked-up test to see if it's uppercase make sure the uppercase version is
|
||||||
// make sure the uppercase version is the same as the orig
|
// the same as the orig and the lowercase version is different
|
||||||
// and the lowercase version is different
|
|
||||||
var chU :String = ch.toUpperCase();
|
var chU :String = ch.toUpperCase();
|
||||||
if (ch == chU && chU != ch.toLowerCase()) {
|
if (ch == chU && chU != ch.toLowerCase()) {
|
||||||
caps++;
|
caps++;
|
||||||
@@ -831,7 +775,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
|
|
||||||
/** Helper function for {@link #mogrifyChat}. */
|
/** Helper function for {@link #mogrifyChat}. */
|
||||||
protected function mogrifyChatText (
|
protected function mogrifyChatText (
|
||||||
text :String, transformsAllowed :Boolean, capFirst :Boolean) :String
|
text :String, transformsAllowed :Boolean, capFirst :Boolean) :String
|
||||||
{
|
{
|
||||||
// do the generic mogrifications and translations
|
// do the generic mogrifications and translations
|
||||||
text = translatedReplacements("x.mogrifies", text);
|
text = translatedReplacements("x.mogrifies", text);
|
||||||
@@ -863,11 +807,10 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do all the replacements (mogrifications) specified in the
|
* Do all the replacements (mogrifications) specified in the translation string specified by
|
||||||
* translation string specified by the key.
|
* the key.
|
||||||
*/
|
*/
|
||||||
protected function translatedReplacements (
|
protected function translatedReplacements (key :String, text :String) :String
|
||||||
key :String, text :String) :String
|
|
||||||
{
|
{
|
||||||
var bundle :MessageBundle = _msgmgr.getBundle(_bundle);
|
var bundle :MessageBundle = _msgmgr.getBundle(_bundle);
|
||||||
if (!bundle.exists(key)) {
|
if (!bundle.exists(key)) {
|
||||||
@@ -893,15 +836,13 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a hashmap containing all command handlers that match the
|
* Returns a hashmap containing all command handlers that match the specified command (i.e. the
|
||||||
* specified command (i.e. the specified command is a prefix of their
|
* specified command is a prefix of their registered command string).
|
||||||
* registered command string).
|
|
||||||
*/
|
*/
|
||||||
internal function getCommandHandlers (command :String) :Map
|
internal function getCommandHandlers (command :String) :Map
|
||||||
{
|
{
|
||||||
var matches :Map = new HashMap();
|
var matches :Map = new HashMap();
|
||||||
var user :BodyObject =
|
var user :BodyObject = (_cctx.getClient().getClientObject() as BodyObject);
|
||||||
(_cctx.getClient().getClientObject() as BodyObject);
|
|
||||||
var keys :Array = _handlers.keys();
|
var keys :Array = _handlers.keys();
|
||||||
for (var ii :int = 0; ii < keys.length; ii++) {
|
for (var ii :int = 0; ii < keys.length; ii++) {
|
||||||
var cmd :String = (keys[ii] as String);
|
var cmd :String = (keys[ii] as String);
|
||||||
@@ -922,8 +863,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies all registered {@link ChatterObserver}s that the list of
|
* Notifies all registered {@link ChatterObserver}s that the list of chatters has changed.
|
||||||
* chatters has changed.
|
|
||||||
*/
|
*/
|
||||||
protected function notifyChatterObservers () :void
|
protected function notifyChatterObservers () :void
|
||||||
{
|
{
|
||||||
@@ -931,8 +871,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function to be called by our _chatterObservers list to apply
|
* A function to be called by our _chatterObservers list to apply updates to each observer.
|
||||||
* updates to each observer.
|
|
||||||
*/
|
*/
|
||||||
protected function chatterObserverNotify (obs :ChatterObserver) :void
|
protected function chatterObserverNotify (obs :ChatterObserver) :void
|
||||||
{
|
{
|
||||||
@@ -947,9 +886,8 @@ public class ChatDirector extends BasicDirector
|
|||||||
if (bundle != null && _msgmgr != null) {
|
if (bundle != null && _msgmgr != null) {
|
||||||
var msgb :MessageBundle = _msgmgr.getBundle(bundle);
|
var msgb :MessageBundle = _msgmgr.getBundle(bundle);
|
||||||
if (msgb == null) {
|
if (msgb == null) {
|
||||||
Log.getLog(this).warning(
|
Log.getLog(this).warning("No message bundle available to translate message " +
|
||||||
"No message bundle available to translate message " +
|
"[bundle=" + bundle + ", message=" + message + "].");
|
||||||
"[bundle=" + bundle + ", message=" + message + "].");
|
|
||||||
} else {
|
} else {
|
||||||
message = msgb.xlate(message);
|
message = msgb.xlate(message);
|
||||||
}
|
}
|
||||||
@@ -961,11 +899,9 @@ public class ChatDirector extends BasicDirector
|
|||||||
* Display the specified system message as if it had come from the server.
|
* Display the specified system message as if it had come from the server.
|
||||||
*/
|
*/
|
||||||
protected function displaySystem (
|
protected function displaySystem (
|
||||||
bundle :String, message :String, attLevel :int,
|
bundle :String, message :String, attLevel :int, localtype :String) :void
|
||||||
localtype :String) :void
|
|
||||||
{
|
{
|
||||||
// nothing should be untranslated, so pass the default bundle if need
|
// nothing should be untranslated, so pass the default bundle if need be.
|
||||||
// be.
|
|
||||||
if (bundle == null) {
|
if (bundle == null) {
|
||||||
bundle = _bundle;
|
bundle = _bundle;
|
||||||
}
|
}
|
||||||
@@ -976,8 +912,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up and returns the message type associated with the specified
|
* Looks up and returns the message type associated with the specified oid.
|
||||||
* oid.
|
|
||||||
*/
|
*/
|
||||||
protected function getLocalType (oid :int) :String
|
protected function getLocalType (oid :int) :String
|
||||||
{
|
{
|
||||||
@@ -1022,8 +957,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
/** A list of registered chat filters. */
|
/** A list of registered chat filters. */
|
||||||
protected var _filters :ObserverList = new ObserverList();
|
protected var _filters :ObserverList = new ObserverList();
|
||||||
|
|
||||||
/** A mapping from auxiliary chat objects to the types under which
|
/** A mapping from auxiliary chat objects to the types under which they are registered. */
|
||||||
* they are registered. */
|
|
||||||
protected var _auxes :HashMap = new HashMap();
|
protected var _auxes :HashMap = new HashMap();
|
||||||
|
|
||||||
/** Validator of who may be added to the chatters list. */
|
/** Validator of who may be added to the chatters list. */
|
||||||
|
|||||||
Reference in New Issue
Block a user