405 modified source files and 17,367 lines of diffs later we now enforce
more discipline when handling names in our code base. Any user entered name should find its way into a Name object as soon as it comes out of a text field or whatnot, and stay that way until it makes its way into a text field or into a database record (for which String objects are vastly simpler because of JORA magic). Dear God, let me never again make a change this large for the rest of my mortal life. Unfortunately, this means we have to keep an eye out for funny business pretty much everywhere. However, since we will absolutely want to test market stalls and so forth on Azure, we'll have an opportunity to iron out any funny business that might fall under the radar during our internal testing. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2980 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ClientManager.java,v 1.35 2004/02/21 01:00:23 ray Exp $
|
||||
// $Id: ClientManager.java,v 1.36 2004/03/06 11:29:19 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
@@ -12,6 +12,8 @@ import java.util.Iterator;
|
||||
import com.samskivert.util.IntervalManager;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.net.AuthRequest;
|
||||
@@ -143,9 +145,9 @@ public class ClientManager
|
||||
* specified authentication username or null if that client is not
|
||||
* currently connected to the server.
|
||||
*/
|
||||
public PresentsClient getClient (String authUsername)
|
||||
public PresentsClient getClient (Name authUsername)
|
||||
{
|
||||
return (PresentsClient)_usermap.get(authUsername.toLowerCase());
|
||||
return (PresentsClient)_usermap.get(authUsername);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,26 +155,16 @@ public class ClientManager
|
||||
* This will return null unless the client object is resolved for some
|
||||
* reason (like they are logged on).
|
||||
*/
|
||||
public ClientObject getClientObject (String username)
|
||||
public ClientObject getClientObject (Name username)
|
||||
{
|
||||
return (ClientObject)_objmap.get(toKey(username));
|
||||
}
|
||||
|
||||
/**
|
||||
* We convert usernames to lower case in the username to client object
|
||||
* mapping so that we can pass arbitrarily cased usernames (like those
|
||||
* that might be typed in by a "user") straight on through.
|
||||
*/
|
||||
protected final String toKey (String username)
|
||||
{
|
||||
return username.toLowerCase();
|
||||
return (ClientObject)_objmap.get(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the specified client, applies the supplied client
|
||||
* operation to them and releases the client.
|
||||
*/
|
||||
public void applyToClient (String username, ClientOp clop)
|
||||
public void applyToClient (Name username, ClientOp clop)
|
||||
{
|
||||
resolveClientObject(username, new ClientOpResolver(clop));
|
||||
}
|
||||
@@ -187,11 +179,10 @@ public class ClientManager
|
||||
* when the caller is finished with the client object.
|
||||
*/
|
||||
public synchronized void resolveClientObject (
|
||||
String username, ClientResolutionListener listener)
|
||||
Name username, ClientResolutionListener listener)
|
||||
{
|
||||
// look to see if the client object is already resolved
|
||||
String key = toKey(username);
|
||||
ClientObject clobj = (ClientObject)_objmap.get(key);
|
||||
ClientObject clobj = (ClientObject)_objmap.get(username);
|
||||
if (clobj != null) {
|
||||
clobj.reference();
|
||||
listener.clientResolved(username, clobj);
|
||||
@@ -199,7 +190,7 @@ public class ClientManager
|
||||
}
|
||||
|
||||
// look to see if it's currently being resolved
|
||||
ClientResolver clr = (ClientResolver)_penders.get(key);
|
||||
ClientResolver clr = (ClientResolver)_penders.get(username);
|
||||
if (clr != null) {
|
||||
// throw this guy onto the bandwagon
|
||||
clr.addResolutionListener(listener);
|
||||
@@ -228,14 +219,13 @@ public class ClientManager
|
||||
* resolved.
|
||||
*/
|
||||
protected synchronized void mapClientObject (
|
||||
String username, ClientObject clobj)
|
||||
Name username, ClientObject clobj)
|
||||
{
|
||||
// stuff the object into the mapping table
|
||||
String key = toKey(username);
|
||||
_objmap.put(key, clobj);
|
||||
_objmap.put(username, clobj);
|
||||
|
||||
// and remove the resolution listener
|
||||
_penders.remove(key);
|
||||
_penders.remove(username);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,10 +233,9 @@ public class ClientManager
|
||||
* #resolveClientObject}. If this caller is the last reference, the
|
||||
* object will be flushed and destroyed.
|
||||
*/
|
||||
public void releaseClientObject (String username)
|
||||
public void releaseClientObject (Name username)
|
||||
{
|
||||
String key = toKey(username);
|
||||
ClientObject clobj = (ClientObject)_objmap.get(key);
|
||||
ClientObject clobj = (ClientObject)_objmap.get(username);
|
||||
if (clobj == null) {
|
||||
Log.warning("Requested to release unmapped client object " +
|
||||
"[username=" + username + "].");
|
||||
@@ -263,7 +252,7 @@ public class ClientManager
|
||||
Log.debug("Destroying client " + clobj.who() + ".");
|
||||
|
||||
// we're all clear to go; remove the mapping
|
||||
_objmap.remove(key);
|
||||
_objmap.remove(username);
|
||||
|
||||
// and destroy the object itself
|
||||
PresentsServer.omgr.destroyObject(clobj.getOid());
|
||||
@@ -274,7 +263,7 @@ public class ClientManager
|
||||
Connection conn, AuthRequest req, AuthResponse rsp)
|
||||
{
|
||||
Credentials creds = req.getCredentials();
|
||||
String username = creds.getUsername().toLowerCase();
|
||||
Name username = creds.getUsername();
|
||||
|
||||
// see if a client is already registered with these credentials
|
||||
PresentsClient client = getClient(username);
|
||||
@@ -378,12 +367,10 @@ public class ClientManager
|
||||
*/
|
||||
synchronized void clientDidEndSession (PresentsClient client)
|
||||
{
|
||||
Credentials creds = client.getCredentials();
|
||||
String username = client.getUsername();
|
||||
|
||||
// remove the client from the username map
|
||||
Credentials creds = client.getCredentials();
|
||||
PresentsClient rc = (PresentsClient)
|
||||
_usermap.remove(creds.getUsername().toLowerCase());
|
||||
_usermap.remove(creds.getUsername());
|
||||
|
||||
// sanity check just because we can
|
||||
if (rc == null) {
|
||||
@@ -440,7 +427,7 @@ public class ClientManager
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void clientResolved (String username, ClientObject clobj)
|
||||
public void clientResolved (Name username, ClientObject clobj)
|
||||
{
|
||||
try {
|
||||
_clop.apply(clobj);
|
||||
@@ -456,7 +443,7 @@ public class ClientManager
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void resolutionFailed (String username, Exception reason)
|
||||
public void resolutionFailed (Name username, Exception reason)
|
||||
{
|
||||
_clop.resolutionFailed(reason);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
//
|
||||
// $Id: ClientResolutionListener.java,v 1.2 2002/11/29 23:40:01 mdb Exp $
|
||||
// $Id: ClientResolutionListener.java,v 1.3 2004/03/06 11:29:19 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.util.Name;
|
||||
|
||||
/**
|
||||
* Entites that wish to resolve client objects must implement this
|
||||
@@ -15,10 +16,10 @@ public interface ClientResolutionListener
|
||||
/**
|
||||
* Called when resolution completed successfully.
|
||||
*/
|
||||
public void clientResolved (String username, ClientObject clobj);
|
||||
public void clientResolved (Name username, ClientObject clobj);
|
||||
|
||||
/**
|
||||
* Called when resolution fails.
|
||||
*/
|
||||
public void resolutionFailed (String username, Exception reason);
|
||||
public void resolutionFailed (Name username, Exception reason);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
//
|
||||
// $Id: ClientResolver.java,v 1.3 2002/11/26 08:52:53 mdb Exp $
|
||||
// $Id: ClientResolver.java,v 1.4 2004/03/06 11:29:19 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
@@ -27,7 +29,7 @@ public class ClientResolver extends Invoker.Unit
|
||||
*
|
||||
* @param username the username of the user to be resolved.
|
||||
*/
|
||||
public void init (String username)
|
||||
public void init (Name username)
|
||||
{
|
||||
_username = username;
|
||||
}
|
||||
@@ -151,7 +153,7 @@ public class ClientResolver extends Invoker.Unit
|
||||
}
|
||||
|
||||
/** The name of the user whose client object is being resolved. */
|
||||
protected String _username;
|
||||
protected Name _username;
|
||||
|
||||
/** The entities to notify of success or failure. */
|
||||
protected ArrayList _listeners = new ArrayList();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PresentsClient.java,v 1.64 2004/02/22 18:52:33 ray Exp $
|
||||
// $Id: PresentsClient.java,v 1.65 2004/03/06 11:29:19 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Iterator;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.Throttle;
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
@@ -113,7 +114,7 @@ public class PresentsClient
|
||||
/**
|
||||
* Returns the username with which this client instance is associated.
|
||||
*/
|
||||
public String getUsername ()
|
||||
public Name getUsername ()
|
||||
{
|
||||
return _username;
|
||||
}
|
||||
@@ -149,10 +150,10 @@ public class PresentsClient
|
||||
* @param ucl an entity that will (optionally) be notified when the
|
||||
* username conversion process is complete.
|
||||
*/
|
||||
public void setUsername (String username, final UserChangeListener ucl)
|
||||
public void setUsername (Name username, final UserChangeListener ucl)
|
||||
{
|
||||
ClientResolutionListener clr = new ClientResolutionListener() {
|
||||
public void clientResolved (String username, ClientObject clobj) {
|
||||
public void clientResolved (Name username, ClientObject clobj) {
|
||||
// if they old client object is gone by now, they ended
|
||||
// their session while we were switching, so freak out
|
||||
if (_clobj == null) {
|
||||
@@ -195,7 +196,7 @@ public class PresentsClient
|
||||
}
|
||||
}
|
||||
|
||||
public void resolutionFailed (String username, Exception reason) {
|
||||
public void resolutionFailed (Name username, Exception reason) {
|
||||
Log.warning("Unable to resolve new client object " +
|
||||
"[oldname=" + _username + ", newname=" + username +
|
||||
", reason=" + reason + "].");
|
||||
@@ -274,7 +275,7 @@ public class PresentsClient
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void clientResolved (String username, ClientObject clobj)
|
||||
public void clientResolved (Name username, ClientObject clobj)
|
||||
{
|
||||
// we'll be keeping this bad boy
|
||||
_clobj = clobj;
|
||||
@@ -285,7 +286,7 @@ public class PresentsClient
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void resolutionFailed (String username, Exception reason)
|
||||
public void resolutionFailed (Name username, Exception reason)
|
||||
{
|
||||
// urk; nothing to do but complain and get the f**k out of dodge
|
||||
Log.warning("Unable to resolve client [username=" + username + "].");
|
||||
@@ -863,7 +864,7 @@ public class PresentsClient
|
||||
|
||||
protected ClientManager _cmgr;
|
||||
protected Credentials _creds;
|
||||
protected String _username;
|
||||
protected Name _username;
|
||||
protected Connection _conn;
|
||||
protected ClientObject _clobj;
|
||||
protected HashIntMap _subscrips = new HashIntMap();
|
||||
|
||||
Reference in New Issue
Block a user