2019-09-23 03:47:38 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2019-12-01 02:07:05 +00:00
|
|
|
"github.com/pterodactyl/wings/parser"
|
2019-09-23 03:47:38 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2019-09-23 04:22:16 +00:00
|
|
|
const (
|
2019-12-01 02:07:05 +00:00
|
|
|
ProcessStopCommand = "command"
|
|
|
|
ProcessStopSignal = "signal"
|
2019-09-23 04:22:16 +00:00
|
|
|
ProcessStopNativeStop = "stop"
|
|
|
|
)
|
|
|
|
|
2019-09-23 03:47:38 +00:00
|
|
|
// Defines the process configuration for a given server instance. This sets what the
|
|
|
|
// daemon is looking for to mark a server as done starting, what to do when stopping,
|
|
|
|
// and what changes to make to the configuration file for a server.
|
|
|
|
type ServerConfiguration struct {
|
|
|
|
Startup struct {
|
|
|
|
Done string `json:"done"`
|
|
|
|
UserInteraction []string `json:"userInteraction"`
|
|
|
|
} `json:"startup"`
|
|
|
|
Stop struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
} `json:"stop"`
|
2019-12-01 02:07:05 +00:00
|
|
|
ConfigurationFiles []parser.ConfigurationFile `json:"configs"`
|
2019-09-23 03:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fetches the server configuration and returns the struct for it.
|
|
|
|
func (r *PanelRequest) GetServerConfiguration(uuid string) (*ServerConfiguration, error) {
|
|
|
|
resp, err := r.Get(fmt.Sprintf("/servers/%s/configuration", uuid))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
r.Response = resp
|
|
|
|
|
|
|
|
if r.HasError() {
|
|
|
|
e, err := r.Error()
|
|
|
|
zap.S().Warnw("got error", zap.String("message", e), zap.Error(err))
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res := &ServerConfiguration{}
|
|
|
|
b, _ := r.ReadBody()
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|