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.
183 lines
7.8 KiB
183 lines
7.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace Friend
|
|
{
|
|
//Facebook好友处理逻辑
|
|
public static class FriendSnsSvc
|
|
{
|
|
/// <summary>
|
|
/// 向account服务器发送查询sns好友信息列表的请求
|
|
/// 这个请通过world转,或者通过httpproxyworld查询也可以,以后再说
|
|
/// </summary>
|
|
/// <param name="player"></param>
|
|
public static void SendAccountQuerySnsFriendList(PlayerInfoFriend player)
|
|
{
|
|
SSQuerySnsFriendAccountReq req = new SSQuerySnsFriendAccountReq();
|
|
req.Uid = player.UserID;
|
|
req.AccountType = player.accountInfo.AccountType;
|
|
req.AccountID = player.accountInfo.AccountID;
|
|
//FriendServerUtils.GetPacketSender().SendToAccountServer((int)SSMsgID.QuerySnsFriendAccountReq, req, player.UserID);
|
|
}
|
|
|
|
public static void OnQuerySnsFriendAccountRes(uint remoteAppID, StructPacket packet)
|
|
{
|
|
ref SSQuerySnsFriendAccountRes res = ref packet.GetMessage<SSQuerySnsFriendAccountRes>();
|
|
|
|
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(res.Uid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("FriendSnsSvc.QuerySnsFriendAccountRes can not find player uid {0}", res.Uid);
|
|
return;
|
|
}
|
|
|
|
player.SnsFriendList.Clear();
|
|
|
|
// todo 拉取到的sns好友是登录过游戏的?
|
|
|
|
OnAccountSnsFriendQueryFinish(player);
|
|
}
|
|
|
|
private static bool IsInMySnsFriendList(PlayerInfoFriend player, long friendUid)
|
|
{
|
|
foreach(var snsFriend in player.SnsFriendList)
|
|
{
|
|
if(snsFriend.Uid == friendUid)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// account回应sns好友列表成功,处理自己的sns好友和游戏好友从数据库里拉取信息
|
|
/// 同步sns好db好友信息,比如好友类型,从sns好友变成游戏好友或者从游戏好友变成sns好友
|
|
/// </summary>
|
|
/// <param name="player"></param>
|
|
public static unsafe void OnAccountSnsFriendQueryFinish(PlayerInfoFriend player)
|
|
{
|
|
TraceLog.Trace("FriendSnsSvc.OnAccountSnsFriendQueryFinish uid {0}", player.UserID);
|
|
|
|
ref FriendCacheInfoStruct info = ref FriendOp.GetFriendInfoByUid(player.UserID);
|
|
if (info.IsNull())
|
|
{
|
|
TraceLog.Error("FriendSnsSvc.OnAccountSnsFriendQueryFinish can not find player uid {0} friendInfo from cache"
|
|
, player.UserID);
|
|
return;
|
|
}
|
|
|
|
//遍历所有好友列表,从cache里更新最新数据,如果cache里没有,需要去数据库里查(sns qq 微信的好友暂时不处理)
|
|
FriendSvc.CheckFriendListStruct(ref info);
|
|
|
|
FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame(player.UserID);
|
|
}
|
|
|
|
public static void OnQueryFriendInfoCacheResFromDB(ref SSQueryFriendInfoCacheRes res)
|
|
{
|
|
if (! FriendUtils.IsPlayerBelongThisServer(res.FromUid))
|
|
{
|
|
FriendServerUtils.GetPacketSender().SendToFriendServer((int) SSGameMsgID.QueryFriendInfoCacheRes, ref res, res.FromUid);
|
|
return;
|
|
}
|
|
|
|
PlayerInfoFriend player = FriendServerUtils.GetPlayerTableOp().GetPlayerInfo(res.FromUid);
|
|
if (player == null)
|
|
{
|
|
TraceLog.Error("FriendSnsSvc.OnQueryFriendInfoCacheResFromDB can not find player uid {0}"
|
|
, res.FromUid);
|
|
return;
|
|
}
|
|
|
|
//先统一处理sns列表
|
|
if (res.Reason == QueryFriendInfoCacheReason.LoginQuerySnsFriend)
|
|
{
|
|
//标记sns好友数据
|
|
foreach (var snsFriend in player.SnsFriendList)
|
|
{
|
|
if (snsFriend.Uid == res.Uid)
|
|
{
|
|
if (res.Self.Uid == 0)
|
|
{
|
|
// snsFriend.DbQueryResult = -1;
|
|
}
|
|
else
|
|
{
|
|
//snsFriend.DbQueryResult = 1;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 好友的DBFriendSelf
|
|
if (res.Self.Uid == 0)
|
|
{
|
|
//这种情况按理说是不可能发生的
|
|
if (res.Reason != QueryFriendInfoCacheReason.LoginQuerySnsFriend)
|
|
{
|
|
TraceLog.Error("FriendSnsSvc.OnQueryFriendInfoCacheResFromDB uid {0} fromuid {1} forSns == false, but not friend data in db, logic error!"
|
|
, res.Uid, res.FromUid);
|
|
}
|
|
|
|
// LoginQuerySnsFriend,发起查询的sns好友肯定是有uid的,有uid但是没有tbfriend信息
|
|
// 目前只有一种情况,建立了account后没有login游戏,有uid没有roleData,也就没有tbfriend
|
|
|
|
// LoginQueryDbfriend,对方在自己的好友列表里面,但是对方的好友信息不存在?
|
|
// A、B成为好友后,A数据落地成功,B数据落地失败,停服没成功?没问题,游戏好友手动再加一次,sns好友下次上线自己添加
|
|
|
|
//facebook好友里有,但是游戏数据库里没有,情况1,数据库会删除重建,情况2,建立了account但是没有建立游戏帐号,也正常(概率应该不高)
|
|
TraceLog.Trace("FriendSnsSvc.OnQueryFriendInfoCacheResFromDB can not find friendInfo from db uid {0} fromuid {1}"
|
|
, res.Uid, res.FromUid);
|
|
}
|
|
else
|
|
{
|
|
//sns好友db信息查询成功,那么添加这个好友到我的好友列表
|
|
if (res.Reason == QueryFriendInfoCacheReason.LoginQuerySnsFriend)
|
|
{
|
|
//添加好友信息到列表
|
|
ref FriendCacheInfoStruct friendInfo = ref FriendOp.GetFriendInfoByUid(player.UserID);
|
|
if (friendInfo.IsNull())
|
|
{
|
|
TraceLog.Error("FriendSnsSvc.OnQueryFriendInfoCacheResFromDB uid {0} no cache"
|
|
, res.Uid);
|
|
return;
|
|
}
|
|
|
|
if(FriendSvc.CanAddNewToFriendList(friendInfo.Self.Uid, res.Self.Uid))
|
|
{
|
|
DBFriendOne newOne = new DBFriendOne();
|
|
FriendUtils.CopySelfToFriendOne(ref res.Self, ref newOne);
|
|
newOne.FriendType = 1;
|
|
|
|
// 主动添加自己的sns好友
|
|
FriendOp.DoAddFriendOneToMySelf(ref friendInfo, newOne.Uid, true);
|
|
|
|
TraceLog.Trace("FriendSnsSvc.OnQueryFriendInfoCacheResFromDB player uid {0} add one friend uid {1}"
|
|
, player.UserID, newOne.Uid);
|
|
}
|
|
else
|
|
{
|
|
if (FriendSvc.IsFriendListFull(ref friendInfo))
|
|
{
|
|
TraceLog.Error("FriendSnsSvc.OnQueryFriendInfoCacheResFromDB player uid {0} friend list full"
|
|
, player.UserID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(res.Reason == QueryFriendInfoCacheReason.QueryBlacklist)
|
|
{
|
|
FriendSvc.CheckPlayerBlacklistSynFromDBFinishAckGame(res.FromUid);
|
|
return;
|
|
}
|
|
FriendSvc.CheckPlayerFriendDataSynFromDBFinishAckGame(res.FromUid);
|
|
}
|
|
}
|
|
}
|
|
|