聊天:加入部分假数据;加入一个服务器群推
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user