Close connected sockets when a server is deleted; closes pterodactyl/panel#2428

This commit is contained in:
Dane Everitt
2020-10-03 20:46:29 -07:00
parent e02c197585
commit 37e59e6928
5 changed files with 101 additions and 0 deletions

View File

@@ -34,9 +34,11 @@ const (
type Handler struct {
sync.RWMutex
Connection *websocket.Conn
jwt *tokens.WebsocketPayload `json:"-"`
server *server.Server
uuid uuid.UUID
}
var (
@@ -99,13 +101,23 @@ func GetHandler(s *server.Server, w http.ResponseWriter, r *http.Request) (*Hand
return nil, err
}
u, err := uuid.NewRandom()
if err != nil {
return nil, errors.WithStack(err)
}
return &Handler{
Connection: conn,
jwt: nil,
server: s,
uuid: u,
}, nil
}
func (h *Handler) Uuid() uuid.UUID {
return h.uuid
}
func (h *Handler) SendJson(v *Message) error {
// Do not send JSON down the line if the JWT on the connection is not valid!
if err := h.TokenValid(); err != nil {