func init() { TRACE = fileLogger.NewDefaultLogger("/usr/local/aiwuTech/log", "trace.log") INFO = fileLogger.NewDefaultLogger("/usr/local/aiwuTech/log", "info.log") WARN = fileLogger.NewDefaultLogger("/usr/local/aiwuTech/log", "warn.log") ERROR = fileLogger.NewDefaultLogger("/usr/local/aiwuTech/log", "error.log") TRACE.SetPrefix("[TRACE] ") INFO.SetPrefix("[INFO] ") WARN.SetPrefix("[WARN] ") ERROR.SetPrefix("[ERROR] ") logFile = fileLogger.NewDefaultLogger("/usr/local/aiwuTech/log", "test.log") logFile.SetLogLevel(fileLogger.INFO) //trace log will not be print }
func main() { cfg := NewWsConfig(cfgFile) cfg.LoadConfig() curDir, err := os.Getwd() if err != nil { panic(err) } logFile = fileLogger.NewDefaultLogger(curDir+"/log", cfg.LogFile) logFile.SetPrefix("[ERROR] ") ws = NewWorldServer(cfg) err = ws.NewServer() if err != nil { println("World Server Error: 启动 WS 服务器 失败. ", err.Error()) logFile.Printf("World Server Error: 启动 WS 服务器 失败. ", err.Error()) return } println("World Key Server start:", ws.keyserver.GetListener().Addr().String()) println("World Server start:", ws.server.GetListener().Addr().String()) usermap = safemap.NewSafeMap() waitgroup = new(sync.WaitGroup) waitgroup.Add(2) go ws.KeyServe() go ws.Serve() //go ws.CheckUserState() waitgroup.Wait() ws.Stop() }
func main() { cfg := NewMsgServerConfig(cfgFile) cfg.LoadConfig() curDir, err := os.Getwd() if err != nil { panic(err) } logFile = fileLogger.NewDefaultLogger(curDir+"/log", cfg.LogFile) logFile.SetPrefix("[ERROR] ") ms = NewMsgServer(cfg) //连接 WS Key Server 获取 RC4 秘钥 if err = ms.ConnectToKeyServer(); err != nil { println("Msg Server Error: 连接 Key Server 失败. ", err.Error()) logFile.Printf("Msg Server Error: 连接 Key Server 失败. ", err.Error()) return } println("已连接 Key Server ...") if err = ms.ReceiveRc4Key(); err != nil { println("Msg Server Error: 接收 Rc4 Key 失败. ", err.Error()) logFile.Printf("Msg Server Error: 接收 Rc4 Key 失败. ", err.Error()) return } ms.wsKeySession.Close() println("已接收 RC4 秘钥...") //连接 WS if err = ms.ConnectToServer(); err != nil { println("Msg Server Error: 连接到 WS 失败. ", err.Error()) logFile.Printf("Msg Server Error: 连接到 WS 失败. ", err.Error()) return } //启动 Msg Server 服务端 err = ms.NewServer() if err != nil { println("Msg Server Error: 启动 Msg Server 失败. ", err.Error()) logFile.Printf("Msg Server Error: 启动 Msg Server 失败. ", err.Error()) return } println("Msg Key Server start:", ms.keyserver.GetListener().Addr().String()) println("Msg Server start:", ms.server.GetListener().Addr().String()) waitgroup = new(sync.WaitGroup) waitgroup.Add(4) go ms.KeyServe() go ms.Serve() go ms.Run() waitgroup.Wait() ms.Stop() }
func main() { cfg := NewClientConfig(cfgfile) cfg.LoadConfig() curDir, err := os.Getwd() if err != nil { panic(err) } logfile = fileLogger.NewDefaultLogger(curDir+"/log", cfg.LogFile) logfile.SetPrefix("[ERROR] ") client = NewClient(cfg) //连接到 Gateway Server,请求分配 Msg Server if err = client.ConnectToGatewayServer(); err != nil { println("Client Error: 连接到 GateWay Server 失败. ", err.Error()) logfile.Printf("Client Error: 连接到 GateWay Server 失败. %s", err.Error()) return } if err = client.ReceiveMSAddr(); err != nil { println("Client Error: 接收 Msg Server 地址信息错误. ", err.Error()) logfile.Printf("Client Error: 接收 Msg Server 地址信息错误. %s", err.Error()) return } client.session.Close() //连接 Msg Server if err = client.ConnectToMsgServer(); err != nil { println("Client Error: 连接到 Msg Server 失败. ", err.Error()) logfile.Printf("Client Error: 连接到 Msg Server 失败. %s", err.Error()) return } println("连接到 Msg Server....") //接收 RC4 秘钥 if err = client.ReceiveRc4Key(); err != nil { println("Client Error: 接收 RC4 Key 失败. ", err.Error()) logfile.Printf("Client Error: 接收 RC4 Key 失败. %s", err.Error()) return } waitgroup = new(sync.WaitGroup) //消息通信 waitgroup.Add(1) go client.HandleMsg() waitgroup.Add(1) go client.Run() waitgroup.Wait() client.Stop() }
func main() { cfg := NewGatewayConfig(cfgFile) cfg.LoadConfig() curDir, err := os.Getwd() if err != nil { panic(err) } logFile = fileLogger.NewDefaultLogger(curDir+"/log", cfg.LogFile) logFile.SetPrefix("[ERROR] ") gateway = NewGateway(cfg) err = gateway.NewServer() if err != nil { logFile.Println(err.Error()) return } println("Gateway Server start:", gateway.server.GetListener().Addr().String()) waitgroup = new(sync.WaitGroup) for { session, err := gateway.server.Accept() println("client conn:", session.GetConn().RemoteAddr().String()) if err != nil { println("GateWay Error: Client 连接失败. ", err.Error()) logFile.Printf("GateWay Error: Client 连接失败. %s", err.Error()) break } //分发msg server地址信息给该client waitgroup.Add(1) globalIndex = (globalIndex + 1) % gateway.cfg.MsgServerNum go gateway.HandleClient(session, globalIndex) } waitgroup.Wait() gateway.Stop() }