聊天:添加屏蔽

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
+27 -7
View File
@@ -23,13 +23,33 @@ export const CHANNEL_PREFIX = {
WORLD_AUCTION: 'w_auction', // 军团拍卖
}
export const CHANNEL_TYPE = new Map([
[ CHANNEL_PREFIX.SYS, 1 ],
[ CHANNEL_PREFIX.WORLD, 2 ],
[ CHANNEL_PREFIX.GUILD, 3 ],
[ CHANNEL_PREFIX.TEAM, 4 ],
[ 'private', 5 ],
]);
export const getChannelType = function(prefix: string) {
switch(prefix) {
case CHANNEL_PREFIX.SYS:
return 1;
case CHANNEL_PREFIX.WORLD:
return 2;
case CHANNEL_PREFIX.GUILD:
return 3;
case CHANNEL_PREFIX.TEAM:
return 4;
case 'private':
return 5;
}
}
export const getSdkChannelId = function(prefix: string) {
switch(prefix) {
case CHANNEL_PREFIX.WORLD:
return 1;
case CHANNEL_PREFIX.GUILD:
return 4;
case CHANNEL_PREFIX.TEAM:
return 3;
case 'private':
return 2;
}
}
// 消息来源
export const MSG_SOURCE = {
+2 -1
View File
@@ -13,7 +13,8 @@ export enum BANTU_VID_ADDR {
export const BANTU_VID_APP_KEY = '05c1c495369769e3c5d98426e9c8c2c0';
export enum SDK_37_ADDR {
LOGIN = 'https://apimyh5.37.com/index.php?c=sdk-unified&a=validate'
LOGIN = 'https://apimyh5.37.com/index.php?c=sdk-unified&a=validate',
CHECK_CHAT = 'http://api.gamechat.37.com/checkChatV2.php'
}
export enum SDK_37_CONST {
GAME_ID = 165, // 研发使用的GAME_ID
+3
View File
@@ -11,6 +11,9 @@ export const STATUS = {
VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' },
BLOCK_WORDS: { code: 9, simStr: '内容有不合法词汇' },
GLOBAL_ERR: { code: 1003, simStr: '服务器内部错误' },
// http请求
REQUEST_TIME_OUT: { code: 2000, simStr: '请求超时' },
REQUEST_FAIL: { code: 2001, simStr: '请求错误' },
// 账号相关状态 10000 - 19999
SMS_IN_60S: { code: 10001, simStr: '60秒内只能发送一次' },
+1 -1
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').lean({ getters: true });
const user: UserType = await UserModel.findOne({ uid }).select('uid tel channelInfo ip').lean({ getters: true });
return user;
}
+73
View File
@@ -1,4 +1,8 @@
import { prop } from "@typegoose/typegoose";
import { SDK_37_CONST } from "../consts";
import { RoleType } from "../db/Role";
import { UserType } from "../db/User";
import { nowSeconds } from "../pubUtils/timeUtil";
// 37的登录验证返回参数
export class LoginValidateData37 {
@@ -31,6 +35,13 @@ export class LoginValidateData37 {
@prop({ required: true })
unique_realname_id: string; // 用户身份证唯一标识
@prop({ required: true })
childGameId: number; // 子游戏id
@prop({ required: true })
platformAppid: string; // 渠道标识
}
export interface LoginValidataReturn37 {
@@ -56,4 +67,66 @@ export interface PayCallback37Data {
time: number; // 请求时间
ext: string; // 扩展参数
sign: string;
}
export class Chat37Params {
game_key: string;
sid: number; // 游戏区
username: number; // channelInfo.uid
actor: string; // roleName
actor_id: string; // roleId
content: string; // 聊天内容
channel: number; // 世界=1,私聊=2,队伍=3,工会=4
ip: string; // 玩家ip
time: number; // unix时间戳
sign: string;
op: string; // channelInfo.platformAppid
actor_level: number; // 等级
actor_recharge_gold: number; // 元宝
guildid: string = ''; // 公会id
to_username: number|string = ''; // 对方channelInfo.uid
to_actor: string = ''; // 对方roleName
to_actor_id: string = ''; // 对方roleId
to_actor_level: number; // 对方等级
to_actor_recharge_gold: number; // 对方元宝
constructor(content: string, channel: number) {
this.game_key = SDK_37_CONST.GAME_KEY;
this.content = content;
this.channel = channel;
this.time = nowSeconds();
}
setByMyRole(role: RoleType, user: UserType) {
let channelInfo = <LoginValidateData37>user.channelInfo;
this.username = channelInfo.uid;
this.actor = role.roleName;
this.actor_id = role.roleId;
this.ip = user.ip;
this.op = channelInfo.platformAppid;
this.actor_level = role.lv;
this.actor_recharge_gold = role.gold;
this.sid = role.serverId;
}
setByGuild(guildCode: string) {
this.guildid = guildCode;
}
setByTargetRole(role: RoleType, user: UserType) {
let channelInfo = <LoginValidateData37>user.channelInfo;
if(channelInfo) {
this.to_username = channelInfo.uid;
this.to_actor = role.roleName;
this.to_actor_id = role.roleId;
this.to_actor_level = role.lv;
this.to_actor_recharge_gold = role.gold;
}
}
setSign(sign: string) {
this.sign = sign;
}
}
+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}`);