Diarkis C# Client SDK
Public Member Functions | Events | List of all members
Diarkis.Modules.WsRoom Class Reference
Inheritance diagram for Diarkis.Modules.WsRoom:
Diarkis.Modules.Room

Public Member Functions

bool Setup (Ws ws)
 
override void Destroy ()
 Destroy all setup listeners and other internal properties. You will need to call SetupAs... to reuse the instance. More...
 
override void Create (ushort maxMembers, bool allowEmpty, bool join, ushort ttl, uint interval=200)
 Creates a new room. More...
 
override 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...
 
override void FindRoomsByType (uint roomType, uint limit)
 Finds a list of rooms that have been registered with a type. Raises OnFindRoomsByType event. More...
 
override 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...
 
override 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...
 
override void UpdateProperties (string roomID, Dictionary< string, byte[]> props, bool sync)
 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...
 
override void SyncProperties ()
 Retrieve properties of the room. Raises OnPropertySync. Only properties with byte array value will be synchronized. More...
 
override void Join (string roomID, byte[] message)
 Joins a room. A client can NOT join more than one room at a time. More...
 
override void JoinRandom (ushort maxMembers, ushort ttl, byte[] message, bool allowEmpty=false, 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...
 
override void Leave (string roomID, byte[] message)
 Leaves the room the client has joined. More...
 
override void BroadcastTo (string roomID, byte[] message, bool reliable=true)
 Sends a message to all members of the room including the sender. More...
 
override void MessageTo (string roomID, List< string > memberIDs, byte[] message, bool reliable=true)
 Sends a message to a selected members of the room. More...
 
override void MessageTo (List< string > memberIDs, byte[] message, bool reliable=true)
 
override void IncrProperty (string propName, long delta, bool sync)
 Increments pre-created long type room property of the matching property name by given delta. More...
 
override void SyncObjects ()
 Retrieves all room objects with their names and values. OnSyncObjects event will be raised. More...
 
override void UpdateObject (byte mode, string name, Dictionary< string, double > obj, bool reliable)
 Manipulates a room object by its name. Successful execution of the operation raises OnObjectUpdate event on all room members including itself. There are 3 modes to manipulate a room object: More...
 
override void GetMemberIDs ()
 Raises OnGetMemberIDs event and retrieves a list of member IDs and the room owner ID. More...
 
override 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...
 
- Public Member Functions inherited from Diarkis.Modules.Room
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)
 
delegate void ChatHandler (RoomChatData chatData)
 
delegate void ChatLogHandler (bool success, List< RoomChatData > chatLog, byte[] payload)
 
delegate void P2PSyncHandler (bool success, Packet.P2PClientAddr[] p2pClientAddrs)
 
delegate void ObjUpdateHandler (byte mode, string name, Dictionary< string, double > obj)
 
delegate void ObjSyncHandler (bool success, Dictionary< string, Dictionary< string, double >> objects)
 
delegate void PropertySyncHandler (bool success, Dictionary< string, byte[]> props)
 
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...
 
string GetLastErrorMessage ()
 Returns a last error message of either Create, Join, JoinRandom, Leave etc. More...
 
byte[] GetLastErrorBytes ()
 Returns a last error payload of either Create, Join, JoinRandom, Leave etc. More...
 
bool StartP2PSync (byte linkedClients=0)
 Starts peer-to-peer comminucations with the remote clients in the same room. This method raises OnStartP2PSync event. More...
 
virtual 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...
 
virtual void GetOwnerID ()
 Get the owner user ID of the room. The method raises OnGetOwnerID event. More...
 
virtual 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 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...
 
virtual void CancelReservation (string roomID, List< string > userIDs)
 Cancel the reservations for the users in the target room. More...
 
virtual void Leave (byte[] message)
 Leaves the room the client has joined. More...
 
virtual void Broadcast (byte[] message, bool reliable=true)
 Sends a message to all members of the room including the sender. 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. More...
 
void Relay (byte[] message, bool reliable=false)
 Sends a message to all other members of the room except the sender. More...
 
void RelayProfile (byte[] message, bool reliable=false)
 Sends a message to all other members of the room except the sender. More...
 
virtual void SendChatMessage (string message)
 Sends a chat message to the members of the room. All chat messages will be stored on the server and can be retrieved by GetChatLog. OnChatSyncResponse will be raised as the response from the server, and OnChatSyncwill be raised on the remote member clients as they receive the chat message. More...
 
virtual void GetChatLog ()
 Retrieves all chat messages as a list. OnChatLog will be raised. 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...
 

Events

override CreateHandler OnCreate
 
override JoinHandler OnJoin
 
override LeaveHandler OnLeave
 
override MessageHandler OnMemberJoin
 
override MessageHandler OnMemberLeave
 
override MessageHandler OnMemberBroadcast
 
override MessageHandler OnMemberMessage
 
override UpdatePropsHandler OnUpdateProperties
 
override GetPropsHandler OnGetProperties
 
override GetOwnerIDHandler OnGetOwnerID
 
override IncrPropHandler OnIncrProperty
 
