Пример #1
0
        public async Task <ActionResult <GenericResponse> > RenamePost(string botName, [FromBody] BotRenameRequest request)
        {
            if (string.IsNullOrEmpty(botName))
            {
                throw new ArgumentNullException(nameof(botName));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (Bot.Bots == null)
            {
                throw new InvalidOperationException(nameof(Bot.Bots));
            }

            if (string.IsNullOrEmpty(request.NewName) || !ASF.IsValidBotName(request.NewName) || Bot.Bots.ContainsKey(request.NewName))
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.NewName)))));
            }

            if (!Bot.Bots.TryGetValue(botName, out Bot? bot))
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botName))));
            }

            bool result = await bot.Rename(request.NewName).ConfigureAwait(false);

            return(Ok(new GenericResponse(result)));
        }
Пример #2
0
        //读取购物车(多个Bot)
        private static async Task <string?> ResponseGetCartGames(ulong steamID, string botNames)
        {
            if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount)
            {
                throw new ArgumentOutOfRangeException(nameof(steamID));
            }

            if (string.IsNullOrEmpty(botNames))
            {
                throw new ArgumentNullException(nameof(botNames));
            }

            HashSet <Bot>?bots = Bot.GetBots(botNames);

            if ((bots == null) || (bots.Count == 0))
            {
                return(ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)) : null);
            }

            IList <string?> results = await Utilities.InParallel(bots.Select(bot => ResponseGetCartGames(bot, steamID))).ConfigureAwait(false);

            List <string> responses = new(results.Where(result => !string.IsNullOrEmpty(result)) !);

            return(responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null);
        }
Пример #3
0
        public async Task <ActionResult <GenericResponse> > ASFPost([FromBody] ASFRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (ASF.GlobalConfig == null)
            {
                throw new InvalidOperationException(nameof(ASF.GlobalConfig));
            }

            if (request.GlobalConfig == null)
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.GlobalConfig)))));
            }

            (bool valid, string?errorMessage) = request.GlobalConfig.CheckValidation();

            if (!valid)
            {
                return(BadRequest(new GenericResponse(false, errorMessage)));
            }

            request.GlobalConfig.ShouldSerializeDefaultValues    = false;
            request.GlobalConfig.ShouldSerializeHelperProperties = false;
            request.GlobalConfig.ShouldSerializeSensitiveDetails = true;

            if (!request.GlobalConfig.IsWebProxyPasswordSet && ASF.GlobalConfig.IsWebProxyPasswordSet)
            {
                request.GlobalConfig.WebProxyPassword = ASF.GlobalConfig.WebProxyPassword;
            }

            if ((ASF.GlobalConfig.AdditionalProperties != null) && (ASF.GlobalConfig.AdditionalProperties.Count > 0))
            {
                request.GlobalConfig.AdditionalProperties ??= new Dictionary <string, JToken>(ASF.GlobalConfig.AdditionalProperties.Count, ASF.GlobalConfig.AdditionalProperties.Comparer);

                foreach ((string key, JToken value) in ASF.GlobalConfig.AdditionalProperties.Where(property => !request.GlobalConfig.AdditionalProperties.ContainsKey(property.Key)))
                {
                    request.GlobalConfig.AdditionalProperties.Add(key, value);
                }

                request.GlobalConfig.AdditionalProperties.TrimExcess();
            }

            string filePath = ASF.GetFilePath(ASF.EFileType.Config);

            if (string.IsNullOrEmpty(filePath))
            {
                ASF.ArchiLogger.LogNullError(filePath);

                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(filePath)))));
            }

            bool result = await GlobalConfig.Write(filePath, request.GlobalConfig).ConfigureAwait(false);

            return(Ok(new GenericResponse(result)));
        }
Пример #4
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            Logging.InitFormLogger();

            BotListView.LargeImageList = BotListView.SmallImageList = AvatarImageList;

            await Task.Run(async() => {
                ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version);

                if (!Directory.Exists(SharedInfo.ConfigDirectory))
                {
                    ASF.ArchiLogger.LogGenericError("Config directory could not be found!");
                    Environment.Exit(1);
                }

                await ASF.CheckForUpdate().ConfigureAwait(false);

                // Before attempting to connect, initialize our list of CMs
                Bot.InitializeCMs(Program.GlobalDatabase.CellID, Program.GlobalDatabase.ServerListProvider);
            });

            foreach (string botName in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension))
            {
                switch (botName)
                {
                case SharedInfo.ASF:
                case "example":
                case "minimal":
                    continue;
                }

                Bot bot = new Bot(botName);

                BotStatusForm botStatusForm = new BotStatusForm(bot);

                BotIndexes[botName] = AvatarImageList.Images.Count;

                AvatarImageList.Images.Add(botName, botStatusForm.AvatarPictureBox.Image);

                botStatusForm.TopLevel = false;
                BotStatusPanel.Controls.Add(botStatusForm);

                ListViewItem botListViewItem = new ListViewItem {
                    ImageIndex = BotIndexes[botName],
                    Text       = botName
                };

                BotListView.Items.Add(botListViewItem);
            }

            if (BotListView.Items.Count > 0)
            {
                BotListView.Items[0].Selected = true;
                BotListView.Select();
            }
        }
