2019-04-20 23:20:08 +00:00
|
|
|
package server
|
|
|
|
|
2020-01-18 22:04:26 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/colorstring"
|
|
|
|
"io"
|
|
|
|
)
|
2019-04-20 23:20:08 +00:00
|
|
|
|
|
|
|
type Console struct {
|
2020-01-18 22:04:26 +00:00
|
|
|
Server *Server
|
2019-04-20 23:20:08 +00:00
|
|
|
HandlerFunc *func(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ io.Writer = Console{}
|
|
|
|
|
|
|
|
func (c Console) Write(b []byte) (int, error) {
|
|
|
|
if c.HandlerFunc != nil {
|
|
|
|
l := make([]byte, len(b))
|
|
|
|
copy(l, b)
|
|
|
|
|
|
|
|
(*c.HandlerFunc)(string(l))
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(b), nil
|
2020-01-18 22:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sends output to the server console formatted to appear correctly as being sent
|
|
|
|
// from Wings.
|
|
|
|
func (s *Server) PublishConsoleOutputFromDaemon(data string) {
|
|
|
|
s.Events().Publish(
|
|
|
|
ConsoleOutputEvent,
|
|
|
|
colorstring.Color(fmt.Sprintf("[yellow][bold][Pterodactyl Daemon]:[default] %s", data)),
|
|
|
|
)
|
|
|
|
}
|