示例#1
0
        public async Task CreateLobby(string name, User user)
        {
            _lobbys.GetByAdminId(user.Id)
            .ToList()
            .ForEach(async l => await CloseLobby(l));

            var lobby = _lobbys.CreateLobby(name, new Player {
                ConnectionId = Context.ConnectionId, Id = user.Id, IsPresenter = true, IsConnected = true, IsRegistered = true, Name = user.Name
            });

            _logger.Log("Created", lobby);

            await Connect(user, lobby.Id);
        }
示例#2
0
    public override void Ready(User user)
    {
        instance = this;
        Debug.LogWarning(user.Display(true));
        // Fetch lobbies.
        Manager = Discord.GetLobbyManager();

#if UNITY_EDITOR
        var cr = Manager.GetLobbyCreateTransaction();
        cr.SetCapacity(2);
        cr.SetType(LobbyType.Public);
        Manager.CreateLobby(cr, (Result res, ref Lobby lob) =>
        {
            if (res == Result.Ok)
            {
                JoinLobby(lob);
            }
            else
            {
                log($"Failed created: {res}");
            }
        });

//#else

        var q = Manager.GetSearchQuery();
        q.Distance(LobbySearchDistance.Local);
        q.Limit(5);
        q.Filter("slots", LobbySearchComparison.GreaterThan, LobbySearchCast.Number, "0"); // lobby with space left

        Manager.Search(q, (r) =>
        {
            if (r == Result.Ok)
            {
                var count = Manager.LobbyCount();
                log($"There are {count} lobbies online");
                for (int i = 0; i < count; i++)
                {
                    var lobby = Manager.GetLobbyId(count);
                    log($"At {i}: {lobby}");
                }
            }
            else
            {
                log($"Failed search: {r}");
            }
        });
#endif
    }
示例#3
0
    // Functions to Use to Call from other scripts
    public void CreateLobby()
    {
        if (currentLobbyId != 0)
        {
            return;
        }

        var txn = lobbyManager.GetLobbyCreateTransaction();

        txn.SetCapacity(5);
        txn.SetType(LobbyType.Public);
        lobbyManager.CreateLobby(txn, (Result result, ref Lobby lobby) =>
        {
            SetCurrent(lobby.Id, lobby.Secret, lobby.OwnerId);
            DiscordNetworkLayerService.INSTANCE.SetMyPeerId();
            NewUpdateLobbyTransaction();
        });
    }
    public void CreateLobby()
    {
        LobbyTransaction txn = lobbyManager.GetLobbyCreateTransaction();

        lobbyManager.CreateLobby(txn, (Result result, ref Lobby lobby) =>
        {
            if (result == Result.Ok)
            {
                GD.Print("Successfully created a new lobby: ", lobby.Id);
                lobbyId = lobby.Id;
                UpdateActivity("In lobby...", true, true);
                UpdateMemberList();
                EmitSignal("JoinedLobby");
            }
            else
            {
                GD.PrintErr("Failed to create a new lobby: ", result);
            }
        });
    }
        private static void CreateLobby(Discord discord, LobbyManager lobbyManager)
        {
            var transaction = lobbyManager.GetLobbyCreateTransaction();

            transaction.SetCapacity(6);
            transaction.SetType(LobbyType.Public);
            //transaction.SetMetadata("a", "123");
            //transaction.SetMetadata("a", "456");
            //transaction.SetMetadata("b", "111");
            //transaction.SetMetadata("c", "222");

            lobbyManager.CreateLobby(transaction, (Result result, ref Lobby lobby) =>
            {
                if (result != Result.Ok)
                {
                    return;
                }

                var secret = lobbyManager.GetLobbyActivitySecret(lobby.Id);

                Console.WriteLine("Secret: " + secret);

                // Check the lobby's configuration.
                Console.WriteLine("lobby {0} with capacity {1} and secret {2}", lobby.Id, lobby.Capacity, lobby.Secret);

                //// Check lobby metadata.
                //foreach (var key in new string[] { "a", "b", "c" })
                //{
                //    Console.WriteLine("{0} = {1}", key, lobbyManager.GetLobbyMetadataValue(lobby.Id, key));
                //}

                // Print all the members of the lobby.
                foreach (var user in lobbyManager.GetMemberUsers(lobby.Id))
                {
                    Console.WriteLine("lobby member: {0}", user.Username);
                }

                // Send everyone a message.
                //lobbyManager.SendLobbyMessage(lobby.Id, "Hello from C#!", (_) =>
                //{
                //    Console.WriteLine("sent message");
                //});

                //// Update lobby.
                //var lobbyTransaction = lobbyManager.GetLobbyUpdateTransaction(lobby.Id);
                //lobbyTransaction.SetMetadata("d", "e");
                //lobbyTransaction.SetCapacity(16);
                //lobbyManager.UpdateLobby(lobby.Id, lobbyTransaction, (_) =>
                //{
                //    Console.WriteLine("lobby has been updated");
                //});

                //// Update a member.
                //var lobbyID = lobby.Id;
                //var userID = lobby.OwnerId;
                //var memberTransaction = lobbyManager.GetMemberUpdateTransaction(lobbyID, userID);
                //memberTransaction.SetMetadata("hello", "there");
                //lobbyManager.UpdateMember(lobbyID, userID, memberTransaction, (_) =>
                //{
                //    Console.WriteLine("lobby member has been updated: {0}", lobbyManager.GetMemberMetadataValue(lobbyID, userID, "hello"));
                //});

                //// Search lobbies.
                //var query = lobbyManager.GetSearchQuery();
                //// Filter by a metadata value.
                //query.Filter("metadata.a", LobbySearchComparison.GreaterThan, LobbySearchCast.Number, "455");
                //query.Sort("metadata.a", LobbySearchCast.Number, "0");
                //// Only return 1 result max.
                //query.Limit(1);
                //lobbyManager.Search(query, (_) =>
                //{
                //    Console.WriteLine("search returned {0} lobbies", lobbyManager.LobbyCount());
                //    if (lobbyManager.LobbyCount() == 1)
                //    {
                //        Console.WriteLine("first lobby secret: {0}", lobbyManager.GetLobby(lobbyManager.GetLobbyId(0)).Secret);
                //    }
                //});

                //lobbyManager.ConnectLobby(lobby.Id, secret, (Result result, ref Lobby lobby) =>
                //{
                //    Console.WriteLine("Connected to Lobby " + lobby.Id + " ? " + result);
                //});

                // Connect to voice chat.
                lobbyManager.ConnectVoice(lobby.Id, (_) =>
                {
                    Console.WriteLine("Connected to voice chat!");
                });

                //// Setup networking.
                //lobbyManager.ConnectNetwork(lobby.Id);
                //lobbyManager.OpenNetworkChannel(lobby.Id, 0, true);

                UpdateActivity(discord);

                discord.GetOverlayManager().OpenVoiceSettings((result) =>
                {
                    if (result == Result.Ok)
                    {
                        Console.WriteLine("Overlay is open to the voice settings for your application/");
                    }
                });
            });
        }