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

Classes

class  RoomListItem
 Represents a room data registered by Register. More...
 

Public Member Functions

delegate void CreateHandler (bool success, string roomID, uint roomCreatedTime)
 
delegate void JoinHandler (bool success, uint roomCreatedTime)
 
delegate void LeaveHandler (bool success)
 
delegate void MessageHandler (byte[] message)
 
delegate void UpdatePropsHandler (bool success)
 
delegate void GetPropsHandler (bool success, Dictionary< string, byte[]> props)
 
delegate void GetOwnerIDHandler (bool success, string ownerID)
 
delegate void IncrPropHandler (bool success, long numProp)
 
delegate void GetMemberIDsHandler (bool success, string ownerID, string[] memberIDs)
 
delegate void IncrPropertySyncHandler (long numProp)
 
delegate void GetNumberOfMembersHandler (bool success, string roomID, int number, int maxnumber)
 
delegate void ResponseHandler (bool success, byte[] msg)
 
delegate void FindRoomsHandler (bool success, List< RoomListItem > rooms)
 
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 SetTcp (Tcp tcp)
 Changes the TCP instance for the room. More...
 
bool SetUdp (Udp udp)
 Changes the UDP instance for the room. 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...
 
void UpdateProperties (string roomID, Dictionary< string, byte[]> props)
 Creates/Replaces room properties by the given property names. The property values are stored as byte array and retrieved as such. This raises OnUpdateProperties event. More...
 
void GetProperties (string roomID, List< string > propNames)
 Gets room properties created/replaced by UpdateProperties method. all property values are retrived as byte array. This raises OnGetProperties event. More...
 
void GetOwnerID ()
 Get the owner user ID of the room. The method raises OnGetOwnerID event. More...
 
void IncrProperty (string propName, long delta, bool sync)
 Increments pre-created long type room property of the matching property name by given delta. More...
 
void GetMemberIDs ()
 Raises OnGetMemberIDs event and retrieves a list of member IDs and the room owner ID. More...
 
void GetNumberOfMembers (string roomID)
 Rasies OnGetNumberOfMembers event and retrieves number of a room. You may retrieve the number of members of a room that you are not part of as well. More...
 
void Create (ushort maxMembers, bool allowEmpty, bool join, ushort ttl, uint interval=200)
 Creates a new room. More...
 
void Join (string roomID, byte[] message)
 Joins a room. A client can NOT join more than one room at a time. More...
 
void Migrate ()
 Migrates a rooom that the user is currently in. This operation can only be performed by the owner of the room. When successful, the owner user raises OnConnect event with reconnect flag true. All members of the room will automatically join the new migrated room without sending join broadcast. More...
 
void Move (string roomID, byte[] leaveMessage, byte[] joinMessage, Action< bool, uint > callback=null)
 Leaves the room that the client is currently in and joins a new room. Raises OnLeave and OnJoin and remotely raises OnMemberLeave and OnMemberJoin. You may callback use the callback instead of listening to the regular events. More...
 
void Register (uint roomType, string roomName, string roomMetadata)
 Registers a room (the client is already a member of) with a type (used by FindRoomsByType). OnRegister event will be raised. More...
 
void FindRoomsByType (uint roomType, uint limit)
 Finds a list of rooms that have been registered with a type. Raises OnFindRoomsByType event. More...
 
void Reserve (List< string > userIDs)
 Reserves the spots for the users in the target room. This operation is permitted only to the owner of the room. More...
 
void CancelReservation (List< string > userIDs)
 Cancel the reservations for the users in the target room. This operation is permitted only to the owner of the room. More...
 
void JoinRandom (ushort maxMembers, ushort ttl, byte[] message, uint interval=200)
 Joins a random room if there is at lease room created by JoinRandom available. If not it will create a new room. If it does not find a room to join, it will instead create a new room. More...
 
void Leave (byte[] message)
 Leaves the room the client has joined. More...
 
void Leave (string roomID, byte[] message)
 Leaves the room the client has joined. More...
 
void Broadcast (byte[] message, bool reliable=true)
 Sends a message to all members of the room including the sender. More...
 
void BroadcastTo (string roomID, byte[] message, bool reliable=true)
 Sends a message to all members of the room including the sender. It will raise OnMemberBroadcast. More...
 
void ExclusiveBroadcastTo (string roomID, byte[] message, bool reliable=true)
 Sends a message to all members of the room including the sender. It will raise OnMemberExclusiveBroadcast. More...
 
void ExclusiveMessageTo (string roomID, List< string > memberIDs, byte[] message, bool reliable=true)
 Sends a message to a selected members of the room. It raises OnMemberMessage<see>. More...
 
