Skip to content

Event Bus

MEMOxiiii edited this page Jul 28, 2026 · 1 revision

Event Bus

Portal.Events() exposes a proxy-wide event bus you can subscribe to without forking the proxy — useful when embedding Portal as a library (see Installation#embedding-portal-as-a-library).

Subscribing

p.Events().Subscribe(event.TopicPlayerJoin, func(payload any) {
    p := payload.(event.PlayerPayload)
    log.Infof("%s joined the network", p.Name)
})

p.Events().Subscribe(event.TopicTransfer, func(payload any) {
    t := payload.(event.TransferPayload)
    if t.Err != nil {
        log.Errorf("%s failed to transfer from %s to %s: %v", t.PlayerName, t.FromServer, t.ToServer, t.Err)
    }
})

Available topics

  • TopicPlayerJoin
  • TopicPlayerQuit
  • TopicServerRegistered
  • TopicServerUnregistered
  • TopicTransfer
  • TopicServerHealthChanged

Each topic's payload is a typed struct in the event package (e.g. event.PlayerPayload, event.TransferPayload) — type-assert it as shown above.

When to use this vs. the Admin Console

The event bus is for reacting to what Portal is doing (metrics, logging, notifications, custom automation). If you instead want to command Portal (kick a player, force a transfer, drain a server), see Admin Console — Portal.HandleAdminCommand is available directly for wiring those same commands into your own transport.

Clone this wiki locally