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.
 
 
 
 
 
 

86 lines
3.3 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 FriendStrangerListDataSyncSvc
{
public static void TickSync(long uid, bool notifyClient)
{
// todo 后期优化性能时可以考虑不在tick时更新stranger, 让玩家可以自由点头像查看对方信息, 这样查看时更新即可
//不在线,
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
if (player == null)
{
//tick里面,所以不打日志
return;
}
if (player.IsOnline == false)
{
//tick里面,所以不打日志
return;
}
//这个是有可能的,db没有加载成功
ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (info.IsNull())
{
return;
}
//stranger 暂时应该没有什么要更新的
for (int i = 0; i < info.FriendOpData.StrangerCount; i++)
{
bool bChg = false;
ref DBFriendStrangerOneStruct strangerId = ref FriendOp.GetFriendStrangerByIndex(ref info, i);
ref DBFriendOneStruct stranger = ref FriendInfoCache.m_cacheStructFriendOne.GetByIndex(strangerId.DBFriendOneID);
if (FriendUtils.IsPlayerBelongThisServer(stranger.oneFriend.Uid))
{
ref FriendCacheInfoStruct strangerInfo = ref FriendOp.GetFriendInfoByUid(stranger.oneFriend.Uid);
if (! strangerInfo.IsNull())
{
bChg = FriendUtils.CheckAndChangeFriendOne(ref stranger, ref strangerInfo);
}
}
else
{
ref RemoteFriendOneStruct strangerInfo = ref FriendOp.GetRemoteFriendOneByUid(stranger.oneFriend.Uid);
if (! strangerInfo.IsNull())
{
bChg = FriendUtils.CheckAndChangeFriendOneByRemoteFriend(ref stranger, ref strangerInfo);
}
}
if (bChg)
{
info.SetNeedSave(true);
TraceLog.Trace("FriendStrangerListDataSyncSvc.TickSync uid {0} friend {1} data in list need udpate, sync to new"
, uid, stranger.oneFriend.Uid);
//if (notifyClient)
//{
// TraceLog.Trace("FriendStrangerListDataSyncSvc.TickSync uid {0} friend {1} data updated, notify client"
// , uid, stranger.oneFriend.Uid);
// FriendNotify.NotifyPlayerFriendStrangerListChg(uid, strangerId);
//}
}
}
}
}
}