Class Handler
The mothership's implementation of the handler. Not all games use this but it could be useful to offload some centralized processing.
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
Type | Name | Description |
---|---|---|
System.String | bucketName | The bucket's name or empty for the default score bucket. |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
log4net.ILog | log | 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 Expects Expects |
MothershipHandler | msHandler | Your implementation of the MothershipHandler interface, implementing all the necessary methods. |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
System.Int32 | receivedSoFar | the count of response received so far. 0 for the first call |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
System.Boolean | raw | false to only include players who sent metadata to the RMB. |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
System.Byte[] | payload | The bytes to be sent |
Returns
Type | Description |
---|---|
System.Boolean |
SendToRoom(Byte[])
Sends data to the bigscreen.
Declaration
public bool SendToRoom(byte[] payload)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | payload | The bytes to be sent |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
System.Byte[] | payload | The bytes to be sent to all satellites currently connected to this mothership |
Returns
Type | Description |
---|---|
System.Boolean | false if an error occured, otherwise true is returned |