예제 #1
0
        internal MatchListing(MatchListingType type, ClientSession creator, LevelData levelData, string name, uint minRank, uint maxRank, uint maxMembers, bool onlyFriends)
        {
            this._Clients      = new ClientSessionCollectionLimited((int)maxMembers, this.Leave0);
            this.LobbyClients  = new ClientSessionCollection();
            this.BannedClients = new ConcurrentBag <IUserIdentifier>();

            this.LevelData = levelData;

            this.Name = name;

            this.MinRank = minRank;
            this.MaxRank = maxRank;

            this.MaxMembers  = maxMembers;
            this.OnlyFriends = onlyFriends;

            this.Type = type;

            if (creator != null)
            {
                this._HostSocketId = creator.SocketId;

                creator.Connection.OnDisconnected += this.OnCreatorDisconnectEarly;
            }
        }
예제 #2
0
        public static string GetLobbyId(this MatchListingType type, uint id)
        {
            return(type switch
            {
                MatchListingType.Normal => $"match-listing-{id}",
                MatchListingType.LevelOfTheDay => $"lotd-{id}",
                MatchListingType.Tournament => $"tournament-{id}",

                _ => throw new NotSupportedException(nameof(type)),
            });
예제 #3
0
    internal async Task <MatchListing> TryCreateMatchAsync(ClientSession session, uint levelId, uint version, uint minRank, uint maxRank, uint maxMembers, bool onlyFriends, MatchListingType type = MatchListingType.Normal)
    {
        LevelData level = await LevelManager.GetLevelDataAsync(levelId, version);

        return(this.TryCreateMatch(session, level, minRank, maxRank, maxMembers, onlyFriends, type));
    }
예제 #4
0
    internal MatchListing TryCreateMatch(ClientSession session, LevelData level, uint minRank, uint maxRank, uint maxMembers, bool onlyFriends, MatchListingType type = MatchListingType.Normal)
    {
        if (session.LobbySession.MatchListing == null)
        {
            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(this, this.matchManager, type, session, level, type.GetLobbyId(this.GetNextMatchListingId()), minRank, maxRank, maxMembers, onlyFriends);
                session.SendPacket(new MatchCreatedOutgoingMessage(listing));

                if (this.MatchListings.TryAdd(listing.Name, listing))
                {
                    return(listing);
                }
                else
                {
                    listing.Leave(session);
                }
            }
        }

        return(null);
    }