minor changes.

This commit is contained in:
Miroslav Šedivý 2020-11-01 18:12:16 +01:00
parent c53ae28196
commit 3ea979ed47
4 changed files with 20 additions and 29 deletions

View File

@ -132,14 +132,12 @@ func (h *MessageHandlerCtx) adminGive(session types.Session, payload *message.Ad
target, ok := h.sessions.Get(payload.ID) target, ok := h.sessions.Get(payload.ID)
if !ok { 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 return nil
} }
// set host
h.sessions.SetHost(target) h.sessions.SetHost(target)
// let everyone know
if err := h.sessions.Broadcast( if err := h.sessions.Broadcast(
message.AdminTarget{ message.AdminTarget{
Event: event.CONTROL_GIVE, 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) target, ok := h.sessions.Get(payload.ID)
if !ok { 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 return nil
} }
@ -254,7 +252,7 @@ func (h *MessageHandlerCtx) adminBan(session types.Session, payload *message.Adm
target, ok := h.sessions.Get(payload.ID) target, ok := h.sessions.Get(payload.ID)
if !ok { 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 return nil
} }

View File

@ -7,17 +7,14 @@ import (
) )
func (h *MessageHandlerCtx) controlRelease(session types.Session) error { func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
// check if session is host
if !session.IsHost() { if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host") h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil return nil
} }
// release host
h.logger.Debug().Str("id", session.ID()).Msgf("host called %s", event.CONTROL_RELEASE) h.logger.Debug().Str("id", session.ID()).Msgf("host called %s", event.CONTROL_RELEASE)
h.sessions.ClearHost() h.sessions.ClearHost()
// tell everyone
if err := h.sessions.Broadcast( if err := h.sessions.Broadcast(
message.Control{ message.Control{
Event: event.CONTROL_RELEASE, 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 { func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.Control) error {
// check if session is host
if !session.IsHost() { if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host") h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil return nil
@ -78,14 +74,12 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.
target, ok := h.sessions.Get(payload.ID) target, ok := h.sessions.Get(payload.ID)
if !ok { 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 return nil
} }
// set host
h.sessions.SetHost(target) h.sessions.SetHost(target)
// let everyone know
if err := h.sessions.Broadcast( if err := h.sessions.Broadcast(
message.ControlTarget{ message.ControlTarget{
Event: event.CONTROL_GIVE, 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 { func (h *MessageHandlerCtx) controlClipboard(session types.Session, payload *message.Clipboard) error {
// check if session is host
if !session.IsHost() { if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host") h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil 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 { func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *message.Keyboard) error {
// check if session is host
if !session.IsHost() { if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host") h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil return nil
@ -122,7 +114,6 @@ func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *mess
h.desktop.SetKeyboardLayout(*payload.Layout) h.desktop.SetKeyboardLayout(*payload.Layout)
} }
// set num lock
var NumLock = 0 var NumLock = 0
if payload.NumLock == nil { if payload.NumLock == nil {
NumLock = -1 NumLock = -1
@ -130,7 +121,6 @@ func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *mess
NumLock = 1 NumLock = 1
} }
// set caps lock
var CapsLock = 0 var CapsLock = 0
if payload.CapsLock == nil { if payload.CapsLock == nil {
CapsLock = -1 CapsLock = -1
@ -138,7 +128,6 @@ func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *mess
CapsLock = 1 CapsLock = 1
} }
// set scroll lock
var ScrollLock = 0 var ScrollLock = 0
if payload.ScrollLock == nil { if payload.ScrollLock == nil {
ScrollLock = -1 ScrollLock = -1

View File

@ -32,16 +32,20 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
} }
func (h *MessageHandlerCtx) screenResolution(session types.Session) error { func (h *MessageHandlerCtx) screenResolution(session types.Session) error {
if size := h.desktop.GetScreenSize(); size != nil { size := h.desktop.GetScreenSize()
if err := session.Send(message.ScreenResolution{ if size == nil {
Event: event.SCREEN_RESOLUTION, h.logger.Debug().Msg("could not get screen size")
Width: size.Width, return nil
Height: size.Height, }
Rate: int(size.Rate),
}); err != nil { if err := session.Send(message.ScreenResolution{
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_RESOLUTION) Event: event.SCREEN_RESOLUTION,
return err 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 return nil

View File

@ -28,7 +28,7 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
} }
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error { func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
// TODO: Refactor. // create member list
members := []*message.MembersListEntry{} members := []*message.MembersListEntry{}
for _, session := range h.sessions.Members() { for _, session := range h.sessions.Members() {
members = append(members, &message.MembersListEntry{ members = append(members, &message.MembersListEntry{
@ -48,7 +48,7 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
return err return err
} }
// send screen current resolution // send current screen resolution
if err := h.screenResolution(session); err != nil { if err := h.screenResolution(session); err != nil {
return err return err
} }