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.
 
 
 
 
 
 

1071 lines
46 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using ProtoCSStruct;
namespace Friend
{
public static class FriendSvc
{
private static SSQueryFriendListRes m_QueryFriendListRes = new SSQueryFriendListRes();
public static void OnQueryFriendListReq(uint remoteAppID, StructPacket packet)
{
ref SSQueryFriendListReq req = ref packet.GetMessage<SSQueryFriendListReq>();
long uid = req.Uid;
m_QueryFriendListRes.Clear();
m_QueryFriendListRes.Uid = uid;
TraceLog.Trace("FriendSvc.OnQueryFriendListReq uid {0}", uid);
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
if (player == null)
{
TraceLog.Trace("FriendSvc.OnQueryFriendListReq uid {0} no player obj", uid);
return;
}
// 不是本服请求不处理, gamesvr发错了, 找找发送错误的原因
if (! FriendUtils.IsPlayerBelongThisServer(player.UserID))
{
TraceLog.Trace("FriendSvc.OnQueryFriendListReq uid {0} no belong this svr", uid);
return;
}
ref var selfInfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (selfInfo.IsNull())
{
uint dbServerID = FriendSvrIDUtils.GetDBServerID(player);
FriendServerUtils.GetPacketSender().SendToServerByID<SSQueryFriendListReq>(dbServerID, packet);
}
else
{
OnQueryPlayerFriendListDBSuccess(player);
}
}
public static void OnQueryFriendListRes(uint remoteAppID, StructPacket packet)
{
ref SSQueryFriendListRes res =ref packet.GetMessage<SSQueryFriendListRes>();
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(res.Uid);
if (player == null)
{
TraceLog.Trace("FriendSvc.OnQueryFriendListRes can not find player obj {0}", res.Uid);
return;
}
//数据库没有,表示是第一次,需要保存一下数据库,这样其他人就可以从数据库查询到这个人的信息
if (res.Self.Uid == 0)
{
InitNewPlayerFriend(player);
SaveNewPlayerFriendStructToDB(player);
}
else
{
FriendOp.AddFriendCacheInfoStruct(ref res.Self, ref res.List, ref res.OpData);
}
//检查friendlist中one是否存在,不存在则从数据库查询加入
//ref FriendCacheInfoStruct infoStruct = ref FriendOp.GetFriendInfoByUid(player.UserID);
//if (infoStruct.IsNull())
//{
//TraceLog.Error("FriendSvc.OnQueryFriendListRes can not find player uid {0} friendInfo from cache"
//, player.UserID);
//return;
//}
//处理一下好友列表和陌生人列表的同步
//FriendStrangerSvc.TickDeleteStrangerIfInFriendList(player.UserID, false);
OnQueryPlayerFriendListDBSuccess(player);
}
private static void OnQueryPlayerFriendListDBSuccess(PlayerInfoFriend player)
{
TraceLog.Trace("FriendSvc.OnQueryPlayerFriendListDBSuccess uid {0} get data from cache", player.UserID);
ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (info.IsNull())
{
TraceLog.Error("FriendSvc.OnQueryPlayerFriendListDBSuccess can not find player uid {0} friendInfo from cache"
, player.UserID);
return;
}
//现在已经没有了排行,之后删除
/*
foreach (var friend in info.FriendList.AllFriends)
{
foreach (var rank in friend.AllRank)
{
if (rank.PositionListLastWeek.Count > 0)
{
rank.PositionListLastWeek.Clear();
info.MakeDirty();
}
}
}
*/
// login成功
if (player.roleBase.Uid != 0)
{
FriendBillLogUtils.LogFriendList(player.UserID, player.accountInfo.AccountID.GetString(),
info.FriendList.iCount, AppTime.GetDayElapse(FriendServerUtils.GetTimeSecond(), player.roleBase.CreateTime));
}
//查询sns好友(现在是QQ和微信,但这个还要讨论,)
if (player.accountInfo.AccountType == (int)AccountType.AccountType_Facebook)
{
FriendSnsSvc.SendAccountQuerySnsFriendList(player); //没有发送请求
}
else
{
FriendSnsSvc.OnAccountSnsFriendQueryFinish(player);
}
}
public static void InitNewPlayerFriend(PlayerInfoFriend player)
{
DBFriendSelf self = new DBFriendSelf();
self.Uid = player.UserID;
self.Nick = player.roleBase.Nick;
self.Level = player.roleBase.Level;
self.IconFrameId = player.iconFrameId;
self.IsOnline = true; // init new肯定是首次上线时
self.LastLoginTime = player.roleBase.LastLoginTime;
self.Icon.SetString(player.accountInfo.AccountType == 0
? player.roleBase.Icon.ToString()
: player.accountInfo.AccountID.ToString());
self.RealmId = player.realmId;
var realm = FriendServerUtils.GetRealmBriefInfo(player.realmId);
if (realm != null)
{
self.RealmName.SetString(realm.realmName);
}
DBFriendList FriendList = new DBFriendList();
DBFriendOpData FriendOpData = new DBFriendOpData();
FriendOp.AddFriendCacheInfoStruct(ref self, ref FriendList, ref FriendOpData);
}
/// <summary>
/// 判断整个好友拉取过程是否完成,可以给gameserver回应了
/// </summary>
public static unsafe void CheckPlayerFriendDataSynFromDBFinishAckGame(long fromUid)
{
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(fromUid);
if (player == null)
{
TraceLog.Error("FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame uid {0} no player", fromUid);
return;
}
if (player.roleBase.Uid == 0)
{
TraceLog.Error("FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame uid {0} rolebase is null", fromUid);
return;
}
ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (info.IsNull())
{
TraceLog.Error("FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame uid {0} no friendCacheInfo", player.UserID);
return;
}
//遍历所有好友列表,从cache里更新最新数据,如果cache里没有,需要去数据库里查
for (int i = 0; i < info.FriendList.iCount; i++)
{
ref DBFriendOneStruct listOne = ref FriendOp.GetFriendOneByIndex(ref info, i);
if (listOne.IsNull())
{
TraceLog.Error("FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame uid {0} friend idx {1} is null"
, player.UserID, i);
return;
}
if (FriendUtils.IsPlayerBelongThisServer(listOne.oneFriend.Uid))
{
ref FriendCacheInfoStruct friendInfo = ref FriendOp.GetFriendInfoByUid(listOne.oneFriend.Uid);
if (friendInfo.IsNull())
{
TraceLog.Trace("FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame self uid {0} friend uid {1} not in cache, wait db ack..."
, info.Self.Uid, listOne.oneFriend.Uid);
return;
}
}
else
{
ref RemoteFriendOneStruct friendInfo = ref FriendOp.GetRemoteFriendOneByUid(listOne.oneFriend.Uid);
if (friendInfo.IsNull())
{
TraceLog.Trace("FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame self uid {0} friend uid {1} not in cache, wait other friendsvr ack..."
, info.Self.Uid, listOne.oneFriend.Uid);
return;
}
}
}
//遍历所有好友列表, 从cache里更新最新数据, 到这里数据应该全部有了
for (int i = 0; i < info.FriendList.iCount; i++)
{
ref DBFriendOneStruct listOne = ref FriendOp.GetFriendOneByIndex(ref info, i);
// 当前服务器管理的玩家从FriendCacheInfoStruct中取数据更新FriendList, 否则从RemoteFriend缓存中取数据更新
// 把我的friend在cache中的最新self信息更新到我的friendList的friendOne中
if (FriendUtils.IsPlayerBelongThisServer(listOne.oneFriend.Uid))
{
ref FriendCacheInfoStruct friendInfo = ref FriendOp.GetFriendInfoByUid(listOne.oneFriend.Uid);
if (! friendInfo.IsNull())
{
FriendUtils.CopySelfToFriendOne(ref friendInfo.Self, ref listOne.oneFriend);
}
}
else
{
ref RemoteFriendOneStruct friendInfo = ref FriendOp.GetRemoteFriendOneByUid(listOne.oneFriend.Uid);
if (! friendInfo.IsNull())
{
FriendUtils.CopyRemoteFriendToDBFriend(ref friendInfo, ref listOne.oneFriend);
}
}
}
// 更新好友礼物数据
UpdateFriendGiftData(ref info);
info.SetNeedSave(true);
//表示全部查询完毕,返回给game服务器
SSQueryFriendListRes res = new SSQueryFriendListRes {Uid = info.Self.Uid};
FriendOp.TransFriendCacheInfoStruct(ref info, ref res.Self, ref res.List, ref res.OpData);
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)SSGameMsgID.QueryFriendListRes,ref res, res.Uid);
}
/// <summary>
/// 判断整个黑名单拉取是否完成,可以给gameserver回应了
/// </summary>
public static unsafe void CheckPlayerBlacklistSynFromDBFinishAckGame(long fromUid)
{
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(fromUid);
if (player == null)
{
TraceLog.Error("FriendSvc.CheckPlayerBlacklistSynFromDBFinishAckGame uid {0} no player", fromUid);
return;
}
if (player.roleBase.Uid == 0)
{
TraceLog.Error("FriendSvc.CheckPlayerBlacklistSynFromDBFinishAckGame uid {0} rolebase is null", fromUid);
return;
}
ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (info.IsNull())
{
TraceLog.Error("FriendSvc.CheckPlayerBlacklistSynFromDBFinishAckGame uid {0} no friendCacheInfo", player.UserID);
return;
}
//遍历黑名单
ref var blacklist = ref info.Self.BlackList;
for (int i = 0; i < blacklist.Count; i++)
{
if (FriendUtils.IsPlayerBelongThisServer(blacklist[i]))
{
ref FriendCacheInfoStruct friendInfo = ref FriendOp.GetFriendInfoByUid(blacklist[i]);
if (friendInfo.IsNull())
{
TraceLog.Trace("FriendSvc.CheckPlayerBlacklistSynFromDBFinishAckGame self uid {0} friend uid {1} not in cache, wait db ack..."
, player.UserID, blacklist[i]);
return;
}
}
else
{
ref RemoteFriendOneStruct friendInfo = ref FriendOp.GetRemoteFriendOneByUid(blacklist[i]);
if (friendInfo.IsNull())
{
TraceLog.Trace("FriendSvc.CheckPlayerBlacklistSynFromDBFinishAckGame self uid {0} friend uid {1} not in cache, wait other friendsvr ack..."
, player.UserID, blacklist[i]);
return;
}
}
}
//表示全部查询完毕,返回给game服务器
SSQueryBlacklistRes res = new SSQueryBlacklistRes { Uid = player.UserID };
//拷贝黑名单,这时候应该有全部数据
FriendOp.FillBlacklistInfo(ref info, ref res);
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)SSGameMsgID.QueryBlacklistRes, ref res, res.Uid);
}
//没有用到,先注释掉(这个是处理sns好友的)
//public static void SyncMeInMyFriendListButNotInHisList(FriendCacheInfo cacheInfoFriend, long myUid)
//{
// FriendCacheInfoStruct mycacheInfo = FriendOp.GetFriendInfoByUid(myUid);
// if (mycacheInfo.IsNull())
// {
// TraceLog.Debug("SyncMeInMyFriendListButNotInHisList my uid {0} not in cache", myUid);
// return;
// }
// if (FriendSvc.CanAddNewToFriendList(cacheInfoFriend.Self.Uid, myUid) == false)
// {
// TraceLog.Trace("FriendSvc.SyncMeInMyFriendListButNotInHisList player uid {0} my uid CanAddNewToFriendList false"
// , cacheInfoFriend.Self.Uid, myUid);
// return;
// }
// TraceLog.Trace("FriendSvc.SyncMeInMyFriendListButNotInHisList player uid {0} notify world add one friend uid {1}"
// , cacheInfoFriend.Self.Uid, myUid);
// DBFriendOneStruct newOne = new DBFriendOneStruct();
// FriendOp.UpdateSelfInfoTOFriendOne(mycacheInfo.Self, newOne);
// FriendOp.DoAddFriendOneToMySelf(cacheInfoFriend.Self.Uid, newOne.Uid);
// PlayerInfoFriend friendPlayer = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(cacheInfoFriend.Self.Uid);
// if (friendPlayer == null)
// {
// TraceLog.Debug("FriendSvc.SyncMeInMyFriendListButNotInHisList can not find player uid {0}"
// , cacheInfoFriend.Self.Uid);
// return;
// }
// if (friendPlayer.WorldServerID == 0)
// {
// TraceLog.Debug("FriendSvc.SyncMeInMyFriendListButNotInHisList player uid {0} not online"
// , cacheInfoFriend.Self.Uid);
// return;
// }
// FriendNotify.NotifyPlayerFriendListChg(friendPlayer.UserID, newOne.Uid);
//}
public static void SaveNewPlayerFriendStructToDB(PlayerInfoFriend player)
{
ref FriendCacheInfoStruct infoStruct = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (infoStruct.IsNull())
{
return;
}
FriendCacheSvc.SendDBSaveFriendListReq(ref infoStruct, true);
}
public static void OnSaveFriendListRes(uint remoteAppID, StructPacket packet)
{
ref SSSaveFriendListRes res =ref packet.GetMessage<SSSaveFriendListRes>();
if (res.NewInsert)
{
return;
}
ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(res.Uid);
if (info.IsNull())
{
TraceLog.Error("FriendSvc.OnSaveFriendListRes uid {0} no data in friend cache!", res.Uid);
return;
}
info.NeedSave = false;
//保存完成后,重新计算下线时间
info.LastAccessTime = FriendServerUtils.GetTimeSecond();
info.GetDataSeqSave().SavedSuccessSeq = res.DataSeq;
TraceLog.Trace("FriendSvc.OnSaveFriendListRes uid {0} save db success SavedSuccessSeq {1}"
, res.Uid, res.DataSeq);
}
// 优先级高的信息同步可以直接调用该接口
// 优先级不高建议等Tick时SaveFriendList后广播给其他FriendSvr
public static void OnFriendSelfChgBroadcastToOtherSvr(ref FriendCacheInfoStruct info)
{
// 我的数据发生变化时, 通知其他好友服务器
// 跟我同服好友在Tick时根据FriendInfoCache中的缓存更新他的好友列表中我的信息
// 跟我不同服的好友在Tick时根据RemoteFriendInfo缓存更新他的好友列表中我的信息
FriendNotify.NotifyOtherFriendSvrFriendSelfChg(ref info.Self);
}
private static void UpdateFriendGiftData(ref FriendCacheInfoStruct friendinfo)
{
// 重置好友礼物数据
var nowSec = FriendServerUtils.GetTimeSecond();
ref DBFriendSelf self = ref friendinfo.Self;
// 首次
if (self.LastResetGiftDataTime == 0)
{
self.LastResetGiftDataTime = (int) nowSec;
return;
}
if (! AppTime.IsSameDay(nowSec, self.LastResetGiftDataTime))
{
TraceLog.Debug("FriendSvc.UpdateFriendGiftData uid {0} reset friend gift data", self.Uid);
self.TodaySelfSendGift = 0;
self.TodaySelfRecvGift = 0;
self.LastResetGiftDataTime = (int) nowSec;
// 现有好友赠送的礼物全部清零
for (int i = 0; i < friendinfo.FriendList.iCount; i++)
{
ref var friendOne = ref FriendOp.GetFriendOneByIndex(ref friendinfo, i);
friendOne.oneFriend.RecvGiftNum = 0;
}
friendinfo.Self.TodaySendGiftUid.Clear();
friendinfo.SetNeedSave(true);
}
}
public static void OnFriendGiftOpReq(uint remoteAppID, StructPacket packet)
{
ref CSFriendGiftOpReq req = ref packet.GetMessage<CSFriendGiftOpReq>();
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendSvc.OnFriendGiftOpReq uid {0} no player", packet.ObjectID);
return;
}
ref FriendCacheInfoStruct selfInfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (selfInfo.IsNull())
{
TraceLog.Error("FriendSvc.OnFriendGiftOpReq uid {0} no friendInfo cache", player.UserID);
return;
}
UpdateFriendGiftData(ref selfInfo);
var res = new CSFriendGiftOpRes
{
Ret = -1,
OpType = req.OpType,
TodaySelfSendGift = selfInfo.Self.TodaySelfSendGift,
TodaySelfRecvGift = selfInfo.Self.TodaySelfRecvGift,
LastResetGiftDataTime = selfInfo.Self.LastResetGiftDataTime,
GiftData = {Uid = req.FriendUid}
};
//在我的好友列表里面找下看看是不是我的好友
ref DBFriendOneStruct friendOne = ref FriendOp.GetFriendOneByUid(selfInfo.Self.Uid, req.FriendUid);
if (friendOne.IsNull())
{
res.Ret = (int) CSErrCode.NotFriend;
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftOpRes, ref res, player.UserID);
return;
}
// 先填上一次的时间, 操作结束时会刷新成本次时间, 保证数据都能同步给客户端
res.GiftData.LastSendGiftTime = friendOne.oneFriend.LastSendGiftTime;
res.GiftData.LastGetGiftTime = friendOne.oneFriend.LastGetGiftTime;
res.GiftData.RecvGiftNum = friendOne.oneFriend.RecvGiftNum;
long nowSecond = FriendServerUtils.GetTimeSecond();
ref DBFriendSelf friendSelf = ref selfInfo.Self;
// 赠送
if (req.OpType == 1)
{
var commDesc = 0; // CommParamDescMgr.Instance.GetConfig((int)CommParamKey.SendFriendGiftDailyLimit);
int sendLimit = 0;
// 超过每日上限
if (friendSelf.TodaySelfSendGift >= sendLimit
|| friendSelf.TodaySelfSendGift >= friendSelf.TodaySendGiftUid.GetMaxCount())
{
TraceLog.Trace("FriendHandler.OnFriendGiftOpReq uid {0} send num {1} to limit maxcount {2}"
, player.UserID, friendSelf.TodaySelfSendGift, sendLimit);
res.Ret = (int)CSErrCode.SendLimit;
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftOpRes, ref res, player.UserID);
return;
}
// 今日已经赠送过了
if (AppTime.IsSameDay(nowSecond, friendOne.oneFriend.LastSendGiftTime)
|| friendSelf.TodaySendGiftUid.Contains(req.FriendUid))
{
res.Ret = (int)CSErrCode.AlreadySendGift;
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftOpRes, ref res, player.UserID);
return;
}
TraceLog.Trace("FriendSvc.OnFriendGiftOpReq uid {0} friend {1} send gift succ", player.UserID, req.FriendUid);
friendSelf.TodaySelfSendGift++;
friendSelf.TodaySendGiftUid.Add(req.FriendUid);
friendOne.oneFriend.LastSendGiftTime = (int)nowSecond;
selfInfo.SetNeedSave(true);
res.Ret = 0;
res.GiftData.LastSendGiftTime = (int)nowSecond;
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftOpRes, ref res, player.UserID);
OnPlayerSendFriendGift(player.UserID, req.FriendUid, (int)nowSecond);
}
else if (req.OpType == 2) // 领取
{
var commDesc = 0;// CommParamDescMgr.Instance.GetConfig((int)CommParamKey.RecvFriendGiftDailyLimit);
int recvLimit = 0;
// 超过每日上限
if (friendSelf.TodaySelfRecvGift >= recvLimit)
{
TraceLog.Trace("FriendHandler.OnFriendGiftOpReq uid {0} recv num {1} to limit maxcount {2}"
, player.UserID, friendSelf.TodaySelfRecvGift, recvLimit);
res.Ret = (int)CSErrCode.RecvLimit;
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftOpRes, ref res, player.UserID);
return;
}
if (friendOne.oneFriend.RecvGiftNum == 0)
{
res.Ret = (int)CSErrCode.NoGift;
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftOpRes, ref res, player.UserID);
return;
}
TraceLog.Trace("FriendSvc.OnFriendGiftOpReq uid {0} friend {1} today recv {2}"
, player.UserID, req.FriendUid, friendSelf.TodaySelfRecvGift);
friendOne.oneFriend.RecvGiftNum = 0;
friendOne.oneFriend.LastGetGiftTime = (int) nowSecond;
friendSelf.TodaySelfRecvGift++;
selfInfo.SetNeedSave(true);
res.Ret = 0;
res.GiftData.RecvGiftNum = friendOne.oneFriend.RecvGiftNum;
res.GiftData.LastGetGiftTime = friendOne.oneFriend.LastGetGiftTime;
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftOpRes, ref res, player.UserID);
}
}
private static void OnPlayerSendFriendGift(long sendUid, long friendUid, int sendTime)
{
if (FriendUtils.IsPlayerBelongThisServer(friendUid))
{
ref FriendCacheInfoStruct friendinfo = ref FriendOp.GetFriendInfoByUid(friendUid);
if (friendinfo.IsNull())
{
TraceLog.Trace("FriendSvc.OnPlayerSendFriendGift friendUid {0} not in cache", friendUid);
FriendCacheSvc.SendDBQueryFriendInfoCache(friendUid, sendUid, QueryFriendInfoCacheReason.QueryBySendGift);
return;
}
DoFriendSendGift(ref friendinfo, sendUid);
}
else
{
// 通知好友所在服务器
FriendNotify.NotifyOtherSvrFriendSendGift(friendUid, sendUid, sendTime);
}
}
public static void OnFriendGiftAutoOpReq(uint remoteAppID, StructPacket packet)
{
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendSvc.OnFriendGiftAutoOpReq uid {0} no player", packet.ObjectID);
return;
}
ref FriendCacheInfoStruct friendinfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (friendinfo.IsNull())
{
TraceLog.Error("FriendSvc.OnFriendGiftAutoOpReq uid {0} no friendInfo cache", player.UserID);
return;
}
UpdateFriendGiftData(ref friendinfo);
long nowSecond = FriendServerUtils.GetTimeSecond();
var commDesc = 0;// CommParamDescMgr.Instance.GetConfig((int)CommParamKey.SendFriendGiftDailyLimit);
int sendLimit = 0;//commDesc != null ? commDesc.int_val : 0;
commDesc = 0;//CommParamDescMgr.Instance.GetConfig((int)CommParamKey.RecvFriendGiftDailyLimit);
int recvLimit = 0;//commDesc != null ? commDesc.int_val : 0;
var res = new CSFriendGiftAutoOpRes();
for (int i = 0; i < friendinfo.FriendList.iCount; i++)
{
ref DBFriendOneStruct friendOne = ref FriendOp.GetFriendOneByIndex(ref friendinfo, i);
if (friendOne.IsNull())
{
TraceLog.Error("FriendSvc.OnFriendGiftAutoOpReq friend {0} not in cache", friendOne.oneFriend.Uid);
continue;
}
TraceLog.Trace("FriendSvc.OnFriendGiftAutoOpReq uid {0} friend {1} lastSendTime {2} recvGiftNum {3}"
, player.UserID, friendOne.oneFriend.Uid, friendOne.oneFriend.LastSendGiftTime, friendOne.oneFriend.RecvGiftNum);
// 赠送
if (friendinfo.Self.TodaySelfSendGift < sendLimit
&& ! AppTime.IsSameDay(nowSecond, friendOne.oneFriend.LastSendGiftTime)
&& ! friendinfo.Self.TodaySendGiftUid.Contains(friendOne.oneFriend.Uid))
{
friendinfo.Self.TodaySelfSendGift++;
friendinfo.Self.TodaySendGiftUid.Add(friendOne.oneFriend.Uid);
friendOne.oneFriend.LastSendGiftTime = (int) nowSecond;
res.SendList.Add(friendOne.oneFriend.Uid);
OnPlayerSendFriendGift(player.UserID, friendOne.oneFriend.Uid, (int) nowSecond);
}
// 领取
if (friendinfo.Self.TodaySelfRecvGift < recvLimit && friendOne.oneFriend.RecvGiftNum > 0)
{
friendinfo.Self.TodaySelfRecvGift++;
friendOne.oneFriend.RecvGiftNum = 0;
friendOne.oneFriend.LastGetGiftTime = (int) nowSecond;
res.RecvList.Add(friendOne.oneFriend.Uid);
}
}
res.TodaySelfSendGift = friendinfo.Self.TodaySelfSendGift;
res.TodaySelfRecvGift = friendinfo.Self.TodaySelfRecvGift;
res.LastResetGiftDataTime = friendinfo.Self.LastResetGiftDataTime;
res.LastSendGiftTime = (int) nowSecond;
if (res.SendList.Count > 0 || res.RecvList.Count > 0)
{
friendinfo.SetNeedSave(true);
}
TraceLog.Trace("FriendSvc.OnFriendGiftAutoOpReq uid {0} sendList {1} recvList {2} today send {3} recv {4}"
, player.UserID, res.SendList.Count, res.RecvList.Count, res.TodaySelfSendGift, res.TodaySelfRecvGift);
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.FriendGiftAutoOpRes, ref res, player.UserID);
}
public static void OnGetFriendGiftDataReq(uint remoteAppID, StructPacket packet)
{
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendSvc.OnGetFriendGiftDataReq uid {0} no player", packet.ObjectID);
return;
}
ref FriendCacheInfoStruct friendinfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (friendinfo.IsNull())
{
TraceLog.Error("FriendSvc.OnGetFriendGiftDataReq uid {0} no friendInfo cache", player.UserID);
return;
}
UpdateFriendGiftData(ref friendinfo);
var res = new CSGetFriendGiftDataRes();
res.TodaySelfSendGift = friendinfo.Self.TodaySelfSendGift;
res.TodaySelfRecvGift = friendinfo.Self.TodaySelfRecvGift;
res.LastResetGiftDataTime = friendinfo.Self.LastResetGiftDataTime;
for (int i = 0; i < friendinfo.FriendList.iCount; i++)
{
ref DBFriendOneStruct friendOne = ref FriendOp.GetFriendOneByIndex(ref friendinfo, i);
if (! friendOne.IsNull())
{
var giftOne = new CSFriendGiftData
{
Uid = friendOne.oneFriend.Uid,
RecvGiftNum = friendOne.oneFriend.RecvGiftNum,
LastSendGiftTime = (int)friendOne.oneFriend.LastSendGiftTime,
};
res.GiftData.Add(ref giftOne);
}
}
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.GetFriendGiftDataRes, ref res, player.UserID);
}
// 收到其他服务器发来的赠送礼物的通知
public static void OnFriendSendGiftNotify(uint remoteAppID, StructPacket packet)
{
long uid = packet.ObjectID;
ref CSFriendSendGiftNotify notify = ref packet.GetMessage<CSFriendSendGiftNotify>();
TraceLog.Trace("FriendOpSvc.OnFriendSendGiftNotify uid {0} sendUid {1}", uid, notify.SendUid);
if (! FriendUtils.IsPlayerBelongThisServer(uid))
{
TraceLog.Error("FriendOpSvc.OnFriendSendGiftNotify uid {0} not belong this svr", uid);
return;
}
ref FriendCacheInfoStruct friendInfo = ref FriendOp.GetFriendInfoByUid(uid);
if (friendInfo.IsNull())
{
TraceLog.Trace("FriendOpSvc.OnFriendSendGiftNotify uid {0} not in cache", uid);
FriendCacheSvc.SendDBQueryFriendInfoCache(uid, notify.SendUid, QueryFriendInfoCacheReason.QueryBySendGift);
return;
}
DoFriendSendGift(ref friendInfo, notify.SendUid);
}
public static void DoFriendSendGiftOnDataLoad(long uid, long sendUid)
{
ref FriendCacheInfoStruct friendInfo = ref FriendOp.GetFriendInfoByUid(uid);
if (friendInfo.IsNull())
{
TraceLog.Error("FriendOpSvc.DoFriendSendGiftOnDataLoad uid {0} not in cache", uid);
return;
}
DoFriendSendGift(ref friendInfo, sendUid);
}
public static void DoFriendSendGift(ref FriendCacheInfoStruct friendInfo, long sendUid)
{
long uid = friendInfo.Self.Uid;
ref DBFriendOneStruct friendOne = ref FriendOp.GetFriendOneByUid(uid, sendUid);
if (friendOne.IsNull())
{
TraceLog.Trace("FriendOpSvc.DoFriendSendGift uid {0} sendUid {1} not in friendList", uid, sendUid);
return;
}
TraceLog.Trace("FriendOpSvc.DoFriendSendGift uid {0} sendUid {1}", uid, friendOne.oneFriend.Uid);
friendOne.oneFriend.RecvGiftNum = 1;
friendInfo.SetNeedSave(true);
FriendNotify.NotifyPlayerFriendSendGift(uid, sendUid);
}
//public static void OnCliGetSignRewardReq(uint remoteAppID, StructPacket packet)
//{
// PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
// if (player == null)
// {
// TraceLog.Error("FriendSvc.OnCliGetFriendRankRewardReq can not find player uid {0}", packet.ObjectID);
// return;
// }
// ref FriendCacheInfoStruct friendinfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
// if (friendinfo.IsNull())
// {
// TraceLog.Error("FriendSvc.OnCliGetFriendRankRewardReq can not find player uid {0} friendInfo from cache"
// , player.UserID);
// return;
// }
// ref CSGetSignRewardReq req = ref packet.GetMessage<CSGetSignRewardReq>();
// CSGetSignRewardRes res = new CSGetSignRewardRes();
// res.ShareNow = req.ShareNow;
// //获取活跃的好友数量
// res.ActfriendCount = FriendUtils.GetActivityFriendCount(ref friendinfo);
// FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.GetSignRewardRes,ref res, player.UserID);
//}
public static void OnCliSendMailToPlayerReq(uint remoteAppID, StructPacket packet)
{
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendSvc.OnCliSendMailToPlayerReq can not find player uid {0}", packet.ObjectID);
return;
}
ref FriendCacheInfoStruct friendinfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (friendinfo.IsNull())
{
TraceLog.Error("FriendSvc.OnCliSendMailToPlayerReq can not find player uid {0} friendInfo from cache"
, player.UserID);
return;
}
ref CSMailSendToPlayerReq req = ref packet.GetMessage<CSMailSendToPlayerReq>();
CSMailSendToPlayerRes res = new CSMailSendToPlayerRes();
res.TargetUid = req.TargetUid;
res.Chip = req.Chip;
res.Title = req.Title;
res.Content = req.Content;
//不是好友不能送钱
if (FriendOp.ISAlreadyBeenFriend(friendinfo.Self.Uid,req.TargetUid) == 0)
{
res.Ret = -1;
TraceLog.Error("FriendSvc.OnCliSendMailToPlayerReq player uid {0} send chip targetuid {1} is not my friend!"
, player.UserID, req.TargetUid);
}
else
{
//if(friend.FriendType == 1)
//{
// res.IsFBFriend = 1;
//}
}
FriendServerUtils.GetPacketSender().SendToServerByID(player.WorldServerID, (int)CSGameMsgID.MailSendToPlayerRes,ref res, player.UserID);
}
public static void ProcessHideMyInfoReq(uint remoteAppID, StructPacket packet)
{
ref CSHideMyInfoReq req =ref packet.GetMessage<CSHideMyInfoReq>();
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendSvc.ProcessHideMyInfoReq player {0} = null", packet.ObjectID);
return;
}
ref FriendCacheInfoStruct friendinfo =ref FriendOp.GetFriendInfoByUid(player.UserID);
if (friendinfo.IsNull())
{
TraceLog.Error("FriendSvc.ProcessHideMyInfoReq can not find player uid {0} friendInfo from cache"
, player.UserID);
return;
}
if (friendinfo.Self.HideMyInfo != req.Hide)
{
friendinfo.Self.HideMyInfo = req.Hide;
friendinfo.SetNeedSave(true);
}
TraceLog.Trace("FriendSvc.ProcessHideMyInfoReq uid {0} CSHideMyInfoReq hide {1}"
, player.UserID, req.Hide);
}
public static void OnRoleDataSave(PlayerInfoFriend player, ref DBRoleBase roleBase, ref SSSaveRoleNotify saveRoleNotify)
{
//存在一定概率,不是错误
ref FriendCacheInfoStruct friendinfo = ref FriendOp.GetFriendInfoByUid(roleBase.Uid);
if (friendinfo.IsNull())
{
TraceLog.Debug("FriendSvc.OnRoleDataSave uid {0} no friendCacheInfo", roleBase.Uid);
return;
}
//更新self
bool bChg = FriendUtils.CheckAndChangeSelfByRoleData(player, ref friendinfo.Self, ref roleBase, ref saveRoleNotify);
if(bChg)
{
friendinfo.SetNeedSave(true);
}
TraceLog.Trace("FriendSvc.OnRoleDataSave uid {0} self change {1}", roleBase.Uid, bChg);
// 加入推荐列表
FriendRecommenTableSvc.Add(ref friendinfo);
}
//game -> world -> friend -> world 要查玩家详细信息
public static void OnQueryOtherDetailReq(uint serverID, StructPacket packet)
{
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendSvc.OnQueryOtherDetailReq player {0} = null", packet.ObjectID);
return;
}
serverID = player.WorldServerID;
ref CSQueryOtherDetailReq req = ref packet.GetMessage<CSQueryOtherDetailReq>();
var res = new CSQueryOtherDetailRes {TargetUid = req.TargetUid};
//如果是机器人,则直接赋值并且回包
if (req.TargetUid < 10000)
{
res.HideInfo = 1;
TraceLog.Error("FriendSvc.OnQueryOtherDetailReq robot {0} not in table", req.TargetUid);
FriendServerUtils.GetPacketSender().SendToServerByID(serverID, (int) CSGameMsgID.QueryOtherDetailRes, ref res, packet.ObjectID);
return;
}
ref FriendCacheInfoStruct targetInfo = ref FriendOp.GetFriendInfoByUid(req.TargetUid);
if (targetInfo.IsNull())
{
TraceLog.Error("FriendSvc.OnQueryOtherDetailReq can not find player uid {0} friendInfo from cache"
, req.TargetUid);
res.Ret = -1;
FriendServerUtils.GetPacketSender().SendToServerByID<CSQueryOtherDetailReq>(serverID, packet);
return;
}
FriendUtils.MakeQueryOtherDetailBySelf(ref res, ref targetInfo.Self);
//转消息给game
FriendServerUtils.GetPacketSender().SendToServerByID(serverID, (int) CSGameMsgID.QueryOtherDetailRes, ref res, packet.ObjectID);
}
public static void CheckFriendListStruct(ref FriendCacheInfoStruct infoStruct)
{
unsafe
{
for (int i = 0; i < infoStruct.FriendList.iCount; i++)
{
ref DBFriendOneStruct oneStruct = ref FriendInfoCache.m_cacheStructFriendOne.GetByIndex(infoStruct.FriendList.DBFriendOneID[i]);
if (oneStruct.IsNull())
{
TraceLog.Error("FriendSvc.CheckFriendListStruct uid {0} friend index {1} no DBFriendOneStruct"
, infoStruct.Self.Uid, infoStruct.FriendList.DBFriendOneID[i]);
continue;
}
// 看看这个好友在不在, 不在的要去DB或者其他FriendSvr查询, 然后更新这个数据到好友上
if (FriendUtils.IsPlayerBelongThisServer(oneStruct.oneFriend.Uid))
{
ref FriendCacheInfoStruct oneFriend = ref FriendOp.GetFriendInfoByUid(oneStruct.oneFriend.Uid);
if (oneFriend.IsNull())
{
FriendCacheSvc.SendDBOrFriendSvrQueryFriendInfo(oneStruct.oneFriend.Uid, infoStruct.Self.Uid,
QueryFriendInfoCacheReason.QueryFriendOneStruct);
}
}
else
{
ref RemoteFriendOneStruct remoteFriend = ref FriendOp.GetRemoteFriendOneByUid(oneStruct.oneFriend.Uid);
if (remoteFriend.IsNull())
{
FriendCacheSvc.SendFriendSvrQueryFriendInfoCache(oneStruct.oneFriend.Uid, infoStruct.Self.Uid,
QueryFriendInfoCacheReason.QueryFriendOneStruct);
}
}
}
}
}
public static bool IsFriendListFull(ref FriendCacheInfoStruct info)
{
return info.FriendList.iCount >= FriendConfig.GetFriendListCountMax();
}
public static bool CanAddNewToFriendList(long playerUid, long friendUid)
{
if (FriendOp.ISAlreadyBeenFriend(playerUid, friendUid) == 1)
{
return false;
}
ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(playerUid);
if (info.IsNull())
{
if (IsFriendListFull(ref info))
{
TraceLog.Debug("FriendSvc.CanAddNewToFriendList friend list full! uid {0}", playerUid);
return false;
}
}
return true;
}
public static bool IsFriendOpListFull(ref FriendCacheInfoStruct info)
{
return info.FriendOpData.OpCount >= FriendConfig.GetFriendOpListCountMax();
}
/// <summary>
/// 陌生人列表是否已经满了
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static bool IsStrangerListFull(ref FriendCacheInfoStruct info)
{
return info.FriendOpData.StrangerCount >= FriendConfig.GetFriendStrangerListCountMax();
}
public static void OnQueryBlacklistReq(uint remoteAppID, StructPacket packet)
{
ref SSQueryBlacklistReq req = ref packet.GetMessage<SSQueryBlacklistReq>();
long uid = req.Uid;
//m_QueryFriendListRes.Clear();
//m_QueryFriendListRes.Uid = uid;
TraceLog.Trace("FriendSvc.OnQueryBlacklistReq uid {0}", uid);
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(uid);
if (player == null)
{
TraceLog.Trace("FriendSvc.OnQueryBlacklistReq uid {0} no player obj", uid);
return;
}
// 不是本服请求不处理, gamesvr发错了, 找找发送错误的原因
if (!FriendUtils.IsPlayerBelongThisServer(player.UserID))
{
TraceLog.Trace("FriendSvc.OnQueryBlacklistReq uid {0} no belong this svr", uid);
return;
}
ref var selfInfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
if (selfInfo.IsNull()) //之前应该查询过数据,没有数据不处理
{
TraceLog.Trace("FriendSvc.OnQueryBlacklistReq uid {0} no selfInfo this svr", uid);
return;
}
FriendSvc.CheckBlacklist(ref selfInfo);
FriendSvc.CheckPlayerBlacklistSynFromDBFinishAckGame(player.UserID);
}
public static void CheckBlacklist(ref FriendCacheInfoStruct selfInfo)
{
unsafe
{
ref var balacklist = ref selfInfo.Self.BlackList;
for(int i = 0; i < balacklist.Count; i++)
{
// 看看在不在, 不在的要去DB或者其他FriendSvr查询
if (FriendUtils.IsPlayerBelongThisServer(balacklist[i]))
{
ref FriendCacheInfoStruct oneFriend = ref FriendOp.GetFriendInfoByUid(balacklist[i]);
if (oneFriend.IsNull())
{
FriendCacheSvc.SendDBOrFriendSvrQueryFriendInfo(balacklist[i], selfInfo.Self.Uid,
QueryFriendInfoCacheReason.QueryBlacklist);
}
}
else
{
ref RemoteFriendOneStruct remoteFriend = ref FriendOp.GetRemoteFriendOneByUid(balacklist[i]);
if (remoteFriend.IsNull())
{
FriendCacheSvc.SendFriendSvrQueryFriendInfoCache(balacklist[i], selfInfo.Self.Uid,
QueryFriendInfoCacheReason.QueryBlacklist);
}
}
}
}
}
}
}