From 53faad3ca663c0154cd7e8c56049ac4522cebfc1 Mon Sep 17 00:00:00 2001 From: core Date: Sat, 6 Apr 2024 16:31:29 -0400 Subject: [PATCH] config format changes, client updates --- .dockerignore | 1 + server/Dockerfile | 6 ++ server/src/main.rs | 73 ++++++++++--------- server/src/ws.rs | 2 +- .../src/components/ui/Button.svelte | 11 +++ starkingdoms-client/src/config.json | 30 ++------ starkingdoms-client/src/config.ts | 8 +- starkingdoms-client/src/pages/Home.svelte | 23 +++--- starkingdoms-client/src/pages/Play.svelte | 10 ++- 9 files changed, 85 insertions(+), 79 deletions(-) create mode 100644 .dockerignore create mode 100644 server/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..1de565933b05f74c75ff9a6520af5f9f8a5a2f1d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..1c887e7e0d8313a9afa9b472e6d39435da42bc3f --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,6 @@ +FROM rust:alpine + +WORKDIR /build +COPY .. . + +RUN cargo build --profile release-ci \ No newline at end of file diff --git a/server/src/main.rs b/server/src/main.rs index 23cb8c45b049cf64601715d645205696e2e1b938..c23ba6bf580a0d638744808785f2188b56cfe0d7 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -320,42 +320,43 @@ fn on_message( } => { // auth // plz no remove - if let Some(token) = jwt { - let key: Hmac = Hmac::new_from_slice(&app_keys.app_key).unwrap(); - let claims: UserToken = match token.verify_with_key(&key) { - Ok(c) => c, - Err(e) => { - event_queue.push(WsEvent::Send { - to: *from, - message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Token is invalid or verification failed: {e}. Please log in again, or contact StarKingdoms staff if the problem persists.") }.into(), - }); - event_queue.push(WsEvent::Close { addr: *from }); - continue; - } - }; - - if claims.permission_level < REQUIRED_PERM_LEVEL { - event_queue.push(WsEvent::Send { - to: *from, - message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Permission level {} is too low, {REQUIRED_PERM_LEVEL} is required. If your permissions were just changed, you need to log out and log back in for the change to take effect. If you believe this is a mistake, contact StarKingdoms staff.", claims.permission_level) }.into(), - }); - event_queue.push(WsEvent::Close { addr: *from }); - continue; - } - - event_queue.push(WsEvent::Send { - to: *from, - message: Packet::Message { message_type: MessageType::Server, actor: "StarKingdoms Team".to_string(), content: "Thank you for participating in the StarKingdoms private alpha! Your feedback is essential to improving the game, so please give us any feedback you have in the Discord! <3".to_string() }.into(), - }); - } else if REQUIRED_PERM_LEVEL != 0 { - event_queue.push(WsEvent::Send { - to: *from, - message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: "Authentication is required to join this server at the moment. Log in and try again, or try again later.".to_string() }.into(), - }); - event_queue.push(WsEvent::Close { addr: *from }); - continue; - } - + /* + if let Some(token) = jwt { + let key: Hmac = Hmac::new_from_slice(&app_keys.app_key).unwrap(); + let claims: UserToken = match token.verify_with_key(&key) { + Ok(c) => c, + Err(e) => { + event_queue.push(WsEvent::Send { + to: *from, + message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Token is invalid or verification failed: {e}. Please log in again, or contact StarKingdoms staff if the problem persists.") }.into(), + }); + event_queue.push(WsEvent::Close { addr: *from }); + continue; + } + }; + + if claims.permission_level < REQUIRED_PERM_LEVEL { + event_queue.push(WsEvent::Send { + to: *from, + message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: format!("Permission level {} is too low, {REQUIRED_PERM_LEVEL} is required. If your permissions were just changed, you need to log out and log back in for the change to take effect. If you believe this is a mistake, contact StarKingdoms staff.", claims.permission_level) }.into(), + }); + event_queue.push(WsEvent::Close { addr: *from }); + continue; + } + + event_queue.push(WsEvent::Send { + to: *from, + message: Packet::Message { message_type: MessageType::Server, actor: "StarKingdoms Team".to_string(), content: "Thank you for participating in the StarKingdoms private alpha! Your feedback is essential to improving the game, so please give us any feedback you have in the Discord! <3".to_string() }.into(), + }); + } else if REQUIRED_PERM_LEVEL != 0 { + event_queue.push(WsEvent::Send { + to: *from, + message: Packet::Message { message_type: MessageType::Error, actor: "SERVER".to_string(), content: "Authentication is required to join this server at the moment. Log in and try again, or try again later.".to_string() }.into(), + }); + event_queue.push(WsEvent::Close { addr: *from }); + continue; + } + */ let angle: f32 = { let mut rng = rand::thread_rng(); rng.gen::() * std::f32::consts::PI * 2. diff --git a/server/src/ws.rs b/server/src/ws.rs index 346eb8e5f6d58966de6c86121c622c78946f23be..08ca88a8fc2cd8861ca00415206a7d50b3fb8e1f 100644 --- a/server/src/ws.rs +++ b/server/src/ws.rs @@ -200,7 +200,7 @@ impl StkTungsteniteServerPlugin { if let Some(client) = clients.get_mut(addr) { match client.send(event.clone()) { Ok(_) => (), - Err(e) => error!("failed to forward event: {}", e) + Err(e) => error!("failed to forward event: {}", e), } } clients.remove(addr); diff --git a/starkingdoms-client/src/components/ui/Button.svelte b/starkingdoms-client/src/components/ui/Button.svelte index 193bc9945aee17c25cd8775551652e5a109f3d8f..d11905adf7752f743fddee8aa7f75b65b95d0d5c 100644 --- a/starkingdoms-client/src/components/ui/Button.svelte +++ b/starkingdoms-client/src/components/ui/Button.svelte @@ -15,6 +15,7 @@ on:click on:focus {style} + class:btn-disabled={disabled} class:btn-selected={selected}> @@ -54,4 +55,14 @@ @extend %standard-hover; background-color: var(--error-transparent); } + + .btn-disabled { + @extend %standard; + border: 2px solid gray; + color: rgba(205, 214, 244, 60); + } + .btn-disabled:hover { + background-color: transparent; + cursor: not-allowed; + } diff --git a/starkingdoms-client/src/config.json b/starkingdoms-client/src/config.json index d45a8c17f981febca4bdec5b70cec44a6b60fdcd..d960119e0ebfb87efa06d51a682f2ee0bc670758 100644 --- a/starkingdoms-client/src/config.json +++ b/starkingdoms-client/src/config.json @@ -1,6 +1,8 @@ { - "servers": { - "stk-prod": { + "configSerial": 2024040503, + "backplaneBaseUrl": "https://backplane.starkingdoms.io", + "environments": [ + { "name": "StarKingdoms", "clientHubUrl": "wss://starkingdoms.io/hub", "apiBaseUrl": "https://api.starkingdoms.io", @@ -8,30 +10,12 @@ "isDevelopment": false, "isPrimary": true }, - "stk-beta": { - "name": "StarKingdoms Beta", - "clientHubUrl": "wss://beta.starkingdoms.io/hub", - "apiBaseUrl": "https://api.beta.starkingdoms.io", - "isProduction": false, - "isDevelopment": false, - "isPrimary": false - }, - "stk-unstable": { - "name": "StarKingdoms Unstable", - "clientHubUrl": "wss://unstable.starkingdoms.io/hub", - "apiBaseUrl": "https://api.unstable.starkingdoms.io", - "isProduction": false, - "isDevelopment": false, - "isPrimary": false - }, - "local-dev": { + { "name": "Local (Development)", "clientHubUrl": "ws://localhost:3000/hub", "apiBaseUrl": "http://localhost:8080", "isProduction": false, - "isDevelopment": true, - "isPrimary": false + "isDevelopment": true } - }, - "backplane": "https://backplane.starkingdoms.io" + ] } diff --git a/starkingdoms-client/src/config.ts b/starkingdoms-client/src/config.ts index 076124ff1b98533978f6646133c3cda987abc32b..09d5c1a86320d7a5e15a9678806f255a0fe88762 100644 --- a/starkingdoms-client/src/config.ts +++ b/starkingdoms-client/src/config.ts @@ -6,10 +6,12 @@ const logger = createDebug("config"); const CONFIG_URL = "https://configuration.starkingdoms.io"; export interface Config { - servers: { [id: string]: ConfigServer }; - backplane: string; + configSerial: number; + backplaneBaseUrl: string; + environments: Environment[]; } -export interface ConfigServer { + +export interface Environment { name: string; clientHubUrl: string; apiBaseUrl: string; diff --git a/starkingdoms-client/src/pages/Home.svelte b/starkingdoms-client/src/pages/Home.svelte index 3bc19b21e95ecf0839de4b722092c8dcfdddfff1..8f8e09107e6f817e38c31c234d504350a9624f27 100644 --- a/starkingdoms-client/src/pages/Home.svelte +++ b/starkingdoms-client/src/pages/Home.svelte @@ -42,7 +42,7 @@ let nonprod_warning: HTMLSpanElement; - let server = ""; + let server: number = 0; let username = ""; function playGame() { @@ -51,8 +51,8 @@ function updateNonprodWarning() { if ( - config.servers[server] !== undefined && - !config.servers[server].isProduction + config.environments[server] !== undefined && + !config.environments[server].isProduction ) { nonprod_warning.classList.remove("hidden"); } else { @@ -64,8 +64,8 @@ -

- test! +

About

+ StarKingdoms is a browser game about floating through space.
@@ -86,15 +86,14 @@ on:change={updateNonprodWarning} id="select" class="select" - autocomplete="off"> - - {#each Object.entries(config.servers) as [server_id, server]} - {#if server.isDevelopment && !is_development} - - {:else} - + {#each config.environments as env, i} + {#if !(env.isDevelopment && !is_development)} + {/if} {/each} diff --git a/starkingdoms-client/src/pages/Play.svelte b/starkingdoms-client/src/pages/Play.svelte index cc99252d89be29827a8e2cc636ca6a656a92bccc..3529b64e31e2dace508b5bfd9da8c96ba39c42c3 100644 --- a/starkingdoms-client/src/pages/Play.svelte +++ b/starkingdoms-client/src/pages/Play.svelte @@ -81,10 +81,10 @@ }, 5000); return; } - let server_id = params.get("srv")!; + let server_id = Number.parseInt(params.get("srv")!); let username = params.get("username")!; - if (!Object.keys(config.servers).includes(server_id)) { + if (!config.environments[server_id]) { chatbox.addMessage( "server-error", "The selected server is currently unavailable. Redirecting to main menu in 5 seconds.", @@ -95,7 +95,7 @@ return; } - let server = config.servers[server_id]; + let server = config.environments[server_id]; await hub_connect( server.clientHubUrl, @@ -163,7 +163,9 @@ - + --