Started work on the 'crowd' package.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3935 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// $Id: ChatDisplay.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.chat.client {
|
||||
|
||||
import com.threerings.crowd.chat.data.ChatMessage;
|
||||
|
||||
/**
|
||||
* A chat display provides a means by which chat messages can be
|
||||
* displayed. The chat display will be notified when chat messages of
|
||||
* various sorts have been received by the client.
|
||||
*/
|
||||
public interface ChatDisplay
|
||||
{
|
||||
/**
|
||||
* Called to clear the chat display.
|
||||
*/
|
||||
public function clear () :void;
|
||||
|
||||
/**
|
||||
* Called to display a chat message.
|
||||
*
|
||||
* @see ChatMessage
|
||||
*/
|
||||
public function displayMessage (msg :ChatMessage) :void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// $Id: ChatService.java 3310 2005-01-24 23:08:21Z 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.chat.client {
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationListener;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
|
||||
/**
|
||||
* The chat services provide a mechanism by which the client can broadcast
|
||||
* chat messages to all clients that are subscribed to a particular place
|
||||
* object or directly to a particular client. These services should not be
|
||||
* used directly, but instead should be accessed via the {@link
|
||||
* ChatDirector}.
|
||||
*/
|
||||
public interface ChatService extends InvocationService
|
||||
{
|
||||
/**
|
||||
* Requests that a tell message be delivered to the user with username
|
||||
* equal to <code>target</code>.
|
||||
*
|
||||
* @param client a connected, operational client instance.
|
||||
* @param target the username of the user to which the tell message
|
||||
* should be delivered.
|
||||
* @param message the contents of the message.
|
||||
* @param listener the reference that will receive the tell response.
|
||||
*/
|
||||
function tell (
|
||||
client :Client, target :Name, message :String, listener :TellListener)
|
||||
:void;
|
||||
|
||||
/**
|
||||
* Requests that a message be broadcast to all users in the system.
|
||||
*
|
||||
* @param client a connected, operational client instance.
|
||||
* @param message the contents of the message.
|
||||
* @param listener the reference that will receive a failure response.
|
||||
*/
|
||||
function broadcast (
|
||||
client :Client, message :String, listener :InvocationListener) :void;
|
||||
|
||||
/**
|
||||
* Sets this client's away message. If the message is null or the
|
||||
* empty string, the away message will be cleared.
|
||||
*/
|
||||
function away (client :Client, message :String) :void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.threerings.crowd.chat.client {
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
|
||||
/**
|
||||
* Used to implement a slash command (e.g. <code>/who</code>).
|
||||
*/
|
||||
public /* abstract */ class CommandHandler
|
||||
{
|
||||
/**
|
||||
* Handles the specified chat command.
|
||||
*
|
||||
* @param speakSvc an optional SpeakService object representing
|
||||
* the object to send the chat message on.
|
||||
* @param command the slash command that was used to invoke this
|
||||
* handler (e.g. <code>/tell</code>).
|
||||
* @param args the arguments provided along with the command (e.g.
|
||||
* <code>Bob hello</code>) or <code>null</code> if no arguments
|
||||
* were supplied.
|
||||
* @param history an in/out parameter that allows the command to
|
||||
* modify the text that will be appended to the chat history. If
|
||||
* this is set to null, nothing will be appended.
|
||||
*
|
||||
* @return an untranslated string that will be reported to the
|
||||
* chat box to convey an error response to the user, or {@link
|
||||
* ChatCodes#SUCCESS}.
|
||||
*/
|
||||
public function handleCommand (
|
||||
speakSvc :SpeakService, cmd :String, args :String, history :Array)
|
||||
:void
|
||||
{
|
||||
throw new Error("abstract");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this user should have access to this chat
|
||||
* command.
|
||||
*/
|
||||
public function checkAccess (user :BodyObject) :Boolean
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// $Id: SpeakService.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.chat.client {
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
|
||||
/**
|
||||
* Provides a means by which "speaking" can be allowed among subscribers
|
||||
* of a particular distributed object.
|
||||
*/
|
||||
public interface SpeakService extends InvocationService
|
||||
{
|
||||
/**
|
||||
* Issues a request to speak "on" the distributed object via which
|
||||
* this speak service was provided.
|
||||
*
|
||||
* @param message the message to be spoken.
|
||||
* @param mode the "mode" of the message. This is an opaque value that
|
||||
* will be passed back down via the {@link ChatDirector} to the {@link
|
||||
* ChatDisplay} implementations which can interpret it in an
|
||||
* application specific manner. It's useful for differentiating
|
||||
* between regular speech, emotes, etc.
|
||||
*/
|
||||
function speak (client :Client, message :String, mode :int) :void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.threerings.crowd.chat.client {
|
||||
|
||||
import com.threerings.util.long;
|
||||
|
||||
import com.threerings.presents.client.InvocationListener
|
||||
|
||||
public interface TellListener extends InvocationListener
|
||||
{
|
||||
function tellSucceeded (idleTime :long, awayMessage :String) :void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// $Id: ChatCodes.java 3725 2005-10-08 22:21:19Z 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.chat.data {
|
||||
|
||||
import com.threerings.presents.data.InvocationCodes;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
|
||||
import com.threerings.crowd.chat.client.ChatDirector;
|
||||
import com.threerings.crowd.chat.client.SpeakService;
|
||||
|
||||
/**
|
||||
* Contains codes used by the chat invocation services.
|
||||
*/
|
||||
public class ChatCodes extends InvocationCodes
|
||||
{
|
||||
/** The message identifier for a chat notification message. */
|
||||
public static const CHAT_NOTIFICATION :String = "chat";
|
||||
|
||||
/** The access control identifier for normal chat privileges. See
|
||||
* {@link BodyObject#checkAccess}. */
|
||||
public static const CHAT_ACCESS :String = "crowd.chat.chat";
|
||||
|
||||
/** The access control identifier for broadcast chat privileges. See
|
||||
* {@link BodyObject#checkAccess}. */
|
||||
public static const BROADCAST_ACCESS :String = "crowd.chat.broadcast";
|
||||
|
||||
/** The configuration key for idle time. */
|
||||
public static const IDLE_TIME_KEY :String = "narya.chat.idle_time";
|
||||
|
||||
/** The default time after which a player is assumed idle. */
|
||||
public static const DEFAULT_IDLE_TIME :Number = 3 * 60 * 1000;
|
||||
|
||||
/** The chat localtype code for chat messages delivered on the place
|
||||
* object currently occupied by the client. This is the only type of
|
||||
* chat message that will be delivered unless the chat director is
|
||||
* explicitly provided with other chat message sources via {@link
|
||||
* ChatDirector#addAuxiliarySource}. */
|
||||
public static const PLACE_CHAT_TYPE :String = "placeChat";
|
||||
|
||||
/** The chat localtype for messages received on the user object. */
|
||||
public static const USER_CHAT_TYPE :String = "userChat";
|
||||
|
||||
/** The default mode used by {@link SpeakService#speak} requests. */
|
||||
public static const DEFAULT_MODE :int = 0;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that the user is
|
||||
* thinking what they're saying, or is it that they're saying what
|
||||
* they're thinking? */
|
||||
public static const THINK_MODE :int = 1;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is
|
||||
* actually an emote. */
|
||||
public static const EMOTE_MODE :int = 2;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is
|
||||
* actually a shout. */
|
||||
public static const SHOUT_MODE :int = 3;
|
||||
|
||||
/** A {@link SpeakService#speak} mode to indicate that a speak is
|
||||
* actually a server-wide broadcast. */
|
||||
public static const BROADCAST_MODE :int = 4;
|
||||
|
||||
/** An error code delivered when the user targeted for a tell
|
||||
* notification is not online. */
|
||||
public static const USER_NOT_ONLINE :String = "m.user_not_online";
|
||||
|
||||
/** An error code delivered when the user targeted for a tell
|
||||
* notification is disconnected. */
|
||||
public static const USER_DISCONNECTED :String = "m.user_disconnected";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// $Id: ChatMessage.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.chat.data {
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamable;
|
||||
|
||||
/**
|
||||
* The abstract base class of all the client-side ChatMessage objects.
|
||||
*/
|
||||
public /*abstract*/ class ChatMessage
|
||||
implements Streamable
|
||||
{
|
||||
/** The actual text of the message. */
|
||||
public var message :String;
|
||||
|
||||
/** The bundle to use when translating this message. */
|
||||
public var bundle :String;
|
||||
|
||||
/** The client side 'localtype' of this chat, set to the type
|
||||
* registered with an auxiliary source in the ChatDirector. */
|
||||
public var localtype :String;
|
||||
|
||||
/**
|
||||
* Once this message reaches the client, the information contained within
|
||||
* is changed around a bit.
|
||||
*/
|
||||
public function setClientInfo (msg :String, localtype :String) :void
|
||||
{
|
||||
message = msg;
|
||||
this.localtype = localtype;
|
||||
bundle = null;
|
||||
//timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a string representation of this instance.
|
||||
*/
|
||||
public function toString () :String
|
||||
{
|
||||
return ClassUtil.shortClassName(this) +
|
||||
" [message=" + message + ", bundle=" + bundle + "]";
|
||||
}
|
||||
|
||||
// documentation inherited from interface Streamable
|
||||
public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
message = ins.readField(String);
|
||||
bundle = ins.readField(String);
|
||||
}
|
||||
|
||||
// documentation inherited from interface Streamable
|
||||
public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
out.writeField(message);
|
||||
out.writeField(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// $Id: SystemMessage.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.chat.data {
|
||||
|
||||
/**
|
||||
* A ChatMessage that represents a message that came from the server
|
||||
* and did not result from direct user action.
|
||||
*/
|
||||
public class SystemMessage extends ChatMessage
|
||||
{
|
||||
/** Attention level constant to indicate that this message is merely
|
||||
* providing the user with information. */
|
||||
public static const INFO :int = 0;
|
||||
|
||||
/** Attention level constant to indicate that this message is the
|
||||
* result of a user action. */
|
||||
public static const FEEDBACK :int = 1;
|
||||
|
||||
/** Attention level constant to indicate that some action is required. */
|
||||
public static const ATTENTION :int = 2;
|
||||
|
||||
//----
|
||||
|
||||
/** The attention level of this message. */
|
||||
public var attentionLevel :int;
|
||||
|
||||
public override function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
attentionLevel = ins.readByte();
|
||||
}
|
||||
|
||||
public override function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeByte(attentionLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// $Id: UserMessage.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.chat.data {
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
/**
|
||||
* A ChatMessage representing a message that came from another user.
|
||||
*/
|
||||
public class UserMessage extends ChatMessage
|
||||
{
|
||||
/** The user that the message came from. */
|
||||
public var speaker :Name;
|
||||
|
||||
/** The mode of the message. @see ChatCodes.DEFAULT_MODE */
|
||||
public var mode :int;
|
||||
|
||||
public override function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
speaker = (ins.readObject() as Name);
|
||||
mode = ins.readByte();
|
||||
}
|
||||
|
||||
public override function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeObject(speaker);
|
||||
out.writeByte(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user