Exemple #1
0
        /// <summary>
        /// Return an agent that is stored in the database.
        /// </summary>
        /// <param name="steamID">SteamID64.</param>
        /// <returns>An awaitable Task.</returns>
        public async Task <AgentsDB> GetDBAgentAsync(ulong steamID)
        {
            AgentsDB agent = new AgentsDB();

            using IServiceScope scope = this.scopeFactory.CreateScope();
            using IntruderContext db  = scope.ServiceProvider.GetRequiredService <IntruderContext>();

            if (this.CheckDBAgent(steamID))
            {
                agent = db.Agents.Where(x => x.SteamID == steamID).FirstOrDefault();
            }
            else
            {
                await this.StoreAgentDBAsync(steamID);
            }

            return(agent);
        }
Exemple #2
0
        /// <summary>
        /// Stores a new Agent DB into the database. Will update if there is an existing entry, but there shouldn't be.
        /// </summary>
        /// <param name="steamID">SteamID64.</param>
        /// <returns>An awaitable task.</returns>
        public async Task StoreAgentDBAsync(ulong steamID)
        {
            // get profile
            Agent profileResponse = await this.GetAgentProfileAsync(steamID);

            // get stats
            AgentStats statsResponse = await this.GetAgentStatsAsync(steamID);

            // get votes
            List <AgentVotes> votesResponse = await this.QueryAgentVotes(steamID);

            // add to db
            AgentsDB agentsDB = new AgentsDB()
            {
                // BEGIN PROFILE INFO
                SteamID     = profileResponse.SteamID,
                SteamAvatar = profileResponse.AvatarURL,
                ID          = profileResponse.IntruderID,
                Role        = profileResponse.Role,
                Name        = profileResponse.Name,
                LoginCount  = profileResponse.LoginCount,
                FirstLogin  = profileResponse.FirstLogin,
                LastLogin   = profileResponse.LastLogin,
                LastUpdate  = profileResponse.LastUpdate,

                // BEGIN STATS INFO
                MatchesWon       = statsResponse.MatchesWon,
                MatchesLost      = statsResponse.MatchesLost,
                RoundsLost       = statsResponse.RoundsLost,
                RoundsTied       = statsResponse.RoundsTied,
                RoundsWonElim    = statsResponse.RoundsWonElim,
                RoundsWonCapture = statsResponse.RoundsWonCapture,
                RoundsWonHack    = statsResponse.RoundsWonHack,
                RoundsWonTimer   = statsResponse.RoundsWonTimer,
                RoundsWonCustom  = statsResponse.RoundsWonCustom,
                TimePlayed       = statsResponse.TimePlayed,
                Kills            = statsResponse.Kills,
                TeamKills        = statsResponse.TeamKills,
                Deaths           = statsResponse.Deaths,
                Arrests          = statsResponse.Arrests,
                GotArrested      = statsResponse.GotArrested,
                Captures         = statsResponse.Captures,
                Pickups          = statsResponse.Pickups,
                NetworkHacks     = statsResponse.NetworkHacks,
                Survivals        = statsResponse.Survivals,
                Suicides         = statsResponse.Suicides,
                Knockdowns       = statsResponse.Knockdowns,
                GotKnockedDown   = statsResponse.GotKnockedDown,
                TeamKnockdowns   = statsResponse.TeamKnockdowns,
                TeamDamage       = statsResponse.TeamDamage,
                Level            = statsResponse.Level,
                LevelXP          = statsResponse.LevelXP,
                LevelXPRequired  = statsResponse.LevelXPRequired,
                TotalXP          = statsResponse.TotalXP,

                // BEGIN VOTES
                PositiveVotes = votesResponse.ElementAt(0).PositiveVotes,
                NegativeVotes = votesResponse.ElementAt(0).NegativeVotes,
                TotalVotes    = votesResponse.ElementAt(0).ReceivedVotes,
                Timestamp     = DateTime.Now,
            };

            using IServiceScope scope = this.scopeFactory.CreateScope();
            using IntruderContext db  = scope.ServiceProvider.GetRequiredService <IntruderContext>();

            try
            {
                db.Agents.Add(agentsDB);
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                db.Agents.Update(agentsDB);
                await db.SaveChangesAsync();
            }

            await Task.CompletedTask;
        }
