minecraft-server-invites/minecraft/minecraft.go
Gabriel Simmer 7f1ba6222d Initial commit of MVP API
Includes Microsoft->Minecraft OAuth, simple server adding and invite
generation, and invite acceptance/RCON whitelisting.
2022-07-05 11:10:18 +01:00

36 lines
776 B
Go

package minecraft
import (
"errors"
"fmt"
mcrcon "github.com/Kelwing/mc-rcon"
"whitelistmanager/store"
)
const (
RconConnectionError = "rcon connection failed"
RconAuthError = "failed to authenticate with rcon server"
RconCommandError = "command failed"
)
func Whitelist(user string, server store.Server) (string, error) {
conn := new(mcrcon.MCConn)
err := conn.Open(server.Rcon.Address, server.Rcon.Password)
if err != nil {
return "", errors.New(RconConnectionError)
}
defer conn.Close()
err = conn.Authenticate()
if err != nil {
return "", errors.New(RconAuthError)
}
command := fmt.Sprintf("whitelist add %s", user)
resp, err := conn.SendCommand(command)
if err != nil {
return "", errors.New(RconCommandError)
}
return resp, nil
}