Merge branch 'master' into feature/warning

This commit is contained in:
dy 2024-01-03 10:18:20 +08:00
commit 953303d9a4
11 changed files with 231 additions and 37 deletions

View File

@ -13,6 +13,9 @@ export default async function (call: ApiCall<ReqOnekeyReceive, ResOnekeyReceive>
if (args.length < 1 || _ids.isDuplication() || heroIds.isDuplication()) return call.error(globalThis.lng.kbzz_1); if (args.length < 1 || _ids.isDuplication() || heroIds.isDuplication()) return call.error(globalThis.lng.kbzz_1);
let event = await G.mongodb.cEvent('xstask').findOne({uid: call.uid, type: 'xstask'});
if (event?.receiveNum >= 8) return call.error(globalThis.lng.xstask_11);
//所有的任务 //所有的任务
let taskList = await XstaskFun.getAllTask(call.uid); let taskList = await XstaskFun.getAllTask(call.uid);
//所有的任务id //所有的任务id

View File

@ -34,6 +34,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
XstaskFun.changeInfo(call.uid, {$set: {...changeInfo}}); XstaskFun.changeInfo(call.uid, {$set: {...changeInfo}});
XstaskFun.delTasks(call.uid, delTask.map(task => task._id)); XstaskFun.delTasks(call.uid, delTask.map(task => task._id));
XstaskFun.receiveNum(call.uid, true)
} }
// needAddTask += await TeQuanFun.getXsTaskNum(call); // needAddTask += await TeQuanFun.getXsTaskNum(call);

View File

@ -8,6 +8,9 @@ export default async function (call: ApiCall<ReqReceive, ResReceive>) {
if (call.req.heroIds.length < 1) return call.error(globalThis.lng.xstask_9); if (call.req.heroIds.length < 1) return call.error(globalThis.lng.xstask_9);
if (call.req.heroIds.isDuplication()) return call.error(globalThis.lng.xstask_10); if (call.req.heroIds.isDuplication()) return call.error(globalThis.lng.xstask_10);
let event = await G.mongodb.cEvent('xstask').findOne({uid: call.uid, type: 'xstask'});
if (event?.receiveNum >= 8) return call.error(globalThis.lng.xstask_11);
let task = await XstaskFun.getTask(call.uid, call.req._id); let task = await XstaskFun.getTask(call.uid, call.req._id);
let taskConf = G.gc.xstask[task?.taskId]; let taskConf = G.gc.xstask[task?.taskId];
if (!task) return call.error(globalThis.lng.xstask_1); if (!task) return call.error(globalThis.lng.xstask_1);
@ -28,6 +31,7 @@ export default async function (call: ApiCall<ReqReceive, ResReceive>) {
heros: call.req.heroIds heros: call.req.heroIds
}; };
XstaskFun.receiveNum(call.uid)
XstaskFun.receiveTask(call.uid, call.req._id, change); XstaskFun.receiveTask(call.uid, call.req._id, change);
HongDianChange.sendChangeKey(call.uid, ['xstaskhd', 'huodonghd']); HongDianChange.sendChangeKey(call.uid, ['xstaskhd', 'huodonghd']);

View File

