From 42c9397349d5c10ab05f9a6ede277ea2db747083 Mon Sep 17 00:00:00 2001 From: luying Date: Thu, 25 May 2023 16:33:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(37=E9=9C=80=E6=B1=82):=20?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=A4=9A=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../servers/connector/handler/entryHandler.ts | 18 +++++++++--------- web-server/app/service/Utils.ts | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/game-server/app/servers/connector/handler/entryHandler.ts b/game-server/app/servers/connector/handler/entryHandler.ts index 775ecc125..79aa20723 100644 --- a/game-server/app/servers/connector/handler/entryHandler.ts +++ b/game-server/app/servers/connector/handler/entryHandler.ts @@ -55,8 +55,16 @@ export class EntryHandler { console.log('user token not found'); return resResult(STATUS.TOKEN_ERR); } - let onlineRoleId = await getOnlineRoleByUserCode(user.userCode); + let ip = this.getIp(session); + let isWhiteList = await checkWhiteList(pinus.app.get('env'), ip, user.uid); + let ipLocation = await getIpLocation(ip); + let role = await RoleModel.findByUidAndSetTime(user.uid, serverId, ip, ipLocation, null, true); + if (!role) { + return resResult(STATUS.ROLE_NOT_FOUND); + } + + let onlineRoleId = isWhiteList? role.roleId: await getOnlineRoleByUserCode(user.userCode); if (!!onlineRoleId) { // 多地登陆踢下线 let connect = await getRoleOnlineInfo(onlineRoleId); if (connect.sid = self.app.getServerId()) { @@ -66,10 +74,8 @@ export class EntryHandler { } } - let ip = this.getIp(session); let server = await ServerlistModel.findByServerId(serverId); if(!server) return resResult(STATUS.SERVER_NOT_FOUND); - let isWhiteList = await checkWhiteList(pinus.app.get('env'), ip, user.uid); if(!isWhiteList) { // 白名单 if(server.openTime > nowSeconds()) { return resResult(STATUS.SERVER_IS_NOT_OPEN); @@ -85,12 +91,6 @@ export class EntryHandler { } } - - let ipLocation = await getIpLocation(ip); - let role = await RoleModel.findByUidAndSetTime(user.uid, serverId, ip, ipLocation, null, true); - if (!role) { - return resResult(STATUS.ROLE_NOT_FOUND); - } let serverName = this.app.getServerId(); await roleLogin(role.roleId, user.userCode, serverName, role.createTime, role.serverId, role.lv, role.topLineupCe); // 保存在线用户 diff --git a/web-server/app/service/Utils.ts b/web-server/app/service/Utils.ts index 5e3487062..13840f840 100644 --- a/web-server/app/service/Utils.ts +++ b/web-server/app/service/Utils.ts @@ -6,6 +6,7 @@ import { REDIS_KEY, SERVER_STATUS } from '@consts'; import { getRedisSubChannel } from 'app/pubUtils/sdkUtil'; import { ServerlistType } from '@db/Serverlist'; import { nowSeconds } from 'app/pubUtils/timeUtil'; +import { checkWhiteList } from 'app/pubUtils/sysUtil'; const csprng = require('csprng'); /** * Utils Service @@ -63,8 +64,9 @@ 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); + let isWhiteList = await checkWhiteList(this.ctx.app.config.realEnv, this.ctx.clientIp, this.ctx.uid); - if (!!onlineRoleId) { // 多地登陆踢下线 + if (!isWhiteList && !!onlineRoleId) { // 多地登陆踢下线 let str = await redisClient.hgetAsync(REDIS_KEY.ONLINE_USERS, onlineRoleId); if(str) {