Skip to content

Commit

Permalink
room stream limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatbostanci committed Jun 10, 2021
1 parent 488e9e0 commit 6b4d1a2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion handler/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ func (h *MultiplayerHandler) RoomStream(stream pb.MultiplayerService_RoomStreamS
} else {
h.rooms[request.GetRoomId()][addedKey] = request.GetPlayer()
}
currentPlayers := h.rooms[request.GetRoomId()]
if len(h.rooms[request.GetRoomId()]) < 2 {
currentPlayers = make([]*pb.Player, 0, len(h.rooms[request.GetRoomId()]))
}
h.roomsMapMutex.Unlock()

err = stream.Send(&pb.RoomStreamResponse{Players: h.rooms[request.GetRoomId()]})
err = stream.Send(&pb.RoomStreamResponse{Players: currentPlayers})
if err != nil {
if err == io.EOF {
break
Expand Down

0 comments on commit 6b4d1a2

Please sign in to comment.