Exemple #3
0
        public async Task UpdateDBAgentAsync(Agent agent)
        {
            using IServiceScope scope = this.scopeFactory.CreateScope();
            using IntruderContext db  = scope.ServiceProvider.GetRequiredService <IntruderContext>();

            AgentsDB dbAgent = await this.GetDBAgentAsync(agent.SteamID);

            if (this.CheckDBAgent(agent.SteamID))
            {
                if (DateTime.Compare(agent.LastLogin, dbAgent.LastLogin) == 1)
                {
                    // Agent has updated stats. lets update our DB.

                    // get stats
                    AgentStats statsResponse = await this.GetAgentStatsAsync(agent.SteamID);

                    // get votes
                    List <AgentVotes> votesResponse = await this.QueryAgentVotes(agent.SteamID);

                    if (dbAgent.Name != agent.Name)
                    {
                        dbAgent.OldAgentName = dbAgent.Name;
                    }

                    // BEGIN PROFILE INFO
                    dbAgent.SteamAvatar = agent.AvatarURL;
                    dbAgent.Role        = agent.Role;
                    dbAgent.Name        = agent.Name;
                    dbAgent.LoginCount  = agent.LoginCount;
                    dbAgent.LastLogin   = agent.LastLogin;
                    dbAgent.LastUpdate  = agent.LastUpdate;

                    // BEGIN STATS INFO
                    dbAgent.MatchesWon       = statsResponse.MatchesWon;
                    dbAgent.MatchesLost      = statsResponse.MatchesLost;
                    dbAgent.RoundsLost       = statsResponse.RoundsLost;
                    dbAgent.RoundsTied       = statsResponse.RoundsTied;
                    dbAgent.RoundsWonElim    = statsResponse.RoundsWonElim;
                    dbAgent.RoundsWonCapture = statsResponse.RoundsWonCapture;
                    dbAgent.RoundsWonHack    = statsResponse.RoundsWonHack;
                    dbAgent.RoundsWonTimer   = statsResponse.RoundsWonTimer;
                    dbAgent.RoundsWonCustom  = statsResponse.RoundsWonCustom;
                    dbAgent.TimePlayed       = statsResponse.TimePlayed;
                    dbAgent.Kills            = statsResponse.Kills;
                    dbAgent.TeamKills        = statsResponse.TeamKills;
                    dbAgent.Deaths           = statsResponse.Deaths;
                    dbAgent.Arrests          = statsResponse.Arrests;
                    dbAgent.GotArrested      = statsResponse.GotArrested;
                    dbAgent.Captures         = statsResponse.Captures;
                    dbAgent.Pickups          = statsResponse.Pickups;
                    dbAgent.NetworkHacks     = statsResponse.NetworkHacks;
                    dbAgent.Survivals        = statsResponse.Survivals;
                    dbAgent.Suicides         = statsResponse.Suicides;
                    dbAgent.Knockdowns       = statsResponse.Knockdowns;
                    dbAgent.GotKnockedDown   = statsResponse.GotKnockedDown;
                    dbAgent.TeamKnockdowns   = statsResponse.TeamKnockdowns;
                    dbAgent.TeamDamage       = statsResponse.TeamDamage;
                    dbAgent.Level            = statsResponse.Level;
                    dbAgent.LevelXP          = statsResponse.LevelXP;
                    dbAgent.LevelXPRequired  = statsResponse.LevelXPRequired;
                    dbAgent.TotalXP          = statsResponse.TotalXP;

                    // BEGIN VOTES
                    dbAgent.PositiveVotes = votesResponse.ElementAt(0).PositiveVotes;
                    dbAgent.NegativeVotes = votesResponse.ElementAt(0).NegativeVotes;
                    dbAgent.TotalVotes    = votesResponse.ElementAt(0).ReceivedVotes;
                    dbAgent.Timestamp     = DateTime.Now;

                    db.Agents.Update(dbAgent);
                }
                else if (DateTime.Compare(agent.LastLogin, dbAgent.LastLogin) == 0)
                {
                    // Same date, do nothing.
                }
            }
            else
            {
                await this.StoreAgentDBAsync(agent.SteamID);
            }

            await db.SaveChangesAsync();
        }
