Fix register room bug

This commit is contained in:
giongto35 2019-05-02 04:16:45 +08:00
parent 03bd3fb1cc
commit 2be2e4d412
4 changed files with 8 additions and 8 deletions

View file

@ -336,3 +336,5 @@ func initClient2(t *testing.T, host string, remoteRoomID string) (conn *websocke
// If receive roomID, the server is running correctly
return ws, roomID
}
// TODO Add test reconnect room

View file

@ -93,7 +93,10 @@ func (s *Session) RegisterBrowserClient() {
// Create new room
// TODO: check if roomID is in the current server
room := s.handler.createNewRoom(s.GameName, s.RoomID, s.PlayerIndex)
room := s.handler.getRoom(s.RoomID)
if room == nil {
room = s.handler.createNewRoom(s.GameName, s.RoomID, s.PlayerIndex)
}
// Attach peerconnection to room
room.addConnectionToRoom(s.peerconnection, s.PlayerIndex)
s.RoomID = room.ID

View file

@ -123,7 +123,7 @@ func (h *Handler) createNewRoom(gameName string, roomID string, playerIndex int)
if roomID == "" || !h.isRoomRunning(roomID) {
room := NewRoom(roomID, gameName)
// TODO: Might have race condition
h.rooms[roomID] = room
h.rooms[room.ID] = room
return room
}

View file

@ -83,17 +83,12 @@ func (s *Session) RegisterOverlordClient() {
// Request room from Server if roomID is existed on the server
room := s.handler.getRoom(s.RoomID)
if room == nil {
log.Println("Room not found", s.RoomID)
log.Println("Room not found ", s.RoomID)
return cws.EmptyPacket
}
room.addConnectionToRoom(peerconnection, s.PlayerIndex)
//roomID, isNewRoom := startSession(peerconnection, resp.Data, resp.RoomID, resp.PlayerIndex)
log.Println("Done, sending back")
// Bridge always access to old room
// TODO: log warn
if room != nil {
log.Fatal("Bridge should not spawn new room")
}
req.ID = "start"
req.RoomID = room.ID