2020-11-02 04:09:48 +13:00
|
|
|
package handler
|
2020-10-23 03:54:50 +13:00
|
|
|
|
|
|
|
import (
|
2020-10-29 07:15:48 +13:00
|
|
|
"demodesk/neko/internal/types"
|
|
|
|
"demodesk/neko/internal/types/event"
|
|
|
|
"demodesk/neko/internal/types/message"
|
2020-10-23 03:54:50 +13:00
|
|
|
)
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
2020-12-01 08:07:19 +13:00
|
|
|
if err := h.systemInit(session); err != nil {
|
2020-10-23 03:54:50 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:07:19 +13:00
|
|
|
if session.Admin() {
|
|
|
|
if err := h.systemAdmin(session); err != nil {
|
2020-10-23 03:54:50 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// let everyone know there is a new session
|
2020-11-19 08:30:33 +13:00
|
|
|
h.sessions.Broadcast(
|
2020-10-23 03:54:50 +13:00
|
|
|
message.Member{
|
2020-12-01 08:07:19 +13:00
|
|
|
Event: event.MEMBER_CONNECTED,
|
2020-11-02 04:37:00 +13:00
|
|
|
ID: session.ID(),
|
|
|
|
Name: session.Name(),
|
|
|
|
Admin: session.Admin(),
|
2020-11-17 06:12:25 +13:00
|
|
|
}, nil)
|
2020-11-19 08:30:33 +13:00
|
|
|
|
|
|
|
return nil
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 08:53:25 +13:00
|
|
|
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
2020-10-23 03:54:50 +13:00
|
|
|
// clear host if exists
|
2020-11-02 08:53:25 +13:00
|
|
|
if session.IsHost() {
|
2020-10-23 03:54:50 +13:00
|
|
|
h.sessions.ClearHost()
|
2020-11-17 06:12:25 +13:00
|
|
|
|
2020-11-19 08:30:33 +13:00
|
|
|
h.sessions.Broadcast(
|
2020-12-01 06:24:38 +13:00
|
|
|
message.ControlHost{
|
|
|
|
Event: event.CONTROL_HOST,
|
|
|
|
HasHost: false,
|
2020-11-19 08:30:33 +13:00
|
|
|
}, nil)
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
// let everyone know session disconnected
|
2020-11-19 08:30:33 +13:00
|
|
|
h.sessions.Broadcast(
|
2020-10-23 03:54:50 +13:00
|
|
|
message.MemberDisconnected{
|
|
|
|
Event: event.MEMBER_DISCONNECTED,
|
2020-11-02 08:53:25 +13:00
|
|
|
ID: session.ID(),
|
2020-11-17 06:12:25 +13:00
|
|
|
}, nil);
|
2020-11-19 08:30:33 +13:00
|
|
|
|
|
|
|
return nil
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|