Exemple #4
0
        /// <summary>
        /// Collects and stores the agent_history from all Package Account Users.
        /// </summary>
        /// <returns>Jack shit.</returns>
        public async Task PopulateAgentTableAsync()
        {
            // Convert SteamIDs from PackageAccounts to Agents using DB.
            List <Agent> agents = await this.GetAllAgents(null, null, null, 101, 100);

            using IServiceScope scope = this.scopeFactory.CreateScope();
            using IntruderContext db  = scope.ServiceProvider.GetRequiredService <IntruderContext>();

            foreach (Agent dbAgent in agents)
            {
                if (db.Agents.Where(x => x.SteamID == dbAgent.SteamID).AsNoTracking().FirstOrDefault() == null || db.Agents.Any(x => x.SteamID != dbAgent.SteamID) || db.Agents.Any(x => x.ID != dbAgent.IntruderID))
                {
                    // Collect Agent Stats
                    AgentStats statsResponse = await this.GetAgentStatsAsync(dbAgent.SteamID);

                    // Collect Agent Votes
                    List <AgentVotes> votesResponse = await this.QueryAgentVotes(dbAgent.SteamID);

                    AgentsDB agentsDB = new AgentsDB
                    {
                        // BEGIN PROFILE INFO
                        SteamID     = dbAgent.SteamID,
                        SteamAvatar = dbAgent.AvatarURL,
                        ID          = dbAgent.IntruderID,
                        Role        = dbAgent.Role,
                        Name        = dbAgent.Name,
                        LoginCount  = dbAgent.LoginCount,
                        FirstLogin  = dbAgent.FirstLogin,
                        LastLogin   = dbAgent.LastLogin,
                        LastUpdate  = dbAgent.LastUpdate,

                        // BEGIN STATS INFO
                        MatchesWon       = statsResponse.MatchesWon,
                        MatchesLost      = statsResponse.MatchesLost,
                        RoundsLost       = statsResponse.RoundsLost,
                        RoundsTied       = statsResponse.RoundsTied,
                        RoundsWonElim    = statsResponse.RoundsWonElim,
                        RoundsWonCapture = statsResponse.RoundsWonCapture,
                        RoundsWonHack    = statsResponse.RoundsWonHack,
                        RoundsWonTimer   = statsResponse.RoundsWonTimer,
                        RoundsWonCustom  = statsResponse.RoundsWonCustom,
                        TimePlayed       = statsResponse.TimePlayed,
                        Kills            = statsResponse.Kills,
                        TeamKills        = statsResponse.TeamKills,
                        Deaths           = statsResponse.Deaths,
                        Arrests          = statsResponse.Arrests,
                        GotArrested      = statsResponse.GotArrested,
                        Captures         = statsResponse.Captures,
                        Pickups          = statsResponse.Pickups,
                        NetworkHacks     = statsResponse.NetworkHacks,
                        Survivals        = statsResponse.Survivals,
                        Suicides         = statsResponse.Suicides,
                        Knockdowns       = statsResponse.Knockdowns,
                        GotKnockedDown   = statsResponse.GotKnockedDown,
                        TeamKnockdowns   = statsResponse.TeamKnockdowns,
                        TeamDamage       = statsResponse.TeamDamage,
                        Level            = statsResponse.Level,
                        LevelXP          = statsResponse.LevelXP,
                        LevelXPRequired  = statsResponse.LevelXPRequired,
                        TotalXP          = statsResponse.TotalXP,

                        // BEGIN VOTES
                        PositiveVotes = votesResponse.ElementAt(0).PositiveVotes,
                        NegativeVotes = votesResponse.ElementAt(0).NegativeVotes,
                        TotalVotes    = votesResponse.ElementAt(0).ReceivedVotes,
                        Timestamp     = DateTime.Now,
                    };
                    try
                    {
                        db.Agents.Add(agentsDB);
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateException)
                    {
                        db.Agents.Update(agentsDB);
                        await db.SaveChangesAsync();
                    }
                }
                else
                {
                    Console.WriteLine($"{dbAgent.Name} IS ALREADY STORED. INTRUDER ID: {dbAgent.IntruderID}");
                }
            }
        }