admanager.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package admanager
  2. import (
  3. "strconv"
  4. "sync"
  5. _ "time"
  6. "bet24.com/log"
  7. )
  8. var mgr *slotadmgr
  9. const DELAY_REMOVE = 300 // 300秒后删除用户
  10. const DELAY_CHECK = 60 // 每分钟检查一次
  11. func newSlotAdManager(isChipRoom bool) *slotadmgr {
  12. ret := new(slotadmgr)
  13. ret.initData()
  14. ret.isChipRoom = isChipRoom
  15. log.Debug("slotadmgr running isChipRoom[%v]", isChipRoom)
  16. return ret
  17. }
  18. type slotConfig struct {
  19. totalAdCount int
  20. freeSpinCount int
  21. }
  22. type slotadmgr struct {
  23. lock *sync.RWMutex
  24. configs map[int]slotConfig
  25. isChipRoom bool
  26. }
  27. func (sm *slotadmgr) initData() {
  28. sm.lock = &sync.RWMutex{}
  29. sm.configs = make(map[int]slotConfig)
  30. }
  31. func (sm *slotadmgr) getSlotConfig(gameId int) (totalAdCount, freeSpinCount int) {
  32. if sm.isChipRoom {
  33. return 0, 0
  34. }
  35. sm.lock.RLock()
  36. cfg, ok := sm.configs[gameId]
  37. sm.lock.RUnlock()
  38. if ok {
  39. return cfg.totalAdCount, cfg.freeSpinCount
  40. }
  41. _, _, totalAdCount, freeSpinCount = getUserInfo(0, gameId)
  42. sm.lock.Lock()
  43. sm.configs[gameId] = slotConfig{totalAdCount: totalAdCount, freeSpinCount: freeSpinCount}
  44. sm.lock.Unlock()
  45. return totalAdCount, freeSpinCount
  46. }
  47. func (sm *slotadmgr) getSlotUserInfo(userId int, gameId int) (adCount, winAmount int) {
  48. winAmount, adCount, totalAdCount, freeSpinCount := getUserInfo(userId, gameId)
  49. if userId == 0 {
  50. sm.lock.Lock()
  51. sm.configs[gameId] = slotConfig{totalAdCount: totalAdCount, freeSpinCount: freeSpinCount}
  52. sm.lock.Unlock()
  53. }
  54. return adCount, winAmount
  55. }
  56. func (sm *slotadmgr) useAd(userId, gameId int) (int, int) {
  57. if sm.isChipRoom {
  58. return 0, 0
  59. }
  60. success, adCount := useAd(userId, gameId)
  61. if !success {
  62. return 0, adCount
  63. }
  64. sm.lock.RLock()
  65. config, _ := sm.configs[gameId]
  66. sm.lock.RUnlock()
  67. return config.freeSpinCount, adCount
  68. }
  69. func (sm *slotadmgr) dump(param1, param2 string) {
  70. log.Debug("-------------------------------")
  71. log.Debug("slotadmgr.dump %s %s", param1, param2)
  72. defer func() {
  73. log.Debug("+++++++++++++++++++++++++++++++")
  74. log.Debug("")
  75. }()
  76. switch param1 {
  77. case "user":
  78. userId, err := strconv.Atoi(param2)
  79. if err != nil {
  80. log.Debug(" atoi error %v", err)
  81. return
  82. }
  83. adCount, winAmount := sm.getSlotUserInfo(userId, 0)
  84. log.Debug(" %d win[%d] count[%d]", userId, winAmount, adCount)
  85. }
  86. }