예제 #1
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()
		}
	}
}
예제 #2
0
파일: startup_work.go 프로젝트: hycxa/gonet
//---------------------------------------------------------- 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()
}