mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add control requesting to the host.
This commit is contained in:
parent
0e8108e9a4
commit
59b2faec66
@ -6,6 +6,8 @@ import (
|
|||||||
"github.com/go-chi/chi"
|
"github.com/go-chi/chi"
|
||||||
|
|
||||||
"github.com/demodesk/neko/pkg/auth"
|
"github.com/demodesk/neko/pkg/auth"
|
||||||
|
"github.com/demodesk/neko/pkg/types/event"
|
||||||
|
"github.com/demodesk/neko/pkg/types/message"
|
||||||
"github.com/demodesk/neko/pkg/utils"
|
"github.com/demodesk/neko/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,12 +35,21 @@ func (h *RoomHandler) controlStatus(w http.ResponseWriter, r *http.Request) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) error {
|
func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) error {
|
||||||
_, hasHost := h.sessions.GetHost()
|
session, _ := auth.GetSession(r)
|
||||||
|
host, hasHost := h.sessions.GetHost()
|
||||||
if hasHost {
|
if hasHost {
|
||||||
return utils.HttpUnprocessableEntity("there is already a host")
|
// TODO: Some throttling mechanism to prevent spamming.
|
||||||
|
|
||||||
|
// let host know that someone wants to take control
|
||||||
|
host.Send(
|
||||||
|
event.CONTROL_REQUEST,
|
||||||
|
message.SessionID{
|
||||||
|
ID: session.ID(),
|
||||||
|
})
|
||||||
|
|
||||||
|
return utils.HttpError(http.StatusAccepted, "control request sent")
|
||||||
}
|
}
|
||||||
|
|
||||||
session, _ := auth.GetSession(r)
|
|
||||||
if h.sessions.Settings().LockedControls && !session.Profile().IsAdmin {
|
if h.sessions.Settings().LockedControls && !session.Profile().IsAdmin {
|
||||||
return utils.HttpForbidden("controls are locked")
|
return utils.HttpForbidden("controls are locked")
|
||||||
}
|
}
|
||||||
|
@ -44,23 +44,29 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
|||||||
return ErrIsNotAllowedToHost
|
return ErrIsNotAllowedToHost
|
||||||
}
|
}
|
||||||
|
|
||||||
if !h.sessions.Settings().ImplicitHosting {
|
// if implicit hosting is enabled, set session as host without asking
|
||||||
// tell session if there is a host
|
if h.sessions.Settings().ImplicitHosting {
|
||||||
if host, hasHost := h.sessions.GetHost(); hasHost {
|
session.SetAsHost()
|
||||||
session.Send(
|
return nil
|
||||||
event.CONTROL_HOST,
|
}
|
||||||
message.ControlHost{
|
|
||||||
HasHost: true,
|
// if there is no host, set session as host
|
||||||
HostID: host.ID(),
|
host, hasHost := h.sessions.GetHost()
|
||||||
|
if !hasHost {
|
||||||
|
session.SetAsHost()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Some throttling mechanism to prevent spamming.
|
||||||
|
|
||||||
|
// let host know that someone wants to take control
|
||||||
|
host.Send(
|
||||||
|
event.CONTROL_REQUEST,
|
||||||
|
message.SessionID{
|
||||||
|
ID: session.ID(),
|
||||||
})
|
})
|
||||||
|
|
||||||
return ErrIsAlreadyHosted
|
return ErrIsAlreadyHosted
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
session.SetAsHost()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) controlMove(session types.Session, payload *message.ControlPos) error {
|
func (h *MessageHandlerCtx) controlMove(session types.Session, payload *message.ControlPos) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user