Skip to content

Commit

Permalink
Implement failsafe logic for GenerateUniqueRoomName
Browse files Browse the repository at this point in the history
We limit the attempts to 10
  • Loading branch information
sbanca committed Dec 11, 2024
1 parent 65d3a8a commit 5d623a2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Assets/Scripts/GUI/MultiplayerPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,22 @@ protected override void OnDisablePanel()

private static string GenerateUniqueRoomName()
{
const int maxAttempts = 10;
string roomName;
int attempts = 0;

do
{
roomName = GenerateRandomRoomName();
} while (MultiplayerManager.m_Instance != null && MultiplayerManager.m_Instance.DoesRoomNameExist(roomName));
attempts++;
} while (MultiplayerManager.m_Instance != null &&
MultiplayerManager.m_Instance.DoesRoomNameExist(roomName) &&
attempts < maxAttempts);

if (attempts >= maxAttempts)
{
return "default room";
}

return roomName;
}
Expand Down

0 comments on commit 5d623a2

Please sign in to comment.