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.
 
 
 
 
 
 

249 lines
11 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using Sog.Service;
using ProtoCSStruct;
namespace Friend
{
public class FriendMsgHandler : BaseReloadableService
{
private ServerApp m_app;
public override int GetServiceType()
{
return FriendServiceType.FriendMsgHandler;
}
//销毁的时候置空
public override void Dispose()
{
m_app = null;
}
public FriendMsgHandler(ServerApp app)
{
m_app = app;
}
public ServerApp GetApp()
{
return m_app;
}
public void HandlerMessage(uint remoteAppID, MessageData message)
{
StructPacket packet;
bool bSuccess = FriendServerUtils.GetProtoPacker().UnpackMessage(message, out packet);
if (bSuccess == false)
{
TraceLog.Error("HandlerMessage ,unpack msg failed {0}, remoteAppID {1}", message.Header.Type, remoteAppID);
return;
}
//因为需要放入每个线程的队列,所以需要clone 一个新的对象,UnpackMessage出来的消息每次其实是同一个
//如果存在性能问题,可以根据消息类型进行缓冲
//packet = packet.Clone();
//预先判断,提高效率
if (TraceLog.GetLogLevel() <= (int)Sog.Log.LogLevel.TraceDetail && TraceLog.IsSkipLogMsgID(packet.MsgID) == false)
{
TraceLog.TraceDetail("recv message from server {0}, message type {1} length {2} : {3}->{4}"
, Sog.ServerIDUtils.IDToString(remoteAppID)
, message.Header.Type
, message.Header.Length
, packet.MessageName()
, packet.ToString());
}
switch (packet.MsgID)
{
#region login
case (int)SSMsgID.LoginCheckValidRes: //玩家登录成功时,world发过来的
LoginSvc.OnLoginCheckRes(remoteAppID, packet);
break;
case (int)SSGameMsgID.QueryRoleDbRes: //玩家查询角色成功后,world通知
LoginSvc.OnQueryRoleRes(remoteAppID, packet);
break;
case (int)SSGameMsgID.SaveRoleNotify: //玩家保存角色信息时(Game连了Friend,gameServer直接发过来的)
LoginSvc.OnSaveRoleNotify(remoteAppID, packet);
break;
case (int)SSGameMsgID.RoleLoginSuccessNotify: // 登录成功通知
LoginSvc.OnRoleLoginSucc(remoteAppID, packet);
break;
case (int)SSGameMsgID.GamePlayerDestroy://world通知过来(不销毁PlayerInfoFriend,在PlayerTickSvc中销毁)
LoginSvc.OnPlayerOffline(remoteAppID, packet);
break;
#endregion
case (int)CSGameMsgID.MailSendToPlayerReq: //好友送钱 判断是否是好友
FriendSvc.OnCliSendMailToPlayerReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.FriendGiftOpReq: // 单个好友礼物赠送领取
FriendSvc.OnFriendGiftOpReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.FriendGiftAutoOpReq: // 一键自动赠送领取好友领悟
FriendSvc.OnFriendGiftAutoOpReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.GetFriendGiftDataReq: // 拉取礼物相关的完整数据
FriendSvc.OnGetFriendGiftDataReq(remoteAppID, packet);
break;
// 收到其他好友服务器发来的赠送礼物通知
case (int)CSGameMsgID.FriendSendGiftNotify:
FriendSvc.OnFriendSendGiftNotify(remoteAppID, packet);
break;
case (int)SSGameMsgID.MailOpRes: //应答,目前版本好友好像就送体力(感觉送体力不用邮件更好,可以像好友列表一样再做个 领取体力列表,记录好友赠送的体力)
MailSvc.OnMailOpRes(remoteAppID, packet);
break;
#region Friend
case (int)SSGameMsgID.QueryFriendListReq: //game->Friend 查询玩家好友列表
FriendSvc.OnQueryFriendListReq(remoteAppID, packet);
break;
case (int)SSGameMsgID.QueryBlacklistReq: //game->Friend 查询黑名单列表
FriendSvc.OnQueryBlacklistReq(remoteAppID, packet);
break;
case (int)SSGameMsgID.QueryFriendListRes: //gameDb返回的我的好友列表
FriendSvc.OnQueryFriendListRes(remoteAppID, packet);
break;
// 其他friendSvr发过来的查询请求
case (int)SSGameMsgID.QueryFriendInfoCacheReq:
FriendCacheSvc.OnQueryFriendInfoCacheReqFromOtherFriendSvr(remoteAppID, packet);
break;
// DB或者其他friendsvr返回的好友数据
case (int)SSGameMsgID.QueryFriendInfoCacheRes:
FriendCacheSvc.OnQueryFriendInfoCacheResFromDB(remoteAppID, packet);
break;
case (int)SSGameMsgID.FriendSelfChgNotify:
FriendCacheSvc.OnFriendSelfChgFromOtherSvr(remoteAppID, packet);
break;
// friendOp双方不在同一服务器时, 收到来自另一个friendsvr的好友操作请求
case (int)SSGameMsgID.FriendOpReq:
FriendOpSvc.OnFriendOpReqFromOtherFriendSvr(remoteAppID, packet);
break;
// friendOp双方不在同一服务器时, 收到target所在friendsvr返回的操作结果
case (int)SSGameMsgID.FriendOpRes:
FriendOpSvc.OnFriendOpResFromOtherFriendSvr(remoteAppID, packet);
break;
// 好友操作最终结果同步消息
case (int)SSGameMsgID.FriendOpFinalResult:
FriendOpSvc.OnFriendOpFinalResultFromOtherFriendSvr(remoteAppID, packet);
break;
case (int)SSMsgID.QuerySnsFriendAccountRes: //SendAccountQuerySnsFriendList 这个没有发,所以这个也不存在返回,用来处理 QQ 微信 好友用,现在暂时不用处理
FriendSnsSvc.OnQuerySnsFriendAccountRes(remoteAppID, packet);
break;
case (int)SSGameMsgID.SaveFriendListRes: //在tick中保存好友数据
FriendSvc.OnSaveFriendListRes(remoteAppID, packet);
break;
case (int)CSGameMsgID.QueryFriendOpReq: //客户端查询好友操作信息,包含操作 聊天 陌生人数据
FriendOpSvc.OnCliQueryFriendOpReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.FriendOpReq: //客户端操作请求
FriendOpSvc.OnCliFriendOpReq(remoteAppID, packet);
break;
case (int)SSGameMsgID.FriendPlayerStatChgNotify: //先保留,玩家统计数据改变后gameserver通知(现在应该没用了,如果统计数据不排名的话)
FriendRankSvc.OnFriendPlayerStatChgNotify(remoteAppID, packet);
break;
//case (int)CSGameMsgID.GetSignRewardReq: //先保留,这里返回活跃好友数量用于领奖,之后看需求
// FriendSvc.OnCliGetSignRewardReq(remoteAppID, packet);
// break;
//查询玩家基本信息(一个DBFriendOne,无法隐藏,可以不是好友(主要用于好友)
//之后也可能要废弃,和QueryOtherDetailReq基本类似,但是不适用现在的,只是个dbfriendone,后期看)
case (int)CSGameMsgID.FriendQueryInfoByUidReq:
FriendRecommenderSvc.OnCliFriendQueryInfoByUidReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.FriendGetRecommenderReq: //获取推荐好友
FriendRecommenderSvc.OnCliFriendGetRecommenderReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.HideMyInfoReq: //隐藏信息不给玩家查询
FriendSvc.ProcessHideMyInfoReq(remoteAppID, packet);
break;
//查看玩家的详细信息(一个DBFriendSelf,可以隐藏,可以不是好友(主要用于好友),
//但是不在线的查询不了,之后可能需要废弃,我这边有单独再提供一个查询所有玩家的)
case (int)CSGameMsgID.QueryOtherDetailReq:
FriendSvc.OnQueryOtherDetailReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.FriendQueryStrangerReq: //获取好友中的陌生人信息
FriendStrangerSvc.OnCliFriendQueryStrangerReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.FriendSetSettingReq: //好友设置 请求
FriendSettingSvc.OnCliFriendSetSettingReq(remoteAppID, packet);
break;
case (int)CSGameMsgID.ChatReq: // 离线私聊
ChatSvc.OnChatReq(remoteAppID, packet);
break;
case (int)SSGameMsgID.PrivateChatNotify: // target服务器收到send服务器发来的私聊通知
ChatSvc.OnPrivateChatNotify(remoteAppID, packet);
break;
case (int)CSGameMsgID.QueryChatDataReq: // chatsvr拉取聊天数据
ChatSvc.OnQueryChatDataReq(remoteAppID, packet);
break;
#endregion
#region Sys
case (int)SSGameMsgID.UpdateRolebaseToWorld: //通过game更新玩家数据
SysSvc.OnUpdateRolebaseToWorld(remoteAppID, packet);
break;
case (int)SSGameMsgID.UpdateRoleDataToWorld: //更新玩家数据(这里主要是黑名单数据)
SysSvc.OnUpdateRoleDataToWorld(remoteAppID, packet);
break;
case (int)SSGameMsgID.AddServerTimeSync:
SysSvc.OnAddServerTimeSync(remoteAppID, packet);
break;
case (int)SSGameMsgID.RankRealmlistRes:
SysSvc.OnGetRealmlistRes(remoteAppID, packet);
break;
case (int)CSGameMsgID.PlayerQueryOtherRoleInfoRes:
QueryPlayerAndCallBack.OnPlayerQueryOtherRoleInfoRes(remoteAppID, packet);
break;
case (int)SSGameMsgID.DealgmcmdNotify:
GmCmdSvc.OnDealGmCmd(packet);
break;
#endregion
default:
TraceLog.Error("FriendMsgHandler unknow MsgID {0}", packet.MsgID);
break;
}
}
}
}