From 176329e1edecba94a68b3ebb96810c79a8ceb838 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 10 Nov 2005 23:18:58 +0000 Subject: [PATCH] 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 --- .../crowd/chat/server/ChatProvider.java | 4 +- .../crowd/chat/server/SpeakProvider.java | 9 ++-- .../com/threerings/crowd/data/BodyObject.java | 13 +++++- .../threerings/crowd/server/CrowdClient.java | 2 +- .../threerings/crowd/server/CrowdServer.java | 42 ++++++++++++++++--- .../threerings/crowd/server/PlaceManager.java | 4 +- .../micasa/lobby/table/TableItem.java | 2 +- .../simulator/server/SimulatorManager.java | 2 +- .../server/TrickCardGameManagerDelegate.java | 12 +++--- .../parlor/client/TableDirector.java | 2 +- .../parlor/game/client/GameController.java | 2 +- .../parlor/game/server/GameManager.java | 2 +- .../parlor/server/ParlorManager.java | 4 +- .../parlor/server/ParlorProvider.java | 4 +- .../parlor/server/TableManager.java | 8 ++-- .../client/TurnGameControllerDelegate.java | 2 +- .../whirled/spot/server/SpotProvider.java | 2 +- 17 files changed, 80 insertions(+), 36 deletions(-) diff --git a/src/java/com/threerings/crowd/chat/server/ChatProvider.java b/src/java/com/threerings/crowd/chat/server/ChatProvider.java index 3f5fbfd63..abf65edb8 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatProvider.java +++ b/src/java/com/threerings/crowd/chat/server/ChatProvider.java @@ -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); } /** diff --git a/src/java/com/threerings/crowd/chat/server/SpeakProvider.java b/src/java/com/threerings/crowd/chat/server/SpeakProvider.java index f1b2fa2a4..011927741 100644 --- a/src/java/com/threerings/crowd/chat/server/SpeakProvider.java +++ b/src/java/com/threerings/crowd/chat/server/SpeakProvider.java @@ -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); } } diff --git a/src/java/com/threerings/crowd/data/BodyObject.java b/src/java/com/threerings/crowd/data/BodyObject.java index bd3144f13..4d5eb2dd4 100644 --- a/src/java/com/threerings/crowd/data/BodyObject.java +++ b/src/java/com/threerings/crowd/data/BodyObject.java @@ -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) { diff --git a/src/java/com/threerings/crowd/server/CrowdClient.java b/src/java/com/threerings/crowd/server/CrowdClient.java index 2c4668269..30cd0a4b8 100644 --- a/src/java/com/threerings/crowd/server/CrowdClient.java +++ b/src/java/com/threerings/crowd/server/CrowdClient.java @@ -92,7 +92,7 @@ public class CrowdClient extends PresentsClient // clear our chat history if (body != null) { - SpeakProvider.clearHistory(body.username); + SpeakProvider.clearHistory(body.getVisibleName()); } } diff --git a/src/java/com/threerings/crowd/server/CrowdServer.java b/src/java/com/threerings/crowd/server/CrowdServer.java index 876255c89..d3963bfea 100644 --- a/src/java/com/threerings/crowd/server/CrowdServer.java +++ b/src/java/com/threerings/crowd/server/CrowdServer.java @@ -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"; } diff --git a/src/java/com/threerings/crowd/server/PlaceManager.java b/src/java/com/threerings/crowd/server/PlaceManager.java index 133a70c74..a9b4009e2 100644 --- a/src/java/com/threerings/crowd/server/PlaceManager.java +++ b/src/java/com/threerings/crowd/server/PlaceManager.java @@ -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; } diff --git a/src/java/com/threerings/micasa/lobby/table/TableItem.java b/src/java/com/threerings/micasa/lobby/table/TableItem.java index 95417ad6a..e9d82ecd8 100644 --- a/src/java/com/threerings/micasa/lobby/table/TableItem.java +++ b/src/java/com/threerings/micasa/lobby/table/TableItem.java @@ -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)); diff --git a/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java b/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java index 29f7ab797..193f07139 100644 --- a/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java +++ b/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java @@ -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); } diff --git a/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java b/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java index d398c7550..89cda766b 100644 --- a/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java +++ b/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java @@ -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; } diff --git a/src/java/com/threerings/parlor/client/TableDirector.java b/src/java/com/threerings/parlor/client/TableDirector.java index 1031f5df3..2363c5c4c 100644 --- a/src/java/com/threerings/parlor/client/TableDirector.java +++ b/src/java/com/threerings/parlor/client/TableDirector.java @@ -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; } diff --git a/src/java/com/threerings/parlor/game/client/GameController.java b/src/java/com/threerings/parlor/game/client/GameController.java index 388c4e15f..712f373ff 100644 --- a/src/java/com/threerings/parlor/game/client/GameController.java +++ b/src/java/com/threerings/parlor/game/client/GameController.java @@ -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 diff --git a/src/java/com/threerings/parlor/game/server/GameManager.java b/src/java/com/threerings/parlor/game/server/GameManager.java index e2e126d36..a72eca7eb 100644 --- a/src/java/com/threerings/parlor/game/server/GameManager.java +++ b/src/java/com/threerings/parlor/game/server/GameManager.java @@ -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 diff --git a/src/java/com/threerings/parlor/server/ParlorManager.java b/src/java/com/threerings/parlor/server/ParlorManager.java index aa4b0f219..6c8a083d1 100644 --- a/src/java/com/threerings/parlor/server/ParlorManager.java +++ b/src/java/com/threerings/parlor/server/ParlorManager.java @@ -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; diff --git a/src/java/com/threerings/parlor/server/ParlorProvider.java b/src/java/com/threerings/parlor/server/ParlorProvider.java index 6bc13dac9..2c8514743 100644 --- a/src/java/com/threerings/parlor/server/ParlorProvider.java +++ b/src/java/com/threerings/parlor/server/ParlorProvider.java @@ -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 diff --git a/src/java/com/threerings/parlor/server/TableManager.java b/src/java/com/threerings/parlor/server/TableManager.java index f53a6312b..beeaf9432 100644 --- a/src/java/com/threerings/parlor/server/TableManager.java +++ b/src/java/com/threerings/parlor/server/TableManager.java @@ -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); } diff --git a/src/java/com/threerings/parlor/turn/client/TurnGameControllerDelegate.java b/src/java/com/threerings/parlor/turn/client/TurnGameControllerDelegate.java index f5b7fcac5..10096b46f 100644 --- a/src/java/com/threerings/parlor/turn/client/TurnGameControllerDelegate.java +++ b/src/java/com/threerings/parlor/turn/client/TurnGameControllerDelegate.java @@ -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())); } /** diff --git a/src/java/com/threerings/whirled/spot/server/SpotProvider.java b/src/java/com/threerings/whirled/spot/server/SpotProvider.java index f865e5518..dee16d21c 100644 --- a/src/java/com/threerings/whirled/spot/server/SpotProvider.java +++ b/src/java/com/threerings/whirled/spot/server/SpotProvider.java @@ -252,7 +252,7 @@ public class SpotProvider } sendClusterChatMessage(getCallerSceneId(caller), source.getOid(), - source.username, null, message, mode); + source.getVisibleName(), null, message, mode); } /**