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.
 
 
 
 
 
 

210 lines
8.6 KiB

using System;
using System.Linq;
using ProtoCSStruct;
using Sog;
namespace Rank
{
public class ActRankScv
{
public static void OnSetActRank(uint remoteAppID, StructPacket packet)
{
ref var res = ref packet.GetMessage<SSQueryActRankDbRes>();
if (res.ActRankId <= 0 || res.RealmId <= 0) return;
RankServerData serverData = RankServerUtils.GetRankServerData();
ActRemRank actRem = null;
serverData.m_ActRank.TryGetValue(res.RealmId, out actRem);
if (actRem != null)
{
//存在就不需要再加载了
if (actRem.m_AcRank.ContainsKey(res.ActRankId)) return;
}
else
{
actRem = new ActRemRank();
actRem.RealmId = res.RealmId;
serverData.m_ActRank.Add(res.RealmId, actRem);
}
//直接初始化个新榜单
if (res.Ret > 0)
{
ActRank.InitActRank(res.RealmId, res.ActRankId);
return;
}
var allplayerInfo = RankServerUtils.GetAllplayerInfo();
//加载db数据
ActRankOne rankOne = new ActRankOne();
rankOne.ActRankID = res.ActRankId;
rankOne.RealmId = res.RealmId;
rankOne.EndTime = res.EndTime;
rankOne.BeginTime = res.BeginTime;
rankOne.endClear = res.EndClear > 0;
for (int i = 0; i < res.RankData.RankList.Count; i++)
{
var uid = res.RankData.RankList[i];
if (!allplayerInfo.ContainsKey(uid))
{
TraceLog.Error("ActRankScv.OnSetActRank not get player info uid:{0}", uid);
continue;
}
rankOne.m_rankRank.Add(allplayerInfo[uid]);
}
actRem.m_AcRank.Add(res.ActRankId, rankOne);
TraceLog.Trace("ActRankScv.OnSetActRank load rank rem:{0} actId;{1} endClear:{2} rankCount:{3}", rankOne.RealmId, rankOne.ActRankID, rankOne.endClear.ToString(), rankOne.m_rankRank.Count);
}
public static void OnUpgradeActRankDataReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSAddActRankDataReq>();
RankServerData serverData = RankServerUtils.GetRankServerData();
ActRemRank actRem = null;
serverData.m_ActRank.TryGetValue(req.RealmId, out actRem);
if (actRem == null)
{
TraceLog.Error("ActRankScv.OnUpgradeActRankDataReq update rank error! no rem Rank. player:{0} rem:{1} actId:{2} param:{3} score:{4}",
packet.ObjectID, req.RealmId, req.ActRankId, req.Param, req.M_Rank.Score);
return;
}
ActRankOne rankOne = null;
actRem.m_AcRank.TryGetValue(req.ActRankId, out rankOne);
if (rankOne == null)
{
TraceLog.Error("ActRankScv.OnUpgradeActRankDataReq update rank error! no rank. player:{0} rem:{1} actId:{2} param:{3} score:{4}",
packet.ObjectID, req.RealmId, req.ActRankId, req.Param, req.M_Rank.Score);
return;
}
var res = new SSAddActRankDataRes();
var nowtime = RankServerUtils.GetTimeSecond();
if (rankOne.BeginTime > nowtime || rankOne.EndTime < nowtime)
{
TraceLog.Trace("ActRankScv.OnUpgradeActRankDataReq update rank not range rank time!");
return;
}
var allplayerInfo = RankServerUtils.GetAllplayerInfo();
if (allplayerInfo.ContainsKey(packet.ObjectID))
{
allplayerInfo[packet.ObjectID] = req.M_Rank;
}
else
{
allplayerInfo.TryAdd(packet.ObjectID, req.M_Rank);
}
var index = -1;
for (var i = rankOne.m_rankRank.Count - 1; i >= 0; i--)
{
if (rankOne.m_rankRank[i].Uid == packet.ObjectID)
{
rankOne.m_rankRank[i] = req.M_Rank;
index = i;
break;
}
}
if (index<0) rankOne.m_rankRank.Add(req.M_Rank);
rankOne.m_rankRank.Sort((one, two) =>
{
if (one.Score > two.Score)
{
return -1;
}
else if (one.Score == two.Score)
{
if (one.Time > two.Time)
{
return 1;
}
else
{
return -1;
}
}
else
{
return 1;
}
});
rankOne.MakeDirty();
RankServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.AddActRankDataRes, ref res, packet.ObjectID);
TraceLog.Trace("ActRankScv.OnUpgradeActRankDataReq update rank player:{0} rem:{1} actId:{2} param:{3} score:{4}", packet.ObjectID, req.RealmId, req.ActRankId, req.Param, req.M_Rank.Score);
}
public static void OnQueryActRankListReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<CSQueryActRankListReq>();
RankServerData serverData = RankServerUtils.GetRankServerData();
ActRemRank actRem = null;
serverData.m_ActRank.TryGetValue(req.RealmId, out actRem);
if (actRem == null)
{
TraceLog.Error("ActRankScv.OnQueryActRankListReq get rank error! no rem Rank. player:{0} rem:{1} actId:{2} ",
packet.ObjectID, req.RealmId, req.RankId);
return;
}
ActRankOne rankOne = null;
actRem.m_AcRank.TryGetValue(req.RankId, out rankOne);
if (rankOne == null)
{
TraceLog.Error("ActRankScv.OnQueryActRankListReq get rank error! no rank. player:{0} rem:{1} actId:{2}",
packet.ObjectID, req.RealmId, req.RankId);
return;
}
var res = new CSQueryActRankListRes();
var nowtime = RankServerUtils.GetTimeSecond();
if (rankOne.BeginTime > nowtime || rankOne.EndTime < nowtime)
{
res.Ret = CSErrCode.ActRankEndErr;
RankServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)CSGameMsgID.QueryActRankListRes, ref res, packet.ObjectID);
TraceLog.Trace("ActRankScv.OnQueryActRankListReq update rank not range rank time!");
return;
}
var myRank = -1;
for (var i = 0; i < rankOne.m_rankRank.Count; i++)
{
if (rankOne.m_rankRank[i].Uid == packet.ObjectID)
{
myRank = i + 1;
}
if (i >= req.StartPos - 1 && i <= req.EndPos - 1)
{
var one = rankOne.m_rankRank[i];
one.Rank = i + 1;
res.RankList.Add(ref one);
}
}
res.MyRank = myRank;
RankServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)CSGameMsgID.QueryActRankListRes, ref res, packet.ObjectID);
TraceLog.Trace("ActRankScv.OnQueryActRankListReq get rank player:{0} rem:{1} actId:{2} myRank:{3}", packet.ObjectID, req.RealmId, req.RankId, myRank);
}
public static void OnSaveActRankDataRes(uint remoteAppID, StructPacket packet)
{
ref var res = ref packet.GetMessage<SSSaveActRankDataRes>();
RankServerData serverData = RankServerUtils.GetRankServerData();
ActRemRank actRem = null;
serverData.m_ActRank.TryGetValue(res.RealmId, out actRem);
if (actRem == null)
{
TraceLog.Error("ActRankScv.OnSaveActRankDataRes get rank error! no rem Rank. player:{0} rem:{1} actId:{2} ",
packet.ObjectID, res.RealmId, res.ActRankId);
return;
}
ActRankOne rankOne = null;
actRem.m_AcRank.TryGetValue(res.ActRankId, out rankOne);
if (rankOne == null)
{
TraceLog.Error("ActRankScv.OnSaveActRankDataRes get rank error! no rank. player:{0} rem:{1} actId:{2}",
packet.ObjectID, res.RealmId, res.ActRankId);
return;
}
rankOne.SavedSuccessSeq = res.SuccessDataSeq;
}
}
}