void MessageTo (List< string > memberIDs, byte[] message, bool reliable=true)
 Sends a message to a selected members of the room. It raises OnMemberMessage<see>. More...
 
void MessageTo (string roomID, List< string > memberIDs, byte[] message, bool reliable=true)
 Sends a message to a selected members of the room. More...
 
string GetRoomID ()
 Returns the room ID that the client has joined. More...
 
void SetRoomID (string roomID)
 Sets room ID manually. More...
 
void OnCustomMessagePush (uint ver, uint cmd, Action< byte[]> callback)
 Registers a callback on custom broadcast and/or message by ver and cmd. Must be callback AFTER group.SetupAsUdp or group.SetupAsTcp This is method is NOT compatible with Broadcast. Use with Message and/or Announce ONLY. More...
 

Public Attributes

byte[] _exclusiveHeader = new byte[4]{ 0xc, 0xa, 0xf, 0xe }
 When a message (Broadcast and Message) starts with _exclusiveHeader, OnMemberBroadcast and OnMemberMessage will not raise. More...
 

Protected Member Functions

void setupOnJoinEvent (uint ver, uint cmd)
 Sets up OnJoin event to ensure OnJoin event is triggered AFTER the reconnection (server to server transter of the client). Use this protected method to implement custom join commands. More...
 
void setRoomID (string roomID)
 Sets _roomID manually. More...
 
void setCreatedTime (uint createdTime)
 Sets _createdTime manually. More...
 

Static Protected Attributes

const uint BUILTIN_CMD_VER = 1
 
const uint CREATE_CMD = 100
 
const uint JOIN_CMD = 101
 
const uint LEAVE_CMD = 102
 
const uint BROADCAST_CMD = 103
 
const uint MESSAGE_CMD = 104
 
const uint UPDATE_PROP_CMD = 107
 
const uint GET_PROP_CMD = 108
 
const uint GET_OWNER_CMD = 109
 
const uint INCR_PROP_CMD = 10
 
const uint GET_MEMBERS_CMD = 11
 
const uint REG_ROOM_CMD = 115
 
const uint FIND_ROOMS_CMD = 116
 
const uint RESERVE_CMD = 117
 
const uint CANCEL_RES_CMD = 118
 
const uint MIGRATE_CMD = 12
 
const uint GET_NUM_OF_MEMBERS_CMD = 13
 

Events

CreateHandler OnCreate
 The event raised as a server response of Create. More...
 
JoinHandler OnJoin
 The event raised as a server response of Join. More...
 
LeaveHandler OnLeave
 The event raised as a server response of Leave. More...
 
MessageHandler OnMemberJoin
 The event raised when a remote client joins the room that you are in. More...
 
MessageHandler OnMemberLeave
 The event is raised when a remote member of the room you are in leaves the room. More...
 
MessageHandler OnMemberBroadcast
 The event is raised when a remote member client(s) of the room you are in sends a message via BroadcastTo. More...
 
MessageHandler OnMemberMessage
 The event is raised when a remote member client(s) of the room you are in sends a message via MessageTo. More...
 
UpdatePropsHandler OnUpdateProperties
 The event raised as a server response of UpdateProperties. More...
 
GetPropsHandler OnGetProperties
 The event raised as a server response of GetProperties. More...
 
GetOwnerIDHandler OnGetOwnerID
 The event raised as a server response of GetOwnerID. More...
 
IncrPropHandler OnIncrProperty
 The event raised as a server response of IncrProperty. More...
 
IncrPropertySyncHandler OnIncrPropertySync
 The event raised when a remote member client of the room successfully executes IncrPorperty. More...
 
GetMemberIDsHandler OnGetMemberIDs
 The event raised as a server response of GetMemberIDs. More...
 
ResponseHandler OnRegister
 The event raised as a server response of Register. More...
 
FindRoomsHandler OnFindRoomsByType
 The event raised as a server response of FindRoomByType. More...
 
ResponseHandler OnReserve
 The event raised as a server response of Reserve. More...
 
ResponseHandler OnCancelReservation
 The event raised as a server response of CancelReserve. More...
 
GetNumberOfMembersHandler OnGetNumberOfMembers
 
MessageHandler OnMemberExclusiveBroadcast
 
MessageHandler OnMemberExclusiveMessage
 

Detailed Description

Room allows clients in the same "room" to exchange packets freely.

Member Function Documentation

◆ Broadcast()

void Diarkis.Modules.Room.Broadcast ( byte[]  message,
bool  reliable = true 
)
inline

Sends a message to all members of the room including the sender.

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

