Ejemplo n.º 1
0
Archivo: main.go Proyecto: hycxa/gonet
//----------------------------------------------- Stats Server start
func main() {
	defer func() {
		if x := recover(); x != nil {
			log.Println("caught panic in main()", x)
		}
	}()

	config := cfg.Get()
	// start logger
	if config["stats_log"] != "" {
		cfg.StartLogger(config["stats_log"])
	}

	log.Println("Starting Stats Server")
	go SignalProc()
	go SysRoutine()

	// Listen
	service := DEFAULT_SERVICE
	if config["stats_service"] != "" {
		service = config["stats_service"]
	}

	log.Println("Stats Service:", service)
	udpAddr, err := net.ResolveUDPAddr("udp", service)
	checkError(err)

	udpconn, err := net.ListenUDP("udp", udpAddr)
	checkError(err)

	log.Println("Stats Server OK.")
	handleClient(udpconn)
}
Ejemplo n.º 2
0
//----------------------------------------------- HUB start
func HubStart() {
	// start logger
	config := cfg.Get()
	if config["hub_log"] != "" {
		cfg.StartLogger(config["hub_log"])
	}

	log.Println("Starting HUB")
	startup_work()
	go SignalProc()

	// Listen
	service := DEFAULT_SERVICE
	if config["hub_service"] != "" {
		service = config["hub_service"]
	}

	log.Println("Hub Service:", service)
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	log.Println("HUB Server OK.")
	for {
		conn, err := listener.AcceptTCP()
		if err != nil {
			continue
		}
		helper.SetConnParam(conn)
		go handleClient(conn)
	}
}
Ejemplo n.º 3
0
//----------------------------------------------- Game Server Start
func main() {
	// start logger
	config := cfg.Get()
	if config["gs_log"] != "" {
		cfg.StartLogger(config["gs_log"])
	}

	// inspector
	go inspect.StartInspect()

	// dial HUB
	hub_client.DialHub()
	event_client.DialEvent()
	stats_client.DialStats()

	log.Println("Starting the server.")
	// signal
	go SignalProc()

	// Listen
	service := ":8080"
	if config["service"] != "" {
		service = config["service"]
	}

	log.Println("Service:", service)
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	log.Println("Game Server OK.")

	for {
		conn, err := listener.Accept()

		if err != nil {
			continue
		}

		// DoS prevention
		IP := net.ParseIP(conn.RemoteAddr().String())
		if !IsBanned(IP) {
			go handleClient(conn)
		} else {
			conn.Close()
		}
	}
}
Ejemplo n.º 4
0
//----------------------------------------------- HUB
func main() {
	defer func() {
		if x := recover(); x != nil {
			log.Println("caught panic in main()", x)
		}
	}()

	// start logger
	config := cfg.Get()
	if config["hub_log"] != "" {
		cfg.StartLogger(config["hub_log"])
	}

	log.Println("Starting HUB")
	// signal handler
	go SignalProc()

	// sys routine
	go SysRoutine()

	// Listen
	service := DEFAULT_SERVICE
	if config["hub_service"] != "" {
		service = config["hub_service"]
	}

	log.Println("Hub Service:", service)
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	// load all users from db
	core.LoadAllUsers()

	log.Println("HUB Server OK.")
	for {
		conn, err := listener.AcceptTCP()
		if err != nil {
			continue
		}
		conn.SetLinger(-1)
		go handleClient(conn)
	}
}
Ejemplo n.º 5
0
//---------------------------------------------------------- Event Server start
func EventStart() {
	config := cfg.Get()
	if config["profile"] == "true" {
		helper.SetMemProfileRate(1)
		defer func() {
			helper.GC()
			helper.DumpHeap()
			helper.PrintGCSummary()
		}()
	}

	// start logger
	if config["event_log"] != "" {
		cfg.StartLogger(config["event_log"])
	}

	log.Println("Starting Event Server")
	startup_work()
	go SignalProc()

	// Listen
	service := DEFAULT_SERVICE
	if config["event_service"] != "" {
		service = config["event_service"]
	}

	log.Println("Event Service:", service)
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	log.Println("Event Server OK.")
	for {
		conn, err := listener.AcceptTCP()
		if err != nil {
			continue
		}
		helper.SetConnParam(conn)
		go handleClient(conn)
	}
}
Ejemplo n.º 6
0
//---------------------------------------------------------- game server start-up procedure
func startup() {
	INFO("Starting GS.")
	// start logger
	config := cfg.Get()
	if config["gs_log"] != "" {
		cfg.StartLogger(config["gs_log"])
	}

	// dial HUB
	hub_client.DialHub()

	// signal
	go SignalProc()

	// sys routine
	go SysRoutine()

	// stats
	go stats_client.DialStats()
}