Пример #5
0
        private static async Task <string> ResponseBooster(ulong steamID, string botNames, string targetGameIDs)
        {
            if ((steamID == 0) || string.IsNullOrEmpty(botNames) || string.IsNullOrEmpty(targetGameIDs))
            {
                ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNames) + " || " + nameof(targetGameIDs));

                return(null);
            }

            HashSet <Bot> bots = Bot.GetBots(botNames);

            if ((bots == null) || (bots.Count == 0))
            {
                return(ASF.IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)) : null);
            }

            IList <string> results = await Utilities.InParallel(bots.Select(bot => ResponseBooster(bot, steamID, targetGameIDs))).ConfigureAwait(false);

            List <string> responses = new List <string>(results.Where(result => !string.IsNullOrEmpty(result)));

            return(responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null);
        }
Пример #6
0
        public async Task <string?> ResponseRandomAvatar(ulong steamID, string botNames)
        {
            if ((steamID == 0) || string.IsNullOrEmpty(botNames))
            {
                ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNames));

                return(null);
            }

            HashSet <Bot>?bots = Bot.GetBots(botNames);

            if ((bots == null) || (bots.Count == 0))
            {
                return(ASF.IsOwner(steamID) ? Commands.FormatStaticResponse(string.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botNames)) : null);
            }

            IList <string?> results = await Utilities.InParallel(bots.Select(curbot => ResponseRandomAvatar(curbot, steamID))).ConfigureAwait(false);

            List <string?> responses = new List <string?>(results.Where(result => !string.IsNullOrEmpty(result)));

            return(responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null);
        }
Пример #7
0
        public async Task <ActionResult <GenericResponse> > BotPost(string botNames, [FromBody] BotRequest request)
        {
            if (string.IsNullOrEmpty(botNames))
            {
                throw new ArgumentNullException(nameof(botNames));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (Bot.Bots == null)
            {
                throw new InvalidOperationException(nameof(Bot.Bots));
            }

            if (request.BotConfig == null)
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.BotConfig)))));
            }

            (bool valid, string?errorMessage) = request.BotConfig.CheckValidation();

            if (!valid)
            {
                return(BadRequest(new GenericResponse(false, errorMessage)));
            }

            request.BotConfig.ShouldSerializeDefaultValues    = false;
            request.BotConfig.ShouldSerializeHelperProperties = false;
            request.BotConfig.ShouldSerializeSensitiveDetails = true;

            HashSet <string> bots = botNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet(Bot.BotsComparer);

            if (bots.Any(botName => !ASF.IsValidBotName(botName)))
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(botNames)))));
            }

            Dictionary <string, bool> result = new Dictionary <string, bool>(bots.Count, Bot.BotsComparer);

            foreach (string botName in bots)
            {
                if (Bot.Bots.TryGetValue(botName, out Bot? bot))
                {
                    if (!request.BotConfig.IsSteamLoginSet && bot.BotConfig.IsSteamLoginSet)
                    {
                        request.BotConfig.SteamLogin = bot.BotConfig.SteamLogin;
                    }

                    if (!request.BotConfig.IsSteamPasswordSet && bot.BotConfig.IsSteamPasswordSet)
                    {
                        request.BotConfig.DecryptedSteamPassword = bot.BotConfig.DecryptedSteamPassword;
                    }

                    if (!request.BotConfig.IsSteamParentalCodeSet && bot.BotConfig.IsSteamParentalCodeSet)
                    {
                        request.BotConfig.SteamParentalCode = bot.BotConfig.SteamParentalCode;
                    }

                    if (bot.BotConfig.AdditionalProperties?.Count > 0)
                    {
                        request.BotConfig.AdditionalProperties ??= new Dictionary <string, JToken>(bot.BotConfig.AdditionalProperties.Count, bot.BotConfig.AdditionalProperties.Comparer);

                        foreach ((string key, JToken value) in bot.BotConfig.AdditionalProperties.Where(property => !request.BotConfig.AdditionalProperties.ContainsKey(property.Key)))
                        {
                            request.BotConfig.AdditionalProperties.Add(key, value);
                        }

                        request.BotConfig.AdditionalProperties.TrimExcess();
                    }
                }

                string filePath = Bot.GetFilePath(botName, Bot.EFileType.Config);

                if (string.IsNullOrEmpty(filePath))
                {
                    ASF.ArchiLogger.LogNullError(filePath);

                    return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(filePath)))));
                }

                result[botName] = await BotConfig.Write(filePath, request.BotConfig).ConfigureAwait(false);
            }

            return(Ok(new GenericResponse <IReadOnlyDictionary <string, bool> >(result.Values.All(value => value), result)));
        }
Пример #8
0
 protected void DegreeType(string degree)
 {
     ASF.GetDegree(degree);
 }
Пример #9
0
 protected void DegreeType(string degree)
 {
     KYResidentInfo.DegreeType(degree);
     ASF.GetDegree(degree);
 }