后台:角色封禁

This commit is contained in:
luying
2021-11-26 16:50:29 +08:00
parent 4d6b87ce97
commit 2e48a4dfc1
12 changed files with 90 additions and 32 deletions

View File

@@ -3,7 +3,7 @@ import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback, pin
import { refresh } from '../../../services/refreshService';
import { checkPrivateChat, checkGuildChat, checkOtherChat, checkRoleName, checkGuildName } from "../../../services/sdkService";
import { resResult, checkWhiteListWithUid, genCode } from "../../../pubUtils/util";
import { CHANNEL_PREFIX, STATUS } from "../../../consts";
import { BLOCK_TYPE, CHANNEL_PREFIX, STATUS } from "../../../consts";
import { UserModel } from "../../../db/User";
import { SERVER_DEBUG_MODE } from "../../../pubUtils/dicParam";
export function globalFilter(app: Application) {
@@ -20,7 +20,21 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
const roleId: string = session.get('roleId');
const uid: number = session.get('userid');
let guildCode = session.get('guildCode');
let blockType = session.get('blockType');
if(blockType == BLOCK_TYPE.BLOCK) return next(new Error(), resResult(STATUS.BLOCKED));
if(blockType == BLOCK_TYPE.BAN) {
if([
'chat.chatHandler.sendPrivateMessage',
'chat.chatHandler.sendGroupMessage',
'battle.barrageHandler.sendBarrage',
'guild.guildHandler.sendMail',
'guild.guildHandler.setGuildInfo',
].indexOf(routeRecord.route) != -1) {
return next(new Error(), resResult(STATUS.BANNED));
}
}
session.push('teamCode', () => {});
const maintenServers = this.app.get('maintenServers');
@@ -33,15 +47,6 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
}
let hasBlockWords = false;
// if(pinus.app.get('env') == 'production') {
// if(routeRecord.route == 'guild.guildHandler.createGuild') {
// hasBlockWords = await checkFilterWords(msg.name);
// } else if (routeRecord.route == 'role.roleHandler.initRole') {
// hasBlockWords = await checkFilterWords(msg.roleName);
// } else if (routeRecord.route == 'role.roleHandler.rename') {
// hasBlockWords = await checkFilterWords(msg.roleName);
// }
// }
if(SERVER_DEBUG_MODE.CHECK_WORD == 1) {
switch(routeRecord.route) {
case 'chat.chatHandler.sendPrivateMessage':
@@ -62,6 +67,18 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
break;
}
}
case 'battle.barrageHandler.sendBarrage':
{
let result = await checkOtherChat(roleId, CHANNEL_PREFIX.WORLD, msg.content);
if(!result) hasBlockWords = true;
break;
}
case 'guild.guildHandler.sendMail':
{
let result = await checkGuildChat(roleId, guildCode, msg.info);
if(!result) hasBlockWords = true;
break;
}
case 'role.roleHandler.rename':
case 'role.roleHandler.initRole':
{

View File

@@ -128,6 +128,7 @@ export class EntryHandler {
session.set('updatedMailAt', updatedMailAt);
session.set('roleName', role.roleName);
session.set('eventStatus', role.eventStatus);
session.set('blockType', role.blockType);
session.set('sid', self.app.get('serverId'));
session.set('serverId', role.serverId);
session.set('guildCode', role.guildCode);
@@ -139,6 +140,7 @@ export class EntryHandler {
session.push('serverId', () => { });
session.push('updatedMailAt', () => { });
session.push('guildCode', () => { });
session.push('blockType', () => { });
// console.log(role.guildCode)
// session.push('rid', function (err) {
// if (err) {

View File

@@ -18,8 +18,8 @@ export class ConnectorRemote {
}
private maintenServers: number[] = []; // 维护中的服务器
public async remoteLogin(uid: string) {
await kickUser(this.app, uid);
public async remoteLogin(uid: string, message?: any) {
await kickUser(this.app, uid, message);
}
public async setOtherUserGuildSession(params: { roleId: string, userGuild: UserGuildType}[]) {
@@ -50,6 +50,18 @@ export class ConnectorRemote {
}
}
public async setOtherUseBlockTypeSession(params: { roleId: string, blockType: string}[]) {
let sessionService = this.app.get('sessionService');
for(let {roleId, blockType} of params) {
let sessions = sessionService.getByUid(roleId);
if(!!sessions) {
sessions.forEach(session => {
sessionService.aimportAll(session.id, { blockType });
});
}
}
}
/**
* 重载json资源
*/

View File

@@ -6,6 +6,7 @@ import { addItems, createHeroes } from '../../../services/rewardService';
import { RewardInter } from '../../../pubUtils/interface';
import { getExpByLv } from '../../../pubUtils/data';
import { RoleModel } from '../../../db/Role';
import { BLOCK_TYPE } from '../../../consts';
let timer: NodeJS.Timer;
export default function (app: Application) {
return new GmRoleHandler(app);
@@ -32,7 +33,7 @@ export class GmRoleHandler {
await createHeroes(roleId, roleName, sid, serverId, heroes.map(hid => { return { hid, count: 1 }}))
}
if(lv && lv > 0) {
let exp = getExpByLv(lv)?.sum||0;
let exp = getExpByLv(lv - 1)?.sum||0;
await RoleModel.updateRoleInfo(roleId, { lv, exp })
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerExpChange', resResult(STATUS.SUCCESS, {
@@ -42,4 +43,18 @@ export class GmRoleHandler {
return resResult(STATUS.SUCCESS);
}
async handleBlock(msg: { roleId: string, blockType: BLOCK_TYPE, blockReason: string }, session: BackendSession) {
let { roleId, blockType, blockReason } = msg;
if(roleId == undefined || blockType == undefined || blockReason == undefined) return resResult(STATUS.WRONG_PARMS);
let role = await RoleModel.updateRoleInfo(roleId, { blockType, blockReason });
if(!role) return resResult(STATUS.ROLE_NOT_FOUND);
let { isOnline, sid } = await getRoleOnlineInfo(roleId);
if(isOnline) {
await this.app.rpc.connector.connectorRemote.setOtherUseBlockTypeSession.toServer(sid,[{ roleId, blockType }]);
if(blockType == BLOCK_TYPE.BLOCK) { // 踢走
await this.app.rpc.connector.connectorRemote.remoteLogin.toServer(sid, roleId, STATUS.BLOCKED);
}
}
return resResult(STATUS.SUCCESS);
}
}

View File

@@ -558,7 +558,7 @@ export class GuildHandler {
await RoleModel.dissmissGuild(members);
await UserGuildApplyModel.deleteApplyByGuild(code);
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid, members.map(roleId => { return { roleId, userGuild: null } })); // 更新session
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.broadcast(members.map(roleId => { return { roleId, userGuild: null } })); // 更新session
// 删除channel
@@ -629,13 +629,14 @@ export class GuildHandler {
await removeTrainRank(code, roleId, guild.trainId);
let chatSid = await getGuildChannelSid(code);
const { sid } = await getRoleOnlineInfo(roleId);
const { isOnline, sid } = await getRoleOnlineInfo(roleId);
this.app.rpc.chat.guildRemote.memberQuit.toServer(chatSid, code, roleId, guild, sid);
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [role.roleName]);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid,[{ roleId: memberRoleId, userGuild }]);
if(isOnline)
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid,[{ roleId: memberRoleId, userGuild }]);
await sendMailByContent(MAIL_TYPE.GUILD_BE_KICK, memberRoleId, { sendName: roleName, params: [guild.name] });
@@ -683,10 +684,10 @@ export class GuildHandler {
// 交换
let oldLeaderUserGuild = await UserGuildModel.updateInfo(leaderRoleId, { auth: GUILD_AUTH.MEMBER, job: GUILD_JOB.SHIBING }, {}, 'auth'); // 团长撤
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid,[{ roleId: leaderRoleId, oldLeaderUserGuild }]); // 更新session
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.broadcast([{ roleId: leaderRoleId, userGuild: oldLeaderUserGuild }]); // 更新session
let newLeaderUserGuild = await UserGuildModel.updateInfo(topUserGuild.roleId, { auth: GUILD_AUTH.LEADER, job: GUILD_JOB.JIANGJUN }, {}, 'auth'); // 最高功勋人升
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid,[{ roleId: topUserGuild.roleId, newLeaderUserGuild }]); // 更新session
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.broadcast([{ roleId: topUserGuild.roleId, userGuild: newLeaderUserGuild }]); // 更新session
let managerCntInc = topUserGuild.auth == GUILD_AUTH.MANAGER ? -1 : 0; // 管理人数

View File

@@ -247,7 +247,7 @@ export async function everydayRefresh() {
setMedianCe();
}
export async function kickUser(app: Application, uid: string) {
export async function kickUser(app: Application, uid: string, message = STATUS.LOGIN_ERR) {
let sessionService = app.get('sessionService');
let sessions = sessionService.getByUid(uid);
if (!!sessions) {
@@ -255,7 +255,7 @@ export async function kickUser(app: Application, uid: string) {
let roleId = session.get('roleId');
let sid = session.get('sid');
let uids = [{ uid: roleId, sid }];
app.get('channelService').pushMessageByUids('onRemoteLogin', resResult(STATUS.LOGIN_ERR), uids);
app.get('channelService').pushMessageByUids('onRemoteLogin', resResult(message), uids);
});
}
await sessionService.akick(uid);

View File

@@ -112,13 +112,12 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol
const { sid } = await getRoleOnlineInfo(roleId);
if (sid) {
await addRoleToGuildChannel(roleId, sid, code);
await pinus.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid,[{ roleId, userGuild }]);
}
//成长任务-加入军团
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.GUILD_JOIN, 1);
await pinus.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid,[{ roleId, userGuild }]);
return { status: 0, guild, userGuild, roleName: role.roleName, memberCnt: guild.memberCnt, guildCe: guild.guildCe }
}

