Add a cousin of setUsername, updateUsername, that does the same thing but in the active client object. Like setUsername, its invocation should always be accompanied by the sacrifice of at least three chickens and if you really want it to succeed, one small goat.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5081 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Charlie Groves
2008-05-12 21:23:16 +00:00
parent cbc7d7b007
commit 8581947de5
2 changed files with 35 additions and 1 deletions
@@ -24,7 +24,6 @@ package com.threerings.presents.server;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.logging.Level;
@@ -307,6 +306,23 @@ public class ClientManager
PresentsServer.omgr.destroyObject(clobj.getOid());
}
/**
* Renames a currently connected client from <code>oldname</code> to <code>newname</code>
*
* @return true if the client was found and renamed.
*/
protected boolean renameClientObject (Name oldname, Name newname)
{
ClientObject clobj = _objmap.remove(oldname);
if (clobj == null) {
log.warning("Requested to rename unmapped client object [username=" + oldname + "].");
Thread.dumpStack();
return false;
}
_objmap.put(newname, clobj);
return true;
}
// documentation inherited from interface ClientResolutionListener
public synchronized void clientResolved (Name username, ClientObject clobj)
{
@@ -261,6 +261,24 @@ public class PresentsClient
_cmgr.resolveClientObject(username, clr);
}
/**
* <em>Double Danger:</em> this method is not for general consumption. Like
* {@code #setUsername}, this changes the username of the client, but unlike setUsername, it
* does it in the existing client object. Care must be taken to ensure that any client or
* server code either doesn't map things based on username before this call, or that it's
* updated to reflect the change.
*
* @return - true if the client was successfully renamed, false otherwise
*/
public boolean updateUsername (Name username)
{
if (_cmgr.renameClientObject(_username, username)) {
_username = username;
return true;
}
return false;
}
/**
* Returns the client object that is associated with this client.
*/