From b2701181766c32463e84496ebbcc9d83ebe6677b Mon Sep 17 00:00:00 2001 From: geneotech Date: Tue, 23 Apr 2024 15:29:30 +0200 Subject: [PATCH] Web: parse origin parameter --- cmake/web_shell.html | 4 +++- docs/pages/todo/brainstorm_now.md | 6 +++++- docs/pages/todo/todo_done.md | 1 + src/cmd_line_params.h | 33 ++++++++++++++++++++++--------- src/work.cpp | 13 +++++++++++- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/cmake/web_shell.html b/cmake/web_shell.html index 66c2fcc92..452dde382 100644 --- a/cmake/web_shell.html +++ b/cmake/web_shell.html @@ -121,7 +121,9 @@ } var urlPath = window.location.pathname; + var queryString = window.location.search; console.log("urlPath:", urlPath); + console.log("queryString:", queryString); var Module = { canvas: (function() { @@ -129,7 +131,7 @@ resizeCanvas(); // Initial canvas resize return canvas; })(), - arguments: [urlPath], + arguments: [urlPath + queryString], setStatus: function(text) { var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); var statusElement = document.getElementById('downloading-text'); diff --git a/docs/pages/todo/brainstorm_now.md b/docs/pages/todo/brainstorm_now.md index e26b88871..532d1d664 100644 --- a/docs/pages/todo/brainstorm_now.md +++ b/docs/pages/todo/brainstorm_now.md @@ -6,12 +6,16 @@ permalink: brainstorm_now summary: That which we are brainstorming at the moment. --- +- see how krunker handles tab switches, if it timeouts, if there is sound etc + +- assign random nicknames, or just ask for one + - will later take them from accounts once we have authentication + - increase timeout - host causal pl server - diagnose why web cant connect to native local servers but first add TURN servers maybe - memory problem with hyperactive space station - - fix clipoard on web - fix tip order in tutorial about fast reloads etc move it to later diff --git a/docs/pages/todo/todo_done.md b/docs/pages/todo/todo_done.md index e9ce2ca5f..9d8c07365 100644 --- a/docs/pages/todo/todo_done.md +++ b/docs/pages/todo/todo_done.md @@ -6921,3 +6921,4 @@ This will discard your redo history." - send back actual id from signalling server to the server and set it as link correctly - also set the link when connecting += origin parameter that adds a preffix to the nickname like /game/us:1&origin=hackernews it would make [hackernews] web_user1 diff --git a/src/cmd_line_params.h b/src/cmd_line_params.h index d392ef2a4..2f9bdaef3 100644 --- a/src/cmd_line_params.h +++ b/src/cmd_line_params.h @@ -63,6 +63,8 @@ struct cmd_line_params { std::optional tutorial_level; bool tutorial_challenge = false; + std::string origin; + void parse(const int argc, const char* const * const argv, const int start_i) { for (int i = start_i; i < argc; ++i) { const auto a = std::string(argv[i]); @@ -89,41 +91,54 @@ struct cmd_line_params { else if (a.size() > 1 && a[0] == '/') { /* URL location argument. */ - if (begins_with(a, "/game")) { + std::string loc; + std::string query; + + if (!typesafe_sscanf(a, "%x?%x", loc, query)) { + loc = a; + } + + if (begins_with(loc, "/game")) { std::string webrtc_id; - if (1 == typesafe_sscanf(a, "/game/%x", webrtc_id)) { + if (1 == typesafe_sscanf(loc, "/game/%x", webrtc_id)) { should_connect = true; connect_address = webrtc_id; } } - else if (begins_with(a, "/host")) { + else if (begins_with(loc, "/host")) { start_server = true; } - else if (begins_with(a, "/tutorial")) { + else if (begins_with(loc, "/tutorial")) { launch_activity = activity_type::TUTORIAL; uint32_t level = 0; std::string keyword; - if (1 == typesafe_sscanf(a, "/tutorial/%x", level)) { + if (1 == typesafe_sscanf(loc, "/tutorial/%x", level)) { tutorial_level = level; } - else if (1 == typesafe_sscanf(a, "/tutorial/%x", keyword)) { + else if (1 == typesafe_sscanf(loc, "/tutorial/%x", keyword)) { if (keyword == "challenge") { tutorial_challenge = true; } } } - else if (begins_with(a, "/menu")) { + else if (begins_with(loc, "/menu")) { launch_activity = activity_type::MAIN_MENU; } - else if (begins_with(a, "/editor")) { + else if (begins_with(loc, "/editor")) { launch_activity = activity_type::EDITOR_PROJECT_SELECTOR; } - else if (begins_with(a, "/range")) { + else if (begins_with(loc, "/range")) { launch_activity = activity_type::SHOOTING_RANGE; } + + if (!query.empty()) { + typesafe_sscanf(query, "origin=%x", origin); + } + + LOG_NVPS(a, loc, query, origin); } else if (a == "--appimage-path") { appimage_path = get_next(); diff --git a/src/work.cpp b/src/work.cpp index be851a72d..b04023bae 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -529,7 +529,18 @@ work_result work( } if (result->client.nickname.empty()) { - result->client.nickname = augs::get_user_name(); + const auto system_user_name = augs::get_user_name(); + +#if PLATFORM_WEB + if (!params.origin.empty()) { + result->client.nickname = typesafe_sprintf("[%x] %x", params.origin, system_user_name); + } + else { + result->client.nickname = system_user_name; + } +#else + result->client.nickname = system_user_name; +#endif } if (is_steam_client) {