mirror of
https://github.com/screego/server.git
synced 2026-04-22 23:47:03 +08:00
43 lines
685 B
Go
43 lines
685 B
Go
package ws
|
|
|
|
type Disconnected struct {
|
|
}
|
|
|
|
func (e *Disconnected) Execute(rooms *Rooms, current ClientInfo) error {
|
|
if current.RoomID == "" {
|
|
return nil
|
|
}
|
|
|
|
room, ok := rooms.Rooms[current.RoomID]
|
|
if !ok {
|
|
// room may already be removed
|
|
return nil
|
|
}
|
|
|
|
user, ok := room.Users[current.ID]
|
|
|
|
if !ok {
|
|
// room may already be removed
|
|
return nil
|
|
}
|
|
|
|
delete(room.Users, current.ID)
|
|
|
|
if user.Owner && room.CloseOnOwnerLeave {
|
|
for _, member := range room.Users {
|
|
member.Close <- "Owner left"
|
|
}
|
|
delete(rooms.Rooms, current.RoomID)
|
|
return nil
|
|
}
|
|
|
|
if len(room.Users) == 0 {
|
|
delete(rooms.Rooms, current.RoomID)
|
|
return nil
|
|
}
|
|
|
|
room.notifyInfoChanged()
|
|
|
|
return nil
|
|
}
|