func main() {
	reader := bufio.NewReader(os.Stdin)
	commands, _ := reader.ReadString('\n')
	cmd := strings.Split(commands, " ")
	var c message.CalendarInfo
	c.Init(strings.Trim(cmd[0], "\n"))
	var mul tcpNet.Multicast
	mul.Init(&c, strings.Trim(cmd[1], "\n"))
	commands, _ = reader.ReadString('\n')
	for commands != "exit" {
		cmd = strings.Split(commands, " ")
		switch cmd[0] {
		case "uni":
			mul.SendUniMessage("lock_request", strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n"), 5000)
		case "multi":
			mul.SendMulticast("lock_reply", strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n"), 5000)
		// case "request": mul.LockRequest(strings.Trim(cmd[1], "\n"))
		// case "release": mul.LockRelease(strings.Trim(cmd[1], "\n"))
		// case "join": mul.VoteRequest(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n"))
		// case "info": go mul.SendInfo(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n"))
		default:
		}
		commands, _ = reader.ReadString('\n')
		commands = strings.Trim(commands, "\n")
		fmt.Println(commands)
	}
	mul.Info.WriteToFile("communication/message/config.txt")
	os.Exit(0)
}
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
	var transport thrift.TServerTransport
	var err error
	if secure {
		cfg := new(tls.Config)
		if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err == nil {
			cfg.Certificates = append(cfg.Certificates, cert)
		} else {
			return err
		}
		transport, err = thrift.NewTSSLServerSocket(addr, cfg)
	} else {
		transport, err = thrift.NewTServerSocket(addr)
	}

	if err != nil {
		return err
	}
	fmt.Printf("%T\n", transport)

	announce_client.InitAnnounceUDP()
	fmt.Println("111")
	timestamp.InitTimeStamp()
	fmt.Println("222")
	cryptowrapper.GenerateRSAKey()
	fmt.Println("333")
	var c message.CalendarInfo
	c.Init()
	fmt.Println("444")
	var mul tcpNet.Multicast
	mul.Init(&c)
	fmt.Println("555")
	handler := NewMyServiceHandler()
	processor := calendar.NewMyServiceProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", addr)
	return server.Serve()
}
func main() {
	announce_client.InitAnnounceUDP()
	timestamp.InitTimeStamp()
	cryptowrapper.GenerateRSAKey()
	var c message.CalendarInfo
	//    c.Init(strings.Trim(cmd[0], "\n"))
	c.Init()
	var mul tcpNet.Multicast
	mul.Init(&c)

	reader := bufio.NewReader(os.Stdin)
	commands, _ := reader.ReadString('\n')
	cmd := strings.Split(commands, " ")

	//commands, _ = reader.ReadString('\n')
	for commands != "exit" {
		cmd = strings.Split(commands, " ")
		switch cmd[0] {
		case "CreateGroup":
			mul.AddGroup(strings.Trim(cmd[1], "\n")) //group name
		case "join":
			mul.SendJoinRequest(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n"), strings.Trim(cmd[3], "\n")) //dest, group, invite_code
		case "VoteRequest":
			mul.VoteRequest(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n")) //(mem, group string)
		case "VoteReply":
			mul.VoteReply(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n")) //dest, decision string
		case "csRequest":
			mul.LockRequest(strings.Trim(cmd[1], "\n")) //group
		case "csRelease":
			mul.LockRelease(strings.Trim(cmd[1], "\n"))
		case "operation":
			mul.UpdateSend(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n")) //group, content
		// case "uni": mul.SendUniMessage("lock_request", strings.Trim(cmd[1], "\n"),strings.Trim(cmd[2], "\n"),5000)
		// case "multi": mul.SendMulticast("lock_reply", strings.Trim(cmd[1], "\n"),strings.Trim(cmd[2], "\n"),5000)
		// case "request": mul.LockRequest(strings.Trim(cmd[1], "\n"))
		// case "release": mul.LockRelease(strings.Trim(cmd[1], "\n"))
		// case "join": mul.VoteRequest(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n"))
		// case "info": go mul.SendInfo(strings.Trim(cmd[1], "\n"), strings.Trim(cmd[2], "\n"))
		case "exit":
			mul.Info.WriteToFile("communication/message/config.txt")
			os.Exit(0)
		default:
			mul.Info.WriteToFile("communication/message/config.txt")
			os.Exit(0)
		}
		commands, _ = reader.ReadString('\n')
		commands = strings.Trim(commands, "\n")
		fmt.Println(commands)
	}

}