From c4084cbcec7c9d1b856de3156029d6f5c0f305e3 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 11 Aug 2022 15:55:33 +0800 Subject: [PATCH] callback kickoff --- config/config.yaml | 3 +++ internal/msg_gateway/gate/callback.go | 25 +++++++++++++++++++++++++ internal/msg_gateway/gate/ws_server.go | 4 ++++ pkg/call_back_struct/msg_gateway.go | 9 +++++++++ pkg/common/config/config.go | 1 + pkg/common/constant/constant.go | 1 + 6 files changed, 43 insertions(+) diff --git a/config/config.yaml b/config/config.yaml index fc76e3615..400f6e6aa 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -299,6 +299,9 @@ callback: callbackUserOffline: enable: false callbackTimeOut: 2 + callbackUserKickOff: + enable: false + callbackTimeOut: 2 callbackOfflinePush: enable: false callbackTimeOut: 2 diff --git a/internal/msg_gateway/gate/callback.go b/internal/msg_gateway/gate/callback.go index 9df9c6373..e0498f615 100644 --- a/internal/msg_gateway/gate/callback.go +++ b/internal/msg_gateway/gate/callback.go @@ -59,3 +59,28 @@ func callbackUserOffline(operationID, userID string, platformID int) cbApi.Commo } return callbackResp } + +func callbackUserKickOff(operationID string, userID string, platformID int) cbApi.CommonCallbackResp { + callbackResp := cbApi.CommonCallbackResp{OperationID: operationID} + if !config.Config.Callback.CallbackUserKickOff.Enable { + return callbackResp + } + callbackUserKickOffReq := cbApi.CallbackUserKickOffReq{ + UserStatusCallbackReq: cbApi.UserStatusCallbackReq{ + UserStatusBaseCallback: cbApi.UserStatusBaseCallback{ + CallbackCommand: constant.CallbackUserKickOffCommand, + OperationID: operationID, + PlatformID: int32(platformID), + Platform: constant.PlatformIDToName(platformID), + }, + UserID: userID, + }, + Seq: int(time.Now().UnixNano() / 1e6), + } + callbackUserKickOffResp := &cbApi.CallbackUserKickOffResp{CommonCallbackResp: callbackResp} + if err := http.PostReturn(config.Config.Callback.CallbackUrl, callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil { + callbackResp.ErrCode = http2.StatusInternalServerError + callbackResp.ErrMsg = err.Error() + } + return callbackResp +} diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index c92aa6a28..aa165e572 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -233,6 +233,10 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int, newConn if err != nil { log.NewError(operationID, "conn close err", err.Error(), uid, platformID) } + callbackResp := callbackUserKickOff(operationID, uid, platformID) + if callbackResp.ErrCode != 0 { + log.NewError(operationID, utils.GetSelfFuncName(), "callbackUserOffline failed", callbackResp) + } } else { log.NewWarn(operationID, "normal uid-conn ", uid, platformID, oldConnMap[platformID]) } diff --git a/pkg/call_back_struct/msg_gateway.go b/pkg/call_back_struct/msg_gateway.go index 2fba45114..5dbf9809b 100644 --- a/pkg/call_back_struct/msg_gateway.go +++ b/pkg/call_back_struct/msg_gateway.go @@ -18,3 +18,12 @@ type CallbackUserOfflineReq struct { type CallbackUserOfflineResp struct { CommonCallbackResp } + +type CallbackUserKickOffReq struct { + UserStatusCallbackReq + Seq int `json:"seq"` +} + +type CallbackUserKickOffResp struct { + CommonCallbackResp +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 29779116e..53082d375 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -264,6 +264,7 @@ type config struct { CallbackWordFilter callBackConfig `yaml:"callbackWordFilter"` CallbackUserOnline callBackConfig `yaml:"callbackUserOnline"` CallbackUserOffline callBackConfig `yaml:"callbackUserOffline"` + CallbackUserKickOff callBackConfig `yaml:"callbackUserKickOff"` CallbackOfflinePush callBackConfig `yaml:"callbackOfflinePush"` CallbackOnlinePush callBackConfig `yaml:"callbackOnlinePush"` CallbackBeforeSuperGroupOnlinePush callBackConfig `yaml:"callbackSuperGroupOnlinePush"` diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 0eab7c022..b81cb07d6 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -200,6 +200,7 @@ const ( CallbackWordFilterCommand = "callbackWordFilterCommand" CallbackUserOnlineCommand = "callbackUserOnlineCommand" CallbackUserOfflineCommand = "callbackUserOfflineCommand" + CallbackUserKickOffCommand = "callbackUserKickOffCommand" CallbackOfflinePushCommand = "callbackOfflinePushCommand" CallbackOnlinePushCommand = "callbackOnlinePushCommand" CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand"