mirror of
https://github.com/screego/server.git
synced 2025-09-27 04:26:34 +08:00

In client.go if room, ok := message.(outgoing.Room); ok { c.info.RoomID = room.ID } this part isn't thread safe. It could happen that user disconnected but wasn't removed from a room, because the disconnecting go routine couldn't see the roomID yet.
24 lines
363 B
Go
24 lines
363 B
Go
package ws
|
|
|
|
func init() {
|
|
register("name", func() Event {
|
|
return &Name{}
|
|
})
|
|
}
|
|
|
|
type Name struct {
|
|
UserName string `json:"username"`
|
|
}
|
|
|
|
func (e *Name) Execute(rooms *Rooms, current ClientInfo) error {
|
|
room, err := rooms.CurrentRoom(current)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
room.Users[current.ID].Name = e.UserName
|
|
|
|
room.notifyInfoChanged()
|
|
return nil
|
|
}
|