From c7dbf45af698f10112b8dbd030f085842af59f28 Mon Sep 17 00:00:00 2001 From: heavyrain2012 Date: Thu, 30 Dec 2021 16:47:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E5=85=B3=E9=97=ADpc=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=97=B6=E5=8F=AF=E4=BB=A5=E6=B8=85=E7=90=86?= =?UTF-8?q?=E6=8E=89=E5=8E=86=E5=8F=B2=E5=9C=A8=E7=BA=BF=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/MemoryMessagesStore.java | 18 ++++++++++++++++++ .../persistence/MemorySessionStore.java | 4 +++- .../java/io/moquette/spi/IMessagesStore.java | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index dcd4fca64..b25fefb0e 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -2313,6 +2313,24 @@ public ErrorCode modifyUserInfo(String userId, WFCMessage.ModifyMyInfoRequest re } + public void forceCleanOnlineStatus(String userId, String clientId) { + if (m_Server.isShutdowning()) { + return; + } + + if(!mMultiPlatformNotification || m_Server.getStore().sessionsStore().isMultiEndpointSupported()) { + WFCMessage.UserSettingEntry pcentry = getUserSetting(userId, kUserSettingPCOnline, "PC"); + if (pcentry != null && !StringUtil.isNullOrEmpty(pcentry.getValue()) && pcentry.getValue().contains(clientId)) { + updateUserSettings(userId, WFCMessage.ModifyUserSettingReq.newBuilder().setScope(kUserSettingPCOnline).setKey("PC").setValue("").build(), clientId); + } + + WFCMessage.UserSettingEntry padentry = getUserSetting(userId, kUserSettingPCOnline, "Pad"); + if (padentry != null && !StringUtil.isNullOrEmpty(padentry.getValue()) && padentry.getValue().contains(clientId)) { + updateUserSettings(userId, WFCMessage.ModifyUserSettingReq.newBuilder().setScope(kUserSettingPCOnline).setKey("Pad").setValue("").build(), clientId); + } + } + } + @Override public void updateUserOnlineSetting(MemorySessionStore.Session session, boolean online) { if(!mMultiPlatformNotification) { diff --git a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java index fd6498831..f568fb9c7 100755 --- a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java @@ -729,7 +729,8 @@ public ErrorCode kickoffPCClient(String operator, String pcClientId) { if (session != null) { if(!operator.equals(session.getUsername())) { LOG.error("kickoffPCClient failure, user {} don't have client {}", operator, pcClientId); - return ErrorCode.ERROR_CODE_NOT_RIGHT; + mServer.getProcessor().getMessagesStore().forceCleanOnlineStatus(operator, pcClientId); + return ErrorCode.ERROR_CODE_SUCCESS; } if (session.getPlatform() == ProtoConstants.Platform.Platform_LINUX || session.getPlatform() == ProtoConstants.Platform.Platform_Windows @@ -746,6 +747,7 @@ public ErrorCode kickoffPCClient(String operator, String pcClientId) { } } else { LOG.error("Can't find the session for client <{}>", pcClientId); + mServer.getProcessor().getMessagesStore().forceCleanOnlineStatus(operator, pcClientId); } return ErrorCode.ERROR_CODE_SUCCESS; } diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index a9486fd4e..8cc493e8d 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -140,6 +140,8 @@ public String toString() { ErrorCode modifyUserInfo(String userId, WFCMessage.ModifyMyInfoRequest request) throws Exception; + void forceCleanOnlineStatus(String userId, String clientId); + void updateUserOnlineSetting(MemorySessionStore.Session session, boolean online); ErrorCode modifyUserStatus(String userId, int status);