Class Handler

The mothership's implementation of the handler. Not all games use this but it could be useful to offload some centralized processing.

Inheritance

System.Object
Handler
Namespace: rmb.mothership
Assembly: rmb.mothership.dll

Syntax

public class Handler : Handler

Methods

ClearBucket(String)

This method clears data for the given bucket.

Declaration

public bool ClearBucket(string bucketName)

Parameters

TypeNameDescription
System.StringbucketName

The bucket's name or empty for the default score bucket.

Returns

TypeDescription
System.Boolean

false if an error occured, otherwise true is returned

Create(log4net.ILog, String[], MothershipHandler)

Handler factory method. Call this method in the main function of the mothership executable. This is the only way to create an object of type rmb.Mothership.Handler.

Declaration

public static Handler Create(log4net.ILog log, string[] args, MothershipHandler msHandler)

Parameters

TypeNameDescription
log4net.ILoglog

The log object created using the initLogging method from the util namespace.

System.String[]args

Command line parameters received from the main function of the mothership's executable. They come directly from the rmb with all the relevant info required to run.

Expects -gamename value pair as game name.

Expects -key value pair as key for rmb to identify actor.

Expects -connection value pair as connecton string for actor to connect to rmb.

MothershipHandlermsHandler

Your implementation of the MothershipHandler interface, implementing all the necessary methods.

Returns

TypeDescription
Handler

Examples

Here's an example of how to create an instance of this class. the log object is created with the type of your game code.

static void Main(string[] args)
{
Util.InitLogging();
Util.SetDefaultLogging(typeof(Showdown));
Util.log.Info("Args = " + (args != null ? string.Join(',', args) : null));
var game = new Showdown();
game.handler = rmb.mothership.Handler.Create(Util.log, args, game);
while(game.handler != null)
{
game.handler.Update();
}
Util.log.Info("Mothership showdown done.");
}

As you can see the main method very simple and straightforward. All the hard word is done in the methods implementing MothershipHandler

RequestAllSatellitesReplied(Int32)

If SendToSatellites(Byte[]) requires acknowledgement, you could set a counter to zero and increment that counter with each response received. You could then use that counter as the parameter to this method to let the RMB tell you if you should expect more answers. You could call this method right after SendToSatellites(Byte[]) with 0 to make sure you should wait for some responses, and then call after each reception or after a certain amount of time.

Pending count is returned via OnAllSatellitesResponded(Int32)

Declaration

public bool RequestAllSatellitesReplied(int receivedSoFar)

Parameters

TypeNameDescription
System.Int32receivedSoFar

the count of response received so far. 0 for the first call

Returns

TypeDescription
System.Boolean

false if an error occured, otherwise true is returned

RequestPlayersCount(Boolean)

Request players count. This is the total number of players assigned to satellites managed by this mothership.

Sometimes, players can connect to the rmb but can't play the current because of various issues like versions mismatch. When raw is set to false, only players who have sent metadata to the RMB are counted.

Declaration

public bool RequestPlayersCount(bool raw)

Parameters

TypeNameDescription
System.Booleanraw

false to only include players who sent metadata to the RMB.

Returns

TypeDescription
System.Boolean

false if an error occured, otherwise true is returned

SendToAllPlayers(Byte[])

Typical broadcast message to all players connected to any satellite managed by this mothership. In fact, the mothership will relay the bytes to all connected satellites sking them to forward those to every player under their management.

Declaration

public bool SendToAllPlayers(byte[] payload)

Parameters

TypeNameDescription
System.Byte[]payload

The bytes to be sent

Returns

TypeDescription
System.Boolean

SendToRoom(Byte[])

Sends data to the bigscreen.

Declaration

public bool SendToRoom(byte[] payload)

Parameters

TypeNameDescription
System.Byte[]payload

The bytes to be sent

Returns

TypeDescription
System.Boolean

false if an error occured, otherwise true is returned

SendToSatellites(Byte[])

Sends the payload to all satellites connected to this mothership.

Declaration

public bool SendToSatellites(byte[] payload)

Parameters

TypeNameDescription
System.Byte[]payload

The bytes to be sent to all satellites currently connected to this mothership

Returns

TypeDescription
System.Boolean

false if an error occured, otherwise true is returned