Skip to content

Commit

Permalink
room stream mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatbostanci committed Jun 10, 2021
1 parent e98dfc2 commit 8af64c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import (
"github.com/PulseyTeam/game-server/jwt"
pb "github.com/PulseyTeam/game-server/proto"
"go.mongodb.org/mongo-driver/mongo"
"sync"
)

type MultiplayerHandler struct {
pb.UnimplementedMultiplayerServiceServer
rooms map[string]map[string]*pb.Player
jwtManager *jwt.Manager
mongoDB *mongo.Client
cfg *config.Config
rooms map[string]map[string]*pb.Player
roomsMapMutex sync.RWMutex
jwtManager *jwt.Manager
mongoDB *mongo.Client
cfg *config.Config
}

type AuthHandler struct {
Expand Down
2 changes: 2 additions & 0 deletions handler/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func (h *MultiplayerHandler) RoomStream(stream pb.MultiplayerService_RoomStreamS
log.Trace().Msg(request.String())
}

h.roomsMapMutex.Lock()
h.rooms[request.GetRoomId()][request.GetPlayer().GetId()] = request.GetPlayer()
h.roomsMapMutex.Unlock()

currentPlayers := make([]*pb.Player, 0, len(h.rooms[request.GetRoomId()]))
if len(h.rooms[request.GetRoomId()]) > 2 {
Expand Down

0 comments on commit 8af64c4

Please sign in to comment.