Skip to content

Commit

Permalink
处理同一个设备多个用户登录的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
imhao183 committed Mar 11, 2021
1 parent 2cbbf0a commit 19bd5e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions broker/src/main/java/io/moquette/persistence/DatabaseStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,35 @@ void clearMultiEndpoint(String uid, String clientId, int platform) {
}
}

void clearMultiUser(String uid, String clientId) {
long start = System.currentTimeMillis();
LOG.info("clearMultiUser {}, {}", uid, clientId);
Connection connection = null;
PreparedStatement statement = null;
try {
connection = DBUtil.getConnection();
String sql = "update t_user_session set _deleted = ?, _token = ?, _voip_token = ?, _dt = ? where _cid = ? and _uid <> ? and _deleted = 0";

statement = connection.prepareStatement(sql);
int index = 1;
statement.setInt(index++, 1);
statement.setString(index++, "");
statement.setString(index++, "");
statement.setLong(index++, System.currentTimeMillis());

statement.setString(index++, clientId);
statement.setString(index++, uid);
int count = statement.executeUpdate();
LOG.info("Update rows {}", count);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Utility.printExecption(LOG, e, RDBS_Exception);
} finally {
DBUtil.closeDB(connection, statement);
}
}

MemorySessionStore.Session createSession(String uid, String clientId, ClientSession clientSession, int platform) {
Connection connection = null;
PreparedStatement statement = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public Session updateOrCreateUserSession(String username, String clientID, int p
session.setPlatform(platform);
databaseStore.updateSessionPlatform(username, clientID, platform);
}

databaseStore.clearMultiUser(username, clientID);

if (!supportMultiEndpoint && platform > 0) {
databaseStore.clearMultiEndpoint(username, clientID, platform);
Expand Down

0 comments on commit 19bd5e8

Please sign in to comment.