聊天:加入部分假数据;加入一个服务器群推

This commit is contained in:
liangtongchuan
2021-03-07 21:25:36 +08:00
parent e0984cc932
commit ba70750f09
7 changed files with 126 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
import { CHANNEL_PREFIX } from './../../../consts/constModules/chatConst';
import { CHANNEL_PREFIX, MSG_SOURCE } from './../../../consts/constModules/chatConst';
import {Application, BackendSession} from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { DEFAULT_MSG_PER_PAGE, STATUS } from '../../../consts';
@@ -83,7 +83,7 @@ export class ChatHandler {
if (channel === CHANNEL_PREFIX.SYS) return resResult(STATUS.SYS_CHANNEL_AUTH_NOT_ENOUGH);
const roleId = session.get('roleId');
const roleName = session.get('roleName');
const msgData = await createGroupMsg(roleId, roleName, channel, channelId, type, content, targetRoleId, targetMsgCode);
const msgData = await createGroupMsg(roleId, roleName, channel, channelId, type, MSG_SOURCE.ROLE_SEND_TEXT, content, targetRoleId, targetMsgCode);
await pushGroupMsgToRoom(groupRoomId(channel, channelId), msgData);
if (!msgData) return resResult(STATUS.WRONG_PARMS);
return resResult(STATUS.SUCCESS);
@@ -99,7 +99,7 @@ export class ChatHandler {
const { type, content, targetRoleId, targetMsgCode } = msg;
const roleId = session.get('roleId');
const roleName = session.get('roleName');
const msgData = await createPrivateMsg(roleId, roleName, type, content, targetRoleId, targetMsgCode);
const msgData = await createPrivateMsg(roleId, roleName, type, MSG_SOURCE.ROLE_SEND_TEXT, content, targetRoleId, targetMsgCode);
await pushMsgToRole(targetRoleId, msgData);
if (!msgData) return resResult(STATUS.WRONG_PARMS);
return resResult(STATUS.SUCCESS, msgData);

View File

@@ -11,6 +11,7 @@ import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, g
import { RewardInter } from '../../../pubUtils/interface';
import { getDropItems } from '../../../consts/constModules/itemConst'
import { getRoleOnlineInfo, getAllOnlineRoles } from '../../../services/redisService';
import { pushHeroQualityUpMsg } from '../../../services/chatService';
export default function(app: Application) {
return new HeroHandler(app);
}
@@ -194,7 +195,9 @@ export class HeroHandler {
// 武将升品
public async qualityUp(msg: { hid: number, quality: number }, session: BackendSession) {
let roleId: string = session.get('roleId');
let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let serverId: string = session.get('serverId');
let {hid, quality} = msg;
let dicHero = gameData.hero.get(hid);
@@ -229,6 +232,7 @@ export class HeroHandler {
hid,
quality : heros[0].quality
}
pushHeroQualityUpMsg(roleId, roleName, serverId, hero);
return resResult(STATUS.SUCCESS, {curHero});
}

View File

@@ -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);
}

View File

@@ -113,7 +113,7 @@ describe('聊天测试', function() {
});
it('测试系统频道消息', function(done) {
// TODO: 玩家无法在系统频道发送消息,需要添加系统推送的监听测试
// TODO: 升品推送
done();
});

View File

@@ -17,9 +17,86 @@ export const CHANNEL_PREFIX = {
GUILD: 'new_guild',
}
// 消息来源
export const MSG_SOURCE = {
ROLE_SEND_TEXT: 0,
PRIVATE_SEND_GIFT: 1,
HERO_QUALITY_UP: 2,
}
export const ON_MSG_ROUTE = 'onMessage';
export const ON_GROUP_MSG_ROUTE = 'onGroupMessage';
export const ON_ADD_CHANNEL_ROUTE = 'onAddChannel';
export const ON_LEAVE_CHANNEL_ROUTE = 'onLeaveChannel';
export const DEFAULT_MSG_PER_PAGE = 10;
export const DEFAULT_MSG_PER_PAGE = 10;
// 要放到策划表里的数据
export const RICH_TEXT_TABLE = [
{
id: 0,
jumpTo: '',
color: '#000000',
type: 'default'
},
{
id: 2,
jumpTo: 'hero',
color: '#ff0000',
type: 'hero'
},
{
id: 3,
jumpTo: 'equip',
color: '#112233',
type: 'equip'
},
{
id: 4,
jumpTo: 'refine',
color: '#aabbcc',
type: 'equip'
},
{
id: 5,
jumpTo: 'recurit',
color: '#aa0000',
type: 'link'
},
{
id: 6,
jumpTo: 'compose',
color: '#00aa00',
type: 'link'
}
];
export const BUBBLE_TABLE = [{
id: 1,
imgUrl: 'a.jpg',
name: '金牛'
}, {
id: 2,
imgUrl: 'b.jpg',
name: '白羊'
}];
export const SYS_EMOJI = [{
id: 1,
name: '大笑',
imgUrl: 'laugh.jpg',
group: 'zhaoyun',
index: 1
}, {
id: 2,
name: '大哭',
imgUrl: 'cry.jpg',
group: 'zhaoyun',
index: 2
}, {
id: 3,
name: '生气',
imgUrl: 'angry.jpg',
group: 'xiahou',
index: 1
}];

View File

@@ -17,6 +17,8 @@ export default class GroupMessage extends BaseModel {
roomId: string; // 频道唯一 Id由 channel 和 channelId 拼接world_serverIdguild_guildId
@prop({ required: true, default: 0 })
type: number; // 消息类型0纯文本1富文本2表情
@prop({ required: true, default: 0 })
source: number; // 消息来源0玩家1玩家送礼2武将升品...
@prop({ required: true, default: '' })
roleId: string; // 消息发送者 roleId

View File

@@ -12,6 +12,8 @@ export default class PrivateMessage extends BaseModel {
roomId: string; // 频道唯一 Id由 roleId 和 targetRoleId 排序后拼接
@prop({ required: true, default: 0 })
type: number; // 消息类型0纯文本1富文本2表情
@prop({ required: true, default: 0 })
source: number; // 消息来源0玩家1玩家送礼2武将升品...
@prop({ required: true, default: '' })
roleId: string; // 消息发送者 roleId