From 88095047df28ae2f712ef8c8f93a27df3cc8c0b5 Mon Sep 17 00:00:00 2001 From: AB Date: Wed, 11 Feb 2026 11:58:04 +0200 Subject: [PATCH] Fix --- k8s/games/minecraft/configmaps.yaml | 118 ++++++++++++++++++++++++++- k8s/games/minecraft/deployments.yaml | 9 +- 2 files changed, 121 insertions(+), 6 deletions(-) diff --git a/k8s/games/minecraft/configmaps.yaml b/k8s/games/minecraft/configmaps.yaml index 3419de3..26ef8ac 100644 --- a/k8s/games/minecraft/configmaps.yaml +++ b/k8s/games/minecraft/configmaps.yaml @@ -45,13 +45,24 @@ data: # Replace default Dynmap title with custom server name sub_filter 'Minecraft Dynamic Map' "Hexor's MC server"; - # Inject all custom content before closing body tag (single replacement) - sub_filter "" '

GEYMERSKIY SOYUZ Server
Get Prism Launcher and client.zip for this server. Server address minecraft.hexor.cy:30565
Requires Java 8

Windows Install Script

'; + # Inject custom script before closing body tag + sub_filter "" ''; # Apply sub_filter replacements globally (not just once) sub_filter_once off; } + # Serve inject.js and .ps1 scripts inline (no forced download) + location = /clients/inject.js { + alias /mc/clients/inject.js; + default_type application/javascript; + } + + location ~ ^/clients/(.+\.ps1)$ { + alias /mc/clients/$1; + default_type text/plain; + } + # Static file serving for client downloads location /clients/ { alias /mc/clients/; @@ -68,9 +79,110 @@ data: apiVersion: v1 kind: ConfigMap metadata: - name: win-install-script + name: client-scripts namespace: minecraft data: + inject.js: | + (function() { + function getUsername() { + var metas = document.querySelectorAll("meta"); + for (var i = 0; i < metas.length; i++) { + if (metas[i].getAttribute("name") === "remote-user") { + return metas[i].getAttribute("content"); + } + } + var jwt = document.cookie.split("; ").find(function(row) { + return row.startsWith("authentik_session="); + }); + if (jwt) { + try { + var token = jwt.split("=")[1]; + var payload = JSON.parse(atob(token.split(".")[1])); + return payload.sub || payload.username || "web-user"; + } catch(e) {} + } + return "web-user"; + } + + var username = getUsername(); + console.log("Username found:", username); + + if (username && username !== "web-user" && + window.location.search.indexOf("playername=") === -1) { + var currentUrl = new URL(window.location.href); + currentUrl.searchParams.set("playername", username); + console.log("Redirecting to:", currentUrl.href); + window.location.href = currentUrl.href; + } + + document.addEventListener("DOMContentLoaded", function() { + // User block + var userBlock = document.createElement("div"); + userBlock.style.cssText = "background-color:#CEC6CB;color:black;padding:8px;text-align:center;font-size:medium;border-radius:4px;position:absolute;top:10px;right:150px;max-width:200px;"; + userBlock.innerHTML = "Logged in as: " + username + ""; + document.body.appendChild(userBlock); + + // Info block + var infoBlock = document.createElement("p"); + infoBlock.style.cssText = "background-color:#CEC6CB;color:black;padding:10px;text-align:center;font-size:large;display:inline-block;border-radius:4px;position:absolute;top:10px;left:150px;"; + infoBlock.innerHTML = 'GEYMERSKIY SOYUZ Server
' + + 'Get Prism Launcher ' + + 'and client.zip for this server. ' + + 'Server address minecraft.hexor.cy:30565
' + + 'Requires Java 8

' + + 'Windows Install Script'; + document.body.appendChild(infoBlock); + + // Modal + var modal = document.createElement("div"); + modal.id = "installModal"; + modal.style.cssText = "display:none;position:fixed;z-index:1000;left:0;top:0;width:100%;height:100%;background-color:rgba(0,0,0,0.5);"; + modal.innerHTML = '
' + + '

Windows Installation

' + + '

Copy and paste this command into PowerShell:

' + + '' + + '

' + + '' + + '' + + '
'; + document.body.appendChild(modal); + + // Generate PowerShell command with username + function buildPsCommand() { + var d = "$"; + var q = "'"; + return d + 'f="' + d + 'env:TEMP\\mc-install.ps1"; iwr -useb https://minecraft.hexor.cy/clients/win-install.ps1 -OutFile ' + + d + 'f; & ' + d + 'f -Username ' + q + username + q + '; Remove-Item ' + d + 'f'; + } + + document.getElementById("showInstallBtn").addEventListener("click", function(e) { + e.preventDefault(); + modal.style.display = "block"; + document.getElementById("scriptCommand").value = buildPsCommand(); + }); + + document.getElementById("closeButton").addEventListener("click", function() { + modal.style.display = "none"; + }); + + document.getElementById("copyButton").addEventListener("click", function() { + var textarea = document.getElementById("scriptCommand"); + textarea.select(); + textarea.setSelectionRange(0, 99999); + document.execCommand("copy"); + var btn = document.getElementById("copyButton"); + btn.style.borderColor = "#4CAF50"; + setTimeout(function() { btn.style.borderColor = "#888"; }, 2000); + }); + + modal.addEventListener("click", function(event) { + if (event.target === modal) { + modal.style.display = "none"; + } + }); + }); + })(); + win-install.ps1: | # Game Setup Script for PrismLauncher and Minecraft Client # This script downloads and configures PrismLauncher with Hexor client diff --git a/k8s/games/minecraft/deployments.yaml b/k8s/games/minecraft/deployments.yaml index 21dca75..8e1ea28 100644 --- a/k8s/games/minecraft/deployments.yaml +++ b/k8s/games/minecraft/deployments.yaml @@ -28,9 +28,9 @@ spec: - name: nginx-config configMap: name: nginx-config - - name: win-install-script + - name: client-scripts configMap: - name: win-install-script + name: client-scripts terminationGracePeriodSeconds: 10 containers: @@ -115,9 +115,12 @@ spec: subPath: nginx.conf - name: storage mountPath: /mc - - name: win-install-script + - name: client-scripts mountPath: /mc/clients/win-install.ps1 subPath: win-install.ps1 + - name: client-scripts + mountPath: /mc/clients/inject.js + subPath: inject.js --- apiVersion: v1