package main

import (
	//"aytechnology.us/gominecraft/mod/mcping"
	"aytechnology.us/gominecraft/mod/config"
	//"bufio"
	"fmt"
	//"os"
	//"io"
	//"os/exec"
	//"strings"
	//"time"
)

func main() {
	mcs := config.NewHandler("./server/")

	p := mcs.ReadAllProperties()
	fmt.Println(p)

	mcs.ChangeProperties("max-players", "99")
	p = mcs.ReadAllProperties()
	fmt.Println(p)

	/*
		q := mcs.ReadAllBannedIPs()
		fmt.Println(q)
		r := mcs.ReadAllBannedPlayers()
		fmt.Println(r)
		s := mcs.ReadAllOps()
		fmt.Println(s)
		t := mcs.ReadAllWhitelists()
		fmt.Println(t)
		u := mcs.ReadEULA()
		fmt.Println(u)
	*/
	/*
		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()
	*/
}
