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.
297 lines
14 KiB
297 lines
14 KiB
1 month ago
|
using ProtoCSStruct;
|
||
|
using Sog;
|
||
|
|
||
|
|
||
|
namespace World
|
||
|
{
|
||
|
public static class QueryRoleInfoSvc
|
||
|
{
|
||
|
public static CSPlayerQueryOtherRoleInfoRes queryRes = new CSPlayerQueryOtherRoleInfoRes();
|
||
|
|
||
|
//保证serverId哪里来的返回到哪去,packet.ObjectID 保证为发起查询的玩家uid
|
||
|
public static void OnPlayerQueryOtherRoleInfoReq(uint serverId, StructPacket packet)
|
||
|
{
|
||
|
ref CSPlayerQueryOtherRoleInfoReq req = ref packet.GetMessage<CSPlayerQueryOtherRoleInfoReq>();
|
||
|
|
||
|
PlayerInfoWorld fromPlayer = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
|
||
|
if (fromPlayer == null || fromPlayer.IsOnline == false)
|
||
|
{
|
||
|
TraceLog.Error("fromPlayer uid {0} is not exist or offline", packet.ObjectID);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
long nowSec = WorldServerUtils.GetTimeSecond();
|
||
|
PlayerInfoWorld targetPlayer = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(req.TargetUid);
|
||
|
|
||
|
SSPlayerQueryOfflineRoleReq query = new SSPlayerQueryOfflineRoleReq();
|
||
|
query.TargetUid = req.TargetUid;
|
||
|
query.FromUid = packet.ObjectID;
|
||
|
query.FromRealm = fromPlayer.RealmID;
|
||
|
query.FromServerID = serverId; //这个不定是从GameServer来的,有可能是FriendServer等服务器来的
|
||
|
query.QueryRoleType = req.QueryRoleType;
|
||
|
|
||
|
TraceLog.Trace("QueryRoleInfoSvc.OnPlayerQueryOtherRoleInfoReq req fromUid {0} targetUid {1} fromRealm {2} fromServerID {3} queryRoleType {4}",
|
||
|
packet.ObjectID, req.TargetUid, fromPlayer.RealmID, serverId, req.QueryRoleType);
|
||
|
|
||
|
//1:是否机器人
|
||
|
if (RobotUtils.IsRobotByUid(req.TargetUid))
|
||
|
{
|
||
|
SendQueryRobotResToServer(serverId, req.TargetUid, packet.ObjectID, fromPlayer.RealmID, req.QueryRoleType);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//2:在线
|
||
|
if (targetPlayer != null && targetPlayer.IsOnline)
|
||
|
{
|
||
|
//领地查看无视逻辑服限制
|
||
|
if ( !WorldServerUtils.CheckIsSameLogicWorld(fromPlayer.RealmID, targetPlayer.RealmID))
|
||
|
{
|
||
|
//不是同一个logicWorld
|
||
|
TraceLog.Error("QueryRoleInfoSvc.OnPlayerQueryOtherRoleInfoReq not same logicWorld from {0} {1} target {2} {3}",
|
||
|
fromPlayer.UserID, fromPlayer.RealmID, targetPlayer.UserID, targetPlayer.RealmID);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//这里借用下SSPlayerQueryOfflineRoleReq这个去game服务器
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(targetPlayer.GameServerID, (int)SSGameMsgID.PlayerQueryOfflineRoleReq, ref query, packet.ObjectID);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//3:不在线,看看缓存中有没有
|
||
|
ref OneRoleCacheStruct oneCache = ref WorldServerUtils.GetRoleCacheInfoSvc().GetOneRoleCacheStructByUid(req.TargetUid);
|
||
|
if (oneCache.IsNull() == false)
|
||
|
{
|
||
|
//领地查看无视逻辑服限制
|
||
|
if (!WorldServerUtils.CheckIsSameLogicWorld(fromPlayer.RealmID, oneCache.realmId))
|
||
|
{
|
||
|
//不是同一个logicWorld
|
||
|
TraceLog.Error("QueryRoleInfoSvc.OnPlayerQueryOtherRoleInfoReq not same logicWorld from {0} {1} target {2} {3}",
|
||
|
fromPlayer.UserID, fromPlayer.RealmID, req.TargetUid, oneCache.realmId);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//更新下访问时间
|
||
|
oneCache.LastAccessTime = nowSec;
|
||
|
|
||
|
SendQueryResToServer(serverId, packet.ObjectID, ref oneCache, req.QueryRoleType);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//4:都没有只能去数据库看看
|
||
|
//发送查询玩家信息的协议到DB,返回world处理
|
||
|
uint dbServerID = DBServerIDUtils.GetGameDBServerID(req.TargetUid);
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(dbServerID, (int)SSGameMsgID.PlayerQueryOfflineRoleReq, ref query, packet.ObjectID);
|
||
|
}
|
||
|
|
||
|
public static void OnPlayerQueryOfflineRoleRes(StructPacket packet)
|
||
|
{
|
||
|
ref SSPlayerQueryOfflineRoleRes res = ref packet.GetMessage<SSPlayerQueryOfflineRoleRes>();
|
||
|
if (res.Ret != CSErrCode.None)
|
||
|
{
|
||
|
SendErrQueryResToServer(res.CallBackReq.FromServerID, res.CallBackReq.FromUid, res.Ret, res.CallBackReq.QueryRoleType);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (!WorldServerUtils.CheckIsSameLogicWorld(res.CallBackReq.FromRealm, res.TargetRealmId))
|
||
|
{
|
||
|
//不是同一个logicWorld
|
||
|
TraceLog.Error("QueryRoleInfoSvc.OnPlayerQueryOfflineRoleRes not same logicWorld from {0} {1} target {2} {3}",
|
||
|
res.CallBackReq.FromUid, res.CallBackReq.FromRealm, res.CallBackReq.TargetUid, res.TargetRealmId);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (res.TargetIsOnline == false)
|
||
|
{
|
||
|
//创建一个缓存数据
|
||
|
ref OneRoleCacheStruct one = ref WorldServerUtils.GetRoleCacheInfoSvc().AddOneRoleCacheByUid(res.CallBackReq.TargetUid);
|
||
|
if (one.IsNull())
|
||
|
{
|
||
|
SendErrQueryResToServer(res.CallBackReq.FromServerID, res.CallBackReq.FromUid, CSErrCode.Fail, res.CallBackReq.QueryRoleType);
|
||
|
return;
|
||
|
}
|
||
|
one.realmId = res.TargetRealmId;
|
||
|
//缓存下数据
|
||
|
CopyDBRoleInfoToRoleCacheStruct(ref res, ref one);
|
||
|
//哪里来的通知到哪里去
|
||
|
SendQueryResToServer(res.CallBackReq.FromServerID, res.CallBackReq.FromUid, ref one, res.CallBackReq.QueryRoleType);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
OneRoleCacheStruct one = new OneRoleCacheStruct();
|
||
|
one.realmId = res.TargetRealmId;
|
||
|
CopyDBRoleInfoToRoleCacheStruct(ref res, ref one);
|
||
|
//哪里来的通知到哪里去
|
||
|
SendQueryResToServer(res.CallBackReq.FromServerID, res.CallBackReq.FromUid, ref one, res.CallBackReq.QueryRoleType);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void CopyDBRoleInfoToRoleCacheStruct(ref SSPlayerQueryOfflineRoleRes res, ref OneRoleCacheStruct one)
|
||
|
{
|
||
|
one.LastAccessTime = WorldServerUtils.GetTimeSecond();
|
||
|
one.LastUpdateTime = WorldServerUtils.GetTimeSecond();
|
||
|
FillRoleBaseInfo(ref res.RoleBase, ref res.RoleData, ref one.showInfo.RoleBaseInfo);
|
||
|
long nowSec = WorldServerUtils.GetTimeSecond();
|
||
|
one.showInfo.HeroInfo.PropView.Knight.PropVal.Clear();
|
||
|
|
||
|
HeroPropUtils.FillHeroInfo(ref one.showInfo.HeroInfo, ref res.RoleData);
|
||
|
}
|
||
|
|
||
|
public static void FillRoleBaseInfo(ref DBRoleBase roleBase, ref DBRoleData roleData, ref RoleBaseInfo roleBaseInfo)
|
||
|
{
|
||
|
roleBaseInfo.Uid = roleBase.Uid;
|
||
|
roleBaseInfo.Level = roleBase.Level;
|
||
|
roleBaseInfo.Gender = roleBase.Gender;
|
||
|
roleBaseInfo.Icon.SetString(roleBase.Icon.ToString());
|
||
|
roleBaseInfo.Nick.SetString(roleBase.Nick.ToString());
|
||
|
roleBaseInfo.IconFrameId = roleData.IconFrameData.IconFrameId;
|
||
|
roleBaseInfo.Power = (int)roleBase.Power;
|
||
|
}
|
||
|
|
||
|
private static void SendErrQueryResToServer(uint fromServerID, long fromUid, CSErrCode ret, QueryRoleType queryRoleType)
|
||
|
{
|
||
|
queryRes.Clear();
|
||
|
queryRes.Ret = ret;
|
||
|
queryRes.FromUid = fromUid;
|
||
|
queryRes.QueryRoleType = queryRoleType;
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(fromServerID,
|
||
|
(int)CSGameMsgID.PlayerQueryOtherRoleInfoRes, ref queryRes, fromUid);
|
||
|
}
|
||
|
|
||
|
private static void SendQueryResToServer(uint serverId, long fromUid, ref OneRoleCacheStruct oneCache, QueryRoleType queryRoleType)
|
||
|
{
|
||
|
queryRes.Clear();
|
||
|
queryRes.Ret = CSErrCode.None;
|
||
|
queryRes.FromUid = fromUid;
|
||
|
queryRes.TargetRealmId = oneCache.realmId;
|
||
|
queryRes.ShowInfo = oneCache.showInfo;
|
||
|
queryRes.QueryRoleType = queryRoleType;
|
||
|
queryRes.ShowInfo.RoleBaseInfo.RealmName.SetString(WorldServerUtils.GetRealmName(queryRes.TargetRealmId));
|
||
|
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(serverId, (int)CSGameMsgID.PlayerQueryOtherRoleInfoRes, ref queryRes, fromUid);
|
||
|
}
|
||
|
|
||
|
private static void SendQueryRobotResToServer(uint serverId, long uid, long fromUid, int realmID, QueryRoleType queryRoleType)
|
||
|
{
|
||
|
queryRes.Clear();
|
||
|
queryRes.Ret = CSErrCode.None;
|
||
|
queryRes.FromUid = fromUid;
|
||
|
queryRes.TargetRealmId = realmID;
|
||
|
queryRes.QueryRoleType = queryRoleType;
|
||
|
RobotUtils.FillRobotInfo(uid, ref queryRes.ShowInfo);
|
||
|
queryRes.ShowInfo.RoleBaseInfo.RealmName.SetString(WorldServerUtils.GetRealmName(queryRes.TargetRealmId));
|
||
|
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(serverId, (int)CSGameMsgID.PlayerQueryOtherRoleInfoRes, ref queryRes, fromUid);
|
||
|
}
|
||
|
|
||
|
public static void OnTick5Second(long nowSec)
|
||
|
{
|
||
|
//1:如果有玩家登录的时候,也要移除下缓存里面的数据(现在不弄,之后看移植到哪里去)
|
||
|
|
||
|
//2:如果空间快满了,缓存超过10分钟就删除,一次删除一个
|
||
|
RoleCacheInfoSvc cacheInfo = WorldServerUtils.GetRoleCacheInfoSvc();
|
||
|
if (cacheInfo.RoleCacheIsFull() == false)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
long rmUid = 0;
|
||
|
foreach (var uid_pos in cacheInfo.m_selfIDMap)
|
||
|
{
|
||
|
ref OneRoleCacheStruct one = ref cacheInfo.GetOneRoleCacheStructByUid(uid_pos.Key);
|
||
|
if (one.IsNull() == false && one.LastAccessTime + 600 >= nowSec)
|
||
|
{
|
||
|
rmUid = uid_pos.Key;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (rmUid > 0)
|
||
|
{
|
||
|
cacheInfo.RemoveOneRoleCacheByUid(rmUid);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//搜索玩家
|
||
|
public static void OnPlayerSearchRoleBynameReq(StructPacket packet)
|
||
|
{
|
||
|
ref CSPlayerSearchRoleByNameReq req = ref packet.GetMessage<CSPlayerSearchRoleByNameReq>();
|
||
|
if (req.TargetName.Length == 0)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
PlayerInfoWorld fromPlayer = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
|
||
|
if (fromPlayer == null || fromPlayer.IsOnline == false)
|
||
|
{
|
||
|
TraceLog.Error("OnPlayerSearchRoleBynameReq fromPlayer uid {0} is not exist or offline", packet.ObjectID);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SSPlayerSearchRoleDBByNameReq dbReq = new SSPlayerSearchRoleDBByNameReq();
|
||
|
dbReq.FromUid = fromPlayer.UserID;
|
||
|
dbReq.TargetName = req.TargetName;
|
||
|
dbReq.FromRealm = fromPlayer.RealmID;
|
||
|
|
||
|
uint dbServerID = DBServerIDUtils.GetGameDBServerID(fromPlayer.UserID);
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(dbServerID, (int)SSGameMsgID.PlayerSearchRoledbBynameReq, ref dbReq, packet.ObjectID);
|
||
|
}
|
||
|
|
||
|
public static void OnPlayerSearchRoledbBynameRes(StructPacket packet)
|
||
|
{
|
||
|
ref SSPlayerSearchRoleDBByNameRes res = ref packet.GetMessage<SSPlayerSearchRoleDBByNameRes>();
|
||
|
|
||
|
PlayerInfoWorld fromPlayer = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(res.FromUid);
|
||
|
if (fromPlayer == null || fromPlayer.IsOnline == false)
|
||
|
{
|
||
|
TraceLog.Error("fromPlayer uid {0} is not exist or offline", packet.ObjectID);
|
||
|
return;
|
||
|
}
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(fromPlayer.GameServerID, (int)SSGameMsgID.PlayerSearchRoledbBynameRes, ref res, packet.ObjectID);
|
||
|
}
|
||
|
|
||
|
public static void OnQueryRoleBaseInfoListReq(uint remoteAppID, StructPacket packet)
|
||
|
{
|
||
|
ref SSQueryRoleBaseInfoListReq req = ref packet.GetMessage<SSQueryRoleBaseInfoListReq>();
|
||
|
|
||
|
PlayerInfoWorld fromPlayer = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(packet.ObjectID);
|
||
|
if (fromPlayer == null || fromPlayer.IsOnline == false)
|
||
|
{
|
||
|
TraceLog.Error("QueryRoleInfoSvc.OnQueryRoleBaseInfoListReq fromPlayer uid {0} is not exist or offline", packet.ObjectID);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SSQueryRoleBaseInfoListRes res = new SSQueryRoleBaseInfoListRes();
|
||
|
res.Type = req.Type;
|
||
|
|
||
|
for (int i = 0; i < req.RoleBaseInfoList.Count; i++)
|
||
|
{
|
||
|
PlayerInfoWorld targetPlayer = WorldServerUtils.GetPlayerTableOp().GetPlayerInfo(req.RoleBaseInfoList[i].Uid);
|
||
|
if(targetPlayer != null) //优先以PlayerInfoWorld为准
|
||
|
{
|
||
|
RoleBaseInfo roleBaseInfo = new RoleBaseInfo();
|
||
|
DBRoleData roleData = new DBRoleData();
|
||
|
FillRoleBaseInfo(ref targetPlayer.roleBase, ref roleData, ref roleBaseInfo);
|
||
|
roleBaseInfo.ChatBlackTime = req.RoleBaseInfoList[i].ChatBlackTime;
|
||
|
res.RoleBaseInfoList.Add(roleBaseInfo);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ref OneRoleCacheStruct oneCache = ref WorldServerUtils.GetRoleCacheInfoSvc().GetOneRoleCacheStructByUid(req.RoleBaseInfoList[i].Uid);
|
||
|
if (oneCache.IsNull() == false)
|
||
|
{
|
||
|
RoleBaseInfo roleBaseInfo = new RoleBaseInfo();
|
||
|
roleBaseInfo.CopyFrom(ref oneCache.showInfo.RoleBaseInfo);
|
||
|
roleBaseInfo.ChatBlackTime = req.RoleBaseInfoList[i].ChatBlackTime;
|
||
|
res.RoleBaseInfoList.Add(roleBaseInfo); //不在线的话,以缓存的为主
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
res.RoleBaseInfoList.Add(req.RoleBaseInfoList[i]); //缓存没有,就以发来的进行返回
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
WorldServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.QueryRoleBaseInfoListRes, ref res, packet.ObjectID);
|
||
|
}
|
||
|
}
|
||
|
}
|