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.
187 lines
6.8 KiB
187 lines
6.8 KiB
1 month ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
using Sog;
|
||
|
using MySql.Data.MySqlClient;
|
||
|
|
||
|
using SimpleHttpServer;
|
||
|
using LitJson;
|
||
|
|
||
|
using ProtoCSStruct;
|
||
|
|
||
|
namespace Operation
|
||
|
{
|
||
|
public enum MailStatus
|
||
|
{
|
||
|
Ready = 0,
|
||
|
Send = 1,
|
||
|
Success = 2,
|
||
|
Timeout = 3,
|
||
|
ReCall = 4,
|
||
|
};
|
||
|
|
||
|
public enum MailMsg
|
||
|
{
|
||
|
msg_Send = 1,
|
||
|
msg_Success = 2,
|
||
|
msg_Timeout = 3,
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 暂时不去tick这部分代码,拉去逻辑测试没问题,可以删掉
|
||
|
/// </summary>
|
||
|
public class SendMailSvc : BaseReloadableService
|
||
|
{
|
||
|
private long lastTickTimeMs = 0;
|
||
|
private long lastKeepAlive = 0;
|
||
|
|
||
|
public MySqlDB m_mySqlDb;
|
||
|
|
||
|
public override int GetServiceType()
|
||
|
{
|
||
|
return OperationServiceType.SendMailSvc;
|
||
|
}
|
||
|
|
||
|
public override void Dispose()
|
||
|
{
|
||
|
m_mySqlDb.Dispose();
|
||
|
m_mySqlDb = null;
|
||
|
}
|
||
|
|
||
|
public SendMailSvc()
|
||
|
{
|
||
|
var config = OperationServerUtils.GetServerConfig();
|
||
|
m_mySqlDb = new MySqlDB(config.dbname,
|
||
|
config.dbip,
|
||
|
config.dbuser,
|
||
|
config.dbpassword);
|
||
|
}
|
||
|
|
||
|
public void OnTick(long nowMs)
|
||
|
{
|
||
|
if (nowMs - lastTickTimeMs < 120000)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
lastTickTimeMs = nowMs;
|
||
|
TickMailBoxTemp();
|
||
|
}
|
||
|
|
||
|
|
||
|
public void TickMailBoxTemp()
|
||
|
{
|
||
|
|
||
|
TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0);
|
||
|
int nowTime = Convert.ToInt32(ts.TotalMinutes); //获取当前时间戳
|
||
|
string strSql = "";
|
||
|
string nowTimeStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
strSql = $"select * from mail_box_temp where dater <='{nowTimeStr}' and datee >='{nowTimeStr}' and status=0"; //邮件再有效期内
|
||
|
strSql += " order by Id asc";
|
||
|
|
||
|
TraceLog.Debug("MailStatus.TickMailBoxTemp sqlStr:{0}", strSql);
|
||
|
MySqlDataReader reader = m_mySqlDb.ExecReader(strSql);
|
||
|
if (reader == null)
|
||
|
{
|
||
|
TraceLog.Error("MailStatus.TickMailBoxTemp error: return reader is null!");
|
||
|
return;
|
||
|
}
|
||
|
if (!reader.HasRows)
|
||
|
{
|
||
|
TraceLog.Trace("MailStatus.TickMailBoxTemp DB has no record");
|
||
|
reader.Close();
|
||
|
return;
|
||
|
}
|
||
|
List<int> mailIds = new List<int>();
|
||
|
List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
|
||
|
try
|
||
|
{
|
||
|
while (reader.Read())
|
||
|
{
|
||
|
int mailId = reader.GetInt32("Id");
|
||
|
mailIds.Add(mailId);
|
||
|
string timeLimit = reader.GetDateTime("dater").ToString() + "#" + reader.GetDateTime("datee");
|
||
|
ExtMail ext = new ExtMail();
|
||
|
int gameDataIndex = reader.GetOrdinal("data");
|
||
|
if (!reader.IsDBNull(gameDataIndex))
|
||
|
{
|
||
|
byte[] buffer = new byte[50 * 1024];
|
||
|
long gameDataLength = reader.GetBytes(gameDataIndex, 0, buffer, 0, buffer.Length);
|
||
|
byte[] gameDataByte = new byte[gameDataLength];
|
||
|
Buffer.BlockCopy(buffer, 0, gameDataByte, 0, (int)gameDataLength);
|
||
|
StructMessageParseUtils.ParseFrom(ref ext, gameDataByte);
|
||
|
}
|
||
|
byte[] dataByte = StructMessageParseUtils.ToByteArray(ref ext);
|
||
|
Dictionary<string, object> data = new Dictionary<string, object>();
|
||
|
data["name"] = reader.GetString("name");
|
||
|
data["title"] = reader.GetString("title");
|
||
|
data["content"] = reader.GetString("content");
|
||
|
data["realmlist"] = reader.GetString("realmlist");
|
||
|
data["herolist"] = reader.GetString("herolist");
|
||
|
data["language"] = reader.GetString("language");
|
||
|
data["uuid"] = reader.GetString("uuid");
|
||
|
data["curstr"] = reader.GetString("curstr");
|
||
|
data["itemstr"] = reader.GetString("itemstr");
|
||
|
data["timeLimit"] = timeLimit;
|
||
|
data["isSendToAll"] = reader.GetInt32("isSendToAll");
|
||
|
data["equipStr"] = reader.GetString("equipStr");
|
||
|
data["dataByte"] = dataByte;
|
||
|
data["customItemStr"] = reader.GetString("customItemStr");
|
||
|
dataList.Add(data);
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
if (reader != null)
|
||
|
reader.Close();
|
||
|
|
||
|
TraceLog.Error("MailStatus.TickMailBoxTemp error:{0}!", ex.Message);
|
||
|
}
|
||
|
reader.Close();
|
||
|
var successful = DeleteMailTemp(mailIds);
|
||
|
if (!successful)
|
||
|
{//没有清理成功,就不能发送邮件
|
||
|
return;
|
||
|
}
|
||
|
for (int i = 0; i < dataList.Count; i++)
|
||
|
{
|
||
|
var data = dataList[i];
|
||
|
DBInsertIntoMailBox(data["name"].ToString(), data["title"].ToString(), data["content"].ToString(), data["realmlist"].ToString(), data["herolist"].ToString(), data["language"].ToString(), data["uuid"].ToString(), data["curstr"].ToString(), data["itemstr"].ToString(), data["timeLimit"].ToString(), (int)data["isSendToAll"], data["equipStr"].ToString(), (byte[])data["dataByte"], data["customItemStr"].ToString());
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public bool DeleteMailTemp(List<int> mailIds)
|
||
|
{
|
||
|
if (mailIds.Count <= 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
string editSql = $"delete from mail_box_temp where Id in({string.Join(",", mailIds)});";
|
||
|
TraceLog.Debug("MailStatus.DeleteMailTemp: sql:{0}", editSql);
|
||
|
try
|
||
|
{
|
||
|
m_mySqlDb.ExecNonQuery(editSql, null);
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
TraceLog.Error("MailStatus.DeleteMailTemp error : {0}", e.Message);
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
public int DBInsertIntoMailBox(string _name, string title11, string content11, string realmlist11,
|
||
|
string herolist11, string language, string uuid, string curstr11, string itemstr11,
|
||
|
string timeLimit11, int isSendToAll, string equipStr, byte[] dataByte, string customItemStr)
|
||
|
{
|
||
|
return MailDBUtils.DBInsertIntoMailBox(m_mySqlDb, _name, title11, content11, realmlist11,
|
||
|
herolist11, language, uuid, curstr11, itemstr11,
|
||
|
timeLimit11, isSendToAll, equipStr, dataByte, customItemStr); ;
|
||
|
}
|
||
|
}
|
||
|
}
|