diff --git a/src/java/com/threerings/crowd/chat/server/ChatProvider.java b/src/java/com/threerings/crowd/chat/server/ChatProvider.java index 125793bb4..5bf24e0c4 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatProvider.java +++ b/src/java/com/threerings/crowd/chat/server/ChatProvider.java @@ -39,14 +39,15 @@ import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationManager; import com.threerings.presents.server.InvocationProvider; -import com.threerings.crowd.chat.client.ChatService; import com.threerings.crowd.chat.client.ChatService.TellListener; +import com.threerings.crowd.chat.client.ChatService; import com.threerings.crowd.chat.data.ChatCodes; import com.threerings.crowd.chat.data.UserMessage; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.CrowdCodes; import com.threerings.crowd.data.OccupantInfo; import com.threerings.crowd.data.PlaceObject; +import com.threerings.crowd.server.BodyLocal; import com.threerings.crowd.server.BodyLocator; import com.threerings.crowd.server.PlaceRegistry; @@ -217,7 +218,8 @@ public class ChatProvider if (tobj.status == OccupantInfo.DISCONNECTED) { String errmsg = MessageBundle.compose( ChatCodes.USER_DISCONNECTED, TimeUtil.getTimeOrderString( - System.currentTimeMillis() - tobj.statusTime, TimeUtil.SECOND)); + System.currentTimeMillis() - tobj.getLocal(BodyLocal.class).statusTime, + TimeUtil.SECOND)); throw new InvocationException(errmsg); } @@ -227,7 +229,7 @@ public class ChatProvider // let the teller know it went ok long idle = 0L; if (tobj.status == OccupantInfo.IDLE) { - idle = System.currentTimeMillis() - tobj.statusTime; + idle = System.currentTimeMillis() - tobj.getLocal(BodyLocal.class).statusTime; } String awayMessage = null; if (!StringUtil.isBlank(tobj.awayMessage)) { diff --git a/src/java/com/threerings/crowd/data/BodyObject.java b/src/java/com/threerings/crowd/data/BodyObject.java index 4561d9d59..66d3f7263 100644 --- a/src/java/com/threerings/crowd/data/BodyObject.java +++ b/src/java/com/threerings/crowd/data/BodyObject.java @@ -55,12 +55,6 @@ public class BodyObject extends ClientObject */ public byte status; - /** - * The time at which the {@link #status} field was last updated. This is only available on the - * server. - */ - public transient long statusTime; - /** * If non-null, this contains a message to be auto-replied whenever another user delivers a * tell message to this user. diff --git a/src/java/com/threerings/crowd/server/BodyLocal.java b/src/java/com/threerings/crowd/server/BodyLocal.java new file mode 100644 index 000000000..4e2477d9b --- /dev/null +++ b/src/java/com/threerings/crowd/server/BodyLocal.java @@ -0,0 +1,36 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2008 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.server; + +import com.threerings.presents.server.ClientLocal; + +/** + * Contains information tracked for each body by the server. + */ +public class BodyLocal extends ClientLocal +{ + /** + * The time at which the {@link #status} field was last updated. This is only available on the + * server. + */ + public long statusTime; +} diff --git a/src/java/com/threerings/crowd/server/BodyManager.java b/src/java/com/threerings/crowd/server/BodyManager.java index 61c44a544..c455e0165 100644 --- a/src/java/com/threerings/crowd/server/BodyManager.java +++ b/src/java/com/threerings/crowd/server/BodyManager.java @@ -89,7 +89,7 @@ public class BodyManager if (body.status != status) { // update the status in their body object body.setStatus(status); - body.statusTime = System.currentTimeMillis(); + body.getLocal(BodyLocal.class).statusTime = System.currentTimeMillis(); } updateOccupantInfo(body, location, new OccupantInfoOp() { diff --git a/src/java/com/threerings/crowd/server/CrowdClient.java b/src/java/com/threerings/crowd/server/CrowdClient.java index 9a84a8352..f56cdf670 100644 --- a/src/java/com/threerings/crowd/server/CrowdClient.java +++ b/src/java/com/threerings/crowd/server/CrowdClient.java @@ -23,6 +23,7 @@ package com.threerings.crowd.server; import com.google.inject.Inject; +import com.threerings.presents.server.ClientLocal; import com.threerings.presents.server.PresentsClient; import com.threerings.crowd.chat.server.SpeakUtil; @@ -34,6 +35,12 @@ import com.threerings.crowd.data.OccupantInfo; */ public class CrowdClient extends PresentsClient { + @Override + protected ClientLocal createLocalAttribute () + { + return new BodyLocal(); + } + @Override protected void sessionConnectionClosed () { diff --git a/src/java/com/threerings/presents/server/ClientLocal.java b/src/java/com/threerings/presents/server/ClientLocal.java new file mode 100644 index 000000000..e7993e6e3 --- /dev/null +++ b/src/java/com/threerings/presents/server/ClientLocal.java @@ -0,0 +1,39 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2008 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.server; + +import com.threerings.io.Streamable; + +import com.threerings.presents.data.ClientObject; + +/** + * Contains information about a client only tracked on the server. This is configured as a local + * attribute on the {@link ClientObject}. + * + *

Note: this object implements streamable so that it can be cleanly passed between servers in + * a peered environment. It is never sent to the client. + */ +public class ClientLocal + implements Streamable +{ + // nothing to track at this level +} diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index e6d69487f..198a1594b 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -367,6 +367,7 @@ public class PresentsClient { // we'll be keeping this bad boy _clobj = clobj; + _clobj.setLocal(ClientLocal.class, createLocalAttribute()); // if our connection was closed while we were resolving our client object, then just // abandon ship @@ -423,6 +424,14 @@ public class PresentsClient disp.dispatch(this, message); } + /** + * Creates a record that will be maintained only on the server to track client related bits. + */ + protected ClientLocal createLocalAttribute () + { + return new ClientLocal(); + } + /** * Called when {@link #setUsername} has been called and the new client object is about to be * applied to this client. The old client object will not yet have been destroyed, so any final