Skip to content

Commit

Permalink
Add config option for DST
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed Feb 7, 2020
1 parent 2974981 commit 503c079
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 49 deletions.
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
File renamed without changes.
2 changes: 2 additions & 0 deletions src/Configuration/DiscordServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class DiscordServerConfig
[JsonProperty("botChannelIds")]
public List<ulong> BotChannelIds { get; set; }

// TODO: Add DST option for each server.

public DiscordServerConfig()
{
//Locale = "en";
Expand Down
3 changes: 3 additions & 0 deletions src/Configuration/WhConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class WhConfig
[JsonProperty("iconStyles")]
public Dictionary<string, string> IconStyles { get; set; }

[JsonProperty("enableDST")]
public bool EnableDST { get; set; }

[JsonIgnore]
public string FileName { get; set; }

Expand Down
10 changes: 6 additions & 4 deletions src/Net/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,9 +71,10 @@ public class HttpServer

#region Constructor

public HttpServer(ushort port)
public HttpServer(ushort port, bool enableDST)
{
Port = port;
_enableDST = enableDST;

Initialize();
}
Expand Down Expand Up @@ -247,7 +249,7 @@ private void ParsePokemon(dynamic message)
return;
}

pokemon.SetDespawnTime();
pokemon.SetDespawnTime(_enableDST);

OnPokemonReceived(pokemon);
}
Expand Down Expand Up @@ -275,7 +277,7 @@ private void ParseRaid(dynamic message)
return;
}

raid.SetTimes();
raid.SetTimes(_enableDST);

OnRaidReceived(raid);
}
Expand Down Expand Up @@ -317,7 +319,7 @@ private void ParsePokestop(dynamic message)
return;
}

pokestop.SetTimes();
pokestop.SetTimes(_enableDST);

OnPokestopReceived(pokestop);
}
Expand Down
36 changes: 18 additions & 18 deletions src/Net/Models/PokemonData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public List<PvPCP> PossibleUltraLeagueCPs

public PokemonData()
{
SetDespawnTime();
SetDespawnTime(false);
//_top100GreatLeagueRanks = _pvpCalc.CalculateTopRanks(Id, FormId, 1500, TopPvPRanks).GetAwaiter().GetResult();
//_top100UltraLeagueRanks = _pvpCalc.CalculateTopRanks(Id, FormId, 2500, TopPvPRanks).GetAwaiter().GetResult();
}
Expand All @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions src/Net/Models/PokestopData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Net/Models/QuestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions src/Net/Models/RaidData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ public List<PokemonType> 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)
Expand Down
4 changes: 1 addition & 3 deletions src/Net/Webhooks/WebhookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -227,8 +227,6 @@ private void Http_QuestReceived(object sender, DataReceivedEventArgs<QuestData>
private void Http_PokestopReceived(object sender, DataReceivedEventArgs<PokestopData> e)
{
var pokestop = e.Data;
pokestop.SetTimes();

if (pokestop.HasLure || pokestop.HasInvasion)
{
ProcessPokestop(pokestop);
Expand Down
2 changes: 1 addition & 1 deletion src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit 503c079

Please sign in to comment.