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.
 
 
 
 
 
 

69 lines
2.4 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using ProtoCSStruct;
using Google.Protobuf.Collections;
namespace Friend
{
/// <summary>
/// 好友列表里的数据是不是和实际这个玩家的数据一致呢,不一致则需要更新
/// 这个更新比较消耗cpu,所以不要tick的太快,不在线的玩家不处理,反正处理了玩家也看不到
/// </summary>
public static class FriendListDataSyncSvc
{
public static void TickSync(long uid, bool notifyClient)
{
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
if (player == null || ! player.IsOnline)
{
return;
}
//这个是有可能的,db没有加载成功
FriendCacheInfoStruct info = FriendOp.GetFriendInfoByUid(player.UserID);
if (info.IsNull())
{
return;
}
for (int i = 0; i < info.FriendList.iCount; i++)
{
bool bChg = false;
ref DBFriendOneStruct friend = ref FriendOp.GetFriendOneByIndex(ref info, i);
if (FriendUtils.IsPlayerBelongThisServer(friend.oneFriend.Uid))
{
ref FriendCacheInfoStruct newInfo = ref FriendOp.GetFriendInfoByUid(friend.oneFriend.Uid);
if (! newInfo.IsNull())
{
bChg = FriendUtils.CheckAndChangeFriendOne(ref friend, ref newInfo);
}
}
else
{
ref RemoteFriendOneStruct newInfo = ref FriendOp.GetRemoteFriendOneByUid(friend.oneFriend.Uid);
if (! newInfo.IsNull())
{
bChg = FriendUtils.CheckAndChangeFriendOneByRemoteFriend(ref friend, ref newInfo);
}
}
if (bChg)
{
TraceLog.Trace("FriendListDataSyncSvc.TickSync uid {0} friend {1} data chg", uid, friend.oneFriend.Uid);
info.SetNeedSave(true);
if (notifyClient)
{
FriendNotify.NotifyPlayerFriendListChg(player, ref friend);
}
}
}
}
}
}