summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-03-27 12:58:24 +0100
committerAotrix <[email protected]>2025-03-27 12:58:24 +0100
commit29832e3eccceb10b5e6a9b9de554e0a45f4f1fc9 (patch)
treeafa88d0e9139026572cb1c152f7fc4ba1594008c
parent31ab522fb80473676ff31f3434f4651a1a4ee1a3 (diff)
switched to std::chrono::seconds for tokens
-rw-r--r--include/hearthstoneAPIHandler.h2
-rw-r--r--resources/token_info.txt2
-rw-r--r--src/hearthstoneAPIHandler.cpp9
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::hours>(
+std::chrono::seconds HearthstoneAPIHandler::get_current_time() {
+ return std::chrono::duration_cast<std::chrono::seconds>(
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<std::chrono::hours>(
+ if (std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::utc_clock::now().time_since_epoch())
.count() >= expire_at) {
write_new_token_info_to_file(file_path);