public static void SetPatronRoles(Player[] players)
        {
            if (ArgumentParsing.ArrayIsNullOrEmpty(players))
            {
                return;
            }

            PatreonPlugin.CreateFile();

            Patron[] patronIds = PatreonPlugin.Patrons;

            foreach (Player player in players)
            {
                foreach (Patron patron in patronIds)
                {
                    if (string.IsNullOrEmpty(player.SteamId) || patron.SteamId != player.SteamId)
                    {
                        continue;
                    }

                    player.SetRank(patron.Colour, patron.Tag);
                    break;
                }
            }
        }
Esempio n. 2
0
        public static Patron FromString(string fileLine)
        {
            fileLine = fileLine?.Trim();

            if (string.IsNullOrEmpty(fileLine))
            {
                return(null);
            }

            string[] args = ArgumentParsing.StringToArgs(fileLine);

            if (ArgumentParsing.ArrayIsNullOrEmpty(args))
            {
                return(null);
            }

            string steam64Match = args[0];

            string tagTagValue    = ArgumentParsing.GetParamFromArgs(args, tagKeys, tagAliases);
            string colourTagValue = ArgumentParsing.GetParamFromArgs(args, colourKeys, colourAliases);
            string itemTagValue   = ArgumentParsing.GetParamFromArgs(args, itemKeys, itemAliases);
            bool   autoRefresh    = ArgumentParsing.GetFlagFromArgs(args, autoRefreshKeys, autoRefreshAliases);
            bool   autoReserve    = ArgumentParsing.GetFlagFromArgs(args, autoReserveKeys, autoReserveAliases);
            string rankTagValue   = ArgumentParsing.GetParamFromArgs(args, rankKeys, rankAliases);

            // Set from default or rank values
            if (tagTagValue == null)
            {
                const string rankConf = ConfigOptions.RankTag;
                const string defConf  = ConfigOptions.PatreonTag;
                tagTagValue = ConfigOptions.ContainsRank(rankConf, rankTagValue) ? ConfigFile.GetString(ConfigOptions.GetRankConf(rankConf, rankTagValue)) : PatreonPlugin.Singleton.GetConfigString(defConf);

                // PatreonPlugin.Singleton.Debug("No custom tag value, using default tag from " + (ConfigOptions.ContainsRank(rankConf, rankTagValue) ? "rank" : "patreon") + " config: \"" + tagTagValue + "\"");
            }

            if (colourTagValue == null)
            {
                const string rankConf = ConfigOptions.RankTagColour;
                const string defConf  = ConfigOptions.PatreonTagColour;
                colourTagValue = ConfigOptions.ContainsRank(rankConf, rankTagValue) ? ConfigFile.GetString(ConfigOptions.GetRankConf(rankConf, rankTagValue)) : PatreonPlugin.Singleton.GetConfigString(defConf);

                // PatreonPlugin.Singleton.Debug("No custom colour value, using default colour from " + (ConfigOptions.ContainsRank(rankConf, rankTagValue) ? "rank" : "patreon") + " config: \"" + colourTagValue + "\"");
            }

            if (itemTagValue == null)
            {
                const string rankConf = ConfigOptions.RankItems;
                const string defConf  = ConfigOptions.PatreonItems;
                itemTagValue = ConfigOptions.ContainsRank(rankConf, rankTagValue) ? ConfigFile.GetString(ConfigOptions.GetRankConf(rankConf, rankTagValue)) : PatreonPlugin.Singleton.GetConfigString(defConf);

                // PatreonPlugin.Singleton.Debug("No custom items value, using default items from " + (ConfigOptions.ContainsRank(rankConf, rankTagValue) ? "rank" : "patreon") + " config: \"" + itemTagValue + "\"");
            }

            if (!autoRefresh)
            {
                const string rankConf = ConfigOptions.RankTagAutoRefresh;
                const string defConf  = ConfigOptions.PatreonTagAutoRefresh;
                autoRefresh = ConfigOptions.ContainsRank(rankConf, rankTagValue) ? ConfigFile.GetBool(ConfigOptions.GetRankConf(rankConf, rankTagValue)) : PatreonPlugin.Singleton.GetConfigBool(defConf);

                // PatreonPlugin.Singleton.Debug("No custom auto-refresh value, using default auto-refresh from " + (ConfigOptions.ContainsRank(rankConf, rankTagValue) ? "rank" : "patreon") + " config: \"" + AutoRefreshTags + "\"");
            }

            if (!autoReserve)
            {
                const string rankConf = ConfigOptions.RankAutoReserve;
                const string defConf  = ConfigOptions.PatreonAutoReserve;
                autoReserve = ConfigOptions.ContainsRank(rankConf, rankTagValue) ? ConfigFile.GetBool(ConfigOptions.GetRankConf(rankConf, rankTagValue)) : PatreonPlugin.Singleton.GetConfigBool(defConf);

                // PatreonPlugin.Singleton.Debug("No custom auto-reserve value, using default auto-reserve from " + (ConfigOptions.ContainsRank(rankConf, rankTagValue) ? "rank" : "patreon") + " config: \"" + AutoRefreshTags + "\"");
            }

            // Return new instance with values
            return(new Patron(steam64Match, tagTagValue, colourTagValue, itemTagValue, autoRefresh, autoReserve, rankTagValue));
        }