diff --git a/game-server/app/servers/gm/handler/gmServerHandler.ts b/game-server/app/servers/gm/handler/gmServerHandler.ts index 0b536995f..3f74b63ca 100644 --- a/game-server/app/servers/gm/handler/gmServerHandler.ts +++ b/game-server/app/servers/gm/handler/gmServerHandler.ts @@ -5,7 +5,7 @@ import moment = require('moment'); import { CreateServerParam, UpdateRegionParams } from '../../../domain/backEndField/params'; import { RegionModel } from '../../../db/Region'; import { gameData } from '../../../pubUtils/data'; -import { Maintenance, ServerlistModel } from '../../../db/Serverlist'; +import { Maintenance, ServerlistModel, ServerlistUpdate } from '../../../db/Serverlist'; import { nowSeconds } from '../../../pubUtils/timeUtil'; import { GM_MAIL_TYPE, MAIL_TIME_TYPE, REF_CIRCLE_MAIL_TIME } from '../../../consts'; import { SendMailFun } from '../../../services/mailService'; @@ -78,6 +78,9 @@ export class GmHandler { let server = await ServerlistModel.findByServerId(id); let maintenance = server.maintenance; if(maintenance) { + // 更新serverlist上的status + await ServerlistModel.updateByServerId(server.id, { 'maintenance.isOpen': false } as ServerlistUpdate); + // console.log('&&&', server, server.id) await pinus.app.rpc.systimer.systimerRemote.stopMaintenance.broadcast(maintenance.batchCode, [server.id]); } diff --git a/game-server/app/services/timeTaskService.ts b/game-server/app/services/timeTaskService.ts index d74eec711..a8295d528 100644 --- a/game-server/app/services/timeTaskService.ts +++ b/game-server/app/services/timeTaskService.ts @@ -486,9 +486,6 @@ async function startMaintenanceSchedule(batchCode: string) { await pinus.app.rpc.chat.chatRemote.sendServerMaintenance.toServer(chatSid, serverId); } } - - // 更新serverlist上的status - await ServerlistModel.updateByServerIds(serverIds, { serverStatus: SERVER_STATUS.MAINTENANCE }); // 更新connectorRemote里面的维护服务器 console.log('******** startMaintenanceSchedule', batchCode, serverIds, maintenance.startTime, maintenance.endTime) @@ -516,9 +513,6 @@ export async function stopMaintenance(batchCode: string, serverIds: number[]) { maintenInfos.delete(batchCode); } - // 更新serverlist上的status - await ServerlistModel.updateByServerIds(serverIds, { serverStatus: SERVER_STATUS.HOT, 'maintenance.isOpen': false } as ServerlistUpdate); - // 更新connectorRemote里面的维护服务器 pinus.app.rpc.connector.connectorRemote.stopServerMainten.broadcast(serverIds); pinus.app.rpc.activity.activityRemote.stopServerMainten.broadcast(serverIds); diff --git a/gm-server/app/controller/game.ts b/gm-server/app/controller/game.ts index ab7ffd912..c0256a531 100644 --- a/gm-server/app/controller/game.ts +++ b/gm-server/app/controller/game.ts @@ -38,6 +38,22 @@ export default class GameController extends Controller { return } + public async stopServerRegister() { + const { ctx } = this; + const { id } = ctx.request.body; + + ctx.body = await ctx.service.game.stopServerRegister(id); + return + } + + public async switchServerStatus() { + const { ctx } = this; + const { id, status } = ctx.request.body; + + ctx.body = await ctx.service.game.switchServerStatus(id, status); + return + } + // public async getMaintenanceList() { // const { ctx } = this; // const {page, pageSize, sortField, sortOrder, form} = ctx.request.body; diff --git a/gm-server/app/router.ts b/gm-server/app/router.ts index ace939d7c..b7d528755 100644 --- a/gm-server/app/router.ts +++ b/gm-server/app/router.ts @@ -55,6 +55,8 @@ export default (app: Application) => { router.post('/api/game/getregions', controller.game.getRegions); router.post('/api/game/getservers', controller.game.getServers); router.post('/api/game/getregionstategy', controller.game.getRegionStategy); + router.post('/api/game/stopserverregister', controller.game.stopServerRegister); + router.post('/api/game/swicthserverstatus', controller.game.switchServerStatus); // router.post('/api/game/getmaintenancelist', controller.game.getMaintenanceList); // router.post('/api/game/updatemaintenance', controller.game.updateMaintenance); diff --git a/gm-server/app/service/Game.ts b/gm-server/app/service/Game.ts index a75627ced..8ea7e3cd0 100644 --- a/gm-server/app/service/Game.ts +++ b/gm-server/app/service/Game.ts @@ -12,6 +12,7 @@ import { MarqueeModel, MarqueeParam } from '@db/Marquee'; import { AccuseRecModel } from '@db/AccuseRec'; import { RegionModel } from '@db/Region'; import { ActivityGroupModel } from '@db/ActivityGroup'; +import { nowSeconds } from '@pubUtils/timeUtil'; /** * Test Service @@ -63,6 +64,20 @@ export default class Game extends Service { }); } + public async stopServerRegister(id: number) { + const { ctx } = this; + const server = await ServerlistModel.updateByServerId(id, { stopRegisterTime: nowSeconds() - 1 }); + if(!server) return ctx.service.utils.resResult(STATUS.WRONG_PARMS); + return ctx.service.utils.resResult(STATUS.SUCCESS); + } + + public async switchServerStatus(id: number, status: number) { + const { ctx } = this; + const server = await ServerlistModel.updateByServerId(id, { serverStatus: status }); + if(!server) return ctx.service.utils.resResult(STATUS.WRONG_PARMS); + return ctx.service.utils.resResult(STATUS.SUCCESS); + } + public async getRegionStategy(id: number) { const { ctx } = this; let region = await RegionModel.findRegionById(id); diff --git a/shared/db/Serverlist.ts b/shared/db/Serverlist.ts index 68ac8e72f..1d1ac3bbf 100644 --- a/shared/db/Serverlist.ts +++ b/shared/db/Serverlist.ts @@ -64,10 +64,13 @@ export default class Serverlist extends BaseModel { activityGroupId: number[]; // 活动组 public get status() { - if (nowSeconds() > this.openTime) { - return this.serverStatus; + let now = nowSeconds(); + if (now < this.openTime) { + return SERVER_STATUS.WILL_OPEN; + } else if (this.maintenance && this.maintenance.isOpen && this.maintenance.startTime < now && this.maintenance.endTime > now) { + return SERVER_STATUS.MAINTENANCE; } else { - return SERVER_STATUS.WILL_OPEN; // 未开服 + return this.serverStatus; // 未开服 } } diff --git a/web-server/app.ts b/web-server/app.ts index 98722b94e..514dc7ba6 100644 --- a/web-server/app.ts +++ b/web-server/app.ts @@ -19,6 +19,10 @@ export default class FooBoot implements IBoot { await this.connectGMDB(this.app); await this.connectRedis(this.app); + this.app.config.realEnv = this.app.config.env; + if(this.app.config.env == 'local') { + this.app.config.realEnv = 'development'; + } } configDidLoad() { diff --git a/web-server/app/controller/game.ts b/web-server/app/controller/game.ts index 574299750..ea6fdb30d 100644 --- a/web-server/app/controller/game.ts +++ b/web-server/app/controller/game.ts @@ -31,6 +31,7 @@ export default class GameController extends Controller { let serverList = new Array(); let loginServerList = new Array(); + console.log('****', ctx.app.config.realEnv) let allServers = await ServerlistModel.findByEnv(ctx.app.config.realEnv); let roles = await RoleModel.findAllByUid(uid, true, true); for (let server of allServers) { @@ -50,7 +51,7 @@ export default class GameController extends Controller { loginServerList.sort((a, b) => { return b.updatedAt.getTime() - a.updatedAt.getTime() }); - if (serverList && serverList.length > 0) { + if (serverList) { ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { serverList, loginServerList }); } else { ctx.body = ctx.service.utils.resResult(STATUS.SERVER_NOT_FOUND); diff --git a/web-server/app/service/Auth.ts b/web-server/app/service/Auth.ts index 5b0b5d332..c79d9f5a0 100644 --- a/web-server/app/service/Auth.ts +++ b/web-server/app/service/Auth.ts @@ -291,10 +291,10 @@ export default class Auth extends Service { const ctx = this.ctx; const { uid } = ctx; const role = await RoleModel.findByUid(uid, serverId); - if(role.blockType == BLOCK_TYPE.BLOCK) { - return ctx.service.utils.resResult(STATUS.BLOCKED); - } if (role) { + if(role.blockType == BLOCK_TYPE.BLOCK) { + return ctx.service.utils.resResult(STATUS.BLOCKED); + } return ctx.service.utils.resResult(STATUS.SUCCESS, { roleId: role.roleId }); } return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);