From 0a7595035699c2655481cf2c29646d219ca82ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 30 Nov 2020 17:31:29 +0100 Subject: [PATCH] remove admin from websockets. --- internal/types/event/events.go | 6 -- internal/types/message/messages.go | 13 ---- internal/websocket/handler/admin.go | 85 --------------------------- internal/websocket/handler/handler.go | 11 ---- 4 files changed, 115 deletions(-) delete mode 100644 internal/websocket/handler/admin.go diff --git a/internal/types/event/events.go b/internal/types/event/events.go index 31743ef2..4b56299e 100644 --- a/internal/types/event/events.go +++ b/internal/types/event/events.go @@ -54,9 +54,3 @@ const ( const ( BORADCAST_STATUS = "broadcast/status" ) - -const ( - ADMIN_CONTROL = "admin/control" // TODO: Remove. - ADMIN_RELEASE = "admin/release" // TODO: Remove. - ADMIN_GIVE = "admin/give" // TODO: Remove. -) diff --git a/internal/types/message/messages.go b/internal/types/message/messages.go index 9bccdddd..bb8e1f31 100644 --- a/internal/types/message/messages.go +++ b/internal/types/message/messages.go @@ -182,19 +182,6 @@ type ControlTarget struct { Target string `json:"target"` } -// TODO: Remove. -type Admin struct { - Event string `json:"event"` - ID string `json:"id"` -} - -// TODO: Remove. -type AdminTarget struct { - Event string `json:"event"` - Target string `json:"target"` - ID string `json:"id"` -} - // TODO: Remove. type ScreenResolution struct { Event string `json:"event"` diff --git a/internal/websocket/handler/admin.go b/internal/websocket/handler/admin.go deleted file mode 100644 index 9dbef032..00000000 --- a/internal/websocket/handler/admin.go +++ /dev/null @@ -1,85 +0,0 @@ -package handler - -import ( - "demodesk/neko/internal/types" - "demodesk/neko/internal/types/event" - "demodesk/neko/internal/types/message" -) - -func (h *MessageHandlerCtx) adminControl(session types.Session) error { - if !session.Admin() { - h.logger.Debug().Msg("user not admin") - return nil - } - - host := h.sessions.GetHost() - h.sessions.SetHost(session) - - if host != nil { - h.sessions.Broadcast( - message.AdminTarget{ - Event: event.ADMIN_CONTROL, - ID: session.ID(), - Target: host.ID(), - }, nil) - } else { - h.sessions.Broadcast( - message.Admin{ - Event: event.ADMIN_CONTROL, - ID: session.ID(), - }, nil) - } - - return nil -} - -func (h *MessageHandlerCtx) adminRelease(session types.Session) error { - if !session.Admin() { - h.logger.Debug().Msg("user not admin") - return nil - } - - host := h.sessions.GetHost() - h.sessions.ClearHost() - - if host != nil { - h.sessions.Broadcast( - message.AdminTarget{ - Event: event.ADMIN_RELEASE, - ID: session.ID(), - Target: host.ID(), - }, nil) - } else { - h.sessions.Broadcast( - message.Admin{ - Event: event.ADMIN_RELEASE, - ID: session.ID(), - }, nil) - } - - return nil -} - -func (h *MessageHandlerCtx) adminGive(session types.Session, payload *message.Admin) error { - if !session.Admin() { - h.logger.Debug().Msg("user not admin") - return nil - } - - target, ok := h.sessions.Get(payload.ID) - if !ok { - h.logger.Debug().Str("id", payload.ID).Msg("can't find target session") - return nil - } - - h.sessions.SetHost(target) - - h.sessions.Broadcast( - message.AdminTarget{ - Event: event.CONTROL_GIVE, - ID: session.ID(), - Target: target.ID(), - }, nil) - - return nil -} diff --git a/internal/websocket/handler/handler.go b/internal/websocket/handler/handler.go index 9daa01a4..6e0a5d4d 100644 --- a/internal/websocket/handler/handler.go +++ b/internal/websocket/handler/handler.go @@ -84,17 +84,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error { err = utils.Unmarshal(payload, raw, func() error { return h.screenSizeChange(session, payload) }) - - // Admin Events - case event.ADMIN_CONTROL: - err = h.adminControl(session) - case event.ADMIN_RELEASE: - err = h.adminRelease(session) - case event.ADMIN_GIVE: - payload := &message.Admin{} - err = utils.Unmarshal(payload, raw, func() error { - return h.adminGive(session, payload) - }) default: return errors.Errorf("unknown message event %s", header.Event) }