Diarkis Room - How To Use Announce

How To Use Announce()

room.Announce allows you to send messages to other members of a room. The difference between Broadcast and Message is that the sender client does NOT have to be a member of the room to send messages.

While it is flexible and useful in some cases not to worry about being a member of the room to send messages, it is also difficult to use Announce correctly without creating unexpected security holes.

If you let any client have access to Announce, Clients can send messages to any room as long as they know the targeted room ID. This could be exploited.

It is very important to have a control logic to call Announce in order to avoid abuse from the client.

The example below uses Announce in the callback of an event. By not having the client access directly to Announce, we can prevent numbers of potential security risks.

// SetOnAnnounce is raised when Broadcast, Message, Announce are invoked
room.SetOnAnnounce(func(roomID string, ver uint8, cmd uint16, msg []byte) {
   // We capture the message sent to the room and send it outside such as CDN etc.
   data := CreateCDNData(roomID, ver, cmd, msg)

Last updated