Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone detection, Y2k36 handling, code refactoring. #18

Merged
merged 9 commits into from
Oct 20, 2023

Conversation

dkosmari
Copy link
Collaborator

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 the cfg.cpp/cfg.hpp files. Helper functions and classes, that didn't seem worth moving to their own files, are all in utils.cpp/utils.hpp. The main.cpp file has been reduced to do only WUPS plugin stuffs. I think this makes the code overall easier to understand and modify.

Daniel K. O. (dkosmari) added 9 commits October 6, 2023 22:38
--HG--
branch : upstream
--HG--
branch : upstream
--HG--
branch : upstream
--HG--
branch : upstream
--HG--
branch : upstream
--HG--
branch : upstream
--HG--
branch : upstream
--HG--
branch : upstream
@Nightkingale Nightkingale merged commit 3d5dd85 into Nightkingale:master Oct 20, 2023
1 check passed
@Nightkingale
Copy link
Owner

Looks and works good on my end, no issues! As usual, thank you for these changes, they really make the plugin a whole lot better. I appreciate the timezone fetching for example, I think that's a super cool idea and executed well (thank you for making it optional!)

I'm probably going to make a new release when I'm free this weekend, and both of your recent pull requests will be apart of that.

@Nightkingale Nightkingale mentioned this pull request Oct 22, 2023
@Nightkingale Nightkingale added the enhancement New feature or request label Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants