Diarkis C# Client SDK
Public Member Functions | Static Protected Attributes | Events | List of all members
Diarkis.Modules.Group Class Reference

Public Member Functions

delegate void CreateHandler (bool success, string groupID, byte[] payload)
 
delegate void ResponseHandler (bool success, string groupID, byte[] payload)
 
delegate void MessageHandler (byte[] message)
 
bool SetupAsTcp (Tcp tcp)
 Sets up the instance of as a TCP client. More...
 
bool SetupAsUdp (Udp udp)
 Sets up the instance of as a UDP client. More...
 
bool SetUdp (Tcp tcp)
 Changes the TCP instance for the group. More...
 
bool SetUdp (Udp udp)
 Changes the UDP instance for the group. More...
 
void Destroy ()
 Destroy all setup listeners and other internal properties. You will need to call SetupAs... to reuse the instance. More...
 
string GetLastErrorMessage ()
 Returns a last error message of either Create, Join, JoinRandom, Leave etc. More...
 
List< string > GetGroupIDs ()
 Rerturns the list of group IDs that the client has joined. The returned list is a reference, please becareful with it. More...
 
void Create (bool allowEmpty, bool join, ushort ttl)
 Creates a new group. More...
 
void Join (string groupID, byte[] message)
 Joins a group. A client can join multiple groups at a time. More...
 
void JoinRandom (ushort ttl, byte[] message, uint interval=200)
 Joins a random group if there is at least a group created by JoinRandom available. If not it will create a new group. If it does not find a group to join, it will instead create a new group. More...
 
void Leave (string groupID, byte[] message)
 Leaves the group the client has joined. More...
 
void BroadcastTo (string groupID, byte[] message, bool reliable=true)
 Sends a message to all members of the group. More...
 
void OnCustomBroadcast (uint ver, uint cmd, Action< byte[]> callback)
 Registers a callback on custom broadcast by ver and cmd More...
 

Static Protected Attributes

const uint BUILTIN_CMD_VER = 1
 
const uint CREATE_CMD = 110
 
const uint JOIN_CMD = 111
 
const uint LEAVE_CMD = 112
 
const uint BROADCAST_CMD = 113
 

Events

CreateHandler OnCreate
 The event raised as a server response of Create. More...
 
ResponseHandler OnJoin
 The event raised as a server response of Join. More...
 
ResponseHandler OnLeave
 The event raised as a server response of Leave. More...
 
MessageHandler OnMemberJoin
 The event is raised when a remote client joins the group. More...
 
MessageHandler OnMemberLeave
 The event is raised when a remote client leaves the group. More...
 
MessageHandler OnMemberBroadcast
 The event raised when a remote client sends a broadcast message via BroadcastTo. More...
 

Detailed Description

Group allows clients to exchange packets freely within the same "group".

Member Function Documentation

◆ BroadcastTo()

void Diarkis.Modules.Group.BroadcastTo ( string  groupID,
byte[]  message,
bool  reliable = true 
)
inline

Sends a message to all members of the group.

Parameters
groupIDGroup ID of the group that the message will be sent to.
messageMessage to be sent.
reliableThis parameter is only relevant for UDP. If true, the message will be delivered as an RUDP message.

◆ Create()

void Diarkis.Modules.Group.Create ( bool  allowEmpty,
bool  join,
ushort  ttl 
)
inline

Creates a new group.

Parameters
allowEmptyIf true, the group will not be destroyed immediately when it is empty of clients.
joinIf true, the creator client of the group is automatically added to the group as a member.
ttlTTL of the group when it is empty of members in seconds.

◆ Destroy()

void Diarkis.Modules.Group.Destroy ( )
inline

Destroy all setup listeners and other internal properties. You will need to call SetupAs... to reuse the instance.

◆ GetGroupIDs()

List<string> Diarkis.Modules.Group.GetGroupIDs ( )
inline

