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

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...
 
virtual 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...
 
byte[] GetLastErrorBytes ()
 Returns a last error message bytes 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...
 
virtual void Create (bool allowEmpty, bool join, ushort ttl)
 Creates a new group. More...
 
virtual void Join (string groupID, byte[] message)
 Joins a group. A client can join multiple groups at a time. More...
 
virtual 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...
 
virtual void Leave (string groupID, byte[] message)
 Leaves the group the client has joined. More...
 
virtual 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...
 

Protected Attributes

List< string > _groupIDs
 
string _lastErrMessage = ""
 

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
 
const uint STATUS_OK = 1
 
const uint RAND_JOIN_CMD = 114
 

Events

virtual CreateHandler OnCreate
 The event raised as a server response of Create. More...
 
virtual ResponseHandler OnJoin
 The event raised as a server response of Join. More...
 
virtual ResponseHandler OnLeave
 The event raised as a server response of Leave. More...
 
virtual MessageHandler OnMemberJoin
 The event is raised when a remote client joins the group. More...
 
virtual MessageHandler OnMemberLeave
 The event is raised when a remote client leaves the group. More...
 
virtual 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()

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

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.

Reimplemented in Diarkis.Modules.WsGroup.

◆ Create()

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

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.

Reimplemented in Diarkis.Modules.WsGroup.

◆ Destroy()

virtual void Diarkis.Modules.Group.Destroy ( )
inlinevirtual

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

Reimplemented in Diarkis.Modules.WsGroup.

◆ 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.

◆ GetLastErrorBytes()

byte [] Diarkis.Modules.Group.GetLastErrorBytes ( )
inline

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

◆ GetLastErrorMessage()

string Diarkis.Modules.Group.GetLastErrorMessage ( )
inline

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

◆ Join()

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

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.

Reimplemented in Diarkis.Modules.WsGroup.

◆ JoinRandom()

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

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.

Reimplemented in Diarkis.Modules.WsGroup.

◆ Leave()

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

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.

Reimplemented in Diarkis.Modules.WsGroup.

◆ 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

virtual 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

virtual 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

virtual 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

virtual 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

virtual 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

virtual 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: