|
|
|
@ -337,17 +337,51 @@ 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:
|
|
|
|
|
if constant.PlatformIDToClass(newClient.PlatformID) == constant.TerminalPC {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
clients, ok := ws.clients.GetAll(newClient.UserID)
|
|
|
|
|
clientOK = ok
|
|
|
|
|
oldClients = make([]*Client, 0, len(clients))
|
|
|
|
|
for _, c := range clients {
|
|
|
|
|
if constant.PlatformIDToClass(c.PlatformID) == constant.TerminalPC {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
oldClients = append(oldClients, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fallthrough
|
|
|
|
|
case constant.AllLoginButSameTermKick:
|
|
|
|
|
if !clientOK {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oldClients = checkSameTokenFunc(oldClients)
|
|
|
|
|
|
|
|
|
|
ws.clients.DeleteClients(newClient.UserID, oldClients)
|
|
|
|
|
for _, c := range oldClients {
|
|
|
|
|
err := c.KickOnlineMessage()
|
|
|
|
@ -373,14 +407,15 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var (
|
|
|
|
|
kickClients []*Client
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var kickClients []*Client
|
|
|
|
|
for _, client := range clients {
|
|
|
|
|
if constant.PlatformIDToClass(client.PlatformID) == constant.PlatformIDToClass(newClient.PlatformID) {
|
|
|
|
|
kickClients = append(kickClients, client)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
kickClients = checkSameTokenFunc(kickClients)
|
|
|
|
|
|
|
|
|
|
kickTokenFunc(kickClients)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|