...

Package room

import "github.com/Diarkis/diarkis/room"
Overview
Index
Subdirectories

Overview ▾

Index ▾

func AfterBroadcastRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func AfterCreateRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func AfterGetRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func AfterJoinRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func AfterLeaveRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func AfterMessageRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func AfterUpdateRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func Announce(roomID string, memberIDs []string, ver uint8, cmd uint16, message []byte, reliable bool)
func BeforeBroadcastRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func BeforeCreateRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func BeforeGetRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func BeforeJoinRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func BeforeLeaveRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func BeforeMessageRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func BeforeUpdateRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))
func Broadcast(roomID string, senderUser *user.User, ver uint8, cmd uint16, message []byte, reliable bool)
func CancelReservation(roomID string, userData *user.User, memberIDs []string, mustBeOwner bool) error
func CancelReservationRemote(roomID string, userData *user.User, memberIDs []string, mustBeOwner bool, cb func(error))
func ChangeTTL(roomID string, ttl int64) bool
func DeleteRoom(roomID string, userData *user.User, ver uint8, cmd uint16, message []byte)
func Exists(roomID string) bool
func ExposeCommands()
func GetAllRoomIDsOnNode() []string
func GetChatHistory(roomID string) [][]string
func GetCreatedTime(roomID string) int64
func GetMapping(roomID string) *mapping.Mapping
func GetMemberByID(roomID string, id string) *user.User
func GetMemberIDs(roomID string) []string
func GetMemberIDsAndOwner(roomID string) ([]string, string, string)
func GetMemberSIDs(roomID string) []string
func GetMemberSIDsAndOwner(roomID string) ([]string, string, string)
func GetMemberUsers(roomID string) []*user.User
func GetMemberUsersAndOwnerUser(roomID string) ([]*user.User, *user.User)
func GetNumberOfRoomMembers(roomID string, callback func(error, int, int))
func GetProperties(roomID string) map[string]interface{}
func GetProperty(roomID string, name string) interface{}
func GetRemoteProperties(roomID string, cb func(error, map[string]interface{}))
func GetRemoteProperty(roomID string, name string, cb func(error, interface{}))
func GetRoomID(userData *user.User) string
func GetRoomNodeAddressList(roomID string) ([]string, error)
func GetRoomOwnerID(roomID string) string
func IncrProperty(roomID string, propName string, delta int64) bool
func IsReserved(roomID string, uid string) bool
func IsUserInRoom(roomID string, userData *user.User) bool
func Join(roomID string, userData *user.User, ver uint8, cmd uint16, message []byte, callback func(error, []string, string, int64))
func Leave(roomID string, userData *user.User, ver uint8, cmd uint16, message []byte) error
func Message(roomID string, memberIDs []string, senderUser *user.User, ver uint8, cmd uint16, message []byte, reliable bool)
func MigrateRoom(userData *user.User, room *Room, callback func(error, string, string))
func NewRoom(userData *user.User, maxMembers int, allowEmpty bool, join bool, ttl int64, interval int64) (string, error)
func Reserve(roomID string, userData *user.User, memberIDs []string, mustBeOwner bool) error
func SetChatHistoryLimit(roomID string, limit int) bool
func SetJoinCondition(cond func(string, *user.User) error)
func SetOnAnnounce(roomID string, cb func(string, uint8, uint16, []byte)) bool
func SetOnChatMessage(roomID string, callback func(*user.User, string) bool) bool
func SetOnClock(roomID string, name string, interval int64, callback func(string)) bool
func SetOnClockStop(roomID string, name string, callback func(string)) bool
func SetOnCustomUserDiscardByID(roomID string, callback func(string, *user.User) (uint8, uint16, []byte)) bool
func SetOnDiscardCustomMessage(custom func(string, string, string) []byte) bool
func SetOnJoinByID(roomID string, callback func(string, *user.User) bool) bool
func SetOnJoinCompleteByID(roomID string, callback func(string, *user.User)) bool
func SetOnMigrated(callback func(string, string))
func SetOnRoomChange(cb func(string, []string, map[string]interface{})) bool
func SetOnRoomDiscard(cb func(string)) bool
func SetOnRoomDiscardByID(roomID string, callback func(string)) bool
func SetOnRoomOwnerChange(cb func(interface{}))
func SetOnRoomPropertyUpdate(cb func(interface{}))
func SetOnTick(roomID string, callback func(string)) bool
func SetOnTickStop(roomID string, callback func(string)) bool
func SetRollbackOnJoinFailureByID(roomID string, callback func(string, *user.User)) bool
func SetupAsTCPServer()
func SetupAsUDPServer()
func SetupAsWSServer()
func SetupBackup(backupNum int)
func StopClock(roomID string, name string) bool
func StopTick(roomID string)
func SyncChatMessage(roomID string, userData *user.User, ver uint8, cmd uint16, message string) bool
func SyncCreateTime(roomID string, ver uint8, cmd uint16, memberIDs []string)
func ThrottledMessage(roomID string, memberIDs []string, senderUser *user.User, ver uint8, cmd uint16, throttleTime int64, message []byte, reliable bool)
func UpdateProperties(roomID string, operation func(properties map[string]interface{}) bool) map[string]interface{}
func UseMapping(roomID string, fieldSize int64)
type Room
    func GetRoomByID(roomID string) *Room

