Added means by which client's username can be changed (very carefully).
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1684 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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;
|
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
|
* 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
|
* should be called to ensure that it is not unloaded by any entities
|
||||||
|
|||||||
@@ -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;
|
package com.threerings.presents.server;
|
||||||
|
|
||||||
@@ -62,6 +62,36 @@ public class PresentsClient
|
|||||||
return _username;
|
return _username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <em>Danger:</em> 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 <em>too</em> early in the session. The client must be fully
|
||||||
|
* resolved.
|
||||||
|
*
|
||||||
|
* <p> 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.
|
* Returns the client object that is associated with this client.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user