public Task <Lobby> CreateLobby(LobbyCreateParams createParams) { var txn = _lobbyManager.GetLobbyCreateTransaction(); txn.SetCapacity(createParams.Capacity); txn.SetType((DiscordApp.LobbyType)createParams.Type); if (createParams.Metadata != null) { foreach (var kvp in createParams.Metadata) { if (kvp.Key == null || kvp.Value == null) { continue; } txn.SetMetadata(kvp.Key, kvp.Value.ToString()); } } var future = new TaskCompletionSource <Lobby>(); _lobbyManager.CreateLobby(txn, (DiscordApp.Result result, ref DiscordApp.Lobby lobby) => { if (result != DiscordApp.Result.Ok) { future.SetException(DiscordUtility.ToError(result)); return; } SetupLobbyChannels(lobby.Id); var outputLobby = new DiscordLobby(this, lobby); _connectedLobbies.Add(lobby.Id, outputLobby); var secret = _lobbyManager.GetLobbyActivitySecret(lobby.Id); var activity = new DiscordApp.Activity { Party = { Id = lobby.Id.ToString(), Size = { CurrentSize = 1, MaxSize = (int)createParams.Capacity } }, Secrets = { Join = secret } }; _activityManager.UpdateActivity(activity, res => {}); future.SetResult(outputLobby); }); return(future.Task); }
public override void ServerStart() { if (ClientConnected()) { Debug.Log("Client is already active!"); return; } if (ServerActive()) { Debug.Log("Server is already active!"); return; } if (discordClient == null || lobbyManager == null) { Debug.Log("Cannot create server as discord is not initialized!"); return; } clients = new BiDictionary <long, int>(); currentMemberId = 1; LobbyTransaction txn = lobbyManager.GetLobbyCreateTransaction(); txn.SetCapacity(serverCapacity); txn.SetType(lobbyType); lobbyCreated = false; lobbyManager.CreateLobby(txn, LobbyCreated); // Wait until server is actually ready. while (true) { discordClient.RunCallbacks(); if (lobbyCreated) { break; } System.Threading.Thread.Sleep(100); } lobbyCreated = false; }