override IncrPropertySyncHandler OnIncrPropertySync
 
override GetMemberIDsHandler OnGetMemberIDs
 
override ResponseHandler OnRegister
 
override FindRoomsHandler OnFindRoomsByType
 
override ResponseHandler OnReserve
 
override ResponseHandler OnCancelReservation
 
override ObjUpdateHandler OnObjectUpdate
 
override ObjSyncHandler OnObjectSync
 
override PropertySyncHandler OnPropertySync
 
- Events inherited from Diarkis.Modules.Room
MessageHandler OnRelay
 The event raised when the client receives a relay message from another room member. More...
 
MessageHandler OnRelayProfile
 The event raised when the client receives a relay profile message from another room member. More...
 
virtual CreateHandler OnCreate
 The event raised as a server response of Create. More...
 
virtual JoinHandler OnJoin
 The event raised as a server response of Join. More...
 
virtual LeaveHandler OnLeave
 The event raised as a server response of Leave. More...
 
virtual MessageHandler OnMemberJoin
 The event raised when a remote client joins the room that you are in. More...
 
virtual MessageHandler OnMemberLeave
 The event is raised when a remote member of the room you are in leaves the room. More...
 
virtual MessageHandler OnMemberBroadcast
 The event is raised when a remote member client(s) of the room you are in sends a message via BroadcastTo. More...
 
virtual MessageHandler OnMemberMessage
 The event is raised when a remote member client(s) of the room you are in sends a message via MessageTo. More...
 
virtual UpdatePropsHandler OnUpdateProperties
 The event raised as a server response of UpdateProperties. More...
 
GetPropsHandler OnUpdatePropertySync
 The event raised when properties are updated with sync flag. More...
 
virtual GetPropsHandler OnGetProperties
 The event raised as a server response of GetProperties. More...
 
virtual GetOwnerIDHandler OnGetOwnerID
 The event raised as a server response of GetOwnerID. More...
 
virtual IncrPropHandler OnIncrProperty
 The event raised as a server response of IncrProperty. More...
 
virtual IncrPropertySyncHandler OnIncrPropertySync
 The event raised when a remote member client of the room successfully executes IncrPorperty. More...
 
virtual GetMemberIDsHandler OnGetMemberIDs
 The event raised as a server response of GetMemberIDs. More...
 
virtual ResponseHandler OnRegister
 The event raised as a server response of Register. More...
 
virtual FindRoomsHandler OnFindRoomsByType
 The event raised as a server response of FindRoomByType. More...
 
virtual ResponseHandler OnReserve
 The event raised as a server response of Reserve. More...
 
virtual ResponseHandler OnCancelReservation
 The event raised as a server response of CancelReserve. More...
 
virtual GetNumberOfMembersHandler OnGetNumberOfMembers
 
virtual ResponseHandler OnChatSyncResponse
 Event raised when SendChatMessage is called. More...
 
virtual ChatHandler OnChatSync
 Event raised when a chat message from a remote member is received. More...
 
virtual ChatLogHandler OnChatLog
 Event raised when GetChatLog sends the history log of chat messages. More...
 
virtual P2PSyncHandler OnStartP2PSync
 Event raised when StartP2PSync is successfully invoked. The event callback receives a list of remote clients to start peer-to-peer with. More...
 
virtual ObjUpdateHandler OnObjectUpdate
 Event raised when UpdateObject is used to manipulate a room object. Any member of the room may maniplulate room objects and the event is raised. The event passes down the manipulated room object along with its name and value with mode that was used. There are 3 modes of manipulations: More...
 
virtual PropertySyncHandler OnPropertySync
 Event raised when SyncProperties is used to retrieve existing properties in the room. Only properties with byte array value will be synchronized. More...
 
virtual ObjSyncHandler OnObjectSync
 Event raised when SyncObjects is used as a response from the server. The event returns all room objects with their current values. More...
 
virtual GetOwnerIDHandler OnOwnerChange
 Event raised when a new room owner has been elected by the server. More...
 
virtual MessageHandler OnMemberExclusiveBroadcast
 
virtual MessageHandler OnMemberExclusiveMessage
 

Additional Inherited Members

- Public Attributes inherited from Diarkis.Modules.Room
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...
 
- Static Public Attributes inherited from Diarkis.Modules.Room
const byte OBJ_INC_MODE = 0x01
 
const byte OBJ_SET_MODE = 0x02
 
const byte OBJ_DEL_MODE = 0x03
 
- Protected Member Functions inherited from Diarkis.Modules.Room
void setRoomID (string roomID)
 Sets _roomID manually. More...
 
void setCreatedTime (uint createdTime)
 Sets _createdTime manually. More...
 
- Protected Attributes inherited from Diarkis.Modules.Room
string _roomID
 
uint _createdTime = 0
 
string _lastErrMessage = ""
 
byte[] _lastErrBytes = new byte[0]
 
- Static Protected Attributes inherited from Diarkis.Modules.Room
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
 
const uint OWNER_CHANGE_CMD = 14
 
const uint CHAT_CMD = 125
 
const uint CHAT_LOG_CMD = 126
 
