api 锁修改,一键接取悬赏
This commit is contained in:
parent
826840455c
commit
ecc17a22a9
@ -1,9 +1,10 @@
|
||||
import { ApiCall } from "tsrpc";
|
||||
import { HeroFun } from '../../public/hero';
|
||||
import { XstaskFun } from '../../public/xstask';
|
||||
import { ReqOnekeyReceive, ResOnekeyReceive } from "../../shared/protocols/xstask/PtlOnekeyReceive";
|
||||
import { HeroShared } from '../../shared/public/hero';
|
||||
import { HongDianChange } from "../hongdian/fun";
|
||||
import {ApiCall} from "tsrpc";
|
||||
import { addGameLog } from "../../gameLog";
|
||||
import {HeroFun} from '../../public/hero';
|
||||
import {XstaskFun} from '../../public/xstask';
|
||||
import {ReqOnekeyReceive, ResOnekeyReceive} from "../../shared/protocols/xstask/PtlOnekeyReceive";
|
||||
import {HeroShared} from '../../shared/public/hero';
|
||||
import {HongDianChange} from "../hongdian/fun";
|
||||
|
||||
export default async function (call: ApiCall<ReqOnekeyReceive, ResOnekeyReceive>) {
|
||||
|
||||
@ -33,7 +34,9 @@ export default async function (call: ApiCall<ReqOnekeyReceive, ResOnekeyReceive>
|
||||
if (heroList.length != heroIds.length) return call.error(globalThis.lng.xstask_6);
|
||||
|
||||
let change: ResOnekeyReceive = {};
|
||||
let lockNum = event?.receiveNum || 0
|
||||
for (let receive of args) {
|
||||
if (lockNum >= 8) continue
|
||||
let task = taskList.find(task => task._id == receive._id);
|
||||
let taskConf = G.gc.xstask[task.taskId];
|
||||
|
||||
@ -43,8 +46,9 @@ export default async function (call: ApiCall<ReqOnekeyReceive, ResOnekeyReceive>
|
||||
let star = heros.map(h => G.gc.hero[h.heroId].star).reduce((a, b) => a + b);
|
||||
if (star < taskConf.needStar) return call.error(globalThis.lng.xstask_8);
|
||||
|
||||
change[receive._id] = { time: G.time, heros: receive.heroIds };
|
||||
change[receive._id] = {time: G.time, heros: receive.heroIds};
|
||||
XstaskFun.receiveNum(call.uid)
|
||||
lockNum += 1
|
||||
}
|
||||
|
||||
Object.entries(change).forEach(([k, v]) => {
|
||||
@ -53,4 +57,6 @@ export default async function (call: ApiCall<ReqOnekeyReceive, ResOnekeyReceive>
|
||||
HongDianChange.sendChangeKey(call.uid, ['xstaskhd', 'huodonghd']);
|
||||
|
||||
call.succ(change);
|
||||
|
||||
addGameLog(call.uid, "_onekeyReceive", {}, change)
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
},
|
||||
{
|
||||
"key":"got_jinbi",
|
||||
"limit":200000000,
|
||||
"limit":2000000000,
|
||||
"tips":"jinbi获取达到20亿"
|
||||
},
|
||||
{
|
||||
|
18
src/setWs.ts
18
src/setWs.ts
@ -13,7 +13,7 @@ import {player} from './shared/protocols/user/type';
|
||||
import {unQueueByConn} from './api_s2c/user/ApiLogin';
|
||||
import {clusterPublish, setUidProcessId} from './clusterUtils';
|
||||
import {clearGud, getGud} from './public/gud';
|
||||
import { mylogger } from './gameLog';
|
||||
import {mylogger} from './gameLog';
|
||||
|
||||
export async function createWs() {
|
||||
|
||||
@ -27,7 +27,7 @@ export async function createWs() {
|
||||
//API超时时间5分钟,为登陆排队做准备
|
||||
apiTimeout: 300000,
|
||||
logLevel: G.argv.logModel as LogLevel,
|
||||
logger:mylogger
|
||||
logger: mylogger
|
||||
});
|
||||
setCrossWs(G.serverCross);
|
||||
await G.serverCross.autoImplementApi(resolve(__dirname, 'api_cross'), true);
|
||||
@ -39,7 +39,7 @@ export async function createWs() {
|
||||
wss: getWssFile(),
|
||||
//API超时时间5分钟,为登陆排队做准备,只针对游服
|
||||
apiTimeout: 300000,
|
||||
logger:mylogger
|
||||
logger: mylogger
|
||||
});
|
||||
setWs(G.server);
|
||||
await G.server.autoImplementApi(resolve(__dirname, 'api_s2c'), true);
|
||||
@ -140,7 +140,7 @@ function setWs(server: WsServer<ServiceType>) {
|
||||
//处理API锁,极限情况下只锁10s,防止死锁
|
||||
//在下方postApiReturnFlow里会解锁
|
||||
if (call.conn.apiLock[call.service.name] && call.conn.apiLock[call.service.name] > new Date().getTime()) {
|
||||
call.error('', {code: -100, message: '', time: 0});
|
||||
call.error('', {code: -100, message: '', apilock: 1});
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -198,11 +198,15 @@ function setWs(server: WsServer<ServiceType>) {
|
||||
//API解锁
|
||||
let now = new Date().getTime();
|
||||
|
||||
if(node.return.isSucc){
|
||||
node.call.conn.apiLock[node.call.service.name] = now+200;
|
||||
}else{
|
||||
if (node.return.isSucc) {
|
||||
if (!writeList.includes(node.call.service.name)){
|
||||
node.call.conn.apiLock[node.call.service.name] = now + 200;
|
||||
}
|
||||
} else {
|
||||
if (!node.return.err.apilock) {
|
||||
delete node.call.conn.apiLock[node.call.service.name];
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user