sdk:添加获取服务器列表、本地屏蔽词库
This commit is contained in:
@@ -12,6 +12,7 @@ import { getAllGuildActivityStatus } from '../../../services/guildActivityServic
|
||||
import { MailParam } from '../../../domain/roleField/mail';
|
||||
import { RankFirstType } from '../../../db/RankFirst';
|
||||
import { LotType } from '../../../db/Lot';
|
||||
import { _checkFilterWords, getTire } from '../../../services/sdkService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -34,6 +35,7 @@ export class ChatRemote {
|
||||
constructor(private app: Application) {
|
||||
this.app = app;
|
||||
this.channelService = app.get('channelService');
|
||||
getTire();
|
||||
}
|
||||
|
||||
private channelService: ChannelService;
|
||||
@@ -274,4 +276,8 @@ export class ChatRemote {
|
||||
channel.pushMessage('onAuctionOver', resResult(STATUS.SUCCESS, { lot }));
|
||||
return true;
|
||||
}
|
||||
|
||||
public async checkFilterWords(word: string) {
|
||||
return await _checkFilterWords(word);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import { getActivities } from '../../../services/activity/activityService';
|
||||
import * as dicParam from '../../../pubUtils/dicParam';
|
||||
import Counter from '../../../db/Counter';
|
||||
import { UserModel } from '../../../db/User';
|
||||
import { reportTAEvent } from '../../../services/sdkService';
|
||||
import { checkFilterWords, reportTAEvent } from '../../../services/sdkService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { LoginValidateData37 } from "../../domain/sdk";
|
||||
import { DicRMB } from "../../pubUtils/dictionary/DicRMB";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { resResult } from "../../pubUtils/util";
|
||||
import { get37Md5Sign } from "../../pubUtils/sdkUtil";
|
||||
import { get37Md5SignA } from "../../pubUtils/sdkUtil";
|
||||
import { pinus } from "pinus";
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ export async function applyOrder37(localOrderID: string, roleId: string, product
|
||||
ext
|
||||
}
|
||||
|
||||
let sign = get37Md5Sign(body, SDK_37_CONST.PAY_KEY);
|
||||
let sign = get37Md5SignA(body, SDK_37_CONST.PAY_KEY);
|
||||
|
||||
|
||||
return { code: 0, data: {
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
/********** 37sdk **********/
|
||||
|
||||
import { RoleModel, RoleType } from "../db/Role";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params } from "../domain/sdk";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params, GetWordParam } from "../domain/sdk";
|
||||
import { sendMailByContent, sendMailToGuildByContent } from './mailService';
|
||||
import { getGoldObject } from '../pubUtils/itemUtils';
|
||||
import { NAMEPLATE } from '../pubUtils/dicParam';
|
||||
import { CHANNEL_PREFIX, getSdkChannelId, MAIL_TYPE, REDIS_KEY, SDK_37_ADDR, SDK_37_CONST, SDK_TA_CONST, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from "../consts";
|
||||
import { CHANNEL_PREFIX, FILENAME, getSdkChannelId, MAIL_TYPE, REDIS_KEY, SDK_37_ADDR, SDK_37_CONST, SDK_TA_CONST, STATUS, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from "../consts";
|
||||
import { UserModel } from "../db/User";
|
||||
import { request37CheckChat, request37Post } from "../pubUtils/httpUtil";
|
||||
import { request37CheckChat, request37GetWord, request37Post } from "../pubUtils/httpUtil";
|
||||
import { GuildModel } from "../db/Guild";
|
||||
import { getRoleOnlineInfo, updateUserInfo } from "./redisService";
|
||||
import { Application, pinus } from "pinus";
|
||||
import { getGuildChannelSid } from "./chatService";
|
||||
import { getRandSingleEelm, readWordTxt, writeWordTxt } from "../pubUtils/util";
|
||||
const ThinkingAnalytics = require("thinkingdata-node");
|
||||
import Trie from '../pubUtils/trie';
|
||||
import _ = require("underscore");
|
||||
|
||||
// 检查私聊是否合法
|
||||
|
||||
@@ -60,7 +63,12 @@ export async function checkRoleName(roleId: string, roleName: string, myRole?: R
|
||||
let myUser = await UserModel.findUserByUid(myRole.userInfo.uid);
|
||||
if(myUser.channelType == '37') {
|
||||
let body = new CheckName37Params(myRole, roleName, myUser);
|
||||
return await request37Post(SDK_37_ADDR.CHECK_NAME, body, SDK_37_CONST.CHAT_KEY);
|
||||
let result = await request37Post(SDK_37_ADDR.CHECK_NAME, body, SDK_37_CONST.CHAT_KEY);
|
||||
if(result == STATUS.REQUEST_TIME_OUT.code) { // 超时
|
||||
return await checkFilterWords(roleName);
|
||||
} else if (result == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -69,11 +77,21 @@ export async function checkGuildName(guildCode: string, serverId: number, name:
|
||||
let nameResult = true, noticeResult = true;
|
||||
if(name != undefined) {
|
||||
let body = new CheckGuild37Params(guildCode, serverId, 1, name);
|
||||
nameResult = await request37Post(SDK_37_ADDR.CHECK_UNION, body, SDK_37_CONST.CHAT_KEY);
|
||||
let result = await request37Post(SDK_37_ADDR.CHECK_UNION, body, SDK_37_CONST.CHAT_KEY);
|
||||
if(result == STATUS.REQUEST_TIME_OUT.code) { // 超时
|
||||
nameResult = await checkFilterWords(name);
|
||||
} else if (result == 0) {
|
||||
nameResult = false;
|
||||
}
|
||||
}
|
||||
if(notice) {
|
||||
if(notice != undefined) {
|
||||
let body = new CheckGuild37Params(guildCode, serverId, 2, notice);
|
||||
noticeResult = await request37Post(SDK_37_ADDR.CHECK_UNION, body, SDK_37_CONST.CHAT_KEY);
|
||||
let result = await request37Post(SDK_37_ADDR.CHECK_UNION, body, SDK_37_CONST.CHAT_KEY);
|
||||
if(result == STATUS.REQUEST_TIME_OUT.code) { // 超时
|
||||
noticeResult = await checkFilterWords(name);
|
||||
} else if (result == 0) {
|
||||
noticeResult = false;
|
||||
}
|
||||
}
|
||||
return nameResult && noticeResult
|
||||
}
|
||||
@@ -124,8 +142,8 @@ export async function treatGuildName(content: string) {
|
||||
await RoleModel.updateGuildName(params.code, newName);
|
||||
|
||||
} else if (params.type == 2) { // 公会公告
|
||||
await checkGuildName(params.code, params.serverId, undefined, '');
|
||||
await GuildModel.updateInfo(params.code, { notice: '', sdkMark: false });
|
||||
await checkGuildName(params.code, params.serverId, undefined, ' ');
|
||||
await GuildModel.updateInfo(params.code, { notice: ' ', sdkMark: false });
|
||||
// 通知处理
|
||||
await sendMailToGuildByContent(MAIL_TYPE.TREAT_GUILD_INFO, params.code, {}); // 邮件
|
||||
let chatSid = await getGuildChannelSid(params.code);
|
||||
@@ -179,4 +197,54 @@ export function reportTAEvent(userCode: string, serverId: number, eventName: st
|
||||
|
||||
};
|
||||
ta.track(event);
|
||||
}
|
||||
|
||||
export async function fetch37Words() {
|
||||
let params = new GetWordParam();
|
||||
let result = await request37GetWord(SDK_37_ADDR.GET_WORD, params, SDK_37_CONST.CHAT_KEY);
|
||||
|
||||
writeWordTxt(FILENAME.FILTER_WORDS, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getTire() {
|
||||
let trie = pinus.app.get('tire');
|
||||
if(!trie) {
|
||||
let blockWords = readWordTxt(FILENAME.FILTER_WORDS);
|
||||
if(!blockWords) {
|
||||
blockWords = await fetch37Words();
|
||||
}
|
||||
trie = new Trie();
|
||||
let blockWordsArr = blockWords.split('\n');
|
||||
blockWordsArr.forEach(word => {
|
||||
let arr = word.split('||');
|
||||
trie.insertData(arr[0]);
|
||||
});
|
||||
pinus.app.set('tire', trie);
|
||||
}
|
||||
|
||||
return trie
|
||||
}
|
||||
|
||||
export async function _checkFilterWords(word: string) {
|
||||
let trie = await getTire();
|
||||
if (word.length > 30) return false;
|
||||
|
||||
let cleanStr = word.trim().replace(/ /gi, '').replace('\n','').replace(/&/gi, '');
|
||||
let hitStr = trie.getHitStr(cleanStr);
|
||||
if (hitStr) {
|
||||
console.log(`命中屏蔽词: ${hitStr}`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function checkFilterWords(word: string) {
|
||||
if(pinus.app.getServerType() == 'chat') {
|
||||
return await _checkFilterWords(word);
|
||||
} else {
|
||||
let servers = pinus.app.getServersByType('chat');
|
||||
let server = getRandSingleEelm(servers);
|
||||
return await pinus.app.rpc.chat.chatRemote.checkFilterWords.toServer(server.id, word);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ export enum SDK_37_ADDR {
|
||||
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',
|
||||
GET_WORD = 'http://api.gamechat.37.com/getWord.php',
|
||||
}
|
||||
export enum SDK_37_CONST {
|
||||
GAME_ID = 165, // 研发使用的GAME_ID
|
||||
|
||||
@@ -478,6 +478,7 @@ export const FILENAME = {
|
||||
DIC_PVP_DIFFICULTRATIO: 'dic_zyz_pvp_difficultRatio',
|
||||
DIC_PVP_DAILY_TASK: 'dic_zyz_pvp_dailyTask',
|
||||
DIC_WHITE_IP: 'dic_pay_white_ip',
|
||||
FILTER_WORDS: 'filterWords'
|
||||
}
|
||||
|
||||
export const WAR_RELATE_TABLES = [
|
||||
|
||||
@@ -4,6 +4,8 @@ import { RoleType } from "../db/Role";
|
||||
import { UserType } from "../db/User";
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
|
||||
|
||||
|
||||
// 37的登录验证返回参数
|
||||
export class LoginValidateData37 {
|
||||
@prop({ required: true })
|
||||
@@ -296,4 +298,44 @@ export class GetGuildInfoByUserParam {
|
||||
let { game_key, sid, uid, time, sign } = this;
|
||||
return { game_key, sid, uid, time, sign }
|
||||
}
|
||||
}
|
||||
|
||||
export class GetWordParam {
|
||||
game_key: string; // 游戏标识
|
||||
time: number; // 时间戳
|
||||
sign: string;
|
||||
|
||||
constructor() {
|
||||
this.game_key = SDK_37_CONST.GAME_KEY;
|
||||
this.time = nowSeconds();
|
||||
}
|
||||
|
||||
getBody() {
|
||||
let { game_key, time } = this;
|
||||
return { game_key, time }
|
||||
}
|
||||
|
||||
setSign(sign: string) {
|
||||
this.sign = sign;
|
||||
}
|
||||
}
|
||||
|
||||
export class GetServerListParam {
|
||||
appid: string; // 联运商ID
|
||||
gid: number; // 游戏id
|
||||
time: number; // 时间戳
|
||||
ext: string; // 扩展参数
|
||||
sign: string;
|
||||
|
||||
constructor(param: GetServerListParam) {
|
||||
this.appid = param.appid;
|
||||
this.gid = param.gid;
|
||||
this.time = param.time;
|
||||
this.ext = param.ext;
|
||||
this.sign = param.sign;
|
||||
}
|
||||
|
||||
checkParams() {
|
||||
return this.appid != undefined && this.gid != undefined && this.time != undefined && this.sign != undefined
|
||||
}
|
||||
}
|
||||
@@ -1,10 +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, get37PostMd5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5SignA, get37Md5SignB, getVidObjSign } from "./sdkUtil";
|
||||
import { STATUS } from '../consts'
|
||||
import { resResult } from "./util";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params } from "../domain/sdk";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params, GetWordParam } from "../domain/sdk";
|
||||
|
||||
// 通用,请求http
|
||||
export async function httpRequest(url: string, method: string, body: any, headers?: any, timeout = 150) {
|
||||
@@ -150,13 +150,27 @@ export async function vidHttpRequest(addr: string, body: any) {
|
||||
// 37sdk请求
|
||||
|
||||
export async function request37(url: string, body: any, key: string) {
|
||||
body['sign'] = get37Md5Sign(body, key);
|
||||
body['sign'] = get37Md5SignA(body, key);
|
||||
|
||||
let result = await httpRequestForm(url, HTTP_METHOD.POST, body, 1000);
|
||||
console.log('******result', result)
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function request37Post(url: string, body: CheckName37Params|CheckGuild37Params, key: string) {
|
||||
body.setSign(get37Md5SignB(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.code == STATUS.REQUEST_TIME_OUT.code) {
|
||||
return STATUS.REQUEST_TIME_OUT.code;
|
||||
}
|
||||
if(result != 1) {
|
||||
return 0
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
export async function request37CheckChat(url: string, body: Chat37Params, key: string) {
|
||||
body.setSign(get37CheckChatMd5Sign(body, key));
|
||||
|
||||
@@ -167,13 +181,9 @@ export async function request37CheckChat(url: string, body: Chat37Params, key: s
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function request37Post(url: string, body: CheckName37Params|CheckGuild37Params, key: string) {
|
||||
body.setSign(get37PostMd5Sign(body.getBody(), key));
|
||||
export async function request37GetWord(url: string, body: GetWordParam, key: string) {
|
||||
body.setSign(get37Md5SignB(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
|
||||
}
|
||||
return true;
|
||||
}
|
||||
let result = await httpRequestForm(url, HTTP_METHOD.GET, body, 5 * 60 * 1000);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { REDIS_KEY, SDK_37_ADDR, SDK_37_CONST } from '../consts';
|
||||
import { request37 } from './httpUtil';
|
||||
import { nowSeconds } from './timeUtil';
|
||||
import { LoginValidataReturn37, Chat37Params } from '../domain/sdk';
|
||||
import { LoginValidataReturn37, Chat37Params, GetServerListParam } from '../domain/sdk';
|
||||
import * as crypto from 'crypto'
|
||||
|
||||
// 通用加密方法
|
||||
@@ -39,21 +39,30 @@ export async function checkMd5Sign(obj: any, treatStr?: (str: string) => string)
|
||||
|
||||
/************** 37sdk **************/
|
||||
|
||||
export function get37Md5Sign(body: any, key: string) {
|
||||
export function get37Md5SignA(body: any, key: string) {
|
||||
return getMd5ObjSign(body, '&', (str) => `${str}&${key}`);
|
||||
}
|
||||
|
||||
export function get37CheckChatMd5Sign(body: Chat37Params, key: string) {
|
||||
let { game_key = '', sid = '', username = '', channel = '', to_username = '', ip = '', time } = body;
|
||||
let str = `${game_key}${sid}${username}${to_username}${channel}${ip}${time}${key}`;
|
||||
console.log('** origin str', body, str);
|
||||
return md5(str);
|
||||
let sign = md5(str);
|
||||
console.log('** origin str', body, str, sign);
|
||||
return sign;
|
||||
}
|
||||
|
||||
export function get37PostMd5Sign(body: any, key: string) {
|
||||
export function get37Md5SignB(body: any, key: string) {
|
||||
return getMd5ObjSign(body, '', (str) => `${str}${key}`);
|
||||
}
|
||||
|
||||
export function get37GetServerMd5Sign(body: GetServerListParam, key: string) {
|
||||
let { time, appid, gid } = body;
|
||||
let str = `${time}${appid}${gid}${key}`;
|
||||
let sign = md5(str);
|
||||
console.log('** origin str', body, str, sign);
|
||||
return sign
|
||||
}
|
||||
|
||||
export async function loginValidate37(clientId: string, pst: string, platformAppid: string = SDK_37_CONST.PID, childGameId: number = SDK_37_CONST.FX_C_GAME_ID) {
|
||||
let result: string = await request37(SDK_37_ADDR.LOGIN, {
|
||||
clientid: clientId,
|
||||
|
||||
160
shared/pubUtils/trie.ts
Normal file
160
shared/pubUtils/trie.ts
Normal file
@@ -0,0 +1,160 @@
|
||||
function Trie(this: any) {
|
||||
this.root = new TrieNode(null);
|
||||
this.hitStr = '';
|
||||
}
|
||||
|
||||
function TrieNode(this: any, key) {
|
||||
this.key = key; // 节点字符
|
||||
this.children = []; // 子节点集合
|
||||
this.end = false;
|
||||
}
|
||||
|
||||
Trie.prototype = {
|
||||
insertData: function (stringData) {
|
||||
this.insert(stringData, this.root);
|
||||
// console.log(JSON.stringify(this.root, null, 2))
|
||||
},
|
||||
// 递归判断插入
|
||||
insert: function (stringData, node) {
|
||||
if (stringData == '') {
|
||||
return;
|
||||
}
|
||||
let children = node.children;
|
||||
let haveData = null;
|
||||
for (let i in children) {
|
||||
if (children[i].key == stringData[0]) {
|
||||
haveData = children[i];
|
||||
}
|
||||
}
|
||||
if (haveData) {
|
||||
this.insert(stringData.substring(1), haveData); //说明找到了对应的节点
|
||||
if (stringData.substring(1).length == 0) haveData.end = true;
|
||||
} else { //那如果没有找到则插入
|
||||
if (children.length == 0) { //当前节点没有子节点
|
||||
let node = new TrieNode(stringData[0]);
|
||||
children.push(node);
|
||||
this.insert(stringData.substring(1), node); //将该字符节点插入节点的children中
|
||||
if (stringData.substring(1).length == 0) node.end = true;
|
||||
} else { //当前节点存在子节点,需要查找一个合适的位置去插入新节点
|
||||
let validPosition = 0;
|
||||
for (let j in children) {
|
||||
if (children[j].key < stringData[0]) {
|
||||
validPosition++;
|
||||
}
|
||||
}
|
||||
let node = new TrieNode(stringData[0]);
|
||||
children.splice(validPosition, 0, node);
|
||||
this.insert(stringData.substring(1), node); //将该字符节点插入节点的children中
|
||||
if (stringData.substring(1).length == 0) node.end = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 查询字符串
|
||||
search: function (queryData) {
|
||||
if (queryData == '' || this.root.children.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (let j = 0; j < queryData.length; j++) {
|
||||
for (let i in this.root.children) {
|
||||
this.hitStr = '';
|
||||
if (this.searchNext(this.root.children[i], queryData.substring(j))) {
|
||||
console.log('hitStr:' + this.hitStr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
// 获取命中的关键词
|
||||
getHitStr: function (queryData) {
|
||||
this.hitStr = '';
|
||||
this.search(queryData)
|
||||
return this.hitStr;
|
||||
},
|
||||
// 递归查询判断
|
||||
searchNext: function (node, stringData) {
|
||||
// 若字符与节点key不相等,则不匹配
|
||||
if (stringData[0] != node.key) {
|
||||
return false;
|
||||
} else { // 若与key相等,继续判断
|
||||
this.hitStr += node.key;
|
||||
let children = node.children;
|
||||
if (children.length == 0) { // 叶子节点,最后一个字符,则完全匹配
|
||||
// if (children.length == 0) { // 叶子节点,最后一个字符,则完全匹配
|
||||
return true;
|
||||
} else if (node.end) {
|
||||
return true;
|
||||
} else if (children.length > 0 && stringData.length > 1) { // 既不是叶子节点,也不是最后一个字符,则继续递归查找
|
||||
for (let i in children) {
|
||||
if (children[i].key == stringData[1]) {
|
||||
return this.searchNext(children[i], stringData.substring(1)); // 记得return 递归函数,否则获取的返回值为undefined
|
||||
}
|
||||
}
|
||||
} else { // C1:叶子节点,C2:最后一个字符;若只满足其中一个条件,则不匹配
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 删除字符串
|
||||
delete: function (stringData) {
|
||||
if (this.search(stringData)) { // 判断是否存在该单词(字符串)
|
||||
for (let i in this.root.children) {
|
||||
if (this.delNext(this.root, i, stringData, stringData)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* 先递归查找到字符串的叶子节点,然后从字符串的叶子节点逐级向根节点递归删除叶子节点,直到删除字符串
|
||||
* @param parent 父节点
|
||||
* @param index 子节点在父节点children数组中的索引位置
|
||||
* @param stringData 递归遍历中的字符串
|
||||
* @param delStr 调用delete方法时的原始字符串
|
||||
*/
|
||||
delNext: function (parent, index, stringData, delStr) {
|
||||
//当前节点对象
|
||||
let node = parent.children[index];
|
||||
// 若字符与节点key不相等,则不匹配
|
||||
if (stringData[0] != node.key) {
|
||||
return false;
|
||||
} else { // 若与key相等,继续判断
|
||||
let children = node.children;
|
||||
if (children.length == 0 && stringData.length == 1) { // 叶子节点,最后一个字符,则完全匹配
|
||||
// 删除叶子节点,利用父节点删除子节点原理
|
||||
parent.children.splice(index, 1);
|
||||
// 字符串从尾部移除一个字符后,继续遍历删除方法
|
||||
this.delete(delStr.substring(0, delStr.length - 1));
|
||||
} else if (children.length > 0 && stringData.length > 1) { // 既不是叶子节点,也不是最后一个字符,则继续递归查找
|
||||
for (let i in children) {
|
||||
if (children[i].key == stringData[1]) {
|
||||
return this.delNext(node, i, stringData.substring(1), delStr); // 记得return 递归函数,否则获取的返回值为undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
// 打印字符串
|
||||
printData: function () {
|
||||
for (let i in this.root.children) {
|
||||
this.printHelper(this.root.children[i], [this.root.children[i].key]);
|
||||
}
|
||||
},
|
||||
// 递归输出字符串
|
||||
printHelper: function (node, data) {
|
||||
if (node.children.length == 0) {
|
||||
console.log('>', data.join(''));
|
||||
return;
|
||||
}
|
||||
for (let i in node.children) {
|
||||
data.push(node.children[i].key);
|
||||
this.printHelper(node.children[i], data);
|
||||
// if (node.end) console.log(data);
|
||||
data.pop(); // 注意,找打一个单词后,返回下一个初始节点继续遍历
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Trie;
|
||||
@@ -433,6 +433,25 @@ export function readWarJsonFileList() {
|
||||
});
|
||||
}
|
||||
|
||||
export function readWordTxt(fileName: string) {
|
||||
try {
|
||||
let file = fs.readFileSync(path.resolve(__dirname, `../resource/${fileName}.txt`)).toString('utf8').replace(/^\uFEFF/, '');
|
||||
return file;
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function writeWordTxt(fileName: string, words: string) {
|
||||
try {
|
||||
let file = fs.writeFileSync(path.resolve(__dirname, `../resource/${fileName}.txt`), words);
|
||||
return file;
|
||||
} catch(e) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function readTsFile(fileName: string) {
|
||||
try {
|
||||
let file = fs.readFileSync(path.resolve(__dirname, `../pubUtils/${fileName}.js`)).toString('utf8').replace(/^\uFEFF/, '');
|
||||
|
||||
59183
shared/resource/filterWords.txt
Normal file
59183
shared/resource/filterWords.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
import { Controller } from 'egg';
|
||||
import { GetGuildInfoByUserParam, GuildNameCallBackParam, PayCallback37Data, RoleNameCallBackParam } from '../domain/sdk';
|
||||
import { GetGuildInfoByUserParam, GetServerListParam, GuildNameCallBackParam, PayCallback37Data, RoleNameCallBackParam } from '../domain/sdk';
|
||||
|
||||
export default class SdkController extends Controller {
|
||||
|
||||
@@ -32,4 +32,12 @@ export default class SdkController extends Controller {
|
||||
ctx.body = await ctx.service.sdk.getGuildByUser(params);
|
||||
return;
|
||||
}
|
||||
|
||||
public async getServerList() {
|
||||
const { ctx } = this;
|
||||
|
||||
const params = new GetServerListParam(ctx.method == 'GET'? ctx.query: ctx.request.body);
|
||||
ctx.body = await ctx.service.sdk.getServerList(params);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,5 +30,6 @@ export default (app: Application) => {
|
||||
router.get('/cb/treatusername', controller.sdk.treatRoleName);
|
||||
router.get('/cb/treatguildname', controller.sdk.treatGuildName);
|
||||
router.get('/cb/getguildbyuser', controller.sdk.getGuildByUser);
|
||||
|
||||
router.get('/cb/getserverlist', controller.sdk.getServerList);
|
||||
router.post('/cb/getserverlist', controller.sdk.getServerList);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
import { Service } from 'egg';
|
||||
import { REDIS_KEY, PAY_37_CALLBACK_CODE, SDK_37_CONST, ORDER_STATE, SDK_37_TREAT_CODE } from '@consts';
|
||||
import { GetGuildInfoByUserParam, GuildNameCallBackParam, PayCallback37Data, RoleNameCallBackParam } from '../domain/sdk';
|
||||
import { REDIS_KEY, PAY_37_CALLBACK_CODE, SDK_37_CONST, ORDER_STATE, SDK_37_TREAT_CODE, SERVER_STATUS } from '@consts';
|
||||
import { GetGuildInfoByUserParam, GetServerListParam, GuildNameCallBackParam, PayCallback37Data, RoleNameCallBackParam } from '../domain/sdk';
|
||||
import { RedisClient } from 'redis';
|
||||
import { get37Md5Sign, get37PostMd5Sign, getChannelId, getRedisSubChannel } from '../pubUtils/sdkUtil';
|
||||
import { get37GetServerMd5Sign, get37Md5SignA, get37Md5SignB, getChannelId, getRedisSubChannel } from '../pubUtils/sdkUtil';
|
||||
import { UserOrderModel } from '@db/UserOrder';
|
||||
import { nowSeconds } from 'app/pubUtils/timeUtil';
|
||||
import { RoleModel } from '@db/Role';
|
||||
@@ -12,6 +12,8 @@ import { resResult } from 'app/pubUtils/util';
|
||||
import { UserModel } from '@db/User';
|
||||
import { UserGuildModel } from '@db/UserGuild';
|
||||
import { GuildModel } from '@db/Guild';
|
||||
import { ServerlistModel } from '@db/Serverlist';
|
||||
import moment = require('moment');
|
||||
|
||||
/**
|
||||
* Test Service
|
||||
@@ -19,7 +21,7 @@ import { GuildModel } from '@db/Guild';
|
||||
export default class Sdk extends Service {
|
||||
|
||||
public check37Sign(params: PayCallback37Data) {
|
||||
let sign = get37Md5Sign(params.getBody(), SDK_37_CONST.PAY_KEY);
|
||||
let sign = get37Md5SignA(params.getBody(), SDK_37_CONST.PAY_KEY);
|
||||
console.log('******37Sign', sign);
|
||||
return sign == params.sign;
|
||||
}
|
||||
@@ -87,7 +89,7 @@ export default class Sdk extends Service {
|
||||
|
||||
|
||||
public check37WordsSign(params: RoleNameCallBackParam|GuildNameCallBackParam|GetGuildInfoByUserParam) {
|
||||
let sign = get37PostMd5Sign(params.getBody(), SDK_37_CONST.CHAT_KEY);
|
||||
let sign = get37Md5SignB(params.getBody(), SDK_37_CONST.CHAT_KEY);
|
||||
console.log('******37Sign', sign);
|
||||
return sign == params.sign;
|
||||
}
|
||||
@@ -206,4 +208,54 @@ export default class Sdk extends Service {
|
||||
|
||||
return resResult(check, []);
|
||||
}
|
||||
|
||||
private valiedateGetServerList(params:GetServerListParam) {
|
||||
if(!params.checkParams()) return SDK_37_TREAT_CODE.WRONG_PARAMS;
|
||||
if(params.gid != SDK_37_CONST.GAME_ID) return SDK_37_TREAT_CODE.WRONG_PARAMS
|
||||
|
||||
let sign = get37GetServerMd5Sign(params, SDK_37_CONST.LOGIN_KEY);
|
||||
if(sign != params.sign) return SDK_37_TREAT_CODE.SIGN_ERR;
|
||||
|
||||
if(nowSeconds() - params.time > 15 * 60) {
|
||||
return SDK_37_TREAT_CODE.TIME_IS_EXPIRED;
|
||||
}
|
||||
return SDK_37_TREAT_CODE.SUCCESS;
|
||||
}
|
||||
|
||||
public async getServerList(params:GetServerListParam) {
|
||||
let validate = this.valiedateGetServerList(params);
|
||||
if(validate.code != SDK_37_TREAT_CODE.SUCCESS.code) {
|
||||
return {
|
||||
state: 0,
|
||||
data: null,
|
||||
msg: resResult(validate).msg
|
||||
}
|
||||
}
|
||||
|
||||
let servers = await ServerlistModel.getAllServerList();
|
||||
let data = servers.map(server => {
|
||||
let statue = 0;
|
||||
switch(server.status) {
|
||||
case SERVER_STATUS.MAINTENANCE:
|
||||
statue = 0; break;
|
||||
case SERVER_STATUS.WILL_OPEN:
|
||||
statue = 1; break;
|
||||
case SERVER_STATUS.NEW:
|
||||
case SERVER_STATUS.HOT:
|
||||
statue = 2; break;
|
||||
}
|
||||
return {
|
||||
dsid: server.id,
|
||||
dsname: server.name,
|
||||
start_time: moment(server.openTime, 'YYYY-MM-DD HH:mm:ss'),
|
||||
statue
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
state: 1,
|
||||
data,
|
||||
msg: '成功'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user