◆ BroadcastTo()

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

Sends a message to all members of the room including the sender. It will raise OnMemberBroadcast.

Parameters
roomIDRoom ID of the room 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.

◆ CancelReservation()

void Diarkis.Modules.Room.CancelReservation ( List< string >  userIDs)
inline

Cancel the reservations for the users in the target room. This operation is permitted only to the owner of the room.

Parameters
userIDsList of user IDs to cancel the reservations in the room.

◆ Create()

void Diarkis.Modules.Room.Create ( ushort  maxMembers,
bool  allowEmpty,
bool  join,
ushort  ttl,
uint  interval = 200 
)
inline

Creates a new room.

Parameters
maxMembersMaximum number of clients allowed to join the room.
allowEmptyIf true, the room will not be destroyed immediately when it is empty of clients.
joinIf true, the creator client of the room is automatically added to the room as a member.
ttlTTL of the room when it is empty of members in seconds.
intervalBroadcast push interval in milliseconds. Default is 200ms. If 0 is given, broadcast packets will not be merged.

◆ Destroy()

void Diarkis.Modules.Room.Destroy ( )
inline

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

◆ ExclusiveBroadcastTo()

void Diarkis.Modules.Room.ExclusiveBroadcastTo ( string  roomID,
byte[]  message,
bool  reliable = true 
)
inline

Sends a message to all members of the room including the sender. It will raise OnMemberExclusiveBroadcast.

Parameters
roomIDRoom ID of the room 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.

◆ ExclusiveMessageTo()

void Diarkis.Modules.Room.ExclusiveMessageTo ( string  roomID,
List< string >  memberIDs,
byte[]  message,
bool  reliable = true 
)
inline

Sends a message to a selected members of the room. It raises OnMemberMessage<see>.

Parameters
roomIDRoom ID of the room that the message will be sent to.
memberIDsA list of member IDs to send the message to.
messageMessage to be sent.
reliableThis parameter is only relevant for UDP. If true, the message will be delivered as an RUDP message.

◆ FindRoomsByType()

void Diarkis.Modules.Room.FindRoomsByType ( uint  roomType,
uint  limit 
)
inline

Finds a list of rooms that have been registered with a type. Raises OnFindRoomsByType event.

Parameters
roomTypeA room type of find.
limitMaximum number of rooms to find by the given type.

◆ GetLastErrorMessage()

string Diarkis.Modules.Room.GetLastErrorMessage ( )
inline

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

◆ GetMemberIDs()

void Diarkis.Modules.Room.GetMemberIDs ( )
inline

Raises OnGetMemberIDs event and retrieves a list of member IDs and the room owner ID.

◆ GetNumberOfMembers()

void Diarkis.Modules.Room.GetNumberOfMembers ( string  roomID)
inline

Rasies OnGetNumberOfMembers event and retrieves number of a room. You may retrieve the number of members of a room that you are not part of as well.

◆ GetOwnerID()

void Diarkis.Modules.Room.GetOwnerID ( )
inline

Get the owner user ID of the room. The method raises OnGetOwnerID event.

◆ GetProperties()

void Diarkis.Modules.Room.GetProperties ( string  roomID,
List< string >  propNames 
)
inline

Gets room properties created/replaced by UpdateProperties method. all property values are retrived as byte array. This raises OnGetProperties event.

Parameters
roomIDRoom ID of the properties to be retrieved.
propNamesList of property names to be retrieved.

◆ GetRoomID()

string Diarkis.Modules.Room.GetRoomID ( )
inline

Returns the room ID that the client has joined.

◆ IncrProperty()

void Diarkis.Modules.Room.IncrProperty ( string  propName,
long  delta,
bool  sync 
)
inline

Increments pre-created long type room property of the matching property name by given delta.

Parameters
propNameProperty name to increment. Property must be a type int64.
deltaIncremenal value. If a negative value is given, it will subtruct instead.
syncIf true, the change will be broadcasted to the other members of the room. This will raise OnIncrPropertySync event.

◆ Join()

void Diarkis.Modules.Room.Join ( string  roomID,
byte[]  message 
)
inline

Joins a room. A client can NOT join more than one room at a time.

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

◆ JoinRandom()

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

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

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

◆ Leave() [1/2]

void Diarkis.Modules.Room.Leave ( byte[]  message)
inline

Leaves the room the client has joined.

Parameters
messageMessage that will be sent to the other members of the room when the client leaves the room.

◆ Leave() [2/2]

void Diarkis.Modules.Room.Leave ( string  roomID,
byte[]  message 
)
inline

Leaves the room the client has joined.

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