func AfterBroadcastRoomCmd

func AfterBroadcastRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

AfterBroadcastRoomCmd registers a callback function to be executed after broadcast room command: Must be called before ExposeCommands

func AfterCreateRoomCmd

func AfterCreateRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

AfterCreateRoomCmd registers a callback function to be executed after create room command: Must be called before ExposeCommands

func AfterGetRoomPropCmd

func AfterGetRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

AfterGetRoomPropCmd registers a callback function to be executed after get room properties: Must be called before ExposeCommands

func AfterJoinRoomCmd

func AfterJoinRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

AfterJoinRoomCmd registers a callback function to be executed after join room command: Must be called before ExposeCommands

func AfterLeaveRoomCmd

func AfterLeaveRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

AfterLeaveRoomCmd registers a callback function to be executed after leave room command: Must be called before ExposeCommands

func AfterMessageRoomCmd

func AfterMessageRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

AfterMessageRoomCmd registers a callback function to be executed after message room command: Must be called before ExposeCommands

func AfterUpdateRoomPropCmd

func AfterUpdateRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

AfterUpdateRoomPropCmd registers a callback function to be executed after update room properties: Must be called before ExposeCommands

func Announce

func Announce(roomID string, memberIDs []string, ver uint8, cmd uint16, message []byte, reliable bool)

Announce Sends a message to selected members to the room without having a "sender" - This function must NOT be called by user

[NOTE] Uses mutex lock internally.

roomID string - Target room ID.

memberIDs []string - An array of member user IDs to send message to.

senderUser *user.USer - User to send broadcast.

ver uint8 - Command version to be used as broadcast message.

cmd uint16 - Command ID to be used as broadcast message.

message []byte - Message byte array.

reliable bool - If true, UDP will be RUDP.

func BeforeBroadcastRoomCmd

func BeforeBroadcastRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

BeforeBroadcastRoomCmd registers a callback function to be executed before broadcast room command: Must be called before ExposeCommands

func BeforeCreateRoomCmd

func BeforeCreateRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

BeforeCreateRoomCmd registers a callback function to be executed before create room command: Must be called before ExposeCommands

func BeforeGetRoomPropCmd

func BeforeGetRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

BeforeGetRoomPropCmd registers a callback function to be executed before get room properties: Must be called before ExposeCommands

func BeforeJoinRoomCmd

func BeforeJoinRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

BeforeJoinRoomCmd registers a callback function to be executed before join room command: Must be called before ExposeCommands

func BeforeLeaveRoomCmd

func BeforeLeaveRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

BeforeLeaveRoomCmd registers a callback function to be executed before leave room command: Must be called before ExposeCommands

func BeforeMessageRoomCmd

func BeforeMessageRoomCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

BeforeMessageRoomCmd registers a callback function to be executed before message room command: Must be called before ExposeCommands

func BeforeUpdateRoomPropCmd

func BeforeUpdateRoomPropCmd(callback func(uint8, uint16, []byte, *user.User, func(error)))

