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-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-11-30 20:07:19 +01:00
|
|
|
if session.Admin() {
|
|
|
|
if err := h.systemAdmin(session); err != nil {
|
2020-10-22 16:54:50 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// let everyone know there is a new session
|
2020-11-18 20:30:33 +01:00
|
|
|
h.sessions.Broadcast(
|
2020-10-22 16:54:50 +02:00
|
|
|
message.Member{
|
2020-11-30 20:07:19 +01:00
|
|
|
Event: event.MEMBER_CONNECTED,
|
2020-11-01 16:37:00 +01:00
|
|
|
ID: session.ID(),
|
|
|
|
Name: session.Name(),
|
|
|
|
Admin: session.Admin(),
|
2020-11-16 18:12:25 +01:00
|
|
|
}, nil)
|
2020-11-18 20:30:33 +01:00
|
|
|
|
|
|
|
return nil
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
// let everyone know session disconnected
|
2020-11-18 20:30:33 +01:00
|
|
|
h.sessions.Broadcast(
|
2020-10-22 16:54:50 +02:00
|
|
|
message.MemberDisconnected{
|
|
|
|
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
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|