package model import ( "rocommon" "rocommon/util" "roserver/baseserver" "roserver/serverproto" "runtime/debug" ) type ChatUpdateItemList struct { ChatList []ChatUpdateItem } type ChatUpdateItem struct { UserId string RoleUid uint64 RoleName string ZoneId int32 Content []string } type ChatUpdateMag struct { chatContentList map[uint64]*ChatUpdateItem updateTimer util.ServerTimer //更新定时器 } func newChatUpdateMag() *ChatUpdateMag { mag := &ChatUpdateMag{ chatContentList: map[uint64]*ChatUpdateItem{}, } mag.updateTimer = util.NewDurationTimer(util.GetCurrentTime(), 1000) return mag } func (this *ChatUpdateMag) Update(ms uint64) { if this.updateTimer.IsStart() && this.updateTimer.IsExpired(ms) { if len(this.chatContentList) <= 0 { return } //send to gmweb urlPath := "/chat" var tmpChatList ChatUpdateItemList for key, val := range this.chatContentList { tmpChatList.ChatList = append(tmpChatList.ChatList, *val) delete(this.chatContentList, key) } go func() { defer func() { //打印奔溃信息 if err := recover(); err != nil { util.InfoF("onError data=%v \n%s\n", err, string(debug.Stack())) } }() tmpRequest := &rocommon.HTTPRequest{} tmpRequest.ReqCodecName = "httpjson" tmpRequest.ReqMsg = tmpChatList parm := GetHttpNodeParam() httpNode := baseserver.CreateHttpConnector(parm) err := httpNode.(rocommon.HTTPConnector).Request("POST", urlPath, tmpRequest) if err != nil { util.InfoF("http Request err=%v", err) return } }() } } func (this *ChatUpdateMag) AddChatMsg(msg *serverproto.SSWebGMChatMsgNtf) { addItem, ok := this.chatContentList[msg.Uid] if !ok { addItem = &ChatUpdateItem{ RoleUid: msg.Uid, RoleName: msg.ChatSelfName, ZoneId: msg.SelectZoneId, Content: []string{msg.Content.Message}, } this.chatContentList[msg.Uid] = addItem } else { addItem.Content = append(addItem.Content, msg.Content.Message) } }