|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
import { cloneDeep, pick } from 'lodash';
|
|
|
|
|
import { RoleModel } from './../db/Role';
|
|
|
|
|
import { GroupMessageModel } from './../db/GroupMessage';
|
|
|
|
|
import { CounterModel } from './../db/Counter';
|
|
|
|
@@ -6,9 +7,10 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './
|
|
|
|
|
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
|
|
|
|
import { genCode, resResult } from '../pubUtils/util';
|
|
|
|
|
import { pinus } from 'pinus';
|
|
|
|
|
import { MSG_CODE_LEN, MSG_STATUS, ON_MSG_ROUTE } from '../consts';
|
|
|
|
|
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_SOURCE, MSG_STATUS, MSG_TYPE, ON_MSG_ROUTE, RICH_TEXT_TABLE } from '../consts';
|
|
|
|
|
import { addRedisChannel, getRoleOnlineInfo, redisChannelServer } from './redisService';
|
|
|
|
|
import { crc32 } from 'crc';
|
|
|
|
|
import { HeroType } from '../db/Hero';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 生成私聊房间号
|
|
|
|
@@ -59,15 +61,15 @@ async function setupBaseMsgParm(msg: PrivateMessageParam | GroupMessageParam ) {
|
|
|
|
|
* @param {string} targetMsgCode
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
async function createPrivateMsgData(roleId: string, roleName: string, type: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const result: PrivateMessageParam = {roleId, roleName, type, content, targetRoleId, targetMsgCode};
|
|
|
|
|
async function createPrivateMsgData(roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const result: PrivateMessageParam = {roleId, roleName, type, source, content, targetRoleId, targetMsgCode};
|
|
|
|
|
result.roomId = privateRoomId(roleId, targetRoleId);
|
|
|
|
|
await setupBaseMsgParm(result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createGroupMsgData(roleId: string, roleName: string, channel: string, channelId: string, type: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const result: GroupMessageParam = {roleId, roleName, channel, channelId, type, content, targetRoleId, targetMsgCode};
|
|
|
|
|
async function createGroupMsgData(roleId: string, roleName: string, channel: string, channelId: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const result: GroupMessageParam = {roleId, roleName, channel, channelId, type, source, content, targetRoleId, targetMsgCode};
|
|
|
|
|
result.roomId = groupRoomId(channel, channelId);
|
|
|
|
|
await setupBaseMsgParm(result);
|
|
|
|
|
return result;
|
|
|
|
@@ -84,8 +86,8 @@ async function createGroupMsgData(roleId: string, roleName: string, channel: str
|
|
|
|
|
* @param {string} targetMsgCode
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export async function createPrivateMsg(roleId: string, roleName: string, type: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const msgData: PrivateMessageParam = await createPrivateMsgData(roleId, roleName, type, content, targetRoleId, targetMsgCode);
|
|
|
|
|
export async function createPrivateMsg(roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const msgData: PrivateMessageParam = await createPrivateMsgData(roleId, roleName, type, source, content, targetRoleId, targetMsgCode);
|
|
|
|
|
const result: PrivateMessageType = await PrivateMessageModel.createMsg(msgData);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@@ -117,8 +119,8 @@ export async function getPrivateMessages(roleId: string, targetRoleId: string, f
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function createGroupMsg(roleId: string, roleName: string, channel: string, channelId: string, type: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const msgData: GroupMessageParam = await createGroupMsgData(roleId, roleName, channel, channelId, type, content, targetRoleId, targetMsgCode);
|
|
|
|
|
export async function createGroupMsg(roleId: string, roleName: string, channel: string, channelId: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
|
|
|
|
const msgData: GroupMessageParam = await createGroupMsgData(roleId, roleName, channel, channelId, type, source, content, targetRoleId, targetMsgCode);
|
|
|
|
|
const result: GroupMessageType = await GroupMessageModel.createMsg(msgData);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@@ -183,4 +185,28 @@ export async function leaveGuildChannel(roleId: string, sid: string) {
|
|
|
|
|
if (!guildCode) return;
|
|
|
|
|
const roomId = groupRoomId('new_guild', guildCode);
|
|
|
|
|
await leaveChannel(roomId, roleId, sid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function richTextSetting(type, jumpTo) {
|
|
|
|
|
const settings = cloneDeep(RICH_TEXT_TABLE);
|
|
|
|
|
for (let setting of settings) {
|
|
|
|
|
if (setting.type === type && setting.jumpTo === jumpTo) {
|
|
|
|
|
return setting;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function wrapRichText(type: string, jumpTo: string, content: string, parm: string) {
|
|
|
|
|
const setting = richTextSetting(type, jumpTo);
|
|
|
|
|
return JSON.stringify({
|
|
|
|
|
id: setting.id, content, parm
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function pushHeroQualityUpMsg(roleId: string, roleName: string, serverId: number | string, heroInfo: Partial<HeroType>) {
|
|
|
|
|
const hero = pick(heroInfo, ['hName', 'hid', 'seqId', 'quality']);
|
|
|
|
|
const content = JSON.stringify({ roleId, roleName, hero });
|
|
|
|
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, MSG_SOURCE.HERO_QUALITY_UP, content, null, null);
|
|
|
|
|
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, `${serverId}`);
|
|
|
|
|
await pushGroupMsgToRoom(roomId, msgData);
|
|
|
|
|
}
|
|
|
|
|