...

Package room

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

Overview ▾

Index ▾

Constants
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) error
func ChangeTTL(roomID string, ttl int64) bool
func Exists(roomID string) bool
func ExposeCommands()
func GetAllRoomIDsOnNode() []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 GetProperties(roomID string) map[string]interface{}
func GetProperty(roomID string, name string) 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 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, map[string]interface{}))
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) error
func SetJoinCondition(cond func(string, *user.User) error)
func SetOnAnnounce(roomID string, cb func(string, uint8, uint16, []byte))
func SetOnDiscardCustomMessage(custom func(string, string) []byte)
func SetOnMigrated(callback func(string, string))
func SetOnRoomChange(cb func(string, []string, map[string]interface{}))
func SetOnRoomDiscard(cb func(string))
func SetOnRoomOwnerChange(cb func(interface{}))
func SetOnRoomPropertyUpdate(cb func(interface{}))
func SetOnTick(roomID string, callback func(string))
func SetupAsTCPServer()
func SetupAsUDPServer()
func SetupAsWSServer()
func SetupBackup(backupNum int)
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

Constants

MeshValueName name of mesh value

const MeshValueName = "r"

VaultName name of vault

const VaultName = "Rooms"

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

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

func CancelReservation

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

CancelReservation removes reservation per members

Only the room owner is permitted to run this operation

func ChangeTTL

func ChangeTTL(roomID string, ttl int64) bool

ChangeTTL changes TTL of the targetted room

func Exists

func Exists(roomID string) bool

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

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

func GetCreatedTime

func GetCreatedTime(roomID string) int64

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

func GetMapping

func GetMapping(roomID string) *mapping.Mapping

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

func GetMemberByID

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

GetMemberByID returns member user by room ID and user ID

func GetMemberIDs

func GetMemberIDs(roomID string) []string

GetMemberIDs returns the list of member IDs (not SIDs)

func GetMemberIDsAndOwner

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

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

func GetMemberSIDs

func GetMemberSIDs(roomID string) []string

GetMemberSIDs returns the 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

func GetMemberUsers

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

GetMemberUsers returns the list of member user struct instances

func GetMemberUsersAndOwnerUser

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

GetMemberUsersAndOwnerUser returns an array of all member IDs and owner ID

func GetProperties

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

GetProperties returns properties of a room

[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
------------------
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
memberNum := capsule.GetAsInt8("memberNum")

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] 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
------------------
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
memberNum := capsule.GetAsInt8("memberNum")

func GetRoomID

func GetRoomID(userData *user.User) string

GetRoomID returns roomID that the user has joined

func GetRoomNodeAddressList

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

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

func GetRoomOwnerID

func GetRoomOwnerID(roomID string) string

GetRoomOwnerID returns the user ID of the owner of the room

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.

func IsUserInRoom

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

IsUserInRoom returns true 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, map[string]interface{}),
)

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. [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 [IMPORTANT] The properties map[string]interface{} that the callback function passes is NOT a copy and if you change this value you "may" change the actual property and corrupt the data. Please use this as read-only

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

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.

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

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)

func NewRoom

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

NewRoom Creates a new room

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.
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) error

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

This operation is permitted only by the owner of the room.

The owner of the room will be included as a reversed member along with the list of member IDs.

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))

func SetOnAnnounce

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

SetOnAnnounce registeres a listener callback on Announce of room It captures Broadcast and Message as well

func SetOnDiscardCustomMessage

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

SetOnDiscardCustomMessage sets a custom function to create a custom message on user discard to be sent to members

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

func SetOnRoomChange

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

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

func SetOnRoomDiscard

func SetOnRoomDiscard(cb func(string))

SetOnRoomDiscard registers a callback function on room deletions

func SetOnRoomOwnerChange

func SetOnRoomOwnerChange(cb func(interface{}))

SetOnRoomOwnerChange sets a callback for room owner change The paramter (interface{}) passed to the callback:

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

func SetOnRoomPropertyUpdate

func SetOnRoomPropertyUpdate(cb func(interface{}))

SetOnRoomPropertyUpdate sets a callback for room property updates. The paramter (interface{}) passed to the callback:

params["roomID"] = roomID string
params["properties"] = properties interface{}

func SetOnTick

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

SetOnTick registers a callback on every heartbeat/echo tick on a room

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

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

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.

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

Operation example:

var updateErr error
_ := room.UpdateProperties(roomID, func(properties map[string]interface{}) {
	capsule := datacapsule.NewCapsule()
	err := capsule.Import(properties["roomPropertyCapsule"])
	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

func UseMapping

func UseMapping(roomID string, fieldSize int64)

UseMapping enables mapping (in-room field module)

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

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