diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index 54dd3fe3a..840f4ec44 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.35 2002/10/28 00:22:38 ray Exp $ +// $Id: ChatDirector.java,v 1.36 2002/10/30 01:47:12 ray Exp $ package com.threerings.crowd.chat; @@ -14,6 +14,7 @@ import com.threerings.presents.dobj.*; import com.threerings.util.MessageBundle; import com.threerings.util.MessageManager; +import com.threerings.util.TimeUtil; import com.threerings.crowd.Log; import com.threerings.crowd.client.LocationObserver; @@ -316,6 +317,16 @@ public class ChatDirector extends BasicDirector addChatter(target); } + public void tellSucceededIdle (long idletime) { + String msg = MessageBundle.compose( + "m.told_idle_format", MessageBundle.taint(target), + MessageBundle.taint(message), + TimeUtil.getTimeOrderString(idletime, TimeUtil.MINUTE)); + + displayFeedbackMessage(_bundle, msg); + addChatter(target); + } + public void requestFailed (String reason) { String msg = MessageBundle.compose("m.tell_failed", target, reason); diff --git a/src/java/com/threerings/crowd/chat/client/ChatService.java b/src/java/com/threerings/crowd/chat/client/ChatService.java index 42f8da23a..a2810d5b9 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatService.java +++ b/src/java/com/threerings/crowd/chat/client/ChatService.java @@ -1,5 +1,5 @@ // -// $Id: ChatService.java,v 1.8 2002/08/14 19:07:49 mdb Exp $ +// $Id: ChatService.java,v 1.9 2002/10/30 01:47:12 ray Exp $ package com.threerings.crowd.chat; @@ -24,6 +24,13 @@ public interface ChatService extends InvocationService * Communicates the response to a {@link #tell} request. */ public void tellSucceeded (); + + /** + * Communicates the response to a {@link #tell} request. + * + * @param idletime, the number of ms the tellee has been idle. + */ + public void tellSucceededIdle (long idletime); } /** diff --git a/src/java/com/threerings/crowd/chat/data/ChatCodes.java b/src/java/com/threerings/crowd/chat/data/ChatCodes.java index 5d7474d61..e33152636 100644 --- a/src/java/com/threerings/crowd/chat/data/ChatCodes.java +++ b/src/java/com/threerings/crowd/chat/data/ChatCodes.java @@ -1,5 +1,5 @@ // -// $Id: ChatCodes.java,v 1.11 2002/08/14 19:07:49 mdb Exp $ +// $Id: ChatCodes.java,v 1.12 2002/10/30 01:47:12 ray Exp $ package com.threerings.crowd.chat; @@ -41,4 +41,8 @@ public interface ChatCodes extends InvocationCodes /** An error code delivered when the user targeted for a tell * notification is not online. */ public static final String USER_NOT_ONLINE = "m.user_not_online"; + + /** An error code delivered when the user targeted for a tell + * notification is disconnected. */ + public static final String USER_DISCONNECTED = "m.user_disconnected"; } diff --git a/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java b/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java index 13900cbf9..955e2b75d 100644 --- a/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java +++ b/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: ChatMarshaller.java,v 1.2 2002/08/20 19:38:13 mdb Exp $ +// $Id: ChatMarshaller.java,v 1.3 2002/10/30 01:47:12 ray Exp $ package com.threerings.crowd.chat; @@ -15,10 +15,6 @@ import com.threerings.presents.dobj.InvocationResponseEvent; * on the server. Also provides an implementation of the response listener * interfaces that marshall the response arguments and deliver them back * to the requesting client. - * - *

Generated from - * $Id: ChatMarshaller.java,v 1.2 2002/08/20 19:38:13 mdb Exp $ - * */ public class ChatMarshaller extends InvocationMarshaller implements ChatService @@ -39,6 +35,18 @@ public class ChatMarshaller extends InvocationMarshaller new Object[] { })); } + /** The method id used to dispatch {@link #tellSucceededIdle} + * responses. */ + public static final int TELL_SUCCEEDED_IDLE = 2; + + // documentation inherited from interface + public void tellSucceededIdle (long arg1) + { + omgr.postEvent(new InvocationResponseEvent( + callerOid, requestId, TELL_SUCCEEDED_IDLE, + new Object[] { new Long(arg1) })); + } + // documentation inherited public void dispatchResponse (int methodId, Object[] args) { @@ -48,6 +56,11 @@ public class ChatMarshaller extends InvocationMarshaller ); return; + case TELL_SUCCEEDED_IDLE: + ((TellListener)listener).tellSucceededIdle( + ((Long)args[0]).longValue()); + return; + default: super.dispatchResponse(methodId, args); } @@ -67,5 +80,5 @@ public class ChatMarshaller extends InvocationMarshaller }); } - // Class file generated on 12:33:02 08/20/02. + // Generated on 17:55:05 10/29/02. } diff --git a/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java b/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java index d1d24d405..cb9daa9e4 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java +++ b/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java @@ -1,5 +1,5 @@ // -// $Id: ChatDispatcher.java,v 1.2 2002/08/20 19:38:13 mdb Exp $ +// $Id: ChatDispatcher.java,v 1.3 2002/10/30 01:47:12 ray Exp $ package com.threerings.crowd.chat; @@ -14,10 +14,6 @@ import com.threerings.presents.server.InvocationException; /** * Dispatches requests to the {@link ChatProvider}. - * - *

