Exemplo n.º 1
0
// One go-runtime per client
func (s *Server) createClient(conn *net.TCPConn) error {
	ilog.Printf("new client %s", conn.RemoteAddr().String())

	c := newClient(s, conn)

	if c.Start() == nil {
		s.cltList = append(s.cltList, c)
	}

	return nil
}
Exemplo n.º 2
0
func main() {
	parseFlag()

	if showVersion {
		fmt.Printf("version %s\n", "1.0.0")
		os.Exit(0)
	}

	//
	outputPid()

	l, err := ilog.InitLog("log")
	if err != nil {
		log.Fatalf("listen failed! [%s]", err.Error())
	}

	go signalHandle(l)

	if toProfile {
		prof.StartProf()
	}

	if err := config.Start(sConfigPath); err != nil {
		ilog.Printf("config start failed![%s]", err.Error())
	}

	if err := data.Start(); err != nil {
		ilog.Printf("data start failed![%s]", err.Error())
	}

	if err := monitor.Start(); err != nil {
		ilog.Printf("monitor start failed![%s]", err.Error())
	}

	if err := web.Start(); err != nil {
		ilog.Printf("web start failed![%s]", err.Error())
	}

	os.Exit(0)
}
Exemplo n.º 3
0
func (s *Server) globalTimer() {
	// 1 second interval
	go func() {
		ticker1 := time.NewTicker(1 * time.Second)
		ticker200Msec := time.NewTicker(200 * time.Millisecond)
		for {
			select {
			case <-ticker1.C:
				go func() {
					ilog.Printf("[%s]1 second ticker![%d clients]", time.Now().Format("2006-01-02 15:04:05.000"), len(s.cltList))
				}()
			case <-ticker200Msec.C:
				go func() {
					//ilog.Printf("[%s]200 msec ticker!", time.Now().Format("2006-01-02 15:04:05.000"))
				}()
			}
		}
	}()
}
Exemplo n.º 4
0
// Accept loop
func (s *Server) acceptLoop() error {
	addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", s.sc.Host, s.sc.Port))
	if err != nil {
		return err
	}
	s.listener, err = net.ListenTCP("tcp", addr)
	if err != nil {
		return err
	}

	for {
		conn, err := s.listener.AcceptTCP()
		if err != nil {
			ilog.Printf("accept error![%s]", err.Error())
		} else {
			s.createClient(conn)
		}
	}
	return nil
}
Exemplo n.º 5
0
func GetGSList() (*map[int]GSInfo, error) {
	db, err := GetDB()
	if err != nil {
		return nil, err
	}

	rows, err := db.Query("select * from gs_info")
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	gslist := make(map[int]GSInfo)
	var gi GSInfo
	for rows.Next() {
		err = rows.Scan(&gi.Id, &gi.Name, &gi.GroupId, &gi.Ip, &gi.Port, &gi.State, &gi.OlPlayer, &gi.OpenTime)
		if err == nil {
			gslist[gi.Id] = gi
			ilog.Printf("insert %d %s", gi.Id, gi.Name)
		}
	}

	return &gslist, nil
}
Exemplo n.º 6
0
func doTestTimer() {
	ilog.Printf("[%s]200 msec ticker!", time.Now().Format("2006-01-02 15:04:05.000"))
}
Exemplo n.º 7
0
func doCheckServerState() {
	ilog.Printf("[%s]1 second ticker!", time.Now().Format("2006-01-02 15:04:05.000"))
}
Exemplo n.º 8
0
func (s *Server) loadConfig() error {
	ilog.Printf("load config ok")
	return nil
}