rpc优化:所有remote加上try catch

This commit is contained in:
luying
2022-01-26 17:41:30 +08:00
parent c909d899ba
commit 6d2cafc119
11 changed files with 920 additions and 372 deletions
@@ -3,6 +3,7 @@ import { PVPConfigModel, PVPConfigType } from '../../../db/SystemConfig';
import { reloadResources } from '../../../pubUtils/data';
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
import { taflush } from '../../../services/sdkService';
import { errlogger } from '../../../util/logger';
export default function (app: Application) {
new HandlerService(app, {});
@@ -80,35 +81,63 @@ export class BattleRemote {
* 重载json资源
*/
public async reloadResources() {
reloadResources();
try {
reloadResources();
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public setPvpSeasonNum(pvpConfig: PVPConfigType) {
if(pvpConfig) {
this.app.set('pvpSeasonNum', pvpConfig.seasonNum);
this.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
try {
if(pvpConfig) {
this.app.set('pvpSeasonNum', pvpConfig.seasonNum);
this.app.set('pvpSeasonEndTime', pvpConfig.seasonEndTime);
}
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public async initPvpSeasonNum() {
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
this.setPvpSeasonNum(pvpConfig);
try {
let pvpConfig = await PVPConfigModel.findCurPVPConfig();
this.setPvpSeasonNum(pvpConfig);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public setServerMainten(serverIds: number[], startTime: number, endTime: number) {
setServerMainten(serverIds, startTime, endTime);
try {
setServerMainten(serverIds, startTime, endTime);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public stopServerMainten(serverIds: number[]) {
stopServerMainten(serverIds);
try {
stopServerMainten(serverIds);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public getServerMainten(serverId: number) {
return getServerMainten(serverId);
try {
return getServerMainten(serverId);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public taflush() {
return taflush();
try {
return taflush();
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
}
@@ -3,6 +3,7 @@ import { resResult } from '../../../pubUtils/util';
import { STATUS } from '../../../consts';
import { handleComBtlProgress } from '../../../services/comBattleService';
import { MemComBtlTeam } from '../../../domain/battleField/ComBattleTeamField';
import { errlogger } from '../../../util/logger';
export default function (app: Application) {
new HandlerService(app, {});
@@ -117,32 +118,40 @@ export class ComBattleRemote {
}
public async hurt(uid: string, sid: string, name: string, bossHurt: number, actorHurt: [{ actorId: number, actorHurt: number }]) {
console.log('hurt channel name: ', name);
let channelService = this.app.get('channelService');
this.bossHp -= bossHurt;
let channel = channelService.getChannel(name, false);
if (!!channel) {
if (this.bossHp < 0) {
this.bossHp = 0;
try {
console.log('hurt channel name: ', name);
let channelService = this.app.get('channelService');
this.bossHp -= bossHurt;
let channel = channelService.getChannel(name, false);
if (!!channel) {
if (this.bossHp < 0) {
this.bossHp = 0;
}
channel.pushMessage('bossHp', resResult(STATUS.SUCCESS, { bossHp: this.bossHp }));
}
channel.pushMessage('bossHp', resResult(STATUS.SUCCESS, { bossHp: this.bossHp }));
return this.bossHp;
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
return this.bossHp;
}
public async leaveFromBattle(roleId: string, teamCode: string ) {
let teamMap: Map<string, MemComBtlTeam> = this.app.get('teamMap');
if(teamMap && teamMap.has(teamCode)) {
let myTeam = teamMap.get(teamCode);
for(let roleStatus of myTeam.roleStatus) {
if(roleStatus.roleId == roleId) {
roleStatus.battleStatus = 2; // 自己失败了
try {
let teamMap: Map<string, MemComBtlTeam> = this.app.get('teamMap');
if(teamMap && teamMap.has(teamCode)) {
let myTeam = teamMap.get(teamCode);
for(let roleStatus of myTeam.roleStatus) {
if(roleStatus.roleId == roleId) {
roleStatus.battleStatus = 2; // 自己失败了
}
}
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false);
await handleComBtlProgress(myTeam, this.app.get('robotHurtTimer'), teamMap, channel); // 结算
}
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false);
await handleComBtlProgress(myTeam, this.app.get('robotHurtTimer'), teamMap, channel); // 结算
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
}