BeforeUpdateRoomPropCmd registers a callback function to be executed before update room properties: Must be called before ExposeCommands

func Broadcast

func Broadcast(roomID string, senderUser *user.User, ver uint8, cmd uint16, message []byte, reliable bool)

Broadcast Sends a broadcast message to the other members in the room

[NOTE] Uses mutex lock internally.

roomID string - Target room ID.

senderUser *user.USer - User to send broadcast.

ver uint8 - Command version to be used as broadcast message.

cmd uint16 - Command ID to be used as broadcast message.

message []byte - Message byte array.

reliable bool - If true, UDP will be RUDP.

func CancelReservation

func CancelReservation(roomID string, userData *user.User, memberIDs []string, mustBeOwner bool) error

CancelReservation removes reservation per members

[NOTE] Uses mutex lock internally.

room ID string      - Target room ID to cancel a reservation.

userData *user.User - Owner user to cancel the reservation.

memberIDs []string  - An array of user IDs to cancel the reservation for.

mustBeOwner bool    - If true userData must be the room owner

func CancelReservationRemote

func CancelReservationRemote(roomID string, userData *user.User, memberIDs []string, mustBeOwner bool, cb func(error))

CancelReservationRemote removes reservation per members

[NOTE] This function is asynchronous.

room ID string      - Target room ID to cancel a reservation.

userData *user.User - Owner user to cancel the reservation.

memberIDs []string  - An array of user IDs to cancel the reservation for.

mustBeOwner bool    - If true userData must be the room owner

cb                  - Callback function

func ChangeTTL

func ChangeTTL(roomID string, ttl int64) bool

ChangeTTL changes TTL of the targetted room

[NOTE] Uses mutex lock internally.

room ID string - Target room ID to change its TTL.

ttl int64 - New TTL of the room.

func DeleteRoom

func DeleteRoom(roomID string, userData *user.User, ver uint8, cmd uint16, message []byte)

DeleteRoom deletes the target room regardless of the room being not empty and sends notification message to its members.

[NOTE] Uses mutex lock internally.

roomID string       - Target room ID to delete.

userData *user.User - User that performs the deletion of the room.

ver uint8           - Command version to send the notification as.

cmd uint16          - Command ID to send the notification as.

message []byte      - Message byte array to be sent to the members.

func Exists

func Exists(roomID string) bool

Exists return true if the given roomID's room still exists

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to check if the room exists or not.

func ExposeCommands

func ExposeCommands()

ExposeCommands Exposes TCP or UDP/RUDP commands to execute room functions from the client

func GetAllRoomIDsOnNode

func GetAllRoomIDsOnNode() []string

GetAllRoomIDsOnNode returns all valid room IDs on the current node

[NOTE] Uses mutex lock internally.

func GetChatHistory

func GetChatHistory(roomID string) [][]string

GetChatHistory returns chat history data as an array

[NOTE] Uses mutex lock internally.

[IMPORTANT] Uses mutex lock internally.

func GetCreatedTime

func GetCreatedTime(roomID string) int64

GetCreatedTime returns the created time (in seconds) of the room

[NOTE] Uses mutex lock internally.

func GetMapping

func GetMapping(roomID string) *mapping.Mapping

GetMapping returns a struct instance of mapping. room.UseMapping() must be called to use this

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get its mapping object.

func GetMemberByID

func GetMemberByID(roomID string, id string) *user.User

GetMemberByID returns member user by room ID and user ID

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get the member *user.User from.

id string - Target user ID to get *user.User of.

func GetMemberIDs

func GetMemberIDs(roomID string) []string

GetMemberIDs returns the list of member IDs (not SIDs)

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get the list of member user IDs.

func GetMemberIDsAndOwner

func GetMemberIDsAndOwner(roomID string) ([]string, string, string)

GetMemberIDsAndOwner returns an array of all member IDs and owner ID and ownerSID

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get the list of member user IDs and its owner user ID from.

Returns member user IDs as an array, owner user ID, and owner user SID.

func GetMemberSIDs

func GetMemberSIDs(roomID string) []string

GetMemberSIDs returns the list of member SIDs

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get a list of member SIDs.

func GetMemberSIDsAndOwner

func GetMemberSIDsAndOwner(roomID string) ([]string, string, string)

