add DelSession
This commit is contained in:
parent
9069d1293c
commit
c3e7360019
@ -67,6 +67,7 @@ func (h *MqttServerHook) OnDisconnect(cl *mqttServerV2.Client, err error, expire
|
|||||||
|
|
||||||
session := GetSession(cl.ID)
|
session := GetSession(cl.ID)
|
||||||
MqttClientDisconnect(session)
|
MqttClientDisconnect(session)
|
||||||
|
DelSession(session.ClientId)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +107,12 @@ func (h *MqttServerHook) OnPublished(cl *mqttServerV2.Client, pk packets.Packet)
|
|||||||
// OnConnectAuthenticate returns true/allowed for all requests.
|
// OnConnectAuthenticate returns true/allowed for all requests.
|
||||||
func (h *MqttServerHook) OnConnectAuthenticate(cl *mqttServerV2.Client, pk packets.Packet) bool {
|
func (h *MqttServerHook) OnConnectAuthenticate(cl *mqttServerV2.Client, pk packets.Packet) bool {
|
||||||
h.Log.Info("Auth", pk.Connect.Username, pk.Connect.Password)
|
h.Log.Info("Auth", pk.Connect.Username, pk.Connect.Password)
|
||||||
session := CreateSession(cl.ID, pk.Connect.Username, pk.Connect.Password)
|
session := GetSession(cl.ID)
|
||||||
|
if session != nil {
|
||||||
|
MqttClientDisconnect(session)
|
||||||
|
DelSession(session.ClientId)
|
||||||
|
}
|
||||||
|
session = CreateSession(cl.ID, pk.Connect.Username, pk.Connect.Password)
|
||||||
err := MqttClientConnect(session)
|
err := MqttClientConnect(session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -23,3 +23,7 @@ func CreateSession(mqttId string, user, passwd []byte) *Session {
|
|||||||
func GetSession(mqttId string) *Session {
|
func GetSession(mqttId string) *Session {
|
||||||
return Sessions[mqttId]
|
return Sessions[mqttId]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DelSession(mqttId string) {
|
||||||
|
delete(Sessions, mqttId)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user