mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-12 00:13:42 +00:00
feat: publish matchmaking state events
This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -205,6 +207,22 @@ func (s *Service) PublishControlPlaneEvent(event ControlPlaneEvent) error {
|
||||
return s.getEventHub().publish(event)
|
||||
}
|
||||
|
||||
func (s *Service) publishTicketEvent(ticket domain.QueueTicket, now time.Time) {
|
||||
_ = s.PublishControlPlaneEvent(ControlPlaneEvent{
|
||||
Event: "state_changed", Revision: ticket.Revision, ResourceID: ticket.TicketID,
|
||||
OccurredAt: now, State: string(ticket.State), PlayerID: ticket.PlayerID,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) publishProposalEvent(proposal domain.Proposal, now time.Time) {
|
||||
for _, participant := range proposal.Participants {
|
||||
_ = s.PublishControlPlaneEvent(ControlPlaneEvent{
|
||||
Event: "proposal_changed", Revision: proposal.Revision, ResourceID: proposal.ProposalID,
|
||||
OccurredAt: now, State: string(proposal.State), PlayerID: participant.PlayerID,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func isWebSocketUpgrade(r *http.Request) bool {
|
||||
return strings.EqualFold(r.Header.Get("Upgrade"), "websocket") && headerContainsToken(r.Header.Values("Connection"), "upgrade")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user