GetMemberSIDsAndOwner returns an array of all member IDs and owner ID and owner SID

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get the list of member SIDs, owner user ID, and owner SID.

Returns an array of member user SIDs, owner user ID, and owner SID.

func GetMemberUsers

func GetMemberUsers(roomID string) []*user.User

GetMemberUsers returns the list of member user struct instances

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get the list of member userData.

func GetMemberUsersAndOwnerUser

func GetMemberUsersAndOwnerUser(roomID string) ([]*user.User, *user.User)

GetMemberUsersAndOwnerUser returns an array of all member IDs and owner ID

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get member *user.User and owner *user.User.

Returns member *user.User as an array and owner *user.User.

func GetNumberOfRoomMembers

func GetNumberOfRoomMembers(roomID string, callback func(error, int, int))

GetNumberOfRoomMembers retrieves number of room members. This can be executed by anyone and they do not have to be part of the room.

roomID string - Target room ID to get the number of members from.

callback func(error, int, int) - Callback to be invoked when the number of current members and max members retrieved.

IMPORTANT: This function works for all users including the users that are not members of the target room.

func GetProperties

func GetProperties(roomID string) map[string]interface{}

GetProperties returns properties of a room

[IMPORTANT] Works with local rooms only
[IMPORTANT] Room properties do NOT support structs.
[IMPORTANT] when you handle properties, please use mesh.GetInt, mesh.GetInt8 etc as the value of properties maybe nil or float64

[NOTE] Uses mutex lock internally.

 ------------------
 Operation example:
 val := mesh.GetInt(properties, "counter")
 properties["counter"] = val + 1 // increment by 1
 -----------------------------------
 Use datacapsule.Capsule as property
 capsule := datacapsule.NewCapsule()
 capsule.Import(properties["memberNum"]) // getting property as a capsule (assumes properties["memberNum"] as map[string]interface)
 memberNum := capsule.GetAsInt8("memberNum")

	roomID string - Target room ID of the properties.

func GetProperty

func GetProperty(roomID string, name string) interface{}

GetProperty returns a property of the given room and property name. Returns nil if not found.

[IMPORTANT] Works with local rooms only
[IMPORTANT] Room properties do NOT support structs.
[IMPORTANT] when you handle properties, please use mesh.GetInt, mesh.GetInt8 etc as the value of properties maybe nil or float64

[NOTE] Uses mutex lock internally.

 ------------------
 Operation example:
 val := mesh.GetInt(properties, "counter")
 properties["counter"] = val + 1 // increment by 1
 -----------------------------------
 Use datacapsule.Capsule as property
 capsule := datacapsule.NewCapsule()
 capsule.Import(properties["memberNum"]) // getting property as a capsule (assumes properties["memberNum"] as map[string]interface)
 memberNum := capsule.GetAsInt8("memberNum")

	roomID string - Target room ID of the properties.

	name string - Property name to retrieve.

func GetRemoteProperties

func GetRemoteProperties(roomID string, cb func(error, map[string]interface{}))

GetRemoteProperties returns properties of a room

[IMPORTANT] Works with local and remote rooms
[IMPORTANT] Room properties do NOT support structs.
[IMPORTANT] when you handle properties, please use mesh.GetInt, mesh.GetInt8 etc as the value of properties maybe nil or float64

[NOTE] This function is asynchronous.

 ------------------
 Operation example:
 val := mesh.GetInt(properties, "counter")
 properties["counter"] = val + 1 // increment by 1
 -----------------------------------
 Use datacapsule.Capsule as property
 capsule := datacapsule.NewCapsule()
 capsule.Import(properties["memberNum"]) // getting property as a capsule (assumes properties["memberNum"] as map[string]interface)
 memberNum := capsule.GetAsInt8("memberNum")

	roomID string - Target room ID of the properties.

func GetRemoteProperty

func GetRemoteProperty(roomID string, name string, cb func(error, interface{}))

GetRemoteProperty returns a property of the given room and property name. Returns nil if not found.

[IMPORTANT] Works with local and remote rooms
[IMPORTANT] Room properties do NOT support structs.
[IMPORTANT] when you handle properties, please use mesh.GetInt, mesh.GetInt8 etc as the value of properties maybe nil or float64

