Localized chat! Server entities may now fake speak and tell messages that

are translated by the client upon receipt. We love to translate.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1319 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-04-30 17:27:30 +00:00
parent 530a348890
commit 4ec673e6c2
7 changed files with 159 additions and 38 deletions
@@ -1,5 +1,5 @@
//
// $Id: ChatMessageHandler.java,v 1.5 2001/12/14 00:11:17 mdb Exp $
// $Id: ChatMessageHandler.java,v 1.6 2002/04/30 17:27:30 mdb Exp $
package com.threerings.crowd.chat;
@@ -40,6 +40,6 @@ public class ChatMessageHandler implements PlaceManager.MessageHandler
// and generate a chat notification
ChatProvider.sendChatMessage(
event.getTargetOid(), source.username, message);
event.getTargetOid(), source.username, null, message);
}
}
@@ -1,5 +1,5 @@
//
// $Id: ChatDirector.java,v 1.19 2002/02/26 20:52:45 mdb Exp $
// $Id: ChatDirector.java,v 1.20 2002/04/30 17:27:30 mdb Exp $
package com.threerings.crowd.chat;
@@ -215,7 +215,24 @@ public class ChatDirector
// pass this on to our chat displays
for (int i = 0; i < _displays.size(); i++) {
ChatDisplay display = (ChatDisplay)_displays.get(i);
display.displayTellMessage(source, message);
display.displayTellMessage(source, null, message);
}
}
/**
* Called by the invocation director when an entity on the server has
* requested that we deliver a tell notification to this
* client. Because the server generated the notification, displays
* will want to translate the message itself using the supplied bundle
* identifier.
*/
public void handleTellNotification (
String source, String bundle, String message)
{
// pass this on to our chat displays
for (int i = 0; i < _displays.size(); i++) {
ChatDisplay display = (ChatDisplay)_displays.get(i);
display.displayTellMessage(source, bundle, message);
}
}
@@ -260,12 +277,22 @@ public class ChatDirector
protected void handleSpeakMessage (String type, Object[] args)
{
String speaker = (String)args[0];
String message = (String)args[1];
String bundle = null;
String message = null;
// determine whether this speak message originated from another
// client or from a server entity
if (args.length == 2) {
message = (String)args[1];
} else {
bundle = (String)args[1];
message = (String)args[2];
}
// pass this on to our chat displays
for (int i = 0; i < _displays.size(); i++) {
ChatDisplay display = (ChatDisplay)_displays.get(i);
display.displaySpeakMessage(type, speaker, message);
display.displaySpeakMessage(type, speaker, bundle, message);
}
}
@@ -1,5 +1,5 @@
//
// $Id: ChatDisplay.java,v 1.8 2002/02/26 05:47:40 mdb Exp $
// $Id: ChatDisplay.java,v 1.9 2002/04/30 17:27:30 mdb Exp $
package com.threerings.crowd.chat;
@@ -22,10 +22,14 @@ public interface ChatDisplay
* auxiliary chat object, the type code provided when that auxiliary
* object was registered.
* @param speaker the username of the speaker.
* @param bundle for speak messages that originated with a server
* entity rather than another client, this will be non-null and will
* contain a bundle identifier that should be used to translate the
* message text.
* @param message the text of the message.
*/
public void displaySpeakMessage (
String type, String speaker, String message);
String type, String speaker, String bundle, String message);
/**
* Called to display a tell message. A tell message is one that is
@@ -33,9 +37,14 @@ public interface ChatDisplay
* location in the system.
*
* @param speaker the username of the speaker.
* @param bundle for tell messages that originated with a server
* entity rather than another client, this will be non-null and will
* contain a bundle identifier that should be used to translate the
* message text.
* @param message the text of the message.
*/
public void displayTellMessage (String speaker, String message);
public void displayTellMessage (
String speaker, String bundle, String message);
/**
* Called to display a system message. A system message is one that is
@@ -1,5 +1,5 @@
//
// $Id: ChatProvider.java,v 1.9 2002/02/26 05:47:40 mdb Exp $
// $Id: ChatProvider.java,v 1.10 2002/04/30 17:27:30 mdb Exp $
package com.threerings.crowd.chat;
@@ -33,27 +33,63 @@ public class ChatProvider
} else {
// deliver a tell notification to the target player
Object[] args = new Object[] { source.username, message };
CrowdServer.invmgr.sendNotification(
tobj.getOid(), MODULE_NAME, TELL_NOTIFICATION, args);
sendTellMessage(tobj.getOid(), source.username, null, message);
// let the teller know it went ok
sendResponse(source, invid, TELL_SUCCEEDED_RESPONSE);
}
}
/**
* Delivers a tell notification to the specified target player,
* originating with the specified speaker.
*
* @param targetOid the body object id of the user that will receive
* the tell message.
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle the bundle identifier that will be used by the client
* to translate the message text (this would be null in all cases
* except where the message originated from some server entity that
* was "faking" a tell to a real player).
* @param message the text of the chat message.
*/
public static void sendTellMessage (
int targetOid, String speaker, String bundle, String message)
{
Object[] args = null;
if (bundle == null) {
args = new Object[] { speaker, message };
} else {
args = new Object[] { speaker, bundle, message };
}
CrowdServer.invmgr.sendNotification(
targetOid, MODULE_NAME, TELL_NOTIFICATION, args);
}
/**
* Sends a chat notification to the specified place object originating
* with the specified speaker and with the supplied message content.
* with the specified speaker (the speaker optionally being a server
* entity that wishes to fake a "speak" message) and with the supplied
* message content.
*
* @param placeOid the place to which to deliver the chat message.
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle null when the message originates from a real human,
* the bundle identifier that will be used by the client to translate
* the message text when the message originates from a server entity
* "faking" a chat message.
* @param message the text of the chat message.
*/
public static void sendChatMessage (
int placeOid, String speaker, String message)
int placeOid, String speaker, String bundle, String message)
{
Object[] outargs = new Object[] { speaker, message };
Object[] outargs = null;
if (bundle == null) {
outargs = new Object[] { speaker, message };
} else {
outargs = new Object[] { speaker, bundle, message };
}
MessageEvent nevt = new MessageEvent(
placeOid, ChatService.SPEAK_NOTIFICATION, outargs);
CrowdServer.omgr.postEvent(nevt);
@@ -1,5 +1,5 @@
//
// $Id: ChatPanel.java,v 1.13 2002/04/15 14:38:45 shaper Exp $
// $Id: ChatPanel.java,v 1.14 2002/04/30 17:27:30 mdb Exp $
package com.threerings.micasa.client;
@@ -226,10 +226,14 @@ public class ChatPanel
// documentation inherited
public void displaySpeakMessage (
String type, String speaker, String message)
String type, String speaker, String bundle, String message)
{
// wrap the speaker in brackets
speaker = "<" + speaker + "> ";
// translate the message if necessary
message = xlate(bundle, message);
// stick a newline on the message
message = message + "\n";
@@ -247,14 +251,7 @@ public class ChatPanel
String type, String bundle, String message)
{
// translate the message
MessageBundle msgb = _ctx.getMessageManager().getBundle(bundle);
if (msgb == null) {
Log.warning("No message bundle available to translate message " +
"[type=" + type + ", bundle=" + bundle +
", message=" + message + "].");
} else {
message = msgb.xlate(message);
}
message = xlate(bundle, message);
// stick a newline on the message
message = message + "\n";
@@ -267,6 +264,25 @@ public class ChatPanel
}
}
/**
* Translates the supplied message using the supplied bundle
* identifier iff the bundle identifier is not null. Otherwise it
* returns the original message.
*/
protected String xlate (String bundle, String message)
{
if (bundle != null) {
MessageBundle msgb = _ctx.getMessageManager().getBundle(bundle);
if (msgb == null) {
Log.warning("No message bundle available to translate " +
"[bundle=" + bundle + ", msg=" + message + "].");
} else {
message = msgb.xlate(message);
}
}
return message;
}
protected void displayError (String message)
{
// stick a newline on the message
@@ -281,10 +297,15 @@ public class ChatPanel
}
// documentation inherited
public void displayTellMessage (String speaker, String message)
public void displayTellMessage (
String speaker, String bundle, String message)
{
// wrap the speaker in brackets
speaker = "[" + speaker + " whispers] ";
// translate the message if necessary
message = xlate(bundle, message);
// stick a newline on the message
message = message + "\n";
@@ -1,5 +1,5 @@
//
// $Id: SpotProvider.java,v 1.6 2002/04/15 16:28:03 shaper Exp $
// $Id: SpotProvider.java,v 1.7 2002/04/30 17:27:30 mdb Exp $
package com.threerings.whirled.spot.server;
@@ -215,21 +215,49 @@ public class SpotProvider extends InvocationProvider
*/
public void handleClusterSpeakRequest (
BodyObject source, int invid, int sceneId, int locId, String message)
{
sendClusterChatMessage(sceneId, locId, source.getOid(),
source.username, null, message);
}
/**
* Sends a cluster chat notification to the specified location in the
* specified place object originating with the specified speaker (the
* speaker can be a server entity that wishes to fake a "speak"
* message, in which case the bundle argument should be non-null and
* should contain the id of the bundle to be used to translate the
* message text) and with the supplied message content.
*
* @param sceneId the scene id in which to deliver the chat message.
* @param locId the location whose cluster will be spoken to.
* @param speakerOid the body object id of the speaker (used to verify
* that they are in the cluster in question).
* @param speaker the username of the user that generated the message
* (or some special speaker name for server messages).
* @param bundle the bundle identifier that will be used by the client
* to translate the message text (or null if the message originated
* from a real live human who wrote it in their native tongue).
* @param message the text of the chat message.
*/
public static void sendClusterChatMessage (
int sceneId, int locId, int speakerOid, String speaker,
String bundle, String message)
{
// look up the scene manager for the specified scene
SpotSceneManager smgr = (SpotSceneManager)
_screg.getSceneManager(sceneId);
if (smgr == null) {
Log.warning("User requested cluster chat in " +
"non-existent scene [user=" + source.username +
"non-existent scene [user=" + speaker +
", sceneId=" + sceneId + ", locId=" + locId +
", message=" + message + "].");
} else {
// pass this request on to the spot scene manager as it will
// need to check that the location exists and that the
// requester occupies it and so on
smgr.handleClusterSpeakRequest(source, locId, message);
// need to check that the location exists and that the speaker
// occupies it and so on
smgr.handleClusterSpeakRequest(
speakerOid, speaker, locId, bundle, message);
}
}
@@ -1,5 +1,5 @@
//
// $Id: SpotSceneManager.java,v 1.5 2002/04/15 16:28:03 shaper Exp $
// $Id: SpotSceneManager.java,v 1.6 2002/04/30 17:27:30 mdb Exp $
package com.threerings.whirled.spot.server;
@@ -169,11 +169,12 @@ public class SpotSceneManager extends SceneManager
* request.
*/
protected void handleClusterSpeakRequest (
BodyObject source, int locationId, String message)
int sourceOid, String source, int locationId,
String bundle, String message)
{
// make sure this user occupies the specified location
int locidx = _sscene.getLocationIndex(locationId);
if (locidx == -1 || _locationOccs[locidx] != source.getOid()) {
if (locidx == -1 || _locationOccs[locidx] != sourceOid) {
Log.warning("User not in specified location for CCREQ " +
"[body=" + source + ", locId=" + locationId +
", message=" + message + "].");
@@ -192,12 +193,11 @@ public class SpotSceneManager extends SceneManager
// all is well, generate a chat notification
int clusterOid = _clusterOids[clusterIndex];
if (clusterOid > 0) {
ChatProvider.sendChatMessage(clusterOid, source.username, message);
ChatProvider.sendChatMessage(clusterOid, source, bundle, message);
} else {
Log.warning("Have no cluster object for CCREQ " +
"[cidx=" + clusterIndex +
", chatter=" + source.username +
"[cidx=" + clusterIndex + ", chatter=" + source +
", message=" + message + "].");
}
}