|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.presents.client.BasicDirector
com.threerings.crowd.chat.client.ChatDirector
public class ChatDirector
The chat director is the client side coordinator of all chat related services. It handles both place constrained chat as well as direct messaging.
| Nested Class Summary | |
|---|---|
protected class |
ChatDirector.BroadcastHandler
Implements /broadcast. |
static interface |
ChatDirector.ChatterObserver
An interface to receive information about the MAX_CHATTERS most recent users that
we've been chatting with. |
static interface |
ChatDirector.ChatterValidator
An interface for those who would like to validate whether usernames may be added to the chatter list. |
protected class |
ChatDirector.ClearHandler
Implements /clear. |
static class |
ChatDirector.CommandHandler
Used to implement a slash command (e.g. |
protected static class |
ChatDirector.DisplayMessageOp
An observer op used to dispatch ChatMessages on the client. |
protected class |
ChatDirector.EmoteHandler
Implements /emote. |
protected static class |
ChatDirector.FilterMessageOp
An operation that checks with all chat filters to properly filter a message prior to sending to the server or displaying. |
protected class |
ChatDirector.HelpHandler
Implements /help. |
protected class |
ChatDirector.SpeakHandler
Implements /speak. |
protected class |
ChatDirector.TellHandler
Implements /tell. |
protected class |
ChatDirector.ThinkHandler
Implements /think. |
| Field Summary | |
|---|---|
protected HashIntMap<String> |
_auxes
A mapping from auxiliary chat objects to the types under which they are registered. |
protected String |
_bundle
The bundle to use for our own internal messages. |
protected ObserverList<ChatDirector.ChatterObserver> |
_chatterObservers
Observers that are watching our chatters list. |
protected LinkedList<Name> |
_chatters
Usernames of users we've recently chatted with. |
protected ChatDirector.ChatterValidator |
_chatterValidator
Validator of who may be added to the chatters list. |
protected ClientObject |
_clobj
The client object that we're listening to for tells. |
protected ChatService |
_cservice
Provides access to chat-related server-side services. |
protected CrowdContext |
_ctx
Our active chat context. |
protected ChatDirector.DisplayMessageOp |
_displayMessageOp
Operation used to display chat messages. |
protected ObserverList<ChatDisplay> |
_displays
A list of registered chat displays. |
protected ChatDirector.FilterMessageOp |
_filterMessageOp
Operation used to filter chat messages. |
protected ObserverList<ChatFilter> |
_filters
A list of registered chat filters. |
protected static HashMap<String,ChatDirector.CommandHandler> |
_handlers
Registered chat command handlers. |
protected static ArrayList<String> |
_history
A history of chat commands. |
protected HistoryList |
_hlist
A rolling chat history, or null if getHistory() is never called. |
protected boolean |
_mogrifyChat
Whether or not to run chat through the mogrifier. |
protected PlaceObject |
_place
The place object that we currently occupy. |
protected static boolean |
_showAliasesInUsage
If set, only show the first alias (translation) of each command in the full list and show the full list of aliases in the command usage. |
protected static int |
MAX_CHATTERS
The maximum number of chatter usernames to track. |
protected static int |
MAX_COMMAND_HISTORY
The maximum number of commands to keep in the chat history. |
| Fields inherited from class com.threerings.presents.client.BasicDirector |
|---|
_availableInStandalone |
| Fields inherited from interface com.threerings.crowd.chat.data.ChatCodes |
|---|
BROADCAST_ACCESS, BROADCAST_MODE, CHAT_ACCESS, CHAT_CHANNEL_NOTIFICATION, CHAT_NOTIFICATION, DEFAULT_IDLE_TIME, DEFAULT_MODE, EMOTE_MODE, IDLE_TIME_KEY, LAST_MODE, PLACE_CHAT_TYPE, SHOUT_MODE, SUCCESS, THINK_MODE, USER_CHAT_TYPE, USER_DISCONNECTED, USER_NOT_ONLINE, XLATE_MODES |
| Fields inherited from interface com.threerings.presents.data.InvocationCodes |
|---|
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR |
| Constructor Summary | |
|---|---|
ChatDirector(CrowdContext ctx,
String bundle)
Creates a chat director and initializes it with the supplied context. |
|
| Method Summary | ||
|---|---|---|
void |
addAuxiliarySource(DObject source,
String localtype)
Adds an additional object via which chat messages may arrive. |
|
boolean |
addChatDisplay(ChatDisplay display)
Adds the supplied chat display to the end of the chat display list. |
|
boolean |
addChatFilter(ChatFilter filter)
Adds the specified chat filter to the list of filters. |
|
protected void |
addChatter(Name name)
Adds a chatter to our list of recent chatters. |
|
boolean |
addChatterObserver(ChatDirector.ChatterObserver co)
Adds an observer that watches the chatters list, and updates it immediately. |
|
protected void |
addToHistory(String cmd)
Adds the specified command to the history. |
|
protected String |
checkCanChat(SpeakService speakSvc,
String message,
byte mode)
Called to determine whether we are permitted to post the supplied chat message. |
|
protected String |
checkLength(String msg)
Check that after mogrification the message is not too long. |
|
void |
clearCommandHistory()
Clear the chat command history. |
|
void |
clearDisplays()
Requests that all chat displays clear their contents. |
|
void |
clientDidLogoff(Client client)
Called after the client has been logged off of the server and has disconnected. |
|
void |
clientDidLogon(Client client)
Called after the client successfully connected to and authenticated with the server. |
|
void |
clientObjectDidChange(Client client)
For systems that allow switching screen names after logon, this method is called whenever a screen name change takes place to report that the client object has been replaced to potential client-side subscribers. |
|
protected String |
deliverChat(SpeakService speakSvc,
String message,
byte mode)
Delivers a plain chat message (not a slash command) on the specified speak service in the specified mode. |
|
void |
dispatchMessage(ChatMessage message,
String localType)
Dispatches the provided message to our chat displays. |
|
protected void |
dispatchPreparedMessage(ChatMessage message)
Dispatch a message to chat displays once it is fully prepared with the clientinfo. |
|
void |
displayAttention(String bundle,
String message)
Display a system ATTENTION message as if it had come from the server. |
|
void |
displayFeedback(String bundle,
String message)
Display a system FEEDBACK message as if it had come from the server. |
|
void |
displayInfo(String bundle,
String message)
Display a system INFO message as if it had come from the server. |
|
void |
displayInfo(String bundle,
String message,
String localtype)
Display a system INFO message as if it had come from the server. |
|
protected void |
displaySystem(String bundle,
String message,
byte attLevel,
String localtype)
Display the specified system message as if it had come from the server. |
|
protected void |
fetchServices(Client client)
Derived directors can override this method and obtain any services they'll need during their operation via calls to Client.getService(java.lang.Class. |
|
String |
filter(String msg,
Name otherUser,
boolean outgoing)
Run a message through all the currently registered filters. |
|
protected Map<String,ChatDirector.CommandHandler> |
getCommandHandlers(String command)
Returns a map containing all command handlers that match the specified command (i.e. the specified command is a prefix of their registered command string). |
|
String |
getCommandHistory(int index)
Get the chat history entry at the specified index, with 0 being the oldest. |
|
int |
getCommandHistorySize()
Return the current size of the history. |
|
HistoryList |
getHistory()
Returns the history list containing a trailing window of messages that have passed through this chat director. |
|
protected String |
getLocalType(int oid)
Looks up and returns the message type associated with the specified oid. |
|
protected boolean |
isCommandPrefix(String enteredCommand,
String handlerCommand,
ChatDirector.CommandHandler handler,
BodyObject user)
Returns true if enteredCommand equals or is a prefix of
handlerCommand and if the handler is available for user. |
|
void |
locationChangeFailed(int placeId,
String reason)
This is called on all location observers when a location change request is rejected by the server or fails for some other reason. |
|
void |
locationDidChange(PlaceObject place)
Called when we have switched to a new location. |
|
boolean |
locationMayChange(int placeId)
Called when someone has requested that we switch to a new location. |
|
void |
messageReceived(MessageEvent event)
Called when an message event has been dispatched on an object. |
|
String |
mogrifyChat(String text)
Runs the supplied message through the various chat mogrifications. |
|
protected StringBuffer |
mogrifyChat(StringBuffer buf,
boolean transformsAllowed,
boolean capFirst)
Helper function for mogrifyChat(String,byte,boolean,boolean). |
|
protected String |
mogrifyChat(String text,
byte mode,
boolean transformsAllowed,
boolean capFirst)
Mogrifies common literary crutches into more appealing chat or commands. |
|
protected void |
notifyChatterObservers()
Notifies all registered ChatDirector.ChatterObservers that the list of chatters has changed. |
|
protected void |
processReceivedMessage(ChatMessage msg,
String localtype)
Processes and dispatches the specified chat message. |
|
void |
pushChatDisplay(ChatDisplay display)
Adds the supplied chat display to the front of the chat display list. |
|
void |
registerCommandHandler(MessageBundle msg,
String command,
ChatDirector.CommandHandler handler)
Registers a chat command handler. |
|
protected void |
registerCommandHandlers()
Registers all the chat-command handlers. |
|
protected void |
registerServices(Client client)
If a director makes use of bootstrap invocation services which are part of a bootstrap service group, it should register interest in that group here with a call to Client.addServiceGroup(java.lang.String). |
|
void |
removeAuxiliarySource(DObject source)
Removes a previously added auxiliary chat source. |
|
boolean |
removeChatDisplay(ChatDisplay display)
Removes the specified chat display from the chat display list. |
|
boolean |
removeChatFilter(ChatFilter filter)
Removes the specified chat filter from the list of chat filter. |
|
boolean |
removeChatterObserver(ChatDirector.ChatterObserver co)
Removes an observer from the list of chatter observers. |
|
void |
requestBroadcast(String message)
Requests to send a site-wide broadcast message. |
|
String |
requestChat(SpeakService speakSvc,
String text,
boolean record)
Parses and delivers the supplied chat message. |
|
void |
requestSpeak(SpeakService speakService,
String message,
byte mode)
Requests that a speak message with the specified mode be generated and delivered via the supplied speak service instance (which will be associated with a particular "speak object"). |
|
|
requestTell(T target,
String msg,
ResultListener<T> rl)
Requests that a tell message be delivered to the specified target user. |
|
void |
setAwayMessage(String message)
Configures a message that will be automatically reported to anyone that sends a tell message to this client to indicate that we are busy or away from the keyboard. |
|
void |
setChatterValidator(ChatDirector.ChatterValidator validator)
Sets the validator that decides if a username is valid to be added to the chatter list, or null if no such filtering is desired. |
|
protected void |
setClientInfo(ChatMessage msg,
String localType)
Set the "client info" on the specified message, if not already set. |
|
void |
setMogrifyChat(boolean mogrifyChat)
Enables or disables the chat mogrifier. |
|
protected boolean |
shouldFilter(ChatMessage msg)
Checks whether we should filter the supplied incoming message. |
|
protected boolean |
suppressTooManyCaps()
Return true if we should lowercase messages containing more than half upper-case characters. |
|
protected StringBuffer |
translatedReplacements(String key,
StringBuffer buf)
Do all the replacements (mogrifications) specified in the translation string specified by the key. |
|
protected String |
xlate(String bundle,
String message)
Translates the specified message using the specified bundle. |
|
| Methods inherited from class com.threerings.presents.client.BasicDirector |
|---|
assertAvailable, clientObjectUpdated, clientWillLogon, isAvailable, isAvailableInStandalone, setAvailableInStandalone |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected CrowdContext _ctx
protected ChatService _cservice
protected String _bundle
protected PlaceObject _place
protected ClientObject _clobj
protected boolean _mogrifyChat
protected ObserverList<ChatDisplay> _displays
protected ObserverList<ChatFilter> _filters
protected HashIntMap<String> _auxes
protected ChatDirector.ChatterValidator _chatterValidator
protected LinkedList<Name> _chatters
protected ObserverList<ChatDirector.ChatterObserver> _chatterObservers
protected ChatDirector.FilterMessageOp _filterMessageOp
protected ChatDirector.DisplayMessageOp _displayMessageOp
protected HistoryList _hlist
getHistory() is never called.
protected static HashMap<String,ChatDirector.CommandHandler> _handlers
protected static ArrayList<String> _history
protected static boolean _showAliasesInUsage
protected static final int MAX_CHATTERS
protected static final int MAX_COMMAND_HISTORY
| Constructor Detail |
|---|
public ChatDirector(CrowdContext ctx,
String bundle)
bundle - the message bundle from which we obtain our chat-related translation strings.| Method Detail |
|---|
public void pushChatDisplay(ChatDisplay display)
public boolean addChatDisplay(ChatDisplay display)
public boolean removeChatDisplay(ChatDisplay display)
public boolean addChatFilter(ChatFilter filter)
public boolean removeChatFilter(ChatFilter filter)
public boolean addChatterObserver(ChatDirector.ChatterObserver co)
public boolean removeChatterObserver(ChatDirector.ChatterObserver co)
public void setChatterValidator(ChatDirector.ChatterValidator validator)
public void setMogrifyChat(boolean mogrifyChat)
x.mogrifies and x.transforms translation
properties.
public void registerCommandHandler(MessageBundle msg,
String command,
ChatDirector.CommandHandler handler)
msg - the message bundle via which the slash command will be translated (as
c.command). If no translation exists the command will be
/command.command - the name of the command that will be used to invoke this handler (e.g.
tell if the command will be invoked as /tell).handler - the chat command handler itself.public int getCommandHistorySize()
public String getCommandHistory(int index)
public void clearCommandHistory()
public void clearDisplays()
public void displayInfo(String bundle,
String message)
public void displayInfo(String bundle,
String message,
String localtype)
public void displayFeedback(String bundle,
String message)
public void displayAttention(String bundle,
String message)
public void dispatchMessage(ChatMessage message,
String localType)
public String requestChat(SpeakService speakSvc,
String text,
boolean record)
speakSvc - the SpeakService representing the target dobj of the speak or null if we
should speak in the "default" way.text - the text to be parsed and sent.record - if text is a command, should it be added to the history?
ChatCodes#SUCCESS if the message was parsed and sent correctly, a
translatable error string if there was some problem.
public void requestSpeak(SpeakService speakService,
String message,
byte mode)
ChatFilters (and
possibly vetoed) before being dispatched.
speakService - the speak service to use when generating the speak request or null if we
should speak in the current "place".message - the contents of the speak message.mode - a speech mode that will be interpreted by the ChatDisplay
implementations that eventually display this speak message.public void requestBroadcast(String message)
message - the contents of the message.
public <T extends Name> void requestTell(T target,
String msg,
ResultListener<T> rl)
target - the username of the user to which the tell message should be delivered.msg - the contents of the tell message.rl - an optional result listener if you'd like to be notified of success or failure.public void setAwayMessage(String message)
public void addAuxiliarySource(DObject source,
String localtype)
localtype - a type to be associated with all chat messages that arrive on the specified
DObject.public void removeAuxiliarySource(DObject source)
public HistoryList getHistory()
public String filter(String msg,
Name otherUser,
boolean outgoing)
public String mogrifyChat(String text)
public boolean locationMayChange(int placeId)
LocationObserver
locationMayChange in interface LocationObserverpublic void locationDidChange(PlaceObject place)
LocationObserver
locationDidChange in interface LocationObserverplace - the place object that represents the new location or
null if we have switched to no location.
public void locationChangeFailed(int placeId,
String reason)
LocationObserver
locationChangeFailed in interface LocationObserverplaceId - the place id to which we attempted to relocate, but
failed.reason - the reason code that explains why the location change
request was rejected or otherwise failed.public void messageReceived(MessageEvent event)
MessageListener
messageReceived in interface MessageListenerevent - The event that was dispatched on the object.public void clientDidLogon(Client client)
SessionObserver
clientDidLogon in interface SessionObserverclientDidLogon in class BasicDirectorpublic void clientObjectDidChange(Client client)
SessionObserver
clientObjectDidChange in interface SessionObserverclientObjectDidChange in class BasicDirectorpublic void clientDidLogoff(Client client)
SessionObserver
clientDidLogoff in interface SessionObserverclientDidLogoff in class BasicDirectorprotected void registerCommandHandlers()
protected void processReceivedMessage(ChatMessage msg,
String localtype)
protected boolean shouldFilter(ChatMessage msg)
protected void dispatchPreparedMessage(ChatMessage message)
protected String checkCanChat(SpeakService speakSvc,
String message,
byte mode)
protected String deliverChat(SpeakService speakSvc,
String message,
byte mode)
ChatCodes.SUCCESS if the message was delivered or a string indicating why it
failed.protected void addToHistory(String cmd)
protected String mogrifyChat(String text,
byte mode,
boolean transformsAllowed,
boolean capFirst)
mode - the chat mode, or -1 if unknown.transformsAllowed - if true, the chat may transformed into a different mode. (lol ->
/emote laughs)capFirst - if true, the first letter of the text is capitalized. This is not desired if
the chat is already an emote.
protected StringBuffer mogrifyChat(StringBuffer buf,
boolean transformsAllowed,
boolean capFirst)
mogrifyChat(String,byte,boolean,boolean).
protected StringBuffer translatedReplacements(String key,
StringBuffer buf)
protected boolean suppressTooManyCaps()
protected String checkLength(String msg)
protected Map<String,ChatDirector.CommandHandler> getCommandHandlers(String command)
protected boolean isCommandPrefix(String enteredCommand,
String handlerCommand,
ChatDirector.CommandHandler handler,
BodyObject user)
enteredCommand equals or is a prefix of
handlerCommand and if the handler is available for user.
protected void addChatter(Name name)
protected void notifyChatterObservers()
ChatDirector.ChatterObservers that the list of chatters has changed.
protected void setClientInfo(ChatMessage msg,
String localType)
protected String xlate(String bundle,
String message)
protected void displaySystem(String bundle,
String message,
byte attLevel,
String localtype)
protected String getLocalType(int oid)
protected void registerServices(Client client)
BasicDirectorClient.addServiceGroup(java.lang.String).
registerServices in class BasicDirectorprotected void fetchServices(Client client)
BasicDirectorClient.getService(java.lang.Class) . If the director is available, it will
automatically be called when the client logs on or when the director is constructed if it is
constructed after the client is already logged on.
fetchServices in class BasicDirector
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||