[NOTE] This function asynchronous.

 ------------------
 Operation example:
 val := mesh.GetInt(properties, "counter")
 properties["counter"] = val + 1 // increment by 1
 -----------------------------------
 Use datacapsule.Capsule as property
 capsule := datacapsule.NewCapsule()
 capsule.Import(properties["memberNum"]) // getting property as a capsule (assumes properties["memberNum"] as map[string]interface)
 memberNum := capsule.GetAsInt8("memberNum")

	roomID string - Target room ID of the properties.

	name string - Property name to retrieve.

func GetRoomID

func GetRoomID(userData *user.User) string

GetRoomID returns roomID that the user has joined

[NOTE] Uses mutex lock internally.

userData *user.User - Target user to get the room ID that the user is currently member of.

func GetRoomNodeAddressList

func GetRoomNodeAddressList(roomID string) ([]string, error)

GetRoomNodeAddressList returns a list of internal node addresses that the room is stored

roomID string - Target room ID to extract the server internal node addresses from.

Returns a list of server internal node addresses of the room and error if it fails.

func GetRoomOwnerID

func GetRoomOwnerID(roomID string) string

GetRoomOwnerID returns the user ID of the owner of the room

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to get the owner from.

func IncrProperty

func IncrProperty(roomID string, propName string, delta int64) bool

IncrProperty increments int64 property by given delta.

The property must be created before you execute this function.

If the property does not exist, it creates the property.

[NOTE] Uses mutex lock internally.

roomID string - Target room ID.

propName string - Target property name.

delta int64 - Delta value to increment by.

func IsReserved

func IsReserved(roomID string, uid string) bool

IsReserved returns true if the given uid (User ID) has a reservation with the given room.

[NOTE] Uses mutex lock internally.

func IsUserInRoom

func IsUserInRoom(roomID string, userData *user.User) bool

IsUserInRoom returns true if the user is in the room

[NOTE] Uses mutex lock internally.

room ID string - Target room ID to check.

userData *user.User - Target user to see if the user is in the room.

func Join

func Join(
    roomID string,
    userData *user.User,
    ver uint8, cmd uint16,
    message []byte,
    callback func(error, []string, string, int64),
)

Join Joins a room and notify the other members of the room on joining the room. If message is empty, Broadcast will not be sent.

[NOTE] Uses mutex lock internally.

[NOTE] This function is asynchornous.

[IMPORTANT] The room to join may not be on the same server process and if that is the case, the client will move to where the room is.

Join(roomID, userData, ver, cmd, message, callback func(error, memberIDs, ownerID, createdTime))

room ID string - Target room ID to join.

userData *user.User - User to join the room.

ver uint8 - Command version to be used for succuessful join message sent to other room members.

cmd uint16 - Command ID to be used for successful join message sent to other room members.

message []byte - Message byte array to be sent as successful message to other room members.
If message is either nil or empty, the message will not be sent.

callback func(error, memberUserIDs []string, roomCreatedTime int64)
Callback to be invoked when join operation completes (both success and failure).

func Leave

func Leave(roomID string, userData *user.User, ver uint8, cmd uint16, message []byte) error

Leave Leaves from a room and notify the other members on leaving. If message is empty Broadcast will not be sent.

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to leave from.

userData *user.User - User that will be leaving the room.

ver uint8 - Command version to be used for message sent when leave is successful.

cmd uint16 - Command ID to be used for message sent when leave is successful.

message []byte - Message byte array to be sent as successful message to other room mebers.
If message is either nil or empty, the message will not be sent.

func Message

func Message(roomID string, memberIDs []string, senderUser *user.User, ver uint8, cmd uint16, message []byte, reliable bool)

Message Sends a message to selected members of the room

[NOTE] Uses mutex lock internally.

roomID string - Target room ID.

memberIDs []string - An array of member user IDs to send message to.

senderUser *user.USer - User to send broadcast.

ver uint8 - Command version to be used as broadcast message.

cmd uint16 - Command ID to be used as broadcast message.

message []byte - Message byte array.

reliable bool - If true, UDP will be RUDP.

func MigrateRoom

