Exemplo n.º 1
0
func init() {
	var bytes []byte
	var err error
	var lines []string

	_, err = os.Stat(configFile)
	if !(err == nil || os.IsExist(err)) {
		goto Error
	}

	bytes, err = ioutil.ReadFile(configFile)
	if err != nil {
		goto Error
	}

	lines = strings.Split(string(bytes[:]), "\n")
	for _, v := range lines {
		strs := strings.Split(v, "= ")

		if len(strs) == 2 {
			strs[1] = strings.Replace(strs[1], "\n", "", -1)
			strs[1] = strings.Replace(strs[1], "\r", "", -1)
		} else {
			continue
		}

		if strings.Contains(v, CourierAddr) {
			configs[CourierAddr] = strs[1]
		} else if strings.Contains(v, CourierPort) {
			configs[CourierPort] = strs[1]
		} else if strings.Contains(v, WorkerAddr) {
			configs[WorkerAddr] = strs[1]
		} else if strings.Contains(v, AdminPort) {
			configs[AdminPort] = strs[1]
		} else if strings.Contains(v, MysqlAddr) {
			configs[MysqlAddr] = strs[1]
		} else if strings.Contains(v, MongoAddr) {
			configs[MongoAddr] = strs[1]
		}
	}

	for k, v := range configs {
		Logger.Println("[Parse Config] configs", k, v)
	}

	return

Error:
	Logger.Println("[Parse Config] Couldn't find config file, file name: config.m")
	os.Exit(0)
}
Exemplo n.º 2
0
func initLogger() bool {
	var flags int

	toConsole, err := utils.Config.GetBool("log", "console")
	if err != nil || toConsole {
		flags = logger.L_CONSOLE
	}

	toFile, err := utils.Config.GetBool("log", "file")
	if err != nil || toFile {
		flags = flags | logger.L_FILE
	}

	logFile, err := utils.Config.GetString("log", "filename")
	if err != nil || len(logFile) <= 0 {
		logFile = "log.txt"
	}

	logger.LogFilename = logFile
	logger.Flags = flags

	result := logger.Init()
	if !result {
		logger.Println("logger init faild")
	}

	return result

}
Exemplo n.º 3
0
func GetConfig(key string) string {
	if !strings.Contains(configs[key], "=") {
		return configs[key]
	} else {
		Logger.Println("[Parse Config] Couldn't find config key: " + key)
	}
	return ""
}
Exemplo n.º 4
0
func Stop() {
	running = false
	ticker.Stop()
	close(chMonitorStop)
	checkState()

	Logger.Println("[ShutDown] Monitor Stop!")
}
Exemplo n.º 5
0
/**
  初始化世界
*/
func InitWorld() (result bool) {
	logger.Println("init world")
	WPlayerMgr = new(PlayerManager)
	WPlayerService = NewPlayerService()

	go worldloop()
	result = true
	return
}
Exemplo n.º 6
0
Arquivo: main.go Projeto: cokeboL/ZIM
func EventMgrExample() {
	mgr := EventMgr.NewEventMgr("haha")
	emgr := EventMgr.GetEventMgrByTag("haha")

	emgr.NewListener("listener_001", 3, func(e interface{}, args []interface{}) {
		Logger.Println("--- event 001 : ", e, args[0])
	})
	emgr.NewListener("listener_002", 3, func(e interface{}, args []interface{}) {
		Logger.Println("--- event 002 : ", e, args[0], args[1])
	})
	emgr.NewListener("listener_003", 3, func(e interface{}, args []interface{}) {
		Logger.Println("--- event 003 : ", e, args[0], args[1], args[2])
	})
	emgr.NewListener("listener_004", 3, func(e interface{}, args []interface{}) {
		Logger.Println("--- event 004 : ", e, args[0], args[1])
	})

	emgr.Dispatch(3, "ss", 10000)
	mgr.Dispatch(3, "yy", 10000, "xx")
	mgr.Dispatch(3)
}
Exemplo n.º 7
0
Arquivo: main.go Projeto: cokeboL/ZIM
func WaitStop() {
	exitCode := <-chAppStop

	Monitor.Stop()

	NetCore.StopTcpServer()

	SigHandler.Stop()

	Logger.Stop()

	Logger.Println("[ShutDown] Server Stop, exitCode:", ErrConf.GetErrString(exitCode))

	os.Exit(0)
}
Exemplo n.º 8
0
func NewServer() *Server {
	logger.Println("init server...")
	server := Server{}
	port, err := utils.Config.GetString("default", "port")
	if err != nil || len(port) <= 0 {
		port = "9080"
	}
	server.Port = port

	version, err := utils.Config.GetInt("default", "clientversion")
	if err != nil {
		version = 0
	}
	server.ClientVersion = version

	server.TimeoutCount = 0

	return &server
}
Exemplo n.º 9
0
func main() {
	SigHandler.Start(chAppStop)

	Logger.Start(1, 1, 1)

	Monitor.Start(Commen.GetConfig(Commen.AdminMonitorAddr), NetConf.MONITOR_INTERNAL, chAppStop)

	ServerJob.InitHandlers()

	ServerJob.InitAgent(Commen.GetConfig(Commen.CourierAddr), NetConf.Admin, chAppStop)

	port, err := strconv.Atoi(Commen.GetConfig(Commen.AdminPort))
	if err != nil {
		Logger.Println("Server Stop, Get Config Port Error:", Commen.GetConfig(Commen.AdminPort), err)
		os.Exit(0)
	}
	HomePage.Start(port)

	WaitStop()
}
Exemplo n.º 10
0
func StopTcpServer() {
	serverRunning = false

	clientValidTimer.Stop()
	agentHeartbeatTmer.Stop()

	for {
		if len(ClientIdMap) == 0 {
			break
		}

		for _, client := range IdClientMap {
			client.ClearAllCloseCB()
			client.Stop()
		}
		time.Sleep(time.Second / 20)
	}

	Logger.Println("[ShutDown] TcpServer Stop!")
}
Exemplo n.º 11
0
func InitHandlers() {
	Logger.Println("Courier ServerJob", LogConf.SERVER, "ServerAgent init()")

	NetCore.AddMsgHandler(MsgConf.Regist, handleRegist)
}
Exemplo n.º 12
0
func InitHandlers() {
	Logger.Println(LogConf.CourierServerJob, LogConf.SERVER, "Server Handlers InitHandlers()")

	NetCore.AddMsgHandler(MsgConf.Courier, handleCourier)
	NetCore.AddMsgHandler(MsgConf.Regist, handleServerRegist)
}
Exemplo n.º 13
0
func InitHandlers() {
	Logger.Println("Courier ServerJob", LogConf.SERVER, "ServerAgent init()")
}
Exemplo n.º 14
0
func AddMsgHandler(cmd uint32, cb HandlerCB) {
	Logger.Println(LogConf.NetCoreClient, LogConf.SERVER, "AddMsgHandler", cmd, cb)

	handlerMap[cmd] = cb
}
Exemplo n.º 15
0
Arquivo: DBMgr.go Projeto: cokeboL/ZIM
func Stop() {
	stopMysqlMgr()
	stopMongoMgr()

	Logger.Println("[ShutDown] DBMgr Stop!")
}