◆ MessageTo() [1/2]

void Diarkis.Modules.Room.MessageTo ( List< string >  memberIDs,
byte[]  message,
bool  reliable = true 
)
inline

Sends a message to a selected members of the room. It raises OnMemberMessage<see>.

Parameters
memberIDsA list of member IDs to send the message to.
messageMessage to be sent.
reliableThis parameter is only relevant for UDP. If true, the message will be delivered as an RUDP message.

◆ MessageTo() [2/2]

void Diarkis.Modules.Room.MessageTo ( string  roomID,
List< string >  memberIDs,
byte[]  message,
bool  reliable = true 
)
inline

Sends a message to a selected members of the room.

Parameters
roomIDRoom ID of the room that the message will be sent to.
Parameters
memberIDsA list of member IDs to send the message to.
messageMessage to be sent.
reliableThis parameter is only relevant for UDP. If true, the message will be delivered as an RUDP message.

◆ Migrate()

void Diarkis.Modules.Room.Migrate ( )
inline

Migrates a rooom that the user is currently in. This operation can only be performed by the owner of the room. When successful, the owner user raises OnConnect event with reconnect flag true. All members of the room will automatically join the new migrated room without sending join broadcast.

◆ Move()

void Diarkis.Modules.Room.Move ( string  roomID,
byte[]  leaveMessage,
byte[]  joinMessage,
Action< bool, uint >  callback = null 
)
inline

Leaves the room that the client is currently in and joins a new room. Raises OnLeave and OnJoin and remotely raises OnMemberLeave and OnMemberJoin. You may callback use the callback instead of listening to the regular events.

Parameters
roomIDA room ID to join
leaveMessageA byte array message to be broadcasted on leave.
Parameters
joinMessageA byte array message to be broadcasted on join.
callbackAn optional callback to be invoked when successfully joined a new room or failed to leave or join.

◆ OnCustomMessagePush()

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

Registers a callback on custom broadcast and/or message by ver and cmd. Must be callback AFTER group.SetupAsUdp or group.SetupAsTcp This is method is NOT compatible with Broadcast. Use with Message and/or Announce ONLY.

◆ Register()

void Diarkis.Modules.Room.Register ( uint  roomType,
string  roomName,
string  roomMetadata 
)
inline

Registers a room (the client is already a member of) with a type (used by FindRoomsByType). OnRegister event will be raised.

Parameters
roomTypeRoom type to be used by FindRoomsByType.
roomNameA name of the room registered.
roomMetadataExtra string data for the room registered.

◆ Reserve()

void Diarkis.Modules.Room.Reserve ( List< string >  userIDs)
inline

Reserves the spots for the users in the target room. This operation is permitted only to the owner of the room.

Parameters
userIDsList of user IDs to reserve the spots in the room.

◆ setCreatedTime()

void Diarkis.Modules.Room.setCreatedTime ( uint  createdTime)
inlineprotected

Sets _createdTime manually.

◆ setRoomID()

void Diarkis.Modules.Room.setRoomID ( string  roomID)
inlineprotected

Sets _roomID manually.

◆ SetRoomID()

void Diarkis.Modules.Room.SetRoomID ( string  roomID)
inline

Sets room ID manually.

◆ SetTcp()

bool Diarkis.Modules.Room.SetTcp ( Tcp  tcp)
inline

Changes the TCP instance for the room.

Parameters
tcpThe new TCP instance.

◆ SetUdp()

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

Changes the UDP instance for the room.

Parameters
udpThe new UDP instance.

◆ SetupAsTcp()

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

Sets up the instance of as a TCP client.

Parameters
tcpAn instance of Tcp

◆ SetupAsUdp()

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

Sets up the instance of as a UDP client.

Parameters
udpAn instance of Udp

◆ setupOnJoinEvent()

void Diarkis.Modules.Room.setupOnJoinEvent ( uint  ver,
uint  cmd 
)
inlineprotected

Sets up OnJoin event to ensure OnJoin event is triggered AFTER the reconnection (server to server transter of the client). Use this protected method to implement custom join commands.

◆ UpdateProperties()

void Diarkis.Modules.Room.UpdateProperties ( string  roomID,
Dictionary< string, byte[]>  props 
)
inline

Creates/Replaces room properties by the given property names. The property values are stored as byte array and retrieved as such. This raises OnUpdateProperties event.

Parameters
roomIDRoom ID of create/replace its properties.
propsDictionary of room properties to be created/replaced.

Member Data Documentation

◆ _exclusiveHeader

byte [] Diarkis.Modules.Room._exclusiveHeader = new byte[4]{ 0xc, 0xa, 0xf, 0xe }

