Class Handler

Handler is the main driver for your game, it will translate data from the wire as necessary and relay clean data to your game thru either of the mothership or satellite interface

Inheritance

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

Syntax

public abstract class Handler : BusClientHandler

Constructors

Handler(ILog, String, String)

Protected constructor called by Satellite and Mothership handlers.

Declaration

protected Handler(ILog log, string gameName, string key)

Parameters

TypeNameDescription
ILoglog

The log object used to output log messages

System.StringgameName

The name used for the current game

System.Stringkey

The unique identifier of this process received from the RMB. It is used for the handshake between this actor and the RMB.

Fields

bus

Declaration

protected BusClient.BusClient bus

Field Value

TypeDescription
BusClient.BusClient

Properties

CustomTarget

The saved custom target value received with the OnStart call. Use this property to refer to the value through the game life cycle.

Declaration

public byte CustomTarget { get; set; }

Property Value

TypeDescription
System.Byte

Key

The Key proprerty is used to uniquely identify this instance of your game. This ensure that it cannot be any confusion with any other instance of this code running by mistake.

Declaration

public string Key { get; set; }

Property Value

TypeDescription
System.String

Log

The main log object.

Declaration

public ILog Log { get; set; }

Property Value

TypeDescription
ILog

MainHandler

This is the interface used to get the data to your game. It is either a satellite or mothership implementation.

Declaration

public BaseHandler MainHandler { get; set; }

Property Value

TypeDescription
BaseHandler

Name

The name of your game. It should match the one added in the RMB configuration file.

Declaration

public string Name { get; set; }

Property Value

TypeDescription
System.String

Players

Saved list of players before calling satellite's on AllPlayers Received. Always empty for the mothership.

Declaration

public List<string> Players { get; set; }

Property Value

TypeDescription
List<System.String>

Methods

CheckActive(String)

Internal use.

Declaration

protected bool CheckActive(string failedMsg)

Parameters

TypeNameDescription
System.StringfailedMsg

The message displayed in the case of a negative outcome.

Returns

TypeDescription
System.Boolean

false if the current connection is not active.

Connect(String, BaseHandler)

Reserved. It could be used for some custom behavior.

Declaration

protected bool Connect(string url, BaseHandler handler)

Parameters

TypeNameDescription
System.Stringurl

The connection url

BaseHandlerhandler

The main object used to work with the connection.

Returns

TypeDescription
System.Boolean

Connected(RoomBusConnection, Int32)

Called when connected to the rmb.

Declaration

public void Connected(RoomBusConnection conn, int peerID)

Parameters

TypeNameDescription
RoomBusConnectionconn

The connection object that was just connected

System.Int32peerID

The connection's unique identifier

Disconnected(RoomBusConnection)

Call when the connection is lost with the rmb. The actors library is designed to be hosted on the same machine as the rmb, this method will only be called if the RMB cashes.

Declaration

public bool Disconnected(RoomBusConnection conn)

Parameters

TypeNameDescription
RoomBusConnectionconn

The connection object that was just disconnected

Returns

TypeDescription
System.Boolean

true

IDAndBucketBytes(String, String)

Internal use.

Declaration

protected byte[] IDAndBucketBytes(string ID, string bucket = "")

Parameters

TypeNameDescription
System.StringID

generic identifier

System.Stringbucket

The bucket's name

Returns

TypeDescription
System.Byte[]

The bytes array containing the packed ID and bucket's name

OnChatMessages(RoomBusConnection, Byte[][])

Driver's stud method. never called.

Declaration

public void OnChatMessages(RoomBusConnection conn, byte[][] bytes)

Parameters

TypeNameDescription
RoomBusConnectionconn

main connection object

System.Byte[][]bytes

chat message bytes

OnCustomTargetSet(RoomBusConnection, Byte, String)

Called to link the custom target byte value with the current game.

Declaration

public void OnCustomTargetSet(RoomBusConnection conn, byte peerType, string name)

Parameters

TypeNameDescription
RoomBusConnectionconn

The connection that is delivering the data

System.BytepeerType

The custom target value used as a peer type to route data to your game.

System.Stringname

OnData(RoomBusConnection, Byte[])

Processed the received data and call the appropriate methods.

Declaration

public bool OnData(RoomBusConnection conn, byte[] bytes)

Parameters

TypeNameDescription
RoomBusConnectionconn

The connection object that is delivering the data

System.Byte[]bytes

The payload in bytes

Returns

TypeDescription
System.Boolean

false if an error occured, otherwise true is returned

OnError(Error, Exception, String)

Driver's stud method. never called.

Declaration

public void OnError(Error error, Exception ex, string msg)

Parameters

TypeNameDescription
Errorerror

custom error object

Exceptionex

passed exception

System.Stringmsg

text used to build the exception about to be thrown.

OnLatestScores(RoomBusConnection, Int32, Object[][])

Driver's stud method. never called.

Declaration

public bool OnLatestScores(RoomBusConnection conn, int limit, object[][] players)

Parameters

TypeNameDescription
RoomBusConnectionconn
System.Int32limit
System.Object[][]players

Returns

TypeDescription
System.Boolean

OnPlayerReject(RejectReason)

Driver's stud method. never called.

Declaration

public void OnPlayerReject(RejectReason reason)

Parameters

TypeNameDescription
RejectReasonreason

The rejection's reason

OnPlayersReady(RoomBusConnection, Byte[][])

Driver's stud method. never called.

Declaration

public void OnPlayersReady(RoomBusConnection conn, byte[][] infoJsons)

Parameters

TypeNameDescription
RoomBusConnectionconn

main network connection

System.Byte[][]infoJsons

players data

OnSession(String)

Driver's stud method. never called.

Declaration

public void OnSession(string session)

Parameters

TypeNameDescription
System.Stringsession

current session ID

OnTopPlayers(RoomBusConnection, Int32, Object[][])

Driver's stud method. never called.

Declaration

public bool OnTopPlayers(RoomBusConnection conn, int limit, object[][] players)

Parameters

TypeNameDescription
RoomBusConnectionconn

network TCP connection

System.Int32limit

N/A

System.Object[][]players

N/A

Returns

TypeDescription
System.Boolean

throws an exception instead

SendIntra(Byte[], IntraKey)

Internal use.

Declaration

protected bool SendIntra(byte[] payload, IntraKey key)

Parameters

TypeNameDescription
System.Byte[]payload

The message's payload

IntraKeykey

The message's key

Returns

TypeDescription
System.Boolean

false if an error occurs

Update()

basic update method, used to read and write data from and to the wire.

Declaration

public virtual void Update()