Skip to content

Commit 13a660a

Browse files
committed
fix: GlobalRooms
1 parent 7b9103d commit 13a660a

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

driving/hall/hall.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package hall
22

33
import (
4-
"encoding/json"
4+
// "encoding/json"
55
"fmt"
66
"github.com/zishang520/socket.io/socket"
77
. "src/model"
@@ -16,10 +16,11 @@ func Hall(io *socket.Server) (err error) {
1616
"rooms": GlobalRooms,
1717
})
1818
if err != nil {
19-
fmt.Println("Error in sendRooms", err)
19+
utils.Logger.Error("Error in sendRooms " + err.Error())
20+
// fmt.Println("Error in sendRooms", err)
2021
}
21-
data, _ := json.Marshal(GlobalRooms)
22-
utils.Logger.Info("sendRooms " + string(data))
22+
// data, _ := json.Marshal(GlobalRooms)
23+
// utils.Logger.Info("sendRooms " + string(data))
2324

2425
err = client.On("createRooms", func(_ ...any) {
2526
//for _, data := range roomsData {

driving/room/disconnect.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ func Disconnect(io *socket.Server, id socket.SocketId, roomID string) {
3838
io.Of("/room", nil).Sockets().Delete(id)
3939

4040
MutexRooms.Lock()
41-
delete(GlobalRooms, roomID)
42-
// removeIdx := -1
43-
// for idx, thisID := range GlobalRooms[roomID] {
44-
// if thisID == string(id) {
45-
// removeIdx = idx
46-
// }
47-
// }
48-
// if removeIdx > -1 {
49-
// GlobalRooms[roomID] = append(GlobalRooms[roomID][:removeIdx], GlobalRooms[roomID][removeIdx+1:]...)
50-
// }
41+
// delete(GlobalRooms, roomID)
42+
removeIdx := -1
43+
for idx, thisID := range GlobalRooms[roomID] {
44+
if thisID == string(id) {
45+
removeIdx = idx
46+
}
47+
}
48+
if removeIdx > -1 {
49+
GlobalRooms[roomID] = append(GlobalRooms[roomID][:removeIdx], GlobalRooms[roomID][removeIdx+1:]...)
50+
}
5151
MutexRooms.Unlock()
5252
// io.Sockets().Sockets().Delete(id)
5353
}

0 commit comments

Comments
 (0)