diff --git a/src/java/com/threerings/presents/server/ClientManager.java b/src/java/com/threerings/presents/server/ClientManager.java index b6ce1672c..4460135d1 100644 --- a/src/java/com/threerings/presents/server/ClientManager.java +++ b/src/java/com/threerings/presents/server/ClientManager.java @@ -1,5 +1,5 @@ // -// $Id: ClientManager.java,v 1.21 2002/07/23 05:52:49 mdb Exp $ +// $Id: ClientManager.java,v 1.22 2002/09/16 23:34:25 mdb Exp $ package com.threerings.presents.server; @@ -185,6 +185,45 @@ public class ClientManager implements ConnectionObserver } } + /** + * Remaps a client from its old username to the specified new + * username. The client must end its session using the new username. + * This most likely shouldn't be called anywhere except from {@link + * PresentsClient#setUsername}. + * + * @return true if the remapping succeeded, false if it failed. + */ + protected synchronized boolean remapClient ( + String oldname, String newname) + { + // make sure they are already mapped + PresentsClient client = (PresentsClient)_usermap.remove(oldname); + if (client == null) { + Log.warning("Aiya! Can't remap non-existent user " + + "[oldname=" + oldname + ", newname=" + newname + "]."); + return false; + } + + // map them under their new name + _usermap.put(newname, client); + + // release their old lock and create a lock for their new name + releaseClient(oldname); + lockClient(newname); + + // update their client object mapping + ClientObject clobj = (ClientObject)_objmap.remove(oldname); + if (clobj == null) { + Log.warning("Aiya! Unable to unmap old client object when " + + "remapping user [oldname=" + oldname + + ", newname=" + newname + "]. Hoping for the best."); + } else { + _objmap.put(newname, clobj); + } + + return true; + } + /** * When a client object becomes part of an active session, this method * should be called to ensure that it is not unloaded by any entities diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index 9c4b49cae..000ec9b42 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -1,5 +1,5 @@ // -// $Id: PresentsClient.java,v 1.35 2002/08/14 19:07:56 mdb Exp $ +// $Id: PresentsClient.java,v 1.36 2002/09/16 23:34:25 mdb Exp $ package com.threerings.presents.server; @@ -62,6 +62,36 @@ public class PresentsClient return _username; } + /** + * Danger: this method is not for general consumption. This + * changes the username of the client, but should only be done very + * early in a user's session, when you know that no one has mapped the + * user based on their username or has in any other way made use of + * their username in a way that will break. However, it should not be + * done too early in the session. The client must be fully + * resolved. + * + *

It exists to support systems wherein a user logs in with an + * account username and then chooses a "screen name" by which they + * will play (often from a small set of available "characters" + * available per account). This will take care of remapping the + * username to client object mappings that were made by the Presents + * services when the user logs on, but anything else that has had its + * grubby mits on the username will be left to its own devices, hence + * the care that must be exercised when using this method. + */ + public void setUsername (String username) + { + // remap the client object in the client manager + if (_cmgr.remapClient(_username, username)) { + // change our internal business + _username = username; + } else { + Log.warning("Unable to remap username [client=" + this + + ", newname=" + username + "]."); + } + } + /** * Returns the client object that is associated with this client. */