Exemplo n.º 1
0
        /// <summary>
        ///     Creates a new <see cref="PlayerMetadata" /> object from the specified clan, rank and username and adds it to the
        ///     database.
        /// </summary>
        /// <param name="clan">The clan, which must not be <c>null</c>.</param>
        /// <param name="rank">The rank, which must not be <c>null</c>.</param>
        /// <param name="username">The username, which must not be <c>null</c>.</param>
        /// <returns>The metadata.</returns>
        public PlayerMetadata Add([NotNull] Clan clan, [NotNull] ClanRank rank, [NotNull] string username)
        {
            if (clan == null)
            {
                throw new ArgumentNullException(nameof(clan));
            }
            if (rank == null)
            {
                throw new ArgumentNullException(nameof(rank));
            }
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }

            lock (_syncLock)
            {
                var metadata = new PlayerMetadata(clan, rank);

                clan.Members.Add(username);
                _metadataCache.Add(username, metadata);
                _connection.Query("INSERT INTO ClanMembers (Clan, Rank, Username) VALUES (@0, @1, @2)", clan.Name,
                                  rank.Name, username);
                return(metadata);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Loads the clans.
        /// </summary>
        public void Load()
        {
            lock (_syncLock)
            {
                _clans.Clear();
                using (var reader = _connection.QueryReader("SELECT * FROM Clans"))
                {
                    while (reader.Read())
                    {
                        var name           = reader.Get <string>("Clan");
                        var owner          = reader.Get <string>("Owner");
                        var prefix         = reader.Get <string>("Prefix");
                        var chatColor      = reader.Get <string>("ChatColor");
                        var motd           = reader.Get <string>("Motd");
                        var isFriendlyFire = reader.Get <int>("IsFriendlyFire") == 1;

                        var clan = new Clan(name, owner)
                        {
                            Prefix         = prefix,
                            ChatColor      = chatColor,
                            Motd           = motd,
                            IsFriendlyFire = isFriendlyFire
                        };
                        using (var reader2 =
                                   _connection.QueryReader("SELECT Permission FROM ClanHasPermission WHERE Clan = @0", name))
                        {
                            while (reader2.Read())
                            {
                                var permission = reader2.Get <string>("Permission");
                                clan.Permissions.Add(permission);
                            }
                        }
                        using (var reader2 =
                                   _connection.QueryReader("SELECT Rank, Tag FROM ClanRanks WHERE Clan = @0", name))
                        {
                            while (reader2.Read())
                            {
                                var rank     = reader2.Get <string>("Rank");
                                var tag      = reader2.Get <string>("Tag");
                                var clanRank = new ClanRank(rank, tag);

                                using (var reader3 = _connection.QueryReader(
                                           "SELECT Permission FROM ClanRankHasPermission WHERE Clan = @0 AND Rank = @1", clan,
                                           rank))
                                {
                                    while (reader3.Read())
                                    {
                                        var permission = reader3.Get <string>("Permission");
                                        clanRank.Permissions.Add(permission);
                                    }
                                }

                                clan.Ranks.Add(clanRank);
                            }
                        }

                        _clans.Add(clan);
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="PlayerMetadata" /> class with the specified clan and rank.
 /// </summary>
 /// <param name="clan">The clan, which must not be <c>null</c>.</param>
 /// <param name="clanRank">The rank, which must not be <c>null</c>.</param>
 public PlayerMetadata([NotNull] Clan clan, [NotNull] ClanRank clanRank)
 {
     Clan = clan ?? throw new ArgumentNullException(nameof(clan));
     Rank = clanRank ?? throw new ArgumentNullException(nameof(clanRank));
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Loads the clans.
        /// </summary>
        public void Load()
        {
            lock (_syncLock)
            {
                _clans.Clear();
                using (var reader = _connection.QueryReader("SELECT * FROM Clans"))
                {
                    while (reader.Read())
                    {
                        var name                  = reader.Get <string>("Clan");
                        var owner                 = reader.Get <string>("Owner");
                        var prefix                = reader.Get <string>("Prefix");
                        var chatColor             = reader.Get <string>("ChatColor");
                        var motd                  = reader.Get <string>("Motd");
                        var spawnPointCoordinates = reader.Get <string>("SpawnPoint");
                        var splitCoordinates      =
                            Regex.Split(
                                Regex.Replace(spawnPointCoordinates ?? string.Empty, @"[{|}|X|:]", string.Empty), "Y");
                        var isFriendlyFire = reader.Get <int>("IsFriendlyFire") == 1;
                        var isPrivate      = reader.Get <int>("IsPrivate") == 1;

                        var clan = new Clan(name, owner)
                        {
                            Prefix          = prefix,
                            ChatColor       = chatColor,
                            Motd            = motd,
                            BaseCoordinates = string.IsNullOrWhiteSpace(spawnPointCoordinates)
                                ? (Vector2?)null
                                : new Vector2(float.Parse(splitCoordinates[0]), float.Parse(splitCoordinates[1])),
                            IsFriendlyFire = isFriendlyFire,
                            IsPrivate      = isPrivate
                        };
                        using (var reader2 =
                                   _connection.QueryReader("SELECT Username FROM ClanHasBan WHERE Clan = @0", name))
                        {
                            while (reader2.Read())
                            {
                                var username = reader2.Get <string>("Username");
                                clan.BannedUsers.Add(username);
                            }
                        }

                        using (var reader2 =
                                   _connection.QueryReader("SELECT Permission FROM ClanHasPermission WHERE Clan = @0", name))
                        {
                            while (reader2.Read())
                            {
                                var permission = reader2.Get <string>("Permission");
                                clan.Permissions.Add(permission);
                            }
                        }

                        using (var reader2 =
                                   _connection.QueryReader("SELECT Rank, Tag FROM ClanRanks WHERE Clan = @0", name))
                        {
                            while (reader2.Read())
                            {
                                var rank     = reader2.Get <string>("Rank");
                                var tag      = reader2.Get <string>("Tag");
                                var clanRank = new ClanRank(rank, tag);

                                using (var reader3 = _connection.QueryReader(
                                           "SELECT Permission FROM ClanRankHasPermission WHERE Clan = @0 AND Rank = @1", name,
                                           rank))
                                {
                                    while (reader3.Read())
                                    {
                                        var permission = reader3.Get <string>("Permission");
                                        clanRank.Permissions.Add(permission);
                                    }
                                }

                                clan.Ranks.Add(clanRank);
                            }
                        }

                        _clans.Add(clan);
                    }
                }
            }
        }