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.
 
 
 
 
 
 

127 lines
4.0 KiB

using Sog;
using ProtoCSStruct;
using System.Runtime.ConstrainedExecution;
using Sog.Log;
using Sog.Service;
namespace Mail
{
public class PlayerMailVerSeqSvc
{
public static long GetPlayerMailVerSeq(PlayerInfoMail playerInfo)
{
if(!playerInfo.isQueryMailVer)
{
return long.MaxValue;
}
return playerInfo.lastMailVer;
}
public static void Tick(long nowMs)
{
var data = MailServerUtils.GetMailServerData();
var players = data.m_playerTable;
int count = 0;
foreach(var player in players.Values)
{
if(SaveMailVer(player, nowMs))
{
count++;
}
if(count > 1000)
{
break;
}
}
}
public static bool IsCanStop()
{
var data = MailServerUtils.GetMailServerData();
var players = data.m_playerTable;
foreach (var player in players.Values)
{
if(player.IsDirty())
{
TraceLog.Debug("PlayerMailVerSeqSvc.IsCanStop false player {0} IsDirty", player.UserID);
return false;
}
}
return true;
}
public static void SetPlayerVerSeq(PlayerInfoMail player, long ver)
{
if (player.lastMailVer < ver)
{
player.lastMailVer = ver;
player.MakeDirty();
TraceLog.Debug("PlayerMailVerSeqSvc.SetPlayerVerSeq uid {0} ver {1}", player.UserID, ver);
}
}
public static bool SaveMailVer(PlayerInfoMail player, long nowMs)
{
if(!player.CanDoSaveReqNow(nowMs))
{
return false;
}
var iTaskIndex = (int)(player.UserID % MessageTaskHandler.MailDBWorkThreadCount);
//构建消息
StructPacket packet = new StructPacket();
packet.Header.Type = (int)SSGameMsgID.MailOpReq;
packet.Header.ObjectID = player.UserID;
StructMessageParser<SSMailOpReq> parser = new StructMessageParser<SSMailOpReq>();
packet.Parser = parser;
ref SSMailOpReq req = ref parser.GetMessage();
req.OpType = (int)MailOpType.MailVerChange;
req.ClientOpUid = player.UserID;//这里需要,否则通知不到玩家客户端
req.AckGameServerID = player.GameServerID;
req.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID();
req.Mail.Uid = player.UserID;//先拷贝一份
req.Mail.InsertUniqueID = req.UniqueID;
req.MailVerSeq = player.lastMailVer;
req.Seq = player.DataSeq;
player.OnSaveReq(nowMs);
//分派消息
MessageTaskDistributor.Instance.Distribute(MailServerUtils.GetAppID(), packet, iTaskIndex);
TraceLog.Debug("PlayerMailVerSeqSvc.SaveMailVer uniqueId {0} uid {1}", req.UniqueID, player.UserID);
return true;
}
public static void SendQueryMailVer(PlayerInfoMail player)
{
var iTaskIndex = (int)(player.UserID % MessageTaskHandler.MailDBWorkThreadCount);
//构建消息
StructPacket packet = new StructPacket();
packet.Header.Type = (int)SSGameMsgID.QueryMailVersionReq;
packet.Header.ObjectID = player.UserID;
StructMessageParser<SSQueryMailVersionReq> parser = new StructMessageParser<SSQueryMailVersionReq>();
packet.Parser = parser;
ref var req = ref parser.GetMessage();
req.Uid = player.UserID;
//分派消息
MessageTaskDistributor.Instance.Distribute(MailServerUtils.GetAppID(), packet, iTaskIndex);
TraceLog.Debug("PlayerMailVerSeqSvc.SendQueryMailVer uid {0}", player.UserID);
}
}
}