internal async Task <string> checkTime(uint appid, uint itemdefid)
        {
            CInventory_ConsumePlaytime_Request reponse = new CInventory_ConsumePlaytime_Request {
                appid = appid, itemdefid = itemdefid
            };
            var steamUnifiedMessages = Client.GetHandler <SteamUnifiedMessages>();

            _inventoryService = steamUnifiedMessages.CreateService <IInventory>();

            var responce = await _inventoryService.SendMessage(x => x.ConsumePlaytime(reponse));

            var result = responce.GetDeserializedResponse <CInventory_Response>();

            if (result.item_json != "[]")
            {
                try
                {
                    Console.WriteLine(result.item_json);
                    var summstring = "";

                    foreach (var item in QuickType.ItemList.FromJson(result.item_json))
                    {
                        summstring += $"Item droped {Client.SteamID} while {item.Origin} game:{appid} => {item.Quantity}x {item.Itemdefid} @ {item.StateChangedTimestamp}\n";
                    }
                    return(summstring);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return($"No Item dropped for {Client.SteamID}");
        }
Exemple #2
0
        internal async Task <string> checkTime(uint appid, uint itemdefid, Bot bot)
        {
            CInventory_ConsumePlaytime_Request playtimeResponse = new CInventory_ConsumePlaytime_Request {
                appid = appid, itemdefid = itemdefid
            };
            CPlayer_GetOwnedGames_Request gamesOwnedRequest = new CPlayer_GetOwnedGames_Request {
                steamid = bot.SteamID, include_played_free_games = true
            };

            var steamUnifiedMessages = Client.GetHandler <SteamUnifiedMessages>();

            _inventoryService = steamUnifiedMessages.CreateService <IInventory>();
            _PlayerService    = steamUnifiedMessages.CreateService <IPlayer>();

            var consumePlaytimeResponse = await _inventoryService.SendMessage(x => x.ConsumePlaytime(playtimeResponse));

            var consumePlaytime = consumePlaytimeResponse.GetDeserializedResponse <CInventory_Response>();

            var ownedReponse = await _PlayerService.SendMessage(x => x.GetOwnedGames(gamesOwnedRequest));

            var resultGamesPlayed      = consumePlaytimeResponse.GetDeserializedResponse <CPlayer_GetOwnedGames_Response>();
            var resultFilteredGameById = resultGamesPlayed.games.Find(game => game.appid == appid);
            var appidPlaytimeForever   = 0;

            if (resultGamesPlayed != null && resultFilteredGameById != null)
            {
                appidPlaytimeForever = resultFilteredGameById.playtime_forever;
            }


            if (consumePlaytime.item_json != "[]")
            {
                try
                {
                    Console.WriteLine(consumePlaytime.item_json);
                    var summstring = "";

                    foreach (var item in QuickType.ItemList.FromJson(consumePlaytime.item_json))
                    {
                        summstring += $"Item drop @ {item.StateChangedTimestamp} => i.ID: {appid}_{item.Itemid}, i.Def: {item.Itemdefid} (playtime: {appidPlaytimeForever})";
                    }
                    return(summstring);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return($"No item drop for game {appid} with playtime {appidPlaytimeForever}.");
        }
Exemple #3
0
        internal async Task <string> checkTime(uint appid, uint itemdefid, Bot bot, bool longoutput)
        {
            var steamUnifiedMessages = Client.GetHandler <SteamUnifiedMessages>();

            if (steamUnifiedMessages == null)
            {
                bot.ArchiLogger.LogNullError(nameof(steamUnifiedMessages));
                return("SteamUnifiedMessages Error");
            }

            CInventory_ConsumePlaytime_Request playtimeRequest = new CInventory_ConsumePlaytime_Request {
                appid = appid, itemdefid = itemdefid
            };

            _inventoryService = steamUnifiedMessages.CreateService <IInventory>();
            var playtimeResponse = await _inventoryService.SendMessage(x => x.ConsumePlaytime(playtimeRequest));

            var resultGamesPlayed = playtimeResponse.GetDeserializedResponse <CInventory_Response>();


            if (resultGamesPlayed.item_json == null)
            {
                bot.ArchiLogger.LogGenericWarning(message: $"{resultGamesPlayed.item_json}");
            }
            if (resultGamesPlayed == null)
            {
                bot.ArchiLogger.LogNullError("resultGamesPlayed");
            }


            CPlayer_GetOwnedGames_Request gamesOwnedRequest = new CPlayer_GetOwnedGames_Request {
                steamid = bot.SteamID, include_appinfo = true, include_free_sub = true, include_played_free_games = true
            };

            _PlayerService = steamUnifiedMessages.CreateService <IPlayer>();
            var ownedReponse = await _PlayerService.SendMessage(x => x.GetOwnedGames(gamesOwnedRequest));

            var consumePlaytime = ownedReponse.GetDeserializedResponse <CPlayer_GetOwnedGames_Response>();

            consumePlaytime.games.ForEach(action => bot.ArchiLogger.LogGenericInfo(message: $"{action.appid} - {action.has_community_visible_stats} - {action.name} - {action.playtime_forever}"));
            var resultFilteredGameById = consumePlaytime.games.Find(game => game.appid == ((int)appid));

            if (consumePlaytime.games == null)
            {
                bot.ArchiLogger.LogNullError(nameof(consumePlaytime.games));
            }
            if (resultFilteredGameById == null)
            {
                bot.ArchiLogger.LogNullError("resultFilteredGameById ");
            }

            var appidPlaytimeForever = 0;

            if (resultGamesPlayed != null && resultFilteredGameById != null)
            {
                bot.ArchiLogger.LogGenericDebug(message: $"Playtime for {resultFilteredGameById.name} is: {resultFilteredGameById.playtime_forever}");
                appidPlaytimeForever = resultFilteredGameById.playtime_forever;
            }


            // proceed only when the player has played the request game id
            if (resultGamesPlayed != null && resultGamesPlayed.item_json != "[]")
            {
                try
                {
                    var summstring = "";

                    foreach (var item in QuickType.ItemList.FromJson(resultGamesPlayed.item_json))
                    {
                        if (longoutput)
                        {
                            summstring += $"Item drop @{item.StateChangedTimestamp} => i.ID: {appid}_{item.Itemid}, i.Def: {item.Itemdefid} (a.PT: {appidPlaytimeForever}m)";
                        }
                        else
                        {
                            summstring += $"Item drop @{item.StateChangedTimestamp}";
                        }

                        // item drop time taken from Steam, to be added to newline
                        string new_v0 = item.StateChangedTimestamp;

                        // Creating iDrop_Logfile if not exists and write a header
                        string iDrop_Logfile = "";
                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                        {
                            // setting filename for Linux OS
                            iDrop_Logfile = $"plugins/ASFItemDropper/droplogs/{bot.BotName}_{appid}.log";
                        }
                        else
                        {
                            // setting filename for Windows OS
                            iDrop_Logfile = $"plugins\\ASFItemDropper\\droplogs\\{bot.BotName}_{appid}.log";
                        }

                        if (!File.Exists(iDrop_Logfile))
                        {
                            using (StreamWriter sw = File.AppendText(iDrop_Logfile))
                            {
                                // writing header information and first dummy data
                                sw.WriteLine($"# Droplog for bot '{bot.BotName}' and AppID {appid} ({resultFilteredGameById.name})");
                                sw.WriteLine($"# Timestamp;TimeDiff;Playtime;PlaytimeDiff");
                                sw.WriteLine($"{new_v0};0.00:00:00;0;0");
                            }
                        }

                        string   newline    = "";
                        string   lastline   = File.ReadLines(iDrop_Logfile).Last();
                        string[] old_values = lastline.Split(';', StringSplitOptions.TrimEntries);

                        // date format of item drop time from Steam, needed for converting
                        string format = "yyyyMMdd'T'HHmmss'Z'";

                        // converting item drop times back to UTC for later calculation
                        DateTime new_v0utc = DateTime.ParseExact(new_v0, format, CultureInfo.InvariantCulture);
                        DateTime old_v0utc = DateTime.ParseExact(old_values[0], format, CultureInfo.InvariantCulture);

                        // calculating difference between last two item drops (newline - lastline)
                        TimeSpan duration = new_v0utc.Subtract(old_v0utc);
                        string   new_v1   = duration.ToString(@"d\.hh\:mm\:ss", CultureInfo.InvariantCulture);

                        // setting and converting appidPlaytimeForever of game for later calculation
                        uint new_v2 = Convert.ToUInt32(appidPlaytimeForever);

                        // calculating the playtime difference from newline to lastline
                        uint new_v3 = new_v2 - Convert.ToUInt32(old_values[2]);

                        // setup and append newline to droplogfile
                        newline = $"{new_v0};{new_v1};{new_v2};{new_v3}";

                        using (StreamWriter sw = File.AppendText(iDrop_Logfile))
                        {
                            sw.WriteLine($"{newline}");
                        }
                    }
                    return(summstring);
                }
                catch (Exception e)
                {
                    bot.ArchiLogger.LogGenericError(message: e.Message);
                    return("Error while parse consumePlaytime");
                }
            }
            else
            {
                if (longoutput)
                {
                    return($"No item drop for game '{resultFilteredGameById.name}' with playtime {appidPlaytimeForever}m.");
                }
                else
                {
                    return($"No item drop.");
                }
            }
        }