internal void AddMatch(MatchListing listing) { if (listing.JoinLobby(this.Session)) { this._Matches.Add(listing); } }
internal async Task <MatchListing> TryCreateMatchAsync(ClientSession session, uint levelId, uint version, uint minRank, uint maxRank, uint maxMembers, bool onlyFriends) { if (session.LobbySession.MatchListing == null) { LevelData level = await LevelManager.GetLevelDataAsync(levelId, version); if (level != null && level.Publish || (!session.IsGuest && level.AuthorUserId == session.UserData.Id) || session.HasPermissions(Permissions.ACCESS_SEE_UNPUBLISHED_LEVELS)) { if (maxMembers < 1) { maxMembers = 1; } else if (maxMembers > 8 && !session.HasPermissions(Permissions.ACCESS_MATCH_LISTING_NO_MEMBERS_LIMIT)) { maxMembers = 8; } MatchListing listing = new MatchListing(session, level, "match-listing-" + this.GetNextMatchListingId(), minRank, maxRank, maxMembers, onlyFriends); session.SendPacket(new MatchCreatedOutgoingMessage(listing)); if (this.MatchListings.TryAdd(listing.Name, listing)) { //Don't do quick join for one player matches, host only obviously if (maxMembers == 1) { return(listing); } else if (listing.SpotsLeft > 0) //Can we do quick join? { //As we use packets some players might not join //So keep track of the current spots and decrease as we send packets to avoid sending too many players //Also other players might join while the packet has not yet arrieved to the client uint spotsLeft = listing.SpotsLeft; foreach (ClientSession other in this.QuickJoinClients.Values) { if (spotsLeft > 0) //Can we fill it up even more { if (listing.CanJoin(other) == MatchListingJoinStatus.Success && this.QuickJoinClients.Remove(other)) { other.SendPacket(new QuickJoinSuccessOutgoingMessage(listing)); spotsLeft--; } } } } return(listing); } else { listing.Leave(session, MatchListingLeaveReason.FailedJoin); } } } return(null); }
internal MatchListing GetLeveOfTheDay() { MatchListing listing = this.MatchListings.Values.Where((m) => m.Type == MatchListingType.LevelOfTheDay).OrderByDescending((l) => l.ClientsCount).FirstOrDefault(); if (listing == null) { IReadOnlyCollection <LevelData> levels = LevelManager.GetCampaignLevels().GetAwaiter().GetResult().Levels; if (levels.Count > 0) { LevelData random = levels.ElementAt(new Random().Next(0, levels.Count)); listing = new MatchListing(MatchListingType.LevelOfTheDay, null, random, MatchListingType.LevelOfTheDay.GetLobbyId(this.GetNextMatchListingId()), 0, uint.MaxValue, 4, false); if (!this.MatchListings.TryAdd(listing.Name, listing)) { return(null); } } } return(listing); }
internal void RemoveMatch(MatchListing listing) { this._Matches.Remove(listing); listing.LeaveLobby(this.Session); }
internal void Die(MatchListing matchListing) { this.MatchListings.TryRemove(matchListing.Name, out _); }