Skip to content

Commit

Permalink
Implement auxiliary ranked match endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Feb 15, 2024
1 parent 89e7b12 commit f171a21
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 29 deletions.
2 changes: 0 additions & 2 deletions docs/pages/todo/brainstorm_now.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions hypersomnia/default_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
67 changes: 40 additions & 27 deletions src/application/setups/server/server_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/application/setups/server/server_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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<url_and_key_pair> report_ranked_match_aux_endpoints;

std::string check_ban_url = "https://hypersomnia.xyz/check_ban";
// END GEN INTROSPECTOR
};

0 comments on commit f171a21

Please sign in to comment.