Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39b62e5942 | ||
|
|
5bb8ab3d95 | ||
|
|
8dfc23b61d | ||
|
|
c8769808b5 | ||
|
|
2fc106aa26 | ||
|
|
da0b725ff8 | ||
|
|
15703d66fb | ||
|
|
c68beeaa51 | ||
|
|
5ef8868916 | ||
|
|
24488cc985 | ||
|
|
1c9faaa1e6 | ||
|
|
ac32875b14 | ||
|
|
07c1dd29e0 | ||
|
|
bd93233c34 | ||
|
|
20aec2fbcf | ||
|
|
a149139143 | ||
|
|
c857d1abb7 | ||
|
|
dde9da7006 | ||
|
|
d18a1970e5 | ||
|
|
66b9aeec17 | ||
|
|
ea301a3923 | ||
|
|
ced272a783 | ||
|
|
c9f320da31 | ||
|
|
025873e66b | ||
|
|
ecddc40aa5 | ||
|
|
cb13a02b75 | ||
|
|
5714a9a1d3 | ||
|
|
d0671c1682 | ||
|
|
88b3ac42bb | ||
|
|
4ecf3dec76 | ||
|
|
b4b70ca7e5 | ||
|
|
d3aa68df05 | ||
|
|
36aa0518ed | ||
|
|
b1c5692322 | ||
|
|
db24edf7d5 | ||
|
|
798a576d0b | ||
|
|
b49225fbf7 | ||
|
|
439cf82fcc | ||
|
|
7527bf4761 |
@@ -51,3 +51,6 @@ broker/config/git.properties
|
|||||||
distribution/src/main/resources/git.properties
|
distribution/src/main/resources/git.properties
|
||||||
broker/h2db
|
broker/h2db
|
||||||
broker/media
|
broker/media
|
||||||
|
common/target
|
||||||
|
server/target
|
||||||
|
sdk/target
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
<img src="http://static.wildfirechat.cn/wx_wfc_qrcode.jpg" width = 50% height = 50% />
|
<img src="http://static.wildfirechat.cn/wx_wfc_qrcode.jpg" width = 50% height = 50% />
|
||||||
|
|
||||||
|
> 强烈建议关注我们的公众号。我们有新版本发布或者有重大更新会通过公众号通知大家,另外我们也会不定期的发布一些关于野火IM的技术介绍。
|
||||||
|
|
||||||
#### 体验Demo
|
#### 体验Demo
|
||||||
我们提供了体验demo,请使用微信扫码下载安装体验
|
我们提供了体验demo,请使用微信扫码下载安装体验
|
||||||
|
|
||||||
@@ -59,6 +61,12 @@
|
|||||||
## 编译
|
## 编译
|
||||||
在安装JDK1.8以上及maven的前提下,在命令行中执行```mvn clean compile package```,生成的目标文件在```./distribution/target/distribution-xxxx-bundle-tar.tar.gz```
|
在安装JDK1.8以上及maven的前提下,在命令行中执行```mvn clean compile package```,生成的目标文件在```./distribution/target/distribution-xxxx-bundle-tar.tar.gz```
|
||||||
|
|
||||||
|
## 捐赠者名单
|
||||||
|
|
||||||
|
| 捐赠者 | 商标 | 金额 | 简介 |
|
||||||
|
| ----- | ---- | -------- | --- |
|
||||||
|
| [SAMOS](http://samos.io) |  | 每月2000¥ | 一站式区块链解决方案服务商(http://samos.io) |
|
||||||
|
|
||||||
## 特别感谢
|
## 特别感谢
|
||||||
1. [moquette](https://github.com/moquette-io/moquette) 本项目是基于此项目二次开发而来,处理MQTT相关业务。
|
1. [moquette](https://github.com/moquette-io/moquette) 本项目是基于此项目二次开发而来,处理MQTT相关业务。
|
||||||
2. [loServer](https://github.com/looly/loServer) 本项目使用loServer处理HTTP相关业务。
|
2. [loServer](https://github.com/looly/loServer) 本项目使用loServer处理HTTP相关业务。
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#*********************************************************************
|
#*********************************************************************
|
||||||
#服务器的接入IP。给客户端提供是${server.ip}和${http_port}。
|
#服务器的接入IP。给客户端提供是${server.ip}和${http_port}。
|
||||||
#客户端会从${http_port}端口获取到长链接端口。
|
#客户端会从${http_port}端口获取到长链接端口。
|
||||||
server.ip 0.0.0.0
|
server.ip 192.168.1.100
|
||||||
|
|
||||||
##原生客户端长链接端口
|
##原生客户端长链接端口
|
||||||
port 1883
|
port 1883
|
||||||
@@ -27,7 +27,7 @@ host 0.0.0.0
|
|||||||
local_port 80
|
local_port 80
|
||||||
|
|
||||||
##是否使用内置DB。0使用mysql;1使用h2db
|
##是否使用内置DB。0使用mysql;1使用h2db
|
||||||
embed.db 1
|
embed.db 0
|
||||||
|
|
||||||
##服务器管理接口密钥
|
##服务器管理接口密钥
|
||||||
http.admin.secret_key 123456
|
http.admin.secret_key 123456
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
insert into t_user (`_uid`,`_name`,`_display_name`,`_type`,`_dt`) values ('admin','admin','系统管理员',3,1);
|
||||||
|
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE t_user_session MODIFY _token VARCHAR(240) DEFAULT NULL;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
alter table `t_group` add column `_mute` tinyint NOT NULL DEFAULT 0;
|
||||||
|
alter table `t_group` add column `_join_type` tinyint NOT NULL DEFAULT 0;
|
||||||
|
alter table `t_group` add column `_private_chat` tinyint NOT NULL DEFAULT 0;
|
||||||
|
alter table `t_group` add column `_searchable` tinyint NOT NULL DEFAULT 0;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table t_user add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||||
|
alter table t_group add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alter table `t_messages` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
DROP TABLE IF EXISTS `t_sensitive_messages`;
|
||||||
|
CREATE TABLE `t_sensitive_messages` (
|
||||||
|
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
`_mid` bigint(20) NOT NULL,
|
||||||
|
`_from` varchar(64) NOT NULL,
|
||||||
|
`_type` tinyint NOT NULL DEFAULT 0,
|
||||||
|
`_target` varchar(64) NOT NULL,
|
||||||
|
`_line` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`_data` BLOB NOT NULL,
|
||||||
|
`_searchable_key` TEXT DEFAULT NULL,
|
||||||
|
`_dt` DATETIME NOT NULL DEFAULT NOW(),
|
||||||
|
`_content_type` int(11) NOT NULL DEFAULT 0,
|
||||||
|
UNIQUE INDEX `sensitive_message_uid_index` (`_mid` ASC)
|
||||||
|
);
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
insert into t_user (`_uid`,`_name`,`_display_name`,`_type`,`_dt`) values ('admin','admin','系统管理员',3,1);
|
||||||
|
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE t_user_session MODIFY _token VARCHAR(240) DEFAULT NULL;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
alter table `t_group` add column `_mute` tinyint NOT NULL DEFAULT 0;
|
||||||
|
alter table `t_group` add column `_join_type` tinyint NOT NULL DEFAULT 0;
|
||||||
|
alter table `t_group` add column `_private_chat` tinyint NOT NULL DEFAULT 0;
|
||||||
|
alter table `t_group` add column `_searchable` tinyint NOT NULL DEFAULT 0;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table t_user add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||||
|
alter table t_group add column `_createTime` TIMESTAMP default CURRENT_TIMESTAMP;
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
alter table `t_messages_0` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_1` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_2` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_3` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_4` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_5` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_6` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_7` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_8` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_9` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_10` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_11` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_12` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_13` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_14` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_15` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_16` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_17` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_18` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_19` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_20` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_21` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_22` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_23` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_24` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_25` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_26` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_27` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_28` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_29` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_30` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_31` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_32` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_33` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_34` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
|
alter table `t_messages_35` add column `_content_type` int(11) NOT NULL DEFAULT '0';
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
DROP TABLE IF EXISTS `t_sensitive_messages`;
|
||||||
|
CREATE TABLE `t_sensitive_messages` (
|
||||||
|
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
`_mid` bigint(20) NOT NULL,
|
||||||
|
`_from` varchar(64) NOT NULL,
|
||||||
|
`_type` tinyint NOT NULL DEFAULT 0,
|
||||||
|
`_target` varchar(64) NOT NULL,
|
||||||
|
`_line` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`_data` BLOB NOT NULL,
|
||||||
|
`_searchable_key` TEXT DEFAULT NULL,
|
||||||
|
`_dt` DATETIME NOT NULL,
|
||||||
|
`_content_type` int(11) NOT NULL DEFAULT '0',
|
||||||
|
INDEX `message_uid_index` (`_mid` DESC)
|
||||||
|
)
|
||||||
|
ENGINE = InnoDB
|
||||||
|
DEFAULT CHARACTER SET = utf8mb4
|
||||||
|
COLLATE = utf8mb4_unicode_ci;
|
||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<relativePath>../</relativePath>
|
<relativePath>../</relativePath>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.21</version>
|
<version>0.23</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>moquette-broker</artifactId>
|
<artifactId>moquette-broker</artifactId>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class RouteAction extends Action {
|
|||||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
|
||||||
response.setContentType("application/octet-stream");
|
response.setContentType("application/octet-stream");
|
||||||
FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest();
|
FullHttpRequest fullHttpRequest = (FullHttpRequest) request.getNettyRequest();
|
||||||
boolean b = false;
|
boolean b = false;
|
||||||
if ("web".equalsIgnoreCase(fullHttpRequest.headers().get("p"))) {
|
if ("web".equalsIgnoreCase(fullHttpRequest.headers().get("p"))) {
|
||||||
b = true;
|
b = true;
|
||||||
@@ -144,10 +144,14 @@ public class RouteAction extends Action {
|
|||||||
|
|
||||||
private void sendResponse(Response response, ErrorCode errorCode, byte[] contents, boolean base64Response) {
|
private void sendResponse(Response response, ErrorCode errorCode, byte[] contents, boolean base64Response) {
|
||||||
response.setStatus(HttpResponseStatus.OK);
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
if(contents == null) {
|
if (contents == null) {
|
||||||
ByteBuf ackPayload = Unpooled.buffer();
|
ByteBuf ackPayload = Unpooled.buffer();
|
||||||
ackPayload.ensureWritable(1).writeByte(errorCode.getCode());
|
ackPayload.ensureWritable(1).writeByte(errorCode.getCode());
|
||||||
response.setContent(ackPayload);
|
contents = ackPayload.array();
|
||||||
|
}
|
||||||
|
if (base64Response) {
|
||||||
|
byte[] base64Data = Base64.getEncoder().encode(contents);
|
||||||
|
response.setContent(base64Data);
|
||||||
} else {
|
} else {
|
||||||
response.setContent(contents);
|
response.setContent(contents);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import cn.wildfirechat.pojos.OutputLoginData;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import win.liyufan.im.GitRepositoryState;
|
import win.liyufan.im.GitRepositoryState;
|
||||||
|
import win.liyufan.im.Utility;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -32,7 +33,8 @@ public class VersionAction extends Action {
|
|||||||
response.setStatus(HttpResponseStatus.OK);
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response.setContent(new Gson().toJson(GitRepositoryState.getGitRepositoryState()));
|
|
||||||
|
response.setContent(Utility.formatJson(new Gson().toJson(GitRepositoryState.getGitRepositoryState())));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
response.setContent("{\"version\":\"unknown\"}");
|
response.setContent("{\"version\":\"unknown\"}");
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class BlockUserAction extends AdminAction {
|
|||||||
result = RestResult.resultOf(errorCode);
|
result = RestResult.resultOf(errorCode);
|
||||||
response.setContent(new Gson().toJson(result));
|
response.setContent(new Gson().toJson(result));
|
||||||
|
|
||||||
if (inputUserBlock.getStatus() != 0) {
|
if (inputUserBlock.getStatus() == 2) {
|
||||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.xiaoleilu.loServer.action.admin;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.wildfirechat.common.APIPath;
|
||||||
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
import cn.wildfirechat.pojos.BroadMessageData;
|
||||||
|
import cn.wildfirechat.pojos.BroadMessageResult;
|
||||||
|
import cn.wildfirechat.pojos.SendMessageData;
|
||||||
|
import cn.wildfirechat.pojos.SendMessageResult;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.hazelcast.util.StringUtil;
|
||||||
|
import com.xiaoleilu.loServer.RestResult;
|
||||||
|
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||||
|
import com.xiaoleilu.loServer.annotation.Route;
|
||||||
|
import com.xiaoleilu.loServer.handler.Request;
|
||||||
|
import com.xiaoleilu.loServer.handler.Response;
|
||||||
|
import io.moquette.persistence.RPCCenter;
|
||||||
|
import io.moquette.persistence.TargetEntry;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
import win.liyufan.im.IMTopic;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
@Route(APIPath.Msg_Broadcast)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class BroadcastMessageAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
BroadMessageData sendMessageData = getRequestBody(request.getNettyRequest(), BroadMessageData.class);
|
||||||
|
if (BroadMessageData.isValide(sendMessageData) && !StringUtil.isNullOrEmpty(sendMessageData.getSender())) {
|
||||||
|
RPCCenter.getInstance().sendRequest(sendMessageData.getSender(), null, IMTopic.BroadcastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), sendMessageData.getSender(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(byte[] result) {
|
||||||
|
ByteBuf byteBuf = Unpooled.buffer();
|
||||||
|
byteBuf.writeBytes(result);
|
||||||
|
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||||
|
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
long messageId = byteBuf.readLong();
|
||||||
|
long count = byteBuf.readLong();
|
||||||
|
sendResponse(response, null, new BroadMessageResult(messageId, count));
|
||||||
|
} else {
|
||||||
|
sendResponse(response, errorCode, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(ErrorCode errorCode) {
|
||||||
|
sendResponse(response, errorCode, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeout() {
|
||||||
|
sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Executor getResponseExecutor() {
|
||||||
|
return command -> {
|
||||||
|
ctx.executor().execute(command);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,10 +48,6 @@ public class CreateUserAction extends AdminAction {
|
|||||||
inputCreateUser.setUserId(messagesStore.getShortUUID());
|
inputCreateUser.setUserId(messagesStore.getShortUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputCreateUser.getPortrait() == null || inputCreateUser.getPortrait().length() == 0) {
|
|
||||||
inputCreateUser.setPortrait("https://avatars.io/gravatar/" + inputCreateUser.getUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
WFCMessage.User.Builder newUserBuilder = WFCMessage.User.newBuilder()
|
WFCMessage.User.Builder newUserBuilder = WFCMessage.User.newBuilder()
|
||||||
.setUid(StringUtil.isNullOrEmpty(inputCreateUser.getUserId()) ? "" : inputCreateUser.getUserId());
|
.setUid(StringUtil.isNullOrEmpty(inputCreateUser.getUserId()) ? "" : inputCreateUser.getUserId());
|
||||||
if (inputCreateUser.getName() != null)
|
if (inputCreateUser.getName() != null)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class AddGroupMember extends GroupHandler<WFCMessage.AddGroupMemberReques
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.AddGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.AddGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||||
ErrorCode errorCode = m_messagesStore.addGroupMembers(fromUser, request.getGroupId(), request.getAddedMemberList());
|
ErrorCode errorCode = m_messagesStore.addGroupMembers(fromUser, isAdmin, request.getGroupId(), request.getAddedMemberList());
|
||||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* 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.proto.ProtoConstants;
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
import com.hazelcast.util.StringUtil;
|
||||||
|
import io.moquette.BrokerConstants;
|
||||||
|
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import win.liyufan.im.IMTopic;
|
||||||
|
import win.liyufan.im.MessageShardingUtil;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static cn.wildfirechat.proto.ProtoConstants.ContentType.Text;
|
||||||
|
|
||||||
|
@Handler(value = IMTopic.BroadcastMessageTopic)
|
||||||
|
public class BroadcastMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||||
|
@Override
|
||||||
|
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.Message message, Qos1PublishHandler.IMCallback callback) {
|
||||||
|
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
|
if (message != null) {
|
||||||
|
if (!isAdmin) { //only admin can broadcast message
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
|
long messageId = MessageShardingUtil.generateId();
|
||||||
|
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).setConversation(WFCMessage.Conversation.newBuilder().setTarget(fromUser).setLine(message.getConversation().getLine()).setType(ProtoConstants.ConversationType.ConversationType_Private).build()).build();
|
||||||
|
|
||||||
|
long count = saveAndBroadcast(fromUser, clientID, message);
|
||||||
|
ackPayload = ackPayload.capacity(20);
|
||||||
|
ackPayload.writeLong(messageId);
|
||||||
|
ackPayload.writeLong(count);
|
||||||
|
} else {
|
||||||
|
errorCode = ErrorCode.ERROR_CODE_INVALID_MESSAGE;
|
||||||
|
}
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
package io.moquette.imhandler;
|
package io.moquette.imhandler;
|
||||||
|
|
||||||
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -205,9 +206,7 @@ abstract public class IMHandler<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(errorCode != ErrorCode.ERROR_CODE_ASYNC_HANDLER) {
|
response(ackPayload, errorCode, callback);
|
||||||
response(ackPayload, errorCode, callback);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Handler {} preAction failure", this.getClass().getName());
|
LOG.error("Handler {} preAction failure", this.getClass().getName());
|
||||||
ByteBuf ackPayload = Unpooled.buffer(1);
|
ByteBuf ackPayload = Unpooled.buffer(1);
|
||||||
@@ -239,8 +238,16 @@ abstract public class IMHandler<T> {
|
|||||||
Set<String> notifyReceivers = new LinkedHashSet<>();
|
Set<String> notifyReceivers = new LinkedHashSet<>();
|
||||||
|
|
||||||
message = m_messagesStore.storeMessage(username, clientID, message);
|
message = m_messagesStore.storeMessage(username, clientID, message);
|
||||||
int pullType = m_messagesStore.getNotifyReceivers(username, message, notifyReceivers);
|
WFCMessage.Message.Builder messageBuilder = message.toBuilder();
|
||||||
this.publisher.publish2Receivers(message, notifyReceivers, clientID, pullType);
|
int pullType = m_messagesStore.getNotifyReceivers(username, messageBuilder, notifyReceivers);
|
||||||
return message.getMessageId();
|
this.publisher.publish2Receivers(messageBuilder.build(), notifyReceivers, clientID, pullType);
|
||||||
|
return notifyReceivers.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected long saveAndBroadcast(String username, String clientID, WFCMessage.Message message) {
|
||||||
|
Set<String> notifyReceivers = m_messagesStore.getAllEnds();
|
||||||
|
WFCMessage.Message updatedMessage = m_messagesStore.storeMessage(username, clientID, message);
|
||||||
|
mServer.getImBusinessScheduler().execute(() -> publisher.publish2Receivers(updatedMessage, notifyReceivers, clientID, ProtoConstants.PullType.Pull_Normal));
|
||||||
|
return notifyReceivers.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ import io.moquette.spi.impl.Qos1PublishHandler;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Name;
|
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Portrait;
|
|
||||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
|
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.*;
|
||||||
import static win.liyufan.im.IMTopic.ModifyGroupInfoTopic;
|
import static win.liyufan.im.IMTopic.ModifyGroupInfoTopic;
|
||||||
|
|
||||||
@Handler(value = ModifyGroupInfoTopic)
|
@Handler(value = ModifyGroupInfoTopic)
|
||||||
@@ -33,6 +32,14 @@ public class ModifyGroupInfoHandler extends GroupHandler<WFCMessage.ModifyGroupI
|
|||||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupNameNotifyContent();
|
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupNameNotifyContent();
|
||||||
} else if(request.getType() == Modify_Group_Portrait) {
|
} else if(request.getType() == Modify_Group_Portrait) {
|
||||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, "").getChangeGroupPortraitNotifyContent();
|
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, "").getChangeGroupPortraitNotifyContent();
|
||||||
|
} else if(request.getType() == Modify_Group_Mute) {
|
||||||
|
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupMuteNotifyContent();
|
||||||
|
} else if(request.getType() == Modify_Group_JoinType) {
|
||||||
|
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupJointypeNotifyContent();
|
||||||
|
} else if(request.getType() == Modify_Group_PrivateChat) {
|
||||||
|
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupPrivatechatNotifyContent();
|
||||||
|
} else if(request.getType() == Modify_Group_Searchable) {
|
||||||
|
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupSearchableNotifyContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class RecallMessageHandler extends IMHandler<WFCMessage.INT64Buf> {
|
|||||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_messagesStore.getNotifyReceivers(fromUser, message, notifyReceivers);
|
m_messagesStore.getNotifyReceivers(fromUser, message.toBuilder(), notifyReceivers);
|
||||||
this.publisher.publishRecall2Receivers(int64Buf.getId(), fromUser, notifyReceivers, clientID);
|
this.publisher.publishRecall2Receivers(int64Buf.getId(), fromUser, notifyReceivers, clientID);
|
||||||
|
|
||||||
return errorCode;
|
return errorCode;
|
||||||
|
|||||||
@@ -58,14 +58,19 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group && !m_messagesStore.isMemberInGroup(fromUser, message.getConversation().getTarget())) {
|
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) {
|
||||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
errorCode = m_messagesStore.canSendMessageInGroup(fromUser, message.getConversation().getTarget());
|
||||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group && m_messagesStore.isForbiddenInGroup(fromUser, message.getConversation().getTarget())) {
|
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
return errorCode;
|
||||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom && !m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) {
|
}
|
||||||
return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM;
|
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom) {
|
||||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel && !m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) {
|
if(!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) {
|
||||||
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
|
return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM;
|
||||||
|
}
|
||||||
|
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
|
||||||
|
if(!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +86,7 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
|||||||
if (!isAdmin && message.getContent().getType() == Text) {
|
if (!isAdmin && message.getContent().getType() == Text) {
|
||||||
Set<String> matched = m_messagesStore.handleSensitiveWord(message.getContent().getSearchableContent());
|
Set<String> matched = m_messagesStore.handleSensitiveWord(message.getContent().getSearchableContent());
|
||||||
if (matched != null && !matched.isEmpty()) {
|
if (matched != null && !matched.isEmpty()) {
|
||||||
|
m_messagesStore.storeSensitiveMessage(message);
|
||||||
if (mSensitiveType == 0) {
|
if (mSensitiveType == 0) {
|
||||||
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||||
} else if(mSensitiveType == 1) {
|
} else if(mSensitiveType == 1) {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* 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.WFCMessage;
|
||||||
|
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import win.liyufan.im.IMTopic;
|
||||||
|
|
||||||
|
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
|
|
||||||
|
@Handler(IMTopic.SetGroupManagerTopic)
|
||||||
|
public class SetGroupManagerHandler extends GroupHandler<WFCMessage.SetGroupManagerRequest> {
|
||||||
|
@Override
|
||||||
|
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.SetGroupManagerRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||||
|
ErrorCode errorCode = m_messagesStore.setGroupManager(fromUser, request.getGroupId(), request.getType(), request.getUserIdList(), isAdmin);
|
||||||
|
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||||
|
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||||
|
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||||
|
} else {
|
||||||
|
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getType() + "", request.getUserIdList()).getSetGroupManagerNotifyContent();
|
||||||
|
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ public class UploadDeviceTokenHandler extends IMHandler<WFCMessage.UploadDeviceT
|
|||||||
session.setAppName(request.getAppName());
|
session.setAppName(request.getAppName());
|
||||||
if (request.getPlatform() == ProtoConstants.Platform.Platform_iOS && request.getPushType() == 2) {
|
if (request.getPlatform() == ProtoConstants.Platform.Platform_iOS && request.getPushType() == 2) {
|
||||||
session.setVoipDeviceToken(request.getDeviceToken());
|
session.setVoipDeviceToken(request.getDeviceToken());
|
||||||
session.setPushType(0);//如果有voip token,肯定是生产环境的推送
|
// session.setPushType(0);//如果有voip token,肯定是生产环境的推送
|
||||||
m_sessionsStore.updateSessionToken(session, true);
|
m_sessionsStore.updateSessionToken(session, true);
|
||||||
} else {
|
} else {
|
||||||
session.setDeviceToken(request.getDeviceToken());
|
session.setDeviceToken(request.getDeviceToken());
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ public class DatabaseStore {
|
|||||||
", `_extra`" +
|
", `_extra`" +
|
||||||
", `_dt` from t_user";
|
", `_dt` from t_user";
|
||||||
if (buzzy) {
|
if (buzzy) {
|
||||||
sql += " where `_display_name` like ?";
|
sql += " where (`_display_name` like ? or `_name` = ? or `_mobile` = ?) ";
|
||||||
} else {
|
} else {
|
||||||
sql += " where `_display_name` = ?";
|
sql += " where (`_display_name` = ? or `_name` = ? or `_mobile` = ?) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += " and _type <> 2"; //can search normal user(0) and robot(1), can not search things
|
sql += " and _type <> 2"; //can search normal user(0) and robot(1), can not search things
|
||||||
@@ -118,6 +118,8 @@ public class DatabaseStore {
|
|||||||
} else {
|
} else {
|
||||||
statement.setString(index++, keyword);
|
statement.setString(index++, keyword);
|
||||||
}
|
}
|
||||||
|
statement.setString(index++, keyword);
|
||||||
|
statement.setString(index++, keyword);
|
||||||
|
|
||||||
rs = statement.executeQuery();
|
rs = statement.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@@ -382,11 +384,12 @@ public class DatabaseStore {
|
|||||||
try {
|
try {
|
||||||
connection = DBUtil.getConnection();
|
connection = DBUtil.getConnection();
|
||||||
String sql = "insert into " + MessageShardingUtil.getMessageTable(message.getMessageId()) +
|
String sql = "insert into " + MessageShardingUtil.getMessageTable(message.getMessageId()) +
|
||||||
" (`_mid`, `_from`, `_type`, `_target`, `_line`, `_data`, `_searchable_key`, `_dt`) values(?, ?, ?, ?, ?, ?, ?, ?)" +
|
" (`_mid`, `_from`, `_type`, `_target`, `_line`, `_data`, `_searchable_key`, `_dt`, `_content_type`) values(?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||||
" ON DUPLICATE KEY UPDATE " +
|
" ON DUPLICATE KEY UPDATE " +
|
||||||
"`_data` = ?," +
|
"`_data` = ?," +
|
||||||
"`_searchable_key` = ?," +
|
"`_searchable_key` = ?," +
|
||||||
"`_dt` = ?";
|
"`_dt` = ?," +
|
||||||
|
"`_content_type` = ?";
|
||||||
|
|
||||||
String searchableContent = message.getContent().getSearchableContent() == null ? "" : message.getContent().getSearchableContent();
|
String searchableContent = message.getContent().getSearchableContent() == null ? "" : message.getContent().getSearchableContent();
|
||||||
|
|
||||||
@@ -402,10 +405,63 @@ public class DatabaseStore {
|
|||||||
statement.setBlob(index++, blob);
|
statement.setBlob(index++, blob);
|
||||||
statement.setString(index++, searchableContent);
|
statement.setString(index++, searchableContent);
|
||||||
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||||
|
statement.setInt(index++, message.getContent().getType());
|
||||||
|
|
||||||
statement.setBlob(index++, blob);
|
statement.setBlob(index++, blob);
|
||||||
statement.setString(index++, searchableContent);
|
statement.setString(index++, searchableContent);
|
||||||
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||||
|
statement.setInt(index++, message.getContent().getType());
|
||||||
|
|
||||||
|
int count = statement.executeUpdate();
|
||||||
|
LOG.info("Update rows {}", count);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
Utility.printExecption(LOG, e);
|
||||||
|
} finally {
|
||||||
|
DBUtil.closeDB(connection, statement);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void persistSensitiveMessage(final WFCMessage.Message message) {
|
||||||
|
if(message.getContent().getPersistFlag() == Transparent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mScheduler.execute(()-> {
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
try {
|
||||||
|
connection = DBUtil.getConnection();
|
||||||
|
String sql = "insert into " + "t_sensitive_messages" +
|
||||||
|
" (`_mid`, `_from`, `_type`, `_target`, `_line`, `_data`, `_searchable_key`, `_dt`, `_content_type`) values(?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||||
|
" ON DUPLICATE KEY UPDATE " +
|
||||||
|
"`_data` = ?," +
|
||||||
|
"`_searchable_key` = ?," +
|
||||||
|
"`_dt` = ?," +
|
||||||
|
"`_content_type` = ?";
|
||||||
|
|
||||||
|
String searchableContent = message.getContent().getSearchableContent() == null ? "" : message.getContent().getSearchableContent();
|
||||||
|
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
int index = 1;
|
||||||
|
statement.setLong(index++, message.getMessageId());
|
||||||
|
statement.setString(index++, message.getFromUser());
|
||||||
|
statement.setInt(index++, message.getConversation().getType());
|
||||||
|
statement.setString(index++, message.getConversation().getTarget());
|
||||||
|
statement.setInt(index++, message.getConversation().getLine());
|
||||||
|
Blob blob = connection.createBlob();
|
||||||
|
blob.setBytes(1, message.getContent().toByteArray());
|
||||||
|
statement.setBlob(index++, blob);
|
||||||
|
statement.setString(index++, searchableContent);
|
||||||
|
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||||
|
statement.setInt(index++, message.getContent().getType());
|
||||||
|
|
||||||
|
statement.setBlob(index++, blob);
|
||||||
|
statement.setString(index++, searchableContent);
|
||||||
|
statement.setTimestamp(index++, new Timestamp(message.getServerTimestamp()));
|
||||||
|
statement.setInt(index++, message.getContent().getType());
|
||||||
|
|
||||||
int count = statement.executeUpdate();
|
int count = statement.executeUpdate();
|
||||||
LOG.info("Update rows {}", count);
|
LOG.info("Update rows {}", count);
|
||||||
@@ -737,7 +793,11 @@ public class DatabaseStore {
|
|||||||
", `_extra`" +
|
", `_extra`" +
|
||||||
", `_dt`" +
|
", `_dt`" +
|
||||||
", `_member_count`" +
|
", `_member_count`" +
|
||||||
", `_member_dt`) values(?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
", `_mute`" +
|
||||||
|
", `_join_type`" +
|
||||||
|
", `_private_chat`" +
|
||||||
|
", `_searchable`" +
|
||||||
|
", `_member_dt`) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" +
|
||||||
" ON DUPLICATE KEY UPDATE " +
|
" ON DUPLICATE KEY UPDATE " +
|
||||||
"`_name` = ?," +
|
"`_name` = ?," +
|
||||||
"`_portrait` = ?," +
|
"`_portrait` = ?," +
|
||||||
@@ -746,6 +806,10 @@ public class DatabaseStore {
|
|||||||
"`_extra` = ?," +
|
"`_extra` = ?," +
|
||||||
"`_dt` = ?," +
|
"`_dt` = ?," +
|
||||||
"`_member_count` = ?," +
|
"`_member_count` = ?," +
|
||||||
|
"`_mute` = ?" +
|
||||||
|
", `_join_type` = ?" +
|
||||||
|
", `_private_chat` = ?" +
|
||||||
|
", `_searchable` = ?, " +
|
||||||
"`_member_dt` = ?";
|
"`_member_dt` = ?";
|
||||||
|
|
||||||
|
|
||||||
@@ -760,6 +824,10 @@ public class DatabaseStore {
|
|||||||
statement.setString(index++, groupInfo.getExtra());
|
statement.setString(index++, groupInfo.getExtra());
|
||||||
statement.setLong(index++, groupInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
statement.setLong(index++, groupInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||||
statement.setInt(index++, groupInfo.getMemberCount());
|
statement.setInt(index++, groupInfo.getMemberCount());
|
||||||
|
statement.setInt(index++, groupInfo.getMute());
|
||||||
|
statement.setInt(index++, groupInfo.getJoinType());
|
||||||
|
statement.setInt(index++, groupInfo.getPrivateChat());
|
||||||
|
statement.setInt(index++, groupInfo.getSearchable());
|
||||||
statement.setLong(index++, groupInfo.getMemberUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
statement.setLong(index++, groupInfo.getMemberUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||||
|
|
||||||
statement.setString(index++, groupInfo.getName());
|
statement.setString(index++, groupInfo.getName());
|
||||||
@@ -769,6 +837,10 @@ public class DatabaseStore {
|
|||||||
statement.setString(index++, groupInfo.getExtra());
|
statement.setString(index++, groupInfo.getExtra());
|
||||||
statement.setLong(index++, groupInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
statement.setLong(index++, groupInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||||
statement.setInt(index++, groupInfo.getMemberCount());
|
statement.setInt(index++, groupInfo.getMemberCount());
|
||||||
|
statement.setInt(index++, groupInfo.getMute());
|
||||||
|
statement.setInt(index++, groupInfo.getJoinType());
|
||||||
|
statement.setInt(index++, groupInfo.getPrivateChat());
|
||||||
|
statement.setInt(index++, groupInfo.getSearchable());
|
||||||
statement.setLong(index++, groupInfo.getMemberUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
statement.setLong(index++, groupInfo.getMemberUpdateDt() == 0 ? System.currentTimeMillis() : groupInfo.getUpdateDt());
|
||||||
int count = statement.executeUpdate();
|
int count = statement.executeUpdate();
|
||||||
LOG.info("Update rows {}", count);
|
LOG.info("Update rows {}", count);
|
||||||
@@ -1099,6 +1171,10 @@ public class DatabaseStore {
|
|||||||
", `_dt`" +
|
", `_dt`" +
|
||||||
", `_member_count`" +
|
", `_member_count`" +
|
||||||
", `_member_dt`" +
|
", `_member_dt`" +
|
||||||
|
", `_mute`" +
|
||||||
|
", `_join_type`" +
|
||||||
|
", `_private_chat`" +
|
||||||
|
", `_searchable`" +
|
||||||
" from t_group where `_gid` = ?";
|
" from t_group where `_gid` = ?";
|
||||||
|
|
||||||
statement = connection.prepareStatement(sql);
|
statement = connection.prepareStatement(sql);
|
||||||
@@ -1134,18 +1210,27 @@ public class DatabaseStore {
|
|||||||
strValue = (strValue == null ? "" : strValue);
|
strValue = (strValue == null ? "" : strValue);
|
||||||
builder.setExtra(strValue);
|
builder.setExtra(strValue);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long longValue = rs.getLong(index++);
|
long longValue = rs.getLong(index++);
|
||||||
builder.setUpdateDt(longValue);
|
builder.setUpdateDt(longValue);
|
||||||
|
|
||||||
|
|
||||||
intValue = rs.getInt(index++);
|
intValue = rs.getInt(index++);
|
||||||
builder.setMemberCount(intValue);
|
builder.setMemberCount(intValue);
|
||||||
|
|
||||||
longValue = rs.getLong(index++);
|
longValue = rs.getLong(index++);
|
||||||
builder.setMemberUpdateDt(longValue);
|
builder.setMemberUpdateDt(longValue);
|
||||||
|
|
||||||
|
intValue = rs.getInt(index++);
|
||||||
|
builder.setMute(intValue);
|
||||||
|
|
||||||
|
intValue = rs.getInt(index++);
|
||||||
|
builder.setJoinType(intValue);
|
||||||
|
|
||||||
|
intValue = rs.getInt(index++);
|
||||||
|
builder.setPrivateChat(intValue);
|
||||||
|
|
||||||
|
intValue = rs.getInt(index++);
|
||||||
|
builder.setSearchable(intValue);
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -1567,6 +1652,27 @@ public class DatabaseStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteUserStatus(String userId) {
|
||||||
|
mScheduler.execute(()->{
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
try {
|
||||||
|
connection = DBUtil.getConnection();
|
||||||
|
String sql = "delete from t_user_status where _uid = ?";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setString(1, userId);
|
||||||
|
int count = statement.executeUpdate();
|
||||||
|
LOG.info("Update rows {}", count);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
Utility.printExecption(LOG, e);
|
||||||
|
} finally {
|
||||||
|
DBUtil.closeDB(connection, statement);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void updateUserStatus(String userId, int status) {
|
void updateUserStatus(String userId, int status) {
|
||||||
mScheduler.execute(()->{
|
mScheduler.execute(()->{
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
@@ -1774,6 +1880,33 @@ public class DatabaseStore {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<String> getAllEnds() {
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
connection = DBUtil.getConnection();
|
||||||
|
String sql = "select distinct(`_uid`) from t_user_session";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
rs = statement.executeQuery();
|
||||||
|
Set<String> out = new HashSet<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
String uid = rs.getString(1);
|
||||||
|
out.add(uid);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
Utility.printExecption(LOG, e);
|
||||||
|
} finally {
|
||||||
|
DBUtil.closeDB(connection, statement, rs);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
List<FriendData> getPersistFriends(String userId) {
|
List<FriendData> getPersistFriends(String userId) {
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
|
|||||||
@@ -49,10 +49,9 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
|
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.ChannelStatus.Channel_Status_Destoryed;
|
import static cn.wildfirechat.proto.ProtoConstants.ChannelStatus.Channel_Status_Destoryed;
|
||||||
|
import static cn.wildfirechat.proto.ProtoConstants.GroupMemberType.*;
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyChannelInfoType.*;
|
import static cn.wildfirechat.proto.ProtoConstants.ModifyChannelInfoType.*;
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Extra;
|
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.*;
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Name;
|
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.ModifyGroupInfoType.Modify_Group_Portrait;
|
|
||||||
import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
|
import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
|
||||||
import static io.moquette.BrokerConstants.*;
|
import static io.moquette.BrokerConstants.*;
|
||||||
import static io.moquette.server.Constants.MAX_CHATROOM_MESSAGE_QUEUE;
|
import static io.moquette.server.Constants.MAX_CHATROOM_MESSAGE_QUEUE;
|
||||||
@@ -170,7 +169,14 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNotifyReceivers(String fromUser, WFCMessage.Message message, Set<String> notifyReceivers) {
|
public void storeSensitiveMessage(WFCMessage.Message message) {
|
||||||
|
databaseStore.persistSensitiveMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNotifyReceivers(String fromUser, WFCMessage.Message.Builder messageBuilder, Set<String> notifyReceivers) {
|
||||||
|
WFCMessage.Message message = messageBuilder.build();
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
int type = message.getConversation().getType();
|
int type = message.getConversation().getType();
|
||||||
|
|
||||||
@@ -190,7 +196,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
||||||
for (WFCMessage.GroupMember member : members) {
|
for (WFCMessage.GroupMember member : members) {
|
||||||
if (member.getType() != ProtoConstants.GroupMemberType.GroupMemberType_Removed) {
|
if (member.getType() != GroupMemberType_Removed) {
|
||||||
notifyReceivers.add(member.getMemberId());
|
notifyReceivers.add(member.getMemberId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,6 +251,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return pullType;
|
return pullType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getAllEnds() {
|
||||||
|
return databaseStore.getAllEnds();
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType) {
|
public WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType) {
|
||||||
WFCMessage.PullMessageResult.Builder builder = WFCMessage.PullMessageResult.newBuilder();
|
WFCMessage.PullMessageResult.Builder builder = WFCMessage.PullMessageResult.newBuilder();
|
||||||
@@ -315,9 +325,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
long targetMessageId = entry.getValue();
|
long targetMessageId = entry.getValue();
|
||||||
|
|
||||||
MessageBundle bundle = mIMap.get(targetMessageId);
|
MessageBundle bundle = mIMap.get(targetMessageId);
|
||||||
if (bundle == null) {
|
|
||||||
bundle = databaseStore.getMessage(targetMessageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !user.equals(bundle.getFromUser())) {
|
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !user.equals(bundle.getFromUser())) {
|
||||||
@@ -407,10 +414,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
long targetMessageId = entry.getValue();
|
long targetMessageId = entry.getValue();
|
||||||
|
|
||||||
MessageBundle bundle = mIMap.get(targetMessageId);
|
MessageBundle bundle = mIMap.get(targetMessageId);
|
||||||
if (bundle == null) {
|
|
||||||
bundle = databaseStore.getMessage(targetMessageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !fromUser.equals(bundle.getFromUser())) {
|
if (exceptClientId == null || !exceptClientId.equals(bundle.getFromClientId()) || !fromUser.equals(bundle.getFromUser())) {
|
||||||
size += bundle.getMessage().getSerializedSize();
|
size += bundle.getMessage().getSerializedSize();
|
||||||
@@ -599,19 +602,25 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
mIMap.put(groupId, groupInfo);
|
mIMap.put(groupId, groupInfo);
|
||||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||||
|
|
||||||
|
List<WFCMessage.GroupMember> updatedMemberList = new ArrayList<>();
|
||||||
for (WFCMessage.GroupMember member : memberList) {
|
for (WFCMessage.GroupMember member : memberList) {
|
||||||
member = member.toBuilder().setUpdateDt(dt).build();
|
if (member.getMemberId().equals(groupInfo.getOwner())) {
|
||||||
|
member = member.toBuilder().setUpdateDt(dt).setType(ProtoConstants.GroupMemberType.GroupMemberType_Owner).build();
|
||||||
|
} else {
|
||||||
|
member = member.toBuilder().setUpdateDt(dt).build();
|
||||||
|
}
|
||||||
groupMembers.put(groupId, member);
|
groupMembers.put(groupId, member);
|
||||||
|
updatedMemberList.add(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
databaseStore.persistGroupMember(groupId, memberList);
|
databaseStore.persistGroupMember(groupId, updatedMemberList);
|
||||||
|
|
||||||
return groupInfo;
|
return groupInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode addGroupMembers(String operator, String groupId, List<WFCMessage.GroupMember> memberList) {
|
public ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupId, List<WFCMessage.GroupMember> memberList) {
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||||
|
|
||||||
@@ -625,6 +634,22 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
|
|
||||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||||
|
|
||||||
|
if (!isAdmin) {
|
||||||
|
boolean isMember = false;
|
||||||
|
for (WFCMessage.GroupMember member : memberList) {
|
||||||
|
if (member.getType() == GroupMemberType_Removed) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||||
|
} else if(member.getType() == GroupMemberType_Silent) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||||
|
}
|
||||||
|
isMember = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!isMember) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long updateDt = System.currentTimeMillis();
|
long updateDt = System.currentTimeMillis();
|
||||||
|
|
||||||
List<WFCMessage.GroupMember> tmp = new ArrayList<>();
|
List<WFCMessage.GroupMember> tmp = new ArrayList<>();
|
||||||
@@ -648,7 +673,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (WFCMessage.GroupMember member : groupMembers.get(groupId)) {
|
for (WFCMessage.GroupMember member : groupMembers.get(groupId)) {
|
||||||
if (member.getType() != ProtoConstants.GroupMemberType.GroupMemberType_Removed) {
|
if (member.getType() != GroupMemberType_Removed) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -684,7 +709,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
boolean removed = groupMembers.remove(groupId, member);
|
boolean removed = groupMembers.remove(groupId, member);
|
||||||
if (removed) {
|
if (removed) {
|
||||||
removeCount++;
|
removeCount++;
|
||||||
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
member = member.toBuilder().setType(GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||||
groupMembers.put(groupId, member);
|
groupMembers.put(groupId, member);
|
||||||
list.add(member);
|
list.add(member);
|
||||||
}
|
}
|
||||||
@@ -735,7 +760,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
databaseStore.persistGroupMember(groupId, list);
|
databaseStore.persistGroupMember(groupId, list);
|
||||||
|
|
||||||
databaseStore.updateGroupMemberCountDt(groupId, groupInfo.getMemberCount()-1, updateDt);
|
databaseStore.updateGroupMemberCountDt(groupId, groupInfo.getMemberCount()-1, updateDt);
|
||||||
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
member = member.toBuilder().setType(GroupMemberType_Removed).setUpdateDt(updateDt).build();
|
||||||
groupMembers.put(groupId, member);
|
groupMembers.put(groupId, member);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -814,6 +839,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
newInfoBuilder.setPortrait(value);
|
newInfoBuilder.setPortrait(value);
|
||||||
else if(modifyType == Modify_Group_Extra)
|
else if(modifyType == Modify_Group_Extra)
|
||||||
newInfoBuilder.setExtra(value);
|
newInfoBuilder.setExtra(value);
|
||||||
|
else if(modifyType == Modify_Group_Mute)
|
||||||
|
newInfoBuilder.setMute(Integer.parseInt(value));
|
||||||
|
else if(modifyType == Modify_Group_JoinType)
|
||||||
|
newInfoBuilder.setJoinType(Integer.parseInt(value));
|
||||||
|
else if(modifyType == Modify_Group_PrivateChat)
|
||||||
|
newInfoBuilder.setPrivateChat(Integer.parseInt(value));
|
||||||
|
else if(modifyType == Modify_Group_Searchable)
|
||||||
|
newInfoBuilder.setSearchable(Integer.parseInt(value));
|
||||||
|
else
|
||||||
|
return ErrorCode.INVALID_PARAMETER;
|
||||||
|
|
||||||
|
|
||||||
newInfoBuilder.setUpdateDt(System.currentTimeMillis());
|
newInfoBuilder.setUpdateDt(System.currentTimeMillis());
|
||||||
@@ -938,6 +973,40 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ErrorCode setGroupManager(String operator, String groupId, int type, List<String> userList, boolean isAdmin) {
|
||||||
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
|
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||||
|
|
||||||
|
|
||||||
|
WFCMessage.GroupInfo groupInfo = mIMap.get(groupId);
|
||||||
|
|
||||||
|
if (groupInfo == null) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAdmin && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||||
|
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
long updateDt = System.currentTimeMillis();
|
||||||
|
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||||
|
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||||
|
for (WFCMessage.GroupMember member : members) {
|
||||||
|
if (userList.contains(member.getMemberId())) {
|
||||||
|
groupMembers.remove(groupId, member);
|
||||||
|
member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Manager).setUpdateDt(updateDt).build();
|
||||||
|
databaseStore.persistGroupMember(groupId, Arrays.asList(member));
|
||||||
|
groupMembers.put(groupId, member);
|
||||||
|
// userList.remove(member.getMemberId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mIMap.put(groupId, groupInfo.toBuilder().setUpdateDt(updateDt).setMemberUpdateDt(updateDt).build());
|
||||||
|
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMemberInGroup(String memberId, String groupId) {
|
public boolean isMemberInGroup(String memberId, String groupId) {
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
@@ -947,7 +1016,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
|
|
||||||
for (WFCMessage.GroupMember member : members
|
for (WFCMessage.GroupMember member : members
|
||||||
) {
|
) {
|
||||||
if (member.getMemberId().equals(memberId) && member.getType() != ProtoConstants.GroupMemberType.GroupMemberType_Removed)
|
if (member.getMemberId().equals(memberId) && member.getType() != GroupMemberType_Removed)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -955,19 +1024,37 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isForbiddenInGroup(String memberId, String groupId) {
|
public ErrorCode canSendMessageInGroup(String memberId, String groupId) {
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||||
|
IMap<String, WFCMessage.GroupInfo> groups = hzInstance.getMap(GROUPS_MAP);
|
||||||
|
WFCMessage.GroupInfo groupInfo = groups.get(groupId);
|
||||||
|
boolean isMute = false;
|
||||||
|
if (groupInfo != null) {
|
||||||
|
isMute = groupInfo.getMute()>0;
|
||||||
|
}
|
||||||
|
|
||||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||||
|
|
||||||
for (WFCMessage.GroupMember member : members
|
for (WFCMessage.GroupMember member : members
|
||||||
) {
|
) {
|
||||||
if (member.getMemberId().equals(memberId) && member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Silent)
|
if (member.getMemberId().equals(memberId)) {
|
||||||
return true;
|
if (member.getType() == GroupMemberType_Silent) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMute && member.getType() != GroupMemberType_Manager && member.getType() != GroupMemberType_Owner) {
|
||||||
|
return ErrorCode.ERROR_CODE_GROUP_MUTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member.getMemberId().equals(memberId) && member.getType() != GroupMemberType_Removed) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -998,7 +1085,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
Collection<WFCMessage.GroupMember> members = groupMembers.get(message.getConversation().getTarget());
|
||||||
for (WFCMessage.GroupMember member : members) {
|
for (WFCMessage.GroupMember member : members) {
|
||||||
if (member.getMemberId().equals(operatorId)) {
|
if (member.getMemberId().equals(operatorId)) {
|
||||||
if (member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Manager || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Owner) {
|
if (member.getType() == GroupMemberType_Manager || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Owner) {
|
||||||
canRecall = true;
|
canRecall = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1161,7 +1248,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
} else {
|
} else {
|
||||||
mUserMap.put(userId, status);
|
mUserMap.put(userId, status);
|
||||||
}
|
}
|
||||||
databaseStore.updateUserStatus(userId, status);
|
|
||||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1691,6 +1777,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
if (friendData == null) {
|
if (friendData == null) {
|
||||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||||
}
|
}
|
||||||
|
friendsMap.remove(fromUser, friendData);
|
||||||
|
|
||||||
friendData.setAlias(alias);
|
friendData.setAlias(alias);
|
||||||
friendData.setTimestamp(System.currentTimeMillis());
|
friendData.setTimestamp(System.currentTimeMillis());
|
||||||
@@ -1867,7 +1954,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
if (entry.getScope() == request.getScope() && entry.getKey().equals(request.getKey())) {
|
if (entry.getScope() == request.getScope() && entry.getKey().equals(request.getKey())) {
|
||||||
userSettingMap.remove(userId, entry);
|
userSettingMap.remove(userId, entry);
|
||||||
userSettingMap.put(userId, settingEntry);
|
userSettingMap.put(userId, settingEntry);
|
||||||
return updateDt;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2111,10 +2198,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
MessageBundle bundle = mIMap.get(messageId);
|
MessageBundle bundle = mIMap.get(messageId);
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
return bundle.getMessage();
|
return bundle.getMessage();
|
||||||
} else {
|
|
||||||
bundle = databaseStore.getMessage(messageId);
|
|
||||||
if (bundle != null)
|
|
||||||
return bundle.getMessage();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import io.moquette.spi.ClientSession;
|
|||||||
import io.moquette.spi.IMessagesStore.StoredMessage;
|
import io.moquette.spi.IMessagesStore.StoredMessage;
|
||||||
import io.moquette.spi.ISessionsStore;
|
import io.moquette.spi.ISessionsStore;
|
||||||
|
|
||||||
|
import io.netty.handler.codec.mqtt.MqttVersion;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
@@ -49,6 +50,8 @@ public class MemorySessionStore implements ISessionsStore {
|
|||||||
|
|
||||||
private volatile int unReceivedMsgs;
|
private volatile int unReceivedMsgs;
|
||||||
|
|
||||||
|
private MqttVersion mqttVersion = MqttVersion.MQTT_3_1_1;
|
||||||
|
|
||||||
public long getLastActiveTime() {
|
public long getLastActiveTime() {
|
||||||
return lastActiveTime;
|
return lastActiveTime;
|
||||||
}
|
}
|
||||||
@@ -230,7 +233,13 @@ public class MemorySessionStore implements ISessionsStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public MqttVersion getMqttVersion() {
|
||||||
|
return mqttVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMqttVersion(MqttVersion mqttVersion) {
|
||||||
|
this.mqttVersion = mqttVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<String, Session> sessions = new ConcurrentHashMap<>();
|
private final Map<String, Session> sessions = new ConcurrentHashMap<>();
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class RPCCenter {
|
|||||||
info.future.cancel(true);
|
info.future.cancel(true);
|
||||||
if (info.callback != null) {
|
if (info.callback != null) {
|
||||||
info.callback.getResponseExecutor().execute(() -> {
|
info.callback.getResponseExecutor().execute(() -> {
|
||||||
if (errorCode == 0) {
|
if (errorCode == 0 || errorCode == ErrorCode.ERROR_CODE_SUCCESS_GZIPED.getCode()) {
|
||||||
info.callback.onSuccess(message);
|
info.callback.onSuccess(message);
|
||||||
} else {
|
} else {
|
||||||
info.callback.onError(ErrorCode.fromCode(errorCode));
|
info.callback.onError(ErrorCode.fromCode(errorCode));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class UserStatusLoader implements MapStore<String, Integer> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(String s) {
|
public void delete(String s) {
|
||||||
getDatabaseStore().deleteUser(s);
|
getDatabaseStore().deleteUserStatus(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -96,12 +96,14 @@ public interface IMessagesStore {
|
|||||||
|
|
||||||
DatabaseStore getDatabaseStore();
|
DatabaseStore getDatabaseStore();
|
||||||
WFCMessage.Message storeMessage(String fromUser, String fromClientId, WFCMessage.Message message);
|
WFCMessage.Message storeMessage(String fromUser, String fromClientId, WFCMessage.Message message);
|
||||||
int getNotifyReceivers(String fromUser, WFCMessage.Message message, Set<String> notifyReceivers);
|
void storeSensitiveMessage(WFCMessage.Message message);
|
||||||
|
int getNotifyReceivers(String fromUser, WFCMessage.Message.Builder message, Set<String> notifyReceivers);
|
||||||
|
Set<String> getAllEnds();
|
||||||
WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType);
|
WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType);
|
||||||
WFCMessage.PullMessageResult loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count);
|
WFCMessage.PullMessageResult loadRemoteMessages(String user, WFCMessage.Conversation conversation, long beforeUid, int count);
|
||||||
long insertUserMessages(String sender, int conversationType, String target, int line, int messageContentType, String userId, long messageId);
|
long insertUserMessages(String sender, int conversationType, String target, int line, int messageContentType, String userId, long messageId);
|
||||||
WFCMessage.GroupInfo createGroup(String operator, WFCMessage.GroupInfo groupInfo, List<WFCMessage.GroupMember> memberList);
|
WFCMessage.GroupInfo createGroup(String operator, WFCMessage.GroupInfo groupInfo, List<WFCMessage.GroupMember> memberList);
|
||||||
ErrorCode addGroupMembers(String operator, String groupId, List<WFCMessage.GroupMember> memberList);
|
ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupId, List<WFCMessage.GroupMember> memberList);
|
||||||
ErrorCode kickoffGroupMembers(String operator, String groupId, List<String> memberList);
|
ErrorCode kickoffGroupMembers(String operator, String groupId, List<String> memberList);
|
||||||
ErrorCode quitGroup(String operator, String groupId);
|
ErrorCode quitGroup(String operator, String groupId);
|
||||||
ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin);
|
ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin);
|
||||||
@@ -111,8 +113,9 @@ public interface IMessagesStore {
|
|||||||
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
||||||
ErrorCode getGroupMembers(String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
ErrorCode getGroupMembers(String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
||||||
ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin);
|
ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin);
|
||||||
|
ErrorCode setGroupManager(String operator, String groupId, int type, List<String> userList, boolean isAdmin);
|
||||||
boolean isMemberInGroup(String member, String groupId);
|
boolean isMemberInGroup(String member, String groupId);
|
||||||
boolean isForbiddenInGroup(String member, String groupId);
|
ErrorCode canSendMessageInGroup(String member, String groupId);
|
||||||
|
|
||||||
ErrorCode recallMessage(long messageUid, String operatorId);
|
ErrorCode recallMessage(long messageUid, String operatorId);
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ public class MessagesPublisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isSlient) {
|
if (isSlient) {
|
||||||
LOG.info("The conversation is slient");
|
LOG.info("Slient of user or conversation");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,8 @@ public class ProtocolProcessor {
|
|||||||
LOG.info("Processing CONNECT message. CId={}, username={}", clientId, payload.userName());
|
LOG.info("Processing CONNECT message. CId={}, username={}", clientId, payload.userName());
|
||||||
|
|
||||||
if (msg.variableHeader().version() != MqttVersion.MQTT_3_1.protocolLevel()
|
if (msg.variableHeader().version() != MqttVersion.MQTT_3_1.protocolLevel()
|
||||||
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()) {
|
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()
|
||||||
|
&& msg.variableHeader().version() != MqttVersion.Wildfire_1.protocolLevel()) {
|
||||||
MqttConnAckMessage badProto = connAck(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION);
|
MqttConnAckMessage badProto = connAck(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION);
|
||||||
|
|
||||||
LOG.error("MQTT protocol version is not valid. CId={}", clientId);
|
LOG.error("MQTT protocol version is not valid. CId={}", clientId);
|
||||||
@@ -162,7 +163,8 @@ public class ProtocolProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!login(channel, msg, clientId)) {
|
MqttVersion mqttVersion = MqttVersion.fromProtocolLevel(msg.variableHeader().version());
|
||||||
|
if (!login(channel, msg, clientId, mqttVersion)) {
|
||||||
channel.close();
|
channel.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -238,7 +240,7 @@ public class ProtocolProcessor {
|
|||||||
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
|
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
|
||||||
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader, new MqttConnectAckPayload(data));
|
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader, new MqttConnectAckPayload(data));
|
||||||
}
|
}
|
||||||
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId) {
|
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId, MqttVersion mqttVersion) {
|
||||||
// handle user authentication
|
// handle user authentication
|
||||||
if (msg.variableHeader().hasUserName()) {
|
if (msg.variableHeader().hasUserName()) {
|
||||||
int status = m_messagesStore.getUserStatus(msg.payload().userName());
|
int status = m_messagesStore.getUserStatus(msg.payload().userName());
|
||||||
@@ -269,6 +271,7 @@ public class ProtocolProcessor {
|
|||||||
failedCredentials(channel);
|
failedCredentials(channel);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
session.setMqttVersion(mqttVersion);
|
||||||
} else if (!this.allowAnonymous) {
|
} else if (!this.allowAnonymous) {
|
||||||
LOG.error("Client didn't supply any password and MQTT anonymous mode is disabled CId={}", clientId);
|
LOG.error("Client didn't supply any password and MQTT anonymous mode is disabled CId={}", clientId);
|
||||||
failedCredentials(channel);
|
failedCredentials(channel);
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
|||||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
||||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -39,6 +41,7 @@ import io.moquette.server.ConnectionDescriptor;
|
|||||||
import io.moquette.server.Server;
|
import io.moquette.server.Server;
|
||||||
import io.moquette.spi.ClientSession;
|
import io.moquette.spi.ClientSession;
|
||||||
import io.moquette.spi.impl.security.AES;
|
import io.moquette.spi.impl.security.AES;
|
||||||
|
import io.netty.handler.codec.mqtt.MqttVersion;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -114,7 +117,7 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
|||||||
byte[] response = new byte[ackPayload.readableBytes()];
|
byte[] response = new byte[ackPayload.readableBytes()];
|
||||||
ackPayload.readBytes(response);
|
ackPayload.readBytes(response);
|
||||||
ReferenceCountUtil.release(ackPayload);
|
ReferenceCountUtil.release(ackPayload);
|
||||||
RPCCenter.getInstance().sendResponse(ERROR_CODE_SUCCESS.getCode(), response, from, requestId);
|
RPCCenter.getInstance().sendResponse(errorCode.getCode(), response, from, requestId);
|
||||||
}
|
}
|
||||||
}, isAdmin);
|
}, isAdmin);
|
||||||
}
|
}
|
||||||
@@ -174,8 +177,23 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
|||||||
data = AES.AESEncrypt(data, "");
|
data = AES.AESEncrypt(data, "");
|
||||||
} else {
|
} else {
|
||||||
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
|
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
|
||||||
if (session != null && session.getUsername().equals(fromUser))
|
if (session != null && session.getUsername().equals(fromUser)) {
|
||||||
data = AES.AESEncrypt(data, session.getSecret());
|
if (data.length > 7*1024 && session.getMqttVersion() == MqttVersion.Wildfire_1) {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
GZIPOutputStream gzip;
|
||||||
|
try {
|
||||||
|
gzip = new GZIPOutputStream(out);
|
||||||
|
gzip.write(data);
|
||||||
|
gzip.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
data = out.toByteArray();
|
||||||
|
code = (byte)ErrorCode.ERROR_CODE_SUCCESS_GZIPED.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = AES.AESEncrypt(data, session.getSecret());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ackPayload.clear();
|
ackPayload.clear();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ final class MqttCodecUtil {
|
|||||||
return clientId != null && clientId.length() >= MIN_CLIENT_ID_LENGTH &&
|
return clientId != null && clientId.length() >= MIN_CLIENT_ID_LENGTH &&
|
||||||
clientId.length() <= MAX_CLIENT_ID_LENGTH;
|
clientId.length() <= MAX_CLIENT_ID_LENGTH;
|
||||||
}
|
}
|
||||||
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
|
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
|
||||||
// In 3.1.3.1 Client Identifier of MQTT 3.1.1 specification, The Server MAY allow ClientId’s
|
// In 3.1.3.1 Client Identifier of MQTT 3.1.1 specification, The Server MAY allow ClientId’s
|
||||||
// that contain more than 23 encoded bytes. And, The Server MAY allow zero-length ClientId.
|
// that contain more than 23 encoded bytes. And, The Server MAY allow zero-length ClientId.
|
||||||
return clientId != null;
|
return clientId != null;
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
|
|||||||
final int willQos = (b1 & 0x18) >> 3;
|
final int willQos = (b1 & 0x18) >> 3;
|
||||||
final boolean willFlag = (b1 & 0x04) == 0x04;
|
final boolean willFlag = (b1 & 0x04) == 0x04;
|
||||||
final boolean cleanSession = (b1 & 0x02) == 0x02;
|
final boolean cleanSession = (b1 & 0x02) == 0x02;
|
||||||
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
|
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
|
||||||
final boolean zeroReservedFlag = (b1 & 0x01) == 0x0;
|
final boolean zeroReservedFlag = (b1 & 0x01) == 0x0;
|
||||||
if (!zeroReservedFlag) {
|
if (!zeroReservedFlag) {
|
||||||
// MQTT v3.1.1: The Server MUST validate that the reserved flag in the CONNECT Control Packet is
|
// MQTT v3.1.1: The Server MUST validate that the reserved flag in the CONNECT Control Packet is
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ import io.netty.util.internal.ObjectUtil;
|
|||||||
*/
|
*/
|
||||||
public enum MqttVersion {
|
public enum MqttVersion {
|
||||||
MQTT_3_1("MQIsdp", (byte) 3),
|
MQTT_3_1("MQIsdp", (byte) 3),
|
||||||
MQTT_3_1_1("MQTT", (byte) 4);
|
MQTT_3_1_1("MQTT", (byte) 4),
|
||||||
|
Wildfire_1("MQTT", (byte) 5);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final byte level;
|
private final byte level;
|
||||||
@@ -52,11 +53,19 @@ public enum MqttVersion {
|
|||||||
if (mv.level == protocolLevel) {
|
if (mv.level == protocolLevel) {
|
||||||
return mv;
|
return mv;
|
||||||
} else {
|
} else {
|
||||||
throw new MqttUnacceptableProtocolVersionException(protocolName + " and " +
|
continue;
|
||||||
protocolLevel + " are not match");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new MqttUnacceptableProtocolVersionException(protocolName + "is unknown protocol name");
|
throw new MqttUnacceptableProtocolVersionException(protocolName + "is unknown protocol name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MqttVersion fromProtocolLevel(int protocolLevel) {
|
||||||
|
for (MqttVersion mv : values()) {
|
||||||
|
if (mv.level == (byte )protocolLevel) {
|
||||||
|
return mv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new MqttUnacceptableProtocolVersionException(protocolLevel + "is unknown protocol level");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
package win.liyufan.im;
|
package win.liyufan.im;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class GitRepositoryState {
|
public class GitRepositoryState {
|
||||||
@@ -64,7 +63,9 @@ public class GitRepositoryState {
|
|||||||
public static GitRepositoryState getGitRepositoryState() throws IOException {
|
public static GitRepositoryState getGitRepositoryState() throws IOException {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
try {
|
||||||
properties.load(new FileInputStream("config/git.properties"));
|
InputStream inputStream = new FileInputStream("config/git.properties");
|
||||||
|
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
|
properties.load(bf);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public interface IMTopic {
|
|||||||
String PullMessageTopic = "MP";
|
String PullMessageTopic = "MP";
|
||||||
String NotifyMessageTopic = "MN";
|
String NotifyMessageTopic = "MN";
|
||||||
String NotifyRecallMessageTopic = "RMN";
|
String NotifyRecallMessageTopic = "RMN";
|
||||||
|
String BroadcastMessageTopic = "MBC";
|
||||||
|
|
||||||
String GetUserSettingTopic = "UG";
|
String GetUserSettingTopic = "UG";
|
||||||
String PutUserSettingTopic = "UP";
|
String PutUserSettingTopic = "UP";
|
||||||
@@ -29,7 +30,7 @@ public interface IMTopic {
|
|||||||
String GetGroupInfoTopic = "GPGI";
|
String GetGroupInfoTopic = "GPGI";
|
||||||
String GetGroupMemberTopic = "GPGM";
|
String GetGroupMemberTopic = "GPGM";
|
||||||
String TransferGroupTopic = "GTG";
|
String TransferGroupTopic = "GTG";
|
||||||
|
String SetGroupManagerTopic = "GSM";
|
||||||
|
|
||||||
String GetUserInfoTopic = "UPUI";
|
String GetUserInfoTopic = "UPUI";
|
||||||
String ModifyMyInfoTopic = "MMI";
|
String ModifyMyInfoTopic = "MMI";
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ public class MessageBundle implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(WFCMessage.Message message) {
|
public void setMessage(WFCMessage.Message message) {
|
||||||
|
this.fromUser = message.getFromUser();
|
||||||
|
this.type = message.getConversation().getType();
|
||||||
|
this.targetId = message.getConversation().getTarget();
|
||||||
|
this.line = message.getConversation().getLine();
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.messageId = message.getMessageId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,4 +59,78 @@ public class Utility {
|
|||||||
|
|
||||||
return macAddressBuilder.toString();
|
return macAddressBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化
|
||||||
|
*
|
||||||
|
* @param jsonStr
|
||||||
|
* @return
|
||||||
|
* @author lizhgb
|
||||||
|
* @Date 2015-10-14 下午1:17:35
|
||||||
|
* @Modified 2017-04-28 下午8:55:35
|
||||||
|
*/
|
||||||
|
public static String formatJson(String jsonStr) {
|
||||||
|
if (null == jsonStr || "".equals(jsonStr))
|
||||||
|
return "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
char last = '\0';
|
||||||
|
char current = '\0';
|
||||||
|
int indent = 0;
|
||||||
|
boolean isInQuotationMarks = false;
|
||||||
|
for (int i = 0; i < jsonStr.length(); i++) {
|
||||||
|
last = current;
|
||||||
|
current = jsonStr.charAt(i);
|
||||||
|
switch (current) {
|
||||||
|
case '"':
|
||||||
|
if (last != '\\'){
|
||||||
|
isInQuotationMarks = !isInQuotationMarks;
|
||||||
|
}
|
||||||
|
sb.append(current);
|
||||||
|
break;
|
||||||
|
case '{':
|
||||||
|
case '[':
|
||||||
|
sb.append(current);
|
||||||
|
if (!isInQuotationMarks) {
|
||||||
|
sb.append('\n');
|
||||||
|
indent++;
|
||||||
|
addIndentBlank(sb, indent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '}':
|
||||||
|
case ']':
|
||||||
|
if (!isInQuotationMarks) {
|
||||||
|
sb.append('\n');
|
||||||
|
indent--;
|
||||||
|
addIndentBlank(sb, indent);
|
||||||
|
}
|
||||||
|
sb.append(current);
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
sb.append(current);
|
||||||
|
if (last != '\\' && !isInQuotationMarks) {
|
||||||
|
sb.append('\n');
|
||||||
|
addIndentBlank(sb, indent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sb.append(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加space
|
||||||
|
*
|
||||||
|
* @param sb
|
||||||
|
* @param indent
|
||||||
|
* @author lizhgb
|
||||||
|
* @Date 2015-10-14 上午10:38:04
|
||||||
|
*/
|
||||||
|
private static void addIndentBlank(StringBuilder sb, int indent) {
|
||||||
|
for (int i = 0; i < indent; i++) {
|
||||||
|
sb.append('\t');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<!--MySQL数据库驱动程序-->
|
<!--MySQL数据库驱动程序-->
|
||||||
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
||||||
<!--MySQL数据库地址-->
|
<!--MySQL数据库地址-->
|
||||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true</property>
|
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||||
<!--MySQL数据库用户名-->
|
<!--MySQL数据库用户名-->
|
||||||
<property name="user">root</property>
|
<property name="user">root</property>
|
||||||
<!--MySQL数据库密码-->
|
<!--MySQL数据库密码-->
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<relativePath>../</relativePath>
|
<relativePath>../</relativePath>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.21</version>
|
<version>0.23</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package cn.wildfirechat.client;
|
package cn.wildfirechat.client;
|
||||||
|
|
||||||
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import cn.wildfirechat.pojos.InputRoute;
|
import com.xiaoleilu.loServer.pojos.InputRoute;
|
||||||
import io.moquette.spi.impl.security.AES;
|
import io.moquette.spi.impl.security.AES;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@@ -18,6 +19,7 @@ import org.fusesource.mqtt.client.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -280,15 +282,38 @@ public class IMClient implements Listener {
|
|||||||
try {
|
try {
|
||||||
WFCMessage.NotifyMessage notifyMessage = WFCMessage.NotifyMessage.parseFrom(body.toByteArray());
|
WFCMessage.NotifyMessage notifyMessage = WFCMessage.NotifyMessage.parseFrom(body.toByteArray());
|
||||||
WFCMessage.PullMessageRequest request = WFCMessage.PullMessageRequest.newBuilder().setId(messageHead).setType(notifyMessage.getType()).build();
|
WFCMessage.PullMessageRequest request = WFCMessage.PullMessageRequest.newBuilder().setId(messageHead).setType(notifyMessage.getType()).build();
|
||||||
connection.publish("MP", request.toByteArray(), QoS.AT_LEAST_ONCE, false, new Callback<byte[]>(){
|
byte[] data = request.toByteArray();
|
||||||
|
data = AES.AESEncrypt(data, privateSecret);
|
||||||
|
connection.publish("MP", data, QoS.AT_LEAST_ONCE, false, new Callback<byte[]>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(byte[] value) {
|
public void onSuccess(byte[] value) {
|
||||||
|
if (value == null || value.length == 0) {
|
||||||
|
System.out.println("Invalide data");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value[0] != 0) {
|
||||||
|
System.out.println("Pull message error with errorCode:" + value[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] data = new byte[value.length - 1];
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
data[i] = value[i+1];
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] data = AES.AESDecrypt(value, privateSecret, true);
|
data = AES.AESDecrypt(data, privateSecret, true);
|
||||||
try {
|
try {
|
||||||
WFCMessage.PullMessageResult result = WFCMessage.PullMessageResult.parseFrom(data);
|
WFCMessage.PullMessageResult result = WFCMessage.PullMessageResult.parseFrom(data);
|
||||||
if (receiveMessageCallback != null) {
|
if (receiveMessageCallback != null && result.getMessageList().size() > 0) {
|
||||||
receiveMessageCallback.onReceiveMessages(result.getMessageList(), false);
|
List<WFCMessage.Message> messages = result.getMessageList();
|
||||||
|
List<WFCMessage.Message> out = new ArrayList<>();
|
||||||
|
for (WFCMessage.Message msg : messages) {
|
||||||
|
if (msg.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private && msg.getConversation().getTarget().equals(userId)) {
|
||||||
|
msg = msg.toBuilder().setConversation(msg.getConversation().toBuilder().setTarget(msg.getFromUser())).build();
|
||||||
|
}
|
||||||
|
out.add(msg);
|
||||||
|
}
|
||||||
|
receiveMessageCallback.onReceiveMessages(out, false);
|
||||||
}
|
}
|
||||||
messageHead = result.getHead();
|
messageHead = result.getHead();
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
@@ -355,23 +380,24 @@ public class IMClient implements Listener {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//token与userid和clientid是绑定的,使用时一定要传入正确的userid和clientid,不然会认为token非法
|
//token与userid和clientid是绑定的,使用时一定要传入正确的userid和clientid,不然会认为token非法
|
||||||
IMClient client = new IMClient("yzyOyOKK", "7SJk13q+YdHHe6EwDzry9BKogxTNf3UgtYj50cBTZgWNkNuxEkiqg2koKg0lXViONIX1LmwCR1jN0Mw8hvk6KGpiSKFi+IRaRkIb3mNzgIfrq4afhyIHaQfa2HOfsi6Ws+9YobkdDgdq7W70bEdVfiCSU9+JOIY449nxZzfg2Zw=", "DD72C212-26C7-4B38-A5FC-88550896B170", "192.168.1.101", 80);
|
//clientId唯一代表一个设备,只能有一个登录。如果使用同一个clientId登录多次,会出现不可预料问题。
|
||||||
|
IMClient client = new IMClient("KNK_K_00", "6I7UTfKSQT7VhsUJfU6UCvDeCyblLfcXPfajAFxgFGOcqvfFVQCvYy8A5vfAGUj2LSYgoM5W02MHh6jtG/otQs6ft8zLT4Efz315UlDLfrz+OSQYfwAuGFw9m0/x4ckrgiooprsKFxPMaNcCDact0qvp1dBhbeGUipdWVhI33b4=", "5B6DEB72-8A3D-45E2-A88A-47DC4E692B00", "192.168.0.193", 80);
|
||||||
|
|
||||||
client.setReceiveMessageCallback(new ReceiveMessageCallback() {
|
client.setReceiveMessageCallback(new ReceiveMessageCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveMessages(List<WFCMessage.Message> messageList, boolean hasMore) {
|
public void onReceiveMessages(List<WFCMessage.Message> messageList, boolean hasMore) {
|
||||||
|
System.out.println("recieved messages");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRecallMessage(long messageUid) {
|
public void onRecallMessage(long messageUid) {
|
||||||
|
System.out.println("recalled messages");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.setConnectionStatusCallback((ConnectionStatus newStatus) -> {
|
client.setConnectionStatusCallback((ConnectionStatus newStatus) -> {
|
||||||
if (newStatus == ConnectionStatus_Connected) {
|
if (newStatus == ConnectionStatus_Connected) {
|
||||||
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(0).setTarget("yzyOyOKK").setLine(0).build();
|
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(0).setTarget("IMININnn").setLine(0).build();
|
||||||
WFCMessage.MessageContent messageContent = WFCMessage.MessageContent.newBuilder().setSearchableContent("helloworld").setType(1).build();
|
WFCMessage.MessageContent messageContent = WFCMessage.MessageContent.newBuilder().setSearchableContent("helloworld").setType(1).build();
|
||||||
client.sendMessage(conversation, messageContent, new SendMessageCallback() {
|
client.sendMessage(conversation, messageContent, new SendMessageCallback() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package cn.wildfirechat.pojos;
|
package com.xiaoleilu.loServer.pojos;
|
||||||
|
|
||||||
|
|
||||||
public class InputRoute {
|
public class InputRoute {
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.21</version>
|
<version>0.23</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
public class BroadMessageData {
|
||||||
|
private String sender;
|
||||||
|
private int line;
|
||||||
|
private MessagePayload payload;
|
||||||
|
|
||||||
|
public String getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSender(String sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLine() {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLine(int line) {
|
||||||
|
this.line = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessagePayload getPayload() {
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayload(MessagePayload payload) {
|
||||||
|
this.payload = payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isValide(BroadMessageData sendMessageData) {
|
||||||
|
if(sendMessageData == null ||
|
||||||
|
StringUtil.isNullOrEmpty(sendMessageData.getSender()) ||
|
||||||
|
sendMessageData.getPayload() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WFCMessage.Message toProtoMessage() {
|
||||||
|
return WFCMessage.Message.newBuilder().setFromUser(sender)
|
||||||
|
.setConversation(WFCMessage.Conversation.newBuilder().setType(ProtoConstants.ConversationType.ConversationType_Private).setTarget(sender).setLine(line))
|
||||||
|
.setContent(payload.toProtoMessageContent())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
public class BroadMessageResult {
|
||||||
|
private long messageUid;
|
||||||
|
private long count;
|
||||||
|
|
||||||
|
public BroadMessageResult() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BroadMessageResult(long messageUid, long count) {
|
||||||
|
this.messageUid = messageUid;
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMessageUid() {
|
||||||
|
return messageUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageUid(long messageUid) {
|
||||||
|
this.messageUid = messageUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(long count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,13 +22,13 @@ public class GroupNotificationBinaryContent {
|
|||||||
//operator
|
//operator
|
||||||
private String o;
|
private String o;
|
||||||
|
|
||||||
//name
|
//value1(name or something)
|
||||||
private String n;
|
private String n;
|
||||||
|
|
||||||
//members
|
//members
|
||||||
private List<String> ms;
|
private List<String> ms;
|
||||||
|
|
||||||
//members
|
//value2(member or something)
|
||||||
private String m;
|
private String m;
|
||||||
|
|
||||||
public GroupNotificationBinaryContent(String g, String o, String n, String m) {
|
public GroupNotificationBinaryContent(String g, String o, String n, String m) {
|
||||||
@@ -124,4 +124,27 @@ public class GroupNotificationBinaryContent {
|
|||||||
public WFCMessage.MessageContent getModifyGroupMemberAliasNotifyContent() {
|
public WFCMessage.MessageContent getModifyGroupMemberAliasNotifyContent() {
|
||||||
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS);
|
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WFCMessage.MessageContent getChangeGroupMuteNotifyContent() {
|
||||||
|
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_MUTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WFCMessage.MessageContent getChangeGroupJointypeNotifyContent() {
|
||||||
|
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WFCMessage.MessageContent getChangeGroupPrivatechatNotifyContent() {
|
||||||
|
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WFCMessage.MessageContent getChangeGroupSearchableNotifyContent() {
|
||||||
|
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WFCMessage.MessageContent getSetGroupManagerNotifyContent() {
|
||||||
|
return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_SET_MANAGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public interface APIPath {
|
|||||||
|
|
||||||
String Msg_Send = "/admin/message/send";
|
String Msg_Send = "/admin/message/send";
|
||||||
String Msg_Recall = "/admin/message/recall";
|
String Msg_Recall = "/admin/message/recall";
|
||||||
|
String Msg_Broadcast = "/admin/message/broadcast";
|
||||||
|
|
||||||
String Create_Group = "/admin/group/create";
|
String Create_Group = "/admin/group/create";
|
||||||
String Group_Dismiss = "/admin/group/del";
|
String Group_Dismiss = "/admin/group/del";
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public enum ErrorCode {
|
|||||||
|
|
||||||
ERROR_CODE_NOT_IN_CHANNEL(21, "not in channel"),
|
ERROR_CODE_NOT_IN_CHANNEL(21, "not in channel"),
|
||||||
|
|
||||||
|
ERROR_CODE_GROUP_MUTED(241, "group is muted"),
|
||||||
ERROR_CODE_SENSITIVE_MATCHED(242, "sensitive matched"),
|
ERROR_CODE_SENSITIVE_MATCHED(242, "sensitive matched"),
|
||||||
ERROR_CODE_SIGN_EXPIRED(243, "sign expired"),
|
ERROR_CODE_SIGN_EXPIRED(243, "sign expired"),
|
||||||
ERROR_CODE_AUTH_FAILURE(244, "auth failure"),
|
ERROR_CODE_AUTH_FAILURE(244, "auth failure"),
|
||||||
@@ -56,7 +57,7 @@ public enum ErrorCode {
|
|||||||
ERROR_CODE_NOT_IMPLEMENT(254, "not implement"),
|
ERROR_CODE_NOT_IMPLEMENT(254, "not implement"),
|
||||||
|
|
||||||
|
|
||||||
ERROR_CODE_ASYNC_HANDLER(255, "异步执行,服务器内部逻辑需要此代码,为正常情况,不能返回客户端"),;
|
ERROR_CODE_SUCCESS_GZIPED(255, "success withe gzip response"),;
|
||||||
|
|
||||||
public int code;
|
public int code;
|
||||||
public String msg;
|
public String msg;
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ public class ProtoConstants {
|
|||||||
int Modify_Group_Name = 0;
|
int Modify_Group_Name = 0;
|
||||||
int Modify_Group_Portrait = 1;
|
int Modify_Group_Portrait = 1;
|
||||||
int Modify_Group_Extra = 2;
|
int Modify_Group_Extra = 2;
|
||||||
|
int Modify_Group_Mute = 3;
|
||||||
|
int Modify_Group_JoinType = 4;
|
||||||
|
int Modify_Group_PrivateChat = 5;
|
||||||
|
int Modify_Group_Searchable = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ModifyGroupInfoRequest -> type
|
//ModifyGroupInfoRequest -> type
|
||||||
@@ -137,5 +141,12 @@ public class ProtoConstants {
|
|||||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_GROUP_NAME = 110;
|
public static final int MESSAGE_CONTENT_TYPE_CHANGE_GROUP_NAME = 110;
|
||||||
public static final int MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS = 111;
|
public static final int MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS = 111;
|
||||||
public static final int MESSAGE_CONTENT_TYPE_CHANGE_GROUP_PORTRAIT = 112;
|
public static final int MESSAGE_CONTENT_TYPE_CHANGE_GROUP_PORTRAIT = 112;
|
||||||
|
|
||||||
|
public static final int MESSAGE_CONTENT_TYPE_CHANGE_MUTE = 113;
|
||||||
|
public static final int MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE = 114;
|
||||||
|
public static final int MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT = 115;
|
||||||
|
public static final int MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE = 116;
|
||||||
|
|
||||||
|
public static final int MESSAGE_CONTENT_TYPE_SET_MANAGER = 117;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
|||||||
<!--<relativePath>../pom.xml</relativePath>-->
|
<!--<relativePath>../pom.xml</relativePath>-->
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.21</version>
|
<version>0.23</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>distribution</artifactId>
|
<artifactId>distribution</artifactId>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<!--MySQL数据库驱动程序-->
|
<!--MySQL数据库驱动程序-->
|
||||||
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
|
||||||
<!--MySQL数据库地址-->
|
<!--MySQL数据库地址-->
|
||||||
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true</property>
|
<property name="jdbcUrl">jdbc:mysql://localhost:3306/wfchat?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8</property>
|
||||||
<!--MySQL数据库用户名-->
|
<!--MySQL数据库用户名-->
|
||||||
<property name="user">root</property>
|
<property name="user">root</property>
|
||||||
<!--MySQL数据库密码-->
|
<!--MySQL数据库密码-->
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ set JAVA_OPTS=
|
|||||||
set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true
|
set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true
|
||||||
set WILDFIRECHAT_PATH=%WILDFIRECHAT_HOME%
|
set WILDFIRECHAT_PATH=%WILDFIRECHAT_HOME%
|
||||||
set LOG_FILE=%WILDFIRECHAT_HOME%\config\log4j.properties
|
set LOG_FILE=%WILDFIRECHAT_HOME%\config\log4j.properties
|
||||||
|
set HZ_CONF_FILE=%WILDFIRECHAT_HOME%\config\hazelcast.xml
|
||||||
|
set C3P0_CONF_FILE=%WILDFIRECHAT_HOME%\config\c3p0-config.xml
|
||||||
|
|
||||||
rem Use the Hotspot garbage-first collector.
|
rem Use the Hotspot garbage-first collector.
|
||||||
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseG1GC
|
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseG1GC
|
||||||
@@ -71,4 +73,4 @@ rem set JAVA_OPTS=%JAVA_OPTS% -XX:+UseGCLogFileRotation
|
|||||||
rem set JAVA_OPTS=%JAVA_OPTS% -XX:NumberOfGCLogFiles=10
|
rem set JAVA_OPTS=%JAVA_OPTS% -XX:NumberOfGCLogFiles=10
|
||||||
rem set JAVA_OPTS=%JAVA_OPTS% -XX:GCLogFileSize=10M"
|
rem set JAVA_OPTS=%JAVA_OPTS% -XX:GCLogFileSize=10M"
|
||||||
|
|
||||||
%JAVA% -server %JAVA_OPTS% %JAVA_OPTS_SCRIPT% -Dlog4j.configuration=file:%LOG_FILE% -Dwildfirechat.path=%WILDFIRECHAT_PATH% -cp %WILDFIRECHAT_HOME%\lib\* cn.wildfirechat.server.Server
|
%JAVA% -server %JAVA_OPTS% %JAVA_OPTS_SCRIPT% -Dlog4j.configuration=file:%LOG_FILE% -Dcom.mchange.v2.c3p0.cfg.xml=%C3P0_CONF_FILE% -Dhazelcast.configuration=file:%HZ_CONF_FILE% -Dwildfirechat.path=%WILDFIRECHAT_PATH% -cp %WILDFIRECHAT_HOME%\lib\* cn.wildfirechat.server.Server
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ JAVA_OPTS="$JAVA_OPTS -XX:+UseGCLogFileRotation"
|
|||||||
JAVA_OPTS="$JAVA_OPTS -XX:NumberOfGCLogFiles=10"
|
JAVA_OPTS="$JAVA_OPTS -XX:NumberOfGCLogFiles=10"
|
||||||
JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M"
|
JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M"
|
||||||
|
|
||||||
|
#JAVA_OPTS="$JAVA_OPTS -Xmx128M"
|
||||||
|
#JAVA_OPTS="$JAVA_OPTS -Xms128M"
|
||||||
|
|
||||||
JAVA_OPTS="$JAVA_OPTS -Xmx128M"
|
|
||||||
JAVA_OPTS="$JAVA_OPTS -Xms128M"
|
|
||||||
|
|
||||||
$JAVA -server $JAVA_OPTS $JAVA_OPTS_SCRIPT -Dlog4j.configuration="file:$LOG_FILE" -Dcom.mchange.v2.c3p0.cfg.xml="$C3P0_CONF_FILE" -Dhazelcast.configuration="file:$HZ_CONF_FILE" -Dwildfirechat.path="$WILDFIRECHAT_PATH" -cp "$WILDFIRECHAT_HOME/lib/*" cn.wildfirechat.server.Server
|
$JAVA -server $JAVA_OPTS $JAVA_OPTS_SCRIPT -Dlog4j.configuration="file:$LOG_FILE" -Dcom.mchange.v2.c3p0.cfg.xml="$C3P0_CONF_FILE" -Dhazelcast.configuration="file:$HZ_CONF_FILE" -Dwildfirechat.path="$WILDFIRECHAT_PATH" -cp "$WILDFIRECHAT_HOME/lib/*" cn.wildfirechat.server.Server
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>0.21</version>
|
<version>0.23</version>
|
||||||
<name>Wildfire Chat</name>
|
<name>Wildfire Chat</name>
|
||||||
<description>Wildfire Chat Server</description>
|
<description>Wildfire Chat Server</description>
|
||||||
<inceptionYear>2019</inceptionYear>
|
<inceptionYear>2019</inceptionYear>
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.21</version>
|
<version>0.23</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,26 @@ public class Main {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultVoid =UserAdmin.updateUserBlockStatus(userInfo.getUserId(), 0);
|
||||||
|
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("block user done");
|
||||||
|
} else {
|
||||||
|
System.out.println("block user failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
resultCheckUserStatus = UserAdmin.checkUserBlockStatus(userInfo.getUserId());
|
||||||
|
if (resultCheckUserStatus != null && resultCheckUserStatus.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
if (resultCheckUserStatus.getResult().getStatus() == 0) {
|
||||||
|
System.out.println("check user status success");
|
||||||
|
} else {
|
||||||
|
System.out.println("user status not correct");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("block user failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
//***********************************************
|
//***********************************************
|
||||||
//**** 群组相关功能
|
//**** 群组相关功能
|
||||||
@@ -264,6 +284,14 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IMResult<BroadMessageResult> resultBroadcastMessage = MessageAdmin.broadcastMessage("user1", 0, payload);
|
||||||
|
if (resultBroadcastMessage != null && resultBroadcastMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("broad message success, send message to " + resultBroadcastMessage.getResult().getCount() + " users");
|
||||||
|
} else {
|
||||||
|
System.out.println("broad message failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//初始化机器人API
|
//初始化机器人API
|
||||||
RobotHttpUtils.init("http://localhost:18080", "robot1", "123456");
|
RobotHttpUtils.init("http://localhost:18080", "robot1", "123456");
|
||||||
|
|||||||
@@ -22,4 +22,13 @@ public class MessageAdmin {
|
|||||||
messageData.setMessageUid(messageUid);
|
messageData.setMessageUid(messageUid);
|
||||||
return AdminHttpUtils.httpJsonPost(path, messageData, Void.class);
|
return AdminHttpUtils.httpJsonPost(path, messageData, Void.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<BroadMessageResult> broadcastMessage(String sender, int line, MessagePayload payload) throws Exception {
|
||||||
|
String path = APIPath.Msg_Broadcast;
|
||||||
|
BroadMessageData messageData = new BroadMessageData();
|
||||||
|
messageData.setSender(sender);
|
||||||
|
messageData.setLine(line);
|
||||||
|
messageData.setPayload(payload);
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, messageData, BroadMessageResult.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<relativePath>../</relativePath>
|
<relativePath>../</relativePath>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>0.21</version>
|
<version>0.23</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>net.xmeter</groupId>
|
<groupId>net.xmeter</groupId>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 2479085966683186422L;
|
private static final long serialVersionUID = 2479085966683186422L;
|
||||||
|
|
||||||
private JLabeledChoice conversationTypeChoice;
|
private JLabeledChoice conversationTypeChoice = new JLabeledChoice("ConversationType:", new String[] { CONV_TYPE_SINGLE, CONV_TYPE_GROUP }, true, false);
|
||||||
private final JLabeledTextField target = new JLabeledTextField("Target:");
|
private final JLabeledTextField target = new JLabeledTextField("Target:");
|
||||||
// private JCheckBox timestamp = new JCheckBox("Add timestamp in payload");
|
// private JCheckBox timestamp = new JCheckBox("Add timestamp in payload");
|
||||||
|
|
||||||
@@ -62,13 +62,11 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
|||||||
JPanel optsPanelCon = new VerticalPanel();
|
JPanel optsPanelCon = new VerticalPanel();
|
||||||
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Send message options"));
|
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Send message options"));
|
||||||
|
|
||||||
conversationTypeChoice = new JLabeledChoice("ConversationType:", new String[] { CONV_TYPE_SINGLE, CONV_TYPE_GROUP }, true, false);
|
|
||||||
conversationTypeChoice.addChangeListener(this);
|
conversationTypeChoice.addChangeListener(this);
|
||||||
|
|
||||||
JPanel optsPanel = new HorizontalPanel();
|
JPanel optsPanel = new HorizontalPanel();
|
||||||
optsPanel.add(conversationTypeChoice);
|
optsPanel.add(conversationTypeChoice);
|
||||||
optsPanel.add(target);
|
optsPanel.add(target);
|
||||||
// optsPanel.add(timestamp);
|
|
||||||
optsPanelCon.add(optsPanel);
|
optsPanelCon.add(optsPanel);
|
||||||
|
|
||||||
return optsPanelCon;
|
return optsPanelCon;
|
||||||
@@ -77,17 +75,11 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
|||||||
private JPanel createPayload() {
|
private JPanel createPayload() {
|
||||||
JPanel optsPanelCon = new VerticalPanel();
|
JPanel optsPanelCon = new VerticalPanel();
|
||||||
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Message Content"));
|
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Message Content"));
|
||||||
|
|
||||||
// JPanel horizon1 = new HorizontalPanel();
|
|
||||||
//
|
|
||||||
// stringLength.setVisible(true);
|
|
||||||
// horizon1.add(stringLength);
|
|
||||||
|
|
||||||
JPanel horizon2 = new VerticalPanel();
|
JPanel horizon2 = new VerticalPanel();
|
||||||
messagePanel.setVisible(true);
|
messagePanel.setVisible(true);
|
||||||
horizon2.add(messagePanel);
|
horizon2.add(messagePanel);
|
||||||
|
|
||||||
// optsPanelCon.add(horizon1);
|
|
||||||
optsPanelCon.add(horizon2);
|
optsPanelCon.add(horizon2);
|
||||||
return optsPanelCon;
|
return optsPanelCon;
|
||||||
}
|
}
|
||||||
@@ -135,12 +127,16 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
|||||||
|
|
||||||
connUI.configure(sampler);
|
connUI.configure(sampler);
|
||||||
// if(sampler.getQOS().trim().indexOf(JMETER_VARIABLE_PREFIX) == -1){
|
// if(sampler.getQOS().trim().indexOf(JMETER_VARIABLE_PREFIX) == -1){
|
||||||
this.conversationTypeChoice.setSelectedIndex(0);
|
if ("1".equals(sampler.getConvType())) {
|
||||||
|
this.conversationTypeChoice.setSelectedIndex(1);
|
||||||
|
} else {
|
||||||
|
this.conversationTypeChoice.setSelectedIndex(0);
|
||||||
|
}
|
||||||
// } else {
|
// } else {
|
||||||
// this.conversationTypeChoice.setText(sampler.getQOS());
|
// this.conversationTypeChoice.setText(sampler.getQOS());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
this.target.setText(sampler.getTopic());
|
this.target.setText(sampler.getTarget());
|
||||||
// this.timestamp.setSelected(sampler.isAddTimestamp());
|
// this.timestamp.setSelected(sampler.isAddTimestamp());
|
||||||
// if(MESSAGE_TYPE_STRING.equalsIgnoreCase(sampler.getMessageType())) {
|
// if(MESSAGE_TYPE_STRING.equalsIgnoreCase(sampler.getMessageType())) {
|
||||||
// this.messageTypes.setSelectedIndex(0);
|
// this.messageTypes.setSelectedIndex(0);
|
||||||
@@ -168,27 +164,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
|||||||
connUI.setupSamplerProperties(sampler);
|
connUI.setupSamplerProperties(sampler);
|
||||||
|
|
||||||
sampler.setTarget(this.target.getText());
|
sampler.setTarget(this.target.getText());
|
||||||
|
sampler.setConvType(this.conversationTypeChoice.getSelectedIndex() + "");
|
||||||
// if(this.conversationTypeChoice.getText().indexOf(JMETER_VARIABLE_PREFIX) == -1) {
|
|
||||||
// int qos = QOS_0;
|
|
||||||
// try {
|
|
||||||
// qos = Integer.parseInt(this.conversationTypeChoice.getText());
|
|
||||||
// if (qos < QOS_0 || qos > QOS_2) {
|
|
||||||
// qos = QOS_0;
|
|
||||||
// logger.info("Invalid QoS value, set to default QoS value 0.");
|
|
||||||
// }
|
|
||||||
// } catch (Exception ex) {
|
|
||||||
// logger.info("Invalid QoS value, set to default QoS value 0.");
|
|
||||||
// qos = QOS_0;
|
|
||||||
// }
|
|
||||||
// sampler.setQOS(String.valueOf(qos));
|
|
||||||
// } else {
|
|
||||||
// sampler.setQOS(this.conversationTypeChoice.getText());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// sampler.setAddTimestamp(this.timestamp.isSelected());
|
|
||||||
// sampler.setMessageType(this.messageTypes.getText());
|
|
||||||
// sampler.setMessageLength(this.stringLength.getText());
|
|
||||||
sampler.setMessage(this.sendMessage.getText());
|
sampler.setMessage(this.sendMessage.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,11 +175,7 @@ public class SendMessageSamplerUI extends AbstractSamplerGui implements Constant
|
|||||||
connUI.clearUI();
|
connUI.clearUI();
|
||||||
connUI.connNamePrefix.setText(DEFAULT_CONN_PREFIX_FOR_PUB);
|
connUI.connNamePrefix.setText(DEFAULT_CONN_PREFIX_FOR_PUB);
|
||||||
this.target.setText(DEFAULT_TARGET);
|
this.target.setText(DEFAULT_TARGET);
|
||||||
this.conversationTypeChoice.setText(CONV_TYPE_SINGLE);
|
this.conversationTypeChoice.setSelectedIndex(0);
|
||||||
// this.timestamp.setSelected(false);
|
|
||||||
|
|
||||||
// this.messageTypes.setSelectedIndex(0);
|
|
||||||
// this.stringLength.setText(String.valueOf(DEFAULT_MESSAGE_FIX_LENGTH));
|
|
||||||
this.sendMessage.setText("");
|
this.sendMessage.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
package net.xmeter.samplers;
|
package net.xmeter.samplers;
|
||||||
|
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import cn.wildfirechat.pojos.InputRoute;
|
|
||||||
import cn.wildfirechat.pojos.InputGetToken;
|
import cn.wildfirechat.pojos.InputGetToken;
|
||||||
import cn.wildfirechat.pojos.OutputGetIMTokenData;
|
import cn.wildfirechat.pojos.OutputGetIMTokenData;
|
||||||
import io.moquette.spi.impl.security.AES;
|
|
||||||
import net.xmeter.IMResult;
|
import net.xmeter.IMResult;
|
||||||
import net.xmeter.Util;
|
import net.xmeter.Util;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.jmeter.samplers.AbstractSampler;
|
import org.apache.jmeter.samplers.AbstractSampler;
|
||||||
|
|
||||||
@@ -24,11 +19,9 @@ import org.apache.jorphan.logging.LoggingManager;
|
|||||||
import org.apache.log.Logger;
|
import org.apache.log.Logger;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
public abstract class AbstractMQTTSampler extends AbstractSampler implements Constants {
|
public abstract class AbstractMQTTSampler extends AbstractSampler implements Constants {
|
||||||
private transient static Logger logger = LoggingManager.getLoggerForClass();
|
private transient static Logger logger = LoggingManager.getLoggerForClass();
|
||||||
@@ -189,7 +182,7 @@ public abstract class AbstractMQTTSampler extends AbstractSampler implements Con
|
|||||||
protected String token;
|
protected String token;
|
||||||
|
|
||||||
protected boolean getToken(String userId, String clientId) {
|
protected boolean getToken(String userId, String clientId) {
|
||||||
String url = "http://" + getServer() + ":18080/admin/user/token";
|
String url = "http://" + getServer() + ":18080/admin/user/get_token";
|
||||||
String adminSecret = "123456";
|
String adminSecret = "123456";
|
||||||
HttpPost post = null;
|
HttpPost post = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -191,8 +191,11 @@ public class SendMessageSampler extends AbstractMQTTSampler implements ThreadLis
|
|||||||
result.sampleStart();
|
result.sampleStart();
|
||||||
|
|
||||||
final Object lock = new Object();
|
final Object lock = new Object();
|
||||||
|
int converType = 0;
|
||||||
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(0).setTarget(getTarget()).setLine(0).build();
|
if ("1".equals(getConvType())) {
|
||||||
|
converType = 1;
|
||||||
|
}
|
||||||
|
WFCMessage.Conversation conversation = WFCMessage.Conversation.newBuilder().setType(converType).setTarget(getTarget()).setLine(0).build();
|
||||||
WFCMessage.MessageContent messageContent = WFCMessage.MessageContent.newBuilder().setType(1).setSearchableContent(getMessage()).build();
|
WFCMessage.MessageContent messageContent = WFCMessage.MessageContent.newBuilder().setType(1).setSearchableContent(getMessage()).build();
|
||||||
|
|
||||||
final List<Long> ret = new ArrayList<>();
|
final List<Long> ret = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user