Compare commits

...

4 Commits

2 changed files with 64 additions and 78 deletions

View File

@ -315,10 +315,17 @@ func (ws *WsServer) KickUserConn(client *Client) error {
}
func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Client, newClient *Client) {
kickTokenFunc := func(kickClients []*Client) {
kickTokenFunc := func(kickClients []*Client, newClient *Client) {
var kickTokens []string
ws.clients.DeleteClients(newClient.UserID, kickClients)
for _, c := range kickClients {
// If reconnecting: When multiple msgGateway instances are deployed, a client may disconnect from instance A and reconnect to instance B.
// During this process, instance A might still be executing, resulting in two clients with the same token existing simultaneously.
// This situation needs to be filtered to prevent duplicate clients.
if c.token == newClient.token {
log.ZDebug(newClient.ctx, "token is same, not kick", "userID", newClient.UserID, "platformID", newClient.PlatformID, "token", newClient.token)
continue
}
kickTokens = append(kickTokens, c.token)
err := c.KickOnlineMessage()
if err != nil {
@ -334,27 +341,6 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
}
}
// If reconnect: When multiple msgGateway instances are deployed, a client may disconnect from instance A and reconnect to instance B.
// During this process, instance A might still be executing, resulting in two clients with the same token existing simultaneously.
// This situation needs to be filtered to prevent duplicate clients.
checkSameTokenFunc := func(oldClients []*Client) []*Client {
var clientsNeedToKick []*Client
for _, c := range oldClients {
if c.token == newClient.token {
log.ZDebug(newClient.ctx, "token is same, not kick",
"userID", newClient.UserID,
"platformID", newClient.PlatformID,
"token", newClient.token)
continue
}
clientsNeedToKick = append(clientsNeedToKick, c)
}
return clientsNeedToKick
}
switch ws.msgGatewayConfig.Share.MultiLogin.Policy {
case constant.DefalutNotKick:
case constant.PCAndOther:
@ -377,10 +363,11 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
return
}
oldClients = checkSameTokenFunc(oldClients)
ws.clients.DeleteClients(newClient.UserID, oldClients)
for _, c := range oldClients {
if c.token == newClient.token {
continue
}
err := c.KickOnlineMessage()
if err != nil {
log.ZWarn(c.ctx, "KickOnlineMessage", err)
@ -414,9 +401,8 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
}
}
}
kickClients = checkSameTokenFunc(kickClients)
kickTokenFunc(kickClients)
kickTokenFunc(kickClients, newClient)
}
}

View File