View File

@@ -116,8 +116,6 @@ export default class GMUsers extends Service {
return ctx.service.utils.resResult(STATUS.SUCCESS);
}
/**
* 根据类型等搜索玩家
*/
@@ -133,10 +131,10 @@ export default class GMUsers extends Service {
let equipCount = await EquipModel.count({ roleId: role.roleId }).lean();
let itemCount = await ItemModel.count({ roleId: role.roleId }).lean();
let { roleId, roleName, serverId, lv, vLv, gold, coin, ce } = role;
let { roleId, roleName, serverId, lv, vLv, gold, coin, ce, blockType = 0, blockReason = '' } = role;
let { uid, tel } = role.userInfo;
list.push({
key: roleId, roleId, roleName, serverId, lv, vLv, uid, tel, heroCount, equipCount, itemCount, gold, coin, ce,
key: roleId, roleId, roleName, serverId, lv, vLv, uid, tel, heroCount, equipCount, itemCount, gold, coin, ce, blockType, blockReason,
env: ctx.app.config.realEnv
});
}

View File

@@ -747,4 +747,11 @@ export enum THINKING_DATA_MODE_LIST {
BATCH = 'batch',
LOGGING = 'logging',
}
export let THINKING_DATA_MODE = THINKING_DATA_MODE_LIST.DEBUG;
export let THINKING_DATA_MODE = THINKING_DATA_MODE_LIST.DEBUG;
export enum BLOCK_TYPE {
NOT = 0,
BAN = 1,
BLOCK = 2,
}