Generated from - * $Id: ChatDispatcher.java,v 1.2 2002/08/20 19:38:13 mdb Exp $ - * */ public class ChatDispatcher extends InvocationDispatcher { @@ -53,4 +49,6 @@ public class ChatDispatcher extends InvocationDispatcher super.dispatchRequest(source, methodId, args); } } + + // Generated on 17:55:05 10/29/02. } diff --git a/src/java/com/threerings/crowd/chat/server/ChatProvider.java b/src/java/com/threerings/crowd/chat/server/ChatProvider.java index 808cf2616..52d764817 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatProvider.java +++ b/src/java/com/threerings/crowd/chat/server/ChatProvider.java @@ -1,5 +1,5 @@ // -// $Id: ChatProvider.java,v 1.13 2002/08/14 19:07:49 mdb Exp $ +// $Id: ChatProvider.java,v 1.14 2002/10/30 01:47:12 ray Exp $ package com.threerings.crowd.chat; @@ -13,10 +13,14 @@ import com.threerings.presents.server.InvocationProvider; import com.threerings.crowd.Log; import com.threerings.crowd.data.BodyObject; +import com.threerings.crowd.data.OccupantInfo; import com.threerings.crowd.server.CrowdServer; import com.threerings.crowd.chat.ChatService.TellListener; +import com.threerings.util.MessageBundle; +import com.threerings.util.TimeUtil; + /** * The chat provider handles the server side of the chat-related * invocation services. @@ -51,12 +55,26 @@ public class ChatProvider throw new InvocationException(USER_NOT_ONLINE); } + if (tobj.status == OccupantInfo.DISCONNECTED) { + throw new InvocationException(MessageBundle.compose( + USER_DISCONNECTED, TimeUtil.getTimeOrderString( + System.currentTimeMillis() - tobj.statusTime, + TimeUtil.MINUTE))); + } + // deliver a tell notification to the target player BodyObject source = (BodyObject)caller; sendTellMessage(tobj, source.username, null, message); // let the teller know it went ok - listener.tellSucceeded(); + if (tobj.status == OccupantInfo.IDLE) { + listener.tellSucceededIdle( + System.currentTimeMillis() - tobj.statusTime); + + } else { + // normal success + listener.tellSucceeded(); + } } /** diff --git a/src/java/com/threerings/util/TimeUtil.java b/src/java/com/threerings/util/TimeUtil.java new file mode 100644 index 000000000..a979413dd --- /dev/null +++ b/src/java/com/threerings/util/TimeUtil.java @@ -0,0 +1,71 @@ +// +// $Id: TimeUtil.java,v 1.1 2002/10/30 01:47:12 ray Exp $ + +package com.threerings.util; + +/** + * Utility for times. + */ +public class TimeUtil +{ + /** Granularity constant. */ + public static final byte MILLISECOND = 0; + + /** Granularity constant. */ + public static final byte SECOND = 1; + + /** Granularity constant. */ + public static final byte MINUTE = 2; + + /** Granularity constant. */ + public static final byte HOUR = 3; + + /** + * Get a translatable string specifying the magnitude of the specified + * duration. Results will be between "1 second" and "X hours", with + * all times rounded to the nearest unit. + */ + public static String getTimeOrderString (long duration, byte granularity) + { + if (granularity == MILLISECOND) { + if (duration < 2) { + return "m.1millisecond"; + } else if (duration < 1000) { + return MessageBundle.tcompose("m.milliseconds", + String.valueOf(duration)); + } + } + + int seconds = (int) Math.round(duration / 1000f); + + if (granularity <= SECOND) { + if (seconds < 2) { + return "m.1second"; + } else if (seconds < 60) { + return MessageBundle.tcompose("m.seconds", + String.valueOf(seconds)); + } + } + + int minutes = (int) Math.round(seconds / 60f); + + if (granularity <= MINUTE) { + if (minutes < 2) { + return "m.1minute"; + } else if (minutes < 60) { + return MessageBundle.tcompose("m.minutes", + String.valueOf(minutes)); + } + } + + int hours = (int) Math.round(minutes / 60f); + + if (hours < 2) { + return "m.1hour"; + } else { + return MessageBundle.tcompose("m.hours", String.valueOf(hours)); + } + + // TODO: days? weeks? months? + } +}