单次session内重复添加同一好友会有提示,重新登陆后添加相同好友却提示发送成功

This commit is contained in:
hahwu 2026-03-05 11:02:25 +08:00
parent a1d97a1ab6
commit 2ae819376f
3 changed files with 22 additions and 2 deletions

View File

@ -332,8 +332,12 @@ func (p *Player) FriendListBackData() {
fl = append(fl, ps) fl = append(fl, ps)
} }
} }
now := GoUtil.Now()
ReqFriendList := make([]int64, 0, len(FriendMod.SendApply)) ReqFriendList := make([]int64, 0, len(FriendMod.SendApply))
for k := range FriendMod.SendApply { for k, v := range FriendMod.SendApply {
if now-v > oneday {
continue
}
ReqFriendList = append(ReqFriendList, int64(k)) ReqFriendList = append(ReqFriendList, int64(k))
} }
p.PushClientRes(&proto.ResFriendList{ p.PushClientRes(&proto.ResFriendList{

View File

@ -133,7 +133,7 @@ func ReqApplyFriend(player *Player, buf []byte) error {
} }
// 对于任何玩家而言向自己在24小时内已从任意途径发送过好友申请的玩家再次发送好友申请时该次申请不会被发出 // 对于任何玩家而言向自己在24小时内已从任意途径发送过好友申请的玩家再次发送好友申请时该次申请不会被发出
sendApplyTime := FriendMod.GetSendApplyTime(Uid) sendApplyTime := FriendMod.GetSendApplyTime(Uid)
if sendApplyTime != 0 && GoUtil.Now()-sendApplyTime < 86400 { if sendApplyTime != 0 && GoUtil.Now()-sendApplyTime < oneday {
player.PushClientRes(&msg.ResApplyFriend{ player.PushClientRes(&msg.ResApplyFriend{
Code: msg.RES_CODE_FAIL, Code: msg.RES_CODE_FAIL,
Uid: req.Uid, Uid: req.Uid,
@ -141,6 +141,7 @@ func ReqApplyFriend(player *Player, buf []byte) error {
}) })
return fmt.Errorf("already applied") return fmt.Errorf("already applied")
} }
FriendMod.AddSendApply(Uid)
now := GoUtil.Now() now := GoUtil.Now()
if req.Type == 1 { if req.Type == 1 {
Items, err := FriendMod.GetSponsorReward() Items, err := FriendMod.GetSponsorReward()

View File

@ -3,7 +3,10 @@ package test
import ( import (
"fmt" "fmt"
"server/game" "server/game"
"server/msg"
"testing" "testing"
"google.golang.org/protobuf/proto"
) )
func TestFriendInit(t *testing.T) { func TestFriendInit(t *testing.T) {
@ -31,3 +34,15 @@ func TestFriendRecommendList(t *testing.T) {
l1 := game.GetRecommendPlayer(p1, 3) l1 := game.GetRecommendPlayer(p1, 3)
fmt.Printf("Recommend List: %v\n", l1) fmt.Printf("Recommend List: %v\n", l1)
} }
func TestReqApplyFriend(t *testing.T) {
p1 := new(game.Player)
p1.InitPlayer("3625212")
req := &msg.ReqApplyFriend{
Uid: 100002,
Type: 0,
}
buf, _ := proto.Marshal(req)
game.ReqApplyFriend(p1, buf)
p1.FriendListBackData()
}