聊天:添加屏蔽

This commit is contained in:
luying
2021-11-10 17:28:11 +08:00
parent b15a9088e8
commit 32fe508625
16 changed files with 260 additions and 54 deletions
+1
View File
@@ -236,4 +236,5 @@ export const GK_MAINELITE = {
};
export const SERVER_DEBUG_MODE = {
CURRENT_TIME: 1, // 服务器是否打开推送时间debug模式
CHECK_WORD: 0, // 服务器是否打开聊天屏蔽
};
+30 -5
View File
@@ -1,17 +1,27 @@
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, get37Md5Sign, getVidObjSign } from "./sdkUtil";
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5Sign, getVidObjSign } from "./sdkUtil";
import { STATUS } from '../consts'
import { resResult } from "./util";
// 通用,请求http
export async function httpRequest(url: string, method: string, headers: any, body: any) {
export async function httpRequest(url: string, method: string, body: any, headers?: any, timeout = 150) {
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(headers)}, ${JSON.stringify(body)}`)
if(!headers) {
headers = {
'content-type': 'application/json;charset=utf-8',
}
}
let options = {
url,
method,
headers,
body,
json: true
json: true,
timeout
}
try {
@@ -20,8 +30,13 @@ export async function httpRequest(url: string, method: string, headers: any, bod
console.log(JSON.stringify(res));
return res;
} catch (e) {
console.error(e);
return false
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);
}
}
}
@@ -105,4 +120,14 @@ export async function request37(url: string, body: any, key: string) {
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);
let result = await httpRequest(url, HTTP_METHOD.GET, {}, body, 3 * 60 * 1000);
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
return false
}
return true;
}
+14 -7
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 } from '../domain/sdk';
import { LoginValidataReturn37, Chat37Params } from '../domain/sdk';
import * as crypto from 'crypto'
// 通用加密方法
@@ -43,14 +43,21 @@ export function get37Md5Sign(body: any, key: string) {
return getMd5ObjSign(body, '&', (str) => `${str}&${key}`);
}
export async function loginValidate37(clientId: string, pst: string) {
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);
}
export async function loginValidate37(clientId: string, pst: string, platformAppid: string, childGameId: number) {
let result: LoginValidataReturn37 = await request37(SDK_37_ADDR.LOGIN, {
clientid: clientId,
pid: SDK_37_CONST.PID,
pid: platformAppid,
game_id: SDK_37_CONST.GAME_ID,
pst,
time: nowSeconds(),
c_game_id: SDK_37_CONST.FX_C_GAME_ID
c_game_id: childGameId
}, SDK_37_CONST.LOGIN_KEY);
if (result && result.code !== 1) {
console.error(result.msg);
@@ -59,9 +66,10 @@ export async function loginValidate37(clientId: string, pst: string) {
return result;
}
export async function loginValidata(channelType: string, clientId: string, pst: string) {
export async function loginValidata(channelType: string, params: { clientId: string, pst: string, platformAppid: string, childGameId: number }) {
if(channelType == '37') {
return await loginValidate37(clientId, pst);
let { clientId, pst, platformAppid, childGameId } = params;
return await loginValidate37(clientId, pst, platformAppid, childGameId);
} else {
return false;
}
@@ -72,7 +80,6 @@ export function getChannelId(channelType: string, uid: number|string) {
}
/********* 厚土防沉迷 *********/
export function getVidObjSign(body: any) {
+1 -1
View File
@@ -265,7 +265,7 @@ export function getRandValueByMinMax(min: number, max: number, decimal = 2): num
}
export function resResult(status: { code: number, simStr: string }, data = null, customMsg = '') {
export function resResult<T>(status: { code: number, simStr: string }, data: T = null, customMsg = ''): { code: number, msg: string, data: T } {
const { code, simStr } = status;
if (code !== STATUS.SUCCESS.code) {
console.log(`normal err, code: ${code}, des: ${customMsg || simStr}`);