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 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); } /// /// 邮件发送需要回应,保证不出错 /// /// 客户端发起的时候填写 /// public static void SendNewMailToPlayer(long clientOpUid, ref DBMail mail) { SendMailOpReqToDB(clientOpUid, MailOpType.Insert, ref mail); } /// /// 邮件发送需要回应,保证不出错 /// /// 客户端发起的时候填写 /// /// /// internal static void SendMailOpReqToDB(long clientOpUid, MailOpType opType, ref DBMail mail,List 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(mailOpReq.UniqueID, mailServerID , (int)SSGameMsgID.MailOpReq , ref mailOpReq , clientOpUid); mailOpReq.UniqueID = WaitAckStructRequestSender.Instance.GeneratorUniqueID(); mailOpReq.ListMId.Clear(); } } } WaitAckStructRequestSender.Instance.BeginSendNeedResend(mailOpReq.UniqueID, mailServerID , (int)SSGameMsgID.MailOpReq , ref mailOpReq , clientOpUid); CommBillLogUtils.LogMailOpBegin(clientOpUid, ref mail, (int)opType); } /// /// 邮件发送,允许发送失败,失败就算了 /// /// 客户端发起的时候填写 /// public static void SendNewMailToPlayerNoCheck(long clientOpUid, ref DBMail mail) { SendMailOpReqToDBNoCheck(clientOpUid, MailOpType.Insert, ref mail); } /// /// 邮件发送,允许发送失败,失败就算了 /// /// 客户端发起的时候填写 /// /// /// 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); } } }