54 lines
1.1 KiB
Go
Raw Normal View History

2020-11-01 16:09:48 +01:00
package handler
import (
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) SessionConnected(session types.Session) error {
2020-11-30 20:07:19 +01:00
if err := h.systemInit(session); err != nil {
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 {
return err
}
}
// let everyone know there is a new session
2020-11-18 20:30:33 +01:00
h.sessions.Broadcast(
2020-12-01 19:47:50 +01:00
message.MemberData{
Event: event.MEMBER_CONNECTED,
ID: session.ID(),
Name: session.Name(),
2020-12-02 16:49:51 +01:00
IsAdmin: session.IsAdmin(),
2020-11-16 18:12:25 +01:00
}, nil)
2020-11-18 20:30:33 +01:00
return nil
}
2020-11-01 20:53:25 +01:00
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
// 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()
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)
}
// let everyone know session disconnected
2020-11-18 20:30:33 +01:00
h.sessions.Broadcast(
2020-12-01 19:47:50 +01:00
message.MemberID{
Event: event.MEMBER_DISCONNECTED,
2020-11-01 20:53:25 +01:00
ID: session.ID(),
2020-11-16 18:12:25 +01:00
}, nil);
2020-11-18 20:30:33 +01:00
return nil
}