2020-11-01 16:09:48 +01:00
|
|
|
package handler
|
2020-10-22 16:54:50 +02:00
|
|
|
|
|
|
|
import (
|
2020-10-28 19:15:48 +01:00
|
|
|
"demodesk/neko/internal/types"
|
|
|
|
"demodesk/neko/internal/types/event"
|
|
|
|
"demodesk/neko/internal/types/message"
|
2020-10-22 16:54:50 +02:00
|
|
|
)
|
|
|
|
|
2020-12-02 18:59:54 +01:00
|
|
|
func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberData{
|
2020-12-03 16:10:52 +01:00
|
|
|
Event: event.MEMBER_CREATED,
|
|
|
|
ID: session.ID(),
|
2020-12-08 15:37:48 +01:00
|
|
|
Profile: session.GetProfile(),
|
|
|
|
State: session.GetState(),
|
2020-12-02 18:59:54 +01:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MessageHandlerCtx) SessionDeleted(session types.Session) error {
|
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberID{
|
|
|
|
Event: event.MEMBER_DELETED,
|
|
|
|
ID: session.ID(),
|
2021-02-14 14:40:17 +01:00
|
|
|
}, nil)
|
2020-12-02 18:59:54 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-01 16:09:48 +01:00
|
|
|
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
2020-11-30 20:07:19 +01:00
|
|
|
if err := h.systemInit(session); err != nil {
|
2020-10-22 16:54:50 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-02 16:49:51 +01:00
|
|
|
if session.IsAdmin() {
|
2020-11-30 20:07:19 +01:00
|
|
|
if err := h.systemAdmin(session); err != nil {
|
2020-10-22 16:54:50 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 16:42:27 +01:00
|
|
|
return h.SessionStateChanged(session)
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|
|
|
|
|
2020-11-01 20:53:25 +01:00
|
|
|
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
2020-10-22 16:54:50 +02:00
|
|
|
// clear host if exists
|
2020-11-01 20:53:25 +01:00
|
|
|
if session.IsHost() {
|
2020-12-02 10:46:00 +01:00
|
|
|
h.desktop.ResetKeys()
|
2020-10-22 16:54:50 +02:00
|
|
|
h.sessions.ClearHost()
|
2020-11-16 18:12:25 +01:00
|
|
|
|
2020-11-18 20:30:33 +01:00
|
|
|
h.sessions.Broadcast(
|
2020-11-30 18:24:38 +01:00
|
|
|
message.ControlHost{
|
|
|
|
Event: event.CONTROL_HOST,
|
|
|
|
HasHost: false,
|
2020-11-18 20:30:33 +01:00
|
|
|
}, nil)
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|
|
|
|
|
2020-12-03 16:42:27 +01:00
|
|
|
return h.SessionStateChanged(session)
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|
2020-12-02 18:59:54 +01:00
|
|
|
|
2020-12-03 16:10:52 +01:00
|
|
|
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
|
2020-12-08 15:37:48 +01:00
|
|
|
profile := session.GetProfile()
|
|
|
|
|
2020-12-02 18:59:54 +01:00
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberProfile{
|
2020-12-08 15:14:20 +01:00
|
|
|
Event: event.MEMBER_PROFILE,
|
|
|
|
ID: session.ID(),
|
2020-12-08 15:37:48 +01:00
|
|
|
MemberProfile: &profile,
|
2020-12-02 18:59:54 +01:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-03 16:10:52 +01:00
|
|
|
|
|
|
|
func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
|
2020-12-08 15:37:48 +01:00
|
|
|
state := session.GetState()
|
|
|
|
|
2020-12-03 16:10:52 +01:00
|
|
|
h.sessions.Broadcast(
|
|
|
|
message.MemberState{
|
|
|
|
Event: event.MEMBER_STATE,
|
|
|
|
ID: session.ID(),
|
2020-12-08 15:37:48 +01:00
|
|
|
MemberState: &state,
|
2020-12-03 16:10:52 +01:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|