diff --git a/game-server/app.ts b/game-server/app.ts index b184fd3b8..4d506c8f9 100644 --- a/game-server/app.ts +++ b/game-server/app.ts @@ -162,15 +162,6 @@ function initRedis(app: _pinus.Application) { app.set('redis', redisClient); redLockService.initRedlock(redisClient); redlockCacheService.init(); - // TODO 重启 1 次只需要初始化 1 次,判断方法可以优化 - if (app.serverId === 'master-server-1') { - redisService.readDataBase(); - redisService.initAllRank(); - redisService.clearComBtlQueue(); - redisService.clearChannelServers(); - updateTeamStatus(COM_TEAM_STATUS.DEFAULT, COM_TEAM_STATUS.LOOSE); - updateTeamStatus(COM_TEAM_STATUS.FIGHTING, COM_TEAM_STATUS.LOOSE); - } } function setupRoutes(app: _pinus.Application) { @@ -223,6 +214,15 @@ if (app.isMaster()) { app.event.on('remove_servers', (server) => { redisService.removeConnectors(server); }) + app.event.on('start_all', (servers) => { + // 全部服务器启动完毕后初始化 redis 数据 + redisService.readDataBase(); + redisService.initAllRank(); + redisService.clearComBtlQueue(); + redisService.clearChannelServers(); + updateTeamStatus(COM_TEAM_STATUS.DEFAULT, COM_TEAM_STATUS.LOOSE); + updateTeamStatus(COM_TEAM_STATUS.FIGHTING, COM_TEAM_STATUS.LOOSE); + }); } // start app