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.
 
 
 
 
 
 

238 lines
9.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using Sog.Log;
using ProtoCSStruct;
namespace Game
{
public static class MailSender
{
public static void SendNewMailToPlayer(PlayerOnGame player, int mailId)
{
var desc = MailDescMgr.Instance.GetConfig(mailId);
DBMail mail = new DBMail();
mail.Uid = player.UserID;
mail.MailConfId = mailId;
mail.MailType = (int)MailType.None;
mail.SendTime = GameServerUtils.GetTimeSecond();
mail.ExpirationTime = GameServerUtils.GetTimeSecond() + desc.expireTime * 24 * 3600;
if (!string.IsNullOrEmpty(desc.mailReward))
{
List<RewardItemRW> res = RewardSvc.Reward(player, desc.mailReward, false, false);
foreach(var r in res)
{
if (!r.IsValid())
{
continue;
}
TypeIDValueString typeIDValueString = new TypeIDValueString();
typeIDValueString.Type = r.type;
typeIDValueString.Id.SetString(r.code);
typeIDValueString.Value = (int)r.amount;
mail.AddGoods.Add(ref typeIDValueString);
}
}
MailSender.SendNewMailToPlayer(player.UserID, ref mail);
}
public static void SendNewMailToPlayer(PlayerOnGame player, int mailId, List<RewardItemRW> res)
{
var desc = MailDescMgr.Instance.GetConfig(mailId);
if (desc == null)
{
return;
}
if (res != null)
{
res = RewardSvc.MergeReward(res);
}
DBMail mail = new DBMail();
mail.Uid = player.UserID;
mail.MailConfId = mailId;
mail.MailType = (int)MailType.None;
mail.SendTime = GameServerUtils.GetTimeSecond();
mail.ExpirationTime = GameServerUtils.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.SendNewMailToPlayer(player.UserID, ref mail);
}
public static void SendNewMailToPlayer(PlayerOnGame player, string title, string content, string rewardId)
{
DBMail mail = new DBMail();
mail.Uid = player.UserID;
mail.MailConfId = 0;
mail.MailType = (int)MailType.None;
mail.Title.SetString(title);
mail.Content.SetString(content);
mail.SendTime = GameServerUtils.GetTimeSecond();
mail.ExpirationTime = GameServerUtils.GetTimeSecond() + 7 * 24 * 3600;
if (!string.IsNullOrEmpty(rewardId))
{
List<RewardItemRW> res = RewardSvc.Reward(player, rewardId, false, false);
foreach (var r in res)
{
if (!r.IsValid())
{
continue;
}
TypeIDValueString typeIDValueString = new TypeIDValueString();
typeIDValueString.Type = r.type;
typeIDValueString.Id.SetString(r.code);
typeIDValueString.Value = (int)r.amount;
mail.AddGoods.Add(ref typeIDValueString);
}
}
MailSender.SendNewMailToPlayer(player.UserID, ref mail);
}
public static void SendNewMailToPlayer(PlayerOnGame player, string title, string content, List<RewardItemRW> res = null)
{
DBMail mail = new DBMail();
mail.Uid = player.UserID;
mail.MailConfId = 0;
mail.MailType = (int)MailType.None;
mail.Title.SetString(title);
mail.Content.SetString(content);
mail.SendTime = GameServerUtils.GetTimeSecond();
mail.ExpirationTime = GameServerUtils.GetTimeSecond() + 7 * 24 * 3600;
if (res != null)
{
foreach (var r in res)
{
if (!r.IsValid())
{
continue;
}
TypeIDValueString typeIDValueString = new TypeIDValueString();
typeIDValueString.Type = r.type;
typeIDValueString.Id.SetString(r.code);
typeIDValueString.Value = (int)r.amount;
mail.AddGoods.Add(ref typeIDValueString);
}
}
MailSender.SendNewMailToPlayer(player.UserID, 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 = GameServerUtils.GetApp().ServerID;
mailOpReq.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID();
if(opType == MailOpType.Insert)
{
mail.InsertUniqueID = mailOpReq.UniqueID;
}
mailOpReq.Mail = mail;
uint mailServerID = GameServerUtils.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 = GameServerUtils.GetApp().ServerID;
mailOpReq.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID();
if (opType == MailOpType.Insert)
{
mail.InsertUniqueID = mailOpReq.UniqueID;
}
mailOpReq.Mail = mail;
GameServerUtils.GetPacketSender().SendToMailServer((int)SSGameMsgID.MailOpReq, ref mailOpReq, clientOpUid);
CommBillLogUtils.LogMailOpBegin(clientOpUid, ref mail, (int)opType);
}
}
}