Progress on the presents client.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3848 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-02-13 22:07:50 +00:00
parent ad7e4f6be6
commit 8366c150f4
7 changed files with 220 additions and 2 deletions
@@ -0,0 +1,40 @@
package com.threerings.presents.net {
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
public class AuthRequest extends UpstreamMessage
{
public function AuthRequest ()
{
super();
}
public function AuthRequest (creds :Credentials, version :String)
{
super();
_creds = creds;
_version = version;
}
// documentation inherited
public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeField(_creds);
out.writeField(_version);
}
// documentation inherited
public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
_creds = ins.readField(Credentials);
_version = ins.readField(String);
}
protected var _creds :Credentials;
protected var _version :String;
}
}
@@ -0,0 +1,25 @@
package com.threerings.presents.net {
import com.threerings.io.Streamable;
public class DownstreamMessage
implements Streamable
{
/** The message id of the upstream message with which this downstream
* message is associated (or -1 if it is not associated with any
* upstream message). */
public var messageId :int = -1;
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeShort(messageId);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
messageId = ins.readShort();
}
}
}
@@ -0,0 +1,38 @@
package com.threerings.presents.net {
import com.threerings.io.ObjectOutputStream;
public class PingRequest extends UpstreamMessage
{
/** The number of milliseconds of idle upstream that are allowed to elapse
* before the client sends a ping message to the server to let it
* know that we're still alive. */
public static const PING_INTERVAL :int = 60 * 1000;
public function PingRequest ()
{
super();
}
public function getPackStamp () :Number
{
return _packStamp;
}
// documentation inherited
public function writeObject (out :ObjectOutputStream)
{
_packStamp = new Date().getTime();
super.writeObject(out);
}
// documentation inherited
public function readObject (ins :ObjectInputStream)
{
trace("read PingRequest on the client?");
}
/** A time stamp obtained when we serialize this object. */
protected var _packStamp :Number;
}
}
@@ -0,0 +1,54 @@
package com.threerings.presents.net {
import com.threerings.util.long;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
public class PongResponse extends DownstreamMessage
{
public function PongResponse ()
{
super();
}
public function getPackStamp () :long
{
return _packStamp;
}
public function getProcessDelay () :int
{
return _processDelay;
}
public function getUnpackStamp () :Number
{
return _unpackStamp;
}
public function writeObject (out :ObjectOutputStream)
{
trace("write a pong on the client??");
}
public function readObject (ins :ObjectInputStream)
{
_unpackStamp = new Date().getTime();
super.readObject(ins);
// TODO: Figure out how we're really going to cope with longs
_packStamp = new long();
_packStamp.readObject(ins);
_processDelay = ins.readInt();
}
protected var _packStamp :long;
protected var _processDelay :int;
protected var _unpackStamp :Number;
}
}
@@ -0,0 +1,48 @@
package com.threerings.presents.net {
import com.threerings.io.Streamable;
public class UpstreamMessage
implements Streamable
{
/** This is a unique (within the context of a reasonable period
* of time) identifier assigned to each upstream message. The message ids
* are used to correlate a downstream response message to the
* appropriate upstream request message. */
public var messageId :int;
/**
* Construct an upstream message.
*/
public function UpstreamMessage ()
{
// automatically generate a valid message id
this.messageId = nextMessageId();
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeShort(messageId);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
messageId = ins.readShort();
}
/**
* Returns the next message id suitable for use by an upstream message./
*/
protected static function nextMessageId () :int
{
_nextMessageId = (_nextMessageId + 1) % JavaConstants.SHORT_MAX_VALUE;
return _nextMessageId;
}
/** This is used to generate monotonically increasing message ids on the
* client as new messages are generated. */
protected static var _nextMessageId :int;
}
}
@@ -0,0 +1,7 @@
package com.threerings.util {
public class JavaConstants
{
public static const SHORT_MAX_VALUE :int = (Math.pow(2, 15) - 1);
}
}
+8 -2
View File
@@ -1,5 +1,11 @@
package com.threerings.util {
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
/**
* TODO: stuff.
*/
public class long extends Object
implements Streamable
{
@@ -13,16 +19,16 @@ public class long extends Object
public function writeObject (out :ObjectOutputStream) :void
//throws IOError
{
out.writeInt(_lowbits);
out.writeInt(_highbits);
out.writeInt(_lowbits);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
//throws IOError
{
_lowbits = ins.readInt();
_highbits = ins.readInt();
_lowbits = ins.readInt();
}
/** Yon bits. */