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) }
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 }
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 "" }
func Stop() { running = false ticker.Stop() close(chMonitorStop) checkState() Logger.Println("[ShutDown] Monitor Stop!") }
/** 初始化世界 */ func InitWorld() (result bool) { logger.Println("init world") WPlayerMgr = new(PlayerManager) WPlayerService = NewPlayerService() go worldloop() result = true return }
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) }
func WaitStop() { exitCode := <-chAppStop Monitor.Stop() NetCore.StopTcpServer() SigHandler.Stop() Logger.Stop() Logger.Println("[ShutDown] Server Stop, exitCode:", ErrConf.GetErrString(exitCode)) os.Exit(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 }
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() }
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!") }
func InitHandlers() { Logger.Println("Courier ServerJob", LogConf.SERVER, "ServerAgent init()") NetCore.AddMsgHandler(MsgConf.Regist, handleRegist) }
func InitHandlers() { Logger.Println(LogConf.CourierServerJob, LogConf.SERVER, "Server Handlers InitHandlers()") NetCore.AddMsgHandler(MsgConf.Courier, handleCourier) NetCore.AddMsgHandler(MsgConf.Regist, handleServerRegist) }
func InitHandlers() { Logger.Println("Courier ServerJob", LogConf.SERVER, "ServerAgent init()") }
func AddMsgHandler(cmd uint32, cb HandlerCB) { Logger.Println(LogConf.NetCoreClient, LogConf.SERVER, "AddMsgHandler", cmd, cb) handlerMap[cmd] = cb }
func Stop() { stopMysqlMgr() stopMongoMgr() Logger.Println("[ShutDown] DBMgr Stop!") }