package main import ( "dcg/client" "dcg/game" "errors" "github.com/urfave/cli" "log" "os" ) func main() { app := cli.NewApp() app.Name = "弹幕指挥官 GameServer" app.Author = "NorthLan" app.Email = "6995syu@163.com" app.Description = "弹幕指挥官 TCP服务端" app.Commands = []cli.Command{ { Name: "server", Flags: []cli.Flag{ cli.StringFlag{ Name: "listen,l", Usage: "-l --listen [ip]:8888", Value: "127.0.0.1:8888", }, }, Action: runMaster, }, { Name: "client", Flags: []cli.Flag{ cli.StringFlag{ Name: "addr", Usage: "--addr xxx:xxx", Value: "127.0.0.1:8888", }, }, Action: runClient, }, } if err := app.Run(os.Args); err != nil { log.Fatalf("Startup server error %+v", err) } } func runMaster(args *cli.Context) error { listen := args.String("listen") if listen == "" { return errors.New("master listen address cannot empty") } log.Println("Game server listen address", listen) game.Run(listen) return nil } func runClient(args *cli.Context) error { addr := args.String("addr") if addr == "" { return errors.New("address cannot empty") } log.Println("Client start, connect to", addr) return client.NewClient(addr) }