From ac51a2302e3c1da950cb7343eadcd5ee5f1f2ad6 Mon Sep 17 00:00:00 2001 From: luying Date: Mon, 10 Jan 2022 14:30:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=EF=BC=9A=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E9=A2=91=E7=8E=87=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/servers/connector/filter/global.ts | 31 +++++++++++++++---- shared/consts/statusCode.ts | 2 +- shared/pubUtils/dictionary/DicServerConst.ts | 16 ++++++++-- shared/resource/jsons/server_const.json | 15 ++++----- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/game-server/app/servers/connector/filter/global.ts b/game-server/app/servers/connector/filter/global.ts index 12bdfb275..188c216eb 100644 --- a/game-server/app/servers/connector/filter/global.ts +++ b/game-server/app/servers/connector/filter/global.ts @@ -18,15 +18,27 @@ var Filter = function(this: any, app: Application) { this.accessTime = new Map(); }; -Filter.prototype.checkFrequency = function(route: string, roleId: string) { - if(gameData.serverConst.PROTECT_API.indexOf(route) == -1) { +Filter.prototype.checkFrequency = function(route: string, msg: any, roleId: string) { + let protect = gameData.serverConst.PROTECT_API.find(cur => { + if(cur.route == route) { + let paramOK = true; + for(let key in cur.param) { + if(msg[key] != cur.param[key]) { + paramOK = false; break; + } + } + if(paramOK) return true; + } + return false; + }); + if(!protect) { return true; } - let keyOfRouteWithUser = `${route}_${roleId}`; + let keyOfRouteWithUser = `${protect.id}_${roleId}`; if(this.accessTime && this.accessTime.has(keyOfRouteWithUser)) { console.log(this.accessTime.get(keyOfRouteWithUser) - Date.now()); - if(Date.now() - this.accessTime.get(keyOfRouteWithUser) < gameData.serverConst.PROTECT_API_INTERVAL) { - errlogger.error(`${keyOfRouteWithUser} 间隔时间小于${gameData.serverConst.PROTECT_API_INTERVAL}ms,为 ${Date.now() - this.accessTime.get(keyOfRouteWithUser)}`); + if(Date.now() - this.accessTime.get(keyOfRouteWithUser) < protect.interval) { + errlogger.info(`${keyOfRouteWithUser} 间隔时间小于${protect.interval}ms,为 ${Date.now() - this.accessTime.get(keyOfRouteWithUser)}`); return false; } } @@ -54,7 +66,7 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se let guildCode = session.get('guildCode'); let blockType = session.get('blockType'); // 访问频率控制 - if(!this.checkFrequency(routeRecord.route, roleId)) { + if(!this.checkFrequency(routeRecord.route, msg, roleId)) { return next(new Error('globalFilter'), resResult(STATUS.ACCESS_BUSY)); } if(!this.checkFunction(routeRecord.route)) { @@ -67,6 +79,7 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se if([ 'chat.chatHandler.sendPrivateMessage', 'chat.chatHandler.sendGroupMessage', + 'battle.comBattleHandler.sendTeamMsg', 'battle.barrageHandler.sendBarrage', 'guild.guildHandler.sendMail', 'guild.guildHandler.setGuildInfo', @@ -113,6 +126,12 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se break; } } + case 'battle.comBattleHandler.sendTeamMsg': + { + let result = await checkOtherChat(roleId, CHANNEL_PREFIX.TEAM, msg.content); + if(!result) hasBlockWords = true; + break; + } case 'battle.barrageHandler.sendBarrage': { let result = await checkOtherChat(roleId, CHANNEL_PREFIX.WORLD, msg.content); diff --git a/shared/consts/statusCode.ts b/shared/consts/statusCode.ts index 09cbd8973..e8ab35553 100644 --- a/shared/consts/statusCode.ts +++ b/shared/consts/statusCode.ts @@ -12,7 +12,7 @@ export const STATUS = { BLOCK_WORDS: { code: 9, simStr: '内容有不合法词汇' }, BLOCKED: { code: 10, simStr: '您已被封禁' }, BANNED: { code: 11, simStr: '您已被禁言' }, - ACCESS_BUSY: { code: 12, simStr: '您的操作过于繁忙' }, + ACCESS_BUSY: { code: 12, simStr: '您不久前发送过消息了,请稍等一下' }, ONLINE_USER_MAX: { code: 13, simStr: '服务器繁忙,请稍后再试' }, FUNCTION_CLOSE: { code: 14, simStr: '抱歉,该功能暂时关闭' }, GLOBAL_ERR: { code: 1003, simStr: '服务器内部错误' }, diff --git a/shared/pubUtils/dictionary/DicServerConst.ts b/shared/pubUtils/dictionary/DicServerConst.ts index d9563b4c6..9d8ee7c1b 100644 --- a/shared/pubUtils/dictionary/DicServerConst.ts +++ b/shared/pubUtils/dictionary/DicServerConst.ts @@ -2,11 +2,21 @@ import { readFileAndParse } from '../util' import { FILENAME } from '../../consts' +interface ProtectApi { + // id + readonly id: number; + // 描述 + readonly desc: string; + // 接口 + readonly route: string; + // 参数 + readonly param: any; + // 频率 毫秒 + readonly interval: number; +} export interface DicServerConst { - // 保护接口,间隔时间 - readonly PROTECT_API_INTERVAL: number; // 保护的接口 - readonly PROTECT_API: string[]; + readonly PROTECT_API: ProtectApi[]; // 某些api功能关闭 readonly API_IS_CLOSE: number; // 关闭的接口 diff --git a/shared/resource/jsons/server_const.json b/shared/resource/jsons/server_const.json index 8cfff8c89..6b14da418 100644 --- a/shared/resource/jsons/server_const.json +++ b/shared/resource/jsons/server_const.json @@ -1,13 +1,14 @@ { - "PROTECT_API_INTERVAL": 500, - "PROTECT_API": [ - "chat.chatHandler.sendGroupMessage", - "chat.chatHandler.sendPrivateMessage", - "battle.barrageHandler.sendBarrage" - ], "API_IS_CLOSE": 0, "CLOSE_APIS": [], "CLOSE_LOGIN": 0, "CLOSE_LOGIN_WHEN_ONLINE_MAX": 1, - "MAX_ONLINE_USER_COUNT": 5000 + "MAX_ONLINE_USER_COUNT": 5000, + "PROTECT_API": [ + { "id": 1, "desc": "世界聊天", "route": "chat.chatHandler.sendGroupMessage", "param": { "channel": "world" }, "interval": 20000 }, + { "id": 2, "desc": "军团聊天", "route": "chat.chatHandler.sendGroupMessage", "param": { "channel": "guild" }, "interval": 5000 }, + { "id": 3, "desc": "组团聊天", "route": "battle.comBattleHandler.sendTeamMsg", "param": {}, "interval": 5000 }, + { "id": 4, "desc": "私聊", "route": "chat.chatHandler.sendPrivateMessage", "param": {}, "interval": 5000 }, + { "id": 5, "desc": "发送弹幕", "route": "battle.barrageHandler.sendBarrage", "param": {}, "interval": 5000 } + ] } \ No newline at end of file