From f171a2131e7261db220c8cad7d1292efffd6defc Mon Sep 17 00:00:00 2001 From: geneotech Date: Fri, 16 Feb 2024 00:47:16 +0100 Subject: [PATCH] Implement auxiliary ranked match endpoints --- docs/pages/todo/brainstorm_now.md | 2 - hypersomnia/default_config.lua | 4 ++ .../setups/server/server_setup.cpp | 67 +++++++++++-------- src/application/setups/server/server_vars.h | 10 +++ 4 files changed, 54 insertions(+), 29 deletions(-) diff --git a/docs/pages/todo/brainstorm_now.md b/docs/pages/todo/brainstorm_now.md index a1ddcbaa3..53b27b7eb 100644 --- a/docs/pages/todo/brainstorm_now.md +++ b/docs/pages/todo/brainstorm_now.md @@ -6,8 +6,6 @@ permalink: brainstorm_now summary: That which we are brainstorming at the moment. --- -- check out the new stun server - - show enemy silhouettes in spectator - we'll have to update to the latest version of yojimbo at some point diff --git a/hypersomnia/default_config.lua b/hypersomnia/default_config.lua index 3db91bbb2..4bc69b95c 100644 --- a/hypersomnia/default_config.lua +++ b/hypersomnia/default_config.lua @@ -758,6 +758,10 @@ treat_as_music_sounds_longer_than_secs = 5, report_ranked_match_api_key = "", report_ranked_match_url = "https://hypersomnia.xyz/report_match", + report_ranked_match_aux_endpoints = { + -- { url = "example.com", api_key = "example" } + }, + check_ban_url = "" --check_ban_url = "https://hypersomnia.xyz/check_ban" }, diff --git a/src/application/setups/server/server_setup.cpp b/src/application/setups/server/server_setup.cpp index fe8920982..f23b04d81 100644 --- a/src/application/setups/server/server_setup.cpp +++ b/src/application/setups/server/server_setup.cpp @@ -704,45 +704,58 @@ void server_setup::push_match_summary_webhook(const messages::match_summary_mess void server_setup::push_report_match_webhook(const messages::match_summary_message& summary) { finalize_webhook_jobs(); - if (const auto report_webhook_url = parsed_url(private_vars.report_ranked_match_url); report_webhook_url.valid()) { - const auto server_name = get_server_name(); + auto post_to = [&](const auto& url, const auto& api_key) { + if (const auto report_webhook_url = parsed_url(url); report_webhook_url.valid()) { + const auto server_name = get_server_name(); - LOG("Reporting ranked match result to: %x", private_vars.report_ranked_match_url); + LOG("Reporting ranked match result to: %x", url); - const auto api_key = private_vars.report_ranked_match_api_key; + const auto json_body = ranked_webhooks::json_report_match( + server_name, + get_current_arena_name(), + get_current_game_mode_name(), + summary + ); - const auto json_body = ranked_webhooks::json_report_match( - server_name, - get_current_arena_name(), - get_current_game_mode_name(), - summary - ); + LOG("Match report JSON: %x", json_body); - LOG("Match report JSON: %x", json_body); + push_notification_job( + [report_webhook_url, api_key, json_body]() -> std::string { + auto http_client = httplib_utils::make_client(report_webhook_url); - push_notification_job( - [report_webhook_url, api_key, json_body]() -> std::string { - auto http_client = httplib_utils::make_client(report_webhook_url); + httplib::Headers headers; + headers.emplace("apikey", api_key); - httplib::Headers headers; - headers.emplace("apikey", api_key); + auto result = http_client->Post(report_webhook_url.location.c_str(), headers, json_body, "application/json"); - auto result = http_client->Post(report_webhook_url.location.c_str(), headers, json_body, "application/json"); + if (result) { + LOG("/report_match: %x", result->body); + } + else { + LOG("/report_match: null result."); + } - if (result) { - LOG("/report_match: %x", result->body); - } - else { - LOG("/report_match: null result."); + return ""; } + ); - return ""; - } - ); - } - else { + return true; + } + + return false; + + }; + + if (!post_to( + private_vars.report_ranked_match_url, + private_vars.report_ranked_match_api_key + )) { LOG("report_ranked_match_url was not set."); } + + for (const auto& aux_endpoint : private_vars.report_ranked_match_aux_endpoints) { + post_to(aux_endpoint.url, aux_endpoint.api_key); + } } void server_setup::push_duel_of_honor_webhook(const std::string& first, const std::string& second) { diff --git a/src/application/setups/server/server_vars.h b/src/application/setups/server/server_vars.h index 8556576bc..bd7b8cacd 100644 --- a/src/application/setups/server/server_vars.h +++ b/src/application/setups/server/server_vars.h @@ -170,6 +170,13 @@ struct server_vars { } }; +struct url_and_key_pair { + // GEN INTROSPECTOR struct url_and_key_pair + std::string url; + std::string api_key; + // END GEN INTROSPECTOR +}; + struct server_private_vars { // GEN INTROSPECTOR struct server_private_vars std::string master_rcon_password = ""; @@ -183,6 +190,9 @@ struct server_private_vars { std::string report_ranked_match_api_key = ""; std::string report_ranked_match_url = "https://hypersomnia.xyz/report_match"; + + std::vector report_ranked_match_aux_endpoints; + std::string check_ban_url = "https://hypersomnia.xyz/check_ban"; // END GEN INTROSPECTOR };