public void Set(UpdateLobbyOptions other) { if (other != null) { m_ApiVersion = LobbyInterface.UpdatelobbyApiLatest; LobbyModificationHandle = other.LobbyModificationHandle; } }
/// <summary> /// Short UpdateLobbyModification /// </summary> /// <param name="lobby">LobbyModification</param> /// <param name="key">Key</param> /// <param name="value">Value</param> /// <param name="visibility">Visibility type</param> public static void AddAttribute(this LobbyModification modify, string key, AttributeDataValue value, LobbyAttributeVisibility visibility) { var attr = new AttributeData(); attr.Key = key; attr.Value = value; var addOp = new LobbyModificationAddAttributeOptions { Attribute = attr, Visibility = visibility }; var addRes = modify.AddAttribute(addOp); if (addRes != Result.Success) { Debug.LogError($"{nameof(addRes)}:{addRes}"); } }
/// <summary> /// Update an attribute that is attached to the lobby. /// </summary> /// <param name="attribute">The new data to apply.</param> private void UpdateAttribute(AttributeData attribute) { LobbyModification modHandle = new LobbyModification(); EOSSDKComponent.GetLobbyInterface().UpdateLobbyModification(new UpdateLobbyModificationOptions { LobbyId = currentLobbyId, LocalUserId = EOSSDKComponent.LocalUserProductId }, out modHandle); modHandle.AddAttribute(new LobbyModificationAddAttributeOptions { Attribute = attribute, Visibility = LobbyAttributeVisibility.Public }); EOSSDKComponent.GetLobbyInterface().UpdateLobby(new UpdateLobbyOptions { LobbyModificationHandle = modHandle }, null, (UpdateLobbyCallbackInfo callback) => { if (callback.ResultCode != Result.Success) { AttributeUpdateFailed?.Invoke(attribute.Key, $"There was an error while updating attribute \"{ attribute.Key }\". Error: " + callback.ResultCode); return; } AttributeUpdateSucceeded?.Invoke(attribute.Key); }); }
/// <summary> /// Remove an attribute attached to the lobby. /// </summary> /// <param name="key">The key of the attribute that will be removed.</param> public virtual void RemoveAttribute(string key) { LobbyModification modHandle = new LobbyModification(); EOSSDKComponent.GetLobbyInterface().UpdateLobbyModification(new UpdateLobbyModificationOptions { LobbyId = currentLobbyId, LocalUserId = EOSSDKComponent.LocalUserProductId }, out modHandle); modHandle.RemoveAttribute(new LobbyModificationRemoveAttributeOptions { Key = key }); EOSSDKComponent.GetLobbyInterface().UpdateLobby(new UpdateLobbyOptions { LobbyModificationHandle = modHandle }, null, (UpdateLobbyCallbackInfo callback) => { if (callback.ResultCode != Result.Success) { AttributeUpdateFailed?.Invoke(key, $"There was an error while removing attribute \"{ key }\". Error: " + callback.ResultCode); return; } AttributeUpdateSucceeded?.Invoke(key); }); }
/// <summary> /// Creates a lobby based on given parameters using Epic Online Services. /// <para>You can get the data that was added to the lobby by subscribing to the <see cref="CreateLobbySucceeded"/> event which gives you a list of <see cref="Attribute"/>.</para> /// <para>This process may throw errors. You can get errors by subscribing to the <see cref="CreateLobbyFailed"/> event.</para> /// </summary> /// <param name="maxConnections">The maximum amount of connections the lobby allows.</param> /// <param name="permissionLevel">The restriction on the lobby to prevent unwanted people from joining.</param> /// <param name="presenceEnabled">Use Epic's overlay to display information to others.</param> /// <param name="lobbyData">Optional data that you can to the lobby. By default, there is an empty attribute for searching and an attribute which holds the host's network address.</param> public virtual void CreateLobby(uint maxConnections, LobbyPermissionLevel permissionLevel, bool presenceEnabled, AttributeData[] lobbyData = null) { EOSSDKComponent.GetLobbyInterface().CreateLobby(new CreateLobbyOptions { //lobby options LocalUserId = EOSSDKComponent.LocalUserProductId, MaxLobbyMembers = maxConnections, PermissionLevel = permissionLevel, PresenceEnabled = presenceEnabled, }, null, (CreateLobbyCallbackInfo callback) => { List <Attribute> lobbyReturnData = new List <Attribute>(); //if the result of CreateLobby is not successful, invoke an error event and return if (callback.ResultCode != Result.Success) { CreateLobbyFailed?.Invoke("There was an error while creating a lobby. Error: " + callback.ResultCode); return; } //create mod handle and lobby data LobbyModification modHandle = new LobbyModification(); AttributeData defaultData = new AttributeData { Key = DefaultAttributeKey, Value = DefaultAttributeKey }; AttributeData hostAddressData = new AttributeData { Key = hostAddressKey, Value = EOSSDKComponent.LocalUserProductIdString }; //set the mod handle EOSSDKComponent.GetLobbyInterface().UpdateLobbyModification(new UpdateLobbyModificationOptions { LobbyId = callback.LobbyId, LocalUserId = EOSSDKComponent.LocalUserProductId }, out modHandle); //add attributes modHandle.AddAttribute(new LobbyModificationAddAttributeOptions { Attribute = defaultData, Visibility = LobbyAttributeVisibility.Public }); modHandle.AddAttribute(new LobbyModificationAddAttributeOptions { Attribute = hostAddressData, Visibility = LobbyAttributeVisibility.Public }); //add user attributes if (lobbyData != null) { foreach (AttributeData data in lobbyData) { modHandle.AddAttribute(new LobbyModificationAddAttributeOptions { Attribute = data, Visibility = LobbyAttributeVisibility.Public }); lobbyReturnData.Add(new Attribute { Data = data, Visibility = LobbyAttributeVisibility.Public }); } } //update the lobby EOSSDKComponent.GetLobbyInterface().UpdateLobby(new UpdateLobbyOptions { LobbyModificationHandle = modHandle }, null, (UpdateLobbyCallbackInfo updateCallback) => { //if there was an error while updating the lobby, invoke an error event and return if (updateCallback.ResultCode != Result.Success) { CreateLobbyFailed?.Invoke("There was an error while updating the lobby. Error: " + updateCallback.ResultCode); return; } LobbyDetails details; EOSSDKComponent.GetLobbyInterface().CopyLobbyDetailsHandle(new CopyLobbyDetailsHandleOptions { LobbyId = callback.LobbyId, LocalUserId = EOSSDKComponent.LocalUserProductId }, out details); ConnectedLobbyDetails = details; isLobbyOwner = true; ConnectedToLobby = true; currentLobbyId = callback.LobbyId; //invoke event CreateLobbySucceeded?.Invoke(lobbyReturnData); }); }); }