Refactor environment handling logic to separate a server from the environment handler itself

This change makes the environment handling logic execute independent of the server itself and should make it much easier for people to contribute changes and additional environment handlers down the road without polluting the server object even more.

There is still a lot of work to do on this front to make things easier to work with, and there are some questionable design decisions at play I'm sure.

Welcome to additional modifications and cleanup to make this code easier to reason about and work with.
This commit is contained in:
Dane Everitt
2020-08-10 21:38:42 -07:00
committed by GitHub
parent 2c8cad2410
commit cc52954a2a
30 changed files with 1669 additions and 1350 deletions

View File

@@ -2,6 +2,7 @@ package websocket
import (
"context"
"github.com/pterodactyl/wings/events"
"github.com/pterodactyl/wings/server"
"time"
)
@@ -38,7 +39,7 @@ func (h *Handler) ListenForExpiration(ctx context.Context) {
// Listens for different events happening on a server and sends them along
// to the connected websocket.
func (h *Handler) ListenForServerEvents(ctx context.Context) {
events := []string{
e := []string{
server.StatsEvent,
server.StatusEvent,
server.ConsoleOutputEvent,
@@ -49,15 +50,15 @@ func (h *Handler) ListenForServerEvents(ctx context.Context) {
server.BackupCompletedEvent,
}
eventChannel := make(chan server.Event)
for _, event := range events {
eventChannel := make(chan events.Event)
for _, event := range e {
h.server.Events().Subscribe(event, eventChannel)
}
for d := range eventChannel {
select {
case <-ctx.Done():
for _, event := range events {
for _, event := range e {
h.server.Events().Unsubscribe(event, eventChannel)
}