添加踢用户下线api接口
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.xiaoleilu.loServer.action.admin;
|
||||||
|
|
||||||
|
import cn.wildfirechat.common.APIPath;
|
||||||
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
import cn.wildfirechat.pojos.InputOutputUserBlockStatus;
|
||||||
|
import cn.wildfirechat.pojos.StringPairPojo;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.xiaoleilu.loServer.RestResult;
|
||||||
|
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||||
|
import com.xiaoleilu.loServer.annotation.Route;
|
||||||
|
import com.xiaoleilu.loServer.handler.Request;
|
||||||
|
import com.xiaoleilu.loServer.handler.Response;
|
||||||
|
import io.moquette.persistence.RPCCenter;
|
||||||
|
import io.moquette.persistence.TargetEntry;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Kickoff_Client)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class KickoffUserClientAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
StringPairPojo pojo = getRequestBody(request.getNettyRequest(), StringPairPojo.class);
|
||||||
|
if (pojo != null && !StringUtil.isNullOrEmpty(pojo.getFirst())) {
|
||||||
|
sessionsStore.kickoffUserClient(pojo.getFirst(), pojo.getSecond());
|
||||||
|
sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, null);
|
||||||
|
} else {
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -419,6 +419,34 @@ public class MemorySessionStore implements ISessionsStore {
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void kickoffUserClient(String username, String cid) {
|
||||||
|
List<String> clientIds = new ArrayList<>();
|
||||||
|
if(StringUtil.isNullOrEmpty(cid)) {
|
||||||
|
ConcurrentSkipListSet<String> sessionSet = getUserSessionSet(username);
|
||||||
|
clientIds.addAll(sessionSet);
|
||||||
|
} else {
|
||||||
|
clientIds.add(cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String clientID: clientIds) {
|
||||||
|
Session session = sessions.get(clientID);
|
||||||
|
if(session == null) {
|
||||||
|
ClientSession clientSession = new ClientSession(clientID, this);
|
||||||
|
session = databaseStore.getSession(username, clientID, clientSession);
|
||||||
|
if (session == null || session.getDeleted() > 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sessions.put(clientID, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.getDeleted() == 0) {
|
||||||
|
session.setDeleted(1);
|
||||||
|
databaseStore.updateSessionDeleted(username, clientID, 1);
|
||||||
|
mServer.getProcessor().kickoffSession(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode loadActiveSession(String username, String clientID) {
|
public ErrorCode loadActiveSession(String username, String clientID) {
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public interface ISessionsStore {
|
|||||||
void updateSessionToken(Session session, boolean voip);
|
void updateSessionToken(Session session, boolean voip);
|
||||||
|
|
||||||
void clearUserSession(String username);
|
void clearUserSession(String username);
|
||||||
|
|
||||||
|
void kickoffUserClient(String userId, String clientId);
|
||||||
/**
|
/**
|
||||||
* @param clientID
|
* @param clientID
|
||||||
* the client owning the session.
|
* the client owning the session.
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public interface APIPath {
|
|||||||
String User_Get_Online_Status = "/admin/user/onlinestatus";
|
String User_Get_Online_Status = "/admin/user/onlinestatus";
|
||||||
String User_Put_Setting = "/admin/user/put_setting";
|
String User_Put_Setting = "/admin/user/put_setting";
|
||||||
String User_Get_Setting = "/admin/user/get_setting";
|
String User_Get_Setting = "/admin/user/get_setting";
|
||||||
|
String User_Kickoff_Client = "/admin/user/kickoff_client";
|
||||||
|
|
||||||
String Friend_Update_Status = "/admin/friend/status";
|
String Friend_Update_Status = "/admin/friend/status";
|
||||||
String Friend_Get_List = "/admin/friend/list";
|
String Friend_Get_List = "/admin/friend/list";
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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 cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
public class StringPairPojo {
|
||||||
|
private String first;
|
||||||
|
private String second;
|
||||||
|
|
||||||
|
public StringPairPojo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringPairPojo(String first, String second) {
|
||||||
|
this.first = first;
|
||||||
|
this.second = second;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirst() {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirst(String first) {
|
||||||
|
this.first = first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecond() {
|
||||||
|
return second;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecond(String second) {
|
||||||
|
this.second = second;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,6 +63,15 @@ public class UserAdmin {
|
|||||||
return AdminHttpUtils.httpJsonPost(path, getUserInfo, OutputCheckUserOnline.class);
|
return AdminHttpUtils.httpJsonPost(path, getUserInfo, OutputCheckUserOnline.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 强迫用户下线,需要用户重新获取token才能进行连接。
|
||||||
|
userId必须有效,clientId可以为空,当为空时,踢下线说有客户端,当不为空时仅踢掉对应客户端。
|
||||||
|
*/
|
||||||
|
public static IMResult<Void> kickoffUserClient(String userId, String clientId) throws Exception {
|
||||||
|
String path = APIPath.User_Kickoff_Client;
|
||||||
|
StringPairPojo pojo = new StringPairPojo(userId, clientId);
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, pojo, Void.class);
|
||||||
|
}
|
||||||
|
|
||||||
public static IMResult<Void> destroyUser(String userId) throws Exception {
|
public static IMResult<Void> destroyUser(String userId) throws Exception {
|
||||||
String path = APIPath.Destroy_User;
|
String path = APIPath.Destroy_User;
|
||||||
InputDestroyUser inputDestroyUser = new InputDestroyUser();
|
InputDestroyUser inputDestroyUser = new InputDestroyUser();
|
||||||
|
|||||||
Reference in New Issue
Block a user