mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
minor changes.
This commit is contained in:
parent
c53ae28196
commit
3ea979ed47
@ -132,14 +132,12 @@ func (h *MessageHandlerCtx) adminGive(session types.Session, payload *message.Ad
|
||||
|
||||
target, ok := h.sessions.Get(payload.ID)
|
||||
if !ok {
|
||||
h.logger.Debug().Str("id", target.ID()).Msg("user does not exist")
|
||||
h.logger.Debug().Str("id", payload.ID).Msg("can't find target session")
|
||||
return nil
|
||||
}
|
||||
|
||||
// set host
|
||||
h.sessions.SetHost(target)
|
||||
|
||||
// let everyone know
|
||||
if err := h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.CONTROL_GIVE,
|
||||
@ -220,7 +218,7 @@ func (h *MessageHandlerCtx) adminKick(session types.Session, payload *message.Ad
|
||||
|
||||
target, ok := h.sessions.Get(payload.ID)
|
||||
if !ok {
|
||||
h.logger.Debug().Str("id", payload.ID).Msg("can't find session id")
|
||||
h.logger.Debug().Str("id", payload.ID).Msg("can't find target session")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -254,7 +252,7 @@ func (h *MessageHandlerCtx) adminBan(session types.Session, payload *message.Adm
|
||||
|
||||
target, ok := h.sessions.Get(payload.ID)
|
||||
if !ok {
|
||||
h.logger.Debug().Str("id", payload.ID).Msg("can't find session id")
|
||||
h.logger.Debug().Str("id", payload.ID).Msg("can't find target session")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -7,17 +7,14 @@ import (
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
|
||||
// check if session is host
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
// release host
|
||||
h.logger.Debug().Str("id", session.ID()).Msgf("host called %s", event.CONTROL_RELEASE)
|
||||
h.sessions.ClearHost()
|
||||
|
||||
// tell everyone
|
||||
if err := h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_RELEASE,
|
||||
@ -70,7 +67,6 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.Control) error {
|
||||
// check if session is host
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
@ -78,14 +74,12 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.
|
||||
|
||||
target, ok := h.sessions.Get(payload.ID)
|
||||
if !ok {
|
||||
h.logger.Debug().Str("id", target.ID()).Msg("user does not exist")
|
||||
h.logger.Debug().Str("id", payload.ID).Msg("can't find target session")
|
||||
return nil
|
||||
}
|
||||
|
||||
// set host
|
||||
h.sessions.SetHost(target)
|
||||
|
||||
// let everyone know
|
||||
if err := h.sessions.Broadcast(
|
||||
message.ControlTarget{
|
||||
Event: event.CONTROL_GIVE,
|
||||
@ -100,7 +94,6 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlClipboard(session types.Session, payload *message.Clipboard) error {
|
||||
// check if session is host
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
@ -111,7 +104,6 @@ func (h *MessageHandlerCtx) controlClipboard(session types.Session, payload *mes
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *message.Keyboard) error {
|
||||
// check if session is host
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
@ -122,7 +114,6 @@ func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *mess
|
||||
h.desktop.SetKeyboardLayout(*payload.Layout)
|
||||
}
|
||||
|
||||
// set num lock
|
||||
var NumLock = 0
|
||||
if payload.NumLock == nil {
|
||||
NumLock = -1
|
||||
@ -130,7 +121,6 @@ func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *mess
|
||||
NumLock = 1
|
||||
}
|
||||
|
||||
// set caps lock
|
||||
var CapsLock = 0
|
||||
if payload.CapsLock == nil {
|
||||
CapsLock = -1
|
||||
@ -138,7 +128,6 @@ func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *mess
|
||||
CapsLock = 1
|
||||
}
|
||||
|
||||
// set scroll lock
|
||||
var ScrollLock = 0
|
||||
if payload.ScrollLock == nil {
|
||||
ScrollLock = -1
|
||||
|
@ -32,16 +32,20 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) screenResolution(session types.Session) error {
|
||||
if size := h.desktop.GetScreenSize(); size != nil {
|
||||
if err := session.Send(message.ScreenResolution{
|
||||
Event: event.SCREEN_RESOLUTION,
|
||||
Width: size.Width,
|
||||
Height: size.Height,
|
||||
Rate: int(size.Rate),
|
||||
}); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_RESOLUTION)
|
||||
return err
|
||||
}
|
||||
size := h.desktop.GetScreenSize()
|
||||
if size == nil {
|
||||
h.logger.Debug().Msg("could not get screen size")
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := session.Send(message.ScreenResolution{
|
||||
Event: event.SCREEN_RESOLUTION,
|
||||
Width: size.Width,
|
||||
Height: size.Height,
|
||||
Rate: int(size.Rate),
|
||||
}); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_RESOLUTION)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -28,7 +28,7 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
// TODO: Refactor.
|
||||
// create member list
|
||||
members := []*message.MembersListEntry{}
|
||||
for _, session := range h.sessions.Members() {
|
||||
members = append(members, &message.MembersListEntry{
|
||||
@ -48,7 +48,7 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// send screen current resolution
|
||||
// send current screen resolution
|
||||
if err := h.screenResolution(session); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user