好友优化

This commit is contained in:
hahwu 2026-03-09 18:11:23 +08:00
parent a882a010d3
commit 65bc278a06
5 changed files with 39 additions and 3 deletions

View File

@ -417,7 +417,7 @@ func ReqGmCommand_(player *Player, Command string) error {
FriendMod.Npc = nil
FriendMod.Id = 0
FriendMod.Log = nil
FriendMod.InitData()
FriendMod.InitData(player.M_DwUin)
player.FriendListBackData()
player.FriendLogBackData()
case "addFriend":

View File

@ -189,7 +189,7 @@ type LogInfo struct {
}
// 初始化数据
func (f *FriendMod) InitData() {
func (f *FriendMod) InitData(M_DwUin int64) {
if f.FriendList == nil {
f.FriendList = make(map[int]struct{})
}
@ -224,6 +224,22 @@ func (f *FriendMod) InitData() {
if f.NewApplyList == nil {
f.NewApplyList = make(map[int]*ApplyInfo)
}
for k, v := range f.Card {
if v.AUid != 0 && !f.CheckFriend(v.AUid) && v.AUid != int(M_DwUin) {
delete(f.Card, k)
continue
}
if v.BUid != 0 && !f.CheckFriend(v.BUid) && v.BUid != int(M_DwUin) {
delete(f.Card, k)
continue
}
}
for k, v := range f.ReplyList {
if !f.CheckFriend(v.Uid) {
f.ReplyList = append(f.ReplyList[:k], f.ReplyList[k+1:]...)
}
}
f.version()
}
@ -302,6 +318,9 @@ func (f *FriendMod) Interact(id, t int, T int64) {
VisitTime: T,
Type: t,
})
if len(f.NewFriendList[id].Interact) > 30 {
f.NewFriendList[id].Interact = f.NewFriendList[id].Interact[len(f.NewFriendList[id].Interact)-30:]
}
}
// 获取好友交互时间

View File

@ -394,6 +394,9 @@ func (p *Player) FriendLogBackData() {
Uid: int64(v.Uid),
}
}
if !FriendMod.CheckFriend(v.Uid) && v.Uid > 10000 {
continue
}
reply = append(reply, &proto.ResFriendReply{
Player: ps,
Type: int32(v.Type),
@ -414,6 +417,12 @@ func (p *Player) FriendCardBackData() {
FriendMod := p.PlayMod.getFriendMod()
msgList := make([]*proto.ResFriendCard, 0, len(FriendMod.Card))
for _, v := range FriendMod.Card {
if !FriendMod.CheckFriend(v.AUid) && v.AUid != int(p.M_DwUin) {
continue
}
if !FriendMod.CheckFriend(v.BUid) && v.BUid != int(p.M_DwUin) {
continue
}
msgList = append(msgList, GetCardInfoMsg(v))
}
p.PushClientRes(&proto.ResFriendCardMsg{

View File

@ -206,7 +206,7 @@ func (p *PlayerModData) InitMod(player *Player) (bool, error) {
p.ModList.Base.InitData(int(p.Data.DwUin), Ip)
p.ModList.SevenLogin.InitData()
p.ModList.LimitedTimeEvent.InitData(BaseMod.GetLevel())
p.ModList.Friend.InitData()
p.ModList.Friend.InitData(p.Data.DwUin)
p.ModList.Mail.InitData()
p.ModList.Charge.InitData()
p.ModList.Endless.InitData()

View File

@ -46,3 +46,11 @@ func TestReqApplyFriend(t *testing.T) {
game.ReqApplyFriend(p1, buf)
p1.FriendListBackData()
}
func TestFriendBackData(t *testing.T) {
p1 := new(game.Player)
p1.InitPlayerByUid(100001)
p1.M_DwUin = 100100129
p1.FriendLogBackData()
p1.FriendCardBackData()
}