分布式部署:服务器分布式部署,扩缩容后路由的计算
This commit is contained in:
@@ -31,7 +31,7 @@ export class GateHandler {
|
||||
return resResult(STATUS.CONNECTOR_ERR);
|
||||
}
|
||||
// select connector
|
||||
let res = dispatch(userCode, connectors);
|
||||
let res = dispatch(userCode, connectors, 'connector');
|
||||
return resResult(STATUS.SUCCESS, { host: res.clientHost, port: res.clientPort });
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Application, BackendSession, pinus} from 'pinus';
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { EventRecordModel } from '../../../db/EventRecord';
|
||||
import { getEvent } from '../../../services/eventSercive';
|
||||
@@ -7,7 +7,6 @@ import { STATUS } from '../../../consts/statusCode';
|
||||
import { GMMailModel } from '../../../db/GMMail';
|
||||
import { setGmMails } from '../../../pubUtils/gmData/gmDataUtil';
|
||||
import { getRoleOnlineInfo } from '../../../services/redisService';
|
||||
import { dispatch } from '../../../util/dispatcher';
|
||||
import { SendMailFun } from '../../../services/mailService';
|
||||
import { GM_MAIL_TYPE } from '../../../consts';
|
||||
import { RewardInter } from '../../../pubUtils/interface';
|
||||
@@ -16,7 +15,7 @@ import { ServerlistModel } from '../../../db/Serverlist';
|
||||
import { getWorldChannelSid } from '../../../services/chatService';
|
||||
import { MaintenanceModel } from '../../../db/Maintenance';
|
||||
import { initMaintenance, stopMaintenance } from '../../../services/gmService';
|
||||
export default function(app: Application) {
|
||||
export default function (app: Application) {
|
||||
return new GmHandler(app);
|
||||
}
|
||||
|
||||
@@ -29,8 +28,8 @@ export class GmHandler {
|
||||
|
||||
let { uid, serverId } = msg;
|
||||
let role = await RoleModel.findByUid(uid, serverId);
|
||||
if(!role) return resResult(STATUS.GM_ROLE_NOT_FOUND);
|
||||
let {roleId, roleName, eventStatus } = role;
|
||||
if (!role) return resResult(STATUS.GM_ROLE_NOT_FOUND);
|
||||
let { roleId, roleName, eventStatus } = role;
|
||||
|
||||
let channelService = this.app.get('channelService');
|
||||
let channel = channelService.getChannel(roleId, true);
|
||||
@@ -49,9 +48,9 @@ export class GmHandler {
|
||||
return resResult(STATUS.SUCCESS, { list: event });
|
||||
}
|
||||
|
||||
async clearEvent(msg: { }, session: BackendSession) {
|
||||
async clearEvent(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
|
||||
await EventRecordModel.deleteAccount(roleId);
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
@@ -64,19 +63,19 @@ export class GmHandler {
|
||||
let content = {};
|
||||
try {
|
||||
content = JSON.parse(message);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return resResult(STATUS.GM_JSON_FORMAT_ERR);
|
||||
}
|
||||
console.log(uid, serverId)
|
||||
let role = await RoleModel.findByUid(uid, serverId);
|
||||
if(!role) return resResult(STATUS.GM_ROLE_NOT_FOUND);
|
||||
if (!role) return resResult(STATUS.GM_ROLE_NOT_FOUND);
|
||||
let { roleId } = role;
|
||||
|
||||
let hisOnlineInfo = await getRoleOnlineInfo(role.roleId);
|
||||
if(hisOnlineInfo.isOnline) {
|
||||
if (hisOnlineInfo.isOnline) {
|
||||
let sid = hisOnlineInfo.sid;
|
||||
if (!!sid) {//下发邮件,对应前端红点提示
|
||||
pinus.app.channelService.pushMessageByUids(eventName, resResult(STATUS.SUCCESS, content), [{uid: roleId, sid}]);
|
||||
pinus.app.channelService.pushMessageByUids(eventName, resResult(STATUS.SUCCESS, content), [{ uid: roleId, sid }]);
|
||||
}
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { msg: content });
|
||||
@@ -84,8 +83,8 @@ export class GmHandler {
|
||||
|
||||
//对接gm后台,下发邮件
|
||||
async addMail(msg: { endTime: number, sendName: string, content: string, goods: RewardInter[], sendTime: number }) {
|
||||
let {endTime, content, sendName, sendTime, goods } = msg;
|
||||
let mail = await GMMailModel.addMail({endTime, content, sendName, sendTime, goods});
|
||||
let { endTime, content, sendName, sendTime, goods } = msg;
|
||||
let mail = await GMMailModel.addMail({ endTime, content, sendName, sendTime, goods });
|
||||
return resResult(STATUS.SUCCESS, { mail });
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ export class GmHandler {
|
||||
let { id, mailType, roleIds, serverIds } = msg;
|
||||
let f = new SendMailFun();
|
||||
await f.setWithGmMail(id);
|
||||
if(mailType == GM_MAIL_TYPE.SINGLE || mailType == GM_MAIL_TYPE.GROUP) {
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE || mailType == GM_MAIL_TYPE.GROUP) {
|
||||
await f.sendToUsers(mailType, roleIds);
|
||||
} else {
|
||||
await f.sendToServer(serverIds);
|
||||
@@ -103,11 +102,11 @@ export class GmHandler {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
async sendWithContent(msg: { contentId: number, mailType: number, params: { params?: string[], sendName?: string, goods?: RewardInter[], endTime?: number}, roleIds?: string[], serverIds?: number[] }, session: BackendSession) {
|
||||
async sendWithContent(msg: { contentId: number, mailType: number, params: { params?: string[], sendName?: string, goods?: RewardInter[], endTime?: number }, roleIds?: string[], serverIds?: number[] }, session: BackendSession) {
|
||||
let { contentId, mailType, roleIds, serverIds, params } = msg;
|
||||
let f = new SendMailFun();
|
||||
f.setWithContentId(contentId, params);
|
||||
if(mailType == GM_MAIL_TYPE.SINGLE || mailType == GM_MAIL_TYPE.GROUP) {
|
||||
if (mailType == GM_MAIL_TYPE.SINGLE || mailType == GM_MAIL_TYPE.GROUP) {
|
||||
await f.sendToUsers(mailType, roleIds);
|
||||
} else {
|
||||
await f.sendToServer(serverIds);
|
||||
@@ -118,41 +117,41 @@ export class GmHandler {
|
||||
async reloadResource(msg: {}, session: BackendSession) {
|
||||
try {
|
||||
let activityServers = this.app.getServersByType('activity');
|
||||
for(let { id } of activityServers) {
|
||||
for (let { id } of activityServers) {
|
||||
await this.app.rpc.activity.activityRemote.reloadResources.toServer(id);
|
||||
}
|
||||
let battleServers = this.app.getServersByType('battle');
|
||||
for(let { id } of battleServers) {
|
||||
for (let { id } of battleServers) {
|
||||
await this.app.rpc.battle.battleRemote.reloadResources.toServer(id);
|
||||
}
|
||||
let chatServers = this.app.getServersByType('chat');
|
||||
for(let { id } of chatServers) {
|
||||
for (let { id } of chatServers) {
|
||||
await this.app.rpc.chat.chatRemote.reloadResources.toServer(id);
|
||||
}
|
||||
let connectServers = this.app.getServersByType('connector');
|
||||
for(let { id } of connectServers) {
|
||||
for (let { id } of connectServers) {
|
||||
await this.app.rpc.connector.connectorRemote.reloadResources.toServer(id);
|
||||
}
|
||||
let guildServers = this.app.getServersByType('guild');
|
||||
for(let { id } of guildServers) {
|
||||
for (let { id } of guildServers) {
|
||||
await this.app.rpc.guild.guildRemote.reloadResources.toServer(id);
|
||||
}
|
||||
let roleServers = this.app.getServersByType('role');
|
||||
for(let { id } of roleServers) {
|
||||
for (let { id } of roleServers) {
|
||||
await this.app.rpc.role.roleRemote.reloadResources.toServer(id);
|
||||
}
|
||||
let systimerServers = this.app.getServersByType('systimer');
|
||||
for(let { id } of systimerServers) {
|
||||
for (let { id } of systimerServers) {
|
||||
await this.app.rpc.systimer.systimerRemote.reloadResources.toServer(id);
|
||||
}
|
||||
let orderServers = this.app.getServersByType('order');
|
||||
for(let { id } of orderServers) {
|
||||
for (let { id } of orderServers) {
|
||||
await this.app.rpc.order.orderRemote.reloadResources.toServer(id);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
isOK: true
|
||||
});
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
isOK: false,
|
||||
err: e.stack
|
||||
@@ -171,9 +170,9 @@ export class GmHandler {
|
||||
async sendMarquee(msg: { code: string }, session: BackendSession) {
|
||||
const { code } = msg;
|
||||
let systimerServers = this.app.getServersByType('systimer');
|
||||
for(let { id } of systimerServers) {
|
||||
for (let { id } of systimerServers) {
|
||||
let result = await this.app.rpc.systimer.systimerRemote.setMarquee.toServer(id, code);
|
||||
if(!result) return resResult(STATUS.GM_MARQUEE_ERR);
|
||||
if (!result) return resResult(STATUS.GM_MARQUEE_ERR);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
@@ -181,9 +180,9 @@ export class GmHandler {
|
||||
async cancelMarquee(msg: { code: string }, session: BackendSession) {
|
||||
const { code } = msg;
|
||||
let systimerServers = this.app.getServersByType('systimer');
|
||||
for(let { id } of systimerServers) {
|
||||
for (let { id } of systimerServers) {
|
||||
let result = await this.app.rpc.systimer.systimerRemote.cancelMarquee.toServer(id, code);
|
||||
if(!result) return resResult(STATUS.GM_MARQUEE_CANCEL_ERR);
|
||||
if (!result) return resResult(STATUS.GM_MARQUEE_CANCEL_ERR);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
@@ -192,7 +191,7 @@ export class GmHandler {
|
||||
const { code } = msg;
|
||||
const uid = session.get('uid');
|
||||
const maintenance = await MaintenanceModel.updateStatusByCode(code, true, uid);
|
||||
if(!maintenance) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!maintenance) return resResult(STATUS.WRONG_PARMS);
|
||||
await initMaintenance(maintenance);
|
||||
|
||||
return resResult(STATUS.SUCCESS,);
|
||||
@@ -202,15 +201,15 @@ export class GmHandler {
|
||||
const { code } = msg;
|
||||
const uid = session.get('uid');
|
||||
const maintenance = await MaintenanceModel.updateStatusByCode(code, false, uid);
|
||||
if(!maintenance) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!maintenance) return resResult(STATUS.WRONG_PARMS);
|
||||
await stopMaintenance(maintenance, uid);
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS,);
|
||||
}
|
||||
|
||||
async setMaintenance() {
|
||||
let connectorServers = pinus.app.getServersByType('connector');
|
||||
for(let { id } of connectorServers) {
|
||||
for (let { id } of connectorServers) {
|
||||
pinus.app.rpc.connector.connectorRemote.setServerMainten.toServer(id, [1]);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
|
||||
Reference in New Issue
Block a user