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.
 
 
 
 
 
 

507 lines
20 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using Sog.Service;
using ProtoCSStruct;
namespace Game
{
public class FriendHandler : BasePacketHandler
{
public override int GetServiceType()
{
return GameServiceType.FriendHandler;
}
//销毁的时候置空
public override void Dispose()
{
}
public FriendHandler()
{
}
public override void HandlerClientPacket(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("FriendHandler.HandlerClientPacket can not find PlayerOnGame sessionid {0}", playerSession.SessionID);
return;
}
switch (packet.MsgID)
{
case (int)CSGameMsgID.QueryFriendListReq:
OnCliQueryFriendListReq(player, packet);
break;
case (int)CSGameMsgID.FriendGiftOpReq:
GameServerUtils.GetPacketSender().SendToWorldServer<CSFriendGiftOpReq>(packet, player.UserID);
break;
case (int)CSGameMsgID.FriendGiftAutoOpReq:
GameServerUtils.GetPacketSender().SendToWorldServer<CSFriendGiftAutoOpReq>(packet, player.UserID);
break;
case (int)CSGameMsgID.GetFriendGiftDataReq:
GameServerUtils.GetPacketSender().SendToWorldServer<CSGetFriendGiftDataReq>(packet, player.UserID);
break;
case (int)CSGameMsgID.QueryFriendStatusReq:
GameServerUtils.GetPacketSender().SendToWorldServer<CSQueryFriendStatusReq>(packet, player.UserID);
break;
//case (int)CSGameMsgID.QueryOtherDetailReq:
// ProcessQueryOtherDetailReq(playerSession, packet);
// break;
case (int)CSGameMsgID.SetPersonalizedSignatureReq:
ProcessSetPersonalizedSignatureReq(playerSession, packet);
break;
case (int)CSGameMsgID.FriendSetSettingReq:
ProcessFriendSetSettingReq(playerSession, packet);
break;
case (int)CSGameMsgID.FriendQueryBlacklistReq:
OnCliFriendQueryBlacklistReq(player, packet);
break;
default:
TraceLog.Error("FriendHandler.HandlerClientPacket msgId {0} not handle", packet.MsgID);
break;
}
}
public override void HandlerServerPacket(uint serverID, StructPacket packet)
{
switch (packet.MsgID)
{
case (int)SSGameMsgID.QueryFriendListRes:
OnSvrQueryFriendListRes(serverID, packet);
break;
case (int)SSGameMsgID.QueryBlacklistRes:
OnSvrQueryBlacklistRes(serverID, packet);
break;
case (int)CSGameMsgID.FriendSelfChgNotify:
OnFriendSelfChgNotify(serverID, packet);
break;
case (int)CSGameMsgID.FriendListChgNotify:
OnFriendListChgNotify(serverID, packet);
break;
case (int)CSGameMsgID.QueryFriendStatusRes:
OnQueryFriendStatusRes(serverID, packet);
break;
case (int)CSGameMsgID.FriendGiftOpRes:
OnFriendGiftOpRes(serverID, packet);
break;
case (int)CSGameMsgID.FriendGiftAutoOpRes:
OnFriendGiftAutoOpRes(serverID, packet);
break;
case (int)CSGameMsgID.FriendSendGiftNotify:
SendToPlayerByObjectID<CSFriendSendGiftNotify>(packet);
break;
case (int)CSGameMsgID.GetFriendGiftDataRes:
SendToPlayerByObjectID<CSGetFriendGiftDataRes>(packet);
break;
case (int)CSGameMsgID.QueryOtherDetailRes:
OnSvrQueryOtherDetailRes(serverID, packet);
break;
case (int)CSGameMsgID.SetPersonalizedSignatureRes:
OnSetPersonalizedSignatureRes(serverID, packet);
break;
case (int)CSGameMsgID.FriendSetSettingRes:
OnFriendSetSettingRes(serverID, packet);
break;
default:
TraceLog.Error("FriendHandler.HandlerServerPacket msgId {0} not handle", packet.MsgID);
break;
}
}
private void OnCliQueryFriendListReq(PlayerOnGame player, StructPacket packet)
{
player.Trace("FriendHandler.OnCliQueryFriendListReq uid {0}", player.UserID);
SSQueryFriendListReq ssreq = new SSQueryFriendListReq();
ssreq.Uid = player.UserID;
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.QueryFriendListReq, ref ssreq, player.UserID);
}
private void OnSvrQueryFriendListRes(uint serverID, StructPacket packet)
{
ref SSQueryFriendListRes ssres = ref packet.GetMessage<SSQueryFriendListRes>();
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(ssres.Uid);
if (player == null)
{
TraceLog.Error("FriendHandler.OnSvrQueryFriendListRes no player object uid {0}", ssres.Uid);
return;
}
ref CSQueryFriendListRes csres = ref CSStructPool<CSQueryFriendListRes>.Instance.GetObjRef();
csres.Self = ssres.Self;
csres.List.CopyFrom(ref ssres.List);
SendToPlayer(player, (int)CSGameMsgID.QueryFriendListRes, ref csres);
}
public void OnFriendSelfChgNotify(uint remoteAppID, StructPacket packet)
{
ref CSFriendSelfChgNotify req = ref packet.GetMessage<CSFriendSelfChgNotify>();
//找不到也正常
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
player.Trace("FriendHandler.OnFriendSelfChgNotify no player object uid {0}", packet.ObjectID);
return;
}
player.SendToClient<CSFriendSelfChgNotify>(packet);
}
public void OnFriendListChgNotify(uint remoteAppID, StructPacket packet)
{
//找不到也正常
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
player.Trace("FriendHandler.OnFriendSelfChgNotify no player object uid {0}", packet.ObjectID);
return;
}
player.SendToClient<CSFriendListChgNotify>(packet);
}
//world通知我的
//public void OnFriendListDeleteNotify(uint remoteAppID, StructPacket packet)
//{
// //找不到也正常
// PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
// if (player == null)
// {
// player.Trace("FriendHandler.OnFriendListDeleteNotify no player object uid {0}", packet.ObjectID);
// return;
// }
// player.SendToClient<CSFriendListDeleteNotify>(packet);
//}
public void OnQueryFriendStatusRes(uint remoteAppID, StructPacket packet)
{
long uid = packet.ObjectID;
ref CSQueryFriendStatusRes res = ref packet.GetMessage<CSQueryFriendStatusRes>();
var player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(uid);
//获取好友数量
var friendCount = res.Friends.Count;
if (player != null)
{
player.friendCount = friendCount;
player.MakeDirty();
SendToPlayer<CSQueryFriendStatusRes>(player, packet);
}
}
private void OnFriendGiftOpRes(uint serverID, StructPacket packet)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendHandler.OnFriendGiftOpRes {0} no player", packet.ObjectID);
return;
}
ref CSFriendGiftOpRes res = ref packet.GetMessage<CSFriendGiftOpRes>();
player.Trace("FriendHandler.OnFriendGiftOpRes uid {0} friend {1} giftOp {2} ret {3}"
, player.UserID, res.GiftData.Uid, res.OpType, res.Ret);
if (res.Ret == 0)
{
// 赠送成功
if (res.OpType == 1)
{
GameServerUtils.GetEventHandlerMgr().TriggerSendFriendGift(player, 1);
}
else if (res.OpType == 2) // 领取成功
{
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.RecvFriendGift);
bagOp.DoOp();
}
GameBillLogUtils.LogFriendGift(player.UserID, res.OpType, res.GiftData.Uid,
res.TodaySelfSendGift, res.TodaySelfRecvGift, 0);
}
SendToPlayer<CSFriendGiftOpRes>(player, packet);
}
private void OnFriendGiftAutoOpRes(uint serverID, StructPacket packet)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendHandler.OnFriendGiftAutoOpRes {0} no player", packet.ObjectID);
return;
}
ref var res = ref packet.GetMessage<CSFriendGiftAutoOpRes>();
player.Trace("FriendSvc.OnFriendGiftAutoOpRes uid {0} sendList {1} recvList {2} today send {3} recv {4}"
, player.UserID, res.SendList.Count, res.RecvList.Count, res.TodaySelfSendGift, res.TodaySelfRecvGift);
for (int i = 0; i < res.SendList.Count; i++)
{
GameBillLogUtils.LogFriendGift(player.UserID, 1, res.SendList[i]
, res.TodaySelfSendGift, res.TodaySelfRecvGift, 1);
}
// 赠送成功
if (res.SendList.Count > 0)
{
GameServerUtils.GetEventHandlerMgr().TriggerSendFriendGift(player, res.SendList.Count);
}
// 领取成功
if (res.RecvList.Count > 0)
{
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.RecvFriendGift);
bagOp.DoOp();
for (int i = 0; i < res.RecvList.Count; i++)
{
GameBillLogUtils.LogFriendGift(player.UserID, 2, res.RecvList[i],
res.TodaySelfSendGift, res.TodaySelfRecvGift, 1);
}
}
SendToPlayer<CSFriendGiftAutoOpRes>(player, packet);
}
private void ProcessInviteFacebookSuccessReq(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("FriendHandler.ProcessInviteFacebookSuccessReq no player object uid {0}", playerSession.UserID);
return;
}
ref CSInviteFacebookSuccessReq req = ref packet.GetMessage<CSInviteFacebookSuccessReq>();
if(req.InviteCount < 1 || req.InviteCount > 100)
{
player.Error("FriendHandler.ProcessInviteFacebookSuccessReq uid {0} invliad req invitecount (1-100)", player.UserID);
return;
}
long oldCount = 0; //StatisticsOp.GetIDDaily(player, (int)CSRoleStatisticsID.InviteFacebookCount);
//坑,客户端别发给服务器了,外挂有可能
if (oldCount > 1000)
{
player.Error("FriendHandler.ProcessInviteFacebookSuccessReq uid {0} InviteFacebookCount {1} to much today"
, player.UserID, oldCount);
return;
}
long newCount = oldCount + req.InviteCount;
long getChipCount = req.InviteCount;
//超出最大值
//if(newCount > CommParamDescUtils.GetCommParam().InviteSnsFriendDailyLimit )
//{
// getChipCount = CommParamDescUtils.GetCommParam().InviteSnsFriendDailyLimit - oldCount;
//}
////long getChipCount = CommParamDescUtils.GetCommParam().InviteSnsFriendDailyLimit - oldCount;
long chipPer = 0; // CommParamDescUtils.GetCommParam().InviteSnsFriendChip;
//统计数据变化操作
RoleStatChgOp statChgOp = new RoleStatChgOp(player);
//statChgOp.AddIDDaily((int)CSRoleStatisticsID.InviteFacebookCount, req.InviteCount);
//通知客户端
statChgOp.NotifyClient();
//如果需要给奖励(没达到每日次数限制)给奖励
if(getChipCount > 0)
{
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.InviteSnsFriendAward);
bagOp.AddGold(getChipCount * chipPer);
CSErrCode iRet = bagOp.DoOp();
if (iRet != 0)
{
player.Error("FriendHandler.ProcessInviteFacebookSuccessReq uid {0} bagOp.DoOp failed ret {1}", player.UserID, iRet);
return;
}
}
//Bill日记
//GameBillLogUtils.LogInviteFacebook(player.UserID, StatisticsOp.GetIDDaily(player, (int)CSRoleStatisticsID.InviteFacebookCount));
player.Trace("FriendHandler.ProcessInviteFacebookSuccessReq uid {0} success", player.UserID);
}
private void ProcessQueryOtherDetailReq(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("FriendHandler.ProcessQueryOtherDetailReq no player object uid {0}", playerSession.UserID);
return;
}
//有可能是机器人或者其他gameServer上的玩家,统一转给world处理
GameServerUtils.GetPacketSender().SendToWorldServer<CSQueryOtherDetailReq>(packet, player.UserID);
}
private void OnSvrQueryOtherDetailRes(uint serverID, StructPacket packet)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendHandler.OnSvrQueryOtherDetailRes no player object uid {0}", packet.ObjectID);
return;
}
player.SendToClient<CSQueryOtherDetailRes>(packet);
}
/*
//world发给我要查我这个服务器上的玩家详细信息
private void OnQueryOtherDetailReq(uint serverID, RequestPacket packet)
{
var req = (CSQueryOtherDetailReq)packet.Message;
CSQueryOtherDetailRes res = new CSQueryOtherDetailRes();
res.TargetUid = req.TargetUid;
PlayerOnGame targetPlayer = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(req.TargetUid);
if (targetPlayer == null)
{
TraceLog.Trace("FriendHandler.OnQueryOtherDetailReq targetuid {0} not in memory,skip", req.TargetUid);
res.Ret = -1;
}
else
{
// 客户端要求查询时下发所有信息,如果对方设置隐私,客户端会根据ret进行隐藏
PlayerUtils.MakeQueryOtherDetailByPlayer(res, targetPlayer);
if (targetPlayer.RoleData.OtherData.HideMyInfo != 0)
{
res.Ret = 116001;
TraceLog.Trace("FriendHandler.ProcessQueryOtherDetailReq targetuid {0} hide info, can not query", req.TargetUid);
}
}
//给wolrd回包,请求的玩家应该不在这台gameserver上,否则不会转过来,这里就不判断了
GameServerUtils.GetPacketSender().SendToFriendServer((int)CSGameMsgID.QueryOtherDetailRes, res, packet.ObjectID);
}*/
private void ProcessSetPersonalizedSignatureReq(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("FriendHandler.ProcessQueryOtherDetailReq no player object uid {0}", playerSession.UserID);
return;
}
ref CSSetPersonalizedSignatureReq req = ref packet.GetMessage<CSSetPersonalizedSignatureReq>();
if(req.Sign.IsEmpty() == false)
{
DirtyStringSvc.DealDirtyStringCheck(player, DirtyStringCheckType.CSSetPersonalizedSignatureReq, ref req, req.Sign.GetString());
return;
}
GameServerUtils.GetPacketSender().SendToWorldServer<CSSetPersonalizedSignatureReq>(packet, player.UserID);
}
private void OnSetPersonalizedSignatureRes(uint serverID, StructPacket packet)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendHandler.OnSetPersonalizedSignatureRes no player object uid {0}", packet.ObjectID);
return;
}
SendToPlayer<CSSetPersonalizedSignatureRes>(player, packet);
}
private void ProcessFriendSetSettingReq(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("FriendHandler.ProcessOnFriendSetSettingReq no player object uid {0}", playerSession.UserID);
return;
}
GameServerUtils.GetPacketSender().SendToWorldServer<CSFriendSetSettingReq>(packet, player.UserID);
}
private void OnFriendSetSettingRes(uint serverID, StructPacket packet)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
TraceLog.Error("FriendHandler.OnFriendSetSettingRes no player object uid {0}", packet.ObjectID);
return;
}
SendToPlayer<CSFriendSetSettingRes>(player, packet);
}
private void OnCliFriendQueryBlacklistReq(PlayerOnGame player, StructPacket packet)
{
player.Trace("FriendHandler.OnCliQueryFriendListReq uid {0}", player.UserID);
SSQueryBlacklistReq ssreq = new SSQueryBlacklistReq();
ssreq.Uid = player.UserID;
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.QueryBlacklistReq, ref ssreq, player.UserID);
}
private void OnSvrQueryBlacklistRes(uint serverID, StructPacket packet)
{
ref SSQueryBlacklistRes ssres = ref packet.GetMessage<SSQueryBlacklistRes>();
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(ssres.Uid);
if (player == null)
{
TraceLog.Error("FriendHandler.OnSvrQueryFriendListRes no player object uid {0}", ssres.Uid);
return;
}
CSFriendQueryBlacklistRes csres = new CSFriendQueryBlacklistRes();
csres.Ret = 0;
csres.BlackList.CopyFrom(ref ssres.Blacklist);
SendToPlayer(player, (int)CSGameMsgID.FriendQueryBlacklistRes, ref csres);
}
}
}