mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-22 09:37:09 +00:00
Fix register room bug
This commit is contained in:
parent
03bd3fb1cc
commit
2be2e4d412
4 changed files with 8 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue