Various updates to allow a system where a user's visible name is not the same

as their authentication name (which we leave in BodyObject.username). This
turns out to be simpler than the system we adopted for Yohoho wherein we
replace the player's user object after they select a character, but converting
to this sort of system is way more work than would be worth it.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3758 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-11-10 23:18:58 +00:00
parent 3c91e33f04
commit 176329e1ed
17 changed files with 80 additions and 36 deletions
@@ -128,7 +128,7 @@ public class ChatProvider
}
// deliver a tell notification to the target player
sendTellMessage(tobj, source.username, null, message);
sendTellMessage(tobj, source.getVisibleName(), null, message);
// let the teller know it went ok
long idle = 0L;
@@ -161,7 +161,7 @@ public class ChatProvider
throw new InvocationException(errmsg);
}
broadcast(body.username, null, message, false);
broadcast(body.getVisibleName(), null, message, false);
}
/**
@@ -143,7 +143,7 @@ public class SpeakProvider
} else {
// issue the speak message on our speak object
sendSpeak(_speakObj, source.username, null, message, mode);
sendSpeak(_speakObj, source.getVisibleName(), null, message, mode);
}
}
@@ -312,9 +312,8 @@ public class SpeakProvider
}
/**
* Notes that the specified user was privy to the specified
* message. If {@link ChatMessage#timestamp} is not already filled in,
* it will be.
* Notes that the specified user was privy to the specified message. If
* {@link ChatMessage#timestamp} is not already filled in, it will be.
*/
protected static void noteMessage (Name username, UserMessage msg)
{
@@ -375,7 +374,7 @@ public class SpeakProvider
public void apply (int bodyOid) {
DObject dobj = CrowdServer.omgr.getObject(bodyOid);
if (dobj != null && dobj instanceof BodyObject) {
noteMessage(((BodyObject)dobj).username, message);
noteMessage(((BodyObject)dobj).getVisibleName(), message);
}
}
@@ -51,7 +51,9 @@ public class BodyObject extends ClientObject
// AUTO-GENERATED: FIELDS END
/**
* The username associated with this body object.
* The username associated with this body object. This should not be used
* directly; in general {@link #getVisibleName} should be used unless you
* specifically know that you want the username.
*/
public Name username;
@@ -109,6 +111,15 @@ public class BodyObject extends ClientObject
return EMPTY_TOKENS;
}
/**
* Returns the name that should be displayed to other users and used for
* the chat system. The default is to use {@link #username}.
*/
public Name getVisibleName ()
{
return username;
}
// documentation inherited
public void applyToListeners (ListenerOp op)
{
@@ -92,7 +92,7 @@ public class CrowdClient extends PresentsClient
// clear our chat history
if (body != null) {
SpeakProvider.clearHistory(body.username);
SpeakProvider.clearHistory(body.getVisibleName());
}
}
@@ -60,6 +60,9 @@ public class CrowdServer extends PresentsServer
// configure the dobject manager with our access controller
omgr.setDefaultAccessController(CrowdObjectAccess.DEFAULT);
// create our body locator
_lookup = createBodyLocator();
// create our place registry
plreg = createPlaceRegistry(invmgr, omgr);
@@ -81,6 +84,21 @@ public class CrowdServer extends PresentsServer
return new PlaceRegistry(invmgr, omgr);
}
/**
* Allow derived instances to create a custom {@link BodyLocator}. If the
* system opts not to use {@link BodyObject#username} as a user's visible
* name, it will need to provide a custom {@link BodyLocator}.
*/
protected BodyLocator createBodyLocator ()
{
return new BodyLocator() {
public BodyObject get (Name visibleName) {
// by default visibleName is username
return (BodyObject)clmgr.getClientObject(visibleName);
}
};
}
/**
* Enumerates the body objects for all active users on the server.
* This should only be called from the dobjmgr thread. The caller had
@@ -93,13 +111,13 @@ public class CrowdServer extends PresentsServer
}
/**
* The server maintains a mapping of username to body object for all
* active users on the server. This should only be called from the
* dobjmgr thread.
* Looks up the {@link BodyObject} for the user with the specified visible
* name, returns null if they are not online. This should only be called
* from the dobjmgr thread.
*/
public static BodyObject lookupBody (Name username)
public static BodyObject lookupBody (Name visibleName)
{
return (BodyObject)clmgr.getClientObject(username);
return _lookup.get(visibleName);
}
public static void main (String[] args)
@@ -114,6 +132,20 @@ public class CrowdServer extends PresentsServer
}
}
/** An interface that allows server extensions to reconfigure the body
* lookup process. See {@link #lookupBody}, {@link #createBodyLocator}. */
protected static interface BodyLocator
{
/** Returns the body object for the user with the specified visible
* name, or null if they are not online. This will only be called from
* the dobjmgr thread. */
public BodyObject get (Name visibleName);
}
/** Used to look up {@link BodyObject} instance for online users. See
* {@link #lookupBody}. */
protected static BodyLocator _lookup;
/** The config key for our list of invocation provider mappings. */
protected final static String PROVIDERS_KEY = "providers";
}
@@ -408,9 +408,9 @@ public class PlaceManager
*/
protected void populateOccupantInfo (OccupantInfo info, BodyObject body)
{
// the base occupant info is only their username
// the base occupant info is only their name and connection status
info.bodyOid = new Integer(body.getOid());
info.username = body.username;
info.username = body.getVisibleName();
info.status = body.status;
}