remove admin from websockets.

This commit is contained in:
Miroslav Šedivý 2020-11-30 17:31:29 +01:00
parent 994a91886d
commit 0a75950356
4 changed files with 0 additions and 115 deletions

View File

@ -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.
)

View File

@ -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"`

View File

@ -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
}

View File

@ -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)
}