2021-01-08 23:14:56 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2021-01-22 22:38:11 +00:00
|
|
|
"github.com/pterodactyl/wings/remote"
|
2021-01-08 23:14:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Manager interface {
|
|
|
|
// Initialize fetches all servers assigned to this node from the API.
|
|
|
|
Initialize(serversPerPage int) error
|
|
|
|
GetAll() []*Server
|
|
|
|
Get(uuid string) *Server
|
|
|
|
Add(s *Server)
|
|
|
|
Remove(s *Server)
|
|
|
|
}
|
|
|
|
|
|
|
|
type manager struct {
|
|
|
|
servers Collection
|
|
|
|
|
2021-01-22 22:38:11 +00:00
|
|
|
panelClient remote.Client
|
2021-01-08 23:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewManager creates a new server manager.
|
2021-01-22 22:38:11 +00:00
|
|
|
func NewManager(panelClient remote.Client) Manager {
|
2021-01-08 23:14:56 +00:00
|
|
|
return &manager{panelClient: panelClient}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *manager) GetAll() []*Server {
|
|
|
|
return m.servers.items
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *manager) Get(uuid string) *Server {
|
|
|
|
return m.servers.Find(func(s *Server) bool {
|
|
|
|
return s.Id() == uuid
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *manager) Add(s *Server) {
|
|
|
|
s.manager = m
|
|
|
|
m.servers.Add(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *manager) Remove(s *Server) {
|
|
|
|
m.servers.Remove(func(sf *Server) bool {
|
|
|
|
return sf.Id() == s.Id()
|
|
|
|
})
|
|
|
|
}
|