When a message (Broadcast and Message) starts with _exclusiveHeader, OnMemberBroadcast and OnMemberMessage will not raise.

Event Documentation

◆ OnCancelReservation

ResponseHandler Diarkis.Modules.Room.OnCancelReservation

The event raised as a server response of CancelReserve.

Parameters
successIndicates if the operation on the server was success or failure.
msgError message byte array if success was false.

◆ OnCreate

CreateHandler Diarkis.Modules.Room.OnCreate

The event raised as a server response of Create.

Parameters
successIndicates if the operation on the server was success or failure.
roomCreatedTimePrepresents the server time of room creation in seconds.

◆ OnFindRoomsByType

FindRoomsHandler Diarkis.Modules.Room.OnFindRoomsByType

The event raised as a server response of FindRoomByType.

Parameters
successIndicates if the operation on the server was success or failure.
roomsA list of rooms found.

◆ OnGetMemberIDs

GetMemberIDsHandler Diarkis.Modules.Room.OnGetMemberIDs

The event raised as a server response of GetMemberIDs.

Parameters
successIndicates if the operation on the server was success or failure.
ownerIDThe room owner ID.
memberIDsAn array of member IDs.

◆ OnGetNumberOfMembers

GetNumberOfMembersHandler Diarkis.Modules.Room.OnGetNumberOfMembers
Parameters
successIndicates if the operation on the server was success or failure.
roomIDThe room ID.
numberNumber of current members.
maxnumberMaximum number of members allowed.

◆ OnGetOwnerID

GetOwnerIDHandler Diarkis.Modules.Room.OnGetOwnerID

The event raised as a server response of GetOwnerID.

Parameters
successIndicates if the operation on the server was success or failure.
ownerIDThe owner ID of the room that you are in.

◆ OnGetProperties

GetPropsHandler Diarkis.Modules.Room.OnGetProperties

The event raised as a server response of GetProperties.

Parameters
successIndicates if the operation on the server was success or failure.
propsA dictionary that contains all requested room properties..

◆ OnIncrProperty

IncrPropHandler Diarkis.Modules.Room.OnIncrProperty

The event raised as a server response of IncrProperty.

Parameters
successIndicates if the operation on the server was success or failure.
numPropUpdated property value.

◆ OnIncrPropertySync

IncrPropertySyncHandler Diarkis.Modules.Room.OnIncrPropertySync

The event raised when a remote member client of the room successfully executes IncrPorperty.

Parameters
numPropUpdated property value.

◆ OnJoin

JoinHandler Diarkis.Modules.Room.OnJoin

The event raised as a server response of Join.

`

Parameters
successIndicates if the operation on the server was success or failure.
roomCreatedTimePrepresents the server time of room creation in seconds.

◆ OnLeave

LeaveHandler Diarkis.Modules.Room.OnLeave

The event raised as a server response of Leave.

Parameters
successIndicates if the operation on the server was success or failure.

◆ OnMemberBroadcast

MessageHandler Diarkis.Modules.Room.OnMemberBroadcast

The event is raised when a remote member client(s) of the room you are in sends a message via BroadcastTo.

Parameters
messageA byte array message from a remote member client.

◆ OnMemberJoin

MessageHandler Diarkis.Modules.Room.OnMemberJoin

The event raised when a remote client joins the room that you are in.

Parameters
messageA message from the newly join remote client as a byte array. The message is the same message byte array sent from Join.

◆ OnMemberLeave

MessageHandler Diarkis.Modules.Room.OnMemberLeave

The event is raised when a remote member of the room you are in leaves the room.

Parameters
messageA message from the member client that has just left the room you are in. The message is the same message byte array sent from Leave.

◆ OnMemberMessage

MessageHandler Diarkis.Modules.Room.OnMemberMessage

The event is raised when a remote member client(s) of the room you are in sends a message via MessageTo.

Parameters
messageA byte array message from a remote member client.

◆ OnRegister

ResponseHandler Diarkis.Modules.Room.OnRegister

The event raised as a server response of Register.

Parameters
successIndicates if the operation on the server was success or failure.
msgError message byte array if success was false.

◆ OnReserve

ResponseHandler Diarkis.Modules.Room.OnReserve

The event raised as a server response of Reserve.

Parameters
successIndicates if the operation on the server was success or failure.
msgError message byte array if success was false.

◆ OnUpdateProperties

UpdatePropsHandler Diarkis.Modules.Room.OnUpdateProperties

The event raised as a server response of UpdateProperties.

Parameters
successIndicates if the operation on the server was success or failure.
propsThe dictionary that contains update properties.

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