func main() { var err error defer func() { if x := recover(); x != nil { fmt.Fprintf(os.Stderr, "Fatal error: %s\nExiting.", x) os.Exit(1) } }() confFile := flag.String("c", "./mcbot.conf", "The location of the configuration file to be used.") flag.Parse() if config, err = ReadConfig(*confFile); err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) } if bot, err = ircbot.NewBot(config.Nick, config.Pass, config.IrcDomain, config.IrcServer, config.IrcPort, config.SSL, config.AttnChar[0]); err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) } if server, err = mcserver.NewServer(config.MCServerCommand.Command, config.MCServerCommand.Args, config.MCServerDir, logInfo, logErr); err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) } go commandDispatch() go readConsoleInput() go teeServerOutput() bot.SetPrivmsgHandler(directedIRC, echoIRCToServer) bot.JoinChannel(config.IrcChan, config.IrcChanKey) select {} }
func main() { var serverJar = flag.String("jar", "", "the /path/to/minecraft_server.jar (required)") var serverDir = flag.String("dir", ".", "the /path/to/minecraft/configs") flag.Parse() if *serverJar == "" { fmt.Fprintln(os.Stderr, "You must specify the location of the minecraft jar with --jar.") os.Exit(1) } logInfo = log.New(os.Stdout, "[I] ", log.LstdFlags|log.Lshortfile) logErr = log.New(os.Stderr, "[E] ", log.LstdFlags|log.Lshortfile) server, err := mc.NewServer("java", []string{"-Xms1024M", "-Xmx1024M", "-jar", *serverJar, "nogui"}, *serverDir, logInfo, logErr) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } go readIn(server.In, server) go writeOut(server.Out) go writeErr(server.Err) err = server.Start() if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } fmt.Println("Main Sleeping") select {} }