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

View File

@@ -11,6 +11,7 @@ import { pick } from 'underscore';
import { LotType } from '../../../db/Lot';
import { DividendType } from '../../../db/Dividend';
import { getRoleOnlineInfo } from '../../../services/redisService';
import { errlogger } from '../../../util/logger';
export default function (app: Application) {
new HandlerService(app, {});
@@ -130,14 +131,18 @@ export class GuildRemote {
* @param sid 玩家sid
*/
public memberQuit(guildCode: string, roleId: string, guild: GuildType, sid?: string) {
// 被踢出公会
this.pushMessageByUids(guildCode, this.MEMBER_QUIT, roleId, {
code: guildCode,
roleId
}, sid);
// 更新人数减少
this.updateInfo(guildCode, { memberCnt: guild.memberCnt, guildCe: guild.guildCe });
leaveGuildChannel(roleId, sid, guildCode);
try {
// 被踢出公会
this.pushMessageByUids(guildCode, this.MEMBER_QUIT, roleId, {
code: guildCode,
roleId
}, sid);
// 更新人数减少
this.updateInfo(guildCode, { memberCnt: guild.memberCnt, guildCe: guild.guildCe });
leaveGuildChannel(roleId, sid, guildCode);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -145,9 +150,13 @@ export class GuildRemote {
* @param guildCode 军团code
*/
public dismiss(guildCode: string) {
let channel = this.pushMessage(guildCode, this.DISMISS, { code: guildCode });
if (!!channel) {
channel.destroy();
try {
let channel = this.pushMessage(guildCode, this.DISMISS, { code: guildCode });
if (!!channel) {
channel.destroy();
}
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
@@ -157,7 +166,11 @@ export class GuildRemote {
* @param info 军团相关信息
*/
public updateInfo(guildCode: string, info: any) {
this.pushMessage(guildCode, this.GUILD_INFO_UPDATE, info);
try {
this.pushMessage(guildCode, this.GUILD_INFO_UPDATE, info);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -174,7 +187,7 @@ export class GuildRemote {
this.demotion(guildCode, oldLeaderId);
this.promotion(guildCode, roleId);
}catch(e) {
console.log(e.stack)
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
@@ -184,9 +197,13 @@ export class GuildRemote {
* @param roleId 旧团长id
*/
public demotion(guildCode: string, roleId: string) {
this.pushMessageByUids(guildCode, this.DEMOTION, roleId, {
code: guildCode
});
try {
this.pushMessageByUids(guildCode, this.DEMOTION, roleId, {
code: guildCode
});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -195,9 +212,13 @@ export class GuildRemote {
* @param roleId 新团长id
*/
public promotion(guildCode: string, roleId: string) {
this.pushMessageByUids(guildCode, this.PROMOTION, roleId, {
code: guildCode
});
try {
this.pushMessageByUids(guildCode, this.PROMOTION, roleId, {
code: guildCode
});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -205,8 +226,12 @@ export class GuildRemote {
* @param guildRecType 动态
*/
public addRec(guildRecType: GuildRecType) {
let { guildCode, type, params, createTime } = guildRecType;
this.pushMessage(guildCode, this.GUILD_REC_ADD, { type, params, createTime });
try {
let { guildCode, type, params, createTime } = guildRecType;
this.pushMessage(guildCode, this.GUILD_REC_ADD, { type, params, createTime });
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -214,7 +239,11 @@ export class GuildRemote {
* @param guildCode
*/
public pushGateHp(guildCode: string, gateHp: number) {
this.pushMessage(guildCode, this.GUILD_GATE_ACT_HP, { gateHp });
try {
this.pushMessage(guildCode, this.GUILD_GATE_ACT_HP, { gateHp });
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -222,7 +251,11 @@ export class GuildRemote {
* @param guildCode
*/
public pushRank(guildCode: string, msg: GuildRankParams) {
this.pushMessage(guildCode, this.GATE_ACT_RANK, msg);
try {
this.pushMessage(guildCode, this.GATE_ACT_RANK, msg);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -230,7 +263,11 @@ export class GuildRemote {
* @param guildCode
*/
public pushCityActRank(guildCode: string, msg: GuildRankParams) {
this.pushMessage(guildCode, this.CITY_ACT_RANK, msg);
try {
this.pushMessage(guildCode, this.CITY_ACT_RANK, msg);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -238,8 +275,12 @@ export class GuildRemote {
* @param guildCode
*/
public async sendGuildActivityEnd(guildCode: string) {
console.log("MSG END")
this.pushMessage(guildCode, this.GUILD_ACTIVITY_END, {});
try {
console.log("MSG END")
this.pushMessage(guildCode, this.GUILD_ACTIVITY_END, {});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -249,16 +290,20 @@ export class GuildRemote {
* @param declareCount 宣战数量
*/
public async sendGuildCityDeclare(cityId: number, declareGuildCode: string, declareCount: number) {
this.pushMessageToCity(cityId, this.GUILD_CITY_DECLARE, {
cityId,
declareGuildCode,
declareCount
});
this.pushMessage(declareGuildCode, this.GUILD_CITY_DECLARE, {
cityId,
declareGuildCode,
declareCount
});
try {
this.pushMessageToCity(cityId, this.GUILD_CITY_DECLARE, {
cityId,
declareGuildCode,
declareCount
});
this.pushMessage(declareGuildCode, this.GUILD_CITY_DECLARE, {
cityId,
declareGuildCode,
declareCount
});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -267,10 +312,14 @@ export class GuildRemote {
* @param gateHp 血条
*/
public async pushCityGateHp(cityId: number, gateHp: number) {
this.pushMessageToCity(cityId, this.GUILD_CITY_ACT_HP, {
cityId,
gateHp
});
try {
this.pushMessageToCity(cityId, this.GUILD_CITY_ACT_HP, {
cityId,
gateHp
});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -280,12 +329,16 @@ export class GuildRemote {
* @param ranks 军团排名和自己所在的排名
*/
public async pushRaceHorseUpdate(guildCode: string, woodenHorseList: WoodenHorse[], ranks: GuildRankParams, events: Event[]) {
this.pushMessage(guildCode, this.GUILD_RACE_UPDATE, {
timestamp: Date.now(),
woodenHorseList,
...ranks,
events
});
try {
this.pushMessage(guildCode, this.GUILD_RACE_UPDATE, {
timestamp: Date.now(),
woodenHorseList,
...ranks,
events
});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
@@ -295,10 +348,14 @@ export class GuildRemote {
* @param woodenHorse 木马
*/
public async pushRaceHorseJoin(guildCode: string, woodenHorse: WoodenHorse) {
this.pushMessage(guildCode, this.GUILD_RACE_JOIN, {
timestamp: Date.now(),
woodenHorse
});
try {
this.pushMessage(guildCode, this.GUILD_RACE_JOIN, {
timestamp: Date.now(),
woodenHorse
});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -306,7 +363,11 @@ export class GuildRemote {
* @param guildCode
*/
public async sendRaceEvent(guildCode: string, events: Event[]) {
this.pushMessage(guildCode, this.GUILD_RACE_EVENT, { timestamp: Date.now(), events });
try {
this.pushMessage(guildCode, this.GUILD_RACE_EVENT, { timestamp: Date.now(), events });
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -317,7 +378,11 @@ export class GuildRemote {
* @param status
*/
public async pushBossStatus(guildCode: string, result: any) {
this.pushMessage(guildCode, this.GUILD_BOSS_OPEN, pick(result, ['status', 'bossInfo', 'leaderOpenCnt']));
try {
this.pushMessage(guildCode, this.GUILD_BOSS_OPEN, pick(result, ['status', 'bossInfo', 'leaderOpenCnt']));
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -325,8 +390,12 @@ export class GuildRemote {
* @param guildCode
*/
public async sendPopUpActivity(guildCode: string, data: any[]) {
console.log("sendPopUpActivity")
this.pushMessage(guildCode, this.GUILD_POP_UP_ACTIVITY, data);
try {
console.log("sendPopUpActivity")
this.pushMessage(guildCode, this.GUILD_POP_UP_ACTIVITY, data);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
/**
@@ -336,24 +405,44 @@ export class GuildRemote {
* @param data 军团内容
*/
public async sendMailToGuild(guildCode: string, path: string, data: { mails: MailParam[] }) {
this.pushMessage(guildCode, path, data);
try {
this.pushMessage(guildCode, path, data);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public async sendTrainReset(guildCode: string) {
this.pushMessage(guildCode, this.GUILD_TRAIN_RESET, {});
try {
this.pushMessage(guildCode, this.GUILD_TRAIN_RESET, {});
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public async pushEncourage(guildCode: string, param: {encourageCnt: number; encourageMax: number; myEncourageCnt: number;}) {
this.pushMessage(guildCode, this.GUILD_BOSS_ENCOURAGE, param);
try {
this.pushMessage(guildCode, this.GUILD_BOSS_ENCOURAGE, param);
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public async pushAuctionUpdate(guildCode: string, param: { lots: LotType[]; dividends: DividendType[] }) {
if(param.lots) this.pushMessage(guildCode, this.AUCTION_UPDATE, { lots: param.lots });
if(param.dividends) this.pushMessage(guildCode, this.DIVIDEND_UPDATE, { dividends: param.dividends });
try {
if(param.lots) this.pushMessage(guildCode, this.AUCTION_UPDATE, { lots: param.lots });
if(param.dividends) this.pushMessage(guildCode, this.DIVIDEND_UPDATE, { dividends: param.dividends });
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
public async pushAuctionAdd(guildCode: string, param: { lots: LotType[]; dividends: DividendType[] }) {
if(param.lots) this.pushMessage(guildCode, this.AUCTION_ADD, { lots: param.lots });
if(param.dividends) this.pushMessage(guildCode, this.DIVIDEND_ADD, { dividends: param.dividends });
try {
if(param.lots) this.pushMessage(guildCode, this.AUCTION_ADD, { lots: param.lots });
if(param.dividends) this.pushMessage(guildCode, this.DIVIDEND_ADD, { dividends: param.dividends });
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
}