/// <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); }
internal void Disconnect(LocalLobbyView view) { var handle = new AccountHandle(view.UserId); if (!_connectedViews.ContainsKey(handle)) { return; } _metadata.RemoveMember(handle); _connectedViews.Remove(handle); foreach (var connectedView in _connectedViews.Values) { connectedView.Members.Remove(handle); } }
internal void Connect(LocalLobbyView view) { if (_connectedViews.Count >= Capacity) { throw new InvalidOperationException("Cannot join a lobby that is already full"); } var handle = new AccountHandle(view.UserId); if (_connectedViews.ContainsKey(handle)) { return; } _metadata.AddMember(handle); _connectedViews[handle] = view; foreach (var connectedView in _connectedViews.Values) { connectedView.Members.Add(handle); } }