コード例 #1
0
        /// <summary>
        /// Creates a local lobby and provides you the connected owner's lobby.
        /// </summary>
        /// <param name="id">the lobby's ID</param>
        /// <param name="capacity">how many player can connect.</param>
        /// <param name="ownerId">the owner of the lobby.</param>
        /// <param name="packetLossPercent">for unreliable packets, how often </param>
        /// <param name="packetLossRng">a System.Random instance for randomly producing packet loss</param>
        public static LocalLobbyView Create(ulong id, int capacity, ulong ownerId = 0,
                                            double packetLossPercent = 0, Random packetLossRng = null)
        {
            packetLossRng = packetLossRng ?? new Random();
            var            lobby = new LocalLobby(id, capacity, ownerId, packetLossPercent, packetLossRng);
            LocalLobbyView owner = lobby.CreateView(ownerId);

            owner.Join().Wait();
            return(owner);
        }
コード例 #2
0
        public void LocalLobby_CreateViewDoesNotTriggerEvents()
        {
            const ulong id        = 69;
            const ulong ownerId   = 400;
            const int   capacity  = 4;
            var         lobbyView = LocalLobby.Create(id, capacity, ownerId);

            lobbyView.OnMemberJoin  += (member) => Assert.Fail("OnMemberJoin should not be called");
            lobbyView.OnMemberLeave += (member) => Assert.Fail("OnMemberLeave should not be called");
            lobbyView.BaseLobby.CreateView(450);
        }
コード例 #3
0
        public void LocalLobby_Create()
        {
            const ulong id        = 69;
            const ulong ownerId   = 400;
            const int   capacity  = 4;
            var         lobbyView = LocalLobby.Create(id, capacity, ownerId);

            Assert.AreEqual(id, lobbyView.Id, "Lobby ID must be the same");
            Assert.AreEqual(ownerId, lobbyView.OwnerId, "Lobby view ID must be the same");
            Assert.AreEqual(ownerId, lobbyView.UserId, "Lobby view user ID must be the same");
            Assert.AreEqual(1, lobbyView.MemberCount, "Lobby view user ID must be the same");
            Assert.AreEqual(capacity, lobbyView.Capacity, "Lobby view capacity must be the same");
        }
コード例 #4
0
        public void LocalLobby_LeaveTriggersOnMemberLeave()
        {
            const ulong id        = 69;
            const ulong ownerId   = 400;
            const int   capacity  = 4;
            var         lobbyView = LocalLobby.Create(id, capacity, ownerId);
            var         triggered = false;

            lobbyView.OnMemberLeave += (member) => triggered = true;
            var remote = lobbyView.BaseLobby.CreateView(450);

            remote.Join().Wait();
            remote.Leave();
            Assert.IsTrue(triggered);
        }
コード例 #5
0
        public void LocalLobby_SetMetadataDoesntUpdate()
        {
            const ulong  id        = 69;
            const ulong  ownerId   = 400;
            const int    capacity  = 4;
            const string key       = "key";
            const string value     = "value";
            var          lobbyView = LocalLobby.Create(id, capacity, ownerId);
            var          triggered = false;
            var          remote    = lobbyView.BaseLobby.CreateView(450);

            remote.Join().Wait();
            lobbyView.SetMetadata(key, value);
            lobbyView.OnUpdated += () => triggered = true;
            lobbyView.SetMetadata(key, value);
            Assert.AreEqual(value, remote.GetMetadata(key));
            Assert.IsFalse(triggered);
        }
コード例 #6
0
        public void LocalLobby_SetMemberMetadataUpdatesEveryone()
        {
            const ulong  id        = 69;
            const ulong  ownerId   = 400;
            const int    capacity  = 4;
            const string key       = "key";
            const string value     = "value";
            var          lobbyView = LocalLobby.Create(id, capacity, ownerId);
            ulong        updatedId = 0;

            lobbyView.OnMemberUpdated += (mem) => updatedId = mem.Id;
            var remote = lobbyView.BaseLobby.CreateView(450);

            remote.Join().Wait();
            var member = lobbyView.Members.Get(remote.UserId);

            member.SetMetadata(key, value);
            Assert.AreEqual(value, remote.Members.Get(remote.UserId).GetMetadata(key));
            Assert.AreEqual(updatedId, remote.UserId);
        }