Created a ServerMessageEvent that is just like a normal MessageEvent

except that messages will never leave the server. If generated on a client,
they'll go to the server and be processed like a normal event there
(event handlers will be called) but the event will not leave the server and
be sent to subscribing clients.

Changed the ManagerCaller used by PlaceObjects to use ServerMessageEvents.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4648 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2007-04-06 19:00:41 +00:00
parent 63413f862c
commit c4fac45b9c
4 changed files with 121 additions and 2 deletions
@@ -21,6 +21,8 @@
package com.threerings.crowd.data {
import com.threerings.presents.dobj.ServerMessageEvent;
public class ManagerCaller
{
public function ManagerCaller (plobj :PlaceObject)
@@ -33,7 +35,7 @@ public class ManagerCaller
*/
public function invoke (method :String, ... args) :void
{
_plobj.postMessage(method, args);
_plobj.postEvent(new ServerMessageEvent(_plobj.getOid(), method, args));
}
/** The place object we're thingy-ing for. */
@@ -0,0 +1,56 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2007 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.dobj {
/**
* A message event that only goes to the server. If generated on the server then it never leaves
* the server.
*/
public class ServerMessageEvent extends MessageEvent
{
/**
* Constructs a new message event on the specified target object with
* the supplied name and arguments.
*
* @param targetOid the object id of the object whose attribute has
* changed.
* @param name the name of the message event.
* @param args the arguments for this message. This array should
* contain only values of valid distributed object types.
*/
public function ServerMessageEvent (
targetOid :int = 0, name :String = null, args :Array = null)
{
super(targetOid, name, args);
}
// Note: isPrivate() is currently not implemented in actionscript, since
// it's a server-only attribute. Rest assured that this event will still
// only be server-only, as it will unserialize into a Java ServerMessageEvent
// on the server and then be properly private.
// override public function isPrivate () :Boolean
// {
// // this is what makes us server-only
// return true;
// }
}
}
@@ -28,6 +28,7 @@ import com.threerings.util.Name;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
import com.threerings.presents.dobj.OidList;
import com.threerings.presents.dobj.ServerMessageEvent;
import com.threerings.crowd.Log;
import com.threerings.crowd.chat.data.SpeakMarshaller;
@@ -60,7 +61,7 @@ public class PlaceObject extends DObject
public class ManagerCaller
{
public void invoke (String method, Object ... args) {
postMessage(method, args);
postEvent(new ServerMessageEvent(_oid, method, args));
}
}
@@ -0,0 +1,60 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2007 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.dobj;
import com.samskivert.util.StringUtil;
/**
* A message event that only goes to the server. If generated on the server then it never leaves
* the server.
*/
public class ServerMessageEvent extends MessageEvent
{
/**
* Constructs a new message event on the specified target object with
* the supplied name and arguments.
*
* @param targetOid the object id of the object whose attribute has
* changed.
* @param name the name of the message event.
* @param args the arguments for this message. This array should
* contain only values of valid distributed object types.
*/
public ServerMessageEvent (int targetOid, String name, Object[] args)
{
super(targetOid, name, args);
}
/**
* Suitable for unserialization.
*/
public ServerMessageEvent ()
{
}
@Override
public boolean isPrivate ()
{
// this is what makes us server-only
return true;
}
}