You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
16 KiB

1 month ago
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
//using Sog;
//using ProtoCSStruct;
//namespace Friend
//{
// /// <summary>
// /// 好友邀请,同意,拒绝,删除等op处理
// /// </summary>
// public static partial class FriendOpSvc
// {
// // 申请添加好友, 由对方处理, 处理对方数据
// // 同意添加, 处理双方数据
// // 删除好友, 处理双方数据
// // 拒绝/忽略, 处理对方数据
// //好友op数据从数据库加载内存成功后,先行处理一遍逻辑
// public static unsafe void ProcessOpdataOnDataLoaded(ref FriendCacheInfoStruct friendInfo)
// {
// for(int i= friendInfo.FriendOpData.OpCount - 1; i >= 0; i--)
// {
// ref DBFriendOneOpStruct oneOp = ref FriendInfoCache.m_cacheStructFriendOneOp.GetByIndex(friendInfo.FriendOpData.OpList[i]);
// bool bDeleteOp = false;
// if(oneOp.OpType == (int)DBFriendOpType.Invite)
// {
// ProcessDBFriendOneOpInvite(ref friendInfo, ref oneOp, out bDeleteOp);
// }
// else if(oneOp.OpType == (int)DBFriendOpType.Delete)
// {
// ProcessDBFriendOneOpDelete(ref friendInfo, ref oneOp, out bDeleteOp);
// }
// else if (oneOp.OpType == (int)DBFriendOpType.AgreeAdd)
// {
// ProcessDBFriendOneOpAgreeAdd(ref friendInfo, ref oneOp, out bDeleteOp);
// }
// if(bDeleteOp)
// {
// // 从FriendOp缓存池中删除该deleteOp
// FriendOp.DoDeleteFriendOP(ref friendInfo, oneOp.GetObjectID());
// }
// }
// }
// public static void ProcessDBFriendOneOpInvite(ref FriendCacheInfoStruct friendInfo, ref DBFriendOneOpStruct oneOp, out bool bDeleteOp)
// {
// bDeleteOp = false;
// ref DBFriendOneStruct opOneFriend = ref FriendInfoCache.m_cacheStructFriendOne.GetByIndex(oneOp.DBFriendOneID);
// if (opOneFriend.IsNull())
// {
// return;
// }
// //看一下是不是已经是好友了,是好友了则自动回一个同意并删除这个op
// if (FriendOp.ISAlreadyBeenFriend(friendInfo.Self.Uid, opOneFriend.oneFriend.Uid) == 1)
// {
// TraceLog.Error("FriendOpSvc.ProcessDBFriendOneOpInvite Uid {0} recv invite from Uid {1}, but already in friendlist,agree it"
// , friendInfo.Self.Uid, opOneFriend.oneFriend.Uid);
// bDeleteOp = true;
// SSFriendOpReq opReqAgree = new SSFriendOpReq();
// opReqAgree.TargetUid = opOneFriend.oneFriend.Uid;
// opReqAgree.Op.OpType = (int)DBFriendOpType.AgreeAdd;
// FriendUtils.CopySelfToFriendOne(ref friendInfo.Self, ref opReqAgree.Op.Friend);
// SendDBOpRequestFromWorld(friendInfo.Self.Uid, opOneFriend.oneFriend.Uid, ref opReqAgree);
// return;
// }
// //判断一下好友是不是已经满了,如果满了通知一下错误
// if(friendInfo.FriendList.iCount >= FriendStructDef.MaxFriendCount)
// {
// bDeleteOp = true;
// FriendNotify.NotifyPlayerFriendOpResult(opOneFriend.oneFriend.Uid, friendInfo.Self.Uid, 310201, CliFriendOpType.Invite);
// return;
// }
// }
// public static void ProcessDBFriendOneOpDelete(ref FriendCacheInfoStruct friendInfo, ref DBFriendOneOpStruct oneOp, out bool bDeleteOp)
// {
// //删除好友是不需要同意的,处理后op都需要删除
// bDeleteOp = true;
// //opOneFriend 和 friendOne 不是同一个,即使数据可能相同
// ref DBFriendOneStruct opOneFriend = ref FriendInfoCache.m_cacheStructFriendOne.GetByIndex(oneOp.DBFriendOneID);
// if (opOneFriend.IsNull())
// {
// return;
// }
// ref DBFriendOneStruct friendOne = ref FriendOp.GetFriendOneByUid(friendInfo.Self.Uid, opOneFriend.oneFriend.Uid);
// if (!friendOne.IsNull() && friendOne.oneFriend.FriendType != 1 && FriendOp.ISAlreadyBeenFriend(friendInfo.Self.Uid, opOneFriend.oneFriend.Uid) == 1)
// {
// TraceLog.Trace("FriendOpSvc.ProcessDBFriendOneOpInvite Uid {0} recv delete from Uid {1}, delete friend in list"
// , friendInfo.Self.Uid, opOneFriend.oneFriend.Uid);
// FriendOp.DoDeleteFriendList(ref friendInfo, opOneFriend.oneFriend.Uid);
// //删除行为,发起方式在线玩家,自己的列表里已经先行删除了,这里收到这个op的是另一方,所以是不需要再次通知对方我删除了
// }
// }
// public static void ProcessDBFriendOneOpAgreeAdd(ref FriendCacheInfoStruct friendInfo, ref DBFriendOneOpStruct oneOp, out bool bDeleteOp)
// {
// //肯定是要删除的,添加要么成功,要么失败
// bDeleteOp = true;
// ref DBFriendOneStruct opOneFriend = ref FriendInfoCache.m_cacheStructFriendOne.GetByIndex(oneOp.DBFriendOneID);
// if (opOneFriend.IsNull())
// {
// return;
// }
// //看一下是不是已经是好友了,是好友了直接删除这个op
// if (FriendOp.ISAlreadyBeenFriend(friendInfo.Self.Uid, opOneFriend.oneFriend.Uid) == 1)
// {
// TraceLog.Error("FriendOpSvc.ProcessDBFriendOneOpAgreeAdd Uid {0} recv agreeadd from Uid {1}, but already in friendlist,agree it"
// , friendInfo.Self.Uid, opOneFriend.oneFriend.Uid);
// return;
// }
// //判断一下好友是不是已经满了,如果满了通知一下错误
// if (friendInfo.FriendList.iCount >= FriendStructDef.MaxFriendCount)
// {
// TraceLog.Error("FriendOpSvc.ProcessDBFriendOneOpAgreeAdd Uid {0} recv agreeadd from Uid {1}, but full, delete it and notify him delete me"
// , friendInfo.Self.Uid, opOneFriend.oneFriend.Uid);
// FriendNotify.NotifyPlayerFriendOpResult(opOneFriend.oneFriend.Uid, friendInfo.Self.Uid, 310201, CliFriendOpType.Agree);
// //通知对方删除我
// SSFriendOpReq opReqDelete = new SSFriendOpReq();
// opReqDelete.TargetUid = opOneFriend.oneFriend.Uid;
// opReqDelete.Op.OpType = (int)DBFriendOpType.Delete;
// FriendUtils.CopySelfToFriendOne(ref friendInfo.Self, ref opReqDelete.Op.Friend);
// SendDBOpRequestFromWorld(friendInfo.Self.Uid, opOneFriend.oneFriend.Uid, ref opReqDelete);
// return;
// }
// //可以正常添加好友
// FriendOp.DoAddFriendOneToMySelf(friendInfo.Self.Uid, opOneFriend.oneFriend.Uid);
// PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(friendInfo.Self.Uid);
// if (player != null && player.IsOnline)
// {
// FriendNotify.NotifyPlayerFriendListChg(player.UserID, opOneFriend.oneFriend.Uid);
// }
// }
// public static void SendDBOpRequestFromWorld(long fromUid, long targetUid, ref SSFriendOpReq req)
// {
// //内存里没有,从db里加载
// ref FriendCacheInfoStruct targetFriendCacheInfo = ref FriendOp.GetFriendInfoByUid(req.TargetUid);
// if (targetFriendCacheInfo.IsNull())
// {
// TraceLog.Trace("FriendOpSvc.SendDBOpRequestFromWorld can not find target FriendCacheInfo Uid {0}"
// , req.TargetUid);
// FriendCacheSvc.m_SSQueryFriendInfoCacheReq.Clear();
// FriendCacheSvc.m_SSQueryFriendInfoCacheReq.SsOpCallback = req;
// FriendCacheSvc.SendDBQueryFriendInfoCache(req.TargetUid, fromUid, QueryFriendInfoCacheReason.QueryBySsOp/*, csreq, req*/);
// return;
// }
// //内存里有,直接处理
// OnFriendOpDBDataQuerySuccessSSOpReq(ref req, fromUid);
// }
// //处理服务器自己给自己的op请求,逻辑和从db加载后的处理类似,不同的是db加载有可能没有对方的信息,这里内存里一定有双方的信息
// public static void OnFriendOpDBDataQuerySuccessSSOpReq(ref SSFriendOpReq req, long fromUid)
// {
// //这种情况按理说是不应该发生的,SSOp的请求发出去前应该都是预先校验过的
// ref FriendCacheInfoStruct targetFriendCacheInfo = ref FriendOp.GetFriendInfoByUid(req.TargetUid);
// if (targetFriendCacheInfo.IsNull())
// {
// TraceLog.Error("FriendOpSvc.OnFriendOpDBDataQuerySuccessSSOpReq can not find target FriendCacheInfo Uid {0}"
// , req.TargetUid);
// return;
// }
// //from的那个玩家的数据
// ref FriendCacheInfoStruct frominfo = ref FriendOp.GetFriendInfoByUid(fromUid);
// if (frominfo.IsNull())
// {
// TraceLog.Error("FriendOpSvc.OnFriendOpDBDataQuerySuccessSSOpReq can not find FriendCacheInfo Uid {0}", fromUid);
// return;
// }
// if (req.Op.OpType == (int)DBFriendOpType.Invite)
// {
// ProcessDBFriendOneOpInviteSSOpReq(ref targetFriendCacheInfo, ref req.Op, ref frominfo);
// }
// else if (req.Op.OpType == (int)DBFriendOpType.Delete)
// {
// ProcessDBFriendOneOpDeleteSSOpReq(ref targetFriendCacheInfo, ref req.Op, ref frominfo);
// }
// else if (req.Op.OpType == (int)DBFriendOpType.AgreeAdd)
// {
// ProcessDBFriendOneOpAgreeAddSSOpReq(ref targetFriendCacheInfo, ref req.Op, ref frominfo);
// }
// }
// public static void ProcessDBFriendOneOpInviteSSOpReq(ref FriendCacheInfoStruct friendInfo, ref DBFriendOneOp oneOp, ref FriendCacheInfoStruct fromFriendInfo)
// {
// //invite不应该调用到,实际逻辑里没有使用
// long Uid = friendInfo.Self.Uid;
// long targetUid = oneOp.Friend.Uid;
// TraceLog.Error("ProcessDBFriendOneOpInviteSSOpReq Uid {0} invite target Uid {1}", Uid, targetUid);
// }
// public static void ProcessDBFriendOneOpAgreeAddSSOpReq(ref FriendCacheInfoStruct friendInfo, ref DBFriendOneOp oneOp, ref FriendCacheInfoStruct fromFriendInfo)
// {
// long Uid = friendInfo.Self.Uid;
// long targetUid = oneOp.Friend.Uid;
// if(targetUid != fromFriendInfo.Self.Uid)
// {
// TraceLog.Error("ProcessDBFriendOneOpAgreeAddSSOpReq Uid {0} agreeadd targetUid {1} != fromuid {2}"
// , Uid, targetUid, fromFriendInfo.Self.Uid);
// return;
// }
// if (Uid == targetUid)
// {
// TraceLog.Error("ProcessDBFriendOneOpAgreeAddSSOpReq Uid {0} agree self", Uid);
// return;
// }
// //收到这个请求说明对方已经加我为好友了
// if (FriendOp.ISAlreadyBeenFriend(Uid, targetUid) == 1)
// {
// TraceLog.Error("ProcessDBFriendOneOpAgreeAddSSOpReq Uid {0} targetuid {1} alrady in friendlist", Uid, targetUid);
// return;
// }
// //没在好友列表的话,尝试添加,先要判断是不是满了,满了的话直接删除对方好友列表里的我
// if (friendInfo.FriendList.iCount >= FriendStructDef.MaxFriendCount)
// {
// TraceLog.Error("ProcessDBFriendOneOpAgreeAddSSOpReq Uid {0} targetuid {1} friend list is full, delete me from his friendlist"
// , Uid, targetUid);
// //==============================对方的操作和通知
// //删除target里好友列表里的我
// ref DBFriendOneStruct mefriend = ref FriendOp.GetFriendOneByUid(targetUid,Uid);
// //不是好友,概率极低,就是在这个op到db转一圈的过程中好友被删除了
// // 现在是同时加载双方好友数据后再处理好友邀请,不存在op到db转一圈的说法
// if (mefriend.IsNull())
// {
// // 不应该打错误日志,我同意邀请时好友满了,我肯定不在对方的好友列表中
// TraceLog.Error("ProcessDBFriendOneOpAgreeAddSSOpReq Uid {0} delete me from targetFriendCacheInfo {1} not in his friend list"
// , Uid, targetUid);
// return;
// }
// //执行内存删除操作
// FriendOp.DoDeleteFriendList(ref fromFriendInfo, Uid);
// //通知玩家好友列表删除变化
// FriendNotify.NotifyPlayerFriendListDelete(targetUid,ref mefriend);
// //如果op列表里有对方发过来的邀请请求,那么删除之
// TryDoDeleteOpByUidAndNotifyPlayer(ref fromFriendInfo, Uid, DBFriendOpType.Invite);
// return;
// }
// TraceLog.Trace("ProcessDBFriendOneOpAgreeAddSSOpReq Uid {0} targetuid {1} , add to my list", Uid, targetUid);
// FriendOp.DoAddFriendOneToMySelf(Uid, targetUid);
// //好友列表变化
// FriendNotify.NotifyPlayerFriendListChg(Uid, targetUid);
// //如果op列表里有对方发过来的邀请请求,那么删除之
// TryDoDeleteOpByUidAndNotifyPlayer(ref friendInfo, targetUid, DBFriendOpType.Invite);
// }
// public static void ProcessDBFriendOneOpDeleteSSOpReq(ref FriendCacheInfoStruct friendInfo, ref DBFriendOneOp oneOp, ref FriendCacheInfoStruct fromFriendInfo)
// {
// long Uid = friendInfo.Self.Uid;
// long targetUid = oneOp.Friend.Uid;
// if (Uid == targetUid)
// {
// TraceLog.Error("ProcessDBFriendOneOpDeleteSSOpReq Uid {0} delete self", Uid);
// return;
// }
// ref DBFriendOneStruct friend = ref FriendOp.GetFriendOneByUid(Uid, targetUid);
// //不是好友了,算成功了
// if (friend.IsNull())
// {
// TraceLog.Error("ProcessDBFriendOneOpDeleteSSOpReq Uid {0} delete targetuid {1} not in friend list"
// , Uid, targetUid);
// return;
// }
// //sns好友无法删除,不应该发生
// if (friend.oneFriend.FriendType == 1)
// {
// TraceLog.Error("ProcessDBFriendOneOpDeleteSSOpReq Uid {0} delete targetuid {1} is sns friend,can not delete"
// , Uid, targetUid);
// return;
// }
// TraceLog.Trace("ProcessDBFriendOneOpDeleteSSOpReq Uid {0} delete targetuid {1} do delete from list"
// , Uid, targetUid);
// //==============================操作和通知,这里不需要通知客户端删除操作成功,因为不是客户端发起的请求,客户端的删除请求在Cli里
// //执行内存删除操作
// FriendOp.DoDeleteFriendList(ref friendInfo, targetUid);
// //通知玩家好友列表删除变化
// FriendNotify.NotifyPlayerFriendListDelete(Uid, ref friend);
// //如果op列表里有对方发过来的邀请请求,那么删除之
// TryDoDeleteOpByUidAndNotifyPlayer(ref friendInfo, targetUid, DBFriendOpType.Invite);
// }
// }
//}