package main

import (
	"fmt"

	"aytechnology.us/gominecraft/mod/config"
)

//"os"
//"io"
//"os/exec"
//"strings"
//"time"

func main() {
	mcs := config.NewHandler("./server/")
	/*
		p := mcs.ReadAllProperties()
		fmt.Println(p)
		mcs.ChangeProperties("gamemode", "creative")
		mcs.SaveProperties()
	*/
	/*
		q := mcs.ReadAllBannedIPs()
		fmt.Println(q)
		mcs.WriteBannedIP("111.11.11.11", "2020-12-13", "Srv", "forever", "LLM")
		q = mcs.ReadBannedIP("LLM", "reason")
		fmt.Println(q)
		mcs.RemoveBannedIP("dllmeaa", "reason")
		q = mcs.ReadAllBannedIPs()
		fmt.Println(q)
		mcs.SaveAllBannedIPs()
	*/
	/*
		r := mcs.ReadAllBannedPlayers()
		fmt.Println(r)
		mcs.WriteBannedPlayer("1234", "HyperXraft", "2020-12-12", "Serrver", "forever", "FUCK")
		fmt.Println(mcs.ReadBannedPlayer("HyperXraft", "name"))
		r = mcs.ReadAllBannedPlayers()
		fmt.Println(r)
		mcs.RemoveBannedPlayer("HyperXraft", "name")
		r = mcs.ReadAllBannedPlayers()
		fmt.Println(r)
		mcs.SaveAllBannedPlayers()
	*/
	/*
		s := mcs.ReadAllOps()
		fmt.Println(s)
		mcs.WriteOps("ffff", "Hyper", 3, true)
		s = mcs.ReadAllOps()
		fmt.Println(s)
		fmt.Println(mcs.ReadOps("Hyper", "name"))
		mcs.RemoveOps("TC", "name")
		s = mcs.ReadAllOps()
		fmt.Println(s)
		mcs.SaveAllOps()
	*/
	/*
		t := mcs.ReadAllWhitelists()
		fmt.Println(t)
		mcs.WriteWhitelist("1234", "TC")
		t = mcs.ReadAllWhitelists()
		fmt.Println(t)
		fmt.Println(mcs.ReadWhitelist("TC", "name"))
		mcs.RemoveWhitelist("Alanyeung", "name")
		mcs.SaveAllWhitelists()
	*/
	u := mcs.ReadEULA()
	fmt.Println(u)
	mcs.WriteEULA(false)
	u = mcs.ReadEULA()
	fmt.Println(u)
	mcs.SaveEULA()
	/*
		cmdName := "java -Xmx1024M -Xms1024M -jar server.jar nogui"
		cmdArgs := strings.Fields(cmdName)

		cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
		cmd.Dir = "./server"
		stdout, _ := cmd.StdoutPipe()
		stdin, _ := cmd.StdinPipe()
		cmd.Start()
		oneByte := make([]byte, 4096)

		go func() {
			for {
				_, err := stdout.Read(oneByte)
				if err != nil {
					fmt.Printf(err.Error())
					break
				}
				r := bufio.NewReader(stdout)
				line, _, _ := r.ReadLine()
				fmt.Println(string(line))
			}
		}()
		num := 0
		for {
			time.Sleep(2 * time.Second)
			defer stdin.Close()

			resp, _ := mcping.Ping("localhost:25565")
			fmt.Println(resp.Online, "players online")
			for _, user := range resp.Sample {
				io.WriteString(stdin, "/kick " + user.Name + " Server fucked up!\n")
			}


			num = num + 1
			if num > 30 {
				io.WriteString(stdin, "/stop\n")
			}
			if num > 33 {
				cmd.Process.Kill()
				os.Exit(0)
			}
		}

		cmd.Wait()
	*/
}
