Merge branch 'bugfix' into release

This commit is contained in:
xichaoyin 2024-01-08 17:13:48 +08:00
commit 1ec21d71e0
8 changed files with 163 additions and 99 deletions

View File

@ -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";
@ -8,7 +6,6 @@ import {HuoDongFun} from "../public/huodongfun";
const defaultKeys: syncBtnKeys[] = [
'huobanzhaomu', 'yibaichou', 'shouchong',
'dayjijin', 'dengjijijin', 'guanqiajijin', 'tianshujijin',
'zhanling',
'xianshilibao',
'xianshizhaomu',
'G123Gift',
@ -65,39 +62,40 @@ export default async function (call: ApiCall<ReqSyncBtn, ResSyncBtn>) {
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':
// 到时间消失

View File

@ -1,14 +1,15 @@
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<ReqOpen, ResOpen>) {
let zls = await G.mongodb.collection('scheduler').findOne({type: 'zhanling'});
let data = await G.mongodb.cEvent('zhanling').findOne({uid: call.uid, type: 'zhanling'});
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 +17,22 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
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 +54,11 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
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 +73,14 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
}
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 }
);
}

View File

@ -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);

3
src/oss/blackapi.json Normal file
View File

@ -0,0 +1,3 @@
[
]

View File

@ -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 });

View File

@ -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();
}
}

View File

@ -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: {} } });
}
}

View File

@ -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<ServiceType>) {
@ -101,15 +122,17 @@ function setWs(server: WsServer<ServiceType>) {
//执行 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;