sdk:添加获取服务器列表、本地屏蔽词库

This commit is contained in:
luying
2021-11-18 16:06:05 +08:00
parent 18c256ba2b
commit 624aa2b5f1
15 changed files with 59596 additions and 36 deletions
+1
View File
@@ -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
+1
View File
@@ -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 = [
+42
View File
@@ -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
}
}
+22 -12
View File
@@ -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;
}
+14 -5
View File
@@ -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
View 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;
+19
View File
@@ -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/, '');
File diff suppressed because it is too large Load Diff