main.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package main
  2. import (
  3. "fmt"
  4. mhayaConst "github.com/mhaya/const"
  5. "github.com/mhaya/game/game_cluster/nodes/center/center"
  6. "github.com/mhaya/game/game_cluster/nodes/game/game"
  7. "github.com/mhaya/game/game_cluster/nodes/webadmin"
  8. // "github.com/mhaya/game/game_cluster/nodes/gate"
  9. "github.com/mhaya/game/game_cluster/nodes/master/master"
  10. "github.com/mhaya/game/game_cluster/nodes/web/web"
  11. "github.com/urfave/cli/v2"
  12. "os"
  13. )
  14. func main() {
  15. app := &cli.App{
  16. Name: "game cluster node",
  17. Description: "game cluster node game",
  18. Commands: []*cli.Command{
  19. versionCommand(),
  20. masterCommand(),
  21. centerCommand(),
  22. webCommand(),
  23. //gateCommand(),
  24. gameCommand(),
  25. webadminCommand(),
  26. },
  27. }
  28. _ = app.Run(os.Args)
  29. }
  30. func versionCommand() *cli.Command {
  31. return &cli.Command{
  32. Name: "version",
  33. Aliases: []string{"ver", "v"},
  34. Usage: "view version",
  35. UsageText: "game cluster node version",
  36. Action: func(c *cli.Context) error {
  37. fmt.Println(mhayaConst.Version())
  38. return nil
  39. },
  40. }
  41. }
  42. func masterCommand() *cli.Command {
  43. return &cli.Command{
  44. Name: "master",
  45. Usage: "run master node",
  46. UsageText: "node master --path=./game/config/profile-gc.json --node=m-master",
  47. Flags: getFlag(),
  48. Action: func(c *cli.Context) error {
  49. path, node := getParameters(c)
  50. master.Run(path, node)
  51. return nil
  52. },
  53. }
  54. }
  55. func centerCommand() *cli.Command {
  56. return &cli.Command{
  57. Name: "center",
  58. Usage: "run center node",
  59. UsageText: "node center --path=./game/config/profile-gc.json --node=m-center",
  60. Flags: getFlag(),
  61. Action: func(c *cli.Context) error {
  62. path, node := getParameters(c)
  63. center.Run(path, node)
  64. return nil
  65. },
  66. }
  67. }
  68. func webCommand() *cli.Command {
  69. return &cli.Command{
  70. Name: "web",
  71. Usage: "run web node",
  72. UsageText: "node web --path=./game/config/profile-gc.json --node=m-web-1",
  73. Flags: getFlag(),
  74. Action: func(c *cli.Context) error {
  75. path, node := getParameters(c)
  76. web.Run(path, node)
  77. return nil
  78. },
  79. }
  80. }
  81. func webadminCommand() *cli.Command {
  82. return &cli.Command{
  83. Name: "webadmin",
  84. Usage: "run webadmin node",
  85. UsageText: "node webadmin --path=./game/config/profile-gc.json --node=m-webadmin-1",
  86. Flags: getFlag(),
  87. Action: func(c *cli.Context) error {
  88. path, node := getParameters(c)
  89. webadmin.Run(path, node)
  90. return nil
  91. },
  92. }
  93. }
  94. /*func gateCommand() *cli.Command {
  95. return &cli.Command{
  96. Name: "gate",
  97. Usage: "run gate node",
  98. UsageText: "node gate --path=./game/config/profile-gc.json --node=m-gate-1",
  99. Flags: getFlag(),
  100. Action: func(c *cli.Context) error {
  101. path, node := getParameters(c)
  102. gate.Run(path, node)
  103. return nil
  104. },
  105. }
  106. }*/
  107. func gameCommand() *cli.Command {
  108. return &cli.Command{
  109. Name: "game",
  110. Usage: "run game node",
  111. UsageText: "node game --path=./game/config/profile-gc.json --node=10001",
  112. Flags: getFlag(),
  113. Action: func(c *cli.Context) error {
  114. path, node := getParameters(c)
  115. game.Run(path, node)
  116. return nil
  117. },
  118. }
  119. }
  120. func getParameters(c *cli.Context) (path, node string) {
  121. path = c.String("path")
  122. node = c.String("node")
  123. return path, node
  124. }
  125. func getFlag() []cli.Flag {
  126. return []cli.Flag{
  127. &cli.StringFlag{
  128. Name: "path",
  129. Usage: "profile config path",
  130. Required: false,
  131. Value: "./game/config/profile-gc.json",
  132. },
  133. &cli.StringFlag{
  134. Name: "node",
  135. Usage: "node id name",
  136. Required: true,
  137. Value: "",
  138. },
  139. }
  140. }