main.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "log"
  7. "os"
  8. "os/signal"
  9. "syscall"
  10. "aytechnology.us/gominecraft/mod/aroz"
  11. "aytechnology.us/gominecraft/mod/config"
  12. "aytechnology.us/gominecraft/mod/server"
  13. )
  14. //MCServer should not be exported
  15. var MCServer *server.Handler
  16. //Config should not be exported
  17. var Config *config.Handler
  18. var serverConfig startupConfig
  19. type startupConfig struct {
  20. Java string `json:"java"`
  21. Min string `json:"min"`
  22. Max string `json:"max"`
  23. Jar string `json:"jar"`
  24. Folder string `json:"folder"`
  25. Arg string `json:"arg"`
  26. }
  27. var (
  28. handler *aroz.ArozHandler
  29. )
  30. //Kill signal handler. Do something before the system the core terminate.
  31. func SetupCloseHandler() {
  32. c := make(chan os.Signal, 2)
  33. signal.Notify(c, os.Interrupt, syscall.SIGTERM)
  34. go func() {
  35. <-c
  36. log.Println("\r- Shutting down demo module.")
  37. //Do other things like close database or opened files
  38. os.Exit(0)
  39. }()
  40. }
  41. func main() {
  42. //AROZOS
  43. //If you have other flags, please add them here
  44. //Start the aoModule pipeline (which will parse the flags as well). Pass in the module launch information
  45. handler = aroz.HandleFlagParse(aroz.ServiceInfo{
  46. Name: "Minecraft Server",
  47. Desc: "GO Minecraft",
  48. Group: "Development",
  49. IconPath: "gominecraft/icon.png",
  50. Version: "0.0.1",
  51. //You can define any path before the actualy html file. This directory (in this case demo/ ) will be the reverse proxy endpoint for this module
  52. StartDir: "gominecraft/index.html",
  53. SupportFW: true,
  54. LaunchFWDir: "gominecraft/index.html",
  55. SupportEmb: true,
  56. LaunchEmb: "gominecraft/404.html",
  57. InitFWSize: []int{720, 480},
  58. InitEmbSize: []int{720, 480},
  59. SupportedExt: []string{},
  60. })
  61. //init the startup configuration
  62. jsonFile, err := os.Open("./startup.json")
  63. if err != nil {
  64. fmt.Println(err)
  65. }
  66. byte, _ := ioutil.ReadAll(jsonFile)
  67. json.Unmarshal(byte, &serverConfig)
  68. MCServer = server.NewHandler(serverConfig.Java, serverConfig.Jar, serverConfig.Min, serverConfig.Max, serverConfig.Arg)
  69. Config = config.NewHandler(serverConfig.Folder)
  70. Config.AutoUpdate() //enable auto update
  71. CrashRestart()
  72. /*
  73. go func() {
  74. i := 0
  75. for {
  76. end := MCServer.LenLog()
  77. log := MCServer.ReadRangeLog(i, end)
  78. for _, line := range log {
  79. fmt.Println(line.Log)
  80. }
  81. i = end
  82. }
  83. }()
  84. */
  85. //To receive kill signal from the System core, you can setup a close handler to catch the kill signal
  86. //This is not nessary if you have no opened files / database running
  87. SetupCloseHandler()
  88. //Any log println will be shown in the core system via STDOUT redirection. But not STDIN.
  89. log.Println("gominecraft module started. Listening on " + handler.Port)
  90. webServer("./webroot/", serverConfig.Folder, handler.Port)
  91. }