From ecfce6c8861ea42ea3681bf0eaba16ca0038dd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 25 Nov 2020 22:16:56 +0100 Subject: [PATCH] remove room lock. --- internal/session/auth.go | 1 + internal/types/event/events.go | 2 -- internal/websocket/handler/admin.go | 44 --------------------------- internal/websocket/handler/handler.go | 25 --------------- internal/websocket/manager.go | 22 +++----------- 5 files changed, 6 insertions(+), 88 deletions(-) diff --git a/internal/session/auth.go b/internal/session/auth.go index 2a9bd59d..3d797f19 100644 --- a/internal/session/auth.go +++ b/internal/session/auth.go @@ -25,6 +25,7 @@ func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session, return nil, fmt.Errorf("invalid password") } + // TODO: Enable persistent user autentication. return manager.Create(types.MemberProfile{ IsAdmin: isAdmin, }) diff --git a/internal/types/event/events.go b/internal/types/event/events.go index 02a227ea..2f8432e2 100644 --- a/internal/types/event/events.go +++ b/internal/types/event/events.go @@ -39,8 +39,6 @@ const ( const ( ADMIN_KICK = "admin/kick" - ADMIN_LOCK = "admin/lock" - ADMIN_UNLOCK = "admin/unlock" ADMIN_CONTROL = "admin/control" ADMIN_RELEASE = "admin/release" ADMIN_GIVE = "admin/give" diff --git a/internal/websocket/handler/admin.go b/internal/websocket/handler/admin.go index ba7803eb..0b3994bc 100644 --- a/internal/websocket/handler/admin.go +++ b/internal/websocket/handler/admin.go @@ -6,50 +6,6 @@ import ( "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 { if !session.Admin() { h.logger.Debug().Msg("user not admin") diff --git a/internal/websocket/handler/handler.go b/internal/websocket/handler/handler.go index 19068b33..9eadc80f 100644 --- a/internal/websocket/handler/handler.go +++ b/internal/websocket/handler/handler.go @@ -27,7 +27,6 @@ func New( desktop: desktop, capture: capture, webrtc: webrtc, - locked: false, } } @@ -37,26 +36,6 @@ type MessageHandlerCtx struct { webrtc types.WebRTCManager desktop types.DesktopManager 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 { @@ -116,10 +95,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error { err = h.boradcastDestroy(session) // Admin Events - case event.ADMIN_LOCK: - err = h.adminLock(session) - case event.ADMIN_UNLOCK: - err = h.adminUnlock(session) case event.ADMIN_CONTROL: err = h.adminControl(session) case event.ADMIN_RELEASE: diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index 89319386..6404cdad 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -142,26 +142,11 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e return connection.Close() } - websocket_peer := &WebSocketPeerCtx{ + session.SetWebSocketPeer(&WebSocketPeerCtx{ session: session, ws: ws, 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. Debug(). @@ -179,6 +164,9 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e Msg("connection ended") session.SetWebSocketConnected(false) + + // TODO: Enable persistent user autentication. + _ = ws.sessions.Delete(session.ID()) }() ws.handle(connection, session)