/// <summary> /// Setup lobby to host a game. /// </summary> /// <returns>true if lobby setup request was properly sent, false otherwise</returns> public bool SetupLobby() { Logger.Log("Setting up lobby."); Steamworks.SteamAPICall_t apiCall = Steamworks.SteamMatchmaking.CreateLobby(Steamworks.ELobbyType.k_ELobbyTypeFriendsOnly, MAX_PLAYERS); if (apiCall == Steamworks.SteamAPICall_t.Invalid) { Logger.Log("Unable to create lobby."); return(false); } Logger.Log("Waiting for lobby create reply.."); lobbyCreatedCallResult.Set(apiCall); return(true); }
/// <summary> /// Join a lobby with the specified ID. /// </summary> /// <param name="lobbyID">Lobby ID.</param> /// <param name="hostID">host ID.</param> public void JoinLobby(Steamworks.CSteamID lobbyID, Steamworks.CSteamID hostID) { Steamworks.SteamAPICall_t apiCall = Steamworks.SteamMatchmaking.JoinLobby(lobbyID); if (apiCall == Steamworks.SteamAPICall_t.Invalid) { Logger.Error($"Unable to join lobby {lobbyID}. JoinLobby call failed."); MPGUI.Instance.ShowMessageBox($"Failed to join lobby.\nPlease try again later."); return; } Logger.Debug("Setup player."); timeSinceLastHeartbeat = 0.0f; hostSteamID = hostID; lobbyEnterCallResult.Set(apiCall); }
/// <summary> /// Callback called when client accepts lobby join request from other steam user. /// </summary> /// <param name="request">The request.</param> private void OnGameLobbyJoinRequested(Steamworks.GameLobbyJoinRequested_t request) { Steamworks.SteamAPICall_t apiCall = Steamworks.SteamMatchmaking.JoinLobby(request.m_steamIDLobby); if (apiCall == Steamworks.SteamAPICall_t.Invalid) { Logger.Log("Unable to join lobby."); return; } Logger.Log("Setup player."); // Setup remote player. The HOST. timeSinceLastHeartbeat = 0.0f; players[1] = new NetPlayer(this, netWorld, request.m_steamIDFriend); lobbyEnterCallResult.Set(apiCall); }
/// <summary> /// Callback called when client accepts lobby join request from other steam user. /// </summary> /// <param name="request">The request.</param> private void OnGameLobbyJoinRequested(Steamworks.GameLobbyJoinRequested_t request) { Steamworks.SteamAPICall_t apiCall = Steamworks.SteamMatchmaking.JoinLobby(request.m_steamIDLobby); if (apiCall == Steamworks.SteamAPICall_t.Invalid) { Logger.Error($"Unable to join lobby {request.m_steamIDLobby}. JoinLobby call failed."); MPGUI.Instance.ShowMessageBox($"Failed to join lobby.\nPlease try again later."); return; } Logger.Debug("Setup player."); // Setup remote player. The HOST. timeSinceLastHeartbeat = 0.0f; players[1] = new NetPlayer(this, netWorld, request.m_steamIDFriend); lobbyEnterCallResult.Set(apiCall); }
/// <summary> /// Request current game lobbies. /// </summary> public void RequestLobbies() { Logger.Log("Trying to get list of available lobbies ..."); Steamworks.SteamAPICall_t apiCall = Steamworks.SteamMatchmaking.RequestLobbyList(); lobbyListResult.Set(apiCall); }