qol change
This commit is contained in:
31
ws/util.go
31
ws/util.go
@@ -126,22 +126,13 @@ func (wsg *WebsocketGateway) registerConn(conn *websocket.Conn, typ, channelId,
|
||||
return true
|
||||
}
|
||||
|
||||
func (wsg *WebsocketGateway) unregisterConn(conn *websocket.Conn, typ, channelId string) {
|
||||
func (wsg *WebsocketGateway) unregisterConn(typ, channelId string) {
|
||||
if typ == "bot" {
|
||||
wsg.registry.UnregisterBot()
|
||||
if conn != nil {
|
||||
_ = conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "Disconnecting."), time.Now().Add(time.Second))
|
||||
_ = conn.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
wsg.registry.UnregisterMod(channelId)
|
||||
|
||||
if conn != nil {
|
||||
_ = conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "Disconnecting."), time.Now().Add(time.Second))
|
||||
_ = conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (wsg *WebsocketGateway) closeAll() {
|
||||
@@ -150,24 +141,14 @@ func (wsg *WebsocketGateway) closeAll() {
|
||||
wsg.registry.UnregisterBot()
|
||||
|
||||
wsg.registry.mu.RLock()
|
||||
entries := make([]*ChannelEntry, 0, len(wsg.registry.entries))
|
||||
for _, e := range wsg.registry.entries {
|
||||
entries = append(entries, e)
|
||||
channelIDs := make([]string, 0, len(wsg.registry.entries))
|
||||
for channelID := range wsg.registry.entries {
|
||||
channelIDs = append(channelIDs, channelID)
|
||||
}
|
||||
wsg.registry.mu.RUnlock()
|
||||
|
||||
for _, e := range entries {
|
||||
e.mu.Lock()
|
||||
modConn := e.Mod
|
||||
if modConn != nil {
|
||||
e.Mod = nil
|
||||
}
|
||||
e.mu.Unlock()
|
||||
|
||||
if modConn != nil && modConn.Conn != nil {
|
||||
_ = modConn.Conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "Shutting down."), time.Now().Add(time.Second))
|
||||
_ = modConn.Conn.Close()
|
||||
}
|
||||
for _, channelID := range channelIDs {
|
||||
wsg.registry.UnregisterMod(channelID)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user