roomconfig.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package config
  2. import (
  3. "bet24.com/log"
  4. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  5. "encoding/json"
  6. "fmt"
  7. "os"
  8. )
  9. const config_key = "greedybigo_rooms"
  10. const config_key_chip = "greedybigo_chip_rooms"
  11. const config_key_private = "greedybigo_private_rooms"
  12. type OpenHistory struct {
  13. SerialNumber int
  14. SpinResult int
  15. }
  16. type RoomInfoBase struct {
  17. RoomName string
  18. ServerIP string
  19. ServerPort int
  20. MinBet int
  21. MaxBet int //个人最大下注额
  22. TotalMax int
  23. BetTime int
  24. OpenTime int
  25. HistoryCount int
  26. State int
  27. StateSec int
  28. SerialNumber int
  29. Historys []OpenHistory
  30. TotalBet int
  31. Odds []float64
  32. TaxRate int
  33. }
  34. type RoomInfo struct {
  35. RoomInfoBase
  36. MinRoom int
  37. RobotConfig []RobotInfo // 机器人配置
  38. JackpotRate int // 奖池比例
  39. ChipAmounts []int // 机器人筹码配置
  40. Probability []int // 概率
  41. }
  42. type RobotInfo struct {
  43. HourStart int
  44. HourEnd int
  45. CountMin int
  46. CountMax int
  47. GoldMin int
  48. GoldMax int
  49. Online int
  50. }
  51. var Rooms struct {
  52. Rooms []RoomInfo
  53. }
  54. var Room *RoomInfo
  55. var RoomConfigName string
  56. func getConfigKey() string {
  57. // 私人场优先
  58. if Server.IsPrivateRoom {
  59. return config_key_private
  60. }
  61. if Server.IsChipRoom {
  62. return config_key_chip
  63. }
  64. return config_key
  65. }
  66. func loadRedisConfig(createRoom bool) bool {
  67. data := platformconfig.GetConfig(getConfigKey())
  68. if data == "" {
  69. log.Release("config msg is null")
  70. return false
  71. }
  72. ok, _ := marshalData([]byte(data))
  73. return ok
  74. }
  75. func loadRoomConfig() {
  76. if loadRedisConfig(true) {
  77. log.Release("using remote config ignored rooms.json !!!")
  78. return
  79. }
  80. // 保存
  81. // 加载房间表
  82. data, err := os.ReadFile("greedy/rooms.json")
  83. //fmt.Println(string(data))
  84. if err != nil {
  85. log.Release("read rooms failed greedy/rooms.json")
  86. return
  87. }
  88. if ok, newConfig := marshalData(data); ok {
  89. // 写入redis
  90. platformconfig.SetConfig(getConfigKey(), newConfig)
  91. }
  92. }
  93. func marshalData(data []byte) (bool, string) {
  94. changedConfigString := string(data)
  95. err := json.Unmarshal(data, &Rooms)
  96. if err != nil {
  97. log.Release("Unmarshal rooms failed err:%v", err)
  98. return false, changedConfigString
  99. }
  100. if len(Rooms.Rooms) <= 0 {
  101. log.Release("Rooms.Rooms == 0")
  102. return false, changedConfigString
  103. }
  104. Room = &Rooms.Rooms[0]
  105. if len(Server.ServerIP) > 0 {
  106. ws := "ws"
  107. if len(Server.CertFile) > 0 {
  108. ws = "wss"
  109. }
  110. for i := 0; i < len(Rooms.Rooms); i++ {
  111. Rooms.Rooms[i].ServerIP = fmt.Sprintf("%s://%s:%d", ws, Server.ServerIP, Server.ServerPort)
  112. }
  113. }
  114. return true, changedConfigString
  115. }
  116. func OnConfigChanged(key string) {
  117. if key != getConfigKey() {
  118. return
  119. }
  120. log.Release("正在刷新配置信息")
  121. loadRedisConfig(false)
  122. }