/// <summary>
        /// Async Find
        /// </summary>
        /// <param name="search">LobbySearch</param>
        /// <param name="localUserId">Login user id</param>
        /// <returns>Task</returns>
        public static async UniTask <LobbySearchFindCallbackInfo> Find(this LobbySearch search, ProductUserId localUserId)
        {
            var op = new LobbySearchFindOptions
            {
                LocalUserId = localUserId
            };
            LobbySearchFindCallbackInfo info = null;

            search.Find(op, null, e =>
            {
                info = e;
            });

            while (info == null || info.ResultCode == Result.OperationWillRetry)
            {
                if (info != null)
                {
                    Debug.LogError($"error {DebugTools.GetClassMethodName()}:{info.ResultCode}");
                    info = null;
                }
                await UniTask.NextFrame();
            }

            if (info.ResultCode == Result.Success)
            {
                return(info);
            }
            Debug.LogError($"error {DebugTools.GetClassMethodName()}:{info.ResultCode}");
            return(null);
        }
 void LobbyFound(Empty e, Result result)
 {
     for (uint i = 0; i < LobbySearch.LobbyCount; i++)
     {
         var id = LobbySearch.GetLobbyByIndex(i);
         MyHud.Notifications.Add(new MyHudNotificationDebug(String.Format("Lobby found {0}, player count {1}", id.LobbyId, id.MemberCount), 3000));
         id.Leave();
     }
 }
Esempio n. 3
0
    /// <summary>
    /// Finds lobbies based on given parameters using Epic Online Services.
    /// <para>You can get the found lobbies by subscribing to the <see cref="FindLobbiesSucceeded"/> event which gives you a list of <see cref="LobbyDetails"/>.</para>
    /// <para>This process may throw errors. You can get errors by subscribing to the <see cref="FindLobbiesFailed"/> event.</para>
    /// </summary>
    /// <param name="maxResults">The maximum amount of results to return.</param>
    /// <param name="lobbySearchSetParameterOptions">The parameters to search by. If left empty, then the search will use the default attribute attached to all the lobbies.</param>
    public virtual void FindLobbies(uint maxResults = 100, LobbySearchSetParameterOptions[] lobbySearchSetParameterOptions = null)
    {
        //create search handle and list of lobby details
        LobbySearch search = new LobbySearch();

        //set the search handle
        EOSSDKComponent.GetLobbyInterface().CreateLobbySearch(new CreateLobbySearchOptions {
            MaxResults = maxResults
        }, out search);

        //set search parameters
        if (lobbySearchSetParameterOptions != null)
        {
            foreach (LobbySearchSetParameterOptions searchOption in lobbySearchSetParameterOptions)
            {
                search.SetParameter(searchOption);
            }
        }
        else
        {
            search.SetParameter(new LobbySearchSetParameterOptions {
                ComparisonOp = ComparisonOp.Equal,
                Parameter    = new AttributeData {
                    Key = DefaultAttributeKey, Value = DefaultAttributeKey
                }
            });
        }

        //find lobbies
        search.Find(new LobbySearchFindOptions {
            LocalUserId = EOSSDKComponent.LocalUserProductId
        }, null, (LobbySearchFindCallbackInfo callback) => {
            //if the search was unsuccessful, invoke an error event and return
            if (callback.ResultCode != Result.Success)
            {
                FindLobbiesFailed?.Invoke("There was an error while finding lobbies. Error: " + callback.ResultCode);
                return;
            }

            foundLobbies.Clear();

            //for each lobby found, add data to details
            for (int i = 0; i < search.GetSearchResultCount(new LobbySearchGetSearchResultCountOptions {
            }); i++)
            {
                LobbyDetails lobbyInformation;
                search.CopySearchResultByIndex(new LobbySearchCopySearchResultByIndexOptions {
                    LobbyIndex = (uint)i
                }, out lobbyInformation);
                foundLobbies.Add(lobbyInformation);
            }

            //invoke event
            FindLobbiesSucceeded?.Invoke(foundLobbies);
        });
    }
        /// <summary>
        /// Short SetLobbyId
        /// </summary>
        /// <param name="search">LobbySearch</param>
        /// <param name="lobbyId">Lobby id</param>
        public static void SetLobbyId(this LobbySearch search, string lobbyId)
        {
            var op = new LobbySearchSetLobbyIdOptions
            {
                LobbyId = lobbyId
            };
            var result = search.SetLobbyId(op);

            if (result != Result.Success)
            {
                Debug.LogError($"error {DebugTools.GetClassMethodName()}:{result}");
            }
        }
        private static void FindLobby()
        {
            // Wait 5s
            Thread.Sleep(5000);

            // Request lobbies from steam
            LobbySearch.AddRequestLobbyListNumericalFilter(
                MyMultiplayer.AppVersionTag,
                MyFinalBuildConstants.APP_VERSION,
                LobbyComparison.LobbyComparisonEqual
                );

            LobbySearch.RequestLobbyList(LobbiesRequestCompleted);
        }
        /// <summary>
        /// Short GetSearchResultCount
        /// </summary>
        /// <param name="search">LobbySearch</param>
        /// <param name="localUserId">Login user id</param>
        public static LobbyDetails CopySearchResultByIndex(this LobbySearch search, uint lobbyIndex)
        {
            var resOp = new LobbySearchCopySearchResultByIndexOptions
            {
                LobbyIndex = lobbyIndex
            };
            var result = search.CopySearchResultByIndex(resOp, out LobbyDetails detail);

            if (result == Result.Success)
            {
                return(detail);
            }
            Debug.LogError($"error {DebugTools.GetClassMethodName()}:{result}");
            return(null);
        }
