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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TableItem
|
||||
_tdtr.addSeatednessObserver(this);
|
||||
|
||||
// figure out who we are
|
||||
_self = ((BodyObject)ctx.getClient().getClientObject()).username;
|
||||
_self = ((BodyObject)ctx.getClient().getClientObject()).getVisibleName();
|
||||
|
||||
// now create our user interface
|
||||
setBorder(BorderFactory.createLineBorder(Color.black));
|
||||
|
||||
@@ -104,7 +104,7 @@ public class SimulatorManager
|
||||
|
||||
// configure the game config with the player names
|
||||
config.players = new Name[_playerCount];
|
||||
config.players[0] = _source.username;
|
||||
config.players[0] = _source.getVisibleName();
|
||||
for (int ii = 1; ii < _playerCount; ii++) {
|
||||
config.players[ii] = new Name("simulant" + ii);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
int fromidx = _cgmgr.getPlayerIndex(client);
|
||||
if (fromidx == -1) {
|
||||
Log.warning("Send request from non-player [username=" +
|
||||
((BodyObject)client).username + ", cards=" +
|
||||
((BodyObject)client).who() + ", cards=" +
|
||||
StringUtil.toString(cards) + "].");
|
||||
return;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
// make sure they have the cards
|
||||
if (!_hands[fromidx].containsAll(cards)) {
|
||||
Log.warning("Tried to send cards not held [username=" +
|
||||
((BodyObject)client).username + ", cards=" +
|
||||
((BodyObject)client).who() + ", cards=" +
|
||||
StringUtil.toString(cards) + "].");
|
||||
return;
|
||||
}
|
||||
@@ -268,7 +268,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
}
|
||||
|
||||
// make sure it's their turn
|
||||
Name username = ((BodyObject)client).username;
|
||||
Name username = ((BodyObject)client).getVisibleName();
|
||||
if (!username.equals(_trickCardGame.getTurnHolder())) {
|
||||
return;
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
// make sure the game is over
|
||||
if (_cardGame.state != CardGameObject.GAME_OVER) {
|
||||
Log.warning("Tried to request rematch when game wasn't over " +
|
||||
"[username=" + ((BodyObject)client).username + "].");
|
||||
"[username=" + ((BodyObject)client).who() + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
int pidx = _cgmgr.getPlayerIndex(client);
|
||||
if (pidx == -1) {
|
||||
Log.warning("Rematch request from non-player [username=" +
|
||||
((BodyObject)client).username + "].");
|
||||
((BodyObject)client).who() + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
if (_trickCardGame.getRematchRequests()[pidx] !=
|
||||
TrickCardGameObject.NO_REQUEST) {
|
||||
Log.warning("Repeated rematch request [username=" +
|
||||
((BodyObject)client).username + "].");
|
||||
((BodyObject)client).who() + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ public class TableDirector extends BasicDirector
|
||||
// look for our username in the occupants array
|
||||
BodyObject self = (BodyObject)_ctx.getClient().getClientObject();
|
||||
for (int i = 0; i < table.occupants.length; i++) {
|
||||
if (self.username.equals(table.occupants[i])) {
|
||||
if (self.getVisibleName().equals(table.occupants[i])) {
|
||||
_ourTable = table;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public abstract class GameController extends PlaceController
|
||||
// runnable here that will let the game manager know that we're
|
||||
// ready on the next pass through the distributed event loop
|
||||
Log.info("Entering game " + _gobj.which() + ".");
|
||||
if (_gobj.getPlayerIndex(bobj.username) != -1) {
|
||||
if (_gobj.getPlayerIndex(bobj.getVisibleName()) != -1) {
|
||||
_ctx.getClient().getRunQueue().postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
// finally let the game manager know that we're ready
|
||||
|
||||
@@ -1062,7 +1062,7 @@ public class GameManager extends PlaceManager
|
||||
BodyObject plobj = (BodyObject)caller;
|
||||
|
||||
// get the user's player index
|
||||
int pidx = _gameobj.getPlayerIndex(plobj.username);
|
||||
int pidx = _gameobj.getPlayerIndex(plobj.getVisibleName());
|
||||
if (pidx == -1) {
|
||||
// only complain if this is not a party game, since it's
|
||||
// perfectly normal to receive a player ready notification
|
||||
|
||||
@@ -103,8 +103,8 @@ public class ParlorManager
|
||||
_invites.put(invite.inviteId, invite);
|
||||
|
||||
// deliver an invite notification to the invitee
|
||||
ParlorSender.sendInvite(invitee, invite.inviteId,
|
||||
inviter.username, config);
|
||||
ParlorSender.sendInvite(
|
||||
invitee, invite.inviteId, inviter.getVisibleName(), config);
|
||||
|
||||
// and let the caller know the invite id we assigned
|
||||
return invite.inviteId;
|
||||
|
||||
@@ -177,7 +177,9 @@ public class ParlorProvider
|
||||
|
||||
try {
|
||||
// just this fellow will be playing
|
||||
config.players = new Name[] { user.username };
|
||||
if (config.players == null || config.players.length == 0) {
|
||||
config.players = new Name[] { user.getVisibleName() };
|
||||
}
|
||||
|
||||
// create the game manager and begin its initialization
|
||||
// process
|
||||
|
||||
@@ -114,7 +114,7 @@ public class TableManager
|
||||
// stick the creator into the first non-AI position
|
||||
int cpos = (config.ais == null) ? 0 : config.ais.length;
|
||||
String error =
|
||||
table.setOccupant(cpos, creator.username, creator.getOid());
|
||||
table.setOccupant(cpos, creator.getVisibleName(), creator.getOid());
|
||||
if (error != null) {
|
||||
Log.warning("Unable to add creator to position zero of " +
|
||||
"table!? [table=" + table + ", creator=" + creator +
|
||||
@@ -170,8 +170,8 @@ public class TableManager
|
||||
}
|
||||
|
||||
// request that the user be added to the table at that position
|
||||
String error =
|
||||
table.setOccupant(position, joiner.username, joiner.getOid());
|
||||
String error = table.setOccupant(
|
||||
position, joiner.getVisibleName(), joiner.getOid());
|
||||
// if that failed, report the error
|
||||
if (error != null) {
|
||||
throw new InvocationException(error);
|
||||
@@ -215,7 +215,7 @@ public class TableManager
|
||||
}
|
||||
|
||||
// request that the user be removed from the table
|
||||
if (!table.clearOccupant(leaver.username)) {
|
||||
if (!table.clearOccupant(leaver.getVisibleName())) {
|
||||
throw new InvocationException(NOT_AT_TABLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class TurnGameControllerDelegate extends GameControllerDelegate
|
||||
{
|
||||
BodyObject self = (BodyObject)_ctx.getClient().getClientObject();
|
||||
return (_gameObj.state == GameObject.IN_PLAY &&
|
||||
self.username.equals(_turnGame.getTurnHolder()));
|
||||
self.getVisibleName().equals(_turnGame.getTurnHolder()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -252,7 +252,7 @@ public class SpotProvider
|
||||
}
|
||||
|
||||
sendClusterChatMessage(getCallerSceneId(caller), source.getOid(),
|
||||
source.username, null, message, mode);
|
||||
source.getVisibleName(), null, message, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user