好友申请列表
This commit is contained in:
parent
ff78edf56b
commit
f2d9d51dd6
|
@ -2,12 +2,14 @@ package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/rpc"
|
||||||
|
|
||||||
"github.com/globalsign/mgo"
|
"github.com/globalsign/mgo"
|
||||||
"github.com/globalsign/mgo/bson"
|
"github.com/globalsign/mgo/bson"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
|
||||||
"mongo.games.com/game/dbproxy/mongo"
|
"mongo.games.com/game/dbproxy/mongo"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/goserver/core/logger"
|
|
||||||
"net/rpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -16,6 +18,12 @@ var (
|
||||||
FriendApplyColError = errors.New("friendapply collection open failed")
|
FriendApplyColError = errors.New("friendapply collection open failed")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
FriendApplyListDBName = "log"
|
||||||
|
FriendApplyListCollName = "log_friendapplylist"
|
||||||
|
FriendApplyListColError = errors.New("friendapplylist collection open failed")
|
||||||
|
)
|
||||||
|
|
||||||
func FriendApplyCollection(plt string) *mongo.Collection {
|
func FriendApplyCollection(plt string) *mongo.Collection {
|
||||||
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, FriendApplyDBName)
|
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, FriendApplyDBName)
|
||||||
if s != nil {
|
if s != nil {
|
||||||
|
@ -28,6 +36,18 @@ func FriendApplyCollection(plt string) *mongo.Collection {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FriendApplyListCollection(plt string) *mongo.Collection {
|
||||||
|
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, FriendApplyListDBName)
|
||||||
|
if s != nil {
|
||||||
|
c, first := s.DB().C(FriendApplyListCollName)
|
||||||
|
if first {
|
||||||
|
c.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true})
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type FriendApplySvc struct {
|
type FriendApplySvc struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +91,49 @@ func (svc *FriendApplySvc) DelFriendApply(args *model.FriendApplyByKey, ret *boo
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *FriendApplySvc) UpsertApplyList(args *model.ApplyListReq, ret *model.ApplyListRes) error {
|
||||||
|
cc := FriendApplyListCollection(args.Platform)
|
||||||
|
if cc == nil {
|
||||||
|
return FriendApplyListColError
|
||||||
|
}
|
||||||
|
if args.Data == nil || args.Data.SnId <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, err := cc.Upsert(bson.M{"snid": args.Data.SnId}, args.Data)
|
||||||
|
if err != nil && err != mgo.ErrNotFound {
|
||||||
|
logger.Logger.Error("UpsertApplyList is err: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ret.Data = args.Data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svc *FriendApplySvc) QueryFriendApplyListBySnid(args *model.FriendApplyByKey, ret *model.ApplyListRes) error {
|
||||||
|
fc := FriendApplyListCollection(args.Platform)
|
||||||
|
if fc == nil {
|
||||||
|
return FriendApplyListColError
|
||||||
|
}
|
||||||
|
err := fc.Find(bson.M{"snid": args.SnId}).One(&ret.Data)
|
||||||
|
if err != nil && !errors.Is(err, mgo.ErrNotFound) {
|
||||||
|
logger.Logger.Error("QueryFriendApplyListBySnid is err: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svc *FriendApplySvc) DelFriendApplyList(args *model.FriendApplyByKey, ret *bool) error {
|
||||||
|
cc := FriendApplyListCollection(args.Platform)
|
||||||
|
if cc == nil {
|
||||||
|
return FriendApplyListColError
|
||||||
|
}
|
||||||
|
err := cc.Remove(bson.M{"snid": args.SnId})
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Error("DelFriendApplyList is err: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var _FriendApplySvc = &FriendApplySvc{}
|
var _FriendApplySvc = &FriendApplySvc{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/globalsign/mgo/bson"
|
"github.com/globalsign/mgo/bson"
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FriendApply struct {
|
type FriendApply struct {
|
||||||
|
@ -43,7 +44,7 @@ func UpsertFriendApply(platform string, snid int32, fa *FriendApply) *FriendAppl
|
||||||
logger.Logger.Error("model.UpsertFriendApply rpcCli == nil")
|
logger.Logger.Error("model.UpsertFriendApply rpcCli == nil")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if fa.ApplySnids == nil || len(fa.ApplySnids) == 0 {
|
if len(fa.ApplySnids) == 0 {
|
||||||
DelFriendApply(platform, snid)
|
DelFriendApply(platform, snid)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -52,8 +53,8 @@ func UpsertFriendApply(platform string, snid int32, fa *FriendApply) *FriendAppl
|
||||||
SnId: snid,
|
SnId: snid,
|
||||||
FA: fa,
|
FA: fa,
|
||||||
}
|
}
|
||||||
var ret *FriendApplyRet
|
ret := &FriendApplyRet{}
|
||||||
err := rpcCli.CallWithTimeout("FriendApplySvc.UpsertFriendApply", args, &ret, time.Second*30)
|
err := rpcCli.CallWithTimeout("FriendApplySvc.UpsertFriendApply", args, ret, time.Second*30)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.Warn("UpsertFriendApply error:", err)
|
logger.Logger.Warn("UpsertFriendApply error:", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -70,14 +71,12 @@ func QueryFriendApplyBySnid(platform string, snid int32) (fa *FriendApply, err e
|
||||||
Platform: platform,
|
Platform: platform,
|
||||||
SnId: snid,
|
SnId: snid,
|
||||||
}
|
}
|
||||||
var ret *FriendApplyRet
|
ret := &FriendApplyRet{}
|
||||||
err = rpcCli.CallWithTimeout("FriendApplySvc.QueryFriendApplyByKey", args, &ret, time.Second*30)
|
err = rpcCli.CallWithTimeout("FriendApplySvc.QueryFriendApplyByKey", args, ret, time.Second*30)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.Warn("QueryFriendApplyBySnid error:", err)
|
logger.Logger.Warn("QueryFriendApplyBySnid error:", err)
|
||||||
}
|
}
|
||||||
if ret != nil {
|
fa = ret.FA
|
||||||
fa = ret.FA
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,3 +95,84 @@ func DelFriendApply(platform string, snid int32) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===========================
|
||||||
|
// Apply List
|
||||||
|
//===========================
|
||||||
|
|
||||||
|
type ApplyList struct {
|
||||||
|
//Id bson.ObjectId `bson:"_id"`
|
||||||
|
SnId int32
|
||||||
|
List []int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApplyList(snId int32) *ApplyList {
|
||||||
|
return &ApplyList{
|
||||||
|
SnId: snId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApplyListReq struct {
|
||||||
|
Platform string
|
||||||
|
Data *ApplyList
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApplyListRes struct {
|
||||||
|
Data *ApplyList
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpsertApplyList(platform string, data *ApplyList) {
|
||||||
|
if rpcCli == nil {
|
||||||
|
logger.Logger.Error("model.UpsertApplyList rpcCli == nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(data.List) == 0 {
|
||||||
|
DelFriendApplyList(platform, data.SnId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
args := &ApplyListReq{
|
||||||
|
Platform: platform,
|
||||||
|
Data: data,
|
||||||
|
}
|
||||||
|
ret := &ApplyListRes{}
|
||||||
|
err := rpcCli.CallWithTimeout("FriendApplySvc.UpsertApplyList", args, ret, time.Second*30)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Warn("UpsertApplyList error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func QueryFriendApplyListBySnid(platform string, snid int32) (data *ApplyList, err error) {
|
||||||
|
if rpcCli == nil {
|
||||||
|
logger.Logger.Error("model.QueryFriendApplyListBySnid rpcCli == nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
args := &FriendApplyByKey{
|
||||||
|
Platform: platform,
|
||||||
|
SnId: snid,
|
||||||
|
}
|
||||||
|
ret := &ApplyListRes{}
|
||||||
|
err = rpcCli.CallWithTimeout("FriendApplySvc.QueryFriendApplyListBySnid", args, ret, time.Second*30)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Warn("QueryFriendApplyListBySnid error:", err)
|
||||||
|
}
|
||||||
|
data = ret.Data
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func DelFriendApplyList(platform string, snid int32) {
|
||||||
|
if rpcCli == nil {
|
||||||
|
logger.Logger.Error("model.DelFriendApplyList rpcCli == nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
args := &FriendApplyByKey{
|
||||||
|
Platform: platform,
|
||||||
|
SnId: snid,
|
||||||
|
}
|
||||||
|
err := rpcCli.CallWithTimeout("FriendApplySvc.DelFriendApplyList", args, nil, time.Second*30)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Warn("DelFriendApplyList error:", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -456,7 +456,6 @@ type PlayerData struct {
|
||||||
WeekCardTime map[int32]int64 // 周卡结束时间 key:类型 value:结束时间
|
WeekCardTime map[int32]int64 // 周卡结束时间 key:类型 value:结束时间
|
||||||
WeekCardAward map[int32]bool //周卡奖励领取状态false-未领取,true已领取
|
WeekCardAward map[int32]bool //周卡奖励领取状态false-未领取,true已领取
|
||||||
ItemRecExpireTime int64 // 记牌器到期时间
|
ItemRecExpireTime int64 // 记牌器到期时间
|
||||||
RequestAddFriend map[int32]int64 //玩家申请好友记录
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 七日签到数据
|
// 七日签到数据
|
||||||
|
@ -775,12 +774,11 @@ func NewPlayerData(acc string, name string, id int32, channel, platform string,
|
||||||
ShopLastLookTime: make(map[int32]int64),
|
ShopLastLookTime: make(map[int32]int64),
|
||||||
IsFoolPlayer: make(map[string]bool),
|
IsFoolPlayer: make(map[string]bool),
|
||||||
//测试数据
|
//测试数据
|
||||||
PowerList: []int32{1}, //默认炮台
|
PowerList: []int32{1}, //默认炮台
|
||||||
UnMaxPower: 10, //初始化炮倍最小倍数
|
UnMaxPower: 10, //初始化炮倍最小倍数
|
||||||
WeekCardTime: make(map[int32]int64),
|
WeekCardTime: make(map[int32]int64),
|
||||||
WeekCardAward: make(map[int32]bool),
|
WeekCardAward: make(map[int32]bool),
|
||||||
WelfData: NewWelfareData(),
|
WelfData: NewWelfareData(),
|
||||||
RequestAddFriend: make(map[int32]int64),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if tel != "" {
|
if tel != "" {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mongo.games.com/goserver/core"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -259,34 +258,46 @@ func (this *FriendMgr) IsFriend(platform string, snid, destSnid int32) bool {
|
||||||
|
|
||||||
// ApplyList 查询好友申请列表
|
// ApplyList 查询好友申请列表
|
||||||
func (this *FriendMgr) ApplyList(platform string, snid int32) {
|
func (this *FriendMgr) ApplyList(platform string, snid int32) {
|
||||||
|
var err error
|
||||||
|
list := &model.ApplyList{}
|
||||||
|
ret := &model.FriendApply{}
|
||||||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
ret, err := model.QueryFriendApplyBySnid(platform, snid)
|
ret, err = model.QueryFriendApplyBySnid(platform, snid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
logger.Logger.Errorf("(this *FriendMgr) ApplyList QueryFriendApplyBySnid %v", err)
|
||||||
|
}
|
||||||
|
list, err = model.QueryFriendApplyListBySnid(platform, snid)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Errorf("(this *FriendMgr) ApplyList QueryFriendApplyListBySnid %v", err)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
if ret, ok := data.(*model.FriendApply); ok && ret != nil && ret.ApplySnids != nil {
|
if ret != nil && ret.ApplySnids != nil {
|
||||||
if ret.ApplySnids != nil {
|
pack := &friend.SCFriendApplyData{}
|
||||||
pack := &friend.SCFriendApplyData{}
|
for _, as := range ret.ApplySnids {
|
||||||
for _, as := range ret.ApplySnids {
|
fa := &friend.FriendApply{
|
||||||
fa := &friend.FriendApply{
|
Snid: proto.Int32(as.SnId),
|
||||||
Snid: proto.Int32(as.SnId),
|
Name: proto.String(as.Name),
|
||||||
Name: proto.String(as.Name),
|
CreateTs: proto.Int64(as.CreateTs),
|
||||||
CreateTs: proto.Int64(as.CreateTs),
|
|
||||||
}
|
|
||||||
pack.FriendApplys = append(pack.FriendApplys, fa)
|
|
||||||
}
|
}
|
||||||
if len(pack.FriendApplys) > 0 {
|
pack.FriendApplys = append(pack.FriendApplys, fa)
|
||||||
proto.SetDefaults(pack)
|
}
|
||||||
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
if len(pack.FriendApplys) > 0 {
|
||||||
if p != nil {
|
proto.SetDefaults(pack)
|
||||||
p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendApplyData), pack)
|
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
||||||
logger.Logger.Trace("SCFriendApplyData: 好友申请列表 pack: ", pack)
|
if p != nil {
|
||||||
}
|
p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendApplyData), pack)
|
||||||
|
logger.Logger.Trace("SCFriendApplyData: 好友申请列表 pack: ", pack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if list != nil && list.List != nil {
|
||||||
|
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
||||||
|
if p != nil {
|
||||||
|
p.ApplyList = list.List
|
||||||
|
this.SendApplyList(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
})).StartByFixExecutor("QueryFriendApplyBySnid")
|
})).StartByFixExecutor("QueryFriendApplyBySnid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,66 +385,22 @@ func (this *FriendMgr) FriendOp(opcode int32, p *Player, destP *model.BindFriend
|
||||||
case OpType_Apply:
|
case OpType_Apply:
|
||||||
logger.Logger.Trace("@Apply friend", p.SnId, " -> ", destP.SnId)
|
logger.Logger.Trace("@Apply friend", p.SnId, " -> ", destP.SnId)
|
||||||
this.FriendApply(p, destP)
|
this.FriendApply(p, destP)
|
||||||
p.RequestAddFriend[destP.SnId] = time.Now().Unix()
|
|
||||||
this.SendRequestAddFriend(p)
|
|
||||||
case OpType_Agree:
|
case OpType_Agree:
|
||||||
logger.Logger.Trace("@AgreeApply friend", p.SnId, " -> ", destP.SnId)
|
logger.Logger.Trace("@AgreeApply friend", p.SnId, " -> ", destP.SnId)
|
||||||
this.FriendAgree(p, destP)
|
this.FriendAgree(p, destP)
|
||||||
destPs := PlayerMgrSington.GetPlayerBySnId(destP.SnId)
|
|
||||||
if destPs != nil {
|
|
||||||
delete(destPs.RequestAddFriend, p.SnId)
|
|
||||||
this.SendRequestAddFriend(destPs)
|
|
||||||
} else {
|
|
||||||
//从DB获取玩家信息
|
|
||||||
task.New(core.CoreObject(), task.CallableWrapper(func(o *basic.Object) interface{} {
|
|
||||||
pd, _ := model.GetPlayerDataBySnId(destP.Platform, destP.SnId, false, false)
|
|
||||||
return pd
|
|
||||||
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
|
||||||
pd, ok := data.(*model.PlayerData)
|
|
||||||
if !ok || pd == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
delete(pd.RequestAddFriend, p.SnId)
|
|
||||||
model.SavePlayerData(pd)
|
|
||||||
}), "FriendMgr.FriendOp").StartByExecutor(strconv.Itoa(int(p.SnId)))
|
|
||||||
}
|
|
||||||
case OpType_Refuse:
|
case OpType_Refuse:
|
||||||
logger.Logger.Trace("@Refuse friend", p.SnId, " -> ", destP.SnId)
|
logger.Logger.Trace("@Refuse friend", p.SnId, " -> ", destP.SnId)
|
||||||
this.FriendRefuse(p, destP)
|
this.FriendRefuse(p, destP)
|
||||||
destPs := PlayerMgrSington.GetPlayerBySnId(destP.SnId)
|
|
||||||
if destPs != nil {
|
|
||||||
delete(destPs.RequestAddFriend, p.SnId)
|
|
||||||
this.SendRequestAddFriend(destPs)
|
|
||||||
} else {
|
|
||||||
//从DB获取玩家信息
|
|
||||||
task.New(core.CoreObject(), task.CallableWrapper(func(o *basic.Object) interface{} {
|
|
||||||
pd, _ := model.GetPlayerDataBySnId(destP.Platform, destP.SnId, false, false)
|
|
||||||
return pd
|
|
||||||
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
|
||||||
pd, ok := data.(*model.PlayerData)
|
|
||||||
if !ok || pd == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
delete(pd.RequestAddFriend, p.SnId)
|
|
||||||
model.SavePlayerData(pd)
|
|
||||||
}), "FriendMgr.FriendOp").StartByExecutor(strconv.Itoa(int(p.SnId)))
|
|
||||||
}
|
|
||||||
case OpType_Delete:
|
case OpType_Delete:
|
||||||
logger.Logger.Trace("@Delete friend", p.SnId, " -> ", destP.SnId)
|
logger.Logger.Trace("@Delete friend", p.SnId, " -> ", destP.SnId)
|
||||||
this.FriendDelete(p, destP)
|
this.FriendDelete(p, destP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (this *FriendMgr) SendRequestAddFriend(p *Player) {
|
|
||||||
pack := &friend.SCRequestAddFriend{}
|
|
||||||
for snid, _ := range p.RequestAddFriend {
|
|
||||||
pack.RequestAddFriend = append(pack.RequestAddFriend, snid)
|
|
||||||
}
|
|
||||||
p.SendToClient(int(friend.FriendPacketID_PACKET_SCRequestAddFriend), pack)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FriendApply 好友申请
|
// FriendApply 好友申请
|
||||||
// 记录在数据库
|
// 记录在数据库
|
||||||
func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
|
func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
|
||||||
|
var applyList []int32
|
||||||
SendToClick := func(retCode friend.OpResultCode, self ...bool) {
|
SendToClick := func(retCode friend.OpResultCode, self ...bool) {
|
||||||
pack := &friend.SCFriendOp{
|
pack := &friend.SCFriendOp{
|
||||||
OpCode: proto.Int32(OpType_Apply),
|
OpCode: proto.Int32(OpType_Apply),
|
||||||
|
@ -442,6 +409,10 @@ func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
|
||||||
}
|
}
|
||||||
if len(self) == 0 {
|
if len(self) == 0 {
|
||||||
p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendOp), pack)
|
p.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendOp), pack)
|
||||||
|
if applyList != nil {
|
||||||
|
p.ApplyList = applyList
|
||||||
|
this.SendApplyList(p)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
destPs := PlayerMgrSington.GetPlayerBySnId(destP.SnId)
|
destPs := PlayerMgrSington.GetPlayerBySnId(destP.SnId)
|
||||||
if destPs != nil && destPs.IsOnLine() {
|
if destPs != nil && destPs.IsOnLine() {
|
||||||
|
@ -502,6 +473,21 @@ func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
|
||||||
RoleId: int32(roleId),
|
RoleId: int32(roleId),
|
||||||
})
|
})
|
||||||
model.UpsertFriendApply(p.Platform, destP.SnId, ret)
|
model.UpsertFriendApply(p.Platform, destP.SnId, ret)
|
||||||
|
|
||||||
|
data, err := model.QueryFriendApplyListBySnid(p.Platform, p.SnId)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Errorf("QueryFriendApplyListBySnid err:%v", err)
|
||||||
|
} else {
|
||||||
|
if data == nil {
|
||||||
|
data = model.NewApplyList(p.SnId)
|
||||||
|
}
|
||||||
|
if !common.InSliceInt32(data.List, destP.SnId) {
|
||||||
|
data.List = append(data.List, destP.SnId)
|
||||||
|
model.UpsertApplyList(p.Platform, data)
|
||||||
|
applyList = data.List
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return friend.OpResultCode_OPRC_Sucess
|
return friend.OpResultCode_OPRC_Sucess
|
||||||
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
SendToClick(friend.OpResultCode_OPRC_Sucess, false) // 对方
|
SendToClick(friend.OpResultCode_OPRC_Sucess, false) // 对方
|
||||||
|
@ -511,6 +497,7 @@ func (this *FriendMgr) FriendApply(p *Player, destP *model.BindFriend) {
|
||||||
|
|
||||||
// FriendAgree 同意好友申请
|
// FriendAgree 同意好友申请
|
||||||
func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
|
func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
|
||||||
|
var applyList []int32
|
||||||
SendToClick := func(retCode friend.OpResultCode, self ...bool) {
|
SendToClick := func(retCode friend.OpResultCode, self ...bool) {
|
||||||
pack := &friend.SCFriendOp{
|
pack := &friend.SCFriendOp{
|
||||||
OpCode: proto.Int32(OpType_Agree),
|
OpCode: proto.Int32(OpType_Agree),
|
||||||
|
@ -551,6 +538,10 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
|
||||||
RoleId: int32(roleId),
|
RoleId: int32(roleId),
|
||||||
}
|
}
|
||||||
destPs.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendOp), pack)
|
destPs.SendToClient(int(friend.FriendPacketID_PACKET_SCFriendOp), pack)
|
||||||
|
if applyList != nil {
|
||||||
|
destPs.ApplyList = applyList
|
||||||
|
this.SendApplyList(destPs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.Logger.Tracef(">>FriendAgree %d -> %d, %v", p.SnId, destP.SnId, pack)
|
logger.Logger.Tracef(">>FriendAgree %d -> %d, %v", p.SnId, destP.SnId, pack)
|
||||||
|
@ -615,6 +606,24 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
|
||||||
//在申请列表 删除
|
//在申请列表 删除
|
||||||
ret.ApplySnids = append(ret.ApplySnids[:i], ret.ApplySnids[i+1:]...)
|
ret.ApplySnids = append(ret.ApplySnids[:i], ret.ApplySnids[i+1:]...)
|
||||||
model.UpsertFriendApply(p.Platform, p.SnId, ret)
|
model.UpsertFriendApply(p.Platform, p.SnId, ret)
|
||||||
|
|
||||||
|
data, err := model.QueryFriendApplyListBySnid(p.Platform, destP.SnId)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Errorf("QueryFriendApplyListBySnid err:%v", err)
|
||||||
|
} else {
|
||||||
|
if data == nil {
|
||||||
|
data = model.NewApplyList(destP.SnId)
|
||||||
|
}
|
||||||
|
for k, v := range data.List {
|
||||||
|
if v == p.SnId {
|
||||||
|
data.List = append(data.List[:k], data.List[k+1:]...)
|
||||||
|
model.UpsertApplyList(p.Platform, data)
|
||||||
|
applyList = data.List
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 保存好友关系
|
// 保存好友关系
|
||||||
if friendDB != nil {
|
if friendDB != nil {
|
||||||
friendDB.BindFriend = append(friendDB.BindFriend, &model.BindFriend{
|
friendDB.BindFriend = append(friendDB.BindFriend, &model.BindFriend{
|
||||||
|
@ -673,6 +682,7 @@ func (this *FriendMgr) FriendAgree(p *Player, destP *model.BindFriend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
|
func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
|
||||||
|
var applyList []int32
|
||||||
SendToClick := func(retCode friend.OpResultCode, self ...bool) {
|
SendToClick := func(retCode friend.OpResultCode, self ...bool) {
|
||||||
pack := &friend.SCFriendOp{
|
pack := &friend.SCFriendOp{
|
||||||
OpCode: proto.Int32(OpType_Refuse),
|
OpCode: proto.Int32(OpType_Refuse),
|
||||||
|
@ -701,6 +711,24 @@ func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
|
||||||
if as.SnId == destP.SnId {
|
if as.SnId == destP.SnId {
|
||||||
ret.ApplySnids = append(ret.ApplySnids[:i], ret.ApplySnids[i+1:]...)
|
ret.ApplySnids = append(ret.ApplySnids[:i], ret.ApplySnids[i+1:]...)
|
||||||
model.UpsertFriendApply(p.Platform, p.SnId, ret)
|
model.UpsertFriendApply(p.Platform, p.SnId, ret)
|
||||||
|
|
||||||
|
data, err := model.QueryFriendApplyListBySnid(p.Platform, destP.SnId)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Errorf("QueryFriendApplyListBySnid err:%v", err)
|
||||||
|
} else {
|
||||||
|
if data == nil {
|
||||||
|
data = model.NewApplyList(destP.SnId)
|
||||||
|
}
|
||||||
|
for k, v := range data.List {
|
||||||
|
if v == p.SnId {
|
||||||
|
data.List = append(data.List[:k], data.List[k+1:]...)
|
||||||
|
model.UpsertApplyList(p.Platform, data)
|
||||||
|
applyList = data.List
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -715,6 +743,14 @@ func (this *FriendMgr) FriendRefuse(p *Player, destP *model.BindFriend) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
SendToClick(friend.OpResultCode_OPRC_Sucess)
|
SendToClick(friend.OpResultCode_OPRC_Sucess)
|
||||||
|
|
||||||
|
destPs := PlayerMgrSington.GetPlayerBySnId(destP.SnId)
|
||||||
|
if destPs != nil && destPs.IsOnLine() {
|
||||||
|
if applyList != nil {
|
||||||
|
destPs.ApplyList = applyList
|
||||||
|
this.SendApplyList(destPs)
|
||||||
|
}
|
||||||
|
}
|
||||||
})).StartByFixExecutor(FriendWrite)
|
})).StartByFixExecutor(FriendWrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,6 +851,15 @@ func (this *FriendMgr) UpdateHead(snId, head int32) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *FriendMgr) SendApplyList(p *Player) {
|
||||||
|
pack := &friend.SCRequestAddFriend{}
|
||||||
|
for _, v := range p.ApplyList {
|
||||||
|
pack.RequestAddFriend = append(pack.RequestAddFriend, v)
|
||||||
|
}
|
||||||
|
p.SendToClient(int(friend.FriendPacketID_PACKET_SCRequestAddFriend), pack)
|
||||||
|
logger.Logger.Tracef("SCRequestAddFriend:%v %v", pack, p.SnId)
|
||||||
|
}
|
||||||
|
|
||||||
//========================implement IPlayerLoad ==============================
|
//========================implement IPlayerLoad ==============================
|
||||||
|
|
||||||
func (this *FriendMgr) Load(platform string, snid int32, player any) *internal.PlayerLoadReplay {
|
func (this *FriendMgr) Load(platform string, snid int32, player any) *internal.PlayerLoadReplay {
|
||||||
|
|
|
@ -147,6 +147,7 @@ type Player struct {
|
||||||
LastGameId int
|
LastGameId int
|
||||||
GameID []int32 // 最近三天玩的游戏
|
GameID []int32 // 最近三天玩的游戏
|
||||||
InviteNum int32 // 邀请人数
|
InviteNum int32 // 邀请人数
|
||||||
|
ApplyList []int32 //玩家申请好友记录
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPlayer(sid int64, pd *model.PlayerData, s *netlib.Session) *Player {
|
func NewPlayer(sid int64, pd *model.PlayerData, s *netlib.Session) *Player {
|
||||||
|
@ -313,9 +314,6 @@ func (this *Player) OnLogined() {
|
||||||
|
|
||||||
this.VipExtra = VipMgrSington.GetVipPointsExtra(this.Platform, this.VIP)
|
this.VipExtra = VipMgrSington.GetVipPointsExtra(this.Platform, this.VIP)
|
||||||
|
|
||||||
if this.RequestAddFriend == nil {
|
|
||||||
this.RequestAddFriend = make(map[int32]int64)
|
|
||||||
}
|
|
||||||
// 头像决定性别
|
// 头像决定性别
|
||||||
this.Sex = (this.Head%2 + 1) % 2
|
this.Sex = (this.Head%2 + 1) % 2
|
||||||
|
|
||||||
|
@ -3025,13 +3023,8 @@ func (this *Player) SendPlayerInfo() {
|
||||||
}
|
}
|
||||||
scPlayerData.Data.WeekCard = append(scPlayerData.Data.WeekCard, &weekInfo)
|
scPlayerData.Data.WeekCard = append(scPlayerData.Data.WeekCard, &weekInfo)
|
||||||
}
|
}
|
||||||
//玩家申请好友记录
|
|
||||||
for snid, _ := range this.RequestAddFriend {
|
|
||||||
scPlayerData.Data.RequestAddFriend = append(scPlayerData.Data.RequestAddFriend, snid)
|
|
||||||
}
|
|
||||||
proto.SetDefaults(scPlayerData)
|
|
||||||
logger.Logger.Tracef("Send SCPlayerData %v", scPlayerData)
|
|
||||||
this.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_PLAYERDATA), scPlayerData)
|
this.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_PLAYERDATA), scPlayerData)
|
||||||
|
logger.Logger.Tracef("Send SCPlayerData %v", scPlayerData)
|
||||||
|
|
||||||
if !this.IsRob {
|
if !this.IsRob {
|
||||||
this.SyncPlayerDataToGateSrv(this.PlayerData)
|
this.SyncPlayerDataToGateSrv(this.PlayerData)
|
||||||
|
|
Loading…
Reference in New Issue