package config import ( "fmt" "io/ioutil" "regexp" "strconv" "strings" "time" ) func initEULA(serverFolder string) []ServerConfig { properties := []ServerConfig{} b, err := ioutil.ReadFile(serverFolder + "/eula.txt") // just pass the file name if err != nil { fmt.Print(err) } str := string(b) // convert content to a 'string' lines := strings.Split(str, "\n") for _, line := range lines { regex := regexp.MustCompile("^(.*)=(.*[^=]*)$") regexSubmatch := regex.FindStringSubmatch(line) if len(regexSubmatch) > 0 { item := ServerConfig{ Key: strings.TrimSpace(regexSubmatch[1]), Value: strings.TrimSpace(regexSubmatch[2]), } properties = append(properties, item) } } return properties } //ReadEULA should exported. func (mch *Handler) ReadEULA() bool { b, _ := strconv.ParseBool(mch.eula[0].Value) return b } //WriteEULA should exported. func (mch *Handler) WriteEULA(accept bool) bool { mch.reloadEULA() mch.eula[0].Value = strconv.FormatBool(accept) mch.SaveEULA() return true } //SaveEULA is exported function func (mch *Handler) SaveEULA() bool { TXT := "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).\n" TXT += "#" + time.Now().Format("Mon Jan 02 15:04:05 MST 2006") + "\n" for _, line := range mch.eula { TXT += line.Key + "=" + line.Value + "\n" } err := ioutil.WriteFile(mch.serverFolder+"/eula.txt", []byte(TXT), 0777) if err != nil { fmt.Println(err) } return true } //there is no remove cuz EULA shouldn't be removed.