mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix locked room bug
This commit is contained in:
parent
9e5019be7d
commit
f093ef762b
@ -48,10 +48,10 @@ export const controls = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const room = {
|
export const room = {
|
||||||
lock: 'Lock Room',
|
lock: 'Lock Room (for users)',
|
||||||
unlock: 'Unlock Room',
|
unlock: 'Unlock Room (for users)',
|
||||||
locked: 'Room Locked',
|
locked: 'Room Locked (for users)',
|
||||||
unlocked: 'Room Unlocked',
|
unlocked: 'Room Unlocked (for users)',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setting = {
|
export const setting = {
|
||||||
|
@ -22,7 +22,7 @@ type MessageHandler struct {
|
|||||||
locked bool
|
locked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) Connected(id string, socket *WebSocket) (bool, string, error) {
|
func (h *MessageHandler) Connected(admin bool, socket *WebSocket) (bool, string, error) {
|
||||||
address := socket.Address()
|
address := socket.Address()
|
||||||
if address == "" {
|
if address == "" {
|
||||||
h.logger.Debug().Msg("no remote address")
|
h.logger.Debug().Msg("no remote address")
|
||||||
@ -34,22 +34,15 @@ func (h *MessageHandler) Connected(id string, socket *WebSocket) (bool, string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.locked {
|
if h.locked && !admin {
|
||||||
session, ok := h.sessions.Get(id)
|
|
||||||
if !ok || !session.Admin() {
|
|
||||||
h.logger.Debug().Msg("server locked")
|
h.logger.Debug().Msg("server locked")
|
||||||
return false, "locked", nil
|
return false, "locked", nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true, "", nil
|
return true, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) Disconnected(id string) error {
|
func (h *MessageHandler) Disconnected(id string) error {
|
||||||
if h.locked && len(h.sessions.Admins()) == 0 {
|
|
||||||
h.locked = false
|
|
||||||
}
|
|
||||||
|
|
||||||
return h.sessions.Destroy(id)
|
return h.sessions.Destroy(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ func (ws *WebSocketHandler) Upgrade(w http.ResponseWriter, r *http.Request) erro
|
|||||||
connection: connection,
|
connection: connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, reason, err := ws.handler.Connected(id, socket)
|
ok, reason, err := ws.handler.Connected(admin, socket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ws.logger.Error().Err(err).Msg("connection failed")
|
ws.logger.Error().Err(err).Msg("connection failed")
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user