Moved the serverless game stuff out of msoy and back into the vilya library.

We'll be using this in game gardens, at least.
Note that the actionscript side currently doesn't compile because of
limitations in building a .swc file, but that'll be fixed soon.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@47 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Ray Greenwell
2006-08-23 02:28:36 +00:00
parent a90d7e655b
commit 70b0d759c0
27 changed files with 2835 additions and 0 deletions
@@ -0,0 +1,68 @@
//
// $Id$
package com.threerings.ezgame.data;
import com.threerings.util.MessageBundle;
import com.threerings.parlor.game.client.GameConfigurator;
import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.game.data.PartyGameConfig;
/**
* A game config for a simple multiplayer game.
*/
public class EZGameConfig extends GameConfig
implements PartyGameConfig
{
/** A creator-submitted name of the game. */
public String gameName;
// from abstract GameConfig
public String getBundleName ()
{
return "general";
}
// from abstract GameConfig
public GameConfigurator createConfigurator ()
{
return null; // nothing here on the java side
}
@Override
public String getGameName ()
{
return MessageBundle.taint(gameName);
}
// from abstract PlaceConfig
public String getManagerClassName ()
{
return "com.threerings.ezgame.server.EZGameManager";
}
// from PartyGameConfig
public byte getPartyGameType ()
{
// TODO
return NOT_PARTY_GAME;
}
@Override
public boolean equals (Object other)
{
if (!super.equals(other)) {
return false;
}
EZGameConfig that = (EZGameConfig) other;
return this.gameName.equals(that.gameName);
}
@Override
public int hashCode ()
{
return super.hashCode(); // TODO: incorp game name?
}
}
@@ -0,0 +1,113 @@
//
// $Id$
package com.threerings.ezgame.data;
import com.threerings.ezgame.client.EZGameService;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent;
/**
* Provides the implementation of the {@link EZGameService} interface
* that marshalls the arguments and delivers the request to the provider
* 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.
*/
public class EZGameMarshaller extends InvocationMarshaller
implements EZGameService
{
/** The method id used to dispatch {@link #addToCollection} requests. */
public static final int ADD_TO_COLLECTION = 1;
// documentation inherited from interface
public void addToCollection (Client arg1, String arg2, byte[][] arg3, boolean arg4, InvocationService.InvocationListener arg5)
{
ListenerMarshaller listener5 = new ListenerMarshaller();
listener5.listener = arg5;
sendRequest(arg1, ADD_TO_COLLECTION, new Object[] {
arg2, arg3, Boolean.valueOf(arg4), listener5
});
}
/** The method id used to dispatch {@link #endGame} requests. */
public static final int END_GAME = 2;
// documentation inherited from interface
public void endGame (Client arg1, int[] arg2, InvocationService.InvocationListener arg3)
{
ListenerMarshaller listener3 = new ListenerMarshaller();
listener3.listener = arg3;
sendRequest(arg1, END_GAME, new Object[] {
arg2, listener3
});
}
/** The method id used to dispatch {@link #endTurn} requests. */
public static final int END_TURN = 3;
// documentation inherited from interface
public void endTurn (Client arg1, int arg2, InvocationService.InvocationListener arg3)
{
ListenerMarshaller listener3 = new ListenerMarshaller();
listener3.listener = arg3;
sendRequest(arg1, END_TURN, new Object[] {
Integer.valueOf(arg2), listener3
});
}
/** The method id used to dispatch {@link #getFromCollection} requests. */
public static final int GET_FROM_COLLECTION = 4;
// documentation inherited from interface
public void getFromCollection (Client arg1, String arg2, boolean arg3, int arg4, String arg5, int arg6, InvocationService.ConfirmListener arg7)
{
InvocationMarshaller.ConfirmMarshaller listener7 = new InvocationMarshaller.ConfirmMarshaller();
listener7.listener = arg7;
sendRequest(arg1, GET_FROM_COLLECTION, new Object[] {
arg2, Boolean.valueOf(arg3), Integer.valueOf(arg4), arg5, Integer.valueOf(arg6), listener7
});
}
/** The method id used to dispatch {@link #mergeCollection} requests. */
public static final int MERGE_COLLECTION = 5;
// documentation inherited from interface
public void mergeCollection (Client arg1, String arg2, String arg3, InvocationService.InvocationListener arg4)
{
ListenerMarshaller listener4 = new ListenerMarshaller();
listener4.listener = arg4;
sendRequest(arg1, MERGE_COLLECTION, new Object[] {
arg2, arg3, listener4
});
}
/** The method id used to dispatch {@link #sendMessage} requests. */
public static final int SEND_MESSAGE = 6;
// documentation inherited from interface
public void sendMessage (Client arg1, String arg2, Object arg3, int arg4, InvocationService.InvocationListener arg5)
{
ListenerMarshaller listener5 = new ListenerMarshaller();
listener5.listener = arg5;
sendRequest(arg1, SEND_MESSAGE, new Object[] {
arg2, arg3, Integer.valueOf(arg4), listener5
});
}
/** The method id used to dispatch {@link #setProperty} requests. */
public static final int SET_PROPERTY = 7;
// documentation inherited from interface
public void setProperty (Client arg1, String arg2, Object arg3, int arg4, InvocationService.InvocationListener arg5)
{
ListenerMarshaller listener5 = new ListenerMarshaller();
listener5.listener = arg5;
sendRequest(arg1, SET_PROPERTY, new Object[] {
arg2, arg3, Integer.valueOf(arg4), listener5
});
}
}
@@ -0,0 +1,162 @@
//
// $Id$
package com.threerings.ezgame.data;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.threerings.util.Name;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
import com.threerings.parlor.game.data.GameObject;
import com.threerings.parlor.turn.data.TurnGameObject;
/**
* Contains the data for an ez game.
*/
public class EZGameObject extends GameObject
implements TurnGameObject
{
/** The identifier for a MessageEvent containing a user message. */
public static final String USER_MESSAGE = "Umsg";
/** The identifier for a MessageEvent containing game-system chat. */
public static final String GAME_CHAT = "Uchat";
// AUTO-GENERATED: FIELDS START
/** The field name of the <code>turnHolder</code> field. */
public static final String TURN_HOLDER = "turnHolder";
/** The field name of the <code>ezGameService</code> field. */
public static final String EZ_GAME_SERVICE = "ezGameService";
// AUTO-GENERATED: FIELDS END
/** The current turn holder. */
public Name turnHolder;
/** The service interface for requesting special things from the server. */
public EZGameMarshaller ezGameService;
// from TurnGameObject
public String getTurnHolderFieldName ()
{
return TURN_HOLDER;
}
// from TurnGameObject
public Name getTurnHolder ()
{
return turnHolder;
}
// from TurnGameObject
public Name[] getPlayers ()
{
return players;
}
/**
* Called by PropertySetEvent to effect the property update.
*/
protected void applyPropertySet (String propName, Object data, int index)
{
if (index >= 0) {
Object something = _props.get(propName);
byte[][] arr = (something instanceof byte[][])
? (byte[][]) something : null;
if (arr == null || arr.length <= index) {
// TODO: in case a user sets element 0 and element 90000,
// we might want to store elements in a hash
byte[][] newArr = new byte[index + 1][];
if (arr != null) {
System.arraycopy(arr, 0, newArr, 0, arr.length);
}
_props.put(propName, newArr);
arr = newArr;
}
arr[index] = (byte[]) data;
} else if (data != null) {
_props.put(propName, data);
} else {
_props.remove(propName);
}
}
// AUTO-GENERATED: METHODS START
/**
* Requests that the <code>turnHolder</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public void setTurnHolder (Name value)
{
Name ovalue = this.turnHolder;
requestAttributeChange(
TURN_HOLDER, value, ovalue);
this.turnHolder = value;
}
/**
* Requests that the <code>ezGameService</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public void setEZGameService (EZGameMarshaller value)
{
EZGameMarshaller ovalue = this.ezGameService;
requestAttributeChange(
EZ_GAME_SERVICE, value, ovalue);
this.ezGameService = value;
}
// AUTO-GENERATED: METHODS END
/**
* A custom serialization method.
*/
public void writeObject (ObjectOutputStream out)
throws IOException
{
out.defaultWriteObject();
// write the number of properties, followed by each one
out.writeInt(_props.size());
for (Map.Entry<String, Object> entry : _props.entrySet()) {
out.writeUTF(entry.getKey());
out.writeObject(entry.getValue());
}
}
/**
* A custom serialization method.
*/
public void readObject (ObjectInputStream ins)
throws IOException, ClassNotFoundException
{
ins.defaultReadObject();
_props.clear();
int count = ins.readInt();
while (count-- > 0) {
String key = ins.readUTF();
_props.put(key, ins.readObject());
}
}
/** The current state of game data, opaque to us here on the server. */
protected transient HashMap<String, Object> _props =
new HashMap<String, Object>();
}
@@ -0,0 +1,50 @@
//
// $Id$
package com.threerings.ezgame.data;
import java.io.IOException;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
import com.threerings.io.Streamer;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.NamedEvent;
/**
* Represents a property change on the actionscript object we
* use in EZGameObject.
*/
public class PropertySetEvent extends NamedEvent
{
/** Suitable for unserialization. */
public PropertySetEvent ()
{
}
/**
* Create a PropertySetEvent.
*/
public PropertySetEvent (
int targetOid, String propName, Object value, int index)
{
super(targetOid, propName);
_data = value;
_index = index;
}
// from abstract DEvent
public boolean applyToObject (DObject target)
{
((EZGameObject) target).applyPropertySet(_name, _data, _index);
return true;
}
/** The index. */
protected int _index;
/** The client-side data that is assigned to this property. */
protected Object _data;
}