Repository: 4ian/GDevelop
File: Extensions/Multiplayer/multiplayertools.ts (TypeScript)

Code before:
        onLobbyQuickJoinFinished(runtimeScene);
        if (openLobbiesPageIfFailure) {
          openLobbiesWindow(runtimeScene);
        }
      }
    };
	
    export const getLobbyID = (): string => {
      return _lobbyId || "";
    };
	
    export const authenticateAndQuickJoinWithLobbyID = async(
      runtimeScene: gdjs.RuntimeScene,
      lobbyID: string
    ) => {
      const playerId = gdjs.playerAuthentication.getUserId();
      const playerToken = gdjs.playerAuthentication.getUserToken();
      if (!playerId || !playerToken) {
        _isWaitingForLogin = true;
        const { status } =
          await gdjs.playerAuthentication.openAuthenticationWindow(runtimeScene)
            .promise;
        _isWaitingForLogin = false;

        if (status === 'logged') {
			_actionAfterJoiningLobby = 'JOIN_GAME';
			handleJoinLobbyEvent(runtimeScene, lobbyID);
        }

        return;
      }
		_actionAfterJoiningLobby = 'JOIN_GAME';
		handleJoinLobbyEvent(runtimeScene, lobbyID);
	}
	
    export const authenticateAndQuickJoinLobby = async (
      runtimeScene: gdjs.RuntimeScene,
      displayLoader: boolean,
      openLobbiesPageIfFailure: boolean
    ) => {
      const requestDoneAt = Date.now();
      if (_lastQuickJoinRequestDoneAt) {
        if (requestDoneAt - _lastQuickJoinRequestDoneAt < 500) {
          _lastQuickJoinRequestDoneAt = requestDoneAt;
          logger.warn(
            'Last request to quick join a lobby was sent too little time ago. Ignoring this one.'
          );
          return;
        }
      } else {
        _lastQuickJoinRequestDoneAt = requestDoneAt;

Review comment (bug):
This looks fine, just one thing, the current quickJoin action differentiates between 'JOIN_GAME' and 'START_GAME'.
I think that if the LobbyId corresponds to a lobby that hasn't started, then the action will fail (nothing will happen).
Do you want to handle that case?

Code after:
            _actionAfterJoiningLobby = 'JOIN_GAME';
          } else {
            throw new Error(
              `Lobby in wrong status: ${quickJoinLobbyResponse.status}`
            );
          }
        } else {
          if (_connectionId) {
            // Already connected to a lobby.
            onLobbyQuickJoinFinished(runtimeScene);
            openLobbiesWindow(runtimeScene);
            return;
          } else {
            _actionAfterJoiningLobby = 'OPEN_LOBBY_PAGE';
          }
        }
        handleJoinLobbyEvent(runtimeScene, quickJoinLobbyResponse.lobby.id);
      } catch (error) {
        logger.error('An error occurred while joining a lobby:', error);
        _quickJoinLobbyJustFailed = true;
        _quickJoinLobbyFailureReason = 'UNKNOWN';
        onLobbyQuickJoinFinished(runtimeScene);
        if (openLobbiesPageIfFailure) {
          openLobbiesWindow(runtimeScene);
        }
      }
    };

    export const getLobbyID = (): string => {
      return _lobbyId || '';
    };

    const quickJoinWithLobbyID = async (
      runtimeScene: gdjs.RuntimeScene,
      lobbyID: string,
      displayLoader: boolean,
      openLobbiesPageIfFailure: boolean
    ) => {
      if (_isQuickJoiningOrStartingAGame) return;
      const _gameId = gdjs.projectData.properties.projectUuid;
      if (!_gameId) {
        logger.error(
          'The game ID is missing, the quick join lobby action cannot continue.'
        );
        return;
      }

      _quickJoinLobbyFailureReason = null;
      _isQuickJoiningOrStartingAGame = true;
      if (displayLoader) {
        gdjs.multiplayerComponents.displayLoader(runtimeScene, true);