rpc优化:所有remote加上try catch
This commit is contained in:
@@ -14,6 +14,7 @@ import { RankFirstType } from '../../../db/RankFirst';
|
||||
import { LotType } from '../../../db/Lot';
|
||||
import { _checkFilterWords, getTire, taflush } from '../../../services/sdkService';
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -55,14 +56,18 @@ export class ChatRemote {
|
||||
*
|
||||
*/
|
||||
public async addWorldChannel(roleId: string, serverId: number, sid: string, flag: boolean = true) {
|
||||
const name = `world${serverId}`;
|
||||
let channel = this.channelService.getChannel(name, flag);
|
||||
if (!channel) return;
|
||||
channel.add(roleId, sid);
|
||||
let param = {
|
||||
roleId
|
||||
};
|
||||
return this.getWorldChannel(name);
|
||||
try {
|
||||
const name = `world${serverId}`;
|
||||
let channel = this.channelService.getChannel(name, flag);
|
||||
if (!channel) return;
|
||||
channel.add(roleId, sid);
|
||||
let param = {
|
||||
roleId
|
||||
};
|
||||
return this.getWorldChannel(name);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +100,16 @@ export class ChatRemote {
|
||||
*
|
||||
*/
|
||||
public async kickWorldChannel(roleId: string, sid: string, serverId: number) {
|
||||
const name = `world${serverId}`;
|
||||
|
||||
let channel = this.channelService.getChannel(name, false);
|
||||
// leave channel
|
||||
if (!channel) return;
|
||||
channel.leave(roleId, sid);
|
||||
try {
|
||||
const name = `world${serverId}`;
|
||||
|
||||
let channel = this.channelService.getChannel(name, false);
|
||||
// leave channel
|
||||
if (!channel) return;
|
||||
channel.leave(roleId, sid);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,12 +119,16 @@ export class ChatRemote {
|
||||
* @param param 信息
|
||||
*/
|
||||
public async sendWorldMessage(serverId: number, param: any) {
|
||||
const name = `world${serverId}`;
|
||||
|
||||
let channel = this.channelService.getChannel(name, false);
|
||||
// leave channel
|
||||
if (!!channel) {
|
||||
channel.pushMessage('onWorldMessage', resResult(STATUS.SUCCESS, param));
|
||||
try {
|
||||
const name = `world${serverId}`;
|
||||
|
||||
let channel = this.channelService.getChannel(name, false);
|
||||
// leave channel
|
||||
if (!!channel) {
|
||||
channel.pushMessage('onWorldMessage', resResult(STATUS.SUCCESS, param));
|
||||
}
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,9 +140,13 @@ export class ChatRemote {
|
||||
* @memberof ChatRemote
|
||||
*/
|
||||
public async addChannel(channelName: string, roleId: string, sid: string) {
|
||||
let channel = this.channelService.getChannel(channelName, true);
|
||||
if (!channel) return;
|
||||
addUserToChannel(channel, new ChannelUser(roleId, sid));
|
||||
try {
|
||||
let channel = this.channelService.getChannel(channelName, true);
|
||||
if (!channel) return;
|
||||
addUserToChannel(channel, new ChannelUser(roleId, sid));
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,10 +157,14 @@ export class ChatRemote {
|
||||
* @memberof ChatRemote
|
||||
*/
|
||||
public async leaveChannel(channelName: string, roleId: string, sid: string) {
|
||||
let channel = this.channelService.getChannel(channelName, false);
|
||||
// leave channel
|
||||
if (!channel) return;
|
||||
channel.leave(roleId, sid);
|
||||
try {
|
||||
let channel = this.channelService.getChannel(channelName, false);
|
||||
// leave channel
|
||||
if (!channel) return;
|
||||
channel.leave(roleId, sid);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,10 +173,14 @@ export class ChatRemote {
|
||||
* @memberof ChatRemote
|
||||
*/
|
||||
public async sendGroupMsg(roomId: string, msg: Partial<GroupMessageType>) {
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
const roleInfo = await getSimpleRoleInfo(msg.roleId);
|
||||
channel.pushMessage(ON_GROUP_MSG_ROUTE, resResult(STATUS.SUCCESS, { ...msg, roleInfo }));
|
||||
try {
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
const roleInfo = await getSimpleRoleInfo(msg.roleId);
|
||||
channel.pushMessage(ON_GROUP_MSG_ROUTE, resResult(STATUS.SUCCESS, { ...msg, roleInfo }));
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +189,11 @@ export class ChatRemote {
|
||||
* @memberof ChatRemote
|
||||
*/
|
||||
public async sendPrivateMsg(msg: Partial<PrivateMessageType>) {
|
||||
|
||||
try {
|
||||
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,10 +201,14 @@ export class ChatRemote {
|
||||
* @param serverId
|
||||
*/
|
||||
public async sendGuildActivityEnd(serverId: number) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(this.GUILD_ACTIVITY_END, resResult(STATUS.SUCCESS, {}));
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(this.GUILD_ACTIVITY_END, resResult(STATUS.SUCCESS, {}));
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,10 +216,14 @@ export class ChatRemote {
|
||||
* @param serverId
|
||||
*/
|
||||
public async sendRaceActivityStart(serverId: number) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(this.RACE_ACTIVITY_START, resResult(STATUS.SUCCESS, {}));
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(this.RACE_ACTIVITY_START, resResult(STATUS.SUCCESS, {}));
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,18 +231,26 @@ export class ChatRemote {
|
||||
* @param serverId
|
||||
*/
|
||||
public async sendRankTopUpdated(serverId: number, ranks: (RankFirstType & {status: number})[]) {
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(this.RANK_TOP_UPDATE, resResult(STATUS.SUCCESS, { ranks }));
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(this.RANK_TOP_UPDATE, resResult(STATUS.SUCCESS, { ranks }));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载json资源
|
||||
*/
|
||||
public async reloadResources() {
|
||||
reloadResources();
|
||||
try {
|
||||
reloadResources();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -214,11 +259,15 @@ export class ChatRemote {
|
||||
* @param serverId
|
||||
*/
|
||||
public async sendGuildActivityUpdate(serverId: number) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
let guildActivities = getAllGuildActivityStatus();
|
||||
channel.pushMessage(this.GUILD_ACTIVITY_STATUS_UPDATE, resResult(STATUS.SUCCESS, { guildActivities }));
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
let guildActivities = getAllGuildActivityStatus();
|
||||
channel.pushMessage(this.GUILD_ACTIVITY_STATUS_UPDATE, resResult(STATUS.SUCCESS, { guildActivities }));
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,10 +277,14 @@ export class ChatRemote {
|
||||
* @param mails 邮件内容
|
||||
*/
|
||||
public async sendMail(serverId: number, path: string, data: { mails: MailParam[] }) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(path, resResult(STATUS.SUCCESS, data));
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(path, resResult(STATUS.SUCCESS, data));
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,21 +292,29 @@ export class ChatRemote {
|
||||
* @param serverId
|
||||
*/
|
||||
public async sendServerMaintenance(serverId: number) {
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return { result: false, serverId };
|
||||
channel.pushMessage('onServerMaintenance', resResult(STATUS.SERVER_MAINTENANCE));
|
||||
return { result: true, serverId };
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return { result: false, serverId };
|
||||
channel.pushMessage('onServerMaintenance', resResult(STATUS.SERVER_MAINTENANCE));
|
||||
return { result: true, serverId };
|
||||
}
|
||||
|
||||
public async pushCurrentTime(serverId: number, time: number) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return { result: false, serverId };
|
||||
|
||||
channel.pushMessage('onPushCurrentTime', resResult(STATUS.SUCCESS, { time }));
|
||||
return { result: true, serverId };
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return { result: false, serverId };
|
||||
|
||||
channel.pushMessage('onPushCurrentTime', resResult(STATUS.SUCCESS, { time }));
|
||||
return { result: true, serverId };
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,49 +322,81 @@ export class ChatRemote {
|
||||
* @param guildCode
|
||||
*/
|
||||
public async sendGuildAuction(guildCode: string, lot: LotType) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.GUILD, guildCode);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if(!channel) return false;
|
||||
|
||||
channel.pushMessage('onAuctionOver', resResult(STATUS.SUCCESS, { lot }));
|
||||
return true;
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.GUILD, guildCode);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if(!channel) return false;
|
||||
|
||||
channel.pushMessage('onAuctionOver', resResult(STATUS.SUCCESS, { lot }));
|
||||
return true;
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async sendWorldAuction(serverId: number, lot: LotType) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if(!channel) return false;
|
||||
|
||||
channel.pushMessage('onAuctionOver', resResult(STATUS.SUCCESS, { lot }));
|
||||
return true;
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if(!channel) return false;
|
||||
|
||||
channel.pushMessage('onAuctionOver', resResult(STATUS.SUCCESS, { lot }));
|
||||
return true;
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async sendAuctionUpdate(serverId: number, params: { lots: LotType[] }) {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if(!channel) return false;
|
||||
|
||||
channel.pushMessage('onAuctionUpdate', resResult(STATUS.SUCCESS, params));
|
||||
return true;
|
||||
try {
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if(!channel) return false;
|
||||
|
||||
channel.pushMessage('onAuctionUpdate', resResult(STATUS.SUCCESS, params));
|
||||
return true;
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async checkFilterWords(word: string) {
|
||||
return await _checkFilterWords(word);
|
||||
try {
|
||||
return await _checkFilterWords(word);
|
||||
} 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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user