@ -2,42 +2,42 @@ package callbackstruct
type CallbackBeforeCreateSingleChatConversationsReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"owner_user_id"`
ConversationID string `json:"conversation_id"`
ConversationType int32 `json:"conversation_type"`
UserID string `json:"user_id"`
RecvMsgOpt int32 `json:"recv_msg_opt"`
IsPinned bool `json:"is_pinned"`
IsPrivateChat bool `json:"is_private_chat"`
BurnDuration int32 `json:"burn_duration"`
GroupAtType int32 `json:"group_at_type"`
AttachedInfo string `json:"attached_info"`
OwnerUserID string `json:"ownerUserId"`
ConversationID string `json:"conversationId"`
ConversationType int32 `json:"conversationType"`
UserID string `json:"userId"`
RecvMsgOpt int32 `json:"recvMsgOpt"`
IsPinned bool `json:"isPinned"`
IsPrivateChat bool `json:"isPrivateChat"`
BurnDuration int32 `json:"burnDuration"`
GroupAtType int32 `json:"groupAtType"`
AttachedInfo string `json:"attachedInfo"`
Ex string `json:"ex"`
}
type CallbackBeforeCreateSingleChatConversationsResp struct {
CommonCallbackResp
RecvMsgOpt *int32 `json:"recv_msg_opt"`
IsPinned *bool `json:"is_pinned"`
IsPrivateChat *bool `json:"is_private_chat"`
BurnDuration *int32 `json:"burn_duration"`
GroupAtType *int32 `json:"group_at_type"`
AttachedInfo *string `json:"attached_info"`
RecvMsgOpt *int32 `json:"recvMsgOpt"`
IsPinned *bool `json:"isPinned"`
IsPrivateChat *bool `json:"isPrivateChat"`
BurnDuration *int32 `json:"burnDuration"`
GroupAtType *int32 `json:"groupAtType"`
AttachedInfo *string `json:"attachedInfo"`
Ex *string `json:"ex"`
}
type CallbackAfterCreateSingleChatConversationsReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"owner_user_id"`
ConversationID string `json:"conversation_id"`
ConversationType int32 `json:"conversation_type"`
UserID string `json:"user_id"`
RecvMsgOpt int32 `json:"recv_msg_opt"`
IsPinned bool `json:"is_pinned"`
IsPrivateChat bool `json:"is_private_chat"`
BurnDuration int32 `json:"burn_duration"`
GroupAtType int32 `json:"group_at_type"`
AttachedInfo string `json:"attached_info"`
OwnerUserID string `json:"ownerUserId"`
ConversationID string `json:"conversationId"`
ConversationType int32 `json:"conversationType"`
UserID string `json:"userId"`
RecvMsgOpt int32 `json:"recvMsgOpt"`
IsPinned bool `json:"isPinned"`
IsPrivateChat bool `json:"isPrivateChat"`
BurnDuration int32 `json:"burnDuration"`
GroupAtType int32 `json:"groupAtType"`
AttachedInfo string `json:"attachedInfo"`
Ex string `json:"ex"`
}
@ -47,42 +47,42 @@ type CallbackAfterCreateSingleChatConversationsResp struct {
type CallbackBeforeCreateGroupChatConversationsReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"owner_user_id"`
ConversationID string `json:"conversation_id"`
ConversationType int32 `json:"conversation_type"`
GroupID string `json:"group_id"`
RecvMsgOpt int32 `json:"recv_msg_opt"`
IsPinned bool `json:"is_pinned"`
IsPrivateChat bool `json:"is_private_chat"`
BurnDuration int32 `json:"burn_duration"`
GroupAtType int32 `json:"group_at_type"`
AttachedInfo string `json:"attached_info"`
OwnerUserID string `json:"ownerUserId"`
ConversationID string `json:"conversationId"`
ConversationType int32 `json:"conversationType"`
GroupID string `json:"groupId"`
RecvMsgOpt int32 `json:"recvMsgOpt"`
IsPinned bool `json:"isPinned"`
IsPrivateChat bool `json:"isPrivateChat"`
BurnDuration int32 `json:"burnDuration"`
GroupAtType int32 `json:"groupAtType"`
AttachedInfo string `json:"attachedInfo"`
Ex string `json:"ex"`
}
type CallbackBeforeCreateGroupChatConversationsResp struct {
CommonCallbackResp
RecvMsgOpt *int32 `json:"recv_msg_opt"`
IsPinned *bool `json:"is_pinned"`
IsPrivateChat *bool `json:"is_private_chat"`
BurnDuration *int32 `json:"burn_duration"`
GroupAtType *int32 `json:"group_at_type"`
AttachedInfo *string `json:"attached_info"`
RecvMsgOpt *int32 `json:"recvMsgOpt"`
IsPinned *bool `json:"isPinned"`
IsPrivateChat *bool `json:"isPrivateChat"`
BurnDuration *int32 `json:"burnDuration"`
GroupAtType *int32 `json:"groupAtType"`
AttachedInfo *string `json:"attachedInfo"`
Ex *string `json:"ex"`
}
type CallbackAfterCreateGroupChatConversationsReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"owner_user_id"`
ConversationID string `json:"conversation_id"`
ConversationType int32 `json:"conversation_type"`
GroupID string `json:"group_id"`
RecvMsgOpt int32 `json:"recv_msg_opt"`
IsPinned bool `json:"is_pinned"`
IsPrivateChat bool `json:"is_private_chat"`
BurnDuration int32 `json:"burn_duration"`
GroupAtType int32 `json:"group_at_type"`
AttachedInfo string `json:"attached_info"`
OwnerUserID string `json:"ownerUserId"`
ConversationID string `json:"conversationId"`
ConversationType int32 `json:"conversationType"`
GroupID string `json:"groupId"`
RecvMsgOpt int32 `json:"recvMsgOpt"`
IsPinned bool `json:"isPinned"`
IsPrivateChat bool `json:"isPrivateChat"`
BurnDuration int32 `json:"burnDuration"`
GroupAtType int32 `json:"groupAtType"`
AttachedInfo string `json:"attachedInfo"`
Ex string `json:"ex"`
}