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.
353 lines
15 KiB
353 lines
15 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.Design;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace Friend
|
|
{
|
|
/// <summary>
|
|
/// 好友相关的发包,通知客户端,通知gameserver等
|
|
/// </summary>
|
|
public static class FriendNotify
|
|
{
|
|
private static CSFriendOpRes m_CSFriendOpRes = new CSFriendOpRes();
|
|
|
|
// op列表发生变化
|
|
private static CSFriendOpListChgNotify m_CSFriendOpListChgNotify = new CSFriendOpListChgNotify();
|
|
|
|
// 好友列表发生变化
|
|
private static CSFriendListChgNotify m_CSFriendListChgNotify = new CSFriendListChgNotify();
|
|
|
|
// DBFriendSelf发生变化时通知其他服务器
|
|
private static SSFriendSelfChgNotify m_SSFriendSelfChgNotify = new SSFriendSelfChgNotify();
|
|
|
|
private static CSFriendSendGiftNotify m_CSFriendSendGiftNotify = new CSFriendSendGiftNotify();
|
|
|
|
private static CSFriendSelfChgNotify m_CSFriendSelfChgNotify = new CSFriendSelfChgNotify();
|
|
|
|
//在线的才通知
|
|
public static void NotifyPlayerFriendSelfChg(ref FriendCacheInfoStruct info)
|
|
{
|
|
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(info.Self.Uid);
|
|
if (player == null || ! player.IsOnline)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_CSFriendSelfChgNotify.Self.CopyFrom(ref info.Self);
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(
|
|
player.WorldServerID, (int)CSGameMsgID.FriendSelfChgNotify, ref m_CSFriendSelfChgNotify, player.UserID);
|
|
}
|
|
|
|
|
|
public static void NotifyPlayerFriendOpListChg(long uid, ref DBFriendOneOpStruct chgOp, ref DBFriendOneStruct friend)
|
|
{
|
|
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null || ! player.IsOnline)
|
|
{
|
|
return;
|
|
}
|
|
|
|
TraceLog.Trace("FriendNotify.NotifyPlayerFriendOpListChg uid {0} opType {1} seq {2} submit {3}"
|
|
, player.UserID, chgOp.OpType, chgOp.OpSeq, friend.oneFriend.Uid);
|
|
|
|
m_CSFriendOpListChgNotify.IsDelete = 0;
|
|
m_CSFriendOpListChgNotify.ChgOp.OpSeq = chgOp.OpSeq;
|
|
m_CSFriendOpListChgNotify.ChgOp.OpType = chgOp.OpType;
|
|
m_CSFriendOpListChgNotify.ChgOp.Friend.CopyFrom(ref friend.oneFriend);
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendOpListChgNotify, ref m_CSFriendOpListChgNotify, player.UserID);
|
|
}
|
|
|
|
public static void NotifyPlayerFriendListChg(PlayerInfoFriend player, ref DBFriendOneStruct friend)
|
|
{
|
|
// 如果出现不在线但是没有登出时间的情况, 打个错误日志查下
|
|
if (friend.oneFriend.IsOnline == false && friend.oneFriend.LastLogoutTime == 0)
|
|
{
|
|
TraceLog.Error("FriendNotify.NotifyPlayerFriendListChg uid {0} online false, logout time 0", friend.oneFriend.Uid);
|
|
}
|
|
|
|
m_CSFriendListChgNotify.Friend.CopyFrom(ref friend.oneFriend);
|
|
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendListChgNotify, ref m_CSFriendListChgNotify, player.UserID);
|
|
}
|
|
|
|
// 转给玩家所在FriendSvr
|
|
public static void NotifyOtherFriendSvrFriendSelfChg(ref DBFriendSelf self)
|
|
{
|
|
m_SSFriendSelfChgNotify.Self.CopyFrom(ref self);
|
|
|
|
uint[] serverIDs = FriendServerUtils.GetApp().GetCluster().GetRemoteAppID((int) ServerType.Friend);
|
|
foreach (uint svrId in serverIDs)
|
|
{
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(svrId, (int)SSGameMsgID.FriendSelfChgNotify, ref m_SSFriendSelfChgNotify, 0);
|
|
}
|
|
}
|
|
|
|
public static void NotifyOtherSvrFriendSendGift(long friendUid, long sendUid, int sendTime)
|
|
{
|
|
m_CSFriendSendGiftNotify.SendUid = sendUid;
|
|
m_CSFriendSendGiftNotify.SendTime = sendTime;
|
|
|
|
FriendServerUtils.GetPacketSender().SendToFriendServer((int)CSGameMsgID.FriendSendGiftNotify,
|
|
ref m_CSFriendSendGiftNotify, friendUid, FriendServerUtils.GetAppID());
|
|
}
|
|
|
|
public static void NotifyPlayerFriendSendGift(long friendUid, long sendUid)
|
|
{
|
|
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(friendUid);
|
|
if (player != null && player.IsOnline)
|
|
{
|
|
m_CSFriendSendGiftNotify.SendUid = sendUid;
|
|
m_CSFriendSendGiftNotify.SendTime = FriendServerUtils.GetTimeSecond();
|
|
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendSendGiftNotify, ref m_CSFriendSendGiftNotify, player.UserID);
|
|
}
|
|
}
|
|
|
|
|
|
public static void NotifySubmitOnFriendOpEnd(long submitUid, int opType, long targetUid, int opFinalRet)
|
|
{
|
|
TraceLog.Trace("FriendNotify.NotifySubmitOnFriendOpEnd submit {0} opType {1} targetUid {2} opFinalRet {3}"
|
|
, submitUid, opType, targetUid, opFinalRet);
|
|
|
|
PlayerInfoFriend submitPlayer = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(submitUid);
|
|
if (submitPlayer == null || ! submitPlayer.IsOnline)
|
|
{
|
|
return;
|
|
}
|
|
|
|
SendSubmitFriendOpRes(submitPlayer, opType, targetUid, opFinalRet);
|
|
|
|
if (opFinalRet == 0)
|
|
{
|
|
if (opType == (int)DBFriendOpType.Invite || opType == (int)DBFriendOpType.AgreeAdd)
|
|
{
|
|
NotifyPlayerAddFriendSucc(submitPlayer, targetUid);
|
|
}
|
|
else if (opType == (int)DBFriendOpType.Delete || opType == (int)DBFriendOpType.AddBlacklist)
|
|
{
|
|
NotifyPlayerDeleteFriendSucc(submitPlayer, targetUid);
|
|
}
|
|
else if (opType == (int) DBFriendOpType.Refuse)
|
|
{
|
|
// 删除对方的申请
|
|
}
|
|
|
|
// 如果有对方的好友申请则删除
|
|
NotifyPlayerDeleteFriendOp(submitPlayer, (int)DBFriendOpType.Invite, targetUid);
|
|
}
|
|
}
|
|
|
|
public static void NotifyTargetOnFriendOpEnd(long submitUid, int opType, long targetUid, int opFinalRet)
|
|
{
|
|
TraceLog.Trace("FriendNotify.NotifyTargetOnFriendOpEnd submit {0} opType {1} targetUid {2} opFinalRet {3}"
|
|
, submitUid, opType, targetUid, opFinalRet);
|
|
|
|
PlayerInfoFriend targetPlayer = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(targetUid);
|
|
if (targetPlayer == null || ! targetPlayer.IsOnline)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (opFinalRet == 0)
|
|
{
|
|
if (opType == (int)DBFriendOpType.Invite || opType == (int)DBFriendOpType.AgreeAdd)
|
|
{
|
|
NotifyPlayerAddFriendSucc(targetPlayer, submitUid);
|
|
|
|
// 如果有对方的好友申请则删除
|
|
NotifyPlayerDeleteFriendOp(targetPlayer, (int)DBFriendOpType.Invite, submitUid);
|
|
}
|
|
else if (opType == (int)DBFriendOpType.Delete || opType == (int)DBFriendOpType.AddBlacklist)
|
|
{
|
|
NotifyPlayerDeleteFriendSucc(targetPlayer, submitUid);
|
|
|
|
// 如果有对方的好友申请则删除
|
|
NotifyPlayerDeleteFriendOp(targetPlayer, (int)DBFriendOpType.Invite, submitUid);
|
|
}
|
|
}
|
|
else if (opFinalRet == (int)CSErrCode.InsertFriendOpList)
|
|
{
|
|
// 通知target收到好友申请
|
|
NotifyPlayerAddFriendOp(targetPlayer, (int)DBFriendOpType.Invite, submitUid);
|
|
}
|
|
}
|
|
|
|
|
|
public static void NotifyPlayerAddFriendSucc(PlayerInfoFriend player, long friendUid)
|
|
{
|
|
DBFriendOneStruct friendOne = FriendOp.GetFriendOneByUid(player.UserID, friendUid);
|
|
if (friendOne.IsNull())
|
|
{
|
|
TraceLog.Error("FriendNotify.NotifyPlayerAddFriendSucc uid {0} not in cache", player.UserID);
|
|
return;
|
|
}
|
|
|
|
m_CSFriendListChgNotify.IsDelete = 0;
|
|
m_CSFriendListChgNotify.Friend.CopyFrom(ref friendOne.oneFriend);
|
|
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendListChgNotify, ref m_CSFriendListChgNotify, player.UserID);
|
|
}
|
|
|
|
|
|
public static void NotifyPlayerDeleteFriendSucc(PlayerInfoFriend player, long friendUid)
|
|
{
|
|
m_CSFriendListChgNotify.Clear();
|
|
m_CSFriendListChgNotify.IsDelete = 1;
|
|
m_CSFriendListChgNotify.Friend.Uid = friendUid;
|
|
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendListChgNotify, ref m_CSFriendListChgNotify, player.UserID);
|
|
}
|
|
|
|
public static void NotifyPlayerAddFriendOp(PlayerInfoFriend player, int opType, long submitUid)
|
|
{
|
|
ref DBFriendOneOpStruct addOp = ref FriendOp.GetFriendOpByUid(player.UserID, submitUid, opType);
|
|
if (addOp.IsNull())
|
|
{
|
|
TraceLog.Error("FriendNotify.NotifyPlayerAddFriendOp submit {0} opType {1} no Op in target {2} list"
|
|
, submitUid, opType, player.UserID);
|
|
return;
|
|
}
|
|
|
|
m_CSFriendOpListChgNotify.IsDelete = 0;
|
|
m_CSFriendOpListChgNotify.ChgOp.OpType = addOp.OpType;
|
|
m_CSFriendOpListChgNotify.ChgOp.OpSeq = addOp.OpSeq;
|
|
|
|
if (FriendUtils.IsPlayerBelongThisServer(submitUid))
|
|
{
|
|
ref FriendCacheInfoStruct submitInfo = ref FriendOp.GetFriendInfoByUid(submitUid);
|
|
if (submitInfo.IsNull())
|
|
{
|
|
TraceLog.Error("FriendNotify.NotifyPlayerAddFriendOp submit {0} not in cache", submitUid);
|
|
return;
|
|
}
|
|
|
|
FriendUtils.CopySelfToFriendOne(ref submitInfo.Self, ref m_CSFriendOpListChgNotify.ChgOp.Friend);
|
|
}
|
|
else
|
|
{
|
|
ref RemoteFriendOneStruct submitInfo = ref FriendOp.GetRemoteFriendOneByUid(submitUid);
|
|
if (submitInfo.IsNull())
|
|
{
|
|
TraceLog.Error("FriendNotify.NotifyPlayerAddFriendOp submit {0} not in remote cache", submitUid);
|
|
return;
|
|
}
|
|
|
|
FriendUtils.CopyRemoteFriendToDBFriend(ref submitInfo, ref m_CSFriendOpListChgNotify.ChgOp.Friend);
|
|
}
|
|
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendOpListChgNotify, ref m_CSFriendOpListChgNotify, player.UserID);
|
|
}
|
|
|
|
public static void NotifyPlayerDeleteFriendOp(long uid, int opType, long friendUid)
|
|
{
|
|
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null || ! player.IsOnline)
|
|
{
|
|
return;
|
|
}
|
|
|
|
NotifyPlayerDeleteFriendOp(player, opType, friendUid);
|
|
}
|
|
|
|
public static void NotifyPlayerDeleteFriendOp(PlayerInfoFriend player, int opType, long friendUid)
|
|
{
|
|
m_CSFriendOpListChgNotify.Clear();
|
|
m_CSFriendOpListChgNotify.IsDelete = 1;
|
|
m_CSFriendOpListChgNotify.ChgOp.OpType = opType;
|
|
m_CSFriendOpListChgNotify.ChgOp.Friend.Uid = friendUid;
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendOpListChgNotify, ref m_CSFriendOpListChgNotify, player.UserID);
|
|
}
|
|
|
|
public static void SendSubmitFriendOpRes(long submitUid, int opType, long targetUid, int opFinalRet)
|
|
{
|
|
PlayerInfoFriend submitPlayer = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(submitUid);
|
|
if (submitPlayer == null || !submitPlayer.IsOnline)
|
|
{
|
|
return;
|
|
}
|
|
|
|
SendSubmitFriendOpRes(submitPlayer, opType, targetUid, opFinalRet);
|
|
}
|
|
|
|
public static void SendSubmitFriendOpRes(PlayerInfoFriend player, int opType, long targetUid, int opFinalRet)
|
|
{
|
|
m_CSFriendOpRes.TargetUid = targetUid;
|
|
m_CSFriendOpRes.OpType = opType;
|
|
m_CSFriendOpRes.Ret = opFinalRet;
|
|
m_CSFriendOpRes.OpSeq = 0;
|
|
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID,
|
|
(int)CSGameMsgID.FriendOpRes, ref m_CSFriendOpRes, player.UserID);
|
|
}
|
|
|
|
public static void NotifyPlayerFriendStrangerListChg(long uid, DBFriendStrangerOneStruct stranger)
|
|
{
|
|
//不通知客户端,改成客户端点开的时候查询,这个客户端不需要实时知道变化
|
|
#if false
|
|
//不在线
|
|
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Debug("FriendNotify.NotifyPlayerFriendStrangerListChg can not find player uid {0}", uid);
|
|
return;
|
|
}
|
|
|
|
if (player.IsOnline == false)
|
|
{
|
|
TraceLog.Debug("FriendNotify.NotifyPlayerFriendStrangerListChg player uid {0} not online", uid);
|
|
return;
|
|
}
|
|
|
|
|
|
TraceLog.Trace("FriendNotify.NotifyPlayerFriendStrangerListChg uid {0} stranger {1}"
|
|
, player.UserID, stranger.Data.Uid);
|
|
|
|
CSFriendStrangerListChgNotify notify = new CSFriendStrangerListChgNotify();
|
|
notify.Stranger = stranger;
|
|
|
|
WorldServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendStrangerListChgNotify, notify, player.UserID);
|
|
#endif
|
|
}
|
|
|
|
public static void NotifyPlayerFriendStrangerListDelete(long uid, long strangerUid)
|
|
{
|
|
//不通知客户端,改成客户端点开的时候查询,这个客户端不需要实时知道变化
|
|
#if false
|
|
|
|
//不在线
|
|
PlayerInfoWorld player = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Debug("FriendNotify.NotifyPlayerFriendStrangerListDelete can not find player uid {0}", uid);
|
|
return;
|
|
}
|
|
|
|
if (player.IsOnline == false)
|
|
{
|
|
TraceLog.Debug("FriendNotify.NotifyPlayerFriendStrangerListDelete player uid {0} not online", uid);
|
|
return;
|
|
}
|
|
|
|
|
|
TraceLog.Trace("FriendNotify.NotifyPlayerFriendStrangerListDelete uid {0} strangerUid {1}"
|
|
, player.UserID, strangerUid);
|
|
|
|
CSFriendStrangerListDeleteNotify notify = new CSFriendStrangerListDeleteNotify();
|
|
notify.StrangerUid = strangerUid;
|
|
|
|
WorldServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendStrangerListDeleteNotify, notify, player.UserID);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|