diff --git a/game-server/app/servers/battle/handler/comBattleHandler.ts b/game-server/app/servers/battle/handler/comBattleHandler.ts index 99bab1fd0..2005652bb 100644 --- a/game-server/app/servers/battle/handler/comBattleHandler.ts +++ b/game-server/app/servers/battle/handler/comBattleHandler.ts @@ -153,7 +153,7 @@ export class ComBattleHandler { channel.add(roleId, sid); } } - channelService.pushMessageByUids('onTeamJoin', {teamInfo: comTeam}, uids); + channelService.pushMessageByUids('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: comTeam}), uids); } let thiz = this; // 倒计时一定时间给队长匹配机器人 @@ -166,7 +166,7 @@ export class ComBattleHandler { for (let st of robotStArr) { await ComBattleTeamModel.addRole(teamCode, st); } - channel.pushMessage('onTeamJoin', {teamInfo: team}); + channel.pushMessage('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: team})); } // TODO: 代码抽象 if (team && team.roleIds && team.roleIds.length === 3) { @@ -243,7 +243,7 @@ export class ComBattleHandler { // if (!team) channelService.pushMessageByUids('onTeamJoin', {teamInfo: null}, [{uid: roleId, sid}]); thiz.teamMap.set(teamCode, comTeam); // 推送组队消息 - channelService.pushMessageByUids('onTeamJoin', {teamInfo: comTeam}, [{uid: roleId, sid}]); + channelService.pushMessageByUids('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: comTeam}), [{uid: roleId, sid}]); let channel = channelService.getChannel(teamCode, true); let users = channel.getMembers(); if (users.indexOf(roleId) === -1) { @@ -252,7 +252,7 @@ export class ComBattleHandler { // 机器人队伍 3 秒直接开战 setTimeout(async () => { await ComBattleTeamModel.updateStatus(teamCode, COM_TEAM_STATUS.FIGHTING); - channelService.pushMessageByUids('onComBtlStart', {teamCode, roleStatus: comTeam.roleStatus}, [{uid: roleId, sid}]); + channelService.pushMessageByUids('onComBtlStart', resResult(STATUS.SUCCESS, {teamCode, roleStatus: comTeam.roleStatus}), [{uid: roleId, sid}]); }, 3000); }, COM_BTL_CONST.ASSIST_TIME); return resResult(STATUS.SUCCESS); @@ -315,7 +315,7 @@ export class ComBattleHandler { if (users.indexOf(roleId) === -1) { channel.add(roleId, sid); } - channel.pushMessage('onTeamJoin', {teamInfo: teamStatus}); + channel.pushMessage('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: teamStatus})); if (teamStatus.roleIds && teamStatus.roleIds.length === 3) { let thiz = this; @@ -382,7 +382,7 @@ export class ComBattleHandler { let channelService = this.app.get('channelService'); let channel = channelService.getChannel(teamCode, false); - channel.pushMessage('onTeammateReady', {teamCode, roleId, heroes}); + channel.pushMessage('onTeammateReady', resResult(STATUS.SUCCESS, {teamCode, roleId, heroes})); return resResult(STATUS.SUCCESS); } @@ -412,7 +412,7 @@ export class ComBattleHandler { let channelService = this.app.get('channelService'); let channel = channelService.getChannel(teamCode, false); - channel.pushMessage('onTeammateReady', {teamCode, roleId, heroes}); + channel.pushMessage('onTeammateReady', resResult(STATUS.SUCCESS, {teamCode, roleId, heroes})); return resResult(STATUS.SUCCESS); } @@ -452,7 +452,7 @@ export class ComBattleHandler { if (users.indexOf(roleIdToRm) !== -1) { channel.removeMember(roleIdToRm); } - channel.pushMessage('onLeaveTeam', {teamCode, roleId: roleIdToRm}); + channel.pushMessage('onLeaveTeam', resResult(STATUS.SUCCESS, {teamCode, roleId: roleIdToRm})); clearComBtlTimer(teamCode, this.teamDisTimer); // 移除队员停止解散计时 let thiz = this; setTimeout(async () => { @@ -472,7 +472,7 @@ export class ComBattleHandler { for (let st of robotStArr) { await ComBattleTeamModel.addRole(teamCode, st); } - channel.pushMessage('onTeamJoin', {teamInfo: team}); + channel.pushMessage('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: team})); } // TODO: 代码抽象 if (team && team.roleIds && team.roleIds.length === 3) { @@ -507,7 +507,7 @@ export class ComBattleHandler { let channelService = this.app.get('channelService'); let channel = channelService.getChannel(teamCode, false); - channel.pushMessage('onTeamDismiss', {teamCode}); + channel.pushMessage('onTeamDismiss', resResult(STATUS.SUCCESS, {teamCode})); channel.destroy(); clearComBtlTimer(teamCode, this.teamDisTimer); // 队伍解散停止解散计时 return resResult(STATUS.SUCCESS); @@ -536,7 +536,7 @@ export class ComBattleHandler { clearComBtlTimer(teamCode, this.teamDisTimer); // 战斗开始停止解散计时 let channelService = this.app.get('channelService'); let channel = channelService.getChannel(teamCode, false); - channel.pushMessage('onComBtlStart', {teamCode, roleStatus: teamStatus.roleStatus}); + channel.pushMessage('onComBtlStart', resResult(STATUS.SUCCESS, {teamCode, roleStatus: teamStatus.roleStatus})); // 每场倒计时结算 let thiz = this; setTimeout(async () => { @@ -546,7 +546,7 @@ export class ComBattleHandler { let channel = channelService.getChannel(teamCode, false); let team = await ComBattleTeamModel.syncTeamData({teamCode, status: COM_TEAM_STATUS.LOOSE, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr}); if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR); - channel.pushMessage('onTeamComplete', {teamCode, result: false}); + channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, {teamCode, result: false})); thiz.teamMap.delete(teamCode); } }, COM_BTL_CONST.BTL_TIME_LMT); @@ -626,7 +626,7 @@ export class ComBattleHandler { let channelService = this.app.get('channelService'); let channel = channelService.getChannel(teamCode, false); const roleStatus = teamStatus.roleStatus.map(st => {return {roleId: st.roleId, totalDmg: st.totalDmg, killed: st.killed}}); - channel.pushMessage('onTeammateAct', {teamCode, bossCurHp: teamStatus.bossCurHp, bossHpArr: teamStatus.bossHpArr, roleStatus}); + channel.pushMessage('onTeammateAct', resResult(STATUS.SUCCESS, {teamCode, bossCurHp: teamStatus.bossCurHp, bossHpArr: teamStatus.bossHpArr, roleStatus})); // 判断战斗是否结束 let battleSt = checkComBattleResult(teamStatus); teamStatus.status = battleSt; @@ -648,7 +648,7 @@ export class ComBattleHandler { let res = await ItemModel.decreaseItems(teamStatus.capId, [{id: teamStatus.blueprtId, count: 1}]); if (res.hasError) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH); } - channel.pushMessage('onTeamComplete', {teamCode, result}); + channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, {teamCode, result})); this.teamMap.delete(teamCode); } return resResult(STATUS.SUCCESS); @@ -670,14 +670,14 @@ export class ComBattleHandler { if (isSuccess && teamStatus.bossCurHp <= 0) { let team = await ComBattleTeamModel.updateResult(teamCode, roleId, isSuccess); if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR); - channel.pushMessage('onTeamComplete', {teamCode, result: isSuccess}); + channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, {teamCode, result: isSuccess})); } else if (!isSuccess) { let team = await ComBattleTeamModel.updateResult(teamCode, roleId, isSuccess); if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR); if (team.status === COM_TEAM_STATUS.LOOSE) { - channel.pushMessage('onTeamComplete', {teamCode, result: isSuccess}); + channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, {teamCode, result: isSuccess})); } else { - channel.pushMessage('onTeammateAct', {teamCode, bossCurHp: teamStatus.bossCurHp, roleStatus: {roleId, battleStatus: 2}}); + channel.pushMessage('onTeammateAct', resResult(STATUS.SUCCESS, {teamCode, bossCurHp: teamStatus.bossCurHp, roleStatus: {roleId, battleStatus: 2}})); } } return resResult(STATUS.SUCCESS, { bossCurHp: teamStatus.bossCurHp }); diff --git a/game-server/app/servers/battle/remote/comBattleRemote.ts b/game-server/app/servers/battle/remote/comBattleRemote.ts index 9a9bdde7e..f5200085c 100644 --- a/game-server/app/servers/battle/remote/comBattleRemote.ts +++ b/game-server/app/servers/battle/remote/comBattleRemote.ts @@ -1,4 +1,6 @@ import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus'; +import { resResult } from '../../../pubUtils/util'; +import { STATUS } from '../../../consts'; export default function (app: Application) { return new ComBattleRemote(app); @@ -22,7 +24,7 @@ export class ComBattleRemote { let param = { user: username }; - channel.pushMessage('onAdd', param); + channel.pushMessage('onAdd', resResult(STATUS.SUCCESS, param)); if (!!channel) { channel.add(uid, sid); @@ -48,7 +50,7 @@ export class ComBattleRemote { let param = { user: username }; - channel.pushMessage('onAdd', param); + channel.pushMessage('onAdd', resResult(STATUS.SUCCESS, param)); if (!!channel) { channel.add(uid, sid); @@ -108,7 +110,7 @@ export class ComBattleRemote { let param = { user: username }; - channel.pushMessage('onLeave', param); + channel.pushMessage('onLeave', resResult(STATUS.SUCCESS, param)); } public async hurt(uid: string, sid: string, name: string, bossHurt: number, actorHurt: [{actorId: number, actorHurt: number}]) { @@ -120,7 +122,7 @@ export class ComBattleRemote { if (this.bossHp < 0) { this.bossHp = 0; } - channel.pushMessage('bossHp', {bossHp: this.bossHp}); + channel.pushMessage('bossHp', resResult(STATUS.SUCCESS, {bossHp: this.bossHp})); } return this.bossHp; } diff --git a/game-server/app/servers/chat/handler/chatHandler.ts b/game-server/app/servers/chat/handler/chatHandler.ts index 502243e1e..ccfa0c211 100644 --- a/game-server/app/servers/chat/handler/chatHandler.ts +++ b/game-server/app/servers/chat/handler/chatHandler.ts @@ -1,4 +1,6 @@ import {Application, BackendSession} from 'pinus'; +import { resResult } from '../../../pubUtils/util'; +import { STATUS } from '../../../consts'; export default function(app: Application) { @@ -29,13 +31,13 @@ export class ChatHandler { // the target is all users if (msg.target === '*') { - channel.pushMessage('onChat', param); + channel.pushMessage('onChat', resResult(STATUS.SUCCESS, param)); } // the target is specific user else { let tuid = msg.target + '*' + rid; let tsid = channel.getMember(tuid)['sid']; - channelService.pushMessageByUids('onChat', param, [{ + channelService.pushMessageByUids('onChat', resResult(STATUS.SUCCESS, param), [{ uid: tuid, sid: tsid }]); @@ -55,13 +57,13 @@ export class ChatHandler { // the target is all users if (msg.target === '*') { - channel.pushMessage('onChat', param); + channel.pushMessage('onChat', resResult(STATUS.SUCCESS, param)); } // the target is specific user else { let tuid = msg.target + '*' + rid; let tsid = channel.getMember(tuid)['sid']; - channelService.pushMessageByUids('onChat', param, [{ + channelService.pushMessageByUids('onChat', resResult(STATUS.SUCCESS, param), [{ uid: tuid, sid: tsid }]); diff --git a/game-server/app/servers/chat/remote/chatRemote.ts b/game-server/app/servers/chat/remote/chatRemote.ts index ab4f48203..97e9edda1 100644 --- a/game-server/app/servers/chat/remote/chatRemote.ts +++ b/game-server/app/servers/chat/remote/chatRemote.ts @@ -1,4 +1,6 @@ import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus'; +import { resResult } from '../../../pubUtils/util'; +import { STATUS } from '../../../consts'; export default function (app: Application) { return new ChatRemote(app); @@ -39,7 +41,7 @@ export class ChatRemote { let param = { user: username }; - channel.pushMessage('onAdd', param); + channel.pushMessage('onAdd', resResult(STATUS.SUCCESS, param)); if (!!channel) { channel.add(uid, sid); @@ -87,6 +89,6 @@ export class ChatRemote { let param = { user: username }; - channel.pushMessage('onLeave', param); + channel.pushMessage('onLeave', resResult(STATUS.SUCCESS, param)); } } \ No newline at end of file diff --git a/game-server/app/servers/gm/handler/gmHandler.ts b/game-server/app/servers/gm/handler/gmHandler.ts index 4b154d504..503eeb28d 100644 --- a/game-server/app/servers/gm/handler/gmHandler.ts +++ b/game-server/app/servers/gm/handler/gmHandler.ts @@ -33,9 +33,7 @@ export class GmHandler { let event = await getEvent(eventStatus, roleId, roleName); let tsid = channel.getMember(roleId)['sid']; - channelService.pushMessageByUids('onSpecialEvent', { - msg: { event } - }, [{ + channelService.pushMessageByUids('onSpecialEvent', resResult(STATUS.SUCCESS, { event }), [{ uid: roleId, sid: tsid }]); @@ -75,9 +73,7 @@ export class GmHandler { let tsid = channel.getMember(roleId)['sid']; - channelService.pushMessageByUids(eventName, { - msg: content - }, [{ + channelService.pushMessageByUids(eventName, resResult(STATUS.SUCCESS, content), [{ uid: roleId, sid: tsid }]); diff --git a/game-server/app/servers/gm/remote/gmRemote.ts b/game-server/app/servers/gm/remote/gmRemote.ts index ab4f48203..97e9edda1 100644 --- a/game-server/app/servers/gm/remote/gmRemote.ts +++ b/game-server/app/servers/gm/remote/gmRemote.ts @@ -1,4 +1,6 @@ import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus'; +import { resResult } from '../../../pubUtils/util'; +import { STATUS } from '../../../consts'; export default function (app: Application) { return new ChatRemote(app); @@ -39,7 +41,7 @@ export class ChatRemote { let param = { user: username }; - channel.pushMessage('onAdd', param); + channel.pushMessage('onAdd', resResult(STATUS.SUCCESS, param)); if (!!channel) { channel.add(uid, sid); @@ -87,6 +89,6 @@ export class ChatRemote { let param = { user: username }; - channel.pushMessage('onLeave', param); + channel.pushMessage('onLeave', resResult(STATUS.SUCCESS, param)); } } \ No newline at end of file diff --git a/game-server/app/services/battleService.ts b/game-server/app/services/battleService.ts index 8665dbec0..a36686a3b 100644 --- a/game-server/app/services/battleService.ts +++ b/game-server/app/services/battleService.ts @@ -88,7 +88,7 @@ export async function towerBattleEnd(sid: string, roleId: string, serverId: numb if (reward) towerReward = reward; if (towerLv == HANG_UP_CONSTS.ENABLE_LV) { await startHangUp(roleId, roleName); - pinus.app.get('channelService').pushMessageByUids('hangUpEnable', {code: 200, data: {enable: true}}, [{uid: roleId, sid}]); + pinus.app.get('channelService').pushMessageByUids('hangUpEnable', resResult(STATUS.SUCCESS, {enable: true}), [{uid: roleId, sid}]); } } return { diff --git a/game-server/app/services/eventSercive.ts b/game-server/app/services/eventSercive.ts index ff206ef74..3ee1b4841 100644 --- a/game-server/app/services/eventSercive.ts +++ b/game-server/app/services/eventSercive.ts @@ -292,9 +292,7 @@ function randomPosition(positionStr: string, prePoint: Array, curPoint: function pushEventMsg(sid: string, roleId: string, msg: any ) { let channelService = pinus.app.get('channelService'); - let param = { msg }; - - channelService.pushMessageByUids('onSpecialEvent', param, [{ + channelService.pushMessageByUids('onSpecialEvent', resResult(STATUS.SUCCESS, msg), [{ uid: roleId, sid: sid }]); diff --git a/game-server/app/services/funcSwitchService.ts b/game-server/app/services/funcSwitchService.ts index 33b6422e3..82ac8c6e8 100644 --- a/game-server/app/services/funcSwitchService.ts +++ b/game-server/app/services/funcSwitchService.ts @@ -1,6 +1,8 @@ import { BackendSession, FrontendSession, pinus } from "pinus"; import { getGamedata } from "../pubUtils/gamedata"; import { RoleModel } from "../db/Role"; +import { resResult } from "../pubUtils/util"; +import { STATUS } from "../consts"; // 开启功能 export async function switchOnFunc(roleId: string, type: number, param: number, session: (BackendSession|FrontendSession)) { @@ -19,7 +21,7 @@ export async function switchOnFunc(roleId: string, type: number, param: number, if(funcs.length > 0) { - pinus.app.get('channelService').pushMessageByUids('onFuncSwitchOn', {funcs}, [{ + pinus.app.get('channelService').pushMessageByUids('onFuncSwitchOn', resResult(STATUS.SUCCESS, {funcs}), [{ uid: roleId, sid: sid }]);