From 503c07963ab0f67a1535b65e4865cae80c4d720a Mon Sep 17 00:00:00 2001 From: versx Date: Thu, 6 Feb 2020 17:12:12 -0800 Subject: [PATCH] Add config option for DST --- config.example.json | 3 +- tables.sql => schema.sql | 0 src/Configuration/DiscordServerConfig.cs | 2 ++ src/Configuration/WhConfig.cs | 3 ++ src/Net/HttpServer.cs | 10 ++++--- src/Net/Models/PokemonData.cs | 36 ++++++++++++------------ src/Net/Models/PokestopData.cs | 20 ++++++------- src/Net/Models/QuestData.cs | 4 +-- src/Net/Models/RaidData.cs | 20 ++++++------- src/Net/Webhooks/WebhookController.cs | 4 +-- src/Properties/AssemblyInfo.cs | 2 +- 11 files changed, 55 insertions(+), 49 deletions(-) rename tables.sql => schema.sql (100%) diff --git a/config.example.json b/config.example.json index 06b0af8f..8b0d1391 100644 --- a/config.example.json +++ b/config.example.json @@ -112,5 +112,6 @@ "iconStyles": { "Default": "https://cdn.example.com/images/original/monsters/{0:D3}_{1:D3}.png", "Shuffle": "https://cdn.example.com/images/shuffle/monsters/{0:D3}_{1:D3}.png" - } + }, + "enableDST": false } \ No newline at end of file diff --git a/tables.sql b/schema.sql similarity index 100% rename from tables.sql rename to schema.sql diff --git a/src/Configuration/DiscordServerConfig.cs b/src/Configuration/DiscordServerConfig.cs index aa3821bf..9cd6e923 100644 --- a/src/Configuration/DiscordServerConfig.cs +++ b/src/Configuration/DiscordServerConfig.cs @@ -63,6 +63,8 @@ public class DiscordServerConfig [JsonProperty("botChannelIds")] public List BotChannelIds { get; set; } + // TODO: Add DST option for each server. + public DiscordServerConfig() { //Locale = "en"; diff --git a/src/Configuration/WhConfig.cs b/src/Configuration/WhConfig.cs index 3196b1f9..f420b5a4 100644 --- a/src/Configuration/WhConfig.cs +++ b/src/Configuration/WhConfig.cs @@ -40,6 +40,9 @@ public class WhConfig [JsonProperty("iconStyles")] public Dictionary IconStyles { get; set; } + [JsonProperty("enableDST")] + public bool EnableDST { get; set; } + [JsonIgnore] public string FileName { get; set; } diff --git a/src/Net/HttpServer.cs b/src/Net/HttpServer.cs index 798833af..0d127316 100644 --- a/src/Net/HttpServer.cs +++ b/src/Net/HttpServer.cs @@ -21,6 +21,7 @@ public class HttpServer private static readonly IEventLogger _logger = EventLogger.GetLogger("HTTP"); private static readonly object _lock = new object(); + private readonly bool _enableDST = false; private HttpListener _server; //private Thread _requestThread; @@ -70,9 +71,10 @@ public class HttpServer #region Constructor - public HttpServer(ushort port) + public HttpServer(ushort port, bool enableDST) { Port = port; + _enableDST = enableDST; Initialize(); } @@ -247,7 +249,7 @@ private void ParsePokemon(dynamic message) return; } - pokemon.SetDespawnTime(); + pokemon.SetDespawnTime(_enableDST); OnPokemonReceived(pokemon); } @@ -275,7 +277,7 @@ private void ParseRaid(dynamic message) return; } - raid.SetTimes(); + raid.SetTimes(_enableDST); OnRaidReceived(raid); } @@ -317,7 +319,7 @@ private void ParsePokestop(dynamic message) return; } - pokestop.SetTimes(); + pokestop.SetTimes(_enableDST); OnPokestopReceived(pokestop); } diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index adc3a457..fa682ac2 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -555,7 +555,7 @@ public List PossibleUltraLeagueCPs public PokemonData() { - SetDespawnTime(); + SetDespawnTime(false); //_top100GreatLeagueRanks = _pvpCalc.CalculateTopRanks(Id, FormId, 1500, TopPvPRanks).GetAwaiter().GetResult(); //_top100UltraLeagueRanks = _pvpCalc.CalculateTopRanks(Id, FormId, 2500, TopPvPRanks).GetAwaiter().GetResult(); } @@ -564,34 +564,34 @@ public PokemonData() #region Public Methods - public void SetDespawnTime() + public void SetDespawnTime(bool enableDST) { //TODO: DST config option DespawnTime = DisappearTime.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(DespawnTime)) - //{ - // DespawnTime = DespawnTime.AddHours(1); //DST - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(DespawnTime)) + { + DespawnTime = DespawnTime.AddHours(1); //DST + } SecondsLeft = DespawnTime.Subtract(DateTime.Now); FirstSeenTime = FirstSeen.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(FirstSeenTime)) - //{ - // FirstSeenTime = FirstSeenTime.AddHours(1); //DST - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(FirstSeenTime)) + { + FirstSeenTime = FirstSeenTime.AddHours(1); //DST + } LastModifiedTime = LastModified.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(LastModifiedTime)) - //{ - // LastModifiedTime = LastModifiedTime.AddHours(1); - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(LastModifiedTime)) + { + LastModifiedTime = LastModifiedTime.AddHours(1); + } UpdatedTime = Updated.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(Updated)) - //{ - // UpdatedTime = UpdatedTime.AddHours(1); - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(UpdatedTime)) + { + UpdatedTime = UpdatedTime.AddHours(1); + } } //public bool IsUnderLevel(int targetLevel) diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index ddc94a7a..515d1ba3 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -76,24 +76,24 @@ public sealed class PokestopData public PokestopData() { - SetTimes(); + SetTimes(false); } #region Public Methods - public void SetTimes() + public void SetTimes(bool enableDST) { LureExpireTime = LureExpire.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(LureExpireTime)) - //{ - //LureExpireTime = LureExpireTime.AddHours(1); //DST - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(LureExpireTime)) + { + LureExpireTime = LureExpireTime.AddHours(1); //DST + } InvasionExpireTime = IncidentExpire.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(InvasionExpireTime)) - //{ - //InvasionExpireTime = InvasionExpireTime.AddHours(1); //DST - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(InvasionExpireTime)) + { + InvasionExpireTime = InvasionExpireTime.AddHours(1); //DST + } } public static string InvasionTypeToString(InvasionGruntType gruntType) diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index 9948f515..31d90521 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -463,8 +463,8 @@ public enum ItemId Wepar_Berry = 704, Pinap_Berry = 705, Golden_Razz_Berry = 706, - Golden_Nanab_Berry = 707, - Golden_Pinap_Berry = 708, + Silver_Nanab_Berry = 707, + Silver_Pinap_Berry = 708, Special_Camera = 801, Incubator_Basic_Unlimited = 901, Incubator_Basic = 902, diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index 6720b091..2aede942 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -103,22 +103,22 @@ public List Weaknesses public RaidData() { - SetTimes(); + SetTimes(false); } - public void SetTimes() + public void SetTimes(bool enableDST) { StartTime = Start.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(StartTime)) - //{ - // StartTime = StartTime.AddHours(1); //DST - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(StartTime)) + { + StartTime = StartTime.AddHours(1); //DST + } EndTime = End.FromUnix(); - //if (TimeZoneInfo.Local.IsDaylightSavingTime(EndTime)) - //{ - // EndTime = EndTime.AddHours(1); //DST - //} + if (enableDST)//TimeZoneInfo.Local.IsDaylightSavingTime(EndTime)) + { + EndTime = EndTime.AddHours(1); //DST + } } public DiscordEmbed GenerateRaidMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city, string raidImageUrl) diff --git a/src/Net/Webhooks/WebhookController.cs b/src/Net/Webhooks/WebhookController.cs index bc1089bd..1fff5f8f 100644 --- a/src/Net/Webhooks/WebhookController.cs +++ b/src/Net/Webhooks/WebhookController.cs @@ -150,7 +150,7 @@ public WebhookController(WhConfig config) } _config = config; - _http = new HttpServer(_config.WebhookPort); + _http = new HttpServer(_config.WebhookPort, _config.EnableDST); _http.PokemonReceived += Http_PokemonReceived; _http.RaidReceived += Http_RaidReceived; _http.QuestReceived += Http_QuestReceived; @@ -227,8 +227,6 @@ private void Http_QuestReceived(object sender, DataReceivedEventArgs private void Http_PokestopReceived(object sender, DataReceivedEventArgs e) { var pokestop = e.Data; - pokestop.SetTimes(); - if (pokestop.HasLure || pokestop.HasInvasion) { ProcessPokestop(pokestop); diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 27e066fb..8295e24a 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.5.*")] +[assembly: AssemblyVersion("3.0.7.*")] //[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file