diff --git a/src/as/com/threerings/crowd/chat/client/ChatDirector.as b/src/as/com/threerings/crowd/chat/client/ChatDirector.as
index 591c231a1..35a79ec9a 100644
--- a/src/as/com/threerings/crowd/chat/client/ChatDirector.as
+++ b/src/as/com/threerings/crowd/chat/client/ChatDirector.as
@@ -82,7 +82,7 @@ import com.threerings.crowd.chat.data.UserSystemMessage;
* messaging.
*/
public class ChatDirector extends BasicDirector
- implements ChatCodes, LocationObserver, MessageListener
+ implements LocationObserver, MessageListener
{
/**
* Creates a chat director and initializes it with the supplied
@@ -94,7 +94,8 @@ public class ChatDirector extends BasicDirector
* @param bundle the message bundle from which we obtain our
* chat-related translation strings.
*/
- public ChatDirector (CrowdContext ctx, MessageManager msgmgr, String bundle)
+ public function ChatDirector (
+ ctx :CrowdContext, msgmgr :MessageManager, bundle :String)
{
super(ctx);
@@ -111,7 +112,7 @@ public class ChatDirector extends BasicDirector
Log.warning("Null bundle or message manager given to ChatDirector");
return;
}
- MessageBundle msg = _msgmgr.getBundle(_bundle);
+ var msg :MessageBundle = _msgmgr.getBundle(_bundle);
registerCommandHandler(msg, "help", new HelpHandler());
registerCommandHandler(msg, "clear", new ClearHandler());
registerCommandHandler(msg, "speak", new SpeakHandler());
@@ -728,7 +729,7 @@ public class ChatDirector extends BasicDirector
* @return {@link ChatCodes#SUCCESS} if the message was delivered or a
* string indicating why it failed.
*/
- protected String deliverChat (
+ internal String deliverChat (
SpeakService speakSvc, String message, byte mode)
{
// run the message through our mogrification process
@@ -1044,114 +1045,6 @@ public class ChatDirector extends BasicDirector
protected ChatMessage _message;
}
- /** Implements /help. */
- protected class HelpHandler extends CommandHandler
- {
- public String handleCommand (
- SpeakService speakSvc, String command, String args, String[] history)
- {
- String hcmd = "";
-
- // grab the command they want help on
- if (!StringUtil.isBlank(args)) {
- hcmd = args;
- int sidx = args.indexOf(" ");
- if (sidx != -1) {
- hcmd = args.substring(0, sidx);
- }
- }
-
- // let the user give commands with or with the /
- if (hcmd.startsWith("/")) {
- hcmd = hcmd.substring(1);
- }
-
- // handle "/help help" and "/help someboguscommand"
- HashMap possibleCommands = getCommandHandlers(hcmd);
- if (hcmd.equals("help") || possibleCommands.isEmpty()) {
- possibleCommands = getCommandHandlers("");
- possibleCommands.remove("help"); // remove help from the list
- }
-
- // if there is only one possible command display its usage
- switch (possibleCommands.size()) {
- case 1:
- Iterator itr = possibleCommands.keySet().iterator();
- // this is a little funny, but we display the feeback
- // message by hand and return SUCCESS so that the chat
- // entry field doesn't think that we've failed and
- // preserve our command text
- displayFeedback(null, "m.usage_" + (String)itr.next());
- return ChatCodes.SUCCESS;
-
- default:
- Object[] commands = possibleCommands.keySet().toArray();
- Arrays.sort(commands);
- String commandList = "";
- for (int ii = 0; ii < commands.length; ii++) {
- commandList += " /" + commands[ii];
- }
- return MessageBundle.tcompose("m.usage_help", commandList);
- }
- }
- }
-
- /** Implements /clear. */
- protected class ClearHandler extends CommandHandler
- {
- public String handleCommand (
- SpeakService speakSvc, String command, String args, String[] history)
- {
- clearDisplays();
- return ChatCodes.SUCCESS;
- }
- }
-
- /** Implements /speak. */
- protected class SpeakHandler extends CommandHandler
- {
- public String handleCommand (
- SpeakService speakSvc, String command, String args, String[] history)
- {
- if (StringUtil.isBlank(args)) {
- return "m.usage_speak";
- }
- // note the command to be stored in the history
- history[0] = command + " ";
- return requestChat(null, args, true);
- }
- }
-
- /** Implements /emote. */
- protected class EmoteHandler extends CommandHandler
- {
- public String handleCommand (
- SpeakService speakSvc, String command, String args, String[] history)
- {
- if (StringUtil.isBlank(args)) {
- return "m.usage_emote";
- }
- // note the command to be stored in the history
- history[0] = command + " ";
- return deliverChat(speakSvc, args, ChatCodes.EMOTE_MODE);
- }
- }
-
- /** Implements /think. */
- protected class ThinkHandler extends CommandHandler
- {
- public String handleCommand (
- SpeakService speakSvc, String command, String args, String[] history)
- {
- if (StringUtil.isBlank(args)) {
- return "m.usage_think";
- }
- // note the command to be stored in the history
- history[0] = command + " ";
- return deliverChat(speakSvc, args, ChatCodes.THINK_MODE);
- }
- }
-
/** Our active chat context. */
protected CrowdContext _ctx;
diff --git a/src/as/com/threerings/crowd/chat/client/ClearHandler.as b/src/as/com/threerings/crowd/chat/client/ClearHandler.as
new file mode 100644
index 000000000..466c38ae1
--- /dev/null
+++ b/src/as/com/threerings/crowd/chat/client/ClearHandler.as
@@ -0,0 +1,21 @@
+package com.threerings.crowd.chat.client {
+
+public class ClearHandler extends CommandHandler
+{
+ public function ClearHandler (chatdir :ChatDirector)
+ {
+ _chatdir = chatdir;
+ }
+
+ public override function handleCommand (
+ speakSvc :SpeakService, cmd :String, args :String, history :Array)
+ :String
+ {
+ _chatdir.clearDisplays();
+ return ChatCodes.SUCCESS;
+ }
+
+ /** Our ChatDirector. */
+ protected var _chatdir :ChatDirector;
+}
+}
diff --git a/src/as/com/threerings/crowd/chat/client/CommandHandler.as b/src/as/com/threerings/crowd/chat/client/CommandHandler.as
index 7d9f06299..3b963dd40 100644
--- a/src/as/com/threerings/crowd/chat/client/CommandHandler.as
+++ b/src/as/com/threerings/crowd/chat/client/CommandHandler.as
@@ -27,7 +27,7 @@ public /* abstract */ class CommandHandler
*/
public function handleCommand (
speakSvc :SpeakService, cmd :String, args :String, history :Array)
- :void
+ :String
{
throw new Error("abstract");
}
diff --git a/src/as/com/threerings/crowd/chat/client/EmoteHandler.as b/src/as/com/threerings/crowd/chat/client/EmoteHandler.as
new file mode 100644
index 000000000..c1da3d775
--- /dev/null
+++ b/src/as/com/threerings/crowd/chat/client/EmoteHandler.as
@@ -0,0 +1,28 @@
+package com.threerings.crowd.chat.client {
+
+import com.threerings.util.StringUtil;
+
+import com.threerings.crowd.chat.data.ChatCodes;
+
+public class EmoteHandler extends CommandHandler
+{
+ public function EmoteHandler (chatdir :ChatDirector)
+ {
+ _chatdir = chatdir;
+ }
+
+ public override function handleCommand (
+ speakSvc :SpeakService, cmd :String, args :String, history :Array)
+ :String
+ {
+ if (StringUtil.isBlank(args)) {
+ return "m.usage_emote";
+ }
+ history[0] = cmd + " ";
+ return _chatdir.deliverChat(speakSvc, args, ChatCodes.EMOTE_MODE);
+ }
+
+ /** Our ChatDirector. */
+ protected var _chatdir :ChatDirector;
+}
+}
diff --git a/src/as/com/threerings/crowd/chat/client/HelpHandler.as b/src/as/com/threerings/crowd/chat/client/HelpHandler.as
new file mode 100644
index 000000000..27c33e4ad
--- /dev/null
+++ b/src/as/com/threerings/crowd/chat/client/HelpHandler.as
@@ -0,0 +1,61 @@
+package com.threerings.crowd.chat.client {
+
+import com.threerings.util.MessageBundle;
+import com.threerings.util.StringUtil;
+
+import com.threerings.crowd.chat.data.ChatCodes;
+
+public class HelpHandler extends CommandHandler
+{
+ public function HelpHandler (chatdir :ChatDirector)
+ {
+ _chatdir = chatdir;
+ }
+
+ public override function handleCommand (
+ speakSvc :SpeakService, cmd :String, args :String, history :Array)
+ :String
+ {
+ var hcmd :String = "";
+
+ // grab the command they want help on
+ if (!StringUtil.isBlank(args)) {
+ hcmd = args;
+ var sidx :int = args.indexOf(" ");
+ if (sidx != -1) {
+ hcmd = args.substring(0, sidx);
+ }
+ }
+
+ // let the user give commands with or without the /
+ if (hcmd.charAt(0) == "/") {
+ hcmd = hcm.substring(1);
+ }
+
+ // handle "/help help" and "/help boguscmd"
+ var possibleCmds :SimpleMap = _chatdir.getCommandHandlers(hcmd);
+ if ((hcmd === "help") || (possibleCmds.size() == 0)) {
+ possibleCmds = _chatdir.getCommandHandlers("");
+ possibleCmds.remove("help"); // remove help from the list
+ }
+
+ switch (possibleCmds.size()) {
+ case 1:
+ _chatdir.displayFeedback(null, "m.usage_" + possibleCmds.keys()[0]);
+ return ChatCodes.SUCCESS;
+
+ default:
+ var cmds :Array = possibleCmds.keys();
+ cmds.sort();
+ var cmdList :String = "";
+ for (var skey :String in cmds) {
+ cmdList += " /" + skey;
+ }
+ return MessageBundle.tcompose("m.usage_help", cmdList);
+ }
+ }
+
+ /** Our ChatDirector. */
+ protected var _chatdir :ChatDirector;
+}
+}
diff --git a/src/as/com/threerings/crowd/chat/client/SpeakHandler.as b/src/as/com/threerings/crowd/chat/client/SpeakHandler.as
new file mode 100644
index 000000000..cc2ffcfc1
--- /dev/null
+++ b/src/as/com/threerings/crowd/chat/client/SpeakHandler.as
@@ -0,0 +1,28 @@
+package com.threerings.crowd.chat.client {
+
+import com.threerings.util.StringUtil;
+
+import com.threerings.crowd.chat.data.ChatCodes;
+
+public class SpeakHandler extends CommandHandler
+{
+ public function SpeakHandler (chatdir :ChatDirector)
+ {
+ _chatdir = chatdir;
+ }
+
+ public override function handleCommand (
+ speakSvc :SpeakService, cmd :String, args :String, history :Array)
+ :String
+ {
+ if (StringUtil.isBlank(args)) {
+ return "m.usage_speak";
+ }
+ history[0] = cmd + " ";
+ return _chatdir.requestChat(null, args, true);
+ }
+
+ /** Our ChatDirector. */
+ protected var _chatdir :ChatDirector;
+}
+}
diff --git a/src/as/com/threerings/crowd/chat/client/ThinkHandler.as b/src/as/com/threerings/crowd/chat/client/ThinkHandler.as
new file mode 100644
index 000000000..181103744
--- /dev/null
+++ b/src/as/com/threerings/crowd/chat/client/ThinkHandler.as
@@ -0,0 +1,28 @@
+package com.threerings.crowd.chat.client {
+
+import com.threerings.util.StringUtil;
+
+import com.threerings.crowd.chat.data.ChatCodes;
+
+public class ThinkHandler extends CommandHandler
+{
+ public function ThinkHandler (chatdir :ChatDirector)
+ {
+ _chatdir = chatdir;
+ }
+
+ public override function handleCommand (
+ speakSvc :SpeakService, cmd :String, args :String, history :Array)
+ :String
+ {
+ if (StringUtil.isBlank(args)) {
+ return "m.usage_think";
+ }
+ history[0] = cmd + " ";
+ return _chatdir.deliverChat(speakSvc, args, ChatCodes.THINK_MODE);
+ }
+
+ /** Our ChatDirector. */
+ protected var _chatdir :ChatDirector;
+}
+}
diff --git a/src/as/com/threerings/crowd/client/LocationObserver.as b/src/as/com/threerings/crowd/client/LocationObserver.as
new file mode 100644
index 000000000..680b2d8c6
--- /dev/null
+++ b/src/as/com/threerings/crowd/client/LocationObserver.as
@@ -0,0 +1,68 @@
+//
+// $Id: LocationObserver.java 3098 2004-08-27 02:12:55Z mdb $
+//
+// Narya library - tools for developing networked games
+// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
+// http://www.threerings.net/code/narya/
+//
+// This library is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as published
+// by the Free Software Foundation; either version 2.1 of the License, or
+// (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+package com.threerings.crowd.client {
+
+import com.threerings.crowd.data.PlaceObject;
+
+/**
+ * The location observer interface makes it possible for entities to be
+ * notified when the client moves to a new location. It also provides a
+ * means for an entity to participate in the ratification process of a new
+ * location. Observers may opt to reject a request to change to a new
+ * location, probably because something is going on in the previous
+ * location that should not be abandoned.
+ *
+ *
Note that these location callbacks occur on the main thread and + * should execute quickly and not block under any circumstance. + */ +public interface LocationObserver +{ + /** + * Called when someone has requested that we switch to a new location. + * An observer may choose to veto the location change request for some + * reason or other. + * + * @return true if it's OK for the location to change, false if the + * change request should be aborted. + */ + function locationMayChange (placeId :int) :Boolean; + + /** + * Called when we have switched to a new location. + * + * @param place the place object that represents the new location or + * null if we have switched to no location. + */ + function locationDidChange (place :PlaceObject) :void; + + /** + * This is called on all location observers when a location change + * request is rejected by the server or fails for some other reason. + * + * @param placeId the place id to which we attempted to relocate, but + * failed. + * @param reason the reason code that explains why the location change + * request was rejected or otherwise failed. + */ + function locationChangeFailed (placeId :int, reason :String) :void; +} +} diff --git a/src/as/com/threerings/presents/data/InvocationCodes.as b/src/as/com/threerings/presents/data/InvocationCodes.as new file mode 100644 index 000000000..86eb15604 --- /dev/null +++ b/src/as/com/threerings/presents/data/InvocationCodes.as @@ -0,0 +1,50 @@ +// +// $Id: InvocationCodes.java 3099 2004-08-27 02:21:06Z mdb $ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.presents.data { + +/** + * The invocation codes interface provides codes that are commonly used by + * invocation service implementations. It is implemented as an interface + * so that were an invocation service to desire to build on two or more + * other services, it can provide a codes interface that inherits from all + * of the services that it extends. + */ +public class InvocationCodes +{ + /** + * Generally used in responses that can either have the value success, + * or a string code explaining the reason for failure. + */ + public static const SUCCESS :String = "success"; + + /** An error code returned to clients when a service cannot be + * performed because of some internal server error that we couldn't + * explain in any meaningful way (things like null pointer + * exceptions). */ + public static const INTERNAL_ERROR :String = "m.internal_error"; + + /** An error code returned to clients when a service cannot be + * performed because the requesting client does not have the proper + * access. */ + public static const ACCESS_DENIED :String = "m.access_denied"; +} +} diff --git a/src/as/com/threerings/util/SimpleMap.as b/src/as/com/threerings/util/SimpleMap.as index 407328d50..bd3ea5d3b 100644 --- a/src/as/com/threerings/util/SimpleMap.as +++ b/src/as/com/threerings/util/SimpleMap.as @@ -29,9 +29,12 @@ public class SimpleMap extends Object public function put (key :Object, value :Object) :Object { var skey :String = key.toString(); - var oldValue :Object = _data[skey]; + var oldValue :* = _data[skey]; _data[skey] = value; - return oldValue; + if (oldValue === undefined) { + _size++; + } + return (oldValue as Object); } public function remove (key :Object) :Object @@ -39,9 +42,17 @@ public class SimpleMap extends Object var skey :String = key.toString(); var value :Object = _data[skey]; delete _data[skey]; + _size--; return value; } - private var _data :Object = new Object(); + public function size () :int + { + return _size; + } + + protected var _data :Object = new Object(); + + protected var _size :int = 0; } } diff --git a/src/as/com/threerings/util/StringUtil.as b/src/as/com/threerings/util/StringUtil.as new file mode 100644 index 000000000..44beef563 --- /dev/null +++ b/src/as/com/threerings/util/StringUtil.as @@ -0,0 +1,10 @@ +package com.threerings.util { + +public class StringUtil +{ + public static function isBlank (str :String) :Boolean + { + return (str == null) || (str.search("\\S") == -1); + } +} +}