✨ feat(config): redis中添加最大同时在线人数
This commit is contained in:
@@ -103,17 +103,25 @@ export default class Utils extends Service {
|
||||
|
||||
// 检测是否可以登录
|
||||
public async validateCanLogin() {
|
||||
if(gameData.serverConst.CLOSE_LOGIN == 1) return false;
|
||||
if(gameData.serverConst.CLOSE_LOGIN_WHEN_ONLINE_MAX) {
|
||||
try {
|
||||
if(gameData.serverConst.CLOSE_LOGIN == 1) return false;
|
||||
if(gameData.serverConst.CLOSE_LOGIN_WHEN_ONLINE_MAX) {
|
||||
|
||||
let redisClient: RedisClient = this.ctx.app.context.redisClient;
|
||||
let count = await redisClient.hlenAsync(REDIS_KEY.ONLINE_USERS);
|
||||
let redisClient: RedisClient = this.ctx.app.context.redisClient;
|
||||
let count = await redisClient.hlenAsync(REDIS_KEY.ONLINE_USERS);
|
||||
const Max = await redisClient.getAsync(REDIS_KEY.MAX_ONLINE_USERS);
|
||||
|
||||
if(count >= gameData.serverConst.MAX_ONLINE_USER_COUNT) {
|
||||
return false
|
||||
console.log('validateCanLogin:', count, Max);
|
||||
if(Max && count >= parseInt(Max)) {
|
||||
console.log('validateCanLogin false:', count, Max);
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch(e) {
|
||||
console.error('validateCanLogin', e);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 比较以 . 分隔的版本号。返回 0 则版本号相等,返回正数则 versionA 大,返回负数则 versionB 大
|
||||
|
||||
Reference in New Issue
Block a user