main.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package main
  2. import (
  3. cherryApp "f1-game/internal/cherry_app"
  4. "f1-game/internal/constant"
  5. "f1-game/internal/version"
  6. "f1-game/nodes/center"
  7. "f1-game/nodes/chat"
  8. "f1-game/nodes/game"
  9. "f1-game/nodes/gate"
  10. sandMap "f1-game/nodes/map"
  11. "f1-game/nodes/master"
  12. "f1-game/nodes/ops"
  13. "f1-game/nodes/pay"
  14. "f1-game/nodes/record"
  15. "f1-game/nodes/web"
  16. "fmt"
  17. "os"
  18. cherryFacade "github.com/cherry-game/cherry/facade"
  19. cherryProfile "github.com/cherry-game/cherry/profile"
  20. "github.com/urfave/cli/v2"
  21. )
  22. var (
  23. nodeTypeRunMap = map[string]func(cherryFacade.INode){}
  24. )
  25. func init() {
  26. nodeTypeRunMap[constant.NodeCenter] = center.Run
  27. nodeTypeRunMap[constant.NodeGame] = game.Run
  28. nodeTypeRunMap[constant.NodeGate] = gate.Run
  29. nodeTypeRunMap[constant.NodeMaster] = master.Run
  30. nodeTypeRunMap[constant.NodePay] = pay.Run
  31. nodeTypeRunMap[constant.NodeWeb] = web.Run
  32. nodeTypeRunMap[constant.NodeOPS] = ops.Run
  33. nodeTypeRunMap[constant.NodeChat] = chat.Run
  34. nodeTypeRunMap[constant.NodeMap] = sandMap.Run
  35. nodeTypeRunMap[constant.NodeRecord] = record.Run
  36. }
  37. func main() {
  38. app := &cli.App{
  39. Usage: "f1 game server node",
  40. Commands: []*cli.Command{
  41. runCommand(),
  42. versionCommand(),
  43. },
  44. }
  45. if err := app.Run(os.Args); err != nil {
  46. fmt.Println(err)
  47. }
  48. }
  49. func runCommand() *cli.Command {
  50. return &cli.Command{
  51. Name: "run",
  52. Usage: "-path=./config/profile-dev.json -node=10001",
  53. Flags: cherryApp.GetFlag(),
  54. Action: func(ctx *cli.Context) error {
  55. path, nodeID := cherryApp.GetParameters(ctx)
  56. node, err := cherryProfile.Init(path, nodeID)
  57. if err != nil {
  58. return err
  59. }
  60. runFunc, found := nodeTypeRunMap[node.NodeType()]
  61. if !found {
  62. return fmt.Errorf("[NodeType = %s] not found", node.NodeType())
  63. }
  64. runFunc(node)
  65. return nil
  66. },
  67. }
  68. }
  69. func versionCommand() *cli.Command {
  70. return &cli.Command{
  71. Name: "version",
  72. Aliases: []string{"ver", "v"},
  73. Usage: "view node version",
  74. Action: func(c *cli.Context) error {
  75. version.Print()
  76. return nil
  77. },
  78. }
  79. }