Rerturns the list of group IDs that the client has joined. The returned list is a reference, please becareful with it.

◆ GetLastErrorMessage()

string Diarkis.Modules.Group.GetLastErrorMessage ( )
inline

Returns a last error message of either Create, Join, JoinRandom, Leave etc.

◆ Join()

void Diarkis.Modules.Group.Join ( string  groupID,
byte[]  message 
)
inline

Joins a group. A client can join multiple groups at a time.

Parameters
groupIDGroup ID that the client will try to join.
messageMessage that will be sent to the other members of the group when the client joins the group.

◆ JoinRandom()

void Diarkis.Modules.Group.JoinRandom ( ushort  ttl,
byte[]  message,
uint  interval = 200 
)
inline

Joins a random group if there is at least a group created by JoinRandom available. If not it will create a new group. If it does not find a group to join, it will instead create a new group.

Parameters
ttlTTL of the group when it is empty of members in seconds.
messageMessage that will be sent to the other members of the group when the client joins the group.
intervalBroadcast push interval in milliseconds. Default is 200ms. If 0 is given, broadcast packets will not be merged.

◆ Leave()

void Diarkis.Modules.Group.Leave ( string  groupID,
byte[]  message 
)
inline

Leaves the group the client has joined.

Parameters
groupIDGroup ID that the client will try to leave from.
messageMessage that will be sent to the other members of the group when the client leaves the group.

◆ OnCustomBroadcast()

void Diarkis.Modules.Group.OnCustomBroadcast ( uint  ver,
uint  cmd,
Action< byte[]>  callback 
)
inline

Registers a callback on custom broadcast by ver and cmd

Parameters
verCustom command version to listen to.
cmdCustom command ID to listen to.
callbackCallback method to be invoked on targeted ver and cmd.

◆ SetUdp() [1/2]

bool Diarkis.Modules.Group.SetUdp ( Tcp  tcp)
inline

Changes the TCP instance for the group.

Parameters
tcpThe new TCP instance.

◆ SetUdp() [2/2]

bool Diarkis.Modules.Group.SetUdp ( Udp  udp)
inline

Changes the UDP instance for the group.

Parameters
udpThe new UDP instance.

◆ SetupAsTcp()

bool Diarkis.Modules.Group.SetupAsTcp ( Tcp  tcp)
inline

Sets up the instance of as a TCP client.

Parameters
tcpAn instance of Tcp

◆ SetupAsUdp()

bool Diarkis.Modules.Group.SetupAsUdp ( Udp  udp)
inline

Sets up the instance of as a UDP client.

Parameters
udpAn instance of Udp

Event Documentation

◆ OnCreate

CreateHandler Diarkis.Modules.Group.OnCreate

The event raised as a server response of Create.

Parameters
successIndicates server operation success or failure.
groupIDGroup ID of the group that was created.

◆ OnJoin

ResponseHandler Diarkis.Modules.Group.OnJoin

The event raised as a server response of Join.

Parameters
successIndicates server operation success or failure.
groupIDGroup ID of the group that was created.

◆ OnLeave

ResponseHandler Diarkis.Modules.Group.OnLeave

The event raised as a server response of Leave.

Parameters
successIndicates server operation success or failure.
groupIDGroup ID of the group that was created.

◆ OnMemberBroadcast

MessageHandler Diarkis.Modules.Group.OnMemberBroadcast

The event raised when a remote client sends a broadcast message via BroadcastTo.

Parameters
messageA message byte array sent from the remote member client.

◆ OnMemberJoin

MessageHandler Diarkis.Modules.Group.OnMemberJoin

The event is raised when a remote client joins the group.

Parameters
messageA message byte array sent from the newly joined remote client.

◆ OnMemberLeave

MessageHandler Diarkis.Modules.Group.OnMemberLeave

The event is raised when a remote client leaves the group.

Parameters
messageA message byte array sent from the remote client that left the group.

The documentation for this class was generated from the following file: