56 lines
1.0 KiB
Go
Raw Normal View History

2020-11-01 16:09:48 +01:00
package handler
import (
2021-09-01 23:10:18 +02:00
"errors"
2020-10-28 19:15:48 +01:00
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
2020-11-01 16:09:48 +01:00
func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
2021-08-29 18:23:58 +02:00
logger := h.logger.With().Str("session_id", session.ID()).Logger()
2021-03-14 00:45:51 +01:00
if !session.Profile().CanHost {
2021-08-29 18:23:58 +02:00
logger.Debug().Msg("is not allowed to host")
2020-12-06 18:50:41 +01:00
return nil
}
2020-10-31 23:03:37 +01:00
if !session.IsHost() {
2021-08-29 18:23:58 +02:00
logger.Debug().Msg("is not the host")
return nil
}
2020-12-02 10:46:00 +01:00
h.desktop.ResetKeys()
h.sessions.ClearHost()
2020-12-02 10:46:00 +01:00
2020-11-18 20:30:33 +01:00
return nil
}
2020-11-01 16:09:48 +01:00
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
2021-03-14 00:45:51 +01:00
if !session.Profile().CanHost {
2021-09-01 23:10:18 +02:00
return errors.New("is not allowed to host")
2020-12-06 18:50:41 +01:00
}
2020-12-02 10:47:20 +01:00
if session.IsHost() {
2021-09-01 23:10:18 +02:00
return errors.New("is already the host")
2020-12-02 10:47:20 +01:00
}
2020-12-02 11:24:20 +01:00
if !h.sessions.ImplicitHosting() {
// tell session if there is a host
if host := h.sessions.GetHost(); host != nil {
2021-09-01 21:58:39 +02:00
session.Send(
event.CONTROL_HOST,
2020-12-02 11:24:20 +01:00
message.ControlHost{
HasHost: true,
HostID: host.ID(),
})
2021-09-01 21:58:39 +02:00
return nil
2020-12-02 11:24:20 +01:00
}
}
2020-11-30 18:24:38 +01:00
h.sessions.SetHost(session)
2020-11-18 20:30:33 +01:00
return nil
}