Merge branch 'bugfix' into dev
This commit is contained in:
commit
24649d335c
@ -11,7 +11,7 @@ export default async function (call: ApiCall<ReqBuy, ResBuy>) {
|
||||
|
||||
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];
|
||||
|
||||
|
@ -17,7 +17,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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<ReqRefresh, ResRefresh>) {
|
||||
let shopId = call.req.shopId;
|
||||
@ -9,7 +9,7 @@ export default async function (call: ApiCall<ReqRefresh, ResRefresh>) {
|
||||
|
||||
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<ReqRefresh, ResRefresh>) {
|
||||
|
||||
await ShopFun.changeShopData(uid, shopId, change);
|
||||
|
||||
let { buyNum, shopItems, ...ops } = change;
|
||||
let {buyNum, shopItems, ...ops} = change;
|
||||
call.succ({buyNum: buyNum, shopItems: shopItems, ...ops});
|
||||
}
|
33
src/fix_patch/patch_test.ts
Normal file
33
src/fix_patch/patch_test.ts
Normal file
@ -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();
|
@ -1213,6 +1213,7 @@ type gc_shop = k_v<{
|
||||
'npcImg': number
|
||||
/** 商店看板娘说话 */
|
||||
'npcText': string
|
||||
'version': string | number
|
||||
}>;
|
||||
|
||||
type gc_shopcom = k_v<{
|
||||
|
@ -4,4 +4,5 @@ import {ResOpen} from '../shared/protocols/shop/PtlOpen';
|
||||
export type CollectionShop = ResOpen & {
|
||||
uid: string; // 玩家uid
|
||||
shopId: string; // 商店id
|
||||
version: string | number;
|
||||
};
|
68
src/patch.ts
Normal file
68
src/patch.ts
Normal file
@ -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();
|
@ -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<boolean> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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){
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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'),
|
||||
])
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"moduleResolution": "node"
|
||||
"moduleResolution": "node",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"include": [
|
||||
"src",
|
||||
|
Loading…
Reference in New Issue
Block a user