diff --git a/server/server.go b/server/server.go index d062e38b735fdf605974f39ad4e72493f11a89fe..71258dc0171546cd3cbeeb6a2e141a5133dc7d6f 100644 --- a/server/server.go +++ b/server/server.go @@ -221,6 +221,7 @@ func SocketRoom(w http.ResponseWriter, r *http.Request) { } uid = key } + fmt.Println("----conn1", hub[pkg.Data.RoomId][uid]) conn1 = hub[pkg.Data.RoomId][uid].Conn conn2 = conn @@ -236,10 +237,37 @@ func SocketRoom(w http.ResponseWriter, r *http.Request) { case pkg2.UpdateConn: //获取当前客户端的uid uid := pkg.Data.Uuid + fmt.Println("@@@@@@", hub[pkg.Data.RoomId][uid]) + fmt.Println("-----uid", pkg.Data.Uuid) + fmt.Println("-----roomId", pkg.Data.RoomId) + if hub[pkg.Data.RoomId][uid] != nil { + //更新该客户端的连接 + hub[pkg.Data.RoomId][uid].Conn = conn + fmt.Println("更新成功") + } + pkg1 := pkg2.PostPkg{ + Type: "updateConn", + Code: "200", + Data: *hub[pkg.Data.RoomId][uid], + } + + conn.WriteJSON(pkg1) + + var uid2 string + for key, _ := range hub[pkg.Data.RoomId] { + if key == pkg.Data.Uuid { + continue + } + uid2 = key + } + + pkg2 := pkg2.PostPkg{ + Type: "updateConn", + Code: "200", + Data: *hub[pkg.Data.RoomId][uid2], + } + hub[pkg.Data.RoomId][uid2].Conn.WriteJSON(pkg2) - //更新该客户端的连接 - hub[pkg.Data.RoomId][uid].Conn = conn - fmt.Println("更新成功") //更新游戏进度 case pkg2.GameProgress: //转发分数 @@ -296,7 +324,7 @@ func SocketRoom(w http.ResponseWriter, r *http.Request) { } case "check": //心跳检测 - fmt.Println("check发送") + //fmt.Println("check发送") conn.WriteJSON("check") } }