func MigrateRoom(userData *user.User, room *Room, callback func(error, string, string))

MigrateRoom migrates a room to another node and moves its members to the new room This is inteded to used when the current node is about to shutdown, but you need to keep the current room. callback(error newRoomID string, oldRoomID string)

[NOTE] Uses mutex lock internally.

[NOTE] This function is asynchronous.

userData *user.User - Owner user to perform the migration.

room *Room - Room that is to be migrated.

callback func(error, newRoomID string, oldRoomID string) - Invoked when migration operation is completed.

IMPORTANT: Migration will change the room ID.

func NewRoom

func NewRoom(userData *user.User, maxMembers int, allowEmpty bool, join bool, ttl int64, interval int64) (string, error)

NewRoom Creates a new room

[NOTE] Uses mutex lock internally.

userData   - User data struct
maxMembers - Maximum number of members allowed to join the room
allowEmpty - If true, the room will not be deleted until TTL expires even if all members leave
join       - If true, the creator user will join the room automatically
ttl        - TTL of the room when it is empty in seconds. The value must be greater than 0. Minimam is 10 seconds
interval   - Broadcast interval in milliseconds. interval below 100ms will be forced to 0. If it's 0, no packet merge

func Reserve

func Reserve(roomID string, userData *user.User, memberIDs []string, mustBeOwner bool) error

Reserve fixes the member of users to join and rejects everyone else.

[NOTE] Uses mutex lock internally.

roomID string       - Target room ID to make a reservation.

userData *user.User - Owner user of the room to make a reservation.

memberIDs []string  - An array of user IDs to make a reservation for.

mustBeOwner bool    - If true, userData must be the owner of the room.

func SetChatHistoryLimit

func SetChatHistoryLimit(roomID string, limit int) bool

SetChatHistoryLimit sets the chat history maximum length

[NOTE] Uses mutex lock internally.

[IMPORTANT] Uses mutex lock internally.

func SetJoinCondition

func SetJoinCondition(cond func(string, *user.User) error)

SetJoinCondition registers a condition function to control room join. Returning an error will cause room join to fail

Join condition is NOT protected by mutext lock.

SetJoinCondition(condition func(roomID string, userData *user.User))

cond func(roomID string, userData *user.User) error - Custom function to be invoked before room join to evaluate join conditions.

func SetOnAnnounce

func SetOnAnnounce(roomID string, cb func(string, uint8, uint16, []byte)) bool

SetOnAnnounce registeres a listener callback on Announce of room

[NOTE] Uses mutex lock internally.

It captures Broadcast and Message as well

roomID string - Target room ID.

cb func(roomID, ver uint8, cmd uint16, message []byte) - Callback to be invoked on every Broadcast and Message.

NOTE: ver and cmd passed to the callback are the ver and cmd used to send Broadcast or Message.

Usage Example: Useful when capturing and sending the message data to external database or service.

func SetOnChatMessage

func SetOnChatMessage(roomID string, callback func(*user.User, string) bool) bool

SetOnChatMessage assigns a callback to be invoked before synchronizing a chat message.

[NOTE] Uses mutex lock internally.

Return false will reject the incoming chat message and rejected chat message will NOT be sent to other members.

[IMPORTANT] Uses mutex lock internally.

func SetOnClock

func SetOnClock(roomID string, name string, interval int64, callback func(string)) bool

SetOnClock assigns a custom callback to be invoked at a given interval until it is stopped by ClockStop callback

[NOTE] Uses mutex lock internally.

roomID - Target room ID of the room to have a clock callback loop

name - Unique name of the clock callback. Duplicates will be ignored

interval - Clock interval in seconds

callback - Callback function to be invoked

func SetOnClockStop

func SetOnClockStop(roomID string, name string, callback func(string)) bool

SetOnClockStop assigns a callback to be invoked when a clock callback is stopped by StopClock

[NOTE] Uses mutex lock internally.

roomID - Target room ID of the room to stop the clock callback

name - Unique name of the clock to stop

callback - Callback function to be invoked when clock is stopped by StopClock

func SetOnCustomUserDiscardByID

func SetOnCustomUserDiscardByID(roomID string, callback func(string, *user.User) (uint8, uint16, []byte)) bool

