Created ClientLocal and BodyLocal which is where we'll track server-only

information.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5474 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-10-28 17:55:17 +00:00
parent c544146c45
commit d1be746bdb
7 changed files with 97 additions and 10 deletions
@@ -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)) {
@@ -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.
@@ -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;
}
@@ -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() {
@@ -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 ()
{
@@ -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}.
*
* <p> 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
}
@@ -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