user_notification.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package gatesink
  2. import (
  3. "bet24.com/log"
  4. coreservice "bet24.com/servers/coreservice/client"
  5. "bet24.com/servers/coreservice/coupontask"
  6. "bet24.com/servers/fishhall/config"
  7. "bet24.com/servers/fishhall/protocol"
  8. "bet24.com/servers/insecureframe/gate"
  9. game "bet24.com/servers/micros/game/proto"
  10. cash "bet24.com/servers/micros/money/proto"
  11. chip "bet24.com/servers/micros/money/proto"
  12. notification "bet24.com/servers/micros/notification/proto"
  13. task "bet24.com/servers/micros/task/proto"
  14. userservices "bet24.com/servers/micros/userservices/proto"
  15. "encoding/json"
  16. "strconv"
  17. "time"
  18. )
  19. const SCROLL_SECOND = 10
  20. func (this *user) selectNotification() {
  21. ticker := time.NewTicker(SCROLL_SECOND * time.Second)
  22. go func(t *time.Ticker) {
  23. for { //循环
  24. select {
  25. case <-this.chan_clear:
  26. t.Stop()
  27. return
  28. case <-t.C:
  29. this.getNotifications(false)
  30. }
  31. }
  32. }(ticker)
  33. }
  34. func (this *user) getNotifications(positive bool) {
  35. // 这里增加在线时长
  36. if !positive {
  37. go task.DoTaskAction(this.getUserId(), task.TaskAction_play_time, SCROLL_SECOND, task.TaskScope{})
  38. }
  39. if Sink.pollNotification {
  40. // 从数据库拉基本信息
  41. data := notification.GetNotifications(this.getUserId())
  42. if data == "" {
  43. return
  44. }
  45. var notifications []*notification.Notification
  46. if err := json.Unmarshal([]byte(data), &notifications); err != nil {
  47. log.Debug("user.getNotifications unmarshal fail %v", err)
  48. return
  49. }
  50. this.onNotification(notifications)
  51. }
  52. }
  53. func (this *user) onNotification(notifications []*notification.Notification) {
  54. //删除重复
  55. list := make(map[int]*notification.Notification)
  56. for i := len(notifications) - 1; i >= 0; i-- {
  57. v := notifications[i]
  58. if v.Id == notification.Notification_Match {
  59. this.onSimpleMatchNotification(v.Data)
  60. continue
  61. }
  62. if v.Id == notification.Notification_Task {
  63. var taskData task.UserTask
  64. json.Unmarshal([]byte(v.Data), &taskData)
  65. if taskData.TaskId == task.PreAddictionTaskId {
  66. notifications = append(notifications[:i], notifications[i+1:]...)
  67. continue
  68. }
  69. }
  70. // 广告大厅不发元宝通知
  71. if v.Id == notification.Notification_Chip && config.Server.IsChipRoom < 0 {
  72. notifications = append(notifications[:i], notifications[i+1:]...)
  73. continue
  74. }
  75. // 基础数值才需要去重(不包含广播)
  76. if v.Id <= notification.Notification_Invalid || v.Id == notification.Notification_Inventory /*|| v.Id == notification.Notification_Chat*/ {
  77. _, ok := list[v.Id]
  78. if ok {
  79. notifications = append(notifications[:i], notifications[i+1:]...)
  80. continue
  81. }
  82. }
  83. v.Data = this.handleNotification(v.Id, v.Data)
  84. list[v.Id] = v
  85. }
  86. d, _ := json.Marshal(notifications)
  87. this.WriteMsg("notification", string(d))
  88. }
  89. func (this *user) handleNotification(notificationId int, data string) string {
  90. switch notificationId {
  91. case notification.Notification_Gold:
  92. data = this.notification_gold(data)
  93. case notification.Notification_Chip:
  94. data = this.notification_chip(data)
  95. case notification.Notification_Vitality:
  96. data = this.notification_vitality(data)
  97. case notification.Notification_Task:
  98. // do nothing
  99. case notification.Notification_Vip:
  100. // do nothing
  101. case notification.Notification_Inventory:
  102. // do nothing
  103. case notification.Notification_Cannon:
  104. // do nothing
  105. case notification.Notification_Recharge:
  106. // 可能是购买重置礼包,尝试触发礼包升级任务
  107. this.notification_lockCountry()
  108. case notification.Notification_Broadcast:
  109. // do nothing
  110. case notification.Notification_Redpoint:
  111. // do nothing
  112. case notification.Notification_Chat:
  113. // do nothing
  114. case notification.Notification_Friend:
  115. // do nothing
  116. case notification.Notification_CouponTask:
  117. // log.Debug("handleNotification userId=%d task==>%+v", this.getUserId(), data)
  118. data = this.notification_coupon(data)
  119. case notification.Notification_Level:
  120. fallthrough
  121. case notification.Notification_Experience:
  122. data = this.notification_level(data)
  123. case notification.Notification_Return:
  124. // do nothing
  125. case notification.Notification_SlotScore:
  126. // do nothing
  127. case notification.Notification_UserInfoChanged:
  128. // 刷新自己的信息
  129. u := userservices.GetUserInfo(this.getUserId())
  130. user_self := gate.GetUserInfo(this.UserIndex)
  131. if u == nil || user_self == nil {
  132. break
  133. }
  134. user_self.SetUserFaceUrl(u.FaceUrl)
  135. user_self.SetDecorations(u.Decorations)
  136. user_self.SetBadges(u.Badges)
  137. default:
  138. log.Debug("handleNotification %d, unhandled id [%d]", this.getUserId(), notificationId)
  139. break
  140. }
  141. return data
  142. }
  143. func (this *user) notification_coupon(data string) string {
  144. var task struct {
  145. Action int
  146. TodayCount int // 今天券数量
  147. Data coupontask.UserTask
  148. }
  149. if err := json.Unmarshal([]byte(data), &task); err != nil {
  150. log.Error("user_notification.notification_coupon unmarshal ret err %v", err)
  151. return ""
  152. }
  153. // 开关模式
  154. if task.Action == 1 {
  155. return data
  156. }
  157. if info := game.GetGame(task.Data.GameId); info != nil {
  158. task.Data.ChineseName = info.ChineseName
  159. }
  160. buf, _ := json.Marshal(task)
  161. log.Debug("notification_coupon userId=%d task==>%+v", this.getUserId(), string(buf))
  162. return string(buf)
  163. }
  164. func (this *user) notification_gold(data string) string {
  165. u := gate.GetUserInfo(this.UserIndex)
  166. if u == nil {
  167. return ""
  168. }
  169. _, gold := cash.GetMoney(u.GetUserId())
  170. u.SetUserGold(gold)
  171. return strconv.Itoa(gold)
  172. }
  173. func (this *user) notification_level(data string) string {
  174. u := gate.GetUserInfo(this.UserIndex)
  175. if u == nil {
  176. return ""
  177. }
  178. info := userservices.GetUserLevel(u.GetUserId())
  179. u.SetUserLevel(info.Level)
  180. u.SetUserExperience(info.Experience)
  181. d, _ := json.Marshal(info)
  182. return string(d)
  183. }
  184. func (this *user) notification_chip(data string) string {
  185. u := gate.GetUserInfo(this.UserIndex)
  186. if u == nil {
  187. return ""
  188. }
  189. _, c := chip.GetUserChip(u.GetUserId())
  190. u.SetChip(c)
  191. return strconv.Itoa(c)
  192. }
  193. func (this *user) notification_vitality(data string) string {
  194. resp := coreservice.GetUserVitalityInfo(this.getUserId())
  195. if resp.RetCode != 1 {
  196. log.Debug("user.GetVitalityInfo failed %v", resp)
  197. return ""
  198. }
  199. var info protocol.GetVitality_resp
  200. if err := json.Unmarshal([]byte(resp.Data), &info); err != nil {
  201. log.Error("user.GetVitalityInfo fail userId=%d %+v", this.getUserId(), info)
  202. return ""
  203. }
  204. d, _ := json.Marshal(info)
  205. return string(d)
  206. }
  207. func (this *user) notification_lockCountry() {
  208. if this.getCurrencyIsModify() != 1 {
  209. return
  210. }
  211. // 锁定国家地区
  212. go func() {
  213. userservices.LockCountry(this.getUserId(), this.getCurrency())
  214. this.setCurrencyIsModify(0)
  215. }()
  216. }