SetOnCustomUserDiscardByID registers a callback to be executed when a room member disconnects unexpected.

[NOTE] Uses mutex lock internally.

The purpose of this callback is to use custom command ver, cmd, and message data to be sent to other members.

func SetOnDiscardCustomMessage

func SetOnDiscardCustomMessage(custom func(string, string, string) []byte) bool

SetOnDiscardCustomMessage sets a custom function to create a custom message on user discard to be sent to members The callback receives roomID string, user ID string, user SID string

custom func(roomID string, userID string, userSID string) []byte
- Custom function to create a custom message byte array to be sent to other members. when the member client disconnects and leave.

func SetOnJoinByID

func SetOnJoinByID(roomID string, callback func(string, *user.User) bool) bool

SetOnJoinByID registers a callback to be executed just before the join operation to evaluate, if the user should join or not.

[NOTE] Uses mutex lock internally.

Returning value false will cause the join operation to fail.

func SetOnJoinCompleteByID

func SetOnJoinCompleteByID(roomID string, callback func(string, *user.User)) bool

SetOnJoinCompleteByID registers a callback on join operation complete

[NOTE] Uses mutex lock internally.

func SetOnMigrated

func SetOnMigrated(callback func(string, string))

SetOnMigrated registers a callback on migrated - The callbacks will be invoked on the server node where the room is migrated to

callback func(newRoomID string, oldRoomID string) - Assign a callback to be invoked when migration is succssful.

func SetOnRoomChange

func SetOnRoomChange(cb func(string, []string, map[string]interface{})) bool

SetOnRoomChange registers a callback function on room change such as create, join, leave, property updates

cb func(roomID string, memberUserIDs []string, roomProperties map[string]interface{})

func SetOnRoomDiscard

func SetOnRoomDiscard(cb func(string)) bool

SetOnRoomDiscard registers a callback function on room deletions

cb func(roomID string) - Function to be invoked on room's deletion.

func SetOnRoomDiscardByID

func SetOnRoomDiscardByID(roomID string, callback func(string)) bool

SetOnRoomDiscardByID registers a callback on room deletion by room ID

[NOTE] Uses mutex lock internally.

func SetOnRoomOwnerChange

func SetOnRoomOwnerChange(cb func(interface{}))

SetOnRoomOwnerChange sets a callback for room owner change

[NOTE] Uses mutex lock internally.

The paramter (interface{}) passed to the callback:

cb func(roomData interface{}) - Callback to be invoked when the room owner changes.

params["roomID"] = roomID string
params["ownerID"] = ownerID string

func SetOnRoomPropertyUpdate

func SetOnRoomPropertyUpdate(cb func(interface{}))

SetOnRoomPropertyUpdate sets a callback for room property updates.

[NOTE] Uses mutex lock internally.

The paramter (interface{}) passed to the callback:

cb func(roomData interface{}) - Callback to be invoked when room property changes.

params["roomID"] = roomID string
// Properties that have been changed
params["properties"] = properties interface{}.(map[string]interface{})

func SetOnTick

func SetOnTick(roomID string, callback func(string)) bool

SetOnTick registers a callback on every 5 seconds tick on a room

[NOTE] Uses mutex lock internally.

roomID string - Target room ID to set a tick callback.

callback func(roomID string) - Callback to be invoked at every tick.

Useage Example: Use this to call matching.Add so that you may keep the room available for matchmaking as long as you with.

func SetOnTickStop

func SetOnTickStop(roomID string, callback func(string)) bool

SetOnTickStop assigns a callback to be invoked when room tick stops

[NOTE] Uses mutex lock internally.

func SetRollbackOnJoinFailureByID

func SetRollbackOnJoinFailureByID(roomID string, callback func(string, *user.User)) bool

SetRollbackOnJoinFailureByID registers a callback to perform rollback operations on join failure

[NOTE] Uses mutex lock internally.

func SetupAsTCPServer

func SetupAsTCPServer()

SetupAsTCPServer Sets up room package

func SetupAsUDPServer

func SetupAsUDPServer()

SetupAsUDPServer Sets up room package

func SetupAsWSServer

func SetupAsWSServer()

