Skip to content

Commit

Permalink
Web: parse origin parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Apr 23, 2024
1 parent 5a7be91 commit b270118
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cmake/web_shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@
}

var urlPath = window.location.pathname;
var queryString = window.location.search;
console.log("urlPath:", urlPath);
console.log("queryString:", queryString);

var Module = {
canvas: (function() {
var canvas = document.getElementById('canvas');
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');
Expand Down
6 changes: 5 additions & 1 deletion docs/pages/todo/brainstorm_now.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docs/pages/todo/todo_done.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 24 additions & 9 deletions src/cmd_line_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct cmd_line_params {
std::optional<int> 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]);
Expand All @@ -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();
Expand Down
13 changes: 12 additions & 1 deletion src/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b270118

Please sign in to comment.