Files
mc-tool/server/status.go
2026-06-25 21:35:09 -04:00

39 lines
650 B
Go

package server
import (
"bytes"
"fmt"
"os/exec"
"github.com/spf13/cobra"
)
func Status(cmd *cobra.Command, args []string) {
dir := "."
if len(args) > 0 {
dir = args[0]
}
name := getServerName(dir)
status_cmd := exec.Command("docker", "exec", name, "rcon-cli", "list")
var outb, errb bytes.Buffer
status_cmd.Stdout = &outb
status_cmd.Stderr = &errb
if err := status_cmd.Run(); err != nil {
fmt.Println("offline")
return
}
var active, max int
_, err := fmt.Sscanf(outb.String(), "There are %d of a max of %d players online:", &active, &max)
if err != nil {
panic(err)
}
fmt.Printf("%d/%d players\n", active, max)
}