SetupAsWSServer Sets up room package

func SetupBackup

func SetupBackup(backupNum int)

SetupBackup Enables room data backup to different nodes - maximum backup nodes you can set is 2

backupNum int - Number of backup servers.

func StopClock

func StopClock(roomID string, name string) bool

StopClock stops a clock callback loop

[NOTE] Uses mutex lock internally.

roomID - Target room ID of the room to stop the clock callback

name - Unique name of the clock to stop

func StopTick

func StopTick(roomID string)

StopTick stops room's tick event loop

[NOTE] Uses mutex lock internally.

func SyncChatMessage

func SyncChatMessage(roomID string, userData *user.User, ver uint8, cmd uint16, message string) bool

SyncChatMessage records the chat message data and synchronize the chat message with room members

[NOTE] Uses mutex lock internally.

[IMPORTANT] Uses mutex lock internally.

func SyncCreateTime

func SyncCreateTime(roomID string, ver uint8, cmd uint16, memberIDs []string)

SyncCreateTime sends room's created time (in seconds) to the selected (or all) members of the room

[NOTE] Uses mutex lock internally.

roomID string - Target room ID.

ver uint8 - Command version to be used for the message.

cmd uint16 - Command ID to be used for the message.

memberIDs []string - An array of member user IDs to sync the room creation time.

func ThrottledMessage

func ThrottledMessage(roomID string, memberIDs []string, senderUser *user.User, ver uint8, cmd uint16, throttleTime int64, message []byte, reliable bool)

ThrottledMessage sends a server push packet to the members given if the packet sent previously has past throttleTime previously set. If not, the packet will be "Dropped". throttleTime is in milliseconds.

[NOTE] Uses mutex lock internally.

func UpdateProperties

func UpdateProperties(roomID string, operation func(properties map[string]interface{}) bool) map[string]interface{}

UpdateProperties updates or creates properties of a room and returns the updated or created properties.

[IMPORTANT] Works with local rooms only

[IMPORTANT] Room properties do NOT support structs.

[IMPORTANT] When you handle properties, please use mesh.GetInt, mesh.GetInt8 etc as the value of properties maybe nil or float64.

[IMPORTANT] operation function is protected by mutex lock, using another mutext lock within the function may cause a deadlock.

[NOTE] Uses mutex lock internally.

Operation example:

var updateErr error
_ := room.UpdateProperties(roomID, func(properties map[string]interface{}) {
	capsule := datacapsule.NewCapsule()
	err := capsule.Import(properties["roomPropertyCapsule"].(map[string]interface{}))
	if err != nil {
		// this is how to propergate an error
		updateErr = err
		return
	}
	counter := capsule.GetAsInt("counter")
	counter++
	capsule.SetAsInt("counter", counter)
	properties["roomPropertyCapsule"] = capsule.Export()
})
if updateErr != nil {
	// handle update error here
}

Use datacapsule.Capsule as property:

capsule := datacapsule.NewCapsule()
capsule.SetAsInt8("memberNum", memberNum)
properties["memberNum"] = capsule.Export() // setting capsule as a property

 roomID string - Target room ID of the properties.

operation func(properties map[string]interface{}) bool - Callback function to perform update operations.
Must return true, when property (properties) is updated and false when there is no update.

func UseMapping

func UseMapping(roomID string, fieldSize int64)

UseMapping enables mapping (in-room field module)

[NOTE] Uses mutex lock internally.

roomID string - Target room ID.

fieldSize int64 - Size of the map to be created within the room.

type Room

Room Room data structure

type Room struct {
    ID         string
    MaxMembers int

    AllowEmpty bool

    // an array of member SIDs
    Members []string
    // ID as key and SID as value
    MemberIDs  map[string]string
    Properties map[string]interface{}
    // contains filtered or unexported fields
}

func GetRoomByID

func GetRoomByID(roomID string) *Room

GetRoomByID returns a room

[NOTE] Uses mutex lock internally.

[NOTE] This will not update TTL of the room.

roomID string - Target room ID to get the room object.

Subdirectories

Name Synopsis
..
mapping Package mapping ▷ Room Mapping - MMO Style Mapping For Room Allows the room members to "see" each other based on positions (x, y).