const uint OBJ_SYNC_CMD = 128
 
const uint OBJ_UPDATE_CMD = 129
 
const uint PROP_SYNC_CMD = 130
 
const uint RELAY_CMD = 18
 
const uint RELAY_PROFILE_CMD = 19
 
const uint STATUS_OK = 1
 
const uint RAND_CREATE_CMD = 105
 
const uint RAND_JOIN_CMD = 106
 

Member Function Documentation

◆ BroadcastTo()

override void Diarkis.Modules.WsRoom.BroadcastTo ( string  roomID,
byte[]  message,
bool  reliable = true 
)
inlinevirtual

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

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.

Reimplemented from Diarkis.Modules.Room.

◆ CancelReservation()

override void Diarkis.Modules.WsRoom.CancelReservation ( List< string >  userIDs)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ Create()

override void Diarkis.Modules.WsRoom.Create ( ushort  maxMembers,
bool  allowEmpty,
bool  join,
ushort  ttl,
uint  interval = 200 
)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ Destroy()

override void Diarkis.Modules.WsRoom.Destroy ( )
inlinevirtual

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

Reimplemented from Diarkis.Modules.Room.

◆ FindRoomsByType()

override void Diarkis.Modules.WsRoom.FindRoomsByType ( uint  roomType,
uint  limit 
)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ GetMemberIDs()

override void Diarkis.Modules.WsRoom.GetMemberIDs ( )
inlinevirtual

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

Reimplemented from Diarkis.Modules.Room.

◆ IncrProperty()

override void Diarkis.Modules.WsRoom.IncrProperty ( string  propName,
long  delta,
bool  sync 
)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ Join()

override void Diarkis.Modules.WsRoom.Join ( string  roomID,
byte[]  message 
)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ JoinRandom()

override void Diarkis.Modules.WsRoom.JoinRandom ( ushort  maxMembers,
ushort  ttl,
byte[]  message,
bool  allowEmpty = false,
uint  interval = 200 
)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ Leave()

override void Diarkis.Modules.WsRoom.Leave ( string  roomID,
byte[]  message 
)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ MessageTo() [1/2]

override void Diarkis.Modules.WsRoom.MessageTo ( List< string >  memberIDs,
byte[]  message,
bool  reliable = true 
)
inlinevirtual
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.

Reimplemented from Diarkis.Modules.Room.

◆ MessageTo() [2/2]

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

Sends a message to a selected members of the room.

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.

Reimplemented from Diarkis.Modules.Room.

◆ Migrate()

override void Diarkis.Modules.WsRoom.Migrate ( )
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ Register()

override void Diarkis.Modules.WsRoom.Register ( uint  roomType,
string  roomName,
string  roomMetadata 
)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ Reserve()

override void Diarkis.Modules.WsRoom.Reserve ( List< string >  userIDs)
inlinevirtual

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.

Reimplemented from Diarkis.Modules.Room.

◆ SyncObjects()

override void Diarkis.Modules.WsRoom.SyncObjects ( )
inlinevirtual

Retrieves all room objects with their names and values. OnSyncObjects event will be raised.

Reimplemented from Diarkis.Modules.Room.

◆ SyncProperties()

override void Diarkis.Modules.WsRoom.SyncProperties ( )
inlinevirtual

Retrieve properties of the room. Raises OnPropertySync. Only properties with byte array value will be synchronized.

Reimplemented from Diarkis.Modules.Room.

◆ UpdateObject()

override void Diarkis.Modules.WsRoom.UpdateObject ( byte  mode,
string  name,
Dictionary< string, double >  obj,
bool  reliable 
)
inlinevirtual

Manipulates a room object by its name. Successful execution of the operation raises OnObjectUpdate event on all room members including itself. There are 3 modes to manipulate a room object:

  • OBJ_SET_MODE creates or replaces a room object by the given properties.
  • OBJ_INC_MODE increments an existing room object's properties.
  • OBJ_DEL_MODE deletes a room object by its name.
Parameters
modeDecides which mode of manipluation to execute.
  • OBJ_SET_MODE creates or replaces a room object by the given properties.
  • OBJ_INC_MODE increments an existing room object's properties.
  • OBJ_DEL_MODE deletes a room object by its name.
nameName of the object.
objThe object is represented as a dictionary and its keys and values represent the properties of the object.
// Object property as a dictionary
obj["x"] = 123.4;
obj["y"] = 567.8;
obj["hp"] = 300;
OBJ_DEL_MODE does not use this parameter because it deletes the target room object.
reliableFlag to decided if the operation command packet will be RUDP or UDP. True will sewnd the packet as an RUDP packet. [IMPORTANT] This is only applicable with UDP client.

Reimplemented from Diarkis.Modules.Room.

◆ UpdateProperties()

override void Diarkis.Modules.WsRoom.UpdateProperties ( string  roomID,
Dictionary< string, byte[]>  props,
bool  sync 
)
inlinevirtual

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.
syncIf true, the updated properties will be synchronized by raising OnUpdatePropertySync event.

Reimplemented from Diarkis.Modules.Room.


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