57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"git.canopymc.net/Etzelia/mineauth/server"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/peterbourgon/ff/v3"
|
|
"github.com/peterbourgon/ff/v3/fftoml"
|
|
"go.jolheiser.com/beaver"
|
|
)
|
|
|
|
func main() {
|
|
fs := flag.NewFlagSet("mineauth", flag.ExitOnError)
|
|
portFlag := fs.Int("port", 25565, "Port to listen on")
|
|
timeoutFlag := fs.Int("timeout", 15, "HTTP timeout")
|
|
pingMessageFlag := fs.String("ping", "Login to authenticate!", "Message for the server list")
|
|
communityFlag := fs.String("community", "", "URL to community")
|
|
hooksFlag := make([]string, 0)
|
|
fs.Func("hook", "Hook to run", func(hook string) error {
|
|
hooksFlag = append(hooksFlag, hook)
|
|
return nil
|
|
})
|
|
debugFlag := fs.Bool("debug", false, "Debug Logging")
|
|
if err := ff.Parse(fs, os.Args[1:],
|
|
ff.WithEnvVarPrefix("MCM_REGISTER"),
|
|
ff.WithConfigFileFlag("config"),
|
|
ff.WithAllowMissingConfigFile(true),
|
|
ff.WithConfigFileParser(fftoml.New().Parse),
|
|
); err != nil {
|
|
beaver.Fatal(err)
|
|
return
|
|
}
|
|
if *debugFlag {
|
|
beaver.Console.Level = beaver.DEBUG
|
|
}
|
|
|
|
http.DefaultClient.Timeout = time.Second * time.Duration(*timeoutFlag)
|
|
|
|
serv, err := server.New(server.Options{
|
|
PingMessage: *pingMessageFlag,
|
|
CommunityURL: *communityFlag,
|
|
Hooks: hooksFlag,
|
|
})
|
|
if err != nil {
|
|
beaver.Error(err)
|
|
return
|
|
}
|
|
|
|
beaver.Infof("Listening on http://localhost:%d", *portFlag)
|
|
if err := serv.Start(*portFlag); err != nil {
|
|
beaver.Error(err)
|
|
}
|
|
}
|