diff --git a/game-server/app/services/redisService.ts b/game-server/app/services/redisService.ts index 34f23caf1..ae9120ac3 100644 --- a/game-server/app/services/redisService.ts +++ b/game-server/app/services/redisService.ts @@ -311,6 +311,7 @@ export async function clearChannelServers() { * @param sid connector服的那个sid */ 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); return await redisClient().hsetAsync(REDIS_KEY.ONLINE_USERS, roleId, `${userCode}|${sid}|${pkgName}|${createTime}|${serverId}`); } @@ -320,7 +321,10 @@ export async function roleLogin(roleId: string, userCode: string, sid: string, p */ export async function roleLeave(roleId: string) { let role = await getRoleOnlineInfo(roleId); - await redisClient().hdelAsync(REDIS_KEY.ONLINE_USERS, roleId); + let count = await redisClient().hincrbyAsync(REDIS_KEY.ONLINE_CNT, roleId, -1); + if(count <= 0) { + await redisClient().hdelAsync(REDIS_KEY.ONLINE_USERS, roleId); + } return role; } diff --git a/shared/consts/constModules/sysConst.ts b/shared/consts/constModules/sysConst.ts index 3769a2dae..353e32b73 100644 --- a/shared/consts/constModules/sysConst.ts +++ b/shared/consts/constModules/sysConst.ts @@ -213,6 +213,7 @@ export enum REDIS_KEY { SERVER_OPEN_TIME = 'serverOpenTime', // 服务器开服时间 ONLINE_USERS ='onlineUsers', // 在线用户情况 ONLINE_TIME ='onlineTime', // 玩家在线时间 + ONLINE_CNT ='onlineCnt', // 在线次数 CHANNEL_SERVERS ='chat:channelServers', // 渠道对应的 chat 服务器 Id, USER_GATE_ACTIVITY ='usrGateAct', // 蛮夷入侵玩家排行 GATE_ACTIVITY ='gateAct', // 蛮夷入侵军团排行