using System; using System.Collections.Generic; using Sog; using ProtoCSStruct; namespace Friend { /// /// 好友邀请,同意,拒绝,删除等op处理,客户端发起的请求 /// public static partial class FriendOpSvc { private static SSFriendOpRes m_SSFriendOpRes = new SSFriendOpRes(); private static SSFriendOpFinalResult m_SSFriendOpFinalResult = new SSFriendOpFinalResult(); public static void OnCliFriendOpReq(uint remoteAppID, StructPacket packet) { ref CSFriendOpReq req = ref packet.GetMessage(); long uid = packet.ObjectID; TraceLog.Trace("FriendOpSvc.OnCliFriendOpReq submit {0} op {1} target {2}", uid, req.OpType, req.TargetUid); // Login成功后, world通知friendSvr时创建player PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid); if (player == null) { TraceLog.Error("FriendOpSvc.OnCliFriendOpReq can not find player uid {0}", uid); return; } // 登录后自动拉取friendInfo, 操作时不存在暂时不处理 ref FriendCacheInfoStruct submitInfo = ref FriendOp.GetFriendInfoByUid(player.UserID); if (submitInfo.IsNull()) { TraceLog.Error("FriendOpSvc.OnCliFriendOpReq uid {0} no FriendCacheInfo", player.UserID); return; } // 特殊处理一键拒绝所有请求 if (req.OpType == (int)DBFriendOpType.Refuse && req.TargetUid == 0) { RefuseAllInvite(player, ref submitInfo); return; } int ret = CheckFriendOp(ref submitInfo, req.OpType, req.TargetUid); if (ret != 0) { TraceLog.Trace("FriendOpSvc.OnCliFriendOpReq invalid friendOp, submit {0} op {1} target {2}" , uid, req.OpType, req.TargetUid); FriendNotify.SendSubmitFriendOpRes(player, req.OpType, req.TargetUid, ret); return; } //只影响自身的op if(req.OpType == (int) DBFriendOpType.DelBlacklist || (req.OpType == (int)DBFriendOpType.AddBlacklist && !FriendOp.IsFriend(ref submitInfo, req.TargetUid))) { int opRet = ProcessSubmitFriendCacheByOp(ref submitInfo, req.OpType, req.TargetUid); FriendNotify.NotifySubmitOnFriendOpEnd(uid, req.OpType, req.TargetUid, opRet); return; } if (FriendUtils.IsPlayerBelongThisServer(req.TargetUid)) { ref FriendCacheInfoStruct targetInfo = ref FriendOp.GetFriendInfoByUid(req.TargetUid); if (targetInfo.IsNull()) { TraceLog.Trace("FriendOpSvc.OnCliFriendOpReq no target {0} FriendCacheInfo", req.TargetUid); FriendCacheSvc.SendDBQueryFriendInfoCacheOnFriendOp(uid, req.OpType, req.TargetUid, QueryFriendInfoCacheReason.QueryByCliOp); return; } // 先处理target数据, 再处理submit数据 int opRet = ProcessTargetFriendCacheByOp(ref targetInfo, req.OpType, uid, player.realmId); if (opRet == 0) { opRet = ProcessSubmitFriendCacheByOp(ref submitInfo, req.OpType, req.TargetUid); if (opRet != 0) { RevertTargetCacheOnFriendOpFail(ref targetInfo, req.OpType, uid); } } else { DeleteSubmitInviteListOnTargetOpFail(ref submitInfo, req.OpType, req.TargetUid, opRet); } FriendNotify.NotifySubmitOnFriendOpEnd(uid, req.OpType, req.TargetUid, opRet); FriendNotify.NotifyTargetOnFriendOpEnd(uid, req.OpType, req.TargetUid, opRet); } else { // target不属于当前svr时, 向target svr发起请求 FriendCacheSvc.m_SSFriendOpReq.Clear(); FriendCacheSvc.m_SSFriendOpReq.OpType = req.OpType; FriendCacheSvc.m_SSFriendOpReq.TargetUid = req.TargetUid; FriendUtils.CopySelfToFriendOne(ref submitInfo.Self, ref FriendCacheSvc.m_SSFriendOpReq.SubmitInfo); FriendServerUtils.GetPacketSender().SendToFriendServer((int) SSGameMsgID.FriendOpReq, ref FriendCacheSvc.m_SSFriendOpReq, req.TargetUid); } } public static unsafe void RefuseAllInvite(PlayerInfoFriend player, ref FriendCacheInfoStruct selfInfo) { for (int i = selfInfo.FriendOpData.OpCount - 1; i >= 0; i--) { long posIndex = selfInfo.FriendOpData.OpList[i]; ref DBFriendOneOpStruct oneOp = ref FriendInfoCache.m_cacheStructFriendOneOp.GetByIndex(posIndex); if (oneOp.IsNull()) { continue; } if (oneOp.OpType == (int)DBFriendOpType.Invite) { TraceLog.Trace("FriendOpSvc.RefuseAllInvite submit {0} posIndex {1}", oneOp.FriendUid, posIndex); FriendOp.DoFreeFriendOPByIndex(posIndex); selfInfo.FriendOpData.OpList[i] = selfInfo.FriendOpData.OpList[selfInfo.FriendOpData.OpCount - 1]; selfInfo.FriendOpData.OpList[selfInfo.FriendOpData.OpCount - 1] = 0; selfInfo.FriendOpData.OpCount--; selfInfo.SetNeedSave(true); FriendNotify.NotifyPlayerDeleteFriendOp(player, (int)DBFriendOpType.Invite, oneOp.FriendUid); } } FriendNotify.SendSubmitFriendOpRes(player, (int)DBFriendOpType.Refuse, 0, 0); } public static int CheckFriendOp(ref FriendCacheInfoStruct submitInfo, int opType, long targetUid) { if (opType <= (int) DBFriendOpType.None || opType >= (int)DBFriendOpType.Max) { return -1; } if (submitInfo.Self.Uid == targetUid) { return -1; } // 操作目标是机器人 if (targetUid < 100000) { // 如果是邀请消息, 则返回请求成功 if (opType == (int)DBFriendOpType.Invite) { return (int) CSErrCode.InsertFriendOpList; } return -1; } if(opType == (int) DBFriendOpType.Invite || opType == (int)DBFriendOpType.AgreeAdd) { if(submitInfo.Self.BlackList.Contains(targetUid)) { TraceLog.Trace("FriendOpSvc.CheckFriendOp submit {0} targetUid {1}, in self blacklist", submitInfo.Self.Uid, targetUid); return (int)CSErrCode.InSelfBlacklist; } } if (opType == (int)DBFriendOpType.Invite) { if (FriendSvc.IsFriendListFull(ref submitInfo)) { TraceLog.Trace("FriendOpSvc.CheckFriendOp submit {0} friend list is full", submitInfo.Self.Uid); return (int) CSErrCode.SelfFriendListIsFull; } } else if (opType == (int) DBFriendOpType.AgreeAdd) { // 检查自己是否收到对方的invite ref var inviteOp = ref FriendOp.GetFriendOpByUid(submitInfo.Self.Uid, targetUid, (int)DBFriendOpType.Invite); if (inviteOp.IsNull()) { TraceLog.Trace("FriendOpSvc.CheckFriendOp submit {0} not recv target {1} invite op", submitInfo.Self.Uid, targetUid); return -1; } } else if(opType == (int)DBFriendOpType.AddBlacklist) { if(submitInfo.Self.BlackList.Contains(targetUid)) { TraceLog.Trace("FriendOpSvc.CheckFriendOp in the self blacklist submit {0} targetUid {1} ", submitInfo.Self.Uid, targetUid); return (int)CSErrCode.InSelfBlacklist; } if(submitInfo.Self.BlackList.Count >= FriendConfig.GetMaxBlacklistCount()) { return (int)CSErrCode.MaxLimitSys; } } else if(opType == (int)DBFriendOpType.DelBlacklist) { if (!submitInfo.Self.BlackList.Contains(targetUid)) { TraceLog.Trace("FriendOpSvc.CheckFriendOp not in the self blacklist submit {0} targetUid {1} ", submitInfo.Self.Uid, targetUid); return (int)CSErrCode.NotBlacklist; } } return 0; } public static void OnCliQueryFriendOpReq(uint remoteAppID, StructPacket packet) { long uid = packet.ObjectID; PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid); if (player == null) { TraceLog.Error("FriendOpSvc.OnCliQueryFriendOpReq can not find player uid {0}", uid); return; } ref CSQueryFriendOpRes res = ref CSStructPool.Instance.GetObjRef(); // 正常, 可能是还没收到world转来的QueryRoleRes消息 if (player.IsOnline == false) { TraceLog.Trace("FriendOpSvc.OnCliQueryFriendOpReq player uid {0} not online", player.UserID); res.Ret = (int) CSErrCode.TryGetFriendOpLater; FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int) CSGameMsgID.QueryFriendOpRes, ref res, player.UserID); return; } // 正常, 可能正处在从DB拉取数据的过程中 ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(player.UserID); if (info.IsNull()) { TraceLog.Trace("FriendOpSvc.OnCliQueryFriendOpReq can not find FriendCacheInfo uid {0}", player.UserID); res.Ret = (int) CSErrCode.TryGetFriendOpLater; FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int) CSGameMsgID.QueryFriendOpRes, ref res, player.UserID); return; } FriendOp.GetOpDataFromFriendCacheInfo(info.Self.Uid, ref res.OpData, false); FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.QueryFriendOpRes,ref res, player.UserID); } // 双方在同一个服务器时, 双方数据都load到内存后处理好友操作 public static void DoFriendOpOnBothDataLoad(ref SSQueryFriendInfoCacheRes res) { ref FriendOpReq op = ref res.OpCallback; // submit操作必须login PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(op.SubmitUid); if (player == null) { TraceLog.Error("FriendOpSvc.DoFriendOpOnBothDataLoad submit {0} no player obj", op.SubmitUid); return; } // target在数据库不存在 if (res.Self.Uid == 0) { TraceLog.Trace("FriendOpSvc.DoFriendOpOnBothDataLoad target {0} {1} not in DB", res.Uid, op.TargetUid); FriendNotify.NotifySubmitOnFriendOpEnd(op.SubmitUid, op.OpType, op.TargetUid, -1); return; } // 调用这个接口必须双方在同一个服务器, 并且数据都load到内存里了 ref FriendCacheInfoStruct submitInfo = ref FriendOp.GetFriendInfoByUid(player.UserID); if (submitInfo.IsNull()) { TraceLog.Error("FriendOpSvc.DoFriendOpOnBothDataLoad submit {0} no FriendCacheInfo" , player.UserID); return; } ref FriendCacheInfoStruct targetInfo = ref FriendOp.GetFriendInfoByUid(op.TargetUid); if (targetInfo.IsNull()) { TraceLog.Error("FriendOpSvc.DoFriendOpOnBothDataLoad target {0} no FriendCacheInfo" , op.TargetUid); return; } // 先处理target数据, 再处理请求方数据 int opRet = ProcessTargetFriendCacheByOp(ref targetInfo, op.OpType, submitInfo.Self.Uid, submitInfo.Self.RealmId); if (opRet == 0) { opRet = ProcessSubmitFriendCacheByOp(ref submitInfo, op.OpType, op.TargetUid); if (opRet != 0) { RevertTargetCacheOnFriendOpFail(ref targetInfo, op.OpType, submitInfo.Self.Uid); } } else { DeleteSubmitInviteListOnTargetOpFail(ref submitInfo, op.OpType, op.TargetUid, opRet); } FriendNotify.NotifySubmitOnFriendOpEnd(op.SubmitUid, op.OpType, op.TargetUid, opRet); FriendNotify.NotifyTargetOnFriendOpEnd(op.SubmitUid, op.OpType, op.TargetUid, opRet); } // 双方不同服时, 收到其他friendsvr发来的好友操作请求, 把target数据从DB读取到内存后处理好友操作 public static void DoFriendOpTargetSideFirst(ref SSQueryFriendInfoCacheRes res) { ref FriendOpReq op = ref res.OpCallback; m_SSFriendOpRes.Clear(); m_SSFriendOpRes.SubmitUid = op.SubmitUid; m_SSFriendOpRes.OpType = op.OpType; m_SSFriendOpRes.OpResult = -1; // 被操作的好友在数据库不存在 if (res.Self.Uid == 0) { TraceLog.Trace("FriendOpSvc.DoFriendOpTargetSideFirst target {0} {1} not in DB", res.Uid, op.TargetUid); FriendServerUtils.GetPacketSender().SendToFriendServer((int)SSGameMsgID.FriendOpRes, ref m_SSFriendOpRes, op.SubmitUid); return; } // 发起操作的玩家和target不同服, 数据在Remote里面 ref RemoteFriendOneStruct submitInfo = ref FriendOp.GetRemoteFriendOneByUid(op.SubmitUid); if (submitInfo.IsNull()) { TraceLog.Error("FriendOpSvc.DoFriendOpTargetSideFirst submit {0} not in RemoteFriendCache", op.SubmitUid); return; } ref FriendCacheInfoStruct targetInfo = ref FriendOp.GetFriendInfoByUid(op.TargetUid); if (targetInfo.IsNull()) { TraceLog.Error("FriendOpSvc.DoFriendOpTargetSideFirst target {0} no FriendCacheInfo", op.TargetUid); return; } FriendUtils.CopySelfToFriendOne(ref targetInfo.Self, ref m_SSFriendOpRes.TargetInfo); // 先处理target数据, 然后转发到submit的服务器去处理 int ret = ProcessTargetFriendCacheByOp(ref targetInfo, op.OpType, op.SubmitUid, submitInfo.RealmId); m_SSFriendOpRes.OpResult = ret; FriendServerUtils.GetPacketSender().SendToFriendServer((int)SSGameMsgID.FriendOpRes, ref m_SSFriendOpRes, op.SubmitUid); // 插入申请列表成功时直接通知, submit服务器不会发SSFriendOpFinalResult通知 if (ret == (int)CSErrCode.InsertFriendOpList) { FriendNotify.NotifyTargetOnFriendOpEnd(op.SubmitUid, (int)DBFriendOpType.Invite, op.TargetUid, ret); } } // 收到其他friendsvr发来的好友操作请求 public static void OnFriendOpReqFromOtherFriendSvr(uint remoteAppID, StructPacket packet) { ref SSFriendOpReq req = ref packet.GetMessage(); long submitUid = req.SubmitInfo.Uid; TraceLog.Trace("FriendOpSvc.OnFriendOpReqFromOtherFriendSvr submit {0} opType {1} target {2}" , req.SubmitInfo.Uid, req.OpType, req.TargetUid); if (! FriendUtils.IsPlayerBelongThisServer(req.TargetUid)) { TraceLog.Error("FriendOpSvc.OnFriendOpReqFromOtherFriendSvr target {0} not belong this svr", req.TargetUid); return; } if (req.SubmitInfo.Uid > 0) { FriendOp.AddOrUpdateRemoteFriendOne(ref req.SubmitInfo, ref req.SubmitMainlineHeros); } ref FriendCacheInfoStruct targetInfo = ref FriendOp.GetFriendInfoByUid(req.TargetUid); if (targetInfo.IsNull()) { TraceLog.Trace("FriendOpSvc.OnFriendOpReqFromOtherFriendSvr target {0} not in cache", req.TargetUid); FriendCacheSvc.SendDBQueryFriendInfoCacheOnFriendOp(submitUid, req.OpType, req.TargetUid, QueryFriendInfoCacheReason.QueryBySsOp); return; } var res = new SSFriendOpRes { OpType = req.OpType, SubmitUid = submitUid}; FriendUtils.CopySelfToFriendOne(ref targetInfo.Self, ref res.TargetInfo); res.OpResult = ProcessTargetFriendCacheByOp(ref targetInfo, req.OpType, submitUid, req.SubmitInfo.RealmId); FriendServerUtils.GetPacketSender().SendToFriendServer((int)SSGameMsgID.FriendOpRes, ref res, res.SubmitUid); // 插入申请列表成功时直接通知, submit服务器不会发SSFriendOpFinalResult通知 if (res.OpResult == (int)CSErrCode.InsertFriendOpList) { FriendNotify.NotifyTargetOnFriendOpEnd(submitUid, (int)DBFriendOpType.Invite, req.TargetUid, res.OpResult); } } // 双方不同服时, 收到其他friendsvr好友操作回复, 收到该消息说明target的数据已经处理完了 public static void OnFriendOpResFromOtherFriendSvr(uint remoteAppID, StructPacket packet) { ref SSFriendOpRes res = ref packet.GetMessage(); var targetUid = res.TargetInfo.Uid; TraceLog.Trace("FriendOpSvc.OnFriendOpResFromOtherFriendSvr submit {0} opType {1} target {2}" , res.SubmitUid, res.OpType, targetUid); if (targetUid == 0) { return; } // 本服玩家不应该向其他服请求信息 if (FriendUtils.IsPlayerBelongThisServer(targetUid)) { TraceLog.Error("FriendOpSvc.OnFriendOpResFromOtherFriendSvr error, target {0} belong this svr", targetUid); return; } FriendOp.AddOrUpdateRemoteFriendOne(ref res.TargetInfo, ref res.TargetMainlineHeros); // 发起FriendOp请求时必然是submit数据准备好了, 此时找不到说明有bug, 也不用向DB请求了, 否则没完没了 ref FriendCacheInfoStruct submitInfo = ref FriendOp.GetFriendInfoByUid(res.SubmitUid); if (submitInfo.IsNull()) { TraceLog.Error("FriendOpSvc.OnFriendOpResFromOtherFriendSvr submit {0} not in cache", res.SubmitUid); return; } // target数据处理有问题, 通知submit if (res.OpResult != 0) { DeleteSubmitInviteListOnTargetOpFail(ref submitInfo, res.OpType, targetUid, res.OpResult); FriendNotify.SendSubmitFriendOpRes(res.SubmitUid, res.OpType, targetUid, res.OpResult); return; } // 通知玩家操作结果 int ret = ProcessSubmitFriendCacheByOp(ref submitInfo, res.OpType, targetUid); TraceLog.Trace("FriendOpSvc.OnFriendOpResFromOtherFriendSvr submit {0} opType {1} target {2} ret {3}" , res.SubmitUid, res.OpType, targetUid, ret); FriendNotify.NotifySubmitOnFriendOpEnd(res.SubmitUid, res.OpType, targetUid, ret); // 同时把submit处理结果通知target服务器 m_SSFriendOpFinalResult.Clear(); m_SSFriendOpFinalResult.OpType = res.OpType; m_SSFriendOpFinalResult.SubmitterUid = res.SubmitUid; m_SSFriendOpFinalResult.TargetUid = targetUid; m_SSFriendOpFinalResult.FinalResult = ret; FriendServerUtils.GetPacketSender().SendToFriendServer( (int)SSGameMsgID.FriendOpFinalResult, ref m_SSFriendOpFinalResult, targetUid); } // target cache 处理失败时, 处理submit cache private static void DeleteSubmitInviteListOnTargetOpFail(ref FriendCacheInfoStruct submitCache, int opType, long targetUid, int opFinalRet) { // 同意好友申请时, 如果是target的原因导致的失败, 则从Op列表中将target的申请删除 if (opType == (int)DBFriendOpType.AgreeAdd) { FriendOp.DoDeleteFriendOp(ref submitCache, targetUid, (int)DBFriendOpType.Invite); FriendNotify.NotifyPlayerDeleteFriendOp(submitCache.Self.Uid, opType, targetUid); } } // 收到submit所在friendsvr发来的好友操作最终结果 public static void OnFriendOpFinalResultFromOtherFriendSvr(uint remoteAppID, StructPacket packet) { ref SSFriendOpFinalResult opRet = ref packet.GetMessage(); TraceLog.Trace("FriendOpSvc.OnFriendOpFinalResultFromOtherFriendSvr submit {0} opType {1} target {2} ret {3}", opRet.SubmitterUid, opRet.OpType, opRet.TargetUid, opRet.FinalResult); // 本服玩家不应该收到其他服发来的信息 if (FriendUtils.IsPlayerBelongThisServer(opRet.SubmitterUid)) { TraceLog.Error("FriendOpSvc.OnFriendOpFinalResultFromOtherFriendSvr error, submit {0} belong this svr", opRet.SubmitterUid); return; } if (opRet.FinalResult != 0) { ref FriendCacheInfoStruct targetInfo = ref FriendOp.GetFriendInfoByUid(opRet.TargetUid); if (targetInfo.IsNull()) { TraceLog.Error("FriendOpSvc.OnFriendOpFinalResultFromOtherFriendSvr target {0} not in cache on friendOp fail", opRet.TargetUid); return; } RevertTargetCacheOnFriendOpFail(ref targetInfo, opRet.OpType, opRet.SubmitterUid); } FriendNotify.NotifyTargetOnFriendOpEnd(opRet.SubmitterUid, opRet.OpType, opRet.TargetUid, opRet.FinalResult); } public static int ProcessTargetFriendCacheByOp(ref FriendCacheInfoStruct targetInfo, int opType, long submitUid, int submitRealm) { long targetUid = targetInfo.Self.Uid; // target不该由当前服务器处理 if (! FriendUtils.IsPlayerBelongThisServer(targetUid)) { TraceLog.Error("FriendOpSvc.ProcessTargetFriendCacheByOp target {0} not belong this svr {1}", targetUid); return -1; } int ret = -1; if (opType == (int) DBFriendOpType.Invite) { ret = ProcessFriendCacheBeInvite(ref targetInfo, submitUid, submitRealm); } else if (opType == (int)DBFriendOpType.Delete) { ret = ProcessFriendCacheBeDelete(ref targetInfo, submitUid); } else if (opType == (int) DBFriendOpType.AgreeAdd) { ret = ProcessFriendCacheWaitAgree(ref targetInfo, submitUid, submitRealm); } else if (opType == (int) DBFriendOpType.Refuse) { ret = 0; // 拒绝邀请时, target do nothing } else if(opType == (int)DBFriendOpType.AddBlacklist) //好友将自身添加到黑名单,自己要删除该好友 { ret = ProcessFriendCacheBeDelete(ref targetInfo, submitUid); } TraceLog.Trace("FriendOpSvc.ProcessTargetFriendCacheByOp submit {0} op {1} target {2} ret {3}" , submitUid, (DBFriendOpType)opType, targetUid, ret); return ret; } // 处理发起请求的玩家cache, 只有在target的好友操作成功后才调用 public static int ProcessSubmitFriendCacheByOp(ref FriendCacheInfoStruct submitCache, int opType, long targetUid) { long submitUid = submitCache.Self.Uid; if (! FriendUtils.IsPlayerBelongThisServer(submitUid)) { TraceLog.Error("FriendOpSvc.ProcessSubmitFriendCacheByOp submit {0} not belong this svr", submitUid); return -1; } int ret = -1; if (opType == (int)DBFriendOpType.Invite) { ret = ProcessFriendCacheSubmitInvite(ref submitCache, targetUid); } else if (opType == (int)DBFriendOpType.Delete) { ret = ProcessFriendCacheSubmitDelete(ref submitCache, targetUid); } else if (opType == (int)DBFriendOpType.AgreeAdd) { ret = ProcessFriendCacheSubmitAgree(ref submitCache, targetUid); } else if (opType == (int) DBFriendOpType.Refuse) { ret = ProcessFriendCacheSubmitRefuse(ref submitCache, targetUid); } else if(opType == (int)DBFriendOpType.AddBlacklist) { ret = ProcessFriendCacheSubmitAddBlacklist(ref submitCache, targetUid); } else if (opType == (int)DBFriendOpType.DelBlacklist) { ret = ProcessFriendCacheSubmitDelBlacklist(ref submitCache, targetUid); } TraceLog.Trace("FriendOpSvc.ProcessSubmitFriendCacheByOp submit {0} op {1} target {2} ret {3}" , submitUid, (DBFriendOpType) opType, targetUid, ret); return ret; } // 发起人数据操作失败时, 尝试恢复target的数据 public static void RevertTargetCacheOnFriendOpFail(ref FriendCacheInfoStruct targetInfo, int opType, long submitUid) { long targetUid = targetInfo.Self.Uid; if (opType == (int)DBFriendOpType.Invite) { // 从好友列表删除, 注意不恢复好友申请op, 玩家再发起一次就好了 FriendOp.DoDeleteFriendList(ref targetInfo, submitUid); } else if (opType == (int)DBFriendOpType.Delete) { // 好友删除不会失败 } else if (opType == (int)DBFriendOpType.AgreeAdd) { // 从好友列表删除, 注意不恢复好友申请op, 玩家再发起一次就好了 FriendOp.DoDeleteFriendList(ref targetInfo, submitUid); } TraceLog.Trace("FriendOpSvc.RevertTargetCacheOnFriendOpFail target {0} op {1} submit {2}" , targetUid, (DBFriendOpType)opType, submitUid); } // 处理发起好友邀请的玩家cache public static int ProcessFriendCacheSubmitInvite(ref FriendCacheInfoStruct submitInfo, long targetUid) { long submitUid = submitInfo.Self.Uid; // 申请者的好友列表已满 if (FriendSvc.IsFriendListFull(ref submitInfo)) { TraceLog.Error("ProcessFriendCacheSubmitInvite submit {0} target {1}, submit friend list is full" , submitUid, targetUid); return (int) CSErrCode.SelfFriendListIsFull; } if(submitInfo.Self.BlackList.Contains(targetUid))//在自身的黑名单,按理说之前应该已经过滤了 { TraceLog.Error("ProcessFriendCacheSubmitInvite submit {0} target {1}, submit in blacklist" , submitUid, targetUid); return (int)CSErrCode.InSelfBlacklist; } int ret = FriendOp.DoAddFriendOneToMySelf(ref submitInfo, targetUid, true); TraceLog.Trace("ProcessFriendCacheSubmitInvite submit {0} target {1} ret {2}", submitUid, targetUid, ret); return ret; } // 处理被邀请对象的cache public static int ProcessFriendCacheBeInvite(ref FriendCacheInfoStruct targetInfo, long submitUid, int submitRealm) { var targetUid = targetInfo.Self.Uid; TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} target {1}", submitUid, targetUid); //不是同一个逻辑world if (!FriendServerUtils.CheckIsSameLogicWorld(targetInfo.Self.RealmId, submitRealm)) { TraceLog.Error("ProcessFriendCacheBeInvite submit {0} {1} target {2} {3} NotSameLogicWorld " , targetInfo.Self.Uid, targetInfo.Self.RealmId, submitUid, submitRealm); return (int)CSErrCode.NotSameLogicWorld; } // 玩家设置了不允许添加好友 if (targetInfo.Self.RefuseAll == 1) { TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} target {1} RefuseAll", submitUid, targetUid); return (int)CSErrCode.RefuseAllFriend; } // 已经是对方好友 if (FriendOp.IsAlreadyBeenFriend(ref targetInfo, submitUid) == 1) { TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} target {1}", submitUid, targetUid); return 0; } // 好友列表已满 if (FriendSvc.IsFriendListFull(ref targetInfo)) { TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} target {1}, target friend list is full" , submitUid, targetUid); return (int)CSErrCode.TargetFriendListIsFull; } int ret = 0; // 允许自动添加好友 if (targetInfo.Self.AutoAccept == 1) { ret = FriendOp.DoAddFriendOneToMySelf(ref targetInfo, submitUid, false); TraceLog.Trace("ProcessFriendCacheBeInvite target {0} auto accept submit {1} ret {2}" , targetUid, submitUid, ret); return ret; } if(targetInfo.Self.BlackList.Contains(submitUid)) //在黑名单 { TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} target {1}, in target blacklist" , submitUid, targetUid); return (int)CSErrCode.InTargetBlacklist; } // 好友op列表已经存在 if (FriendOp.AlreadyExistOp(ref targetInfo, submitUid, DBFriendOpType.Invite)) { TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} invite target {1}, op already exist" , submitUid, targetUid); return (int)CSErrCode.InsertFriendOpList; } // 好友Op列表满了 if (FriendSvc.IsFriendOpListFull(ref targetInfo)) { TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} invite target {1}, target oplist is full" , submitUid, targetUid); return (int)CSErrCode.FriendOpListIsFull; } ret = FriendOp.DoAddNewFriendOpToMySelf(ref targetInfo, submitUid, (int) DBFriendOpType.Invite); TraceLog.Trace("ProcessFriendCacheBeInvite submit {0} invite target {1} insert op list ret {2} op count {3}" , submitUid, targetUid, ret, targetInfo.FriendOpData.OpCount); return ret == 0 ? (int) CSErrCode.InsertFriendOpList : -1; } // 处理提交删除请求的玩家, 删除操作不会失败 public static int ProcessFriendCacheSubmitDelete(ref FriendCacheInfoStruct submitInfo, long targetUid) { TraceLog.Trace("ProcessFriendCacheSubmitDelete submit {0} delete target {1}", submitInfo.Self.Uid, targetUid); //如果op列表里有对方发过来的邀请请求,那么删除之 FriendOp.DoDeleteFriendOp(ref submitInfo, targetUid, (int)DBFriendOpType.Invite); FriendOp.DoDeleteFriendList(ref submitInfo, targetUid); return 0; } // 处理被删除对象 public static int ProcessFriendCacheBeDelete(ref FriendCacheInfoStruct targetInfo, long submitUid) { TraceLog.Trace("ProcessFriendCacheBeDelete target {0} delete submit {1}", targetInfo.Self.Uid, submitUid); //如果op列表里有对方发过来的邀请请求,那么删除之 FriendOp.DoDeleteFriendOp(ref targetInfo, submitUid, (int)DBFriendOpType.Invite); FriendOp.DoDeleteFriendList(ref targetInfo, submitUid); return 0; } // 同意对方的好友申请 public static int ProcessFriendCacheSubmitAgree(ref FriendCacheInfoStruct submitInfo, long targetUid) { if (submitInfo.Self.BlackList.Contains(targetUid))//在自身的黑名单,按理说之前应该已经过滤了,防止异步调用这里也过滤下 { TraceLog.Error("ProcessFriendCacheSubmitInvite submit {0} target {1}, targetUid in blacklist" , submitInfo.Self.Uid, targetUid); return (int)CSErrCode.InSelfBlacklist; } int ret = FriendOp.DoAddFriendOneToMySelf(ref submitInfo, targetUid, true); TraceLog.Trace("ProcessFriendCacheSubmitAgree submit {0} target {1} ret {2}" , submitInfo.Self.Uid, targetUid, ret); return ret; } // 等待好友申请被同意的玩家, 就是当初发起invite的submit public static int ProcessFriendCacheWaitAgree(ref FriendCacheInfoStruct targetInfo, long submitUid, int submitRealm) { //不是同一个逻辑world if(!FriendServerUtils.CheckIsSameLogicWorld(targetInfo.Self.RealmId, submitRealm)) { TraceLog.Error("ProcessFriendCacheWaitAgree submit {0} {1} target {2} {3} NotSameLogicWorld " , targetInfo.Self.Uid, targetInfo.Self.RealmId, submitUid, submitRealm); return (int)CSErrCode.NotSameLogicWorld; } if (targetInfo.Self.BlackList.Contains(submitUid)) //在黑名单 { TraceLog.Trace("ProcessFriendCacheWaitAgree submit {0} target {1}, in target blacklist" , submitUid, targetInfo.Self.Uid); return (int)CSErrCode.InTargetBlacklist; } int ret = FriendOp.DoAddFriendOneToMySelf(ref targetInfo, submitUid, false); TraceLog.Trace("ProcessFriendCacheWaitAgree target {0} submit {1} ret {2}" , targetInfo.Self.Uid, submitUid, ret); return ret; } // 拒绝对方的好友申请 public static int ProcessFriendCacheSubmitRefuse(ref FriendCacheInfoStruct submitInfo, long targetUid) { TraceLog.Trace("ProcessFriendCacheSubmitRefuse submit {0} target {1}", submitInfo.Self.Uid, targetUid); FriendOp.DoDeleteFriendOp(ref submitInfo, targetUid, (int)DBFriendOpType.Invite); return 0; } // 处理提交黑名单请求的玩家 public static int ProcessFriendCacheSubmitAddBlacklist(ref FriendCacheInfoStruct submitInfo, long targetUid) { TraceLog.Trace("ProcessFriendCacheSubmitAddBlacklist submit {0} target {1}", submitInfo.Self.Uid, targetUid); FriendOp.DoAddBlackList(ref submitInfo, targetUid); ProcessFriendCacheSubmitDelete(ref submitInfo, targetUid); return 0; } public static int ProcessFriendCacheSubmitDelBlacklist(ref FriendCacheInfoStruct submitInfo, long targetUid) { TraceLog.Trace("ProcessFriendCacheSubmitDelBlacklist submit {0} target {1}", submitInfo.Self.Uid, targetUid); return FriendOp.DoDelBlackList(ref submitInfo, targetUid); } } }