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.
477 lines
17 KiB
477 lines
17 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace Friend
|
|
{
|
|
public static class FriendUtils
|
|
{
|
|
/// <summary>
|
|
/// 更新整个self数据到friendOne,包括所有数据
|
|
/// 类似的操作都调用这个
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="friendOne"></param>
|
|
public static void CopySelfToFriendOne(ref DBFriendSelf self, ref DBFriendOne friendOne)
|
|
{
|
|
friendOne.Uid = self.Uid;
|
|
friendOne.Icon = self.Icon;
|
|
friendOne.Nick = self.Nick;
|
|
friendOne.Level = self.Level;
|
|
friendOne.LastLoginTime = self.LastLoginTime;
|
|
friendOne.VipExp = self.VipExp;
|
|
friendOne.VipLevel = self.VipLevel;
|
|
friendOne.Chip = self.Chip;
|
|
friendOne.Gender = self.Gender;
|
|
friendOne.MaxPassMainlandId = self.MaxPassMainlandId;
|
|
friendOne.MainlineFightPower = self.MainlineFightPower;
|
|
friendOne.RealmName = self.RealmName;
|
|
friendOne.IsOnline = self.IsOnline;
|
|
friendOne.LastLogoutTime = (int)self.LastLogoutTime;
|
|
friendOne.IconFrameId = self.IconFrameId;
|
|
friendOne.RealmId = self.RealmId;
|
|
}
|
|
|
|
public static void CopySelfToRemoteFriend(ref DBFriendSelf self, ref RemoteFriendOneStruct remoteFriend)
|
|
{
|
|
remoteFriend.Uid = self.Uid;
|
|
remoteFriend.Icon = self.Icon;
|
|
remoteFriend.Nick = self.Nick;
|
|
remoteFriend.Level = self.Level;
|
|
remoteFriend.LastLoginTime = self.LastLoginTime;
|
|
remoteFriend.VipExp = self.VipExp;
|
|
remoteFriend.VipLevel = self.VipLevel;
|
|
remoteFriend.Chip = self.Chip;
|
|
remoteFriend.Gender = self.Gender;
|
|
remoteFriend.MaxPassMainlandId = self.MaxPassMainlandId;
|
|
remoteFriend.MainlineFightPower = self.MainlineFightPower;
|
|
remoteFriend.RealmName = self.RealmName;
|
|
remoteFriend.MainlineHeros = self.MainlineHeros;
|
|
remoteFriend.IsOnline = self.IsOnline;
|
|
remoteFriend.LastLogoutTime = (int)self.LastLogoutTime;
|
|
remoteFriend.IconFrameId = self.IconFrameId;
|
|
remoteFriend.RealmId = self.RealmId;
|
|
|
|
remoteFriend.LastAccessTime = FriendServerUtils.GetTimeSecond();
|
|
}
|
|
|
|
public static void CopyDBFriendToRemoteFriend(ref DBFriendOne dbFriend, ref RepeatedDBFriendHeroOne_8 heroList,
|
|
ref RemoteFriendOneStruct remoteFriend)
|
|
{
|
|
remoteFriend.Uid = dbFriend.Uid;
|
|
remoteFriend.Icon = dbFriend.Icon;
|
|
remoteFriend.Nick = dbFriend.Nick;
|
|
remoteFriend.Level = dbFriend.Level;
|
|
remoteFriend.LastLoginTime = dbFriend.LastLoginTime;
|
|
remoteFriend.VipExp = dbFriend.VipExp;
|
|
remoteFriend.VipLevel = dbFriend.VipLevel;
|
|
remoteFriend.Chip = dbFriend.Chip;
|
|
remoteFriend.Gender = dbFriend.Gender;
|
|
remoteFriend.MaxPassMainlandId = dbFriend.MaxPassMainlandId;
|
|
remoteFriend.MainlineFightPower = dbFriend.MainlineFightPower;
|
|
remoteFriend.RealmName = dbFriend.RealmName;
|
|
remoteFriend.MainlineHeros = heroList;
|
|
remoteFriend.IsOnline = dbFriend.IsOnline;
|
|
remoteFriend.LastLogoutTime = dbFriend.LastLogoutTime;
|
|
remoteFriend.IconFrameId = dbFriend.IconFrameId;
|
|
remoteFriend.RealmId = dbFriend.RealmId;
|
|
|
|
remoteFriend.LastAccessTime = FriendServerUtils.GetTimeSecond();
|
|
}
|
|
|
|
public static void CopyRemoteFriendToDBFriend(ref RemoteFriendOneStruct remoteFriend, ref DBFriendOne dbFriend)
|
|
{
|
|
dbFriend.Uid = remoteFriend.Uid;
|
|
dbFriend.Icon = remoteFriend.Icon;
|
|
dbFriend.Nick = remoteFriend.Nick;
|
|
dbFriend.Level = remoteFriend.Level;
|
|
dbFriend.LastLoginTime = remoteFriend.LastLoginTime;
|
|
dbFriend.VipExp = remoteFriend.VipExp;
|
|
dbFriend.VipLevel = remoteFriend.VipLevel;
|
|
dbFriend.Chip = remoteFriend.Chip;
|
|
dbFriend.Gender = remoteFriend.Gender;
|
|
dbFriend.MaxPassMainlandId = remoteFriend.MaxPassMainlandId;
|
|
dbFriend.MainlineFightPower = remoteFriend.MainlineFightPower;
|
|
dbFriend.RealmName = remoteFriend.RealmName;
|
|
dbFriend.IsOnline = remoteFriend.IsOnline;
|
|
dbFriend.LastLogoutTime = remoteFriend.LastLogoutTime;
|
|
dbFriend.IconFrameId = remoteFriend.IconFrameId;
|
|
dbFriend.RealmId = remoteFriend.RealmId;
|
|
|
|
remoteFriend.LastAccessTime = FriendServerUtils.GetTimeSecond();
|
|
}
|
|
|
|
public static void CopyDBFriendChatToCSChat(ref DBFriendChatOne friendChat, ref CSChatRes chatRes)
|
|
{
|
|
chatRes.Uid = friendChat.SenderUid;
|
|
chatRes.Nick = friendChat.SenderNick;
|
|
chatRes.Icon = friendChat.SenderIcon;
|
|
chatRes.Gender = friendChat.SenderGender;
|
|
chatRes.Message = friendChat.Message;
|
|
chatRes.SendTime = friendChat.SendTime;
|
|
chatRes.ChatSeq = friendChat.ChatSeq;
|
|
chatRes.TargetUid = friendChat.TargetUid;
|
|
chatRes.IconFrameId = friendChat.IconFrameId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 比较self和玩家身上rolebase信息,如果不同则更新
|
|
/// </summary>
|
|
/// <param name="player"></param>
|
|
/// <param name="self"></param>
|
|
/// <param name="roleBase"></param>
|
|
/// <returns></returns>
|
|
public static bool CheckAndChangeSelfByPlayer(PlayerInfoFriend player, ref DBFriendSelf self, ref DBRoleBase roleBase)
|
|
{
|
|
bool bChg = false;
|
|
|
|
if (self.Level != roleBase.Level)
|
|
{
|
|
self.Level = roleBase.Level;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.Nick.Equals(roleBase.Nick.GetPtr()) == false)
|
|
{
|
|
self.Nick.SetString(roleBase.Nick.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.Icon.Equals(roleBase.Icon.GetPtr()) == false)
|
|
{
|
|
|
|
self.Icon.SetString(roleBase.Icon.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.VipExp != roleBase.VipExp)
|
|
{
|
|
self.VipExp = roleBase.VipExp;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.VipLevel != roleBase.VipLevel)
|
|
{
|
|
self.VipLevel = roleBase.VipLevel;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.Chip != roleBase.Chip)
|
|
{
|
|
self.Chip = roleBase.Chip;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.Diamond != roleBase.Diamond)
|
|
{
|
|
self.Diamond = roleBase.Diamond;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.MaxPassMainlandId != player.mainlinePassId)
|
|
{
|
|
self.MaxPassMainlandId = player.mainlinePassId;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.MainlineFightPower != player.mainlineFightPower)
|
|
{
|
|
self.MainlineFightPower = player.mainlineFightPower;
|
|
bChg = true;
|
|
}
|
|
|
|
// 现在客户端显示的阵容数据是world下发的, 没用FriendSvr
|
|
// gamesvr计算好之后发到friendsvr保存在PlayerInfoFriend, tick时更新到DBFriendSelf
|
|
//for (int i = 0; i < self.MainlineHeros.Count && i < player.MainlineHeros.Count; i++)
|
|
//{
|
|
// if (self.MainlineHeros[i].DescId != player.MainlineHeros[i].DescId
|
|
// || self.MainlineHeros[i].Power != player.MainlineHeros[i].Power)
|
|
// {
|
|
// self.MainlineHeros[i] = player.MainlineHeros[i];
|
|
// bChg = true;
|
|
// }
|
|
//}
|
|
|
|
if (self.IsOnline != player.IsOnline)
|
|
{
|
|
self.IsOnline = player.IsOnline;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.LastLoginTime != player.LoginTime)
|
|
{
|
|
self.LastLoginTime = player.LoginTime;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.LastLogoutTime != player.LogoutTime)
|
|
{
|
|
self.LastLogoutTime = player.LogoutTime;
|
|
bChg = true;
|
|
}
|
|
|
|
if (self.IconFrameId != player.iconFrameId)
|
|
{
|
|
self.IconFrameId = player.iconFrameId;
|
|
bChg = true;
|
|
}
|
|
|
|
return bChg;
|
|
}
|
|
|
|
public static bool CheckAndChangeSelfByRoleData(PlayerInfoFriend player, ref DBFriendSelf self, ref DBRoleBase roleBase, ref SSSaveRoleNotify saveRoleNotify)
|
|
{
|
|
bool bChg = CheckAndChangeSelfByPlayer(player, ref self, ref roleBase);
|
|
|
|
if (self.HideMyInfo != saveRoleNotify.HideMyInfo)
|
|
{
|
|
self.HideMyInfo = saveRoleNotify.HideMyInfo;
|
|
bChg = true;
|
|
}
|
|
|
|
return bChg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 比较self和friendOne的数据,如果不同则更新friendOne
|
|
/// </summary>
|
|
/// <param name="friendOne"></param>
|
|
/// <param name="self"></param>
|
|
/// <returns></returns>
|
|
public static bool CheckAndChangeFriendOneByRemoteFriend(ref DBFriendOneStruct friendOne, ref RemoteFriendOneStruct remoteFriend)
|
|
{
|
|
bool bChg = false;
|
|
|
|
if (friendOne.oneFriend.Level != remoteFriend.Level)
|
|
{
|
|
friendOne.oneFriend.Level = remoteFriend.Level;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.Nick.Equals(remoteFriend.Nick.GetPtr()) == false)
|
|
{
|
|
friendOne.oneFriend.Nick.SetString(remoteFriend.Nick.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.Icon.Equals(remoteFriend.Icon.GetPtr()) == false)
|
|
{
|
|
friendOne.oneFriend.Icon.SetString(remoteFriend.Icon.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
|
|
if (friendOne.oneFriend.VipExp != remoteFriend.VipExp)
|
|
{
|
|
friendOne.oneFriend.VipExp = remoteFriend.VipExp;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.VipLevel != remoteFriend.VipLevel)
|
|
{
|
|
friendOne.oneFriend.VipLevel = remoteFriend.VipLevel;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.MaxPassMainlandId != remoteFriend.MaxPassMainlandId)
|
|
{
|
|
friendOne.oneFriend.MaxPassMainlandId = remoteFriend.MaxPassMainlandId;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.MainlineFightPower != remoteFriend.MainlineFightPower)
|
|
{
|
|
friendOne.oneFriend.MainlineFightPower = remoteFriend.MainlineFightPower;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.IsOnline != remoteFriend.IsOnline)
|
|
{
|
|
friendOne.oneFriend.IsOnline = remoteFriend.IsOnline;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.LastLoginTime != remoteFriend.LastLoginTime)
|
|
{
|
|
friendOne.oneFriend.LastLoginTime = remoteFriend.LastLoginTime;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.LastLogoutTime != remoteFriend.LastLogoutTime)
|
|
{
|
|
friendOne.oneFriend.LastLogoutTime = remoteFriend.LastLogoutTime;
|
|
bChg = true;
|
|
}
|
|
|
|
|
|
if (friendOne.oneFriend.IconFrameId != remoteFriend.IconFrameId)
|
|
{
|
|
friendOne.oneFriend.IconFrameId = remoteFriend.IconFrameId;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.RealmId != remoteFriend.RealmId)
|
|
{
|
|
friendOne.oneFriend.RealmId = remoteFriend.RealmId;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.RealmName.Equals(remoteFriend.RealmName.GetPtr()) == false)
|
|
{
|
|
friendOne.oneFriend.RealmName.SetString(remoteFriend.RealmName.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
return bChg;
|
|
}
|
|
|
|
public static bool CheckAndChangeFriendOne(ref DBFriendOneStruct friendOne, ref FriendCacheInfoStruct selfInfo)
|
|
{
|
|
ref DBFriendSelf self = ref selfInfo.Self;
|
|
bool bChg = false;
|
|
|
|
if (friendOne.oneFriend.Level != self.Level)
|
|
{
|
|
friendOne.oneFriend.Level = self.Level;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.Nick.Equals(self.Nick.GetPtr()) == false)
|
|
{
|
|
friendOne.oneFriend.Nick.SetString(self.Nick.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.Icon.Equals(self.Icon.GetPtr()) == false)
|
|
{
|
|
friendOne.oneFriend.Icon.SetString(self.Icon.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.VipExp != self.VipExp)
|
|
{
|
|
friendOne.oneFriend.VipExp = self.VipExp;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.VipLevel != self.VipLevel)
|
|
{
|
|
friendOne.oneFriend.VipLevel = self.VipLevel;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.IsOnline != self.IsOnline)
|
|
{
|
|
friendOne.oneFriend.IsOnline = self.IsOnline;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.LastLoginTime != self.LastLoginTime)
|
|
{
|
|
friendOne.oneFriend.LastLoginTime = self.LastLoginTime;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.LastLogoutTime != (int)self.LastLogoutTime)
|
|
{
|
|
friendOne.oneFriend.LastLogoutTime = (int)self.LastLogoutTime;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.MaxPassMainlandId != self.MaxPassMainlandId)
|
|
{
|
|
friendOne.oneFriend.MaxPassMainlandId = self.MaxPassMainlandId;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.MainlineFightPower != self.MainlineFightPower)
|
|
{
|
|
friendOne.oneFriend.MainlineFightPower = self.MainlineFightPower;
|
|
bChg = true;
|
|
}
|
|
|
|
|
|
|
|
if (friendOne.oneFriend.IconFrameId != self.IconFrameId)
|
|
{
|
|
friendOne.oneFriend.IconFrameId = self.IconFrameId;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.RealmId != self.RealmId)
|
|
{
|
|
friendOne.oneFriend.RealmId = self.RealmId;
|
|
bChg = true;
|
|
}
|
|
|
|
if (friendOne.oneFriend.RealmName.Equals(self.RealmName.GetPtr()) == false)
|
|
{
|
|
friendOne.oneFriend.RealmName.SetString(self.RealmName.GetPtr());
|
|
bChg = true;
|
|
}
|
|
|
|
return bChg;
|
|
}
|
|
|
|
//2周内登录过的算活跃好友
|
|
public static int GetActivityFriendCount(ref FriendCacheInfoStruct info)
|
|
{
|
|
int count = 0;
|
|
|
|
//这周开始时间
|
|
long nowSecond = FriendServerUtils.GetTimeSecond();
|
|
long todayStartTime = AppTime.GetTodayStartTime(nowSecond);
|
|
long weekStartTime = AppTime.GetThisWeekStartTime1(nowSecond);
|
|
|
|
//改成30天
|
|
long activityTimeBegin = todayStartTime - 30 * AppTime.SECONDS_ADAY;
|
|
|
|
//遍历自己的所有好友
|
|
for (int i=0;i<info.FriendList.iCount;i++)
|
|
{
|
|
DBFriendOneStruct friend = FriendOp.GetFriendOneByIndex(ref info, i);
|
|
if(friend.oneFriend.FriendType == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (friend.oneFriend.LastLoginTime >= activityTimeBegin)
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
public static void MakeQueryOtherDetailBySelf(ref CSQueryOtherDetailRes res, ref DBFriendSelf self)
|
|
{
|
|
res.TargetUid = self.Uid;
|
|
res.Nick = self.Nick;
|
|
res.Level = self.Level;
|
|
res.Icon = self.Icon;
|
|
res.VipLevel = self.VipLevel;
|
|
res.Exp = self.Exp;
|
|
res.Chip = self.Chip;
|
|
res.Diamond = self.Diamond;
|
|
res.IconFrameId = self.IconFrameId;
|
|
res.HideInfo = self.HideMyInfo;
|
|
}
|
|
|
|
// 玩家是否属于当前这个服务器
|
|
public static bool IsPlayerBelongThisServer(long uid)
|
|
{
|
|
uint friendInstId = (uint)(uid % FriendSvrIDUtils.friendSvrNum);
|
|
if (friendInstId == 0)
|
|
{
|
|
friendInstId = (uint) FriendSvrIDUtils.friendSvrNum;
|
|
}
|
|
|
|
return friendInstId == Sog.ServerIDUtils.GetInstanceID(FriendServerUtils.GetAppID());
|
|
}
|
|
}
|
|
}
|
|
|