From 29832e3eccceb10b5e6a9b9de554e0a45f4f1fc9 Mon Sep 17 00:00:00 2001 From: Aotrix Date: Thu, 27 Mar 2025 12:58:24 +0100 Subject: switched to std::chrono::seconds for tokens --- include/hearthstoneAPIHandler.h | 2 +- resources/token_info.txt | 2 +- src/hearthstoneAPIHandler.cpp | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/hearthstoneAPIHandler.h b/include/hearthstoneAPIHandler.h index 2e0c933..9d5ec58 100644 --- a/include/hearthstoneAPIHandler.h +++ b/include/hearthstoneAPIHandler.h @@ -10,7 +10,7 @@ class HearthstoneAPIHandler { private: static size_t curl_callback_string_output(void *t_contents, size_t t_size, size_t t_nmemb, std::string *t_s); - std::chrono::hours get_current_time(); + std::chrono::seconds get_current_time(); std::string extract_string_with_regex(const std::string &t_str, const std::string t_regex); void write_new_token_info_to_file(const std::string &t_file_path); diff --git a/resources/token_info.txt b/resources/token_info.txt index 2e63a0c..e18f2ba 100644 --- a/resources/token_info.txt +++ b/resources/token_info.txt @@ -1 +1 @@ -EUFbkUjCXKrSY8z1dUDjS9oHKSrho6LDHT 484196 \ No newline at end of file +EUFbkUjCXKrSY8z1dUDjS9oHKSrho6LDHT 1743163065 \ No newline at end of file diff --git a/src/hearthstoneAPIHandler.cpp b/src/hearthstoneAPIHandler.cpp index 7db7b04..ff8aa9b 100644 --- a/src/hearthstoneAPIHandler.cpp +++ b/src/hearthstoneAPIHandler.cpp @@ -23,8 +23,8 @@ size_t HearthstoneAPIHandler::curl_callback_string_output(void *t_contents, return newLength; } -std::chrono::hours HearthstoneAPIHandler::get_current_time() { - return std::chrono::duration_cast( +std::chrono::seconds HearthstoneAPIHandler::get_current_time() { + return std::chrono::duration_cast( std::chrono::utc_clock::now().time_since_epoch()); } @@ -64,7 +64,8 @@ void HearthstoneAPIHandler::write_new_token_info_to_file( } std::string token = extract_string_with_regex(token_info, "\"access_token\":\"(\\w+)\""); - std::chrono::hours expires_at = get_current_time() + std::chrono::hours(24); + std::chrono::seconds expires_at = + get_current_time() + std::chrono::hours(24); token_file << token << " " << expires_at.count(); } @@ -78,7 +79,7 @@ void HearthstoneAPIHandler::refresh_token_if_needed() { write_new_token_info_to_file(file_path); } else { unsigned long expire_at = std::stoull(line.substr(line.find(" ") + 1)); - if (std::chrono::duration_cast( + if (std::chrono::duration_cast( std::chrono::utc_clock::now().time_since_epoch()) .count() >= expire_at) { write_new_token_info_to_file(file_path); -- cgit v1.2.3