From 93bb9b50aea8dba653502c07b37de991ff3e6e7f Mon Sep 17 00:00:00 2001 From: "heavyrain.lee" Date: Fri, 24 Apr 2020 09:36:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0PC=E4=B8=8B=E7=BA=BF=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imhandler/KickoffPCClientHandler.java | 33 +++++++++++++++++++ .../persistence/MemorySessionStore.java | 19 +++++++++++ .../java/io/moquette/spi/ISessionsStore.java | 2 ++ .../src/main/java/win/liyufan/im/IMTopic.java | 1 + 4 files changed, 55 insertions(+) create mode 100644 broker/src/main/java/io/moquette/imhandler/KickoffPCClientHandler.java diff --git a/broker/src/main/java/io/moquette/imhandler/KickoffPCClientHandler.java b/broker/src/main/java/io/moquette/imhandler/KickoffPCClientHandler.java new file mode 100644 index 00000000..a1c9a0c6 --- /dev/null +++ b/broker/src/main/java/io/moquette/imhandler/KickoffPCClientHandler.java @@ -0,0 +1,33 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package io.moquette.imhandler; + +import cn.wildfirechat.common.ErrorCode; +import cn.wildfirechat.pojos.GroupNotificationBinaryContent; +import cn.wildfirechat.proto.ProtoConstants; +import cn.wildfirechat.proto.WFCMessage; +import com.hazelcast.util.StringUtil; +import io.moquette.spi.impl.Qos1PublishHandler; +import io.netty.buffer.ByteBuf; + +import static win.liyufan.im.IMTopic.KickoffGroupMemberTopic; +import static win.liyufan.im.IMTopic.KickoffPCClientTopic; + +@Handler(value = KickoffPCClientTopic) +public class KickoffPCClientHandler extends GroupHandler { + @Override + public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) { + String pcClientId = request.getId(); + if (StringUtil.isNullOrEmpty(pcClientId)) { + return ErrorCode.INVALID_PARAMETER; + } + + return m_sessionsStore.kickoffPCClient(fromUser, pcClientId); + } +} diff --git a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java index 581ef757..cb7e7f01 100755 --- a/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemorySessionStore.java @@ -653,6 +653,25 @@ public class MemorySessionStore implements ISessionsStore { return sessions.get(clientID).secondPhaseStore.size(); } + + @Override + public ErrorCode kickoffPCClient(String operator, String pcClientId) { + Session session = sessions.get(pcClientId); + if (session != null) { + if (session.getPlatform() == ProtoConstants.Platform.Platform_LINUX + || session.getPlatform() == ProtoConstants.Platform.Platform_WEB + || session.getPlatform() == ProtoConstants.Platform.Platform_Windows + || session.getPlatform() == ProtoConstants.Platform.Platform_OSX) { + databaseStore.updateSessionDeleted(operator, pcClientId, 1); + sessions.remove(pcClientId); + mServer.getProcessor().kickoffSession(session); + } else { + return ErrorCode.ERROR_CODE_NOT_RIGHT; + } + } + return ErrorCode.ERROR_CODE_SUCCESS; + } + @Override public void cleanSession(String clientID) { LOG.info("Fooooooooo <{}>", clientID); diff --git a/broker/src/main/java/io/moquette/spi/ISessionsStore.java b/broker/src/main/java/io/moquette/spi/ISessionsStore.java index b3648169..9d190ed4 100755 --- a/broker/src/main/java/io/moquette/spi/ISessionsStore.java +++ b/broker/src/main/java/io/moquette/spi/ISessionsStore.java @@ -151,4 +151,6 @@ public interface ISessionsStore { void cleanSession(String clientID); boolean isMultiEndpointSupported(); + + ErrorCode kickoffPCClient(String operator, String pcClientId); } diff --git a/broker/src/main/java/win/liyufan/im/IMTopic.java b/broker/src/main/java/win/liyufan/im/IMTopic.java index b1fb2df6..aa1fe9d1 100755 --- a/broker/src/main/java/win/liyufan/im/IMTopic.java +++ b/broker/src/main/java/win/liyufan/im/IMTopic.java @@ -74,4 +74,5 @@ public interface IMTopic { String DestroyUserTopic = "DESTROYUSER"; String LoadRemoteMessagesTopic = "LRM"; + String KickoffPCClientTopic = "KPCC"; }