登录:当账号登录的时候,将已登录玩家踢下

This commit is contained in:
luying
2022-06-18 17:36:11 +08:00
parent a7b4cbd7a0
commit e49c35fa4d
5 changed files with 61 additions and 14 deletions
+13 -1
View File
@@ -312,6 +312,7 @@ export async function clearChannelServers() {
*/
export async function roleLogin(roleId: string, userCode: string, sid: string, pkgName: string, createTime: number, serverId: number) {
await redisClient().hincrbyAsync(REDIS_KEY.ONLINE_CNT, roleId, 1);
await redisClient().hsetAsync(REDIS_KEY.USER_CODE, userCode, roleId);
return await redisClient().hsetAsync(REDIS_KEY.ONLINE_USERS, roleId, `${userCode}|${sid}|${pkgName}|${createTime}|${serverId}`);
}
@@ -323,7 +324,9 @@ export async function roleLeave(roleId: string) {
let role = await getRoleOnlineInfo(roleId);
let count = await redisClient().hincrbyAsync(REDIS_KEY.ONLINE_CNT, roleId, -1);
if(count <= 0) {
await redisClient().hdelAsync(REDIS_KEY.ONLINE_CNT, roleId);
await redisClient().hdelAsync(REDIS_KEY.ONLINE_USERS, roleId);
await redisClient().hdelAsync(REDIS_KEY.USER_CODE, role.userCode);
}
return role;
}
@@ -337,6 +340,11 @@ export async function isRoleOnline(roleId: string) {
return !!result;
}
export async function getOnlineRoleByUserCode(userCode: string) {
let roleId = await redisClient().hgetAsync(REDIS_KEY.USER_CODE, userCode);
return roleId;
}
/**
* 获得在线玩家userCode和sid
* @param roleId
@@ -550,7 +558,8 @@ export async function redisSubScribe() {
let treatRoleChannel = getRedisSubChannel(REDIS_KEY.TREAT_ROLE_CHANNEL, env);
let treatGuildChannel = getRedisSubChannel(REDIS_KEY.TREAT_GUILD_CHANNEL, env);
let surveyChannel = getRedisSubChannel(REDIS_KEY.SURVEY_CHANNEL, env);
await redisClientPub().subscribeAsync(payChannel, treatRoleChannel, treatGuildChannel, refundChannel, surveyChannel);
let userChannel = getRedisSubChannel(REDIS_KEY.USER_CHANNEL, env);
await redisClientPub().subscribeAsync(payChannel, treatRoleChannel, treatGuildChannel, refundChannel, surveyChannel, userChannel);
redisClientPub().on('message', (channel, message) => {
console.log('**********redisSubScribe*******')
console.log('channel: ', channel, payChannel);
@@ -575,6 +584,9 @@ export async function redisSubScribe() {
let servers = pinus.app.getServersByType('role');
let server = getRandSingleEelm(servers);
pinus.app.rpc.role.roleRemote.sendSurveyMail.toServer(server.id, message);
} else if(channel == userChannel) {
let [sid, roleId] = (message||'').split('|');
if(!!sid && !!roleId) pinus.app.rpc.connector.connectorRemote.remoteLogin.toServer(sid, roleId);
}
});
}