From 823bafb2f56961cca50658e0f08297ae858d6578 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 19 Jun 2002 23:12:48 +0000 Subject: [PATCH] added ChatValidator interface, so that validators can be registered to veto speak or tell requests. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1494 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/client/ChatDirector.java | 40 ++++++++++++++++++- .../crowd/chat/client/ChatValidator.java | 22 ++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/java/com/threerings/crowd/chat/client/ChatValidator.java diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index 18d9d6822..b8cc39a60 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatDirector.java +++ b/src/java/com/threerings/crowd/chat/client/ChatDirector.java @@ -1,5 +1,5 @@ // -// $Id: ChatDirector.java,v 1.22 2002/05/26 02:24:45 mdb Exp $ +// $Id: ChatDirector.java,v 1.23 2002/06/19 23:12:48 ray Exp $ package com.threerings.crowd.chat; @@ -61,6 +61,24 @@ public class ChatDirector _displays.remove(display); } + /** + * Add the specified chat validator to the list of validators. + * All chat requests will be validated with all validators before + * they may be accepted. + */ + public void addChatValidator (ChatValidator validator) + { + _validators.add(validator); + } + + /** + * Removes the specified chat validator from the list of chat validators. + */ + public void removeChatValidator (ChatValidator validator) + { + _validators.remove(validator); + } + /** * Requests that the specified system message be dispatched to all * registered chat displays. The message will be delivered as if it @@ -115,6 +133,13 @@ public class ChatDirector return -1; } + // make sure they can say what they want to say + for (int ii=0; ii < _validators.size(); ii++) { + if (!((ChatValidator) _validators.get(ii)).validateSpeak(message)) { + return -1; + } + } + // dispatch a speak request on the active place object int reqid = _ctx.getClient().getInvocationDirector().nextInvocationId(); @@ -122,6 +147,9 @@ public class ChatDirector MessageEvent mevt = new MessageEvent( _place.getOid(), SPEAK_REQUEST, args); _ctx.getDObjectManager().postEvent(mevt); + // TODO: when this gets changed such that we actually validate + // this on the server, we have to make sure that the + // user is not on a portal before we allow the 'shout' to go through return reqid; } @@ -139,6 +167,13 @@ public class ChatDirector */ public int requestTell (String target, String message) { + // make sure they can say what they want to say + for (int ii=0; ii < _validators.size(); ii++) { + if (!((ChatValidator) _validators.get(ii)).validateTell(target, + message)) { + return -1; + } + } return ChatService.tell(_ctx.getClient(), target, message, this); } @@ -328,6 +363,9 @@ public class ChatDirector /** A list of registered chat displays. */ protected ArrayList _displays = new ArrayList(); + /** A list of registered chat validators. */ + protected ArrayList _validators = new ArrayList(); + /** A mapping from auxiliary chat objects to the types under which * they are registered. */ protected HashIntMap _auxes = new HashIntMap(); diff --git a/src/java/com/threerings/crowd/chat/client/ChatValidator.java b/src/java/com/threerings/crowd/chat/client/ChatValidator.java new file mode 100644 index 000000000..d6e2d93c0 --- /dev/null +++ b/src/java/com/threerings/crowd/chat/client/ChatValidator.java @@ -0,0 +1,22 @@ +// +// $Id: ChatValidator.java,v 1.1 2002/06/19 23:12:48 ray Exp $ + +package com.threerings.crowd.chat; + +/** + * A chat validator validates chat messages before they are sent to the + * server. By default, each method returns true, it is assumed that + * validators will be added that override at least one of the methods. + */ +public interface ChatValidator +{ + /** + * Validate that the specified speak message may be sent. + */ + public boolean validateSpeak (String msg); + + /** + * Validate that the specified tell message may be sent. + */ + public boolean validateTell (String target, String msg); +}