public void AddLogEntry(MySQLContext context, int SessionId, LogEntry log)
        {
            log.SessionId = SessionId;

            //Update session stats
            context.Database.ExecuteSqlRaw($"UPDATE `Session` SET TotalGainedXp=TotalGainedXp+\"{log.XpReward}\", TotalGainedStardust=TotalGainedStardust+{log.StardustReward}, " +
                                           $"CaughtPokemon=CaughtPokemon+{((log.LogEntryType == LogEntryType.Pokemon && log.CaughtSuccess) ? 1 : 0)}, EscapedPokemon=EscapedPokemon+{((log.LogEntryType == LogEntryType.Pokemon && !log.CaughtSuccess) ? 1 : 0)}, " +
                                           $"ShinyPokemon=ShinyPokemon+{((log.Shiny) ? 1 : 0)}, Shadow=Shadow+{((log.Shadow) ? 1 : 0)}, Pokestops=Pokestops+{(log.LogEntryType == LogEntryType.Fort ? 1 : 0)}, " +
                                           $"Rockets=Rockets+{(log.LogEntryType == LogEntryType.Rocket ? 1 : 0)}, Raids=Raids+{(log.LogEntryType == LogEntryType.Raid ? 1 : 0)}, " +
                                           $"LastUpdate=UTC_TIMESTAMP(), EndTime=UTC_TIMESTAMP(), TotalMinutes=TIMESTAMPDIFF(MINUTE, StartTime, UTC_TIMESTAMP()) WHERE Id={SessionId} ORDER BY Id");
            context.Logs.Add(log);
        }
        internal void AddRaidToDatabase(int dbSessionId, int xp, int stardust)
        {
            using (var context = new MySQLContext()) {
                LogEntry raidLogEntry = new LogEntry {
                    LogEntryType = LogEntryType.Raid, timestamp = DateTime.UtcNow
                };

                raidLogEntry.XpReward       = xp;
                raidLogEntry.StardustReward = stardust;
                this.AddLogEntry(context, dbSessionId, raidLogEntry);
                context.SaveChanges();
            }
        }
        public void AddSpinnedFortToDatabase(int dbSessionId, FortSearchOutProto fortSearchProto)
        {
            using (var context = new MySQLContext()) {
                LogEntry fortLogEntry = new LogEntry {
                    LogEntryType = LogEntryType.Fort, timestamp = DateTime.UtcNow
                };

                fortLogEntry.XpReward = fortSearchProto.XpAwarded;

                this.AddLogEntry(context, dbSessionId, fortLogEntry);
                context.SaveChanges();
            }
        }
Esempio n. 4
0
        private void EncounterConsumer()
        {
            while (true)
            {
                List <EncounterOutProto> encounterList = new List <EncounterOutProto>();

                if (ConfigurationManager.Shared.Config.MySql.Enabled && ConfigurationManager.Shared.Config.Encounter.SaveToDatabase)
                {
                    using (var context = new MySQLContext())
                    {
                        while (blockingEncounterQueue.Count > 0)
                        {
                            EncounterOutProto encounter = blockingEncounterQueue.Take();
                            if (alreadySendEncounters.ContainsKey(encounter.Pokemon.EncounterId))
                            {
                                continue;
                            }
                            lock (lockObj)
                            {
                                alreadySendEncounters.Add(encounter.Pokemon.EncounterId, DateTime.Now);
                            }
                            encounterList.Add(encounter);
                            connectionManager.AddEncounterToDatabase(encounter, context);
                        }
                        context.SaveChanges();
                    }
                }
                else
                {
                    while (blockingEncounterQueue.Count > 0)
                    {
                        EncounterOutProto encounter = blockingEncounterQueue.Take();
                        if (alreadySendEncounters.ContainsKey(encounter.Pokemon.EncounterId))
                        {
                            continue;
                        }
                        lock (lockObj)
                        {
                            alreadySendEncounters.Add(encounter.Pokemon.EncounterId, DateTime.Now);
                        }
                        encounterList.Add(encounter);
                    }
                }
                if (encounterList.Count > 0)
                {
                    ConfigurationManager.Shared.Config.Encounter.DiscordWebhooks.ForEach(hook => SendDiscordWebhooks(hook, encounterList));
                    Thread.Sleep(3000);
                }
                Thread.Sleep(1000);
            }
        }
        public void AddFeedBerryToDatabase(int dbSessionId, GymFeedPokemonOutProto gymFeedPokemonProto)
        {
            using (var context = new MySQLContext()) {
                LogEntry feedBerryLogEntry = new LogEntry {
                    LogEntryType = LogEntryType.FeedBerry, timestamp = DateTime.UtcNow
                };

                feedBerryLogEntry.XpReward       = gymFeedPokemonProto.XpAwarded;
                feedBerryLogEntry.StardustReward = gymFeedPokemonProto.StardustAwarded;
                feedBerryLogEntry.CandyAwarded   = gymFeedPokemonProto.NumCandyAwarded;

                this.AddLogEntry(context, dbSessionId, feedBerryLogEntry);
                context.SaveChanges();
            }
        }
        internal void UpdateLevelAndExp(int accountId, PlayerStatsProto playerStats)
        {
            if (playerStats == null)
            {
                return;
            }

            using (var context = new MySQLContext())
            {
                try
                {
                    context.Database.ExecuteSqlRaw($"UPDATE `Account` SET Level={playerStats.Level},Experience={(int)playerStats.Experience},NextLevelExp={playerStats.NextLevelExp} WHERE Id={accountId} ORDER BY Id");
                }
                catch (Exception e)
                {
                    Log.Information(e.Message);
                    Log.Information(e.InnerException.Message);
                }
            }
        }
        public void AddEncounterToDatabase(EncounterOutProto encounterProto, MySQLContext context)
        {
            if (context.Encounters.Where(e => e.EncounterId == encounterProto.Pokemon.EncounterId).FirstOrDefault() != null)
            {
                return;
            }

            Encounter encounter = new Encounter();

            encounter.EncounterId = encounterProto.Pokemon.EncounterId;
            encounter.PokemonName = encounterProto.Pokemon.Pokemon.PokemonId;
            encounter.Form        = encounterProto.Pokemon.Pokemon.PokemonDisplay.Form;
            encounter.Stamina     = encounterProto.Pokemon.Pokemon.IndividualStamina;
            encounter.Attack      = encounterProto.Pokemon.Pokemon.IndividualAttack;
            encounter.Defense     = encounterProto.Pokemon.Pokemon.IndividualDefense;
            encounter.Latitude    = encounterProto.Pokemon.Latitude;
            encounter.Longitude   = encounterProto.Pokemon.Longitude;
            encounter.timestamp   = DateTime.UtcNow;

            context.Encounters.Add(encounter);
        }
 public Session GetSession(MySQLContext context, int id)
 {
     return(context.Sessions.Where(s => s.Id == id).FirstOrDefault <Session>());
 }