forked from Paroxity/portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Event Bus
MEMOxiiii edited this page Jul 28, 2026
·
1 revision
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).
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)
}
})TopicPlayerJoinTopicPlayerQuitTopicServerRegisteredTopicServerUnregisteredTopicTransferTopicServerHealthChanged
Each topic's payload is a typed struct in the event package (e.g. event.PlayerPayload, event.TransferPayload) — type-assert it as shown above.
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.
Getting started
Integrating a backend
Embedding Portal