fishhall.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package main
  2. import (
  3. _ "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "os"
  7. "strconv"
  8. "time"
  9. "bet24.com/log"
  10. "bet24.com/redis"
  11. coreservice "bet24.com/servers/coreservice/client"
  12. _ "bet24.com/servers/coreservice/servicesink"
  13. "bet24.com/servers/fishhall/config"
  14. "bet24.com/servers/fishhall/gatesink"
  15. slotmanager "bet24.com/servers/games/slotcommon/manager"
  16. "bet24.com/servers/games/slotcommon/usermanager"
  17. "bet24.com/servers/insecureframe"
  18. "bet24.com/servers/insecureframe/gate"
  19. micro_common "bet24.com/servers/micros/common"
  20. game "bet24.com/servers/micros/game/proto"
  21. notification "bet24.com/servers/micros/notification/proto"
  22. _ "bet24.com/servers/monitor"
  23. "bet24.com/servers/transaction"
  24. "bet24.com/utils"
  25. "github.com/gin-gonic/gin"
  26. _ "github.com/smallnest/rpcx/protocol"
  27. )
  28. var stopping bool
  29. func waitInput() {
  30. for {
  31. var cmd string
  32. var param1 string
  33. var param2 string
  34. fmt.Scanf("%s %s %s", &cmd, &param1, &param2)
  35. switch cmd {
  36. case "exit":
  37. stopping = true
  38. gate.StopServer()
  39. case "slotuser":
  40. usermanager.Dump(param1, param2)
  41. case "slotconfig":
  42. log.Release("%v", slotmanager.GetConfigList(param1))
  43. case "getslotconfig":
  44. log.Release("%v", slotmanager.GetConfig(param1, param2))
  45. case "listuser":
  46. gate.DumpUsers()
  47. case "clientpool":
  48. micro_common.DumpClientPools()
  49. case "messagerecord":
  50. userId, err := strconv.Atoi(param1)
  51. if err != nil {
  52. userId = 0
  53. }
  54. gate.DumpMessageRecord(userId)
  55. case "clearrecord":
  56. userId, err := strconv.Atoi(param1)
  57. if err != nil {
  58. userId = 0
  59. }
  60. gate.ClearMessageRecord(userId)
  61. default:
  62. log.Release("unknown command")
  63. }
  64. }
  65. }
  66. func main() {
  67. //defer waitInput()
  68. rand.Seed(time.Now().UnixNano())
  69. redis.InitPool(config.Server.ChannelUrl, config.Server.ChannelPassword, config.Server.RedisDB)
  70. coreservice.SetServiceAddr(config.Server.ServiceAddr)
  71. config.Run()
  72. //monitor.Run(config.Server.MonitorPort)
  73. logFilename := "log/fishhall/err.log"
  74. // redirect stdout and stderr to log file
  75. logFile, _ := os.OpenFile(logFilename, os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644)
  76. utils.RedirectStderr(logFile)
  77. os.Stderr.Write([]byte(fmt.Sprintf("[%v]fishhall starting\n", time.Now())))
  78. log.Release("fishhall.run config = %v", config.HallConfig.ThirdPaymentOpen)
  79. if config.Server.TestPay {
  80. log.Error("TestPay enabled")
  81. }
  82. transaction.Run()
  83. // 对用户的服务永远放在最后
  84. gatesink.Run()
  85. slotmanager.RunAllSlots(gatesink.Sink)
  86. insecureframe.Run(gatesink.Sink,
  87. config.Server.ChannelUrl, config.Server.ChannelPassword, config.Server.RedisDB, config.Server.LogPath)
  88. pollAddrToService()
  89. go notification.Subscribe(gatesink.Sink.OnNotification, config.Server.ServerPort)
  90. log.Release("Server started %v", time.Now())
  91. router := gin.Default()
  92. router.Run(":19090")
  93. }
  94. func pollAddrToService() {
  95. if !gatesink.Sink.IsChipRoom() {
  96. return
  97. }
  98. if stopping {
  99. return
  100. }
  101. time.AfterFunc(10*time.Second, pollAddrToService)
  102. game.GamePolling(fmt.Sprintf("wss://%s:%d", config.Server.ServerIP, config.Server.ServerPort), gate.GetUserCount())
  103. }