diff --git a/src/api_s2c/shop/ApiBuy.ts b/src/api_s2c/shop/ApiBuy.ts index ea47e0f..6ce5924 100644 --- a/src/api_s2c/shop/ApiBuy.ts +++ b/src/api_s2c/shop/ApiBuy.ts @@ -11,7 +11,7 @@ export default async function (call: ApiCall) { let uid = shopId != "2" ? call.uid : call.conn.gud.ghId - let shopData = await ShopFun.getShopData(uid, shopId); + let shopData = await ShopFun.getShopData(uid, shopId, call.conn.gud.lv); let shopItem = shopData.shopItems[index]; diff --git a/src/api_s2c/shop/ApiOpen.ts b/src/api_s2c/shop/ApiOpen.ts index 809bb94..e78a366 100644 --- a/src/api_s2c/shop/ApiOpen.ts +++ b/src/api_s2c/shop/ApiOpen.ts @@ -17,7 +17,7 @@ export default async function (call: ApiCall) { let uid = shopId != "2" ? call.uid : call.conn.gud.ghId - let shopData = await ShopFun.getShopData(uid, shopId) + let shopData = await ShopFun.getShopData(uid, shopId, call.conn.gud.lv) call.succ(shopData); } diff --git a/src/api_s2c/shop/ApiRefresh.ts b/src/api_s2c/shop/ApiRefresh.ts index b77029c..e095dcd 100644 --- a/src/api_s2c/shop/ApiRefresh.ts +++ b/src/api_s2c/shop/ApiRefresh.ts @@ -1,7 +1,7 @@ -import { ApiCall } from "tsrpc"; -import { PlayerFun } from '../../public/player'; -import { ShopFun } from '../../public/shop'; -import { ReqRefresh, ResRefresh } from "../../shared/protocols/shop/PtlRefresh"; +import {ApiCall} from "tsrpc"; +import {PlayerFun} from '../../public/player'; +import {ShopFun} from '../../public/shop'; +import {ReqRefresh, ResRefresh} from "../../shared/protocols/shop/PtlRefresh"; export default async function (call: ApiCall) { let shopId = call.req.shopId; @@ -9,7 +9,7 @@ export default async function (call: ApiCall) { let uid = shopId != "2" ? call.uid : call.conn.gud.ghId - let shopData = await ShopFun.getShopData(uid, shopId); + let shopData = await ShopFun.getShopData(uid, shopId, call.conn.gud.lv); if (!shopData) return call.error(globalThis.lng.shop_1); @@ -46,6 +46,6 @@ export default async function (call: ApiCall) { await ShopFun.changeShopData(uid, shopId, change); - let { buyNum, shopItems, ...ops } = change; + let {buyNum, shopItems, ...ops} = change; call.succ({buyNum: buyNum, shopItems: shopItems, ...ops}); } \ No newline at end of file diff --git a/src/fix_patch/patch_test.ts b/src/fix_patch/patch_test.ts new file mode 100644 index 0000000..f2e7e46 --- /dev/null +++ b/src/fix_patch/patch_test.ts @@ -0,0 +1,33 @@ +import { patchFun, patchInit } from "../patch"; + +class Path{ + @patchFun + async fun1(a:any) { + //这里执行脚本的内容,加了patchFun的函数,不允许重复执行 + console.log("这是第1个脚本里内容"); + return 12 + } + + @patchFun + async fun2(a:any) { + //这里执行脚本的内容,加了patchFun的函数,不允许重复执行 + console.log("这是第2个脚本里内容"); + return 12 + } + + async run(){ + await this.fun1(1); + await this.fun2(2); + } +} + +async function main(){ + await patchInit() + let patch = new Path(); + await patch.run(); + setInterval(() => { + console.log(new Date().format("MM-dd hh:mm:ss")); + }, 1000); + console.log("逻辑执行完成,等待退出"); +} +main(); diff --git a/src/jsonType.ts b/src/jsonType.ts index aacb4a8..c953d75 100644 --- a/src/jsonType.ts +++ b/src/jsonType.ts @@ -1213,6 +1213,7 @@ type gc_shop = k_v<{ 'npcImg': number /** 商店看板娘说话 */ 'npcText': string + 'version': string | number }>; type gc_shopcom = k_v<{ diff --git a/src/module/collection_shop.ts b/src/module/collection_shop.ts index cf12500..657838b 100644 --- a/src/module/collection_shop.ts +++ b/src/module/collection_shop.ts @@ -4,4 +4,5 @@ import {ResOpen} from '../shared/protocols/shop/PtlOpen'; export type CollectionShop = ResOpen & { uid: string; // 玩家uid shopId: string; // 商店id + version: string | number; }; \ No newline at end of file diff --git a/src/patch.ts b/src/patch.ts new file mode 100644 index 0000000..c5b3d7a --- /dev/null +++ b/src/patch.ts @@ -0,0 +1,68 @@ +import { extendType } from "./extends"; +import { ctor } from "./global"; +import { initIORedis } from "./ioredis"; +import { initGcType } from "./jsonType"; +import { createLng } from "./lng"; +import { initMongoDB } from "./setMongodb"; +import { initRedis } from "./setRedis"; + +var path = require('path'); +var scriptName = path.basename(__filename); + +export function patchFun(target: any, key: string, descriptor: PropertyDescriptor) { + let scriptName; + try { + throw new Error(); + } catch (e) { + let caller = (e.stack.split("\n").slice(2)[0].split("\\").slice(-2)); + scriptName = caller[1].split(':')[0]; + } + + if(!scriptName){ + console.log('获取不到脚本名'); + return; + } + const originalMethod = descriptor.value; + descriptor.value = function(...args: any[]) { + //@ts-ignore + G.mongodb.collection("_patch_run_log").findOne({ fileName: scriptName, funName: key }).then(async runed=>{ + if(runed){ + console.log(`脚本${scriptName}已经执行过${key}方法,跳过`); + return (null as any); + } + + console.log(`调用了${scriptName}脚本里的${key}方法,参数为:${args}`); + const result = await originalMethod.apply(this, args); + console.log(`执行结果为:${result}`); + + //@ts-ignore + await G.mongodb.collection("_patch_run_log").insertOne({ + "fileName": scriptName, + "funName": key as any, + "ctime":Date.now(), + "res":result + }); + return (result as any); + }); + } +} + +export async function patchInit() { + await patchStart(); +} + +async function patchStart() { + //扩展框架 + extendType(); + //游戏配置提示文件 + initGcType(); + //连接mongodb + await initMongoDB(); + //连接redis + await initRedis(); + await initIORedis(); +} +// //定义全局变量 +ctor(); +//创建语言包 +createLng(); \ No newline at end of file diff --git a/src/public/gonghui/gh.ts b/src/public/gonghui/gh.ts index 3b17a08..7676982 100644 --- a/src/public/gonghui/gh.ts +++ b/src/public/gonghui/gh.ts @@ -31,14 +31,21 @@ export class GH { } /**更改isFightBoss状态 */ - changeIsFightBoss(bool = false) { - G.redis.hSet('gonghui:isFightBoss', this.data._id, bool) + async changeIsFightBoss(bool = false) { + const key = 'gonghui:isFightBoss:' + this.data._id; + if (bool) { + await G.ioredis.setnx(key, 1); + await G.ioredis.expire(key, 1); + } else { + await G.ioredis.del(key); + } return } /**获取isFightBoss状态 */ async getIsFightBoss(): Promise { - return await G.redis.hGet('gonghui:isFightBoss', this.data._id) || false + const key = 'gonghui:isFightBoss:' + this.data._id; + return await G.ioredis.get(key)? true : false; } /** diff --git a/src/public/gud.ts b/src/public/gud.ts index 8ba809b..c4a4dda 100644 --- a/src/public/gud.ts +++ b/src/public/gud.ts @@ -23,6 +23,12 @@ export async function clearGud(uid) { console.log('清空tanxian Redis',uid); G.redis.del("tanxian",uid); } + try{ + console.log('清空friend:list Redis',uid); + G.redis.hDel("friend:list",uid); + }catch(e){ + + } }; /** diff --git a/src/public/shop.ts b/src/public/shop.ts index 9145f0f..a8c8e9e 100644 --- a/src/public/shop.ts +++ b/src/public/shop.ts @@ -94,7 +94,7 @@ export class ShopFun { )).value } - static async getShopData(uid: string, shopId: string) { + static async getShopData(uid: string, shopId: string, lv: number) { let where = { uid: uid, shopId: shopId @@ -114,6 +114,10 @@ export class ShopFun { await this.changeShopData(uid, shopId, {useFreeRefreshNum: 0, lastFreeRefreshTime: G.time}); } + if (shopConf.version && shopConf.version != shopData.version) { + await this.changeShopData(uid, shopId, {shopItems: this.getShopItems(shopId, lv)}) + } + return shopData } diff --git a/src/setRedis.ts b/src/setRedis.ts index b27ee0c..6e6b155 100644 --- a/src/setRedis.ts +++ b/src/setRedis.ts @@ -77,8 +77,9 @@ async function clearRedis() { G.redis.fromatKey('hero'), G.redis.fromatKey('equip'), G.redis.fromatKey('shiwu'), - //G.redis.fromatKey('gbtx'), - //G.redis.fromatKey('dxlt'), + G.redis.fromatKey('tanxian'), + G.redis.fromatKey('gbtx'), + G.redis.fromatKey('dxlt'), ]) } diff --git a/tsconfig.json b/tsconfig.json index 4352908..dd6c539 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "moduleResolution": "node" + "moduleResolution": "node", + "experimentalDecorators": true }, "include": [ "src",