@ -12,6 +12,9 @@ export default async function (call: ApiCall<ReqRefresh, ResRefresh>) {
if (delNum < 1) return call.error(globalThis.lng.xstask_11); if (delNum < 1) return call.error(globalThis.lng.xstask_11);
let event = await G.mongodb.cEvent('xstask').findOne({uid: call.uid, type: 'xstask'});
if (event?.receiveNum >= 8) return call.error(globalThis.lng.xstask_11);
let change: ResRefresh = {}; let change: ResRefresh = {};
let needDel = taskList.filter(task => task.receiveData == undefined || task.receiveData.rec == true); let needDel = taskList.filter(task => task.receiveData == undefined || task.receiveData.rec == true);

View File

@ -0,0 +1,68 @@
import {patchInit} from "../patch";
// import {addGameLog, connGameLogDB} from "../gameLog";
import {MongoClient} from "mongodb";
class Path {
async fun1(a: any) {
let logDB = await connGameLogDB();
console.log(11111,'开始查询')
let ab = await logDB.collection('gameLog').aggregate([
{$match: {"type": "kuangdong/YanShi", "req.hdid": {$lte: 21}}},
{$group: {_id: "$uid", total: {$sum: 1}}}
]).toArray()
let auids = ab.map(i => ({
uid: i._id,
type: 'yanshiNum',
time: G.time,
num: i.total,
data: {
...i
}
}))
console.log(auids)
// @ts-ignore
G.crossmongodb.collection('fupanLog').insertMany(auids)
return auids
}
async run() {
await this.fun1(1);
}
}
async function connGameLogDB() {
console.log('connect gamelog mongodb ......');
let logDBUrl:string;
if(G.config.isG123){
logDBUrl = "mongodb://root:lffu2bD%5eGn2%5eE%2bE7@blacklagoon-mongo-log-primary.pro.g123-cpp.com:3717,blacklagoon-mongo-log-secondary.pro.g123-cpp.com:3717?replicaSet=mgset-351742307";
}else{
logDBUrl = "mongodb://root:lyMaple525458@10.0.1.20:27017/heijiao_gamelog?authSource=admin";
}
let client = await MongoClient.connect(logDBUrl,{
maxPoolSize:10,
maxIdleTimeMS: 5*60*1000
});
return client.db(`gameLog${G.config.serverId}`);
}
async function main() {
await patchInit()
let patch = new Path();
await patch.run();
console.log("逻辑执行完成,等待退出");
setTimeout(function () {
console.log('结束程序');
process.exit();
}, 3000);
}
main();

View File

@ -0,0 +1,59 @@
import {log} from "console";
import {patchFun, patchInit} from "../patch";
import {TanXianFun} from "../public/tanxian";
import {PublicShared} from "../shared/public/public";
import {addGameLog} from "../gameLog";
class Path {
async fun1(a: any) {
// 查询今天登录的用户
let today_login_users = await G.mongodb.collection("actionLog").find(
{"log.use_attr_rmbmoney": {$gte: 100000}},
{projection: {uid: 1, "log.use_attr_rmbmoney": 1}}
).toArray();
let uids = today_login_users.map(i => i.uid)
let users = await G.mongodb.collection("user").find({
uid: {$in: uids},
vip: {$lte: 6}
}, {projection: {uid: 1, vip: 1, lv: 1}}).toArray()
let auids = users.map(i => ({
uid: i.uid,
type: 'shuazuanshi',
time: G.time,
data: {
vip: i.vip,
lv: i.lv,
rmbmoney: today_login_users.find(v => v.uid == i.uid)?.log?.use_attr_rmbmoney
}
}))
console.log(auids)
// @ts-ignore
G.crossmongodb.collection('fupanLog').insertMany(auids)
return auids
}
async run() {
await this.fun1(1);
}
}
async function main() {
await patchInit()
let patch = new Path();
await patch.run();
console.log("逻辑执行完成,等待退出");
setTimeout(function () {
console.log('结束程序');
process.exit();
}, 3000);
}
main();

View File

@ -1,4 +1,5 @@
import { Db, MongoClient } from "mongodb"; import { Db, MongoClient } from "mongodb";
import { Logger } from "tsrpc";
let logDB:Db; let logDB:Db;
let errorLogDB:Db; let errorLogDB:Db;
@ -28,13 +29,28 @@ async function connGameLogDB() {
return logDB; return logDB;
} }
export let mylogger: Logger = {
debug(...args: any[]){
console.debug(...args);
},
log(...args: any[]){
console.log(...args);
},
warn(...args: any[]){
console.warn(...args);
},
error(...args: any[]){
addErrorLog( args );
console.error(...args);
}
}
process.on('uncaughtException',function(err:Error){ process.on('uncaughtException',function(err:Error){
addErrorLog((err?.stack)?.toString()); addErrorLog( (err?.stack || err)?.toString() );
}) })
process.on('unhandledRejection', function (err:Error, promise) { process.on('unhandledRejection', function (err:Error, promise) {
addErrorLog((err?.stack)?.toString()); addErrorLog( (err?.stack || err)?.toString() );
}) })
async function addErrorLog(errData:any){ async function addErrorLog(errData:any){

View File

@ -58,6 +58,10 @@ export type eventType = {
payForDiamond: { payForDiamond: {
[time: number]: number [time: number]: number
} }
xstask: {
refreshTime: number,
receiveNum: number
}
} & { } & {
[k: `${number}jijin`]: ResOpenYuedujijin; [k: `${number}jijin`]: ResOpenYuedujijin;

View File

@ -401,7 +401,6 @@ export class PlayerFun {
*/ */
static async cutEquip(call: call, _idArr: string[]) { static async cutEquip(call: call, _idArr: string[]) {
for (let _id of _idArr) { for (let _id of _idArr) {
G.redis.del('equip', call.uid, _id);
G.mongodb.collection('equip').deleteOne({uid: call.uid, _id: new ObjectId(_id)}); G.mongodb.collection('equip').deleteOne({uid: call.uid, _id: new ObjectId(_id)});
call.addEventMsg('msg_s2c/EquipChange', _id, {num: 0}); call.addEventMsg('msg_s2c/EquipChange', _id, {num: 0});
@ -472,7 +471,6 @@ export class PlayerFun {
static async cutHero(call: call, _idArr: string[]) { static async cutHero(call: call, _idArr: string[]) {
for (let _id of _idArr) { for (let _id of _idArr) {
await HeroFun.delHero(call, _id); await HeroFun.delHero(call, _id);
G.redis.del('hero', call.uid, _id);
G.mongodb.collection('hero').deleteOne({uid: call.uid, _id: new ObjectId(_id)}); G.mongodb.collection('hero').deleteOne({uid: call.uid, _id: new ObjectId(_id)});
call.addEventMsg('msg_s2c/HeroChange', _id, {num: 0}); call.addEventMsg('msg_s2c/HeroChange', _id, {num: 0});
addGameLog(call.uid, "_cutHero", {}, {_id: _id}) addGameLog(call.uid, "_cutHero", {}, {_id: _id})

View File

@ -5,21 +5,26 @@ import { CollectionXstask } from '../module/collection_xstask';
import {PublicShared} from '../shared/public/public'; import {PublicShared} from '../shared/public/public';
export class XstaskFun { export class XstaskFun {
/**所有玩家的悬赏任务缓存 */ /**所有玩家的悬赏任务缓存 */
static uidTask: k_v<CollectionXstask[]> = {}; static uidTask: k_v<CollectionXstask[]> = {};
/**获取单个悬赏任务 */ /**获取单个悬赏任务 */
static async getTask(uid: string, _id: string) { static async getTask(uid: string, _id: string) {
return this.uidTask[uid]?.find(task => task._id == _id) || await G.mongodb.collection('xstask').findOne({ uid: uid, _id: G.mongodb.conversionId(_id) }); return this.uidTask[uid]?.find(task => task._id == _id) || await G.mongodb.collection('xstask').findOne({
uid: uid,
_id: G.mongodb.conversionId(_id)
});
} }
/**获取所有悬赏任务 */ /**获取所有悬赏任务 */
static async getAllTask(uid: string) { static async getAllTask(uid: string) {
let taskList = this.uidTask[uid]; let taskList = this.uidTask[uid];
if (!taskList) { if (!taskList) {
taskList = this.uidTask[uid] = (await G.mongodb.collection('xstask').find({uid: uid}).toArray()).map(task => G.mongodb.conversionIdObj(task)); taskList = this.uidTask[uid] = (await G.mongodb.collection('xstask').find({uid: uid}).toArray()).map(task => G.mongodb.conversionIdObj(task));
}; }
;
return taskList; return taskList;
} }
@ -27,7 +32,10 @@ export class XstaskFun {
/**完成任务标记 */ /**完成任务标记 */
static async finishTask(uid: string, _id: string) { static async finishTask(uid: string, _id: string) {
// 修改数据库 // 修改数据库
G.mongodb.collection('xstask').updateOne({ uid: uid, _id: G.mongodb.conversionId(_id) }, { $set: { 'receiveData.rec': true } }); G.mongodb.collection('xstask').updateOne({
uid: uid,
_id: G.mongodb.conversionId(_id)
}, {$set: {'receiveData.rec': true}});
// 修改缓存 // 修改缓存
let index = this.uidTask[uid]?.findIndex(task => task._id == _id); let index = this.uidTask[uid]?.findIndex(task => task._id == _id);
this.uidTask[uid][index].receiveData.rec = true this.uidTask[uid][index].receiveData.rec = true
@ -36,7 +44,10 @@ export class XstaskFun {
/**更新任务单个 */ /**更新任务单个 */
static async updateTask(uid: string, _id: string, taskId: string) { static async updateTask(uid: string, _id: string, taskId: string) {
G.mongodb.collection('xstask').updateOne({ uid: uid, _id: G.mongodb.conversionId(_id) }, { $unset: { receiveData: 1 }, $set: {taskId: taskId} }); G.mongodb.collection('xstask').updateOne({
uid: uid,
_id: G.mongodb.conversionId(_id)
}, {$unset: {receiveData: 1}, $set: {taskId: taskId}});
let index = this.uidTask[uid]?.findIndex(task => task._id == _id); let index = this.uidTask[uid]?.findIndex(task => task._id == _id);
delete this.uidTask[uid][index].receiveData; delete this.uidTask[uid][index].receiveData;
this.uidTask[uid][index].taskId = taskId; this.uidTask[uid][index].taskId = taskId;
@ -50,11 +61,13 @@ export class XstaskFun {
G.mongodb.collection('xstask').deleteOne({uid: uid, _id: G.mongodb.conversionId(_id)}); G.mongodb.collection('xstask').deleteOne({uid: uid, _id: G.mongodb.conversionId(_id)});
} }
/**删除多个悬赏任务 */ /**删除多个悬赏任务 */
static async delTasks(uid: string, _id: string[]) { static async delTasks(uid: string, _id: string[]) {
for (let id of _id) await this.delTask(uid, id); for (let id of _id) await this.delTask(uid, id);
} }
/**添加多个悬赏任务 */ /**添加多个悬赏任务 */
static async addTasks(uid: string, taskArr: { taskId: string; }[]) { static async addTasks(uid: string, taskArr: { taskId: string; }[]) {
@ -76,12 +89,17 @@ export class XstaskFun {
return this.uidTask[uid]; return this.uidTask[uid];
} }
/**派遣任务任务 */ /**派遣任务任务 */
static async receiveTask(uid: string, _id: string, d: CollectionXstask['receiveData']) { static async receiveTask(uid: string, _id: string, d: CollectionXstask['receiveData']) {
let cache = this.uidTask[uid]?.find(task => task._id == _id); let cache = this.uidTask[uid]?.find(task => task._id == _id);
if (cache) cache.receiveData = d; if (cache) cache.receiveData = d;
G.mongodb.collection('xstask').updateOne({ uid: uid, _id: G.mongodb.conversionId(_id) }, { $set: { receiveData: d } }); G.mongodb.collection('xstask').updateOne({
uid: uid,
_id: G.mongodb.conversionId(_id)
}, {$set: {receiveData: d}});
} }
/**获取所有已被派遣的英雄 */ /**获取所有已被派遣的英雄 */
static async getAllReceiveHero(uid: string) { static async getAllReceiveHero(uid: string) {
let heroIds: string[] = []; let heroIds: string[] = [];
@ -91,10 +109,12 @@ export class XstaskFun {
return heroIds; return heroIds;
} }
/**获取悬赏任务记录信息 */ /**获取悬赏任务记录信息 */
static async getInfo(uid: string) { static async getInfo(uid: string) {
return await G.mongodb.collection('playerInfo', 'xstask').findOne({uid: uid, type: 'xstask'}); return await G.mongodb.collection('playerInfo', 'xstask').findOne({uid: uid, type: 'xstask'});
} }
/**修改悬赏任务记录信息 */ /**修改悬赏任务记录信息 */
static async changeInfo(uid: string, change: Pick<UpdateFilter<OptionalId<playerInfoType['xstask']>>, '$inc' | '$set'>) { static async changeInfo(uid: string, change: Pick<UpdateFilter<OptionalId<playerInfoType['xstask']>>, '$inc' | '$set'>) {
@ -104,6 +124,7 @@ export class XstaskFun {
{upsert: true} {upsert: true}
); );
} }
/**随机任务 */ /**随机任务 */
static randomTasks(lv: number, num: number) { static randomTasks(lv: number, num: number) {
let tasks = Object.values(G.gc.xstask).filter(task => G.gc.xstaskcom.lv[lv].taskColor.includes(task.colour)).sort(function () { let tasks = Object.values(G.gc.xstask).filter(task => G.gc.xstaskcom.lv[lv].taskColor.includes(task.colour)).sort(function () {
@ -136,4 +157,18 @@ export class XstaskFun {
} }
return _res; return _res;
} }
/**
* 8
*/
static async receiveNum(uid: string, refresh = false) {
if (refresh) {
G.mongodb.cEvent('xstask').updateOne({uid: uid, type: 'xstask'},
{$set: {refreshTime: G.time, receiveNum: 0}}, {upsert: true});
} else {
G.mongodb.cEvent('xstask').updateOne({uid: uid, type: 'xstask'},
{$inc: {receiveNum: 1}}, {upsert: true});
}
}
} }

View File

@ -13,6 +13,7 @@ import {player} from './shared/protocols/user/type';
import {unQueueByConn} from './api_s2c/user/ApiLogin'; import {unQueueByConn} from './api_s2c/user/ApiLogin';
import {clusterPublish, setUidProcessId} from './clusterUtils'; import {clusterPublish, setUidProcessId} from './clusterUtils';
import {clearGud, getGud} from './public/gud'; import {clearGud, getGud} from './public/gud';
import { mylogger } from './gameLog';
export async function createWs() { export async function createWs() {
@ -25,7 +26,8 @@ export async function createWs() {
json: true, json: true,
//API超时时间5分钟为登陆排队做准备 //API超时时间5分钟为登陆排队做准备
apiTimeout: 300000, apiTimeout: 300000,
logLevel: G.argv.logModel as LogLevel logLevel: G.argv.logModel as LogLevel,
logger:mylogger
}); });
setCrossWs(G.serverCross); setCrossWs(G.serverCross);
await G.serverCross.autoImplementApi(resolve(__dirname, 'api_cross'), true); await G.serverCross.autoImplementApi(resolve(__dirname, 'api_cross'), true);
@ -37,6 +39,7 @@ export async function createWs() {
wss: getWssFile(), wss: getWssFile(),
//API超时时间5分钟为登陆排队做准备只针对游服 //API超时时间5分钟为登陆排队做准备只针对游服
apiTimeout: 300000, apiTimeout: 300000,
logger:mylogger
}); });
setWs(G.server); setWs(G.server);
await G.server.autoImplementApi(resolve(__dirname, 'api_s2c'), true); await G.server.autoImplementApi(resolve(__dirname, 'api_s2c'), true);