break everything
- upgrade dependencies - run gofmt and goimports to organize code - fix typos - other small tweaks
This commit is contained in:
@@ -62,7 +62,7 @@ func (s *Server) Backup(b backup.BackupInterface) error {
|
||||
ignored := b.Ignored()
|
||||
if b.Ignored() == "" {
|
||||
if i, err := s.getServerwideIgnoredFiles(); err != nil {
|
||||
log.WithField("server", s.Id()).WithField("error", err).Warn("failed to get server-wide ignored files")
|
||||
log.WithField("server", s.ID()).WithField("error", err).Warn("failed to get server-wide ignored files")
|
||||
} else {
|
||||
ignored = i
|
||||
}
|
||||
|
||||
@@ -174,4 +174,4 @@ func (ad *ArchiveDetails) ToRequest(successful bool) remote.BackupRequest {
|
||||
Size: ad.Size,
|
||||
Successful: successful,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,10 @@ import (
|
||||
"os"
|
||||
|
||||
"emperror.dev/errors"
|
||||
|
||||
"github.com/pterodactyl/wings/server/filesystem"
|
||||
|
||||
"github.com/mholt/archiver/v3"
|
||||
|
||||
"github.com/pterodactyl/wings/remote"
|
||||
"github.com/pterodactyl/wings/server/filesystem"
|
||||
)
|
||||
|
||||
type LocalBackup struct {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"emperror.dev/errors"
|
||||
"github.com/mitchellh/colorstring"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/juju/ratelimit"
|
||||
"github.com/karrick/godirwalk"
|
||||
"github.com/klauspost/pgzip"
|
||||
"github.com/sabhiram/go-gitignore"
|
||||
ignore "github.com/sabhiram/go-gitignore"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
)
|
||||
|
||||
@@ -144,4 +144,4 @@ func wrapError(err error, resolved string) error {
|
||||
return err
|
||||
}
|
||||
return errors.WithStackDepth(&Error{code: ErrCodeUnknownError, err: err, resolved: resolved}, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
"emperror.dev/errors"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/karrick/godirwalk"
|
||||
ignore "github.com/sabhiram/go-gitignore"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
ignore "github.com/sabhiram/go-gitignore"
|
||||
)
|
||||
|
||||
type Filesystem struct {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
. "github.com/franela/goblin"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/client"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/remote"
|
||||
@@ -88,7 +89,7 @@ func (s *Server) Reinstall() error {
|
||||
|
||||
// Internal installation function used to simplify reporting back to the Panel.
|
||||
func (s *Server) internalInstall() error {
|
||||
script, err := s.client.GetInstallationScript(s.Context(), s.Id())
|
||||
script, err := s.client.GetInstallationScript(s.Context(), s.ID())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -156,7 +157,7 @@ func (s *Server) SetRestoring(state bool) {
|
||||
|
||||
// Removes the installer container for the server.
|
||||
func (ip *InstallationProcess) RemoveContainer() error {
|
||||
err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", types.ContainerRemoveOptions{
|
||||
err := ip.client.ContainerRemove(ip.context, ip.Server.ID()+"_installer", types.ContainerRemoveOptions{
|
||||
RemoveVolumes: true,
|
||||
Force: true,
|
||||
})
|
||||
@@ -206,7 +207,7 @@ func (ip *InstallationProcess) Run() error {
|
||||
|
||||
// Returns the location of the temporary data for the installation process.
|
||||
func (ip *InstallationProcess) tempDir() string {
|
||||
return filepath.Join(os.TempDir(), "pterodactyl/", ip.Server.Id())
|
||||
return filepath.Join(os.TempDir(), "pterodactyl/", ip.Server.ID())
|
||||
}
|
||||
|
||||
// Writes the installation script to a temporary file on the host machine so that it
|
||||
@@ -329,7 +330,7 @@ func (ip *InstallationProcess) BeforeExecute() error {
|
||||
|
||||
// Returns the log path for the installation process.
|
||||
func (ip *InstallationProcess) GetLogPath() string {
|
||||
return filepath.Join(config.Get().System.LogDirectory, "/install", ip.Server.Id()+".log")
|
||||
return filepath.Join(config.Get().System.LogDirectory, "/install", ip.Server.ID()+".log")
|
||||
}
|
||||
|
||||
// Cleans up after the execution of the installation process. This grabs the logs from the
|
||||
@@ -365,7 +366,7 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
|
||||
|
|
||||
| Details
|
||||
| ------------------------------
|
||||
Server UUID: {{.Server.Id}}
|
||||
Server UUID: {{.Server.ID}}
|
||||
Container Image: {{.Script.ContainerImage}}
|
||||
Container Entrypoint: {{.Script.Entrypoint}}
|
||||
|
||||
@@ -469,7 +470,7 @@ func (ip *InstallationProcess) Execute() (string, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
r, err := ip.client.ContainerCreate(ctx, conf, hostConf, nil, nil, ip.Server.Id()+"_installer")
|
||||
r, err := ip.client.ContainerCreate(ctx, conf, hostConf, nil, nil, ip.Server.ID()+"_installer")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -573,5 +574,5 @@ func (ip *InstallationProcess) resourceLimits() container.Resources {
|
||||
// server is. A boolean value of "true" means everything was successful, "false"
|
||||
// means something went wrong and the server must be deleted and re-created.
|
||||
func (s *Server) SyncInstallState(successful bool) error {
|
||||
return s.client.SetInstallationStatus(s.Context(), s.Id(), successful)
|
||||
return s.client.SetInstallationStatus(s.Context(), s.ID(), successful)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/apex/log"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/events"
|
||||
@@ -40,7 +41,7 @@ func (dsl *diskSpaceLimiter) Reset() {
|
||||
// 15 seconds, and terminate it forcefully if it does not stop.
|
||||
//
|
||||
// This function is only executed one time, so whenever a server is marked as booting the limiter
|
||||
// should be reset so it can properly be triggered as needed.
|
||||
// should be reset, so it can properly be triggered as needed.
|
||||
func (dsl *diskSpaceLimiter) Trigger() {
|
||||
dsl.o.Do(func() {
|
||||
dsl.server.PublishConsoleOutputFromDaemon("Server is exceeding the assigned disk space limit, stopping process now.")
|
||||
@@ -50,7 +51,7 @@ func (dsl *diskSpaceLimiter) Trigger() {
|
||||
})
|
||||
}
|
||||
|
||||
// Adds all of the internal event listeners we want to use for a server. These listeners can only be
|
||||
// StartEventListeners adds all the internal event listeners we want to use for a server. These listeners can only be
|
||||
// removed by deleting the server as they should last for the duration of the process' lifetime.
|
||||
func (s *Server) StartEventListeners() {
|
||||
console := func(e events.Event) {
|
||||
@@ -106,15 +107,15 @@ func (s *Server) StartEventListeners() {
|
||||
}
|
||||
|
||||
stats := func(e events.Event) {
|
||||
st := new(environment.Stats)
|
||||
if err := json.Unmarshal([]byte(e.Data), st); err != nil {
|
||||
var st environment.Stats
|
||||
if err := json.Unmarshal([]byte(e.Data), &st); err != nil {
|
||||
s.Log().WithField("error", err).Warn("failed to unmarshal server environment stats")
|
||||
return
|
||||
}
|
||||
|
||||
// Update the server resource tracking object with the resources we got here.
|
||||
s.resources.mu.Lock()
|
||||
s.resources.Stats = *st
|
||||
s.resources.Stats = st
|
||||
s.resources.mu.Unlock()
|
||||
|
||||
// If there is no disk space available at this point, trigger the server disk limiter logic
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/gammazero/workerpool"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/environment/docker"
|
||||
@@ -28,9 +29,9 @@ type Manager struct {
|
||||
servers []*Server
|
||||
}
|
||||
|
||||
// NewManager returns a new server manager instance. This will boot up all of
|
||||
// the servers that are currently present on the filesystem and set them into
|
||||
// the manager.
|
||||
// NewManager returns a new server manager instance. This will boot up all the
|
||||
// servers that are currently present on the filesystem and set them into the
|
||||
// manager.
|
||||
func NewManager(ctx context.Context, client remote.Client) (*Manager, error) {
|
||||
m := NewEmptyManager(client)
|
||||
if err := m.init(ctx); err != nil {
|
||||
@@ -52,7 +53,7 @@ func (m *Manager) Client() remote.Client {
|
||||
return m.client
|
||||
}
|
||||
|
||||
// Put replaces all of the current values in the collection with the value that
|
||||
// Put replaces all the current values in the collection with the value that
|
||||
// is passed through.
|
||||
func (m *Manager) Put(s []*Server) {
|
||||
m.mu.Lock()
|
||||
@@ -60,7 +61,7 @@ func (m *Manager) Put(s []*Server) {
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
// All returns all of the items in the collection.
|
||||
// All returns all the items in the collection.
|
||||
func (m *Manager) All() []*Server {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
@@ -78,7 +79,7 @@ func (m *Manager) Add(s *Server) {
|
||||
// found in the global collection or not.
|
||||
func (m *Manager) Get(uuid string) (*Server, bool) {
|
||||
match := m.Find(func(server *Server) bool {
|
||||
return server.Id() == uuid
|
||||
return server.ID() == uuid
|
||||
})
|
||||
return match, match != nil
|
||||
}
|
||||
@@ -130,7 +131,7 @@ func (m *Manager) Remove(filter func(match *Server) bool) {
|
||||
func (m *Manager) PersistStates() error {
|
||||
states := map[string]string{}
|
||||
for _, s := range m.All() {
|
||||
states[s.Id()] = s.Environment.State()
|
||||
states[s.ID()] = s.Environment.State()
|
||||
}
|
||||
data, err := json.Marshal(states)
|
||||
if err != nil {
|
||||
@@ -175,11 +176,11 @@ func (m *Manager) InitServer(data remote.ServerConfigurationResponse) (*Server,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.fs = filesystem.New(filepath.Join(config.Get().System.Data, s.Id()), s.DiskSpace(), s.Config().Egg.FileDenylist)
|
||||
s.fs = filesystem.New(filepath.Join(config.Get().System.Data, s.ID()), s.DiskSpace(), s.Config().Egg.FileDenylist)
|
||||
|
||||
// Right now we only support a Docker based environment, so I'm going to hard code
|
||||
// this logic in. When we're ready to support other environment we'll need to make
|
||||
// some modifications here obviously.
|
||||
// some modifications here, obviously.
|
||||
settings := environment.Settings{
|
||||
Mounts: s.Mounts(),
|
||||
Allocations: s.cfg.Allocations,
|
||||
@@ -191,7 +192,7 @@ func (m *Manager) InitServer(data remote.ServerConfigurationResponse) (*Server,
|
||||
Image: s.Config().Container.Image,
|
||||
}
|
||||
|
||||
if env, err := docker.New(s.Id(), &meta, envCfg); err != nil {
|
||||
if env, err := docker.New(s.ID(), &meta, envCfg); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
s.Environment = env
|
||||
@@ -212,7 +213,7 @@ func (m *Manager) InitServer(data remote.ServerConfigurationResponse) (*Server,
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// initializeFromRemoteSource iterates over a given directory and loads all of
|
||||
// initializeFromRemoteSource iterates over a given directory and loads all
|
||||
// the servers listed before returning them to the calling function.
|
||||
func (m *Manager) init(ctx context.Context) error {
|
||||
log.Info("fetching list of servers from API")
|
||||
@@ -252,7 +253,7 @@ func (m *Manager) init(ctx context.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
// Wait until we've processed all of the configuration files in the directory
|
||||
// Wait until we've processed all the configuration files in the directory
|
||||
// before continuing.
|
||||
pool.StopWait()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/apex/log"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
)
|
||||
|
||||
@@ -6,9 +6,10 @@ import (
|
||||
"time"
|
||||
|
||||
"emperror.dev/errors"
|
||||
"golang.org/x/sync/semaphore"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"golang.org/x/sync/semaphore"
|
||||
)
|
||||
|
||||
type PowerAction string
|
||||
@@ -18,7 +19,7 @@ type PowerAction string
|
||||
// example, sending two "start" actions back to back will not process the second action until
|
||||
// the first action has been completed.
|
||||
//
|
||||
// This utilizes a workerpool with a limit of one worker so that all of the actions execute
|
||||
// This utilizes a workerpool with a limit of one worker so that all the actions execute
|
||||
// in a sync manner.
|
||||
const (
|
||||
PowerActionStart = "start"
|
||||
@@ -27,7 +28,7 @@ const (
|
||||
PowerActionTerminate = "kill"
|
||||
)
|
||||
|
||||
// Checks if the power action being received is valid.
|
||||
// IsValid checks if the power action being received is valid.
|
||||
func (pa PowerAction) IsValid() bool {
|
||||
return pa == PowerActionStart ||
|
||||
pa == PowerActionStop ||
|
||||
@@ -39,7 +40,7 @@ func (pa PowerAction) IsStart() bool {
|
||||
return pa == PowerActionStart || pa == PowerActionRestart
|
||||
}
|
||||
|
||||
// Check if there is currently a power action being processed for the server.
|
||||
// ExecutingPowerAction checks if there is currently a power action being processed for the server.
|
||||
func (s *Server) ExecutingPowerAction() bool {
|
||||
if s.powerLock == nil {
|
||||
return false
|
||||
@@ -54,9 +55,9 @@ func (s *Server) ExecutingPowerAction() bool {
|
||||
return !ok
|
||||
}
|
||||
|
||||
// Helper function that can receive a power action and then process the actions that need
|
||||
// to occur for it. This guards against someone calling Start() twice at the same time, or
|
||||
// trying to restart while another restart process is currently running.
|
||||
// HandlePowerAction is a helper function that can receive a power action and then process the
|
||||
// actions that need to occur for it. This guards against someone calling Start() twice at the
|
||||
// same time, or trying to restart while another restart process is currently running.
|
||||
//
|
||||
// However, the code design for the daemon does depend on the user correctly calling this
|
||||
// function rather than making direct calls to the start/stop/restart functions on the
|
||||
@@ -107,7 +108,7 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
|
||||
// Release the lock once the process being requested has finished executing.
|
||||
defer s.powerLock.Release(1)
|
||||
} else {
|
||||
// Still try to acquire the lock if terminating and it is available, just so that other power
|
||||
// Still try to acquire the lock if terminating, and it is available, just so that other power
|
||||
// actions are blocked until it has completed. However, if it is unavailable we won't stop
|
||||
// the entire process.
|
||||
if ok := s.powerLock.TryAcquire(1); ok {
|
||||
@@ -190,14 +191,14 @@ func (s *Server) onBeforeStart() error {
|
||||
// Update the configuration files defined for the server before beginning the boot process.
|
||||
// This process executes a bunch of parallel updates, so we just block until that process
|
||||
// is complete. Any errors as a result of this will just be bubbled out in the logger,
|
||||
// we don't need to actively do anything about it at this point, worst comes to worst the
|
||||
// we don't need to actively do anything about it at this point, worse comes to worst the
|
||||
// server starts in a weird state and the user can manually adjust.
|
||||
s.PublishConsoleOutputFromDaemon("Updating process configuration files...")
|
||||
s.UpdateConfigurationFiles()
|
||||
|
||||
if config.Get().System.CheckPermissionsOnBoot {
|
||||
s.PublishConsoleOutputFromDaemon("Ensuring file permissions are set correctly, this could take a few seconds...")
|
||||
// Ensure all of the server file permissions are set correctly before booting the process.
|
||||
// Ensure all the server file permissions are set correctly before booting the process.
|
||||
if err := s.Filesystem().Chown("/"); err != nil {
|
||||
return errors.WithMessage(err, "failed to chown root server directory during pre-boot process")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/pterodactyl/wings/system"
|
||||
)
|
||||
|
||||
// Defines the current resource usage for a given server instance. If a server is offline you
|
||||
// ResourceUsage defines the current resource usage for a given server instance. If a server is offline you
|
||||
// should obviously expect memory and CPU usage to be 0. However, disk will always be returned
|
||||
// since that is not dependent on the server being running to collect that data.
|
||||
type ResourceUsage struct {
|
||||
@@ -26,7 +26,7 @@ type ResourceUsage struct {
|
||||
Disk int64 `json:"disk_bytes"`
|
||||
}
|
||||
|
||||
// Returns the current resource usage stats for the server instance. This returns
|
||||
// Proc returns the current resource usage stats for the server instance. This returns
|
||||
// a copy of the tracked resources, so making any changes to the response will not
|
||||
// have the desired outcome for you most likely.
|
||||
func (s *Server) Proc() ResourceUsage {
|
||||
@@ -38,11 +38,12 @@ func (s *Server) Proc() ResourceUsage {
|
||||
return s.resources
|
||||
}
|
||||
|
||||
// Resets the usages values to zero, used when a server is stopped to ensure we don't hold
|
||||
// Reset resets the usages values to zero, used when a server is stopped to ensure we don't hold
|
||||
// onto any values incorrectly.
|
||||
func (ru *ResourceUsage) Reset() {
|
||||
ru.mu.Lock()
|
||||
defer ru.mu.Unlock()
|
||||
|
||||
ru.Memory = 0
|
||||
ru.CpuAbsolute = 0
|
||||
ru.Network.TxBytes = 0
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/creasty/defaults"
|
||||
"golang.org/x/sync/semaphore"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/environment/docker"
|
||||
@@ -18,7 +20,6 @@ import (
|
||||
"github.com/pterodactyl/wings/remote"
|
||||
"github.com/pterodactyl/wings/server/filesystem"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
"golang.org/x/sync/semaphore"
|
||||
)
|
||||
|
||||
// Server is the high level definition for a server instance being controlled
|
||||
@@ -93,8 +94,8 @@ func New(client remote.Client) (*Server, error) {
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
// Id returns the UUID for the server instance.
|
||||
func (s *Server) Id() string {
|
||||
// ID returns the UUID for the server instance.
|
||||
func (s *Server) ID() string {
|
||||
return s.Config().GetUuid()
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ eloop:
|
||||
for k := range s.Config().EnvVars {
|
||||
// Don't allow any environment variables that we have already set above.
|
||||
for _, e := range out {
|
||||
if strings.HasPrefix(e, strings.ToUpper(k) + "=") {
|
||||
if strings.HasPrefix(e, strings.ToUpper(k)+"=") {
|
||||
continue eloop
|
||||
}
|
||||
}
|
||||
@@ -141,7 +142,7 @@ eloop:
|
||||
}
|
||||
|
||||
func (s *Server) Log() *log.Entry {
|
||||
return log.WithField("server", s.Id())
|
||||
return log.WithField("server", s.ID())
|
||||
}
|
||||
|
||||
// Sync syncs the state of the server on the Panel with Wings. This ensures that
|
||||
@@ -151,7 +152,7 @@ func (s *Server) Log() *log.Entry {
|
||||
// This also means mass actions can be performed against servers on the Panel
|
||||
// and they will automatically sync with Wings when the server is started.
|
||||
func (s *Server) Sync() error {
|
||||
cfg, err := s.client.GetServerConfiguration(s.Context(), s.Id())
|
||||
cfg, err := s.client.GetServerConfiguration(s.Context(), s.ID())
|
||||
if err != nil {
|
||||
if err := remote.AsRequestError(err); err != nil && err.StatusCode() == http.StatusNotFound {
|
||||
return &serverDoesNotExist{}
|
||||
@@ -246,7 +247,7 @@ func (s *Server) EnsureDataDirectoryExists() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sets the state of the server internally. This function handles crash detection as
|
||||
// OnStateChange sets the state of the server internally. This function handles crash detection as
|
||||
// well as reporting to event listeners for the server.
|
||||
func (s *Server) OnStateChange() {
|
||||
prevState := s.resources.State.Load()
|
||||
@@ -261,7 +262,7 @@ func (s *Server) OnStateChange() {
|
||||
s.Events().Publish(StatusEvent, st)
|
||||
}
|
||||
|
||||
// Reset the resource usage to 0 when the process fully stops so that all of the UI
|
||||
// Reset the resource usage to 0 when the process fully stops so that all the UI
|
||||
// views in the Panel correctly display 0.
|
||||
if st == environment.ProcessOfflineState {
|
||||
s.resources.Reset()
|
||||
@@ -293,7 +294,7 @@ func (s *Server) OnStateChange() {
|
||||
}
|
||||
|
||||
// IsRunning determines if the server state is running or not. This is different
|
||||
// than the environment state, it is simply the tracked state from this daemon
|
||||
// from the environment state, it is simply the tracked state from this daemon
|
||||
// instance, and not the response from Docker.
|
||||
func (s *Server) IsRunning() bool {
|
||||
st := s.Environment.State()
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"emperror.dev/errors"
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/imdario/mergo"
|
||||
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
)
|
||||
|
||||
@@ -25,7 +26,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
// Don't allow obviously corrupted data to pass through into this function. If the UUID
|
||||
// doesn't match something has gone wrong and the API is attempting to meld this server
|
||||
// instance into a totally different one, which would be bad.
|
||||
if src.Uuid != "" && s.Id() != "" && src.Uuid != s.Id() {
|
||||
if src.Uuid != "" && s.ID() != "" && src.Uuid != s.ID() {
|
||||
return errors.New("server/update: attempting to merge a data stack with an invalid UUID")
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ type WebsocketBag struct {
|
||||
conns map[uuid.UUID]*context.CancelFunc
|
||||
}
|
||||
|
||||
// Returns the websocket bag which contains all of the currently open websocket connections
|
||||
// Websockets returns the websocket bag which contains all the currently open websocket connections
|
||||
// for the server instance.
|
||||
func (s *Server) Websockets() *WebsocketBag {
|
||||
s.wsBagLocker.Lock()
|
||||
@@ -25,7 +25,7 @@ func (s *Server) Websockets() *WebsocketBag {
|
||||
return s.wsBag
|
||||
}
|
||||
|
||||
// Adds a new websocket connection to the stack.
|
||||
// Push adds a new websocket connection to the end of the stack.
|
||||
func (w *WebsocketBag) Push(u uuid.UUID, cancel *context.CancelFunc) {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
@@ -37,14 +37,14 @@ func (w *WebsocketBag) Push(u uuid.UUID, cancel *context.CancelFunc) {
|
||||
w.conns[u] = cancel
|
||||
}
|
||||
|
||||
// Removes a connection from the stack.
|
||||
// Remove removes a connection from the stack.
|
||||
func (w *WebsocketBag) Remove(u uuid.UUID) {
|
||||
w.mu.Lock()
|
||||
delete(w.conns, u)
|
||||
w.mu.Unlock()
|
||||
}
|
||||
|
||||
// Cancels all of the stored cancel functions which has the effect of disconnecting
|
||||
// CancelAll cancels all the stored cancel functions which has the effect of disconnecting
|
||||
// every listening websocket for the server.
|
||||
func (w *WebsocketBag) CancelAll() {
|
||||
w.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user