Esempio n. 7
0
            public LoadLobbyListResult(bool showOnlyCompatible)
            {
                MySandboxGame.Log.WriteLine("Requesting dedicated servers");

                if (showOnlyCompatible)
                {
                    LobbySearch.AddRequestLobbyListNumericalFilter(MyMultiplayer.AppVersionTag, MyFinalBuildConstants.APP_VERSION, LobbyComparison.LobbyComparisonEqual);
                }

                //var searchName = m_blockSearch.Text.Trim();
                //if (!string.IsNullOrWhiteSpace(searchName))
                //    LobbySearch.AddRequestLobbyListStringFilter(MyMultiplayer.WorldNameTag, searchName, LobbyComparison.LobbyComparisonEqual);

                MySandboxGame.Log.WriteLine("Requesting worlds, only compatible: " + showOnlyCompatible);
                LobbySearch.RequestLobbyList(LobbiesCompleted);
            }
        /// <summary>
        /// Short SetParameter
        /// </summary>
        /// <param name="search">LobbySearch</param>
        /// <param name="key">Key</param>
        /// <param name="value">Value</param>
        /// <param name="comparisonOp">Compare option</param>
        public static void SetParameter(this LobbySearch search, string key, AttributeDataValue value, ComparisonOp comparisonOp)
        {
            var attr = new AttributeData();

            attr.Key   = key;
            attr.Value = value;
            var paramOp = new LobbySearchSetParameterOptions
            {
                Parameter    = attr,
                ComparisonOp = comparisonOp,
            };
            var result = search.SetParameter(paramOp);

            if (result != Result.Success)
            {
                Debug.LogError($"error {DebugTools.GetClassMethodName()}:{result}");
            }
        }
Esempio n. 9
0
        private void endPublicLobbiesAction(IMyAsyncResult result, MyGuiScreenProgressAsync screen)
        {
            var loadResult = (LoadLobbyListResult)result;

            m_lobbies.Clear();

            if (m_showOnlyFriends.IsChecked)
            {
                LobbySearch.AddFriendLobbies(m_lobbies);
            }
            else
            {
                LobbySearch.AddFriendLobbies(m_lobbies);
                LobbySearch.AddPublicLobbies(m_lobbies);
            }

            RefreshGameList();
            screen.CloseScreen();
        }
        private static void LobbiesRequestCompleted(Result result)
        {
            // if the request is ok
            if (result != Result.OK)
            {
                return;
            }

            var lobbies = new List <Lobby>();

            // Add all lobbies
            LobbySearch.AddPublicLobbies(lobbies);
            LobbySearch.AddFriendLobbies(lobbies);

            // search for new lobby
            foreach (var lobby in lobbies)
            {
                var owner = MyMultiplayerLobby.GetLobbyHostSteamId(lobby);
                if (owner == m_ownerId && lobby.LobbyId != m_oldLobbyId)
                {
                    //
                    MyScreenManager.RemoveScreenByType(typeof(MyGuiScreenProgress));
                    // Join the game
                    MyJoinGameHelper.JoinGame(lobby);
                    return;
                }
            }

            // Exit if the search is taking too long
            m_elapsedMs += 5000;
            if (m_elapsedMs > 120000)
            {
                // Remove the progress wheel
                MyScreenManager.RemoveScreenByType(typeof(MyGuiScreenProgress));
                return;
            }

            // Repeat the search
            FindLobby();
        }
 /// <summary>
 /// Short GetSearchResultCount
 /// </summary>
 /// <param name="search">LobbySearch</param>
 /// <returns>Result count</returns>
 public static uint GetSearchResultCount(this LobbySearch search) => search.GetSearchResultCount(new LobbySearchGetSearchResultCountOptions());