Timezone detection, Y2k36 handling, code refactoring. #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I implemented a function to fetch timezone information from an online geolocation service.
At first I wanted it to be generic, to work with a multitude of geolocation services, but I couldn't get libcurl to work under WUPS, it always crashed. So I wrote a bare-bones HTTP (no HTTPS) client, and looked for a free service that worked over plain HTTP, and found one: ip-api.com. Even better, it can produce results in plain text, one per line, so there's no need to parse JSON or XML content.
To use the feature, go to the "Configuration" screen, select the "Detect Timezone" option, and press "A". The geolocation service will look up the IP into a database, and report back what it thinks is the timezone name and its corresponding UTC offset. That UTC offset is then used to update the "Hours" and "Minutes" offsets.
This is not done automatically, because I didn't want to introduce privacy concerns (even though no identifiable information is transmitted, only a HTTP GET request with "User-Agent: Wii U Time Sync Plugin".)
Most users will ever need to use this feature twice per year, to adjust for DST changes. I did not attempt to use the timzeone database to automate DST changes, because it's more work than it's worth it; it's updated multiple times per year, it's obnoxious to parse, and any sort of automated downloading of that DB would require libcurl (and again, I could not get it to work inside WUPS.)
Also, I added code to handle the NTP wraparound, that will happen in 2036. Hopefully we get NTPv5 before then.
Most of the changes are code cleanup and refactoring. The core functionality (performing NTP queries) now lives in
core.cpp
/core.hpp
. The "Configuration" and "Preview" screens are setup in their own separate files. Configuration variables are in thecfg.cpp
/cfg.hpp
files. Helper functions and classes, that didn't seem worth moving to their own files, are all inutils.cpp
/utils.hpp
. Themain.cpp
file has been reduced to do only WUPS plugin stuffs. I think this makes the code overall easier to understand and modify.