Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2bc616e18 | ||
|
|
934f8ba4d7 | ||
|
|
477616ce38 | ||
|
|
f66d0e5cd7 | ||
|
|
2bb6de1198 | ||
|
|
6570d71234 | ||
|
|
64c7da70e7 | ||
|
|
a2eadf5a78 | ||
|
|
7fb040ac1a | ||
|
|
b575274680 | ||
|
|
8bfe3583b9 | ||
|
|
ab3882e1d4 | ||
|
|
0cbb9fd1a4 | ||
|
|
115a597038 | ||
|
|
a8fde271ea | ||
|
|
b0143bb5bf | ||
|
|
025af5eae0 | ||
|
|
ce16f87e12 | ||
|
|
b47084f61f | ||
|
|
936e3581b4 | ||
|
|
cc756842c4 | ||
|
|
9aa29685ef | ||
|
|
c1bb45fe14 | ||
|
|
928555b36e | ||
|
|
744d516932 | ||
|
|
8721c80a9f | ||
|
|
06698a54e1 | ||
|
|
7f48b54b73 | ||
|
|
cf619ebeee | ||
|
|
9fdc6c2e1b | ||
|
|
1d309816ba | ||
|
|
21aa248d49 | ||
|
|
90c8e49808 | ||
|
|
2326850538 | ||
|
|
cef0cb1076 | ||
|
|
9b34e51494 |
@@ -54,9 +54,16 @@
|
||||
|
||||
<img src="http://static.wildfirechat.cn/ios-voip-view.png" width = 50% height = 50% />
|
||||
|
||||
## 编译
|
||||
在安装JDK1.8以上及maven的前提下,在命令行中执行```mvn clean compile package```,生成的目标文件在```./distribution/target/distribution-xxxx-bundle-tar.tar.gz```
|
||||
|
||||
## 特别感谢
|
||||
1. [moquette](https://github.com/moquette-io/moquette) 本项目是基于此项目二次开发而来,处理MQTT相关业务。
|
||||
2. [loServer](https://github.com/looly/loServer) 本项目使用loServer处理HTTP相关业务。
|
||||
|
||||
*** 对他们表示诚挚的感谢🙏 ***
|
||||
|
||||
## License
|
||||
|
||||
1. Under the Creative Commons Attribution-NoDerivs 3.0 Unported license. See the [LICENSE](https://github.com/wildfirechat/server/blob/wildfirechat/LICENSE) file for details.
|
||||
2. Under the Anti 996 License. See the [Anti 996 LICENSE](https://github.com/wildfirechat/server/blob/wildfirechat/LICENSE_996) file for details.
|
||||
2. Under the Anti 996 License. See the [Anti 996 LICENSE](https://github.com/wildfirechat/server/blob/wildfirechat/LICENSE_996) file for details.
|
||||
|
||||
Executable
@@ -1,26 +1,4 @@
|
||||
DROP TABLE IF EXISTS `t_messages`;
|
||||
CREATE TABLE `t_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(),
|
||||
UNIQUE INDEX `message_uid_index` (`_mid` ASC)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `t_user_messages`;
|
||||
CREATE TABLE `t_user_messages` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`_mid` bigint(20) NOT NULL,
|
||||
`_uid` varchar(64) NOT NULL,
|
||||
`_seq` bigint(20) NOT NULL,
|
||||
`_dt` DATETIME NOT NULL DEFAULT NOW(),
|
||||
UNIQUE INDEX `message_seq_uid_index` (`_uid` DESC, `_seq` DESC)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `t_group`;
|
||||
CREATE TABLE `t_group` (
|
||||
@@ -181,6 +159,7 @@ CREATE TABLE `t_robot` (
|
||||
`_owner` varchar(64) DEFAULT '',
|
||||
`_secret` varchar(64) DEFAULT '',
|
||||
`_callback` varchar(1024) DEFAULT '',
|
||||
`_state` tinyint DEFAULT 0,
|
||||
`_extra` TEXT DEFAULT NULL,
|
||||
`_dt` bigint(20) NOT NULL,
|
||||
UNIQUE INDEX `robot_uid_index` (`_uid` ASC),
|
||||
@@ -219,11 +198,3 @@ CREATE TABLE `t_sensitiveword` (
|
||||
`_word` TEXT DEFAULT NULL
|
||||
);
|
||||
|
||||
|
||||
|
||||
insert into t_chatroom (`_cid`, `_title`, `_desc`,`_dt`) values ('chatroom1','火信聊天室1','火信测试聊天室1,用来演示聊天室功能', 1);
|
||||
|
||||
insert into t_chatroom (`_cid`, `_title`, `_desc`,`_dt`) values ('chatroom2','火信聊天室2','火信测试聊天室2,用来演示聊天室功能', 1);
|
||||
|
||||
insert into t_chatroom (`_cid`, `_title`, `_desc`,`_dt`) values ('chatroom3','火信聊天室3','火信测试聊天室3,用来演示聊天室功能', 1);
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_messages`;
|
||||
CREATE TABLE `t_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(),
|
||||
UNIQUE INDEX `message_uid_index` (`_mid` ASC)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `t_user_messages`;
|
||||
CREATE TABLE `t_user_messages` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`_mid` bigint(20) NOT NULL,
|
||||
`_uid` varchar(64) NOT NULL,
|
||||
`_seq` bigint(20) NOT NULL,
|
||||
`_dt` DATETIME NOT NULL DEFAULT NOW(),
|
||||
UNIQUE INDEX `message_seq_uid_index` (`_uid` DESC, `_seq` DESC)
|
||||
);
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
|
||||
insert into t_chatroom (`_cid`, `_title`, `_desc`,`_dt`) values ('chatroom1','火信聊天室1','火信测试聊天室1,用来演示聊天室功能', 1);
|
||||
|
||||
insert into t_chatroom (`_cid`, `_title`, `_desc`,`_dt`) values ('chatroom2','火信聊天室2','火信测试聊天室2,用来演示聊天室功能', 1);
|
||||
|
||||
insert into t_chatroom (`_cid`, `_title`, `_desc`,`_dt`) values ('chatroom3','火信聊天室3','火信测试聊天室3,用来演示聊天室功能', 1);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
|
||||
insert into t_user (`_uid`,`_name`,`_display_name`,`_portrait`,`_type`,`_dt`) values ('FireRobot','FireRobot','小火','http://cdn2.wildfirechat.cn/robot.png',1,1);
|
||||
|
||||
insert into t_robot (`_uid`,`_owner`,`_secret`,`_callback`,`_state`,`_dt`) values ('FireRobot', 'FireRobot', '123456', 'http://127.0.0.1:8883/robot/recvmsg', 0, 1);
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
|
||||
alter table t_friend add column `_alias` varchar(64) DEFAULT NULL;
|
||||
Executable
@@ -1,3 +1,4 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_messages`;
|
||||
CREATE TABLE `t_messages` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
+2353
File diff suppressed because it is too large
Load Diff
+3
@@ -0,0 +1,3 @@
|
||||
insert into t_user (`_uid`,`_name`,`_display_name`,`_portrait`,`_type`,`_dt`) values ('FireRobot','FireRobot','小火','http://cdn2.wildfirechat.cn/robot.png',1,1);
|
||||
|
||||
insert into t_robot (`_uid`,`_owner`,`_secret`,`_callback`,`_state`,`_dt`) values ('FireRobot', 'FireRobot', '123456', 'http://127.0.0.1:8883/robot/recvmsg', 0, 1);
|
||||
+1
@@ -0,0 +1 @@
|
||||
alter table t_friend add column `_alias` varchar(64) DEFAULT NULL;
|
||||
+17
-1
@@ -5,7 +5,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>0.12</version>
|
||||
<version>0.20</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
@@ -249,6 +249,22 @@
|
||||
<version>1.4.197</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.13.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-core -->
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
<version>5.2.4</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
CREATE DATABASE IF NOT EXISTS wfchat CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
show_help_info(){
|
||||
echo "### Usage: ./initial_db.sh -u{user} -p{password}"
|
||||
echo "### 初始化数据库。"
|
||||
echo "###"
|
||||
|
||||
}
|
||||
|
||||
for i in "$@"
|
||||
do
|
||||
PFLAG=`echo $i|cut -b1-2`
|
||||
PPARAM=`echo $i|cut -b3-`
|
||||
if [ $PFLAG = "-u" ]; then
|
||||
USER=${PPARAM}
|
||||
elif [ $PFLAG = "-p" ]; then
|
||||
PASSWORD=${PPARAM}
|
||||
elif [ $PFLAG = "-h" ]; then
|
||||
show_help_info
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
if [ "${USER}" = "" ]; then
|
||||
show_help_info
|
||||
exit 1
|
||||
elif [ "${PASSWORD}" = "" ]; then
|
||||
show_help_info
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
mysql -u${USER} -p${PASSWORD} -e"source 1_create_database.sql;"
|
||||
mysql -u${USER} -p${PASSWORD} -e"use wfchat; source 2_create_table.sql; source 3_create_default_chatroom.sql;"
|
||||
|
||||
for((i=0;i<36;i++));
|
||||
do
|
||||
create_message_tbl_sql="USE wfchat;
|
||||
DROP TABLE IF EXISTS \`t_messages_${i}\`;
|
||||
CREATE TABLE \`t_messages_${i}\` (
|
||||
\`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,
|
||||
INDEX \`message_uid_index\` (\`_mid\` DESC)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
"
|
||||
|
||||
echo "create table t_messages_$i"
|
||||
mysql -u${USER} -p${PASSWORD} -e"${create_message_tbl_sql}"
|
||||
done
|
||||
|
||||
|
||||
for((i=0;i<128;i++));
|
||||
do
|
||||
create_user_message_tbl_sql="USE wfchat;
|
||||
DROP TABLE IF EXISTS \`t_user_messages_${i}\`;
|
||||
CREATE TABLE \`t_user_messages_${i}\` (
|
||||
\`id\` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
\`_mid\` bigint(20) NOT NULL,
|
||||
\`_uid\` varchar(64) NOT NULL,
|
||||
\`_seq\` bigint(20) NOT NULL,
|
||||
\`_dt\` DATETIME NOT NULL DEFAULT NOW(),
|
||||
INDEX \`message_seq_uid_index\` (\`_uid\` DESC, \`_seq\` DESC)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
"
|
||||
|
||||
echo "create table t_user_messages_$i"
|
||||
mysql -u${USER} -p${PASSWORD} -e"${create_user_message_tbl_sql}"
|
||||
done
|
||||
@@ -30,14 +30,14 @@ public class ThreadPoolExecutorWrapper {
|
||||
|
||||
public void execute(Runnable task) {
|
||||
int startCount = runCounter.incrementAndGet();
|
||||
LOG.info("Submit task and current taskcount {}", startCount);
|
||||
LOG.debug("Submit task and current task count {}", startCount);
|
||||
final long startTime = System.currentTimeMillis();
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
task.run();
|
||||
} finally {
|
||||
int endCount = runCounter.decrementAndGet();
|
||||
LOG.info("Finish task and current taskcount {} use time {}", endCount, System.currentTimeMillis()-startTime);
|
||||
LOG.debug("Finish task and current task count {} use time {}", endCount, System.currentTimeMillis()-startTime);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,8 +39,6 @@ abstract public class Action {
|
||||
|
||||
public ChannelHandlerContext ctx;
|
||||
|
||||
protected boolean isSync = true;
|
||||
|
||||
public ErrorCode preAction(Request request, Response response) {
|
||||
if (getClass().getAnnotation(RequireAuthentication.class) != null) {
|
||||
//do authentication
|
||||
@@ -50,6 +48,7 @@ abstract public class Action {
|
||||
}
|
||||
public boolean doAction(Request request, Response response) {
|
||||
ErrorCode errorCode = preAction(request, response);
|
||||
boolean isSync = true;
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
//事务逻辑有缺陷,先注释掉
|
||||
// if (isTransactionAction() && !(this instanceof IMAction)) {
|
||||
@@ -63,9 +62,8 @@ abstract public class Action {
|
||||
// throw e;
|
||||
// }
|
||||
// } else {
|
||||
action(request, response);
|
||||
isSync = action(request, response);
|
||||
// }
|
||||
afterAction(request, response);
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
if (errorCode == null) {
|
||||
@@ -77,19 +75,12 @@ abstract public class Action {
|
||||
response.send();
|
||||
}
|
||||
|
||||
if(this instanceof IMAction || this instanceof RouteAction || this instanceof GetIMTokenAction) {
|
||||
isSync = false;
|
||||
}
|
||||
return isSync;
|
||||
}
|
||||
public boolean isTransactionAction() {
|
||||
return false;
|
||||
}
|
||||
abstract public void action(Request request, Response response);
|
||||
public void afterAction(Request request, Response response) {
|
||||
|
||||
}
|
||||
|
||||
abstract public boolean action(Request request, Response response);
|
||||
|
||||
protected <T> T getRequestBody(HttpRequest request, Class<T> cls) {
|
||||
if (request instanceof FullHttpRequest) {
|
||||
|
||||
@@ -12,7 +12,8 @@ import io.moquette.spi.IMessagesStore;
|
||||
*/
|
||||
public class DefaultIndexAction extends Action{
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
response.setContent("Welcome to LoServer.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,15 +34,15 @@ public class FileAction extends Action {
|
||||
private static final org.slf4j.Logger Logger = LoggerFactory.getLogger(FileAction.class);
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (false == Request.METHOD_GET.equalsIgnoreCase(request.getMethod())) {
|
||||
response.sendError(HttpResponseStatus.METHOD_NOT_ALLOWED, "Please use GET method to request file!");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(ServerSetting.isRootAvailable() == false){
|
||||
response.sendError(HttpResponseStatus.NOT_FOUND, "404 Root dir not avaliable!");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
final File file = getFileByPath(request.getPath());
|
||||
@@ -51,13 +51,13 @@ public class FileAction extends Action {
|
||||
// 隐藏文件,跳过
|
||||
if (file.isHidden() || !file.exists()) {
|
||||
response.sendError(HttpResponseStatus.NOT_FOUND, "404 File not found!");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 非文件,跳过
|
||||
if (false == file.isFile()) {
|
||||
response.sendError(HttpResponseStatus.FORBIDDEN, "403 Forbidden!");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cache Validation
|
||||
@@ -76,12 +76,13 @@ public class FileAction extends Action {
|
||||
if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) {
|
||||
Logger.debug("File {} not modified.", file.getPath());
|
||||
response.sendNotModified();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.setContent(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final Pattern INSECURE_URI = Pattern.compile(".*[<>&\"].*");
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.concurrent.Executor;
|
||||
public class IMAction extends Action {
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest();
|
||||
@@ -46,15 +46,15 @@ public class IMAction extends Action {
|
||||
bytes = Base64.getDecoder().decode(str);
|
||||
} catch (IllegalArgumentException e) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
String cid = fullHttpRequest.headers().get("cid");
|
||||
byte[] cbytes = Base64.getDecoder().decode(cid);
|
||||
cbytes = AES.AESDecrypt(cbytes, null, true);
|
||||
cbytes = AES.AESDecrypt(cbytes, "", true);
|
||||
if (cbytes == null) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
cid = new String(cbytes);
|
||||
|
||||
@@ -64,13 +64,13 @@ public class IMAction extends Action {
|
||||
bytes = AES.AESDecrypt(bytes, session.getSecret(), true);
|
||||
} else {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (bytes == null) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -102,12 +102,14 @@ public class IMAction extends Action {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
return false;
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_INVALID_DATA, null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendResponse(Response response, ErrorCode errorCode, byte[] contents) {
|
||||
|
||||
@@ -27,7 +27,8 @@ public class NotFoundAction extends Action{
|
||||
private final static String TEMPLATE_ERROR = "<!DOCTYPE html><html><head><title>LoServer - Error report</title><style>h1,h3 {color:white; background-color: gray;}</style></head><body><h1>HTTP Status {} - {}</h1><hr size=\"1\" noshade=\"noshade\" /><p>{}</p><hr size=\"1\" noshade=\"noshade\" /><h3>LoServer</h3></body></html>";
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
response.sendError(HttpResponseStatus.NOT_FOUND, "404 Not found!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.concurrent.Executor;
|
||||
public class RouteAction extends Action {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RouteAction.class);
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
@@ -55,24 +55,24 @@ public class RouteAction extends Action {
|
||||
bytes = Base64.getDecoder().decode(str);
|
||||
} catch (IllegalArgumentException e) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null, base64Response);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
String cid = fullHttpRequest.headers().get("cid");
|
||||
byte[] cbytes = Base64.getDecoder().decode(cid);
|
||||
cbytes = AES.AESDecrypt(cbytes, null, true);
|
||||
cbytes = AES.AESDecrypt(cbytes, "", true);
|
||||
if (cbytes == null) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null, base64Response);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
cid = new String(cbytes);
|
||||
|
||||
String uid = fullHttpRequest.headers().get("uid");
|
||||
byte[] ubytes = Base64.getDecoder().decode(uid);
|
||||
ubytes = AES.AESDecrypt(ubytes, null, true);
|
||||
ubytes = AES.AESDecrypt(ubytes, "", true);
|
||||
if (ubytes == null) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null, base64Response);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
uid = new String(ubytes);
|
||||
|
||||
@@ -82,7 +82,7 @@ public class RouteAction extends Action {
|
||||
ErrorCode errorCode = sessionsStore.createNewSession(uid, cid, true);
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
sendResponse(response, errorCode, null, base64Response);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
session = sessionsStore.sessionForClientAndUser(uid, cid);
|
||||
}
|
||||
@@ -92,13 +92,13 @@ public class RouteAction extends Action {
|
||||
bytes = AES.AESDecrypt(bytes, session.getSecret(), true);
|
||||
} else {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null, base64Response);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (bytes == null) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SECRECT_KEY_MISMATCH, null, base64Response);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -132,12 +132,14 @@ public class RouteAction extends Action {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
return false;
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_INVALID_DATA, null, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendResponse(Response response, ErrorCode errorCode, byte[] contents, boolean base64Response) {
|
||||
|
||||
@@ -27,7 +27,8 @@ public class UnknownErrorAction extends Action{
|
||||
private final static String TEMPLATE_ERROR = "<!DOCTYPE html><html><head><title>LoServer - Error report</title><style>h1,h3 {color:white; background-color: gray;}</style></head><body><h1>HTTP Status {} - {}</h1><hr size=\"1\" noshade=\"noshade\" /><p>{}</p><hr size=\"1\" noshade=\"noshade\" /><h3>LoServer</h3></body></html>";
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class UploadFileAction extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request r, Response response) {
|
||||
public boolean action(Request r, Response response) {
|
||||
if (r.getNettyRequest() instanceof FullHttpRequest) {
|
||||
|
||||
FullHttpRequest request = (FullHttpRequest) r.getNettyRequest();
|
||||
@@ -84,12 +84,13 @@ public class UploadFileAction extends Action {
|
||||
logger.warn("http decode failed!");
|
||||
response.setStatus(HttpResponseStatus.BAD_REQUEST);
|
||||
response.setContent("http decode failed");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
multipartUpload(request, requestId, response);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class VersionAction extends Action {
|
||||
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
|
||||
@@ -44,5 +44,6 @@ public class VersionAction extends Action {
|
||||
response.setContent("{\"version\":\"unknown\"}");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BlockUserAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputOutputUserBlockStatus inputUserBlock = getRequestBody(request.getNettyRequest(), InputOutputUserBlockStatus.class);
|
||||
if (inputUserBlock != null
|
||||
@@ -44,7 +44,7 @@ public class BlockUserAction extends AdminAction {
|
||||
result = RestResult.resultOf(errorCode);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
|
||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null);
|
||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
||||
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, null);
|
||||
} else {
|
||||
@@ -54,5 +54,6 @@ public class BlockUserAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,16 +30,17 @@ public class CheckUserOnlineAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId == null || !StringUtil.isNullOrEmpty(inputUserId.getUserId())) {
|
||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.CHECK_USER_ONLINE_REQUEST, inputUserId.getUserId().getBytes(), inputUserId.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null);
|
||||
return;
|
||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.CHECK_USER_ONLINE_REQUEST, inputUserId.getUserId().getBytes(), inputUserId.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
||||
return true;
|
||||
} else {
|
||||
sendResponse(response, ErrorCode.INVALID_PARAMETER, null);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class CreateChatroomAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest();
|
||||
byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content());
|
||||
@@ -67,5 +67,6 @@ public class CreateChatroomAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CreateGroupAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputCreateGroup inputCreateGroup = getRequestBody(request.getNettyRequest(), InputCreateGroup.class);
|
||||
if (inputCreateGroup.isValide()) {
|
||||
@@ -74,12 +74,14 @@ public class CreateGroupAction extends AdminAction {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CreateRobotAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputCreateRobot inputCreateRobot = getRequestBody(request.getNettyRequest(), InputCreateRobot.class);
|
||||
if (inputCreateRobot != null
|
||||
@@ -76,5 +76,6 @@ public class CreateRobotAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CreateUserAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputCreateUser inputCreateUser = getRequestBody(request.getNettyRequest(), InputCreateUser.class);
|
||||
if (inputCreateUser != null
|
||||
@@ -90,5 +90,6 @@ public class CreateUserAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class DestoryChatroomAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
FullHttpRequest fullHttpRequest = (FullHttpRequest)request.getNettyRequest();
|
||||
byte[] bytes = Utils.readBytesAndRewind(fullHttpRequest.content());
|
||||
@@ -54,5 +54,6 @@ public class DestoryChatroomAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class GetChatroomInfoAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
|
||||
String chatroomid = request.getParam("id");
|
||||
@@ -40,10 +40,10 @@ public class GetChatroomInfoAction extends AdminAction {
|
||||
WFCMessage.ChatroomInfo info = messagesStore.getChatroomInfo(chatroomid);
|
||||
|
||||
RestResult result;
|
||||
if (info == null) {
|
||||
if (info != null) {
|
||||
result = RestResult.ok(new OutputGetChatroomInfo(chatroomid, messagesStore.getChatroomMemberCount(chatroomid), info));
|
||||
} else {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_SUCCESS);
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||
}
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
|
||||
@@ -56,5 +56,6 @@ public class GetChatroomInfoAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GetIMTokenAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetToken input = getRequestBody(request.getNettyRequest(), InputGetToken.class);
|
||||
String userId = input.getUserId();
|
||||
@@ -75,7 +75,9 @@ public class GetIMTokenAction extends AdminAction {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
});
|
||||
}, true);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class GetUserAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId != null
|
||||
@@ -64,5 +64,6 @@ public class GetUserAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -27,11 +27,12 @@ public class GetUserBlockListAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.ok(messagesStore.getUserStatusList());
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -32,7 +32,7 @@ public class GetUserBlockStatusAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId != null
|
||||
@@ -49,5 +49,6 @@ public class GetUserBlockStatusAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class RecallMessageAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
RecallMessageData recallMessageData = getRequestBody(request.getNettyRequest(), RecallMessageData.class);
|
||||
if (recallMessageData != null && !StringUtil.isNullOrEmpty(recallMessageData.getOperator())) {
|
||||
@@ -69,12 +69,14 @@ public class RecallMessageAction extends AdminAction {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
|
||||
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;
|
||||
@@ -38,10 +39,10 @@ public class SendMessageAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
SendMessageData sendMessageData = getRequestBody(request.getNettyRequest(), SendMessageData.class);
|
||||
if (SendMessageData.isValide(sendMessageData)) {
|
||||
if (SendMessageData.isValide(sendMessageData) && !StringUtil.isNullOrEmpty(sendMessageData.getSender())) {
|
||||
RPCCenter.getInstance().sendRequest(sendMessageData.getSender(), null, IMTopic.SendMessageTopic, sendMessageData.toProtoMessage().toByteArray(), sendMessageData.getSender(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
@@ -73,12 +74,14 @@ public class SendMessageAction extends AdminAction {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -33,7 +33,7 @@ public class SensitiveWordAddAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputOutputSensitiveWords input = getRequestBody(request.getNettyRequest(), InputOutputSensitiveWords.class);
|
||||
if (input != null && input.getWords() != null && !input.getWords().isEmpty()) {
|
||||
@@ -47,5 +47,6 @@ public class SensitiveWordAddAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -29,7 +29,7 @@ public class SensitiveWordDeleteAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputOutputSensitiveWords input = getRequestBody(request.getNettyRequest(), InputOutputSensitiveWords.class);
|
||||
if (input != null && input.getWords() != null && !input.getWords().isEmpty()) {
|
||||
@@ -44,5 +44,6 @@ public class SensitiveWordDeleteAction extends AdminAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -31,12 +31,13 @@ public class SensitiveWordQueryAction extends AdminAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
List<String> words = messagesStore.getAllSensitiveWords();
|
||||
InputOutputSensitiveWords out = new InputOutputSensitiveWords();
|
||||
out.setWords(words);
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, out);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SendMessageAction extends ChannelAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
SendMessageData sendMessageData = getRequestBody(request.getNettyRequest(), SendMessageData.class);
|
||||
sendMessageData.setConv(new Conversation());
|
||||
@@ -81,12 +81,14 @@ public class SendMessageAction extends ChannelAction {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
return false;
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import win.liyufan.im.ErrorCode;
|
||||
public class GetUserAction extends RobotAction {
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId != null
|
||||
@@ -59,5 +59,6 @@ public class GetUserAction extends RobotAction {
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SendMessageAction extends RobotAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(Request request, Response response) {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
SendMessageData sendMessageData = getRequestBody(request.getNettyRequest(), SendMessageData.class);
|
||||
sendMessageData.setSender(robot.getUid());
|
||||
@@ -76,12 +76,14 @@ public class SendMessageAction extends RobotAction {
|
||||
ctx.executor().execute(command);
|
||||
};
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
return false;
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,15 @@ import java.io.Serializable;
|
||||
public class FriendData implements Serializable {
|
||||
private String userId;
|
||||
private String friendUid;
|
||||
private String alias;
|
||||
private int state;
|
||||
private long timestamp;
|
||||
|
||||
|
||||
public FriendData(String userId, String friendUid, int state, long timestamp) {
|
||||
public FriendData(String userId, String friendUid, String alias, int state, long timestamp) {
|
||||
this.userId = userId;
|
||||
this.friendUid = friendUid;
|
||||
this.alias = alias;
|
||||
this.state = state;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
@@ -43,6 +45,14 @@ public class FriendData implements Serializable {
|
||||
this.friendUid = friendUid;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
+19
-2
@@ -16,6 +16,9 @@ import io.moquette.BrokerConstants;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupNotificationBinaryContent {
|
||||
//groupId
|
||||
private String g;
|
||||
|
||||
//operator
|
||||
private String o;
|
||||
|
||||
@@ -28,19 +31,33 @@ public class GroupNotificationBinaryContent {
|
||||
//members
|
||||
private String m;
|
||||
|
||||
public GroupNotificationBinaryContent(String o, String n, String m) {
|
||||
public GroupNotificationBinaryContent(String g, String o, String n, String m) {
|
||||
this.o = o;
|
||||
this.n = n;
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public GroupNotificationBinaryContent(String operator, String name, List<String> members) {
|
||||
public GroupNotificationBinaryContent(String g, String operator, String name, List<String> members) {
|
||||
this.o = operator;
|
||||
this.n = name;
|
||||
this.ms = members;
|
||||
}
|
||||
|
||||
public String getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public void setG(String g) {
|
||||
this.g = g;
|
||||
}
|
||||
|
||||
public String getM() {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void setM(String m) {
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public String getO() {
|
||||
return o;
|
||||
|
||||
@@ -21,7 +21,7 @@ import static win.liyufan.im.IMTopic.HandleFriendRequestTopic;
|
||||
@Handler(IMTopic.AddFriendRequestTopic)
|
||||
public class AddFriendHandler extends GroupHandler<WFCMessage.AddFriendRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.AddFriendRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.AddFriendRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
long[] head = new long[1];
|
||||
ErrorCode errorCode = m_messagesStore.saveAddFriendRequest(fromUser, request, head);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
@@ -30,7 +30,7 @@ public class AddFriendHandler extends GroupHandler<WFCMessage.AddFriendRequest>
|
||||
publisher.publishNotification(IMTopic.NotifyFriendRequestTopic, request.getTargetUid(), head[0]);
|
||||
} else if(user != null && user.getType() == ProtoConstants.UserType.UserType_Robot) {
|
||||
WFCMessage.HandleFriendRequest handleFriendRequest = WFCMessage.HandleFriendRequest.newBuilder().setTargetUid(fromUser).setStatus(ProtoConstants.FriendRequestStatus.RequestStatus_Accepted).build();
|
||||
mServer.internalRpcMsg(request.getTargetUid(), null, handleFriendRequest.toByteArray(), 0, fromUser, HandleFriendRequestTopic);
|
||||
mServer.internalRpcMsg(request.getTargetUid(), null, handleFriendRequest.toByteArray(), 0, fromUser, HandleFriendRequestTopic, false);
|
||||
}
|
||||
}
|
||||
return errorCode;
|
||||
|
||||
@@ -22,13 +22,13 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
public class AddGroupMember extends GroupHandler<WFCMessage.AddGroupMemberRequest> {
|
||||
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, 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());
|
||||
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(fromUser, null, getMemberIdList(request.getAddedMemberList())).getAddGroupNotifyContent();
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, getMemberIdList(request.getAddedMemberList())).getAddGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.BlackListUserTopic)
|
||||
public class BlackListRequestHandler extends GroupHandler<WFCMessage.BlackUserRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.BlackUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.BlackUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
long[] head = new long[1];
|
||||
ErrorCode errorCode = m_messagesStore.blackUserRequest(fromUser, request.getUid(), request.getStatus(), head);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
|
||||
@@ -23,11 +23,11 @@ import static win.liyufan.im.UserSettingScope.kUserSettingListenedChannels;
|
||||
public class ChannelListenMember extends IMHandler<WFCMessage.ListenChannel> {
|
||||
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.ListenChannel request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ListenChannel request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.listenChannel(fromUser, request.getChannelId(), request.getListen()>0);
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
WFCMessage.ModifyUserSettingReq modifyUserSettingReq = WFCMessage.ModifyUserSettingReq.newBuilder().setScope(kUserSettingListenedChannels).setKey(request.getChannelId()).setValue(request.getListen() > 0 ? "1" : "0").build();
|
||||
mServer.internalRpcMsg(fromUser, null, modifyUserSettingReq.toByteArray(), 0, fromUser, PutUserSettingTopic);
|
||||
mServer.internalRpcMsg(fromUser, null, modifyUserSettingReq.toByteArray(), 0, fromUser, PutUserSettingTopic, false);
|
||||
|
||||
publisher.notifyChannelListenStatusChanged(m_messagesStore.getChannelInfo(request.getChannelId()), fromUser, request.getListen() > 0);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
@Handler(IMTopic.ChannelSearchTopic)
|
||||
public class ChannelSearchHandler extends IMHandler<WFCMessage.SearchUserRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.SearchUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.SearchUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
List<WFCMessage.ChannelInfo> users = m_messagesStore.searchChannel(request.getKeyword(), request.getFuzzy() > 0, request.getPage());
|
||||
WFCMessage.SearchChannelResult.Builder builder = WFCMessage.SearchChannelResult.newBuilder();
|
||||
builder.addAllChannel(users);
|
||||
|
||||
@@ -25,7 +25,7 @@ import static win.liyufan.im.UserSettingScope.kUserSettingMyChannels;
|
||||
@Handler(value = IMTopic.CreateChannelTopic)
|
||||
public class CreateChannelHandler extends GroupHandler<WFCMessage.ChannelInfo> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.ChannelInfo request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ChannelInfo request, Qos1PublishHandler.IMCallback callback) {
|
||||
WFCMessage.ChannelInfo.Builder builder = request.toBuilder();
|
||||
if (StringUtil.isNullOrEmpty(request.getTargetId())) {
|
||||
builder.setTargetId(m_messagesStore.getShortUUID());
|
||||
@@ -44,7 +44,7 @@ public class CreateChannelHandler extends GroupHandler<WFCMessage.ChannelInfo> {
|
||||
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
WFCMessage.ModifyUserSettingReq modifyUserSettingReq = WFCMessage.ModifyUserSettingReq.newBuilder().setScope(kUserSettingMyChannels).setKey(request.getTargetId()).setValue("1").build();
|
||||
mServer.internalRpcMsg(fromUser, null, modifyUserSettingReq.toByteArray(), 0, fromUser, PutUserSettingTopic);
|
||||
mServer.internalRpcMsg(fromUser, null, modifyUserSettingReq.toByteArray(), 0, fromUser, PutUserSettingTopic, false);
|
||||
byte[] data = request.getTargetId().getBytes();
|
||||
ackPayload.ensureWritable(data.length).writeBytes(data);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@@ -21,13 +21,13 @@ import static io.moquette.BrokerConstants.MESSAGE_CONTENT_TYPE_CREATE_GROUP;
|
||||
@Handler(value = IMTopic.CreateGroupTopic)
|
||||
public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.CreateGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.CreateGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.createGroup(fromUser, request.getGroup().getGroupInfo(), request.getGroup().getMembersList());
|
||||
if (groupInfo != null) {
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(fromUser, groupInfo.getName(), "").getCreateGroupNotifyContent();
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(groupInfo.getTargetId(), fromUser, groupInfo.getName(), "").getCreateGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.DeleteFriendTopic)
|
||||
public class DeleteFriendHandler extends IMHandler<WFCMessage.IDBuf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
return m_messagesStore.deleteFriend(fromUser, request.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import static win.liyufan.im.IMTopic.DismissGroupTopic;
|
||||
@Handler(value = DismissGroupTopic)
|
||||
public class DismissGroupHandler extends GroupHandler<WFCMessage.DismissGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.DismissGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.DismissGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
ErrorCode errorCode;
|
||||
if (groupInfo == null) {
|
||||
@@ -33,7 +33,7 @@ public class DismissGroupHandler extends GroupHandler<WFCMessage.DismissGroupReq
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(fromUser, null, "").getDismissGroupNotifyContent();
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(groupInfo.getTargetId(), fromUser, null, "").getDismissGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.dismissGroup(fromUser, request.getGroupId());
|
||||
|
||||
@@ -20,11 +20,11 @@ import static win.liyufan.im.UserSettingScope.kUserSettingMyChannels;
|
||||
@Handler(value = IMTopic.DestoryChannelInfoTopic)
|
||||
public class DistoryChannelHandler extends GroupHandler<WFCMessage.IDBuf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.distoryChannel(fromUser, request.getId());
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
WFCMessage.ModifyUserSettingReq modifyUserSettingReq = WFCMessage.ModifyUserSettingReq.newBuilder().setScope(kUserSettingMyChannels).setKey(request.getId()).setValue("0").build();
|
||||
mServer.internalRpcMsg(fromUser, null, modifyUserSettingReq.toByteArray(), 0, fromUser, PutUserSettingTopic);
|
||||
mServer.internalRpcMsg(fromUser, null, modifyUserSettingReq.toByteArray(), 0, fromUser, PutUserSettingTopic, false);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ import java.util.List;
|
||||
@Handler(IMTopic.FriendPullTopic)
|
||||
public class FriendPullHandler extends IMHandler<WFCMessage.Version> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
List<FriendData> friendDatas = m_messagesStore.getFriendList(fromUser, request.getVersion());
|
||||
WFCMessage.GetFriendsResult.Builder builder = WFCMessage.GetFriendsResult.newBuilder();
|
||||
for (FriendData data : friendDatas
|
||||
) {
|
||||
builder.addEntry(WFCMessage.Friend.newBuilder().setState(data.getState()).setUid(data.getFriendUid()).setUpdateDt(data.getTimestamp()).build());
|
||||
builder.addEntry(WFCMessage.Friend.newBuilder().setState(data.getState()).setUid(data.getFriendUid()).setUpdateDt(data.getTimestamp()).setAlias(data.getAlias()).build());
|
||||
}
|
||||
byte[] data = builder.build().toByteArray();
|
||||
ackPayload.ensureWritable(data.length).writeBytes(data);
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
@Handler(IMTopic.FriendRequestPullTopic)
|
||||
public class FriendRequestPullHandler extends IMHandler<WFCMessage.Version> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
List<WFCMessage.FriendRequest> friendDatas = m_messagesStore.getFriendRequestList(fromUser, request.getVersion());
|
||||
WFCMessage.GetFriendRequestResult.Builder builder = WFCMessage.GetFriendRequestResult.newBuilder();
|
||||
builder.addAllEntry(friendDatas);
|
||||
|
||||
@@ -17,7 +17,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.ChannelPullTopic)
|
||||
public class GetChannelInfoHandler extends IMHandler<WFCMessage.PullChannelInfo> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.PullChannelInfo request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.PullChannelInfo request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
WFCMessage.ChannelInfo info = m_messagesStore.getChannelInfo(request.getChannelId());
|
||||
if (info == null) {
|
||||
|
||||
@@ -17,7 +17,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.GetChatroomInfoTopic)
|
||||
public class GetChatroomInfoHandler extends IMHandler<WFCMessage.GetChatroomInfoRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.GetChatroomInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.GetChatroomInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
WFCMessage.ChatroomInfo info = m_messagesStore.getChatroomInfo(request.getChatroomId());
|
||||
if (info == null) {
|
||||
|
||||
@@ -17,7 +17,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.GetChatroomMemberTopic)
|
||||
public class GetChatroomMemberHandler extends IMHandler<WFCMessage.GetChatroomMemberInfoRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.GetChatroomMemberInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.GetChatroomMemberInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
WFCMessage.ChatroomMemberInfo info = m_messagesStore.getChatroomMemberInfo(request.getChatroomId(), request.getMaxCount());
|
||||
if (info != null) {
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
@Handler(IMTopic.GetGroupInfoTopic)
|
||||
public class GetGroupInfoHandler extends IMHandler<WFCMessage.PullUserRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.PullUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.PullUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
List<WFCMessage.GroupInfo> infos = m_messagesStore.getGroupInfos(request.getRequestList());
|
||||
|
||||
WFCMessage.PullGroupInfoResult result = WFCMessage.PullGroupInfoResult.newBuilder().addAllInfo(infos).build();
|
||||
|
||||
@@ -22,7 +22,7 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.GetGroupMemberTopic)
|
||||
public class GetGroupMemberHandler extends IMHandler<WFCMessage.PullGroupMemberRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.PullGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.PullGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
List<WFCMessage.GroupMember> members = new ArrayList<>();
|
||||
ErrorCode errorCode = m_messagesStore.getGroupMembers(request.getTarget(), request.getHead(), members);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.GetQiniuUploadTokenTopic)
|
||||
public class GetQiniuUploadTokenHandler extends IMHandler<Byte> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, Byte request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, Byte request, Qos1PublishHandler.IMCallback callback) {
|
||||
int type = request;
|
||||
String token;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.GetTokenTopic)
|
||||
public class GetTokenHandler extends IMHandler<WFCMessage.GetTokenRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.GetTokenRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.GetTokenRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
MemorySessionStore.Session session = m_sessionsStore.createUserSession(fromUser, clientID);
|
||||
TokenAuthenticator authenticator = new TokenAuthenticator();
|
||||
String strToken = authenticator.generateToken(fromUser);
|
||||
|
||||
@@ -19,7 +19,7 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.GetUserInfoTopic)
|
||||
public class GetUserInfoHandler extends IMHandler<WFCMessage.PullUserRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.PullUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.PullUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
WFCMessage.PullUserResult.Builder resultBuilder = WFCMessage.PullUserResult.newBuilder();
|
||||
|
||||
ErrorCode errorCode = m_messagesStore.getUserInfo(request.getRequestList(), resultBuilder);
|
||||
|
||||
@@ -19,7 +19,7 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.GetUserSettingTopic)
|
||||
public class GetUserSettingHandler extends IMHandler<WFCMessage.Version> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
WFCMessage.GetUserSettingResult.Builder builder = WFCMessage.GetUserSettingResult.newBuilder();
|
||||
ErrorCode errorCode = m_messagesStore.getUserSettings(fromUser, request.getVersion(), builder);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.HandleFriendRequestTopic)
|
||||
public class HandleFriendRequestHandler extends IMHandler<WFCMessage.HandleFriendRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.HandleFriendRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.HandleFriendRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
WFCMessage.Message.Builder builder = WFCMessage.Message.newBuilder();
|
||||
builder.setFromUser(request.getTargetUid());
|
||||
long[] heads = new long[2];
|
||||
|
||||
@@ -89,8 +89,8 @@ abstract public class IMHandler<T> {
|
||||
for (Method method : getClass().getDeclaredMethods()
|
||||
) {
|
||||
|
||||
if (method.getName() == actionName && method.getParameterCount() == 5) {
|
||||
dataCls = method.getParameterTypes()[3];
|
||||
if (method.getName() == actionName && method.getParameterCount() == 6) {
|
||||
dataCls = method.getParameterTypes()[4];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ abstract public class IMHandler<T> {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
public void doHandler(String clientID, String fromUser, String topic, byte[] payloadContent, Qos1PublishHandler.IMCallback callback) {
|
||||
public void doHandler(String clientID, String fromUser, String topic, byte[] payloadContent, Qos1PublishHandler.IMCallback callback, boolean isAdmin) {
|
||||
m_imBusinessExecutor.execute(() -> {
|
||||
Qos1PublishHandler.IMCallback callbackWrapper = new Qos1PublishHandler.IMCallback() {
|
||||
@Override
|
||||
@@ -191,7 +191,7 @@ abstract public class IMHandler<T> {
|
||||
|
||||
try {
|
||||
LOG.debug("execute handler for topic {}", topic);
|
||||
errorCode = action(ackPayload, clientID, fromUser, getDataObject(payloadContent), callbackWrapper);
|
||||
errorCode = action(ackPayload, clientID, fromUser, isAdmin, getDataObject(payloadContent), callbackWrapper);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
@@ -234,7 +234,7 @@ abstract public class IMHandler<T> {
|
||||
|
||||
|
||||
@ActionMethod
|
||||
abstract public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, T request, Qos1PublishHandler.IMCallback callback) ;
|
||||
abstract public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, T request, Qos1PublishHandler.IMCallback callback) ;
|
||||
|
||||
public void afterAction(String clientID, String fromUser, String topic, Qos1PublishHandler.IMCallback callback) {
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.JoinChatroomTopic)
|
||||
public class JoinChatroomHandler extends IMHandler<WFCMessage.IDBuf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
return m_messagesStore.handleJoinChatroom(fromUser, clientID, request.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static win.liyufan.im.IMTopic.KickoffGroupMemberTopic;
|
||||
@Handler(value = KickoffGroupMemberTopic)
|
||||
public class KickoffGroupMember extends GroupHandler<WFCMessage.RemoveGroupMemberRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.RemoveGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.RemoveGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode;
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
if (groupInfo == null) {
|
||||
@@ -32,7 +32,7 @@ public class KickoffGroupMember extends GroupHandler<WFCMessage.RemoveGroupMembe
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(fromUser, null, request.getRemovedMemberList()).getKickokfMemberGroupNotifyContent();
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, request.getRemovedMemberList()).getKickokfMemberGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.kickoffGroupMembers(fromUser, request.getGroupId(), request.getRemovedMemberList());
|
||||
|
||||
@@ -18,10 +18,14 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(value = IMTopic.LoadRemoteMessagesTopic)
|
||||
public class LoadRemoteMessagesHandler extends IMHandler<WFCMessage.LoadRemoteMessages> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.LoadRemoteMessages request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.LoadRemoteMessages request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
WFCMessage.PullMessageResult result = m_messagesStore.loadRemoteMessages(fromUser, request.getConversation(), request.getBeforeUid(), request.getCount());
|
||||
long beforeUid = request.getBeforeUid();
|
||||
if (beforeUid == 0) {
|
||||
beforeUid = Long.MAX_VALUE;
|
||||
}
|
||||
WFCMessage.PullMessageResult result = m_messagesStore.loadRemoteMessages(fromUser, request.getConversation(), beforeUid, request.getCount());
|
||||
byte[] data = result.toByteArray();
|
||||
LOG.info("User {} load message with count({}), payload size({})", fromUser, result.getMessageCount(), data.length);
|
||||
ackPayload.ensureWritable(data.length).writeBytes(data);
|
||||
|
||||
@@ -23,7 +23,7 @@ import static win.liyufan.im.IMTopic.ModifyGroupInfoTopic;
|
||||
@Handler(value = ModifyChannelInfoTopic)
|
||||
public class ModifyChannelInfoHandler extends GroupHandler<WFCMessage.ModifyChannelInfo> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.ModifyChannelInfo request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ModifyChannelInfo request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode= m_messagesStore.modifyChannelInfo(fromUser, request.getChannelId(), request.getType(), request.getValue());
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.ModifyGroupAliasTopic)
|
||||
public class ModifyGroupAliasHandler extends GroupHandler<WFCMessage.ModifyGroupMemberAlias> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.ModifyGroupMemberAlias request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ModifyGroupMemberAlias request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.modifyGroupAlias(fromUser, request.getGroupId(), request.getAlias());
|
||||
if (errorCode == ERROR_CODE_SUCCESS && request.hasNotifyContent()) {
|
||||
if (request.hasNotifyContent()&& request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(fromUser, request.getAlias(), "").getModifyGroupMemberAliasNotifyContent();
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getAlias(), "").getModifyGroupMemberAliasNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import static win.liyufan.im.IMTopic.ModifyGroupInfoTopic;
|
||||
@Handler(value = ModifyGroupInfoTopic)
|
||||
public class ModifyGroupInfoHandler extends GroupHandler<WFCMessage.ModifyGroupInfoRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.ModifyGroupInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ModifyGroupInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode= m_messagesStore.modifyGroupInfo(fromUser, request.getGroupId(), request.getType(), request.getValue());
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
@@ -30,9 +30,9 @@ public class ModifyGroupInfoHandler extends GroupHandler<WFCMessage.ModifyGroupI
|
||||
} else {
|
||||
WFCMessage.MessageContent content = null;
|
||||
if (request.getType() == Modify_Group_Name) {
|
||||
content = new GroupNotificationBinaryContent(fromUser, request.getValue(), "").getChangeGroupNameNotifyContent();
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getValue(), "").getChangeGroupNameNotifyContent();
|
||||
} else if(request.getType() == Modify_Group_Portrait) {
|
||||
content = new GroupNotificationBinaryContent(fromUser, null, "").getChangeGroupPortraitNotifyContent();
|
||||
content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, "").getChangeGroupPortraitNotifyContent();
|
||||
}
|
||||
|
||||
if (content != null) {
|
||||
|
||||
@@ -17,7 +17,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.ModifyMyInfoTopic)
|
||||
public class ModifyMyInfoHandler extends IMHandler<WFCMessage.ModifyMyInfoRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.ModifyMyInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ModifyMyInfoRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
return m_messagesStore.modifyUserInfo(fromUser, request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(value = IMTopic.PullMessageTopic)
|
||||
public class PullMessageHandler extends IMHandler<WFCMessage.PullMessageRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.PullMessageRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.PullMessageRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
if (request.getType() == ProtoConstants.PullType.Pull_ChatRoom && !m_messagesStore.checkUserClientInChatroom(fromUser, clientID, null)) {
|
||||
|
||||
@@ -17,7 +17,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.PutUserSettingTopic)
|
||||
public class PutUserSettingHandler extends IMHandler<WFCMessage.ModifyUserSettingReq> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.ModifyUserSettingReq request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.ModifyUserSettingReq request, Qos1PublishHandler.IMCallback callback) {
|
||||
long timestamp = m_messagesStore.updateUserSettings(fromUser, request);
|
||||
publisher.publishNotification(IMTopic.NotifyUserSettingTopic, fromUser, timestamp);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@@ -17,7 +17,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.QuitChatroomTopic)
|
||||
public class QuitChatroomHandler extends IMHandler<WFCMessage.IDBuf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
m_messagesStore.handleQuitChatroom(fromUser, clientID, request.getId());
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static win.liyufan.im.IMTopic.QuitGroupTopic;
|
||||
@Handler(value = QuitGroupTopic)
|
||||
public class QuitGroupHandler extends GroupHandler<WFCMessage.QuitGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.QuitGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.QuitGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
if (groupInfo == null) {
|
||||
@@ -29,7 +29,7 @@ public class QuitGroupHandler extends GroupHandler<WFCMessage.QuitGroupRequest>
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, groupInfo.getTargetId(), request.getToLineList(), request.getNotifyContent());
|
||||
} else {
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(fromUser, null, "").getQuitGroupNotifyContent();
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, "").getQuitGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.quitGroup(fromUser, request.getGroupId());
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Set;
|
||||
@Handler(value = IMTopic.RecallMessageTopic)
|
||||
public class RecallMessageHandler extends IMHandler<WFCMessage.INT64Buf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.INT64Buf int64Buf, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.INT64Buf int64Buf, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.recallMessage(int64Buf.getId(), fromUser);
|
||||
|
||||
if(errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import static io.moquette.BrokerConstants.HZ_Cluster_Node_External_Short_Port;
|
||||
@Handler(IMTopic.RouteTopic)
|
||||
public class RouteHandler extends IMHandler<WFCMessage.RouteRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.RouteRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.RouteRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
Member member = mServer.getHazelcastInstance().getCluster().getLocalMember();
|
||||
String serverIp = member.getStringAttribute(HZ_Cluster_Node_External_IP);
|
||||
String longPort = member.getStringAttribute(HZ_Cluster_Node_External_Long_Port);
|
||||
|
||||
@@ -43,69 +43,68 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.Message message, Qos1PublishHandler.IMCallback callback) {
|
||||
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) {
|
||||
int userStatus = m_messagesStore.getUserStatus(fromUser);
|
||||
if (userStatus == 1 || userStatus == 2) {
|
||||
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG;
|
||||
}
|
||||
if (!isAdmin) { //admin do not check the right
|
||||
int userStatus = m_messagesStore.getUserStatus(fromUser);
|
||||
if (userStatus == 1 || userStatus == 2) {
|
||||
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG;
|
||||
}
|
||||
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private) {
|
||||
if (m_messagesStore.isBlacked(message.getConversation().getTarget(), fromUser)) {
|
||||
return ErrorCode.ERROR_CODE_IN_BLACK_LIST;
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private) {
|
||||
if (m_messagesStore.isBlacked(message.getConversation().getTarget(), fromUser)) {
|
||||
return ErrorCode.ERROR_CODE_IN_BLACK_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group && !m_messagesStore.isMemberInGroup(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group && m_messagesStore.isForbiddenInGroup(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
} 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_Channel && !m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
|
||||
}
|
||||
}
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group &&
|
||||
!m_messagesStore.isMemberInGroup(fromUser, message.getConversation().getTarget())) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group &&
|
||||
m_messagesStore.isForbiddenInGroup(fromUser, message.getConversation().getTarget())) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom &&
|
||||
!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_IN_CHATROOM;
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel &&
|
||||
!m_messagesStore.checkUserInChannel(fromUser, message.getConversation().getTarget())) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
|
||||
} else {
|
||||
long messageId = MessageShardingUtil.generateId();
|
||||
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).build();
|
||||
long messageId = MessageShardingUtil.generateId();
|
||||
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).build();
|
||||
|
||||
if (mForwardUrl != null) {
|
||||
publisher.forwardMessage(message, mForwardUrl);
|
||||
}
|
||||
if (mForwardUrl != null) {
|
||||
publisher.forwardMessage(message, mForwardUrl);
|
||||
}
|
||||
|
||||
boolean ignoreMsg = false;
|
||||
if (message.getContent().getType() == Text) {
|
||||
Set<String> matched = m_messagesStore.handleSensitiveWord(message.getContent().getSearchableContent());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
if (mSensitiveType == 0) {
|
||||
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
} else if(mSensitiveType == 1) {
|
||||
ignoreMsg = true;
|
||||
} else {
|
||||
String text = message.getContent().getSearchableContent();
|
||||
for (String word : matched) {
|
||||
text = text.replace(word, "***");
|
||||
}
|
||||
|
||||
message = message.toBuilder().setContent(message.getContent().toBuilder().setSearchableContent(text).build()).build();
|
||||
boolean ignoreMsg = false;
|
||||
if (!isAdmin && message.getContent().getType() == Text) {
|
||||
Set<String> matched = m_messagesStore.handleSensitiveWord(message.getContent().getSearchableContent());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
if (mSensitiveType == 0) {
|
||||
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
} else if(mSensitiveType == 1) {
|
||||
ignoreMsg = true;
|
||||
} else {
|
||||
String text = message.getContent().getSearchableContent();
|
||||
for (String word : matched) {
|
||||
text = text.replace(word, "***");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (!ignoreMsg) {
|
||||
saveAndPublish(fromUser, clientID, message);
|
||||
message = message.toBuilder().setContent(message.getContent().toBuilder().setSearchableContent(text).build()).build();
|
||||
}
|
||||
ackPayload = ackPayload.capacity(20);
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (!ignoreMsg) {
|
||||
saveAndPublish(fromUser, clientID, message);
|
||||
}
|
||||
ackPayload = ackPayload.capacity(20);
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(timestamp);
|
||||
}
|
||||
} else {
|
||||
errorCode = ErrorCode.ERROR_CODE_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.proto.WFCMessage;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.ErrorCode;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.SetFriendAliasTopic)
|
||||
public class SetFriendAliasRequestHandler extends GroupHandler<WFCMessage.AddFriendRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.AddFriendRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
long[] head = new long[1];
|
||||
ErrorCode errorCode = m_messagesStore.setFriendAliasRequest(fromUser, request.getTargetUid(), request.getReason(), head);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
publisher.publishNotification(IMTopic.NotifyFriendTopic, fromUser, head[0]);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.RriendRequestUnreadSyncTopic)
|
||||
public class SyncFriendRequestUnreadHandler extends GroupHandler<WFCMessage.Version> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.Version request, Qos1PublishHandler.IMCallback callback) {
|
||||
long[] head = new long[1];
|
||||
ErrorCode errorCode = m_messagesStore.SyncFriendRequestUnread(fromUser, request.getVersion(), head);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.TransferChannelInfoTopic)
|
||||
public class TransferChannelHandler extends GroupHandler<WFCMessage.TransferChannel> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.TransferChannel request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.TransferChannel request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.transferChannel(fromUser, request.getChannelId(), request.getNewOwner());
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
@Handler(IMTopic.TransferGroupTopic)
|
||||
public class TransferGroupHandler extends GroupHandler<WFCMessage.TransferGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.TransferGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.TransferGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.transferGroup(fromUser, request.getGroupId(), request.getNewOwner());
|
||||
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(fromUser, null, request.getNewOwner()).getTransferGroupNotifyContent();
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, null, request.getNewOwner()).getTransferGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import win.liyufan.im.IMTopic;
|
||||
@Handler(IMTopic.UploadDeviceTokenTopic)
|
||||
public class UploadDeviceTokenHandler extends IMHandler<WFCMessage.UploadDeviceTokenRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.UploadDeviceTokenRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.UploadDeviceTokenRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
MemorySessionStore.Session session = m_sessionsStore.getSession(clientID);
|
||||
session.setPlatform(request.getPlatform());
|
||||
session.setAppName(request.getAppName());
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
@Handler(IMTopic.UserSearchTopic)
|
||||
public class UserSearchHandler extends IMHandler<WFCMessage.SearchUserRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, WFCMessage.SearchUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.SearchUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
List<WFCMessage.User> users = m_messagesStore.searchUser(request.getKeyword(), request.getFuzzy() > 0, request.getPage());
|
||||
WFCMessage.SearchUserResult.Builder builder = WFCMessage.SearchUserResult.newBuilder();
|
||||
builder.addAllEntry(users);
|
||||
|
||||
@@ -272,7 +272,7 @@ public class DatabaseStore {
|
||||
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `_uid`, `_friend_uid`, `_state`, `_dt` from t_friend";
|
||||
String sql = "select `_uid`, `_friend_uid`, `_alias`, `_state`, `_dt` from t_friend";
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
int index;
|
||||
@@ -290,6 +290,9 @@ public class DatabaseStore {
|
||||
value = (value == null ? "" : value);
|
||||
builder.setFriendUid(value);
|
||||
|
||||
value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
builder.setAlias(value);
|
||||
|
||||
int intvalue = rs.getInt(index++);
|
||||
builder.setState(intvalue);
|
||||
@@ -537,23 +540,25 @@ public class DatabaseStore {
|
||||
List<WFCMessage.Message> messages = loadRemoteMessagesFromTable(user, conversation, beforeUid, count, MessageShardingUtil.getMessageTable(beforeUid));
|
||||
if (messages != null && messages.size() < count) {
|
||||
String nexTable = MessageShardingUtil.getPreviousMessageTable(beforeUid);
|
||||
List<WFCMessage.Message> nextMessages = loadRemoteMessagesFromTable(user, conversation, beforeUid, count-messages.size(), nexTable);
|
||||
if (nextMessages != null) {
|
||||
messages.addAll(nextMessages);
|
||||
if (!StringUtil.isNullOrEmpty(nexTable)) {
|
||||
List<WFCMessage.Message> nextMessages = loadRemoteMessagesFromTable(user, conversation, beforeUid, count - messages.size(), nexTable);
|
||||
if (nextMessages != null) {
|
||||
messages.addAll(nextMessages);
|
||||
}
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
List<WFCMessage.Message> loadRemoteMessagesFromTable(String user, WFCMessage.Conversation conversation, long beforeUid, int count, String table) {
|
||||
String sql = "select `_from`, `_type`, `_target`, `_line`, `_data`, `_dt` from " + table +" where";
|
||||
String sql = "select `_mid`, `_from`, `_type`, `_target`, `_line`, `_data`, `_dt` from " + table +" where";
|
||||
if (conversation.getType() == ProtoConstants.ConversationType.ConversationType_Private) {
|
||||
sql += " _type = ? and _line = ? and _mid > ? and ((_target = ? and _from = ?) or (_target = ? and _from = ?)";
|
||||
sql += " _type = ? and _line = ? and _mid < ? and ((_target = ? and _from = ?) or (_target = ? and _from = ?))";
|
||||
} else {
|
||||
sql += " _type = ? and _line = ? and _mid > ? and _target = ?";
|
||||
sql += " _type = ? and _line = ? and _mid < ? and _target = ?";
|
||||
}
|
||||
|
||||
sql += " limit ?";
|
||||
sql += "order by `_mid` DESC limit ?";
|
||||
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
@@ -598,7 +603,7 @@ public class DatabaseStore {
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement, resultSet);
|
||||
}
|
||||
return null;
|
||||
return out;
|
||||
}
|
||||
|
||||
void persistUserMessage(final String userId, final long messageId, final long messageSeq) {
|
||||
@@ -1775,7 +1780,7 @@ public class DatabaseStore {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `_friend_uid`, `_state`, `_dt` from t_friend where `_uid` = ?";
|
||||
String sql = "select `_friend_uid`, `_alias`, `_state`, `_dt` from t_friend where `_uid` = ?";
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
|
||||
@@ -1787,10 +1792,11 @@ public class DatabaseStore {
|
||||
List<FriendData> out = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
String uid = rs.getString(1);
|
||||
int state = rs.getInt(2);
|
||||
long timestamp = rs.getLong(3);
|
||||
String alias = rs.getString(2);
|
||||
int state = rs.getInt(3);
|
||||
long timestamp = rs.getLong(4);
|
||||
|
||||
FriendData data = new FriendData(userId, uid, state, timestamp);
|
||||
FriendData data = new FriendData(userId, uid, alias, state, timestamp);
|
||||
out.add(data);
|
||||
}
|
||||
return out;
|
||||
@@ -1945,8 +1951,9 @@ public class DatabaseStore {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "insert into t_friend (`_uid`, `_friend_uid`, `_state`, `_dt`) values(?, ?, ?, ?)" +
|
||||
String sql = "insert into t_friend (`_uid`, `_friend_uid`, `_alias`, `_state`, `_dt`) values(?, ?, ?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE " +
|
||||
"`_alias` = ?," +
|
||||
"`_state` = ?," +
|
||||
"`_dt` = ?";
|
||||
|
||||
@@ -1955,8 +1962,10 @@ public class DatabaseStore {
|
||||
int index = 1;
|
||||
statement.setString(index++, request.getUserId());
|
||||
statement.setString(index++, request.getFriendUid());
|
||||
statement.setString(index++, request.getAlias());
|
||||
statement.setInt(index++, request.getState());
|
||||
statement.setLong(index++, request.getTimestamp());
|
||||
statement.setString(index++, request.getAlias());
|
||||
statement.setInt(index++, request.getState());
|
||||
statement.setLong(index++, request.getTimestamp());
|
||||
int count = statement.executeUpdate();
|
||||
|
||||
@@ -455,7 +455,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (lastEntry != null) {
|
||||
messageSeq = (lastEntry.getKey() + 1);
|
||||
}
|
||||
Long maxPullSeq = userMaxPullSeq.get(sender);
|
||||
Long maxPullSeq = userMaxPullSeq.get(user);
|
||||
if (maxPullSeq != null && maxPullSeq > messageSeq) {
|
||||
messageSeq = maxPullSeq + 1;
|
||||
}
|
||||
@@ -1567,11 +1567,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData1 = new FriendData(userId, request.getTargetUid(), 0, System.currentTimeMillis());
|
||||
FriendData friendData1 = new FriendData(userId, request.getTargetUid(), "", 0, System.currentTimeMillis());
|
||||
friendsMap.put(userId, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
|
||||
FriendData friendData2 = new FriendData(request.getTargetUid(), userId, 0, friendData1.getTimestamp());
|
||||
FriendData friendData2 = new FriendData(request.getTargetUid(), userId, "", 0, friendData1.getTimestamp());
|
||||
friendsMap.put(request.getTargetUid(), friendData2);
|
||||
databaseStore.persistOrUpdateFriendData(friendData2);
|
||||
|
||||
@@ -1588,15 +1588,58 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] heads) {
|
||||
public ErrorCode blackUserRequest(String fromUser, String targetUserId, int state, long[] heads) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData1 = new FriendData(fromUser, targetUserId, status, System.currentTimeMillis());
|
||||
friendsMap.put(fromUser, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
heads[0] = friendData1.getTimestamp();
|
||||
if (friendData == null) {
|
||||
friendData = new FriendData(fromUser, targetUserId, "", state, System.currentTimeMillis());
|
||||
}
|
||||
friendData.setState(state);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] heads){
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (friendData == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
friendData.setAlias(alias);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -368,10 +368,21 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
}
|
||||
|
||||
Session session = sessions.get(clientID);
|
||||
ClientSession clientSession = new ClientSession(clientID, this);
|
||||
return clientSession;
|
||||
|
||||
return session.getClientSession();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadUserSession(String username, String clientID) {
|
||||
if (sessions.containsKey(clientID)) {
|
||||
return;
|
||||
}
|
||||
Session session = databaseStore.getSession(username, clientID, new ClientSession(clientID, this));
|
||||
if (session != null) {
|
||||
sessions.put(clientID, session);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Session> sessionForUser(String username) {
|
||||
ConcurrentSkipListSet<String> sessionSet = userSessions.get(username);
|
||||
@@ -514,7 +525,7 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
|
||||
@Override
|
||||
public void cleanSession(String clientID) {
|
||||
LOG.error("Fooooooooo <{}>", clientID);
|
||||
LOG.info("Fooooooooo <{}>", clientID);
|
||||
|
||||
Session session = sessions.get(clientID);
|
||||
if (session == null) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class RPCCenter {
|
||||
|
||||
protected RPCCenter() {}
|
||||
|
||||
public void sendRequest(String fromUser, String clientId, String request, byte[] message, String target, TargetEntry.Type type, Callback callback) {
|
||||
public void sendRequest(String fromUser, String clientId, String request, byte[] message, String target, TargetEntry.Type type, Callback callback, boolean isAdmin) {
|
||||
int requestId = 0;
|
||||
|
||||
if (callback != null) {
|
||||
@@ -61,7 +61,7 @@ public class RPCCenter {
|
||||
requestMap.put(requestId, new RequestInfo(fromUser, clientId, callback, message, requestId, request));
|
||||
}
|
||||
|
||||
server.internalRpcMsg(fromUser, clientId, message, requestId, "", request);
|
||||
server.internalRpcMsg(fromUser, clientId, message, requestId, "", request, isAdmin);
|
||||
}
|
||||
|
||||
public void sendResponse(int errorCode, byte[] message, String toUuid, int requestId) {
|
||||
|
||||
@@ -370,7 +370,8 @@ public class Server {
|
||||
throw new IllegalArgumentException("nodeId error: " + nodeIdStr);
|
||||
}
|
||||
if (nodeIdSet != null && nodeIdSet.contains(nodeId)){
|
||||
throw new IllegalArgumentException("nodeId conflict " + nodeId + ", 请修改wildfirechat.conf文件,是各个节点的nodeId不冲突");
|
||||
LOG.error("只允许一个实例运行,多个实例会引起冲突,进程终止");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
MessageShardingUtil.setNodeId(nodeId);
|
||||
@@ -389,14 +390,14 @@ public class Server {
|
||||
return hazelcastInstance;
|
||||
}
|
||||
|
||||
public void internalRpcMsg(String fromUser, String clientId, byte[] message, int messageId, String from, String request) {
|
||||
public void internalRpcMsg(String fromUser, String clientId, byte[] message, int messageId, String from, String request, boolean isAdmin) {
|
||||
|
||||
if (!m_initialized) {
|
||||
LOG.error("Moquette is not started, internal message cannot be notify");
|
||||
return;
|
||||
}
|
||||
LOG.debug("internalNotifyMsg");
|
||||
m_processor.onRpcMsg(fromUser, clientId, message, messageId, from, request);
|
||||
m_processor.onRpcMsg(fromUser, clientId, message, messageId, from, request, isAdmin);
|
||||
}
|
||||
|
||||
public void stopServer() {
|
||||
|
||||
@@ -157,6 +157,7 @@ public interface IMessagesStore {
|
||||
ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
|
||||
ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] head);
|
||||
boolean isBlacked(String fromUser, String userId);
|
||||
ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
|
||||
|
||||
ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId);
|
||||
ErrorCode handleQuitChatroom(String userId, String clientId, String chatroomId);
|
||||
|
||||
@@ -57,6 +57,8 @@ public interface ISessionsStore {
|
||||
Session sessionForClientAndUser(String username, String clientID);
|
||||
|
||||
ClientSession sessionForClient(String clientID);
|
||||
|
||||
void loadUserSession(String username, String clientID);
|
||||
|
||||
Collection<Session> sessionForUser(String username);
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ public class MessagesPublisher {
|
||||
}
|
||||
|
||||
if (pullType == ProtoConstants.PullType.Pull_ChatRoom) {
|
||||
if (exceptClientId.equals(targetSession.getClientID())) {
|
||||
if (exceptClientId != null && exceptClientId.equals(targetSession.getClientID())) {
|
||||
targetSession.refreshLastChatroomActiveTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -343,7 +343,7 @@ public class ProtocolProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
m_sessionsStore.loadUserSession(username, clientId);
|
||||
ClientSession clientSession = m_sessionsStore.sessionForClient(clientId);
|
||||
boolean isSessionAlreadyStored = clientSession != null;
|
||||
if (isSessionAlreadyStored) {
|
||||
@@ -608,12 +608,12 @@ public class ProtocolProcessor {
|
||||
return m_sessionsStore;
|
||||
}
|
||||
|
||||
public void onRpcMsg(String fromUser, String clientId, byte[] message, int messageId, String from, String request) {
|
||||
public void onRpcMsg(String fromUser, String clientId, byte[] message, int messageId, String from, String request, boolean isAdmin) {
|
||||
if(request.equals(RPCCenter.KICKOFF_USER_REQUEST)) {
|
||||
mServer.getImBusinessScheduler().execute(()->handleTargetRemovedFromCurrentNode(new TargetEntry(TargetEntry.Type.TARGET_TYPE_USER, from)));
|
||||
return;
|
||||
}
|
||||
qos1PublishHandler.onRpcMsg(fromUser, clientId, message, messageId, from, request);
|
||||
qos1PublishHandler.onRpcMsg(fromUser, clientId, message, messageId, from, request, isAdmin);
|
||||
}
|
||||
public void shutdown() {
|
||||
messagesPublisher.stopChatroomScheduler();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user