Call webhook on player disconnect (#396)

This commit is contained in:
UrbaneChimp
2025-04-25 02:58:43 +01:00
committed by GitHub
parent 9601ceedcb
commit cc5d77e4c8
3 changed files with 27 additions and 1 deletions
+20 -1
View File
@@ -22,7 +22,8 @@ type WebhookNotifier struct {
}
const (
WebhookEventConnecting = "connect"
WebhookEventConnecting = "connect"
WebhookEventDisconnecting = "disconnect"
)
const (
@@ -109,6 +110,24 @@ func (w *WebhookNotifier) NotifyConnected(ctx context.Context, clientAddr net.Ad
return w.send(ctx, payload)
}
func (w *WebhookNotifier) NotifyDisconnected(ctx context.Context, clientAddr net.Addr, serverAddress string, playerInfo *PlayerInfo, backendHostPort string) error {
if w.requireUser && playerInfo == nil {
return nil
}
payload := &WebhookNotifierPayload{
Event: WebhookEventDisconnecting,
Timestamp: time.Now(),
Status: WebhookStatusSuccess,
Client: ClientInfoFromAddr(clientAddr),
Server: serverAddress,
PlayerInfo: playerInfo,
BackendHostPort: backendHostPort,
}
return w.send(ctx, payload)
}
func (w *WebhookNotifier) send(ctx context.Context, payload *WebhookNotifierPayload) error {
jsonPayload, err := json.Marshal(payload)
if err != nil {