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.
 
 
 
 
 
 

150 lines
5.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using Sog.Log;
using ProtoCSStruct;
namespace World
{
public static class MailSender
{
public static void SendNewMailToPlayer(long uid, int mailId, List<RewardItemRW> res)
{
var desc = MailDescMgr.Instance.GetConfig(mailId);
if (desc == null)
{
return;
}
DBMail mail = new DBMail();
mail.Uid = uid;
mail.MailConfId = mailId;
mail.MailType = (int)MailType.None;
mail.SendTime = WorldServerUtils.GetTimeSecond();
mail.ExpirationTime = WorldServerUtils.GetTimeSecond() + desc.expireTime * 24 * 3600;
foreach (var r in res)
{
if (!r.IsValid())
{
continue;
}
var typeIdValueString = new TypeIDValueString();
typeIdValueString.Type = r.type;
typeIdValueString.Id.SetString(r.code);
typeIdValueString.Value = (int)r.amount;
mail.AddGoods.Add(ref typeIdValueString);
}
MailSender.SendNewMailToPlayerNoCheck(uid, ref mail);
}
/// <summary>
/// 邮件发送需要回应,保证不出错
/// </summary>
/// <param name="clientOpUid">客户端发起的时候填写</param>
/// <param name="mail"></param>
public static void SendNewMailToPlayer(long clientOpUid, ref DBMail mail)
{
SendMailOpReqToDB(clientOpUid, MailOpType.Insert, ref mail);
}
/// <summary>
/// 邮件发送需要回应,保证不出错
/// </summary>
/// <param name="clientOpUid">客户端发起的时候填写</param>
/// <param name="opType"></param>
/// <param name="mail"></param>
/// <param name="notifyclient"></param>
internal static void SendMailOpReqToDB(long clientOpUid, MailOpType opType, ref DBMail mail,List<long> list = null)
{
TraceLog.UserDebug(clientOpUid,"MailSender.SendMailOpReqToDB clientOpUid {0} opType {1} ", clientOpUid, opType);
SSMailOpReq mailOpReq = new SSMailOpReq();
mailOpReq.OpType = (int)opType;
mailOpReq.ClientOpUid = clientOpUid;
mailOpReq.AckGameServerID = WorldServerUtils.GetApp().ServerID;
mailOpReq.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID();
if(opType == MailOpType.Insert)
{
mail.InsertUniqueID = mailOpReq.UniqueID;
}
mailOpReq.Mail = mail;
uint mailServerID = WorldServerUtils.GetPacketSender().GetMailServerID();
if (list!=null && list.Count> 0 && (opType == MailOpType.AllDelete || opType == MailOpType.AllGetItem))
{
for(int i=0; i < list.Count; i++)
{
mailOpReq.ListMId.Add(list[i]);
if(list.Count>= mailOpReq.ListMId.GetMaxCount())
{
WaitAckStructRequestSender.Instance.BeginSendNeedResend<SSMailOpReq>(mailOpReq.UniqueID, mailServerID
, (int)SSGameMsgID.MailOpReq
, ref mailOpReq
, clientOpUid);
mailOpReq.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID();
mailOpReq.ListMId.Clear();
}
}
}
WaitAckStructRequestSender.Instance.BeginSendNeedResend<SSMailOpReq>(mailOpReq.UniqueID, mailServerID
, (int)SSGameMsgID.MailOpReq
, ref mailOpReq
, clientOpUid);
CommBillLogUtils.LogMailOpBegin(clientOpUid, ref mail, (int)opType);
}
/// <summary>
/// 邮件发送,允许发送失败,失败就算了
/// </summary>
/// <param name="clientOpUid">客户端发起的时候填写</param>
/// <param name="mail"></param>
public static void SendNewMailToPlayerNoCheck(long clientOpUid, ref DBMail mail)
{
SendMailOpReqToDBNoCheck(clientOpUid, MailOpType.Insert, ref mail);
}
/// <summary>
/// 邮件发送,允许发送失败,失败就算了
/// </summary>
/// <param name="clientOpUid">客户端发起的时候填写</param>
/// <param name="opType"></param>
/// <param name="mail"></param>
/// <param name="notifyclient"></param>
private static void SendMailOpReqToDBNoCheck(long clientOpUid, MailOpType opType, ref DBMail mail)
{
TraceLog.UserDebug(clientOpUid,"MailSender.SendMailOpReqToDBNoCheck clientOpUid {0} opType {1} ", clientOpUid, opType);
SSMailOpReq mailOpReq = new SSMailOpReq();
mailOpReq.OpType = (int)opType;
mailOpReq.ClientOpUid = clientOpUid;
mailOpReq.AckGameServerID = WorldServerUtils.GetApp().ServerID;
mailOpReq.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID();
if (opType == MailOpType.Insert)
{
mail.InsertUniqueID = mailOpReq.UniqueID;
}
mailOpReq.Mail = mail;
WorldServerUtils.GetPacketSender().SendToMailServer((int)SSGameMsgID.MailOpReq, ref mailOpReq, clientOpUid);
CommBillLogUtils.LogMailOpBegin(clientOpUid, ref mail, (int)opType);
}
}
}