满足条件开启功能推送,详细功能校验暂缺
This commit is contained in:
35
game-server/app/services/funcSwitchService.ts
Normal file
35
game-server/app/services/funcSwitchService.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Application, BackendSession, FrontendSession } from "pinus";
|
||||
import { getGamedata } from "../pubUtils/gamedata";
|
||||
import Role, { RoleModel } from "../db/Role";
|
||||
import { FUNC_OPT_TYPE } from "../consts/consts";
|
||||
|
||||
// 开启功能
|
||||
export async function switchOnFunc(roleId: string, type: number, param: number, app: Application, session: (BackendSession|FrontendSession)) {
|
||||
|
||||
const serverId = session.get('serverId');
|
||||
const dataFuncs = session.get('funcs');
|
||||
const dicFuncSwitch = getGamedata('dic_func_switch');
|
||||
|
||||
let funcs = new Array<{id: number, desc: string, script: string}>(), addFuncs = new Array<number>();
|
||||
for(let obj of dicFuncSwitch) {
|
||||
if(obj.conditionType == type && !dataFuncs.includes(obj.id) && obj.param == param) {
|
||||
funcs.push({id: obj.id, desc: obj.desc, script: obj.script});
|
||||
addFuncs.push(obj.id);
|
||||
}
|
||||
}
|
||||
|
||||
let channelService = app.get('channelService');
|
||||
let channel = channelService.getChannel(`server-${serverId}`, false);
|
||||
if(!!channel && funcs.length > 0) {
|
||||
let tsid = channel.getMember(roleId)['sid'];
|
||||
|
||||
channelService.pushMessageByUids('onFuncSwitchOn', {funcs}, [{
|
||||
uid: roleId,
|
||||
sid: tsid
|
||||
}]);
|
||||
}
|
||||
const recs = await RoleModel.pushFuncs(roleId, addFuncs);
|
||||
session.set('funcs', recs.funcs||[]);
|
||||
session.push('funcs', () => {});
|
||||
return recs
|
||||
}
|
||||
Reference in New Issue
Block a user