mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
remove room lock.
This commit is contained in:
parent
d1fccf5ab6
commit
ecfce6c886
@ -25,6 +25,7 @@ func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session,
|
|||||||
return nil, fmt.Errorf("invalid password")
|
return nil, fmt.Errorf("invalid password")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Enable persistent user autentication.
|
||||||
return manager.Create(types.MemberProfile{
|
return manager.Create(types.MemberProfile{
|
||||||
IsAdmin: isAdmin,
|
IsAdmin: isAdmin,
|
||||||
})
|
})
|
||||||
|
@ -39,8 +39,6 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
ADMIN_KICK = "admin/kick"
|
ADMIN_KICK = "admin/kick"
|
||||||
ADMIN_LOCK = "admin/lock"
|
|
||||||
ADMIN_UNLOCK = "admin/unlock"
|
|
||||||
ADMIN_CONTROL = "admin/control"
|
ADMIN_CONTROL = "admin/control"
|
||||||
ADMIN_RELEASE = "admin/release"
|
ADMIN_RELEASE = "admin/release"
|
||||||
ADMIN_GIVE = "admin/give"
|
ADMIN_GIVE = "admin/give"
|
||||||
|
@ -6,50 +6,6 @@ import (
|
|||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) adminLock(session types.Session) error {
|
|
||||||
if !session.Admin() {
|
|
||||||
h.logger.Debug().Msg("user not admin")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if h.locked {
|
|
||||||
h.logger.Debug().Msg("server already locked...")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
h.locked = true
|
|
||||||
|
|
||||||
h.sessions.Broadcast(
|
|
||||||
message.Admin{
|
|
||||||
Event: event.ADMIN_LOCK,
|
|
||||||
ID: session.ID(),
|
|
||||||
}, nil)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) adminUnlock(session types.Session) error {
|
|
||||||
if !session.Admin() {
|
|
||||||
h.logger.Debug().Msg("user not admin")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !h.locked {
|
|
||||||
h.logger.Debug().Msg("server not locked...")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
h.locked = false
|
|
||||||
|
|
||||||
h.sessions.Broadcast(
|
|
||||||
message.Admin{
|
|
||||||
Event: event.ADMIN_UNLOCK,
|
|
||||||
ID: session.ID(),
|
|
||||||
}, nil)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) adminControl(session types.Session) error {
|
func (h *MessageHandlerCtx) adminControl(session types.Session) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
|
@ -27,7 +27,6 @@ func New(
|
|||||||
desktop: desktop,
|
desktop: desktop,
|
||||||
capture: capture,
|
capture: capture,
|
||||||
webrtc: webrtc,
|
webrtc: webrtc,
|
||||||
locked: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,26 +36,6 @@ type MessageHandlerCtx struct {
|
|||||||
webrtc types.WebRTCManager
|
webrtc types.WebRTCManager
|
||||||
desktop types.DesktopManager
|
desktop types.DesktopManager
|
||||||
capture types.CaptureManager
|
capture types.CaptureManager
|
||||||
locked bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) Connected(session types.Session, websocket_peer types.WebSocketPeer) (bool, string) {
|
|
||||||
if h.locked && !session.Admin(){
|
|
||||||
h.logger.Debug().Msg("server locked")
|
|
||||||
return false, "locked"
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove, unused.
|
|
||||||
func (h *MessageHandlerCtx) Disconnected(id string) error {
|
|
||||||
// TODO: Refactor.
|
|
||||||
if h.locked && len(h.sessions.Admins()) == 0 {
|
|
||||||
h.locked = false
|
|
||||||
}
|
|
||||||
|
|
||||||
return h.sessions.Delete(id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
||||||
@ -116,10 +95,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
|||||||
err = h.boradcastDestroy(session)
|
err = h.boradcastDestroy(session)
|
||||||
|
|
||||||
// Admin Events
|
// Admin Events
|
||||||
case event.ADMIN_LOCK:
|
|
||||||
err = h.adminLock(session)
|
|
||||||
case event.ADMIN_UNLOCK:
|
|
||||||
err = h.adminUnlock(session)
|
|
||||||
case event.ADMIN_CONTROL:
|
case event.ADMIN_CONTROL:
|
||||||
err = h.adminControl(session)
|
err = h.adminControl(session)
|
||||||
case event.ADMIN_RELEASE:
|
case event.ADMIN_RELEASE:
|
||||||
|
@ -142,26 +142,11 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e
|
|||||||
return connection.Close()
|
return connection.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
websocket_peer := &WebSocketPeerCtx{
|
session.SetWebSocketPeer(&WebSocketPeerCtx{
|
||||||
session: session,
|
session: session,
|
||||||
ws: ws,
|
ws: ws,
|
||||||
connection: connection,
|
connection: connection,
|
||||||
}
|
})
|
||||||
|
|
||||||
ok, reason := ws.handler.Connected(session, websocket_peer)
|
|
||||||
if !ok {
|
|
||||||
// TODO: Refactor
|
|
||||||
if err = connection.WriteJSON(message.Disconnect{
|
|
||||||
Event: event.SYSTEM_DISCONNECT,
|
|
||||||
Message: reason,
|
|
||||||
}); err != nil {
|
|
||||||
ws.logger.Error().Err(err).Msg("failed to send disconnect")
|
|
||||||
}
|
|
||||||
|
|
||||||
return connection.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
session.SetWebSocketPeer(websocket_peer)
|
|
||||||
|
|
||||||
ws.logger.
|
ws.logger.
|
||||||
Debug().
|
Debug().
|
||||||
@ -179,6 +164,9 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e
|
|||||||
Msg("connection ended")
|
Msg("connection ended")
|
||||||
|
|
||||||
session.SetWebSocketConnected(false)
|
session.SetWebSocketConnected(false)
|
||||||
|
|
||||||
|
// TODO: Enable persistent user autentication.
|
||||||
|
_ = ws.sessions.Delete(session.ID())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ws.handle(connection, session)
|
ws.handle(connection, session)
|
||||||
|
Loading…
Reference in New Issue
Block a user