How To Implement Custom Condition For Room Join With Diarkis Room

Diarkis Room allows you to implement your own custom rules for room join.

We will be using an example where the custom rule to join a room requires a room property called "roomType" to be 100. Any other value will cause the denial of room join.

NOTE: room.SetJoinCondition applies to all rooms.

// Required packages
// import "errors"
// import ""
// import ""
// import ""

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

  roomType := room.GetProperty(roomID, "roomType")

  if roomType == nil {
    // Missing roomType, we decline the user to join the room
    return errors.New("Room type not found")

  // interface{} can be any data type, so we want to make sure it is as we expected
  if _, ok := roomType.(int); !ok {
    // roomType is not int and that is not expected, decline the user to join the room
    return errors.New("Corrupt roomType data type...")

  if roomType.(int) != 100 {
    // roomType must be 100 for the user to join
    return errors.New("Room join is not allowed")

  // The user is allow to join the room
  return nil


Last updated