chat_update.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package model
  2. import (
  3. "rocommon/util"
  4. "roserver/serverproto"
  5. )
  6. type ChatUpdateItemList struct {
  7. ChatList []ChatUpdateItem
  8. }
  9. type ChatUpdateItem struct {
  10. UserId string
  11. RoleUid uint64
  12. RoleName string
  13. ZoneId int32
  14. Content []string
  15. }
  16. type ChatUpdateMag struct {
  17. chatContentList map[uint64]*ChatUpdateItem
  18. updateTimer util.ServerTimer //更新定时器
  19. }
  20. func newChatUpdateMag() *ChatUpdateMag {
  21. mag := &ChatUpdateMag{
  22. chatContentList: map[uint64]*ChatUpdateItem{},
  23. }
  24. mag.updateTimer = util.NewDurationTimer(util.GetCurrentTime(), 1000)
  25. return mag
  26. }
  27. func (this *ChatUpdateMag) Update(ms uint64) {
  28. if this.updateTimer.IsStart() && this.updateTimer.IsExpired(ms) {
  29. if len(this.chatContentList) <= 0 {
  30. return
  31. }
  32. //send to gmweb
  33. //urlPath := "/chat"
  34. var tmpChatList ChatUpdateItemList
  35. for key, val := range this.chatContentList {
  36. tmpChatList.ChatList = append(tmpChatList.ChatList, *val)
  37. delete(this.chatContentList, key)
  38. }
  39. //go func() {
  40. // defer func() {
  41. // //打印奔溃信息
  42. // if err := recover(); err != nil {
  43. // util.InfoF("onError data=%v \n%s\n", err, string(debug.Stack()))
  44. // }
  45. // }()
  46. // tmpRequest := &rocommon.HTTPRequest{}
  47. // tmpRequest.ReqCodecName = "httpjson"
  48. // tmpRequest.ReqMsg = tmpChatList
  49. //
  50. // parm := GetHttpNodeParam()
  51. // httpNode := baseserver.CreateHttpConnector(parm)
  52. // err := httpNode.(rocommon.HTTPConnector).Request("POST", urlPath, tmpRequest)
  53. // if err != nil {
  54. // util.ErrorF("http Request err=%v", err)
  55. // return
  56. // }
  57. //}()
  58. }
  59. }
  60. func (this *ChatUpdateMag) AddChatMsg(msg *serverproto.SSWebGMChatMsgNtf) {
  61. addItem, ok := this.chatContentList[msg.Uid]
  62. if !ok {
  63. addItem = &ChatUpdateItem{
  64. RoleUid: msg.Uid,
  65. RoleName: msg.ChatSelfName,
  66. ZoneId: msg.SelectZoneId,
  67. Content: []string{msg.Content.Message},
  68. }
  69. this.chatContentList[msg.Uid] = addItem
  70. } else {
  71. addItem.Content = append(addItem.Content, msg.Content.Message)
  72. }
  73. }