diff --git a/game-server/app/servers/battle/handler/comBattleHandler.ts b/game-server/app/servers/battle/handler/comBattleHandler.ts index e466b96e8..d14446bfa 100644 --- a/game-server/app/servers/battle/handler/comBattleHandler.ts +++ b/game-server/app/servers/battle/handler/comBattleHandler.ts @@ -21,7 +21,7 @@ import { setAp } from '../../../services/actionPointService'; import { roleLevelup } from '../../../services/normalBattleService'; import { addUserToChannel } from '../../../services/roleService'; import { ChannelUser } from '../../../domain/ChannelUser'; -import { pushComBtlTeamMsg, pushNormalEquipMsg } from '../../../services/chatService'; +import { pushComBtlTeamMsg, pushNormalEquipMsg, pushTeamInviteMsg } from '../../../services/chatService'; export default function(app: Application) { return new ComBattleHandler(app); @@ -656,13 +656,29 @@ export class ComBattleHandler { let roleName = session.get('roleName'); const { teamCode, type, content, targetRoleId, targetMsgCode } = msg; - const result = await pushComBtlTeamMsg(teamCode, roleId, roleName, type, MSG_SOURCE.TEAM, content, targetRoleId, targetMsgCode); + const result = await pushComBtlTeamMsg(teamCode, roleId, roleName, type, MSG_SOURCE.TEAM_ROLE, content, targetRoleId, targetMsgCode); if (!result) { return resResult(STATUS.WRONG_PARMS); } return resResult(STATUS.SUCCESS); } + /** + * @description 一键邀请,自动在世界频道发送消息 + * @param {{ teamCode: string }} msg + * @param {BackendSession} session + * @memberof ComBattleHandler + */ + async autoInvite(msg: { teamCode: string }, session: BackendSession) { + let roleId = session.get('roleId'); + let roleName = session.get('roleName'); + let serverId = session.get('serverId'); + const { teamCode } = msg; + const msgData = await pushTeamInviteMsg(roleId, roleName, serverId, teamCode); + if (!msgData) return resResult(STATUS.WRONG_PARMS); + return resResult(STATUS.SUCCESS); + } + /** * @description 藏宝图合成 * @param {{original: Array<{id: number, count: number}>}} msg diff --git a/game-server/app/services/chatService.ts b/game-server/app/services/chatService.ts index 0e61d8790..a350321a5 100644 --- a/game-server/app/services/chatService.ts +++ b/game-server/app/services/chatService.ts @@ -7,7 +7,7 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './ import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage'; import { genCode, resResult } from '../pubUtils/util'; import { pinus } from 'pinus'; -import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, ON_MSG_ROUTE, RECENT_PRIVATE_CHATS_CNT, RECENT_GROUP_MSGS_CNT } from '../consts'; +import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, ON_MSG_ROUTE, RECENT_PRIVATE_CHATS_CNT, RECENT_GROUP_MSGS_CNT, MSG_TYPE, MSG_SOURCE } from '../consts'; import { getRoleOnlineInfo } from './redisService'; import { ChatInfoModel } from '../db/ChatInfo'; import { channelServer } from './chatChannelService'; @@ -285,3 +285,13 @@ export async function updatePrivateMsgReadInfo(roleId: string, targetRoleId: str const chatRec = chatInfo.recentPrivateChats.find(rec => { return rec.targetRoleId === targetRoleId }); return chatRec; } + +/** + * @description 发送组队一键邀请消息 + * @param {string} teamCode 队伍唯一标识 + */ +export async function pushTeamInviteMsg(roleId: string, roleName: string, serverId: number, teamCode: string) { + const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.WORLD, `${serverId}`, MSG_TYPE.RICH_TEXT, MSG_SOURCE.TEAM_INVITE, teamCode, null, null); + await pushGroupMsgToRoom(msgData); + return msgData; +} diff --git a/game-server/test/comBattle.test.ts b/game-server/test/comBattle.test.ts index 2a8da3897..2a44cb115 100644 --- a/game-server/test/comBattle.test.ts +++ b/game-server/test/comBattle.test.ts @@ -154,6 +154,41 @@ describe('寻宝创建队伍', function() { }); }); + it('一键邀请消息发送', function(done) { + let msgReceiveCnt = 0; + let teamCode = ''; + function checkInviteRes(res) { + checkSuccessResponse(res); + expect(res.data.content).to.be.equal(teamCode); + msgReceiveCnt += 1; + } + pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => { + checkInviteRes(res); + }); + pinusClient.on(ON_GROUP_MSG_ROUTE, (res) => { + checkInviteRes(res); + }); + pinusClient.request('battle.comBattleHandler.createTeam', createTeamParms, (res) => { + checkSuccessResponse(res); + teamCode = res.data.teamCode; + expect(teamCode).to.be.a('string'); + expect(res.data.roleStatus).to.be.an('array'); + res.data.roleStatus.forEach(roleSt => { + expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'headHid', 'sHid', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio'); + }); + pinusClient.request('battle.comBattleHandler.autoInvite', {teamCode}, (inviteRes) => { + checkSuccessResponse(inviteRes, false); + setTimeout(() => { + expect(msgReceiveCnt).to.be.equal(2); + pinusClient.request('battle.comBattleHandler.dismiss', {teamCode}, (dismissRes) => { + checkSuccessResponse(dismissRes, false); + done(); + }); + }, 500); + }); + }); + }); + it('搜索队伍再取消', function(done) { pinusClient.request('battle.comBattleHandler.searchTeam', searchTeamParms, (res) => { checkSuccessResponse(res, false); diff --git a/shared/consts/constModules/chatConst.ts b/shared/consts/constModules/chatConst.ts index 5f26d5fdc..6272aafac 100644 --- a/shared/consts/constModules/chatConst.ts +++ b/shared/consts/constModules/chatConst.ts @@ -26,7 +26,7 @@ export const CHANNEL_PREFIX = { export const MSG_SOURCE = { ROLE_SEND_TEXT: 0, PRIVATE_SEND_GIFT: 1, - TEAM: 2, + TEAM_ROLE: 2, HERO_QUALITY_UP: 3, COMPOSE_ORANGE_HERO: 4, HERO_STAR_MAX: 5, @@ -42,6 +42,7 @@ export const MSG_SOURCE = { TOWER_SUC: 15, MYSTERY_FIRST_SUC: 16, VESTIGE_FIRST_SUC: 17, + TEAM_INVITE: 18, } export const ON_MSG_ROUTE = 'onMessage';