From e469ed0b6ab5296eb95373f2e9ca4ee91cd341e6 Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Mon, 8 Jan 2024 13:49:25 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E8=BF=BD=E6=9D=80=E4=BB=A4=E6=97=A0?= =?UTF-8?q?=E9=99=90=E5=88=B7bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/ApiSyncBtn.ts | 63 +++++++++++++-------------- src/api_s2c/event/zhanling/ApiOpen.ts | 40 +++++++++-------- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/api_s2c/ApiSyncBtn.ts b/src/api_s2c/ApiSyncBtn.ts index 7b3308a..26b0ab4 100644 --- a/src/api_s2c/ApiSyncBtn.ts +++ b/src/api_s2c/ApiSyncBtn.ts @@ -1,6 +1,4 @@ import {ApiCall} from "tsrpc"; -import {EventFun} from '../public/event/event'; -import {PayFun} from '../public/pay'; import {ReqSyncBtn, ResSyncBtn, syncBtnKeys} from "../shared/protocols/PtlSyncBtn"; import {PublicShared} from '../shared/public/public'; import {HuoDongFun} from "../public/huodongfun"; @@ -65,39 +63,40 @@ export default async function (call: ApiCall) { break; case 'zhanling': //30天一轮循环,不管奖励。常驻活动 - if (!PublicShared.getEventIsOpen(G.gc.zhanling.eventOpen, call.conn.gud)) { - data[key] = {active: false}; - } else { - let zls = await G.mongodb.collection('scheduler').findOne({type: 'zhanling'}); - if (!data[key] || data[key].round != zls?.round) { - let lastRunTime = zls && zls.lastRunTime? zls.lastRunTime : G.time - let round = zls && zls.lastRunTime? zls.round : 1 - data[key] = {active: true, sTime: lastRunTime, round: round}; - change[key] = data[key]; + // if (!PublicShared.getEventIsOpen(G.gc.zhanling.eventOpen, call.conn.gud)) { + // data[key] = {active: false}; + // } else { + // let zls = await G.mongodb.collection('scheduler').findOne({type: 'zhanling'}); + // if (!data[key] || data[key].round != (zls?.round || 0)) { + // let lastRunTime = zls && zls.lastRunTime? zls.lastRunTime : G.time + // let round = zls && zls.lastRunTime? zls.round : 1 - PayFun.delPayLog(call.uid, {payId: G.gc.zhanling.payId, val: []}); + // data[key] = {active: true, sTime: lastRunTime, round: round}; + // change[key] = data[key]; - G.mongodb.cEvent('zhanling').findOne({uid: call.uid, type: 'zhanling'}).then(data => { - //新一轮战令 不管玩家多久没上线 只补发玩家上一轮没有领取的奖励 - data && EventFun.reissueZhanLingPrize(data, call.conn.gud); + // PayFun.delPayLog(call.uid, {payId: G.gc.zhanling.payId, val: []}); - G.mongodb.cEvent('zhanling').updateOne( - {uid: call.uid, type: 'zhanling'}, - { - $set: { - lv: 1, - exp: 0, - rec: {}, - isPay: false, - taskRec: [], - refreshTime: G.time - } - }, - {upsert: true} - ); - }); - } - } + // G.mongodb.cEvent('zhanling').findOne({uid: call.uid, type: 'zhanling'}).then(data => { + // //新一轮战令 不管玩家多久没上线 只补发玩家上一轮没有领取的奖励 + // data && EventFun.reissueZhanLingPrize(data, call.conn.gud); + + // G.mongodb.cEvent('zhanling').updateOne( + // {uid: call.uid, type: 'zhanling'}, + // { + // $set: { + // lv: 1, + // exp: 0, + // rec: {}, + // isPay: false, + // taskRec: [], + // refreshTime: G.time + // } + // }, + // {upsert: true} + // ); + // }); + // } + // } break; case 'xianshilibao': // 到时间消失 diff --git a/src/api_s2c/event/zhanling/ApiOpen.ts b/src/api_s2c/event/zhanling/ApiOpen.ts index 95b2ce7..e72339b 100644 --- a/src/api_s2c/event/zhanling/ApiOpen.ts +++ b/src/api_s2c/event/zhanling/ApiOpen.ts @@ -1,14 +1,16 @@ -import {ApiCall} from "tsrpc"; -import {ZhanLingTasks} from '../../../public/zhanling'; -import {ReqOpen, ResOpen} from "../../../shared/protocols/event/zhanling/PtlOpen"; -import {player} from '../../../shared/protocols/user/type'; -import {PublicShared} from '../../../shared/public/public'; +import { ApiCall } from "tsrpc"; +import { ZhanLingTasks } from '../../../public/zhanling'; +import { ReqOpen, ResOpen } from "../../../shared/protocols/event/zhanling/PtlOpen"; +import { player } from '../../../shared/protocols/user/type'; +import { PublicShared } from '../../../shared/public/public'; +import { PayFun } from "../../../public/pay"; export default async function (call: ApiCall) { - let zls = await G.mongodb.collection('scheduler').findOne({type: 'zhanling'}); - let data = await G.mongodb.cEvent('zhanling').findOne({uid: call.uid, type: 'zhanling'}); + call.error(lng.huodong_open_1) + let zls = await G.mongodb.collection('scheduler').findOne({ type: 'zhanling' }); + let data = await G.mongodb.cEvent('zhanling').findOne({ uid: call.uid, type: 'zhanling' }); - if (!data || data.round != (zls?.round | 0)) { + if (!data || data.round != (zls?.round || 0)) { let set = { lv: 1, exp: 0, @@ -16,18 +18,22 @@ export default async function (call: ApiCall) { isPay: false, taskRec: [], round: zls?.round || 0, - reWeekTime:G.time, + reWeekTime: G.time, refreshTime: G.time, } + await PayFun.delPayLog( + call.uid, { payId: G.gc.zhanling.payId, val: [] } + ); + data = (await G.mongodb.cEvent('zhanling').findOneAndUpdate({ uid: call.uid, type: 'zhanling' - }, {$set: set}, {upsert: true, returnDocument: 'after'})).value; + }, { $set: set }, { upsert: true, returnDocument: 'after' })).value; } if (PublicShared.getToWeekMondayZeroTime() > data.reWeekTime || PublicShared.getToDayZeroTime() > data.refreshTime) { - let set: any = {taskRec: []}; + let set: any = { taskRec: [] }; let reType = []; if (PublicShared.getToWeekMondayZeroTime() > data.reWeekTime) { @@ -49,11 +55,11 @@ export default async function (call: ApiCall) { data = (await G.mongodb.cEvent('zhanling').findOneAndUpdate({ uid: call.uid, type: 'zhanling' - }, {$set: set}, {upsert: true, returnDocument: 'after'})).value; + }, { $set: set }, { upsert: true, returnDocument: 'after' })).value; } let tasks = G.gc.zhanling.task.map(t => { - return {type: t.type as 'day' | 'week' | 'round', key: t.taskId}; + return { type: t.type as 'day' | 'week' | 'round', key: t.taskId }; }); let taskFinished = await ZhanLingTasks.getLog(call.uid, tasks); @@ -68,14 +74,14 @@ export default async function (call: ApiCall) { } export async function payZhanLing(player: player) { - let zlData = await G.mongodb.cEvent('zhanling').findOne({uid: player.uid, type: 'zhanling'}); + let zlData = await G.mongodb.cEvent('zhanling').findOne({ uid: player.uid, type: 'zhanling' }); let curLv = zlData?.lv || 1; let maxLv = Number(Object.keys(G.gc.zhanling.lv).slice(-1)[0]); let addLv = maxLv - curLv >= G.gc.zhanling.payAddLv ? G.gc.zhanling.payAddLv : maxLv - curLv; await G.mongodb.cEvent('zhanling').updateOne( - {uid: player.uid, type: 'zhanling'}, - {$set: {isPay: true, exp: G.gc.zhanling.lv[curLv + addLv], lv: curLv + addLv}}, - {upsert: true} + { uid: player.uid, type: 'zhanling' }, + { $set: { isPay: true, exp: G.gc.zhanling.lv[curLv + addLv], lv: curLv + addLv } }, + { upsert: true } ); } \ No newline at end of file From e597f2969e6e3b5d80bea511256dfcac86364925 Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Mon, 8 Jan 2024 14:03:09 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=85=A8=E5=B1=80API=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=94=81=E5=AE=9A=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/oss/blackapi.json | 3 +++ src/setWs.ts | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 src/oss/blackapi.json diff --git a/src/oss/blackapi.json b/src/oss/blackapi.json new file mode 100644 index 0000000..1610ea1 --- /dev/null +++ b/src/oss/blackapi.json @@ -0,0 +1,3 @@ +[ + +] \ No newline at end of file diff --git a/src/setWs.ts b/src/setWs.ts index a1186a8..5b6e89f 100644 --- a/src/setWs.ts +++ b/src/setWs.ts @@ -47,6 +47,12 @@ export async function createWs() { G.argv.serverType == 'msg' && G.config.corssWsUrl && await createWsClient(); } + + /**每分钟刷新一次黑名单API接口 */ + setInterval(()=>{ + getBlackList(); + },60000); + getBlackList(); } function getWssFile() { @@ -63,6 +69,21 @@ function getWssFile() { } const writeList = ['hongdian/Get'] +/**当前锁定的API接口 */ +let blackApi = []; + +async function getBlackList(){ + let confFile = resolve(__dirname, 'oss/blackapi.json'); + if (existsSync(confFile)) { + try { + blackApi = await JSON.parse(readFileSync(confFile, 'utf-8')); + } catch (e) { + blackApi = []; + } + }else{ + blackApi = []; + } +} function setWs(server: WsServer) { @@ -101,15 +122,17 @@ function setWs(server: WsServer) { //执行 API 接口实现之前 server.flows.preApiCallFlow.push(async call => { - // 临时停服维护方案 - // let lng = { - // "zh-TW": "停服維護中,請等待!", - // "ko": "서버 점검 중, 잠시만 기다려 주세요.", - // "ja": "サーバーメンテナンス中、しばらくお待ちください。", - // "en": "Server under maintenance. Please wait.", - // } - // call.error("", {code: -1, message: lng[call.req.lng] || lng["ja"]}) - // return null; + //判断是否是被关闭的API + if (blackApi.includes(call.service.name) || blackApi.includes("all")) { + let lng = { + "zh-TW": "維護中,請等待", + "ko": "유지 보수 중, 대기 중", + "ja": "メンテナンス中ですので、お待ちください", + "en": "Maintenance in progress, please wait", + } + call.error("", {code: -1, message: lng[call.req.lng] || lng["ja"]}) + return null; + } //是否短时间内重复请求某个api // let timeIntervalLimit = call.service.conf?.timeIntervalLimit == undefined ? 500 : call.service.conf?.timeIntervalLimit; From 63ce399c560bdc56d5863e02703bc31e049056aa Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Mon, 8 Jan 2024 15:26:24 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E6=88=98=E4=BB=A4=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/ApiSyncBtn.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api_s2c/ApiSyncBtn.ts b/src/api_s2c/ApiSyncBtn.ts index 26b0ab4..8a997f9 100644 --- a/src/api_s2c/ApiSyncBtn.ts +++ b/src/api_s2c/ApiSyncBtn.ts @@ -6,7 +6,6 @@ import {HuoDongFun} from "../public/huodongfun"; const defaultKeys: syncBtnKeys[] = [ 'huobanzhaomu', 'yibaichou', 'shouchong', 'dayjijin', 'dengjijijin', 'guanqiajijin', 'tianshujijin', - 'zhanling', 'xianshilibao', 'xianshizhaomu', 'G123Gift', From 85dc5e02ffdb9a3e3e54441038b776a9f2e37c3c Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Mon, 8 Jan 2024 15:39:48 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix=20=E6=AF=8F=E6=97=A5=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E5=8F=AA=E6=89=A7=E8=A1=8C1=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/globalListener.ts | 3 +- src/public/actionLog/actionLog.ts | 28 +++++++++- src/public/scheduler/scheduler_newDay.ts | 70 ++++++++++++++---------- 3 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/globalListener.ts b/src/globalListener.ts index 68bc8c8..57fee50 100644 --- a/src/globalListener.ts +++ b/src/globalListener.ts @@ -211,7 +211,8 @@ export function addListener() { // 签到增加天数 SignFun.updateLogin(gud.uid); - ActionLog.initDayLog(gud.uid); + //移到定时器里统一执行 + //ActionLog.initDayLog(gud.uid); ActionLog.addRetainLog(gud.uid, { key: 'login_day', val: 1 }); ZhanLingTasks.clearLog(gud.uid, 'day'); PayFun.checkGiftDayEmail(gud, lastTime, curTime); diff --git a/src/public/actionLog/actionLog.ts b/src/public/actionLog/actionLog.ts index a3e64b2..2ca05a1 100644 --- a/src/public/actionLog/actionLog.ts +++ b/src/public/actionLog/actionLog.ts @@ -1,9 +1,33 @@ +import { PublicShared } from "../../shared/public/public"; export class ActionLog { - static async initDayLog(uid: string) { - G.mongodb.cActionLog('day').updateOne({ uid: uid, type: 'day' }, { $set: { log: {} } }, { upsert: true }); + /** + * 每天0点的时候,重置所有的统计数据 + */ + static async initAllDayLog() { + await G.mongodb.cActionLog('day').updateMany({type: 'day' }, { + $set: { + log: {}, + //增加刷新时间 + lastTime: PublicShared.getToDayZeroTime(G.time) + } + }); } + + /** + * 重置某个玩家的统计信息 + * @param uid + */ + // static async initDayLog(uid: string) { + // G.mongodb.cActionLog('day').updateOne({ uid: uid, type: 'day' }, { + // $set: { + // log: {}, + // //增加刷新时间 + // lastTime: PublicShared.getToDayZeroTime(G.time) + // } + // }, { upsert: true }); + // } static async addDayLog(uid: string, ...args: { key: string, val: number; }[]) { const addObj = G.mongodb.createTreeObj(...args.map(a => { return { key: 'log', k: a.key, val: a.val }; })); G.mongodb.cActionLog('day').updateOne({ uid: uid, type: 'day' }, { $inc: addObj }); diff --git a/src/public/scheduler/scheduler_newDay.ts b/src/public/scheduler/scheduler_newDay.ts index 4ca793b..2e6598a 100644 --- a/src/public/scheduler/scheduler_newDay.ts +++ b/src/public/scheduler/scheduler_newDay.ts @@ -4,11 +4,14 @@ import { Wjjl } from "../../module/collection_wjjl"; import { ZhanLingTasks } from "../zhanling"; import { setGud } from '../gud'; import { EmailFun } from '../email'; +import { ActionLog } from '../actionLog/actionLog'; +import { clusterFun } from '../../clusterFunction'; +import { clusterRunOnce } from '../../clusterUtils'; export class SchedulerNewDayLocalCtor extends Scheduler { id: schedulerType = 'newDay_local_ctor'; - time = 0; + time = 1; name = '定时推送跨天通知'; type: 'day' | 'week' = 'day'; @@ -23,6 +26,41 @@ export class SchedulerNewDayLocalCtor extends Scheduler { } async start() { + + clusterRunOnce(async ()=>{ + //这个定时器会被每个进程都启动,这是这部分逻辑,应该只执行1次 + + //重置所有的ActionLog + await ActionLog.initAllDayLog(); + + // 每周一,发放终身卡 + (async () => { + if (PublicShared.getWeek(G.time) == 1) { + let logs = await G.mongodb.collection("payLogNew").find( + { key: "zhongshenka", del_time: { $exists: false } }, { projection: { _id: 0, } } + ).toArray(); + + if (logs.length == 0) { + console.log("没有终身卡数据,不发放终身卡"); + } + let con = G.gc.payEmail.zhongshenka.filter(e => e.day == 7)[0]; + for (let i = 0; i < logs.length; i++) { + console.log("发放终身卡", logs[i].uid); + // 发送邮件 + EmailFun.addEmail({ + uid: logs[i].uid, + type: "system", + title: con.title, + content: con.content, + contentInsertArr: [], + createTime: G.time, + prize:con.prize, + }) + } + } + })() + }) + let users = Object.values(G.server.uid_connections) if (users.length) { for (let item of users) { @@ -56,34 +94,6 @@ export class SchedulerNewDayLocalCtor extends Scheduler { G.server.broadcastClusterMsg('msg_s2c/NewDay', { time: this.zeroTime }); } - (async () => { - // 每周一,发放终身卡 - if (PublicShared.getWeek(G.time) != 1) { - console.log("不是周一,不发放终身卡", PublicShared.getWeek(G.time)); - return - }; - - let logs = await G.mongodb.collection("payLogNew").find( - { key: "zhongshenka", del_time: { $exists: false } }, { projection: { _id: 0, } } - ).toArray(); - - if (logs.length == 0) { - console.log("没有终身卡数据,不发放终身卡"); - } - let con = G.gc.payEmail.zhongshenka.filter(e => e.day == 7)[0]; - for (let i = 0; i < logs.length; i++) { - console.log("发放终身卡", logs[i].uid); - // 发送邮件 - EmailFun.addEmail({ - uid: logs[i].uid, - type: "system", - title: con.title, - content: con.content, - contentInsertArr: [], - createTime: G.time, - prize:con.prize, - }) - } - })() + await this.record(); } } From e016e708c466590688d73abe9ff1b828c0192010 Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Mon, 8 Jan 2024 15:48:22 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=E8=A7=A3=E9=99=A4=E5=B1=8F=E8=94=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/zhanling/ApiOpen.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api_s2c/event/zhanling/ApiOpen.ts b/src/api_s2c/event/zhanling/ApiOpen.ts index e72339b..e6dc37b 100644 --- a/src/api_s2c/event/zhanling/ApiOpen.ts +++ b/src/api_s2c/event/zhanling/ApiOpen.ts @@ -6,7 +6,6 @@ import { PublicShared } from '../../../shared/public/public'; import { PayFun } from "../../../public/pay"; export default async function (call: ApiCall) { - call.error(lng.huodong_open_1) let zls = await G.mongodb.collection('scheduler').findOne({ type: 'zhanling' }); let data = await G.mongodb.cEvent('zhanling').findOne({ uid: call.uid, type: 'zhanling' }); From d91c413603b8c6acf7cb332dd1d1303c15f8435e Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Mon, 8 Jan 2024 17:12:11 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=E6=88=98=E4=BB=A4=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/scheduler/scheduler_zhanling.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/public/scheduler/scheduler_zhanling.ts b/src/public/scheduler/scheduler_zhanling.ts index b77d0e5..b00fdf6 100644 --- a/src/public/scheduler/scheduler_zhanling.ts +++ b/src/public/scheduler/scheduler_zhanling.ts @@ -1,5 +1,5 @@ -import {PublicShared} from '../../shared/public/public'; -import {Scheduler, schedulerType} from './scheduler'; +import { PublicShared } from '../../shared/public/public'; +import { Scheduler, schedulerType } from './scheduler'; export class SchedulerZhanLing extends Scheduler { @@ -12,12 +12,12 @@ export class SchedulerZhanLing extends Scheduler { this.isReady = false; return } - let data = await this.db.findOne({type: this.id}); + let data = await this.db.findOne({ type: this.id }); if (!data) { // 开服时间整除战令周期 - let round = Math.floor(PublicShared.getOpenServerDay() / G.gc.zhanling.eventOpen.day) + let round = Math.floor((PublicShared.getOpenServerDay() - 1) / G.gc.zhanling.eventOpen.day) let prev_run_time = PublicShared.getToDayZeroTime(G.openTime) + round * G.gc.zhanling.eventOpen.day * 86400 - this.db.updateOne({type: this.id}, {$set: {lastRunTime: prev_run_time, round: round}}, {upsert: true}); + this.db.updateOne({ type: this.id }, { $set: { lastRunTime: prev_run_time, round: round } }, { upsert: true }); } if (!data || G.time > PublicShared.getToDayZeroTime(data.lastRunTime) + 24 * 3600 * G.gc.zhanling.eventOpen.day) { @@ -33,11 +33,11 @@ export class SchedulerZhanLing extends Scheduler { // 开服时间整除战令周期 let round = Math.floor(PublicShared.getOpenServerDay() / G.gc.zhanling.eventOpen.day) // lastRunTime仅储存最大值,问题记录: 本地多人启动服务时,有调用此定时器的情况下,时间会混乱。 - await this.db.updateOne({type: this.id}, {$set: {round: round}, $max: {lastRunTime: G.time}}, {upsert: true}); + await this.db.updateOne({ type: this.id }, { $set: { round: round }, $max: { lastRunTime: G.time } }, { upsert: true }); this.startTime = PublicShared.getToDayZeroTime() + 24 * 3600 * G.gc.zhanling.eventOpen.day; this.isStart = false; - G.mongodb.collection('zhanling').updateMany({type: 'round'}, {$set: {data: {}}}); + G.mongodb.collection('zhanling').updateMany({ type: 'round' }, { $set: { data: {} } }); } } \ No newline at end of file