main.go 1.9 KB

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