起名:添加屏蔽词检测

This commit is contained in:
luying
2021-11-10 19:41:06 +08:00
parent 32fe508625
commit a7f3bcc730
11 changed files with 178 additions and 33 deletions

View File

@@ -1,8 +1,8 @@
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback, pinus} from "pinus";
// import { checkEvent } from '../../../services/eventSercive';
import { refresh } from '../../../services/refreshService';
import { checkPrivateChat, checkGuildChat, checkOtherChat, getWorldChannelSid } from "../../../services/chatService";
import { resResult, checkWhiteListWithUid } from "../../../pubUtils/util";
import { checkPrivateChat, checkGuildChat, checkOtherChat, getWorldChannelSid, checkRoleName, checkGuildName } from "../../../services/chatService";
import { resResult, checkWhiteListWithUid, genCode } from "../../../pubUtils/util";
import { CHANNEL_PREFIX, STATUS } from "../../../consts";
import { UserModel } from "../../../db/User";
import { SERVER_DEBUG_MODE } from "../../../pubUtils/dicParam";
@@ -19,6 +19,7 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
const sid: string = session.get('sid');
const roleId: string = session.get('roleId');
const uid: number = session.get('userid');
let guildCode = session.get('guildCode');
session.push('teamCode', () => {});
@@ -52,7 +53,6 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
case 'chat.chatHandler.sendGroupMessage':
{
if(msg.channel == CHANNEL_PREFIX.GUILD) {
const guildCode = session.get('guildCode');
let result = await checkGuildChat(roleId, guildCode, msg.content);
if(!result) hasBlockWords = true;
break;
@@ -62,6 +62,24 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
break;
}
}
case 'role.roleHandler.rename':
case 'role.roleHandler.initRole':
{
let result = await checkRoleName(roleId, msg.roleName);
if(!result) hasBlockWords = true;
break;
}
case 'guild.guildHandler.createGuild':
case 'guild.guildHandler.setGuildInfo':
{
if(!guildCode) {
guildCode = genCode(6);
msg.guildCode = guildCode;
}
let result = await checkGuildName(guildCode, serverId, msg.name, msg.notice);
if(!result) hasBlockWords = true;
break;
}
}
}

View File