View File

@@ -10,6 +10,8 @@ export const STATUS = {
SERVER_MAINTENANCE: { code: 7, simStr: '服务器维护中' },
VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' },
BLOCK_WORDS: { code: 9, simStr: '内容有不合法词汇' },
BLOCKED: { code: 10, simStr: '您已被封禁' },
BANNED: { code: 11, simStr: '您已被禁言' },
GLOBAL_ERR: { code: 1003, simStr: '服务器内部错误' },
// http请求
REQUEST_TIME_OUT: { code: 2000, simStr: '请求超时' },

View File

@@ -1,4 +1,4 @@
import { ROLE_TERAPH, ROLE_SELECT, ABI_TYPE, HERO_CE_RATIO } from './../consts';
import { ROLE_TERAPH, ROLE_SELECT, ABI_TYPE, HERO_CE_RATIO, BLOCK_TYPE } from './../consts';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, Ref, mongoose } from '@typegoose/typegoose';
import User from './User';
@@ -147,8 +147,10 @@ export default class Role extends BaseModel {
serverType: string; // 服务器类型
@prop({ required: true })
serverId: number; // 区服 id
@prop({ required: true, default: false })
blocked: boolean; // 是否屏蔽
@prop({ required: true, default: 0 })
blockType: BLOCK_TYPE; // 封禁类型 1-封言 2-封禁
@prop({ required: true, default: '' })
blockReason: string; // 封禁理由
@prop({ required: true })
code: string; // 邀请码
@prop({ required: true, default: false })

View File

@@ -1,5 +1,5 @@
import { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, TASK_TYPE } from '@consts';
import { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, TASK_TYPE, BLOCK_TYPE } from '@consts';
import { RoleModel } from '@db/Role';
import { UserModel, UserType } from '@db/User';
import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts';
@@ -291,6 +291,9 @@ export default class Auth extends Service {
const ctx = this.ctx;
const { uid } = ctx;
const role = await RoleModel.findByUid(uid, serverId);
if(role.blockType == BLOCK_TYPE.BLOCK) {
return ctx.service.utils.resResult(STATUS.BLOCKED);
}
if (role) {
return ctx.service.utils.resResult(STATUS.SUCCESS, { roleId: role.roleId });
}