Files
DP-S_Script/示例项目/自动刷新GM工具的邮件/自动刷新GM工具的邮件.nut
2026-04-16 16:27:53 +08:00

88 lines
3.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
文件名:自动刷新GM工具的邮件.nut
路径:OfficialProject/自动刷新GM工具的邮件/自动刷新GM工具的邮件.nut
创建日期:2025-12-16 20:49
文件用途:
*/
//数据库连接
_DetectingDatabaseEmailMysql_ <- null;
//上次查询的最新ID
_DetectingDatabaseEmailLastId_ <- -1;
function _DetectingDatabaseEmailRefresh_() {
//第一次初始化数据库连接
if (_DetectingDatabaseEmailMysql_ == null) {
_DetectingDatabaseEmailMysql_ = Mysql(Str_Ptr("127.0.0.1"), 3306, Str_Ptr("taiwan_cain"), Str_Ptr("game"), Str_Ptr("uu5!^%jg"));
if (_DetectingDatabaseEmailMysql_ == null) {
print("数据库连接失败!");
return;
}
_DetectingDatabaseEmailMysql_.Exec_Sql(format("SET NAMES %s", "latin1"));
}
//查询最新主键
local Ret = _DetectingDatabaseEmailMysql_.Select("SELECT letter_id FROM taiwan_cain_2nd.letter ORDER BY letter_id DESC LIMIT 1", ["int"]);
if (!Ret || Ret.len() == 0) {
// print("查询最新letter_id失败或无数据");
return;
}
local LatestId = Ret[0][0];
//第一次初始化记录最新ID不处理数据
if (_DetectingDatabaseEmailLastId_ == -1) {
_DetectingDatabaseEmailLastId_ = LatestId;
print("首次初始化最新letter_id" + LatestId);
return;
}
//有新的邮件数据最新ID大于上次记录的ID
if (LatestId > _DetectingDatabaseEmailLastId_) {
//查询新增数据的条数和charac_no字段
local sql = format("SELECT charac_no FROM taiwan_cain_2nd.letter WHERE letter_id > %d AND letter_id <= %d", _DetectingDatabaseEmailLastId_, LatestId);
local NewDataRet = _DetectingDatabaseEmailMysql_.Select(sql, ["int"]);
if (NewDataRet && NewDataRet.len() > 0) {
local NewCount = NewDataRet.len();
print("新增邮件数据条数:" + NewCount);
local CharacMap = {};
//遍历获取所有新增的charac_no
for (local i = 0; i< NewDataRet.len(); i++) {
local charac_no = NewDataRet[i][0];
CharacMap.rawset(charac_no, true);
}
foreach(cid,_ in CharacMap) {
local SUser = World.GetUserByCid(cid);
if (SUser) {
local MailBox = Sq_CallFunc(S_Ptr("0x0823020C"), "pointer", ["pointer"], SUser.C_Object);
local NotLoaded_Count = Sq_CallFunc(S_Ptr("0x084ED330"), "int", ["pointer"], MailBox);
local Not_Count = Sq_CallFunc(S_Ptr("0x0823455A"), "int", ["pointer"], MailBox);
local Pack = Packet();
Pack.Put_Header(0, 99);
Pack.Put_Short(Not_Count);
Pack.Finalize(true);
SUser.Send(Pack);
Pack.Delete();
}
}
} else {
print("查询新增数据失败");
}
//更新上次记录的最新ID为当前最新ID
_DetectingDatabaseEmailLastId_ = LatestId;
} else {
//无新增数据
//print("无新增邮件数据");
}
}
function _Dps_AutomaticallyRefreshGmToolEmails_Main_() {
Timer.SetCronTask(function() {
_DetectingDatabaseEmailRefresh_();
}, "*/1 * * * * ?");
}