@@ -3,7 +3,7 @@ import { Application, BackendSession, ChannelService, HandlerService, pinus, } f
import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, CURRENCY_BY_TYPE, CURRENCY_TYPE, DATA_NAME, LOT_STATUS, CHANNEL_PREFIX, MAIL_TYPE } from "../../../consts";
import { LotModel } from "../../../db/Lot";
import { ItemReward } from "../../../domain/dbGeneral";
import { resResult } from "../../../pubUtils/util";
import { genCode, resResult } from "../../../pubUtils/util";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver, treatSingleLotTime, treatLotsTime } from "../../../services/auctionService";
import { addItems, handleCost } from '../../../services/rewardService';
import { getSimpleRoleInfo } from '../../../services/roleService';
@@ -254,7 +254,7 @@ export class AuctionHandler {
const name = '测试公会'
const icon = 1
const notice = '测试公会'
const guild = await GuildModel.createGuild({ name, icon, notice }, role, serverId);
const guild = await GuildModel.createGuild({ guildCode: genCode(6), name, icon, notice }, role, serverId);
if (!guild) return resResult(STATUS.GUILD_CREATE_ERROR);
guild.leader = <RoleType>guild.leader;
//创建科技树

View File

@@ -40,13 +40,13 @@ export class GuildHandler {
}
// 创建军团
async createGuild(msg: guildInter & { name: string, icon: number, notice: string }, session: BackendSession) {
async createGuild(msg: guildInter & { guildCode: string } & { name: string, icon: number, notice: string }, session: BackendSession) {
const roleId = session.get('roleId');
const roleName = session.get('roleName');
const sid = session.get('sid');
const serverId = session.get('serverId');
const { name, icon, notice } = msg;
const { name, icon, notice, guildCode } = msg;
// 检查名字是否重
const checkNameResult = await GuildModel.checkName(name, serverId);
@@ -66,7 +66,7 @@ export class GuildHandler {
await handleCost(roleId, sid, [getGoldObject(ARMY.ARMY_CREAT_COST)]);
// 创建公会
const guild = await GuildModel.createGuild({ name, icon, notice }, role, serverId);
const guild = await GuildModel.createGuild({ guildCode, name, icon, notice }, role, serverId);
if (!guild) return resResult(STATUS.GUILD_CREATE_ERROR);
guild.leader = <RoleType>guild.leader;
//创建科技树

View File

@@ -15,9 +15,9 @@ import { channelServer } from './chatChannelService';
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
import { getSimpleRoleInfo, getSimpleRoleInfos } from './roleService';
import * as FCClient from '@alicloud/fc2';
import { Chat37Params } from '../domain/sdk';
import { Chat37Params, CheckGuild37Params, CheckName37Params } from '../domain/sdk';
import { UserModel } from '../db/User';
import { request37CheckChat } from '../pubUtils/httpUtil';
import { request37CheckChat, request37Post } from '../pubUtils/httpUtil';
export * from './chatChannelService';
export * from './sysChatService';
@@ -442,6 +442,29 @@ export async function checkOtherChat(roleId: string, channelPrefix: string, mess
return true;
}
export async function checkRoleName(roleId: string, roleName: string) {
let myRole = await RoleModel.findByRoleId(roleId);
let myUser = await UserModel.findUserByUid(myRole.userInfo.uid);
let body = new CheckName37Params(myRole, roleName, myUser);
if(myUser.channelType == '37') {
return await request37Post(SDK_37_ADDR.CHECK_NAME, body, SDK_37_CONST.CHAT_KEY);
}
return true;
}
export async function checkGuildName(guildCode: string, serverId: number, name: string, notice: string) {
let nameResult = true, noticeResult = true;
if(name) {
let body = new CheckGuild37Params(guildCode, serverId, 1, name);
nameResult = await request37Post(SDK_37_ADDR.CHECK_UNION, body, SDK_37_CONST.CHAT_KEY);
}
if(notice) {
let body = new CheckGuild37Params(guildCode, serverId, 2, notice);
noticeResult = await request37Post(SDK_37_ADDR.CHECK_UNION, body, SDK_37_CONST.CHAT_KEY);
}
return nameResult && noticeResult
}
export async function pushCurrentTime(time: number) {
let serverlists = await getAllServers()
for(let serverId of serverlists) {

View File

@@ -14,7 +14,9 @@ export const BANTU_VID_APP_KEY = '05c1c495369769e3c5d98426e9c8c2c0';
export enum SDK_37_ADDR {
LOGIN = 'https://apimyh5.37.com/index.php?c=sdk-unified&a=validate',
CHECK_CHAT = 'http://api.gamechat.37.com/checkChatV2.php'
CHECK_CHAT = 'http://api.gamechat.37.com/checkChatV2.php',
CHECK_NAME = 'http://api.gamechat.37.com/checkName.php',
CHECK_UNION = 'http://api.gamechat.37.com/checkUnion.php',
}
export enum SDK_37_CONST {
GAME_ID = 165, // 研发使用的GAME_ID

View File

@@ -1,7 +1,6 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
import Role, { RoleType } from './Role';
import { genCode } from '../pubUtils/util';
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT, REDIS_KEY, SHOP_REFRESH_TYPE } from '../consts';
import { getZeroPoint, getZeroPointD, nowSeconds } from '../pubUtils/timeUtil';
import { reduceCe } from '../pubUtils/util';
@@ -112,11 +111,11 @@ export default class Guild extends BaseModel {
@prop({ required: true, default: 0 })
openBossCnt: number; // 开启boss本次数
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
public static async createGuild(params: { guildCode: string, name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
const doc = new GuildModel();
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId, lvUpdateTime: nowSeconds() });
delete update._id;
const code = genCode(6);
const code = params.guildCode;
const result: GuildType = await GuildModel.findOneAndUpdate({ code }, update, { upsert: true, new: true })
.select({ _id: 0, __v: 0, createdAt: 0, updatedAt: 0 })
.populate('leader', { roleId: 1, roleName: 1, head: 1, frame: 1, spine: 1, lv: 1, quitTime: 1, ce: 1, title: 1, _id: 0 }, 'Role')

View File

@@ -259,7 +259,7 @@ export default class User extends BaseModel {
}
public static async findUserByUid(uid: number) {
const user: UserType = await UserModel.findOne({ uid }).select('uid tel channelInfo ip').lean({ getters: true });
const user: UserType = await UserModel.findOne({ uid }).select('uid tel channelInfo channelType ip').lean({ getters: true });
return user;
}

View File

@@ -126,6 +126,69 @@ export class Chat37Params {
}
}
setSign(sign: string) {
this.sign = sign;
}
}
export class CheckName37Params {
game_key: string;
sid: number; // 游戏区
username: number; // channelInfo.uid
actor: string; // roleName
actor_id: string; // roleId
ip: string; // 玩家ip
time: number; // unix时间戳
sign: string;
constructor(role: RoleType, roleName: string, user: UserType) {
let channelInfo = <LoginValidateData37>user.channelInfo;
this.game_key = SDK_37_CONST.GAME_KEY;
this.sid = role.serverId;
this.username = channelInfo.uid;
this.actor = roleName;
this.actor_id = role.roleId;
this.ip = user.ip;
this.time = nowSeconds();
}
getBody() {
let { game_key, sid, username, actor_id, ip, time } = this;
return {
game_key, sid, username, actor_id, ip, time
}
}
setSign(sign: string) {
this.sign = sign;
}
}
export class CheckGuild37Params {
game_key: string;
sid: number; // 游戏区
guildid: number; // 军团code
time: number; // unix时间戳
sign: string;
type: number;
content: string; // 内容
constructor(guildCode: string, serverId: number, type: number, content: string) {
this.game_key = SDK_37_CONST.GAME_KEY;
this.sid = serverId;
this.guildid = 10;
this.time = nowSeconds();
this.type = type;
this.content = content;
}
getBody() {
let { game_key, sid, time, type } = this;
return {
game_key, sid, time, type
}
}
setSign(sign: string) {
this.sign = sign;
}

View File

@@ -1,9 +1,10 @@
import * as request from "request-promise";
import { RequestError } from "request-promise/errors";
import { BANTU_VID_ADDR, BANTU_VID_APP_KEY, HTTP_METHOD } from '../consts';
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5Sign, getVidObjSign } from "./sdkUtil";
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5Sign, get37PostMd5Sign, getVidObjSign } from "./sdkUtil";
import { STATUS } from '../consts'
import { resResult } from "./util";
import { Chat37Params, CheckGuild37Params, CheckName37Params } from "../domain/sdk";
// 通用请求http
export async function httpRequest(url: string, method: string, body: any, headers?: any, timeout = 150) {
@@ -20,8 +21,8 @@ export async function httpRequest(url: string, method: string, body: any, header
method,
headers,
body,
json: true,
timeout
timeout,
JSON: true
}
try {
@@ -30,11 +31,41 @@ export async function httpRequest(url: string, method: string, body: any, header
console.log(JSON.stringify(res));
return res;
} catch (e) {
let code = (<RequestError>e).cause.code;
console.error('******', e);
let code = (<RequestError>e).cause?.code;
if(code == 'ESOCKETTIMEDOUT') {
return resResult(STATUS.REQUEST_TIME_OUT);
} else {
return resResult(STATUS.REQUEST_TIME_OUT);
}
}
}
export async function httpRequestForm(url: string, method: string, form: any, timeout = 150) {
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(form)}`)
let options = {
url,
method,
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
form,
timeout,
JSON: true
}
try {
let res = await request(options);
console.log('*****request result*****');
console.log(JSON.stringify(res));
return res;
} catch (e) {
console.error('******', e);
let code = (<RequestError>e).cause?.code;
if(code == 'ESOCKETTIMEDOUT') {
return resResult(STATUS.REQUEST_TIME_OUT);
} else {
console.error(e);
return resResult(STATUS.REQUEST_TIME_OUT);
}
}
@@ -117,15 +148,26 @@ export async function vidHttpRequest(addr: string, body: any) {
export async function request37(url: string, body: any, key: string) {
body['sign'] = get37Md5Sign(body, key);
let result = await httpRequest(url, HTTP_METHOD.POST, {}, body);
let result = await httpRequest(url, HTTP_METHOD.POST, body, {});
console.log('******result', result)
return result;
}
export async function request37CheckChat(url: string, body: any, key: string) {
body['sign'] = get37CheckChatMd5Sign(body, key);
export async function request37CheckChat(url: string, body: Chat37Params, key: string) {
body.setSign(get37CheckChatMd5Sign(body, key));
let result = await httpRequest(url, HTTP_METHOD.GET, {}, body, 3 * 60 * 1000);
let result = await httpRequestForm(url, HTTP_METHOD.GET, body, 3 * 60 * 1000);
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
return false
}
return true;
}
export async function request37Post(url: string, body: CheckName37Params|CheckGuild37Params, key: string) {
body.setSign(get37PostMd5Sign(body.getBody(), key));
let result = await httpRequestForm(url, HTTP_METHOD.POST, body, 1 * 60 * 1000);
console.log('*******', result != 1, result.code != STATUS.REQUEST_TIME_OUT.code)
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
return false
}

View File

@@ -50,6 +50,10 @@ export function get37CheckChatMd5Sign(body: Chat37Params, key: string) {
return md5(str);
}
export function get37PostMd5Sign(body: any, key: string) {
return getMd5ObjSign(body, '', (str) => `${str}${key}`);
}
export async function loginValidate37(clientId: string, pst: string, platformAppid: string, childGameId: number) {
let result: LoginValidataReturn37 = await request37(SDK_37_ADDR.LOGIN, {
clientid: clientId,

View File

@@ -24,15 +24,9 @@ export default class SdkController extends Controller {
public async treatGuildName() {
const { ctx } = this;
let promiseFun = () => {
return new Promise(resolve => {
setTimeout(() => {
resolve(ctx.service.utils.resResult(STATUS.SUCCESS, ''));
}, 1000)
})
}
ctx.body = await promiseFun();
const params = ctx.request.body;
console.log(params)
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, '');
return;
}