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:
Michael Bayne
2004-03-06 11:29:19 +00:00
parent 92b716d790
commit 32dee3cbaf
58 changed files with 335 additions and 286 deletions
@@ -1,5 +1,5 @@
//
// $Id: ChatDirector.java,v 1.57 2004/02/25 14:41:47 mdb Exp $
// $Id: ChatDirector.java,v 1.58 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.client;
@@ -20,6 +20,7 @@ import com.threerings.presents.dobj.MessageListener;
import com.threerings.util.MessageBundle;
import com.threerings.util.MessageManager;
import com.threerings.util.Name;
import com.threerings.util.TimeUtil;
import com.threerings.crowd.Log;
@@ -63,7 +64,7 @@ public class ChatDirector extends BasicDirector
/**
* Returns whether the username may be added to the chatters list.
*/
public boolean isChatterValid (String username);
public boolean isChatterValid (Name username);
}
/**
@@ -152,7 +153,7 @@ public class ChatDirector extends BasicDirector
/**
* Adds a chatter to our list of recent chatters.
*/
protected void addChatter (String name)
protected void addChatter (Name name)
{
// check to see if the chatter validator approves..
if ((_chatterValidator != null) &&
@@ -351,8 +352,8 @@ public class ChatDirector extends BasicDirector
* @param rl an optional result listener if you'd like to be notified
* of success or failure.
*/
public void requestTell (
final String target, String msg, final ResultListener rl)
public void requestTell (final Name target, String msg,
final ResultListener rl)
{
// make sure they can say what they want to say
final String message = filter(msg, target, true);
@@ -502,13 +503,13 @@ public class ChatDirector extends BasicDirector
// if the message came from a user, make sure we want to hear it
if (msg instanceof UserMessage) {
UserMessage umsg = (UserMessage)msg;
String speaker = umsg.speaker;
message = filter(message, speaker, false);
if (message == null) {
Name speaker = umsg.speaker;
if ((message = filter(message, speaker, false)) == null) {
return;
}
} else if (USER_CHAT_TYPE.equals(localtype) &&
umsg.mode == ChatCodes.DEFAULT_MODE) {
if (USER_CHAT_TYPE.equals(localtype) &&
umsg.mode == ChatCodes.DEFAULT_MODE) {
// if it was a tell, add the speaker as a chatter
addChatter(speaker);
@@ -529,7 +530,7 @@ public class ChatDirector extends BasicDirector
// if we auto-responded, report as much
if (autoResponse != null) {
String teller = ((UserMessage) msg).speaker;
Name teller = ((UserMessage) msg).speaker;
String amsg = MessageBundle.tcompose(
"m.auto_responded", teller, autoResponse);
displayFeedback(_bundle, amsg);
@@ -630,7 +631,7 @@ public class ChatDirector extends BasicDirector
/**
* Run a message through all the currently registered filters.
*/
public String filter (String msg, String otherUser, boolean outgoing)
public String filter (String msg, Name otherUser, boolean outgoing)
{
_filterMessageOp.setMessage(msg, otherUser, outgoing);
_filters.apply(_filterMessageOp);
@@ -643,7 +644,7 @@ public class ChatDirector extends BasicDirector
*/
protected static class FilterMessageOp implements ObserverList.ObserverOp
{
public void setMessage (String msg, String otherUser, boolean outgoing)
public void setMessage (String msg, Name otherUser, boolean outgoing)
{
_msg = msg;
_otherUser = otherUser;
@@ -663,7 +664,7 @@ public class ChatDirector extends BasicDirector
return _msg;
}
protected String _otherUser;
protected Name _otherUser;
protected String _msg;
protected boolean _out;
}
@@ -1,8 +1,10 @@
//
// $Id: ChatFilter.java,v 1.1 2003/09/15 21:11:40 ray Exp $
// $Id: ChatFilter.java,v 1.2 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.client;
import com.threerings.util.Name;
/**
* Filters messages chat messages to or from the server.
*/
@@ -18,5 +20,5 @@ public interface ChatFilter
*
* @return the filtered message, or null to block it completely.
*/
public String filter (String msg, String otherUser, boolean outgoing);
public String filter (String msg, Name otherUser, boolean outgoing);
}
@@ -1,8 +1,10 @@
//
// $Id: ChatService.java,v 1.12 2003/09/18 17:53:48 mdb Exp $
// $Id: ChatService.java,v 1.13 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.client;
import com.threerings.util.Name;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
@@ -41,7 +43,7 @@ public interface ChatService extends InvocationService
* @param message the contents of the message.
* @param listener the reference that will receive the tell response.
*/
public void tell (Client client, String target, String message,
public void tell (Client client, Name target, String message,
TellListener listener);
/**
@@ -1,5 +1,5 @@
//
// $Id: MuteDirector.java,v 1.10 2003/09/15 21:11:40 ray Exp $
// $Id: MuteDirector.java,v 1.11 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.client;
@@ -8,6 +8,7 @@ import java.util.HashSet;
import com.samskivert.util.ObserverList;
import com.threerings.util.MessageBundle;
import com.threerings.util.Name;
import com.threerings.crowd.util.CrowdContext;
@@ -31,7 +32,7 @@ public class MuteDirector extends BasicDirector
/**
* The specified player was added or removed from the mutelist.
*/
public void muteChanged (String playername, boolean nowMuted);
public void muteChanged (Name playername, boolean nowMuted);
}
/**
@@ -45,7 +46,7 @@ public class MuteDirector extends BasicDirector
/**
* Set up the mute director with the specified list of initial mutees.
*/
public MuteDirector (CrowdContext ctx, String[] list)
public MuteDirector (CrowdContext ctx, Name[] list)
{
this(ctx);
@@ -84,7 +85,7 @@ public class MuteDirector extends BasicDirector
/**
* Check to see if the specified user is muted.
*/
public boolean isMuted (String username)
public boolean isMuted (Name username)
{
return _mutelist.contains(username);
}
@@ -92,7 +93,7 @@ public class MuteDirector extends BasicDirector
/**
* Mute or unmute the specified user.
*/
public void setMuted (String username, boolean mute)
public void setMuted (Name username, boolean mute)
{
if (mute ? _mutelist.add(username) : _mutelist.remove(username)) {
_chatdir.displayFeedback(null, MessageBundle.tcompose(
@@ -107,13 +108,13 @@ public class MuteDirector extends BasicDirector
* This list may be out of date immediately upon returning from this
* method.
*/
public String[] getMuted ()
public Name[] getMuted ()
{
return (String[]) _mutelist.toArray(new String[_mutelist.size()]);
return (Name[]) _mutelist.toArray(new Name[_mutelist.size()]);
}
// documentation inherited from interface ChatFilter
public String filter (String msg, String otherUser, boolean outgoing)
public String filter (String msg, Name otherUser, boolean outgoing)
{
// we are only concerned with filtering things going to or coming
// from muted users
@@ -132,7 +133,7 @@ public class MuteDirector extends BasicDirector
/**
* Notify our observers of a change in the mutelist.
*/
protected void notifyObservers (final String username, final boolean muted)
protected void notifyObservers (final Name username, final boolean muted)
{
_observers.apply(new ObserverList.ObserverOp() {
public boolean apply (Object observer) {
@@ -1,12 +1,15 @@
//
// $Id: ChatMarshaller.java,v 1.7 2004/02/25 14:41:47 mdb Exp $
// $Id: ChatMarshaller.java,v 1.8 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.data;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.client.ChatService.TellListener;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService.InvocationListener;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent;
import com.threerings.util.Name;
/**
* Provides the implementation of the {@link ChatService} interface
@@ -53,7 +56,7 @@ public class ChatMarshaller extends InvocationMarshaller
public static final int TELL = 1;
// documentation inherited from interface
public void tell (Client arg1, String arg2, String arg3, TellListener arg4)
public void tell (Client arg1, Name arg2, String arg3, TellListener arg4)
{
TellMarshaller listener4 = new TellMarshaller();
listener4.listener = arg4;
@@ -1,8 +1,10 @@
//
// $Id: SpeakObject.java,v 1.2 2003/06/14 00:59:24 mdb Exp $
// $Id: SpeakObject.java,v 1.3 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.data;
import com.threerings.util.Name;
/**
* Provides a mechanism by which the speak service can identify chat
* listeners so as to maintain a recent history of all chat traffic on the
@@ -17,7 +19,7 @@ public interface SpeakObject
public void apply (int bodyOid);
/** Call this method if you can provide usernames directly. */
public void apply (String username);
public void apply (Name username);
}
/**
@@ -1,15 +1,17 @@
//
// $Id: UserMessage.java,v 1.2 2003/06/03 21:41:33 ray Exp $
// $Id: UserMessage.java,v 1.3 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.data;
import com.threerings.util.Name;
/**
* A ChatMessage representing a message that came from another user.
*/
public class UserMessage extends ChatMessage
{
/** The user that the message came from. */
public String speaker;
public Name speaker;
/** The mode of the message. @see ChatCodes.DEFAULT_MODE */
public byte mode;
@@ -24,8 +26,7 @@ public class UserMessage extends ChatMessage
/**
* Construct a user message.
*/
public UserMessage (String message, String bundle,
String speaker, byte mode)
public UserMessage (String message, String bundle, Name speaker, byte mode)
{
super(message, bundle);
this.speaker = speaker;
@@ -1,15 +1,18 @@
//
// $Id: ChatDispatcher.java,v 1.7 2004/02/25 14:41:47 mdb Exp $
// $Id: ChatDispatcher.java,v 1.8 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.server;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.client.ChatService.TellListener;
import com.threerings.crowd.chat.data.ChatMarshaller;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService.InvocationListener;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
import com.threerings.util.Name;
/**
* Dispatches requests to the {@link ChatProvider}.
@@ -40,7 +43,7 @@ public class ChatDispatcher extends InvocationDispatcher
case ChatMarshaller.TELL:
((ChatProvider)provider).tell(
source,
(String)args[0], (String)args[1], (TellListener)args[2]
(Name)args[0], (String)args[1], (TellListener)args[2]
);
return;
@@ -1,5 +1,5 @@
//
// $Id: ChatProvider.java,v 1.26 2004/02/25 14:41:47 mdb Exp $
// $Id: ChatProvider.java,v 1.27 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.server;
@@ -7,6 +7,7 @@ import java.util.Iterator;
import com.samskivert.util.StringUtil;
import com.threerings.util.MessageBundle;
import com.threerings.util.Name;
import com.threerings.util.TimeUtil;
import com.threerings.presents.client.InvocationService.InvocationListener;
@@ -84,7 +85,7 @@ public class ChatProvider
* Processes a request from a client to deliver a tell message to
* another client.
*/
public void tell (ClientObject caller, String target, String message,
public void tell (ClientObject caller, Name target, String message,
TellListener listener)
throws InvocationException
{
@@ -177,7 +178,7 @@ public class ChatProvider
* @param message the text of the chat message.
*/
public static void sendTellMessage (
BodyObject target, String speaker, String bundle, String message)
BodyObject target, Name speaker, String bundle, String message)
{
UserMessage msg =
new UserMessage(message, bundle, speaker, DEFAULT_MODE);
@@ -1,5 +1,5 @@
//
// $Id: SpeakProvider.java,v 1.19 2004/02/25 14:41:47 mdb Exp $
// $Id: SpeakProvider.java,v 1.20 2004/03/06 11:29:18 mdb Exp $
package com.threerings.crowd.chat.server;
@@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import com.samskivert.util.ObserverList;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.DObject;
@@ -55,7 +56,7 @@ public class SpeakProvider
/**
* Called for each player that hears a particular chat message.
*/
public void messageDelivered (String hearer, UserMessage message);
public void messageDelivered (Name hearer, UserMessage message);
}
/**
@@ -144,7 +145,7 @@ public class SpeakProvider
* "faking" a chat message.
* @param message the text of the speak message.
*/
public static void sendSpeak (DObject speakObj, String speaker,
public static void sendSpeak (DObject speakObj, Name speaker,
String bundle, String message)
{
sendSpeak(speakObj, speaker, bundle, message, ChatCodes.DEFAULT_MODE);
@@ -167,7 +168,7 @@ public class SpeakProvider
* @param mode the mode of the message, see {@link
* ChatCodes#DEFAULT_MODE}.
*/
public static void sendSpeak (DObject speakObj, String speaker,
public static void sendSpeak (DObject speakObj, Name speaker,
String bundle, String message, byte mode)
{
sendMessage(speakObj, new UserMessage(message, bundle, speaker, mode));
@@ -277,7 +278,7 @@ public class SpeakProvider
* Returns a list of {@link ChatMessage} objects to which this user
* has been privy in the recent past.
*/
public static ArrayList getChatHistory (String username)
public static ArrayList getChatHistory (Name username)
{
HistoryList history = getHistoryList(username);
pruneHistory(System.currentTimeMillis(), history);
@@ -287,7 +288,7 @@ public class SpeakProvider
/**
* Called to clear the chat history for the specified user.
*/
public static void clearHistory (String username)
public static void clearHistory (Name username)
{
// Log.info("Clearing history for " + username + ".");
_histories.remove(username);
@@ -298,7 +299,7 @@ public class SpeakProvider
* message. If {@link ChatMessage#timestamp} is not already filled in,
* it will be.
*/
protected static void noteMessage (String username, UserMessage msg)
protected static void noteMessage (Name username, UserMessage msg)
{
// fill in the message's time stamp if necessary
if (msg.timestamp == 0L) {
@@ -325,7 +326,7 @@ public class SpeakProvider
/**
* Returns this user's chat history, creating one if necessary.
*/
protected static HistoryList getHistoryList (String username)
protected static HistoryList getHistoryList (Name username)
{
HistoryList history = (HistoryList)_histories.get(username);
if (history == null) {
@@ -361,7 +362,7 @@ public class SpeakProvider
}
}
public void apply (String username) {
public void apply (Name username) {
noteMessage(username, message);
}
}
@@ -378,7 +379,7 @@ public class SpeakProvider
/** Used to notify our {@link MessageObserver}s. */
protected static class MessageObserverOp implements ObserverList.ObserverOp
{
public void init (String hearer, UserMessage message) {
public void init (Name hearer, UserMessage message) {
_hearer = hearer;
_message = message;
}
@@ -388,7 +389,7 @@ public class SpeakProvider
return true;
}
protected String _hearer;
protected Name _hearer;
protected UserMessage _message;
}
@@ -1,5 +1,5 @@
//
// $Id: OccupantDirector.java,v 1.6 2002/10/27 23:30:56 shaper Exp $
// $Id: OccupantDirector.java,v 1.7 2004/03/06 11:29:19 mdb Exp $
package com.threerings.crowd.client;
@@ -7,6 +7,7 @@ import java.util.Iterator;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.ObserverList;
import com.threerings.util.Name;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client;
@@ -88,7 +89,7 @@ public class OccupantDirector extends BasicDirector
* the currently occupied place. Returns null if no occupant info
* exists with the specified username.
*/
public OccupantInfo getOccupantInfo (String username)
public OccupantInfo getOccupantInfo (Name username)
{
// make sure we're somewhere
if (_place == null) {
@@ -1,8 +1,10 @@
//
// $Id: BodyObject.dobj,v 1.13 2003/09/18 17:53:48 mdb Exp $
// $Id: BodyObject.dobj,v 1.14 2004/03/06 11:29:19 mdb Exp $
package com.threerings.crowd.data;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.crowd.chat.data.SpeakObject;
@@ -16,7 +18,7 @@ public class BodyObject extends ClientObject
/**
* The username associated with this body object.
*/
public String username;
public Name username;
/**
* The oid of the place currently occupied by this body or -1 if they
@@ -50,7 +52,7 @@ public class BodyObject extends ClientObject
// documentation inherited
public String who ()
{
StringBuffer buf = new StringBuffer(username);
StringBuffer buf = new StringBuffer(username.toString());
buf.append(" (").append(getOid());
if (status != OccupantInfo.ACTIVE) {
buf.append(" ").append(OccupantInfo.X_STATUS[status]);
@@ -1,8 +1,10 @@
//
// $Id: BodyObject.java,v 1.8 2003/09/18 17:53:48 mdb Exp $
// $Id: BodyObject.java,v 1.9 2004/03/06 11:29:19 mdb Exp $
package com.threerings.crowd.data;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.crowd.chat.data.SpeakObject;
@@ -28,7 +30,7 @@ public class BodyObject extends ClientObject
/**
* The username associated with this body object.
*/
public String username;
public Name username;
/**
* The oid of the place currently occupied by this body or -1 if they
@@ -62,7 +64,7 @@ public class BodyObject extends ClientObject
// documentation inherited
public String who ()
{
StringBuffer buf = new StringBuffer(username);
StringBuffer buf = new StringBuffer(username.toString());
buf.append(" (").append(getOid());
if (status != OccupantInfo.ACTIVE) {
buf.append(" ").append(OccupantInfo.X_STATUS[status]);
@@ -78,7 +80,7 @@ public class BodyObject extends ClientObject
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public void setUsername (String username)
public void setUsername (Name username)
{
requestAttributeChange(USERNAME, username);
this.username = username;
@@ -1,9 +1,11 @@
//
// $Id: OccupantInfo.java,v 1.11 2002/10/30 00:42:37 mdb Exp $
// $Id: OccupantInfo.java,v 1.12 2004/03/06 11:29:19 mdb Exp $
package com.threerings.crowd.data;
import com.threerings.io.SimpleStreamableObject;
import com.threerings.util.Name;
import com.threerings.presents.dobj.DSet;
/**
@@ -43,7 +45,7 @@ public class OccupantInfo extends SimpleStreamableObject
public Integer bodyOid;
/** The username of this occupant. */
public String username;
public Name username;
/** The status of this occupant. */
public byte status = ACTIVE;
@@ -1,10 +1,12 @@
//
// $Id: PlaceObject.dobj,v 1.16 2003/07/11 00:47:33 mdb Exp $
// $Id: PlaceObject.dobj,v 1.17 2004/03/06 11:29:19 mdb Exp $
package com.threerings.crowd.data;
import java.util.Iterator;
import com.threerings.util.Name;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
import com.threerings.presents.dobj.OidList;
@@ -59,7 +61,7 @@ public class PlaceObject extends DObject
* @return the occupant info record for the named user or null if no
* user in the room has that username.
*/
public OccupantInfo getOccupantInfo (String username)
public OccupantInfo getOccupantInfo (Name username)
{
try {
Iterator iter = occupantInfo.entries();
@@ -1,10 +1,12 @@
//
// $Id: PlaceObject.java,v 1.15 2003/07/11 00:47:33 mdb Exp $
// $Id: PlaceObject.java,v 1.16 2004/03/06 11:29:19 mdb Exp $
package com.threerings.crowd.data;
import java.util.Iterator;
import com.threerings.util.Name;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
import com.threerings.presents.dobj.OidList;
@@ -68,7 +70,7 @@ public class PlaceObject extends DObject
* @return the occupant info record for the named user or null if no
* user in the room has that username.
*/
public OccupantInfo getOccupantInfo (String username)
public OccupantInfo getOccupantInfo (Name username)
{
try {
Iterator iter = occupantInfo.entries();
@@ -1,10 +1,12 @@
//
// $Id: CrowdServer.java,v 1.18 2003/06/03 21:41:33 ray Exp $
// $Id: CrowdServer.java,v 1.19 2004/03/06 11:29:19 mdb Exp $
package com.threerings.crowd.server;
import java.util.Iterator;
import com.threerings.util.Name;
import com.threerings.presents.server.PresentsServer;
import com.threerings.crowd.Log;
@@ -86,7 +88,7 @@ public class CrowdServer extends PresentsServer
* active users on the server. This should only be called from the
* dobjmgr thread.
*/
public static BodyObject lookupBody (String username)
public static BodyObject lookupBody (Name username)
{
return (BodyObject)clmgr.getClientObject(username);
}