diff --git a/ASFAchievementManager/ASFAchievementManager.cs b/ASFAchievementManager/ASFAchievementManager.cs index 07ef984..7742908 100644 --- a/ASFAchievementManager/ASFAchievementManager.cs +++ b/ASFAchievementManager/ASFAchievementManager.cs @@ -20,9 +20,6 @@ public sealed class ASFAchievementManager : IBotSteamClient, IBotCommand { public void OnLoaded() => ASF.ArchiLogger.LogGenericInfo("ASF Achievement Manager Plugin by Ryzhehvost, powered by ginger cats"); public async Task OnBotCommand([NotNull] Bot bot, ulong steamID, [NotNull] string message, string[] args) { - if (!bot.HasPermission(steamID, BotConfig.EPermission.Master)) { - return null; - } switch (args.Length) { case 0: @@ -38,17 +35,17 @@ public async Task OnBotCommand([NotNull] Bot bot, ulong steamID, [NotNul default: switch (args[0].ToUpperInvariant()) { case "ALIST" when args.Length > 2: - return await ResponseAchievementList(args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); + return await ResponseAchievementList(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "ALIST": - return await ResponseAchievementList(bot, args[1]).ConfigureAwait(false); + return await ResponseAchievementList(steamID ,bot, args[1]).ConfigureAwait(false); case "ASET" when args.Length > 3: - return await ResponseAchievementSet(args[1], args[2], Utilities.GetArgsAsText(args, 3, ","), true).ConfigureAwait(false); + return await ResponseAchievementSet(steamID, args[1], args[2], Utilities.GetArgsAsText(args, 3, ","), true).ConfigureAwait(false); case "ASET" when args.Length > 2: - return await ResponseAchievementSet(bot, args[1], Utilities.GetArgsAsText(args, 2, ","), true).ConfigureAwait(false); + return await ResponseAchievementSet(steamID, bot, args[1], Utilities.GetArgsAsText(args, 2, ","), true).ConfigureAwait(false); case "ARESET" when args.Length > 3: - return await ResponseAchievementSet(args[1], args[2], Utilities.GetArgsAsText(args, 3, ","), false).ConfigureAwait(false); + return await ResponseAchievementSet(steamID, args[1], args[2], Utilities.GetArgsAsText(args, 3, ","), false).ConfigureAwait(false); case "ARESET" when args.Length > 2: - return await ResponseAchievementSet(bot, args[1], Utilities.GetArgsAsText(args, 2, ","), false).ConfigureAwait(false); + return await ResponseAchievementSet(steamID, bot, args[1], Utilities.GetArgsAsText(args, 2, ","), false).ConfigureAwait(false); default: return null; } @@ -65,7 +62,12 @@ public IReadOnlyCollection OnBotSteamHandlersInit([NotNull] Bo //Responses - private static async Task ResponseAchievementList(Bot bot, string appids) { + private static async Task ResponseAchievementList(ulong steamID, Bot bot, string appids) { + + if (!bot.HasPermission(steamID, BotConfig.EPermission.Master)) { + return null; + } + string[] gameIDs = appids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (gameIDs.Length == 0) { @@ -97,7 +99,7 @@ private static async Task ResponseAchievementList(Bot bot, string appids } - private static async Task ResponseAchievementList(string botNames, string appids) { + private static async Task ResponseAchievementList(ulong steamID, string botNames, string appids) { HashSet bots = Bot.GetBots(botNames); @@ -105,7 +107,7 @@ private static async Task ResponseAchievementList(string botNames, strin return Commands.FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)); } - IList results = await Utilities.InParallel(bots.Select(bot => ResponseAchievementList(bot, appids))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => ResponseAchievementList(steamID, bot, appids))).ConfigureAwait(false); List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); @@ -113,7 +115,11 @@ private static async Task ResponseAchievementList(string botNames, strin } - private static async Task ResponseAchievementSet(Bot bot, string appid, string AchievementNumbers, bool set = true) { + private static async Task ResponseAchievementSet(ulong steamID, Bot bot, string appid, string AchievementNumbers, bool set = true) { + if (!bot.HasPermission(steamID, BotConfig.EPermission.Master)) { + return null; + } + if (string.IsNullOrEmpty(AchievementNumbers)) { return bot.Commands.FormatBotResponse(string.Format(Strings.ErrorObjectIsNull, nameof(AchievementNumbers))); } @@ -144,7 +150,7 @@ private static async Task ResponseAchievementSet(Bot bot, string appid, return bot.Commands.FormatBotResponse(await Task.Run(() => AchievementHandler.SetAchievements(bot, appId, achievements, set)).ConfigureAwait(false)); } - private static async Task ResponseAchievementSet(string botNames, string appid, string AchievementNumbers, bool set = true) { + private static async Task ResponseAchievementSet(ulong steamID, string botNames, string appid, string AchievementNumbers, bool set = true) { HashSet bots = Bot.GetBots(botNames); @@ -152,7 +158,7 @@ private static async Task ResponseAchievementSet(string botNames, string return Commands.FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)); } - IList results = await Utilities.InParallel(bots.Select(bot => ResponseAchievementSet(bot, appid, AchievementNumbers, set))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => ResponseAchievementSet(steamID, bot, appid, AchievementNumbers, set))).ConfigureAwait(false); List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); diff --git a/ASFAchievementManager/ASFAchievementManager.csproj b/ASFAchievementManager/ASFAchievementManager.csproj index 4c0919f..a3f25eb 100644 --- a/ASFAchievementManager/ASFAchievementManager.csproj +++ b/ASFAchievementManager/ASFAchievementManager.csproj @@ -2,7 +2,7 @@ Ryzhehvost - 0.1.1.0 + 0.1.2.0 netcoreapp3.1;net48 diff --git a/ASFAchievementManager/AchievementHandler.cs b/ASFAchievementManager/AchievementHandler.cs index 3b05d70..08c6206 100644 --- a/ASFAchievementManager/AchievementHandler.cs +++ b/ASFAchievementManager/AchievementHandler.cs @@ -38,10 +38,6 @@ private void HandleGetUserStatsResponse(IPacketMsg packetMsg) { return; } ClientMsgProtobuf response = new ClientMsgProtobuf(packetMsg); - //store data - if (!response.Body.game_idSpecified) { - ASF.ArchiLogger.LogNullError("response.Body.game_id"); - } if (!Responses.TryAdd(response.Body.game_id,new StoredResponse{ Success = response.Body.eresult == 1, Response = response.Body @@ -61,9 +57,6 @@ private void HandleStoreUserStatsResponse(IPacketMsg packetMsg) { return; } ClientMsgProtobuf response = new ClientMsgProtobuf(packetMsg); - if (!response.Body.game_idSpecified) { - ASF.ArchiLogger.LogNullError("response.Body.game_id"); - } if (!Responses.TryAdd(response.Body.game_id, new StoredResponse { Success = response.Body.eresult == 1, Response = null //we don't care about this, just need to know that request was successful @@ -82,7 +75,7 @@ private void HandleStoreUserStatsResponse(IPacketMsg packetMsg) { private List ParseResponse(CMsgClientGetUserStatsResponse Response) { List result = new List(); KeyValue KeyValues = new KeyValue(); - if (Response.schemaSpecified && Response.schema != null) { + if (Response.schema != null) { using (MemoryStream ms = new MemoryStream(Response.schema)) { if (!KeyValues.TryReadAsBinary(ms)) { ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(Response.schema)));