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.
 
 
 
 
 
 

302 lines
12 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using ProtoCSStruct;
namespace World
{
public static class RankHandler
{
//public static void OnSaveRankDbRes(uint remoteAppID, StructPacket packet)
//{
// ref SSSaveRankDbRes res = ref packet.GetMessage<SSSaveRankDbRes>();
// WorldRankDataOne oneRank = RankUtils.GetWorldRankDataOne(res.RankId);
// if(oneRank == null)
// {
// TraceLog.Error("RankHandler.OnSaveRankDbRes rankId {0} beginTime {1}, not WorldRankDataOne in memory", res.RankId, res.BeginTime);
// return;
// }
// if(oneRank.CurRecord != null && oneRank.CurRecord.BeginTime == res.BeginTime)
// {
// oneRank.CurRecord.SavedSuccessSeq = res.DataSeq;
// TraceLog.Trace("RankHandler.OnSaveRankDbRes curRank rankId {0} beginTime {1} SavedSuccessSeq {2} newDataSeq {3}"
// , res.RankId, res.BeginTime, res.DataSeq, oneRank.CurRecord.DataSeq);
// return;
// }
// if (oneRank.LastRecord != null && oneRank.LastRecord.BeginTime == res.BeginTime)
// {
// oneRank.LastRecord.SavedSuccessSeq = res.DataSeq;
// TraceLog.Trace("RankHandler.OnSaveRankDbRes lastRank rankId {0} beginTime {1} SavedSuccessSeq {2} newDataSeq {3}"
// , res.RankId, res.BeginTime, res.DataSeq, oneRank.LastRecord.DataSeq);
// return;
// }
// TraceLog.Error("RankHandler.OnSaveRankDbRes rankId {0} beginTime {1}, not record in memory", res.RankId, res.BeginTime);
//}
private static WorldRankDataRecord GetRankDataRecordForClientQuery(int rankId)
{
WorldRankDataOne rankDataOne = RankUtils.GetWorldRankDataOne(rankId);
if (rankDataOne == null)
{
TraceLog.Error("RankHandler.GetRankDataRecordForClientQuery rankId {0} not exist", rankId);
return null;
}
if (rankDataOne.CurRecord == null || rankDataOne.LastRecord == null)
{
TraceLog.Error("RankHandler.GetRankDataRecordForClientQuery rankId {0} not exist record", rankId);
return null;
}
RankConfigDesc rankDesc = RankConfigDescMgr.Instance.GetConfig(rankId);
if(rankDesc == null)
{
TraceLog.Error("RankHandler.GetRankDataRecordForClientQuery rankId {0} not config desc", rankId);
return null;
}
long nowSecond = WorldServerUtils.GetTimeSecond();
//周
if(rankDesc.refreshType == 1)
{
//查询当期榜
if(nowSecond - rankDataOne.CurRecord.BeginTime > 10800)
{
return rankDataOne.CurRecord;
}
TraceLog.Trace("RankHandler.GetRankDataRecordForClientQuery rankId {0} return last record, nowsecond {1} rankDataOne.CurRecord.BeginTime {2}"
, rankId, nowSecond, rankDataOne.CurRecord.BeginTime);
//上个榜
return rankDataOne.LastRecord;
}
//日
if(rankDesc.refreshType == 2)
{
//查询当期榜
if (nowSecond - rankDataOne.CurRecord.BeginTime > 10800)
{
return rankDataOne.CurRecord;
}
//上个榜
return rankDataOne.LastRecord;
}
return null;
}
//public static void OnCliQueryRankListReq(uint remoteAppID, StructPacket packet)
//{
// ref CSQueryRankListReq req = ref packet.GetMessage<CSQueryRankListReq>();
// TraceLog.Trace("RankHandler.OnCliQueryRankListReq rankId {0} pos {1} uid {2}", req.RankId, req.StartPos, packet.ObjectID);
// if(req.StartPos <= 0)
// {
// TraceLog.Trace("RankHandler.OnCliQueryRankListReq invalid StartPos rankId {0} pos {1} uid {2}"
// , req.RankId, req.StartPos, packet.ObjectID);
// return;
// }
// RankConfigDesc rankDesc = RankConfigDescMgr.Instance.GetConfig(req.RankId);
// if (rankDesc == null)
// {
// TraceLog.Error("RankHandler.OnCliQueryRankListReq rankId {0} not config desc", req.RankId);
// return ;
// }
// WorldRankDataRecord rankRecord = GetRankDataRecordForClientQuery(req.RankId);
// if(rankRecord == null)
// {
// TraceLog.Trace("RankHandler.OnCliQueryRankListReq GetRankDataRecordForClientQuery null rankId {0} pos {1} uid {2}"
// , req.RankId, req.StartPos, packet.ObjectID);
// return;
// }
// //补丁
// if (rankRecord.Data.RankList.Count > 0 && rankRecord.RankDict.Count == 0)
// {
// for(int i =0;i< rankRecord.Data.RankList.Count;i++)
// {
// rankRecord.RankDict.Add(rankRecord.Data.RankList[i].Uid, rankRecord.Data.RankList[i]);
// }
// }
// CSQueryRankListRes res = new CSQueryRankListRes();
// res.RankId = req.RankId;
// res.Ret = 0;
// res.Version = rankRecord.RankDataVersion;
// res.MaxCount = rankRecord.Data.RankList.Count;
// //根据版本号确定查询的头部和尾部
// //如果版本号不同,则需要发客户端头3个
// if (req.Version != res.Version && req.StartPos > 1)
// {
// for (int i = 0; i < 3 && i < rankRecord.Data.RankList.Count; i++)
// {
// DBRankPlayerInfo rankPlayer = rankRecord.Data.RankList[i];
// CSRankPlayerOne csPlayerOne = RankUtils.MakeCSRankPlayerOneFromDBRankPlayerInfo(rankPlayer);
// csPlayerOne.Rank = i + 1;
// res.RankList.Add(csPlayerOne);
// }
// }
// int queryCountOneTime = 12;
// int queryCount = 0;
// for(int i= req.StartPos -1; i < rankDesc.listCount && i < rankRecord.Data.RankList.Count; i++)
// {
// DBRankPlayerInfo rankPlayer = rankRecord.Data.RankList[i];
// CSRankPlayerOne csPlayerOne = RankUtils.MakeCSRankPlayerOneFromDBRankPlayerInfo(rankPlayer);
// csPlayerOne.Rank = i + 1;
// res.RankList.Add(csPlayerOne);
// queryCount++;
// if(queryCount >= queryCountOneTime)
// {
// break;
// }
// }
// //每次返回自己
// if (rankRecord.RankDict.ContainsKey(packet.ObjectID))
// {
// for (int i = 0; i < rankDesc.listCount && i < rankRecord.Data.RankList.Count; i++)
// {
// DBRankPlayerInfo rankPlayer = rankRecord.Data.RankList[i];
// if (rankPlayer.Uid == packet.ObjectID)
// {
// CSRankPlayerOne csPlayerOne = RankUtils.MakeCSRankPlayerOneFromDBRankPlayerInfo(rankPlayer);
// csPlayerOne.Rank = i + 1;
// res.RankList.Add(csPlayerOne);
// break;
// }
// }
// }
// WorldServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)CSGameMsgID.QueryRankListRes, ref res, packet.ObjectID);
//}
//public static void OnCliQueryRankSelfReq(uint remoteAppID, StructPacket packet)
//{
// ref CSQueryRankSelfReq req = ref packet.GetMessage<CSQueryRankSelfReq>();
// TraceLog.Trace("RankHandler.OnCliQueryRankSelfReq rankId {0} uid {1}", req.RankId, packet.ObjectID);
// RankConfigDesc rankDesc = RankConfigDescMgr.Instance.GetConfig(req.RankId);
// if (rankDesc == null)
// {
// TraceLog.Error("RankHandler.OnCliQueryRankSelfReq rankId {0} not config desc", req.RankId);
// return;
// }
// WorldRankDataRecord rankRecord = GetRankDataRecordForClientQuery(req.RankId);
// if (rankRecord == null)
// {
// TraceLog.Trace("RankHandler.OnCliQueryRankSelfReq GetRankDataRecordForClientQuery null rankId {0} uid {1}"
// , req.RankId, packet.ObjectID);
// return;
// }
// //补丁
// if(rankRecord.Data.RankList.Count > 0 && rankRecord.RankDict.Count == 0)
// {
// for(int i = 0;i<rankRecord.Data.RankList.Count;i++)
// {
// rankRecord.RankDict.Add(rankRecord.Data.RankList[i].Uid, rankRecord.Data.RankList[i]);
// }
// }
// CSQueryRankSelfRes res = new CSQueryRankSelfRes();
// res.RankId = req.RankId;
// res.Ret = 0;
// if(rankRecord.RankDict.ContainsKey(packet.ObjectID))
// {
// for (int i = 0; i < rankDesc.listCount && i < rankRecord.Data.RankList.Count; i++)
// {
// DBRankPlayerInfo rankPlayer = rankRecord.Data.RankList[i];
// if (rankPlayer.Uid == packet.ObjectID)
// {
// CSRankPlayerOne csPlayerOne = RankUtils.MakeCSRankPlayerOneFromDBRankPlayerInfo(rankPlayer);
// csPlayerOne.Rank = i + 1;
// res.SelfInfo = csPlayerOne;
// break;
// }
// }
// }
// WorldServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)CSGameMsgID.QueryRankSelfRes, ref res, packet.ObjectID);
//}
//public static void OnCliQueryRankDetailReq(uint remoteAppID, StructPacket packet)
//{
// ref CSQueryRankDetailReq req = ref packet.GetMessage<CSQueryRankDetailReq>();
// TraceLog.Trace("RankHandler.OnCliQueryRankDetailReq rankId {0} uid {1}", req.RankId, packet.ObjectID);
// RankConfigDesc rankDesc = RankConfigDescMgr.Instance.GetConfig(req.RankId);
// if (rankDesc == null)
// {
// TraceLog.Error("RankHandler.OnCliQueryRankDetailReq rankId {0} not config desc", req.RankId);
// return;
// }
// WorldRankDataRecord rankRecord = GetRankDataRecordForClientQuery(req.RankId);
// if (rankRecord == null)
// {
// TraceLog.Trace("RankHandler.OnCliQueryRankDetailReq GetRankDataRecordForClientQuery null rankId {0} uid {1}"
// , req.RankId, packet.ObjectID);
// return;
// }
// CSQueryRankDetailRes res = new CSQueryRankDetailRes();
// res.RankId = req.RankId;
// res.Ret = 0;
// res.Uid = req.Uid;
// if (rankRecord.RankDict.ContainsKey(packet.ObjectID))
// {
// for (int i = 0; i < rankDesc.listCount && i < rankRecord.Data.RankList.Count; i++)
// {
// DBRankPlayerInfo rankPlayer = rankRecord.Data.RankList[i];
// if (rankPlayer.Uid == packet.ObjectID)
// {
// res.DetailInfo = rankPlayer;
// break;
// }
// }
// }
// WorldServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)CSGameMsgID.QueryRankDetailRes, ref res, packet.ObjectID);
//}
}
}