登录:当账号登录的时候,将已登录玩家踢下
This commit is contained in:
@@ -3,6 +3,7 @@ import { resResult as pubResult } from '../pubUtils/util';
|
||||
import { gameData } from 'app/pubUtils/data';
|
||||
import { RedisClient } from 'redis';
|
||||
import { REDIS_KEY } from '@consts';
|
||||
import { getRedisSubChannel } from 'app/pubUtils/sdkUtil';
|
||||
const csprng = require('csprng');
|
||||
/**
|
||||
* Utils Service
|
||||
@@ -57,6 +58,25 @@ export default class Utils extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
public async checkOnlineUser(userCode: string) {
|
||||
let redisClient: RedisClient = this.ctx.app.context.redisClient;
|
||||
let onlineRoleId = await redisClient.hgetAsync(REDIS_KEY.USER_CODE, userCode);
|
||||
|
||||
if (!!onlineRoleId) { // 多地登陆踢下线
|
||||
let str = await redisClient.hgetAsync(REDIS_KEY.ONLINE_USERS, onlineRoleId);
|
||||
|
||||
if(str) {
|
||||
try {
|
||||
let [,sid] = str?.split('|')??[];
|
||||
let name = getRedisSubChannel(REDIS_KEY.USER_CHANNEL, this.ctx.app.config.env);
|
||||
let result = await redisClient.publishAsync(name, `${sid}|${onlineRoleId}`);
|
||||
} catch(e) {
|
||||
console.error('checkOnlineUser', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否可以登录
|
||||
public async validateCanLogin() {
|
||||
if(gameData.serverConst.CLOSE_LOGIN == 1) return false;
|
||||
|
||||
Reference in New Issue
Block a user