1 Star 0 Fork 0

liuxuezhan / mylib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Asset_Chat.go 26.08 KB
一键复制 编辑 原始数据 按行查看 历史
liuxuezhan 提交于 2020-12-19 16:15 . 'ok'
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
package cache
import (
"sync/atomic"
"gitee.com/liuxuezhan/mylib/GameServer/CSV"
proto "gitee.com/liuxuezhan/mylib/Protocol"
"gitee.com/liuxuezhan/mylib/Utils/wlog"
"gitee.com/liuxuezhan/mylib/common"
"gitee.com/liuxuezhan/mylib/wtime"
)
type ChatList struct {
Basic
List []*proto.ST_Asset_Chat_Item_PB
}
type Asset_Chat struct {
Basic
followTitleIDs *ChatList
newMyList map[uint64]bool // 新动态的 我的话题列表
newFollowList map[uint64]bool // 新动态的 关注话题列表
newFollowVersion uint64 // 关注话题的版本号
newMyListVersion uint64 // 我的话的版本号
myTitleIDs *ChatList
lastChatTime uint64 // 上次世界发送世界话题时间
dayChatCount uint32 // 当天发送世界话题条数
lastLeagueChatTime uint64 // 上次联盟聊天时间
lastWorldChatWXTime uint64 // 上次世界微信聊天时间
forbid map[uint32]*proto.ST_ForbiddenChat_PB
globalMessageVersion uint64
privateChatList map[uint64]*proto.ST_PrivateChat_PB
}
func (this *Asset_Chat) ReUse() {
this.Lock()
defer this.Unlock()
this.followTitleIDs = &ChatList{
List: make([]*proto.ST_Asset_Chat_Item_PB, 0, CSV.GetGameConfigValueUint32("FollowTopicNumber")),
}
this.myTitleIDs = &ChatList{
List: make([]*proto.ST_Asset_Chat_Item_PB, 0, CSV.GetGameConfigValueUint32("MyTopicNumber")),
}
this.newFollowList = make(map[uint64]bool)
this.newMyList = make(map[uint64]bool)
this.forbid = make(map[uint32]*proto.ST_ForbiddenChat_PB)
this.privateChatList = make(map[uint64]*proto.ST_PrivateChat_PB)
this.lastChatTime = 0
this.dayChatCount = 0
this.newFollowVersion = 0
atomic.StoreUint64(&this.newMyListVersion, 0)
}
func (this *Asset_Chat) ToClientPB() proto.Message {
chatPB := &proto.ST_Asset_Chat_PB{}
this.RLock()
defer this.RUnlock()
for k := range this.followTitleIDs.List {
chatPB.FollowTitleIDList = append(chatPB.FollowTitleIDList, this.followTitleIDs.List[k])
}
for k := range this.myTitleIDs.List {
chatPB.MyTitleIDList = append(chatPB.MyTitleIDList, this.myTitleIDs.List[k])
}
for _, v := range this.privateChatList {
privateChat := &proto.ST_PrivateChat_PB{
Uid: proto.SetUint64(v.GetUid()),
FTime: proto.SetUint64(v.GetFTime()),
NewCount: proto.SetUint32(v.GetNewCount()),
Name: proto.SetString(v.GetName()),
Avatar: proto.SetString(v.GetAvatar()),
AvatarID: proto.SetString(v.GetAvatarID()),
AvatarBoxID: proto.SetUint32(v.GetAvatarBoxID()),
LeagueName: proto.SetString(v.GetLeagueName()),
NextId: proto.SetUint64(v.GetNextId()),
}
if len(v.ChatList) > 0 {
privateChat.ChatList = append(privateChat.ChatList, v.ChatList[len(v.ChatList)-1])
}
chatPB.PrivateChatList = append(chatPB.PrivateChatList, privateChat)
}
chatPB.LastChatTime = proto.SetUint64(this.lastChatTime)
chatPB.DayChatCount = proto.SetUint32(this.dayChatCount)
return chatPB
}
func (this *Asset_Chat) ToServerPB() proto.Message {
chatPB := &proto.ST_Asset_Chat_PB{}
this.RLock()
defer this.RUnlock()
for k := range this.followTitleIDs.List {
chatPB.FollowTitleIDList = append(chatPB.FollowTitleIDList, this.followTitleIDs.List[k])
}
for k := range this.myTitleIDs.List {
chatPB.MyTitleIDList = append(chatPB.MyTitleIDList, this.myTitleIDs.List[k])
}
for _, v := range this.forbid {
chatPB.Forbidden = append(chatPB.Forbidden, v)
}
for _, v := range this.privateChatList {
chatPB.PrivateChatList = append(chatPB.PrivateChatList, v)
}
chatPB.LastChatTime = proto.SetUint64(this.lastChatTime)
chatPB.DayChatCount = proto.SetUint32(this.dayChatCount)
return chatPB
}
func (this *Asset_Chat) ToClientString() []byte {
str := proto.Marshal(this.ToClientPB())
return common.AddVersionInfoBeforeData(str, this.versionid)
}
func (this *Asset_Chat) ToServerString() []byte {
return proto.Marshal(this.ToServerPB())
}
func (this *Asset_Chat) pbToMap(pb []byte) {
chatPB := &proto.ST_Asset_Chat_PB{}
err := proto.Unmarshal(pb, chatPB)
if err != nil {
wlog.Error("ChatAsset Marshal error : ", err.Error())
}
this.Lock()
defer this.Unlock()
for k := range chatPB.FollowTitleIDList {
this.followTitleIDs.List = append(this.followTitleIDs.List, chatPB.FollowTitleIDList[k])
}
for k := range chatPB.MyTitleIDList {
this.myTitleIDs.List = append(this.myTitleIDs.List, chatPB.MyTitleIDList[k])
}
for _, v := range chatPB.Forbidden {
this.forbid[v.GetForbiddenType()] = v
}
for _, v := range chatPB.PrivateChatList {
this.privateChatList[v.GetUid()] = v
}
this.lastChatTime = chatPB.GetLastChatTime()
this.dayChatCount = chatPB.GetDayChatCount()
}
func (this *Asset_Chat) FromString(pb []byte) {
this.ReUse()
if len(pb) != 0 {
this.pbToMap(pb)
}
}
func (this *Asset_Chat) GetGlobalMessageVersion() uint64 {
return atomic.LoadUint64(&this.globalMessageVersion)
}
func (this *Asset_Chat) SetGlobalMessageVersion(version uint64) {
atomic.StoreUint64(&this.globalMessageVersion, version)
}
func (this *Asset_Chat) SetForbidChat(forbiddenType uint32, duration uint64, msg string) {
this.Lock()
defer this.Unlock()
forbidden := &proto.ST_ForbiddenChat_PB{
ForbiddenType: proto.SetUint32(forbiddenType),
StartTime: proto.SetUint64(wtime.GetNow()),
Msg: proto.SetString(msg),
Duration: proto.SetUint64(duration),
}
this.forbid[forbiddenType] = forbidden
}
func (this *Asset_Chat) GetForbidChat(forbiddenType uint32) *proto.ST_ForbiddenChat_PB {
this.RLock()
defer this.RUnlock()
return this.forbid[forbiddenType]
}
func (this *Asset_Chat) GetForbidChatInfo() []*proto.ST_ForbiddenChat_PB {
this.RLock()
defer this.RUnlock()
forbidden := make([]*proto.ST_ForbiddenChat_PB, 0)
for _, v := range this.forbid {
forbidden = append(forbidden, v)
}
return forbidden
}
// 添加关注
func (this *Asset_Chat) AddFollow(titleID uint64, timestamp uint64, replyCount uint32) {
if nil != this.GetFollow(titleID) {
return
}
if this.getFollowCount() >= int(CSV.GetGameConfigValueUint32("FollowTopicNumber")) {
return
}
this.Lock()
defer this.Unlock()
data := &proto.ST_Asset_Chat_Item_PB{
TitleID: proto.SetUint64(titleID),
Timestamp: proto.SetUint64(timestamp),
LastReplyCount: proto.SetUint32(replyCount),
}
this.followTitleIDs.List = append([]*proto.ST_Asset_Chat_Item_PB{data}, this.followTitleIDs.List...)
this.followTitleIDs.List[0] = data
this.Dirty()
}
// 删除关注new
func (this *Asset_Chat) RemoveNewFollow(titleID uint64) {
this.Lock()
defer this.Unlock()
delete(this.newFollowList, titleID)
}
// 设置关注话题new
func (this *Asset_Chat) SetFollowNew(titleID uint64) {
followData := this.GetFollow(titleID)
if nil == followData {
return
}
this.Lock()
defer this.Unlock()
this.newFollowList[titleID] = true
this.newFollowVersion += 1
}
// 删除我的new
func (this *Asset_Chat) RemoveNewMy(titleID uint64) {
this.Lock()
defer this.Unlock()
delete(this.newMyList, titleID)
}
// 设置我的话题new
func (this *Asset_Chat) SetMyNew(titleID uint64) {
myData := this.GetMyChat(titleID)
if nil == myData {
return
}
this.Lock()
defer this.Unlock()
this.newMyList[titleID] = true
atomic.AddUint64(&this.newMyListVersion, 1)
}
// 删除关注
func (this *Asset_Chat) RemoveFollow(titleID uint64) {
if nil == this.GetFollow(titleID) {
return
}
this.Lock()
defer this.Unlock()
for k := range this.followTitleIDs.List {
if this.followTitleIDs.List[k].GetTitleID() == titleID {
this.followTitleIDs.List = append(this.followTitleIDs.List[:k], this.followTitleIDs.List[k+1:]...)
break
}
}
if _, ok := this.newFollowList[titleID]; ok {
this.newFollowVersion += 1
delete(this.newFollowList, titleID)
}
this.Dirty()
}
// 关注数量
func (this *Asset_Chat) getFollowCount() int {
this.RLock()
defer this.RUnlock()
return len(this.followTitleIDs.List)
}
// 获取关注
func (this *Asset_Chat) GetFollow(titleID uint64) *proto.ST_Asset_Chat_Item_PB {
this.RLock()
defer this.RUnlock()
for k := range this.followTitleIDs.List {
if this.followTitleIDs.List[k].GetTitleID() == titleID {
return this.followTitleIDs.List[k]
}
}
return nil
}
// 获取我的话题
func (this *Asset_Chat) GetMyChat(titleID uint64) *proto.ST_Asset_Chat_Item_PB {
this.RLock()
defer this.RUnlock()
for k := range this.myTitleIDs.List {
if this.myTitleIDs.List[k].GetTitleID() == titleID {
return this.myTitleIDs.List[k]
}
}
return nil
}
// 获取我的话题的数量
func (this *Asset_Chat) GetMyChatCount() int {
this.RLock()
defer this.RUnlock()
return len(this.myTitleIDs.List)
}
// 添加我的话题
func (this *Asset_Chat) AddMyChat(titleID uint64, timestamp uint64) {
this.Lock()
defer this.Unlock()
data := &proto.ST_Asset_Chat_Item_PB{
TitleID: proto.SetUint64(titleID),
Timestamp: proto.SetUint64(timestamp),
LastReplyCount: proto.SetUint32(0),
}
this.myTitleIDs.List = append([]*proto.ST_Asset_Chat_Item_PB{data}, this.myTitleIDs.List...)
this.myTitleIDs.List[0] = data
if len(this.myTitleIDs.List) > int(CSV.GetGameConfigValueUint32("MyTopicNumber")) {
id := this.myTitleIDs.List[len(this.myTitleIDs.List)-1].GetTitleID()
if _, ok := this.newMyList[id]; ok {
atomic.AddUint64(&this.newMyListVersion, 1)
delete(this.newMyList, id)
}
this.myTitleIDs.List = this.myTitleIDs.List[:int(CSV.GetGameConfigValueUint32("MyTopicNumber"))]
}
this.Dirty()
}
// 删除我的话题
func (this *Asset_Chat) RemoveMyChat(titleID uint64) {
this.Lock()
defer this.Unlock()
for k := range this.myTitleIDs.List {
if this.myTitleIDs.List[k].GetTitleID() == titleID {
this.myTitleIDs.List = append(this.myTitleIDs.List[:k], this.myTitleIDs.List[k+1:]...)
break
}
}
delete(this.newMyList, titleID)
this.Dirty()
}
//
func (this *Asset_Chat) GetFollowChatList(startIdx uint32, count uint32) []uint64 {
this.RLock()
defer this.RUnlock()
idList := make([]uint64, 0)
if startIdx >= uint32(len(this.followTitleIDs.List)) {
return idList
}
end := startIdx + count
if end > uint32(len(this.followTitleIDs.List)) {
end = uint32(len(this.followTitleIDs.List))
}
for idx := startIdx; idx < end; idx++ {
idList = append(idList, this.followTitleIDs.List[idx].GetTitleID())
}
return idList
}
//
func (this *Asset_Chat) GetMyChatList(startIdx uint32, count uint32) []uint64 {
this.RLock()
defer this.RUnlock()
idList := make([]uint64, 0)
if startIdx >= uint32(len(this.myTitleIDs.List)) {
return idList
}
end := startIdx + count
if end > uint32(len(this.myTitleIDs.List)) {
end = uint32(len(this.myTitleIDs.List))
}
for idx := startIdx; idx < end; idx++ {
idList = append(idList, this.myTitleIDs.List[idx].GetTitleID())
}
return idList
}
// 设置我的话题的回复数
func (this *Asset_Chat) SetMyChatReplyCount(titleID uint64, replyCount uint32) {
myChatData := this.GetMyChat(titleID)
if nil == myChatData {
return
}
this.Lock()
defer this.Unlock()
myChatData.LastReplyCount = proto.SetUint32(replyCount)
this.Dirty()
}
// 获取我的话题的回复数
func (this *Asset_Chat) GetMyChatReplyCount(titleID uint64) uint32 {
myChatData := this.GetMyChat(titleID)
if nil == myChatData {
return 0
}
return myChatData.GetLastReplyCount()
}
// 设置关注话题的回复数
func (this *Asset_Chat) SetFollowChatReplyCount(titleID uint64, replyCount uint32) {
followChatData := this.GetFollow(titleID)
if nil == followChatData {
return
}
this.Lock()
defer this.Unlock()
followChatData.LastReplyCount = proto.SetUint32(replyCount)
this.Dirty()
}
// 获取关注话题的回复数
func (this *Asset_Chat) GetFollowChatReplyCount(titleID uint64) uint32 {
followChatData := this.GetFollow(titleID)
if nil == followChatData {
return 0
}
return followChatData.GetLastReplyCount()
}
func (this *Asset_Chat) GetFollowTitleIDs() map[uint64]uint64 {
this.RLock()
defer this.RUnlock()
idMap := make(map[uint64]uint64)
for _, v := range this.followTitleIDs.List {
idMap[v.GetTitleID()] = 0
}
return idMap
}
// 玩家上线处理清理已经删除的话题
func (this *Asset_Chat) SetChatIds(followIds, myIDs map[uint64]uint32) {
this.Lock()
defer this.Unlock()
GOTO1:
for k, v := range this.followTitleIDs.List {
replyCount, ok := followIds[v.GetTitleID()]
if !ok {
this.followTitleIDs.List = append(this.followTitleIDs.List[:k], this.followTitleIDs.List[k+1:]...)
goto GOTO1
} else {
if replyCount > v.GetLastReplyCount() {
this.newFollowList[v.GetTitleID()] = true
this.followTitleIDs.Dirty()
}
}
}
GOTO2:
for k, v := range this.myTitleIDs.List {
replyCount, ok := myIDs[v.GetTitleID()]
if !ok {
this.myTitleIDs.List = append(this.myTitleIDs.List[:k], this.myTitleIDs.List[k+1:]...)
wlog.Info("delete mytitle %d", v.GetTitleID())
goto GOTO2
} else {
if replyCount != v.GetLastReplyCount() {
this.newMyList[v.GetTitleID()] = true
this.myTitleIDs.Dirty()
}
}
}
atomic.StoreUint64(&this.newMyListVersion, 1)
this.newFollowVersion = 1
this.Dirty()
}
func (this *Asset_Chat) GetMyTitleIDs() map[uint64]uint64 {
this.RLock()
defer this.RUnlock()
idMap := make(map[uint64]uint64)
for _, v := range this.myTitleIDs.List {
idMap[v.GetTitleID()] = 0
}
return idMap
}
func (this *Asset_Chat) GetDayChatCount() uint32 {
this.Lock()
defer this.Unlock()
if this.lastChatTime/86400 != wtime.GetNow()/86400 {
this.dayChatCount = 0
}
return this.dayChatCount
}
func (this *Asset_Chat) AddDayChatCount() {
this.Lock()
defer this.Unlock()
if this.lastChatTime/86400 != wtime.GetNow()/86400 {
this.dayChatCount = 0
}
this.dayChatCount += 1
}
func (this *Asset_Chat) SetLastChatTime(time uint64) {
this.Lock()
defer this.Unlock()
this.lastChatTime = wtime.GetNow()
}
func (this *Asset_Chat) SetLeagueChatTime() {
this.Lock()
defer this.Unlock()
this.lastLeagueChatTime = wtime.GetNow()
}
func (this *Asset_Chat) GetLastChatTime() uint64 {
this.RLock()
defer this.RUnlock()
return this.lastChatTime
}
func (this *Asset_Chat) GetLeagueChatTime() uint64 {
this.RLock()
defer this.RUnlock()
return this.lastLeagueChatTime
}
func (this *Asset_Chat) GetNewFollowListCount() uint64 {
return uint64(len(this.newFollowList))
}
func (userData *Info) GetWorldChatWXTime() uint64 {
chatAsset := userData.info.AssetData_Chat
chatAsset.RLock()
defer chatAsset.RUnlock()
return chatAsset.lastWorldChatWXTime
}
func (userData *Info) SetWorldChatWXTime() {
chatAsset := userData.info.AssetData_Chat
chatAsset.Lock()
defer chatAsset.Unlock()
chatAsset.lastWorldChatWXTime = wtime.GetNow()
}
func (this *Asset_Chat) GetNewMyListVersion() uint64 {
return atomic.LoadUint64(&this.newMyListVersion)
}
func (this *Asset_Chat) GetNewMyList() []uint64 {
this.RLock()
defer this.RUnlock()
list := make([]uint64, len(this.newMyList))
for k := range this.newMyList {
list = append(list, k)
}
return list
}
func (this *Asset_Chat) GetNewFollowList() []uint64 {
this.RLock()
defer this.RUnlock()
list := make([]uint64, 0)
for k := range this.newFollowList {
list = append(list, k)
}
return list
}
func (this *Asset_Chat) CheckCanPrivateChat(targetUid uint64) bool {
this.RLock()
defer this.RUnlock()
if _, ok := this.privateChatList[targetUid]; !ok {
if len(this.privateChatList) >= int(CSV.GetGameConfigValueUint32("PrivateChatPlayerLimit")) {
return false
}
}
return true
}
func (this *Asset_Chat) AddPrivateChat(targetUserData *Info, chatData *proto.ST_PrivateChat_Content_PB) bool {
this.Lock()
defer this.Unlock()
privateChat := this.privateChatList[targetUserData.GetUid()]
if nil == privateChat {
if len(this.privateChatList) >= int(CSV.GetGameConfigValueUint32("PrivateChatPlayerLimit")) {
//找到最早的聊天记录删除掉
deleteUid := uint64(0)
deleteTime := uint64(0)
for k, v := range this.privateChatList {
if v.GetFTime() < deleteTime || deleteTime == 0 {
deleteTime = v.GetFTime()
deleteUid = k
}
}
delete(this.privateChatList, deleteUid)
}
privateChat = &proto.ST_PrivateChat_PB{
Uid: proto.SetUint64(targetUserData.GetUid()),
NewCount: proto.SetUint32(0),
ChatList: make([]*proto.ST_PrivateChat_Content_PB, 0),
NextId: proto.SetUint64(0),
LeagueName: proto.SetString(""),
}
this.privateChatList[targetUserData.GetUid()] = privateChat
}
chatData.ID = proto.SetUint64(privateChat.GetNextId())
privateChat.NextId = proto.SetUint64(privateChat.GetNextId() + 1)
privateChat.FTime = proto.SetUint64(wtime.GetNow())
privateChat.LeagueName = proto.SetString(Instance_GlobalAssetLeague.GetLeagueShortName(targetUserData.GetLeagueID()))
privateChat.Name = proto.SetString(targetUserData.GetUserName())
privateChat.Avatar = proto.SetString(targetUserData.GetAvatar())
privateChat.AvatarBoxID = proto.SetUint32(targetUserData.GetAvatarBoxId())
privateChat.AvatarID = proto.SetString(targetUserData.GetLordIcon())
if chatData.GetSenderUid() == targetUserData.GetUid() {
privateChat.NewCount = proto.SetUint32(privateChat.GetNewCount() + 1)
}
privateChat.ChatList = append(privateChat.ChatList, chatData)
if len(privateChat.ChatList) > int(CSV.GetGameConfigValueUint32("PrivateChatNumberLimit")) {
privateChat.ChatList = privateChat.ChatList[len(privateChat.ChatList)-int(CSV.GetGameConfigValueUint32("PrivateChatNumberLimit")):]
}
this.Dirty()
return true
}
func (this *Asset_Chat) RemovePrivateChat(ids []uint64) {
this.Lock()
defer this.Unlock()
for _, id := range ids {
delete(this.privateChatList, id)
}
this.Dirty()
}
func (this *Asset_Chat) GetPrivateChatList(targetUid uint64, startIdx uint64, maxCount uint32) (bool, []*proto.ST_PrivateChat_Content_PB) {
this.Lock()
defer this.Unlock()
result := make([]*proto.ST_PrivateChat_Content_PB, 0)
privateChat := this.privateChatList[targetUid]
if nil == privateChat || len(privateChat.ChatList) <= 0 {
return false, result
}
dirty := false
if privateChat.GetNewCount() > 0 {
privateChat.NewCount = proto.SetUint32(0)
this.Dirty()
dirty = true
}
var idIdx int
for idIdx = len(privateChat.ChatList) - 1; idIdx >= 0; idIdx-- {
if privateChat.ChatList[idIdx].GetID() <= startIdx {
break
}
}
if idIdx < 0 {
return dirty, result
}
for count := uint32(0); idIdx >= 0 && count < maxCount; idIdx-- {
result = append(result, privateChat.ChatList[idIdx])
count++
}
return dirty, result
}
func (this *Asset_Chat) GetNewPrivateChat(targetUid uint64) []*proto.ST_PrivateChat_Content_PB {
this.Lock()
defer this.Unlock()
result := make([]*proto.ST_PrivateChat_Content_PB, 0)
privateChat := this.privateChatList[targetUid]
if nil == privateChat || len(privateChat.ChatList) <= 0 || privateChat.GetNewCount() <= 0 {
return result
}
count := int(privateChat.GetNewCount())
if count > len(privateChat.ChatList) {
count = len(privateChat.ChatList)
}
for idx := len(privateChat.ChatList) - 1; idx > 0 && count > 0; idx-- {
if privateChat.ChatList[idx].GetSenderUid() == targetUid {
result = append(result, privateChat.ChatList[idx])
}
count--
}
if privateChat.GetNewCount() > 0 {
privateChat.NewCount = proto.SetUint32(0)
this.Dirty()
}
return result
}
func (this *Asset_Chat) ReadAllPrivateChat() bool {
this.Lock()
defer this.Unlock()
hasNew := false
for _, v := range this.privateChatList {
if v.GetNewCount() > 0 {
v.NewCount = proto.SetUint32(0)
hasNew = true
}
}
if hasNew {
this.Dirty()
}
return hasNew
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// 是否已关注
func (userData *Info) HasFollowed(titleID uint64) bool {
if nil == userData.info.AssetData_Chat.GetFollow(titleID) {
return false
}
return true
}
// 取消关注
func (userData *Info) CancelFollow(titleID uint64) {
userData.info.AssetData_Chat.RemoveFollow(titleID)
userData.DirtyAll()
}
// 获取关注数量
func (userData *Info) GetFollowCount() int {
return userData.info.AssetData_Chat.getFollowCount()
}
// 获取我的话题数量
func (userData *Info) GetMyChatCount() int {
return userData.info.AssetData_Chat.GetMyChatCount()
}
// 设置我的话题的回复数
func (userData *Info) SetMyChatReplyCount(id uint64, replyCount uint32) {
userData.info.AssetData_Chat.SetMyChatReplyCount(id, replyCount)
userData.DirtyAll()
}
// 设置我关注话题的回复数
func (userData *Info) SetFollowChatReplyCount(id uint64, replyCount uint32) {
userData.info.AssetData_Chat.SetFollowChatReplyCount(id, replyCount)
userData.DirtyAll()
}
// 删除自己话题
func (userData *Info) RemoveMyChat(id uint64) {
userData.info.AssetData_Chat.RemoveMyChat(id)
}
// 添加我的聊天
func (userData *Info) AddMyChat(id uint64, timestamp uint64) {
userData.info.AssetData_Chat.AddMyChat(id, timestamp)
userData.DirtyAll()
}
// 添加关注
func (userData *Info) AddFollow(id uint64, timestamp uint64, replyCount uint32) {
userData.info.AssetData_Chat.AddFollow(id, timestamp, replyCount)
userData.DirtyAll()
}
func (userData *Info) GetFollowChatTitleIDs() map[uint64]uint64 {
return userData.info.AssetData_Chat.GetFollowTitleIDs()
}
func (userData *Info) GetFollowChatList(startIdx uint32, count uint32) []uint64 {
return userData.info.AssetData_Chat.GetFollowChatList(startIdx, count)
}
func (userData *Info) GetMyChatList(startIdx uint32, count uint32) []uint64 {
return userData.info.AssetData_Chat.GetMyChatList(startIdx, count)
}
func (userData *Info) GetMyChatTitleIDs() map[uint64]uint64 {
return userData.info.AssetData_Chat.GetMyTitleIDs()
}
func (userData *Info) GetFollowChatVersion() uint64 {
return userData.info.AssetData_Chat.GetNewFollowListCount()
}
func (userData *Info) GetMyChatVersion() uint64 {
return userData.info.AssetData_Chat.GetNewMyListVersion()
}
func (userData *Info) GetNewMyList() []uint64 {
return userData.info.AssetData_Chat.GetNewMyList()
}
func (userData *Info) GetMyChatReplyCount(titleID uint64) uint32 {
return userData.info.AssetData_Chat.GetMyChatReplyCount(titleID)
}
func (userData *Info) GetFollowChatReplyCount(titleID uint64) uint32 {
return userData.info.AssetData_Chat.GetFollowChatReplyCount(titleID)
}
func (userData *Info) GetNewFollowList() []uint64 {
return userData.info.AssetData_Chat.GetNewFollowList()
}
func (userData *Info) GetDayChatCount() uint32 {
return userData.info.AssetData_Chat.GetDayChatCount()
}
func (userData *Info) AddDayChatCount() {
userData.info.AssetData_Chat.AddDayChatCount()
userData.DirtyAll()
}
func (userData *Info) SetLastChatTime(time uint64) {
userData.info.AssetData_Chat.SetLastChatTime(time)
userData.DirtyAll()
}
func (userData *Info) GetLastChatTime() uint64 {
return userData.info.AssetData_Chat.GetLastChatTime()
}
// 删除关注new
func (userData *Info) RemoveNewFollow(titleID uint64) {
userData.info.AssetData_Chat.RemoveNewFollow(titleID)
userData.info.AssetData_Chat.Dirty()
userData.ClientDirty()
}
// 设置关注话题new
func (userData *Info) SetFollowNew(titleID uint64) {
userData.info.AssetData_Chat.SetFollowNew(titleID)
userData.info.AssetData_Chat.Dirty()
userData.ClientDirty()
}
// 删除我的new
func (userData *Info) RemoveNewMy(titleID uint64) {
userData.info.AssetData_Chat.RemoveNewMy(titleID)
userData.info.AssetData_Chat.Dirty()
userData.ClientDirty()
}
// 设置我的话题new
func (userData *Info) SetMyNew(titleID uint64) {
userData.info.AssetData_Chat.SetMyNew(titleID)
userData.info.AssetData_Chat.Dirty()
userData.ClientDirty()
}
// 获取上次联盟聊天时间
func (userData *Info) GetLeagueChatTime() uint64 {
return userData.info.AssetData_Chat.GetLeagueChatTime()
}
func (userData *Info) SetLeagueChatTime() {
userData.info.AssetData_Chat.SetLeagueChatTime()
}
func (userData *Info) GetGlobalMessageVersion() uint64 {
return userData.info.AssetData_Chat.GetGlobalMessageVersion()
}
func (userData *Info) SetGlobalMessageVersion(version uint64) {
userData.info.AssetData_Chat.SetGlobalMessageVersion(version)
}
func (userData *Info) GetGlobalWorldSituationVersion() uint64 {
return userData.info.AssetData_WorldSituation.GetGlobalWorldSituationVersion()
}
func (userData *Info) SetGlobalWorldSituationVersion(version uint64) {
userData.info.AssetData_WorldSituation.SetGlobalWorldSituationVersion(version)
}
func (userData *Info) GetGlobalWorldSituationRankSnapshotVersion() uint64 {
return userData.info.AssetData_WorldSituation.GetGlobalWorldSituationRankSnapshotVersion()
}
func (userData *Info) SetGlobalWorldSituationRankSnapshotVersion(version uint64) {
userData.info.AssetData_WorldSituation.SetGlobalWorldSituationRankSnapshotVersion(version)
}
func (userData *Info) SetForbidChat(forbiddenType uint32, duration uint64, msg string) {
userData.info.AssetData_Chat.SetForbidChat(forbiddenType, duration, msg)
userData.ServerDirty()
}
func (userData *Info) GetForbidChat(forbiddenType uint32) *proto.ST_ForbiddenChat_PB {
return userData.info.AssetData_Chat.GetForbidChat(forbiddenType)
}
func (userData *Info) GetForbidChatInfo() []*proto.ST_ForbiddenChat_PB {
return userData.info.AssetData_Chat.GetForbidChatInfo()
}
// 添加私聊
func (userData *Info) AddPrivateChat(targetUserData *Info, chatData *proto.ST_PrivateChat_Content_PB) bool {
result := userData.info.AssetData_Chat.AddPrivateChat(targetUserData, chatData)
userData.DirtyAll()
return result
}
func (userData *Info) CheckCanPrivateChat(targetUid uint64) bool {
return userData.info.AssetData_Chat.CheckCanPrivateChat(targetUid)
}
// 删除私聊
func (userData *Info) RemovePrivateChat(ids []uint64) {
userData.info.AssetData_Chat.RemovePrivateChat(ids)
userData.DirtyAll()
}
// 获取聊天列表
func (userData *Info) GetPrivateChatList(targetUid uint64, startIdx uint64, maxCount uint32) []*proto.ST_PrivateChat_Content_PB {
dirty, result := userData.info.AssetData_Chat.GetPrivateChatList(targetUid, startIdx, maxCount)
if dirty {
userData.DirtyAll()
}
return result
}
func (userData *Info) GetNewPrivateChat(targetUid uint64) []*proto.ST_PrivateChat_Content_PB {
result := userData.info.AssetData_Chat.GetNewPrivateChat(targetUid)
if len(result) > 0 {
userData.DirtyAll()
}
return result
}
func (userData *Info) ReadAllPrivateChat() {
if userData.info.AssetData_Chat.ReadAllPrivateChat() {
userData.DirtyAll()
}
}
////////////////////////////////////////////////////////////////////////
func (userData *Info) SetChatIds(followIds, myIDs map[uint64]uint32) {
userData.info.AssetData_Chat.SetChatIds(followIds, myIDs)
}
1
https://gitee.com/liuxuezhan/mylib.git
git@gitee.com:liuxuezhan/mylib.git
liuxuezhan
mylib
mylib
v1.1.3

搜索帮助