Implemented Discord OAuth2 authentication flow with a new Discord.cs handler and integrated it into Program.cs. Refactored authentication logic to use shared JsonSerializerOptions from LauncherConstants. Updated BashUtils with cross-platform URL opening, improved MojangAPI to use shared HttpClient, and enhanced frontend login and log handling in logged.js and login.js.
247 lines
8.1 KiB
JavaScript
247 lines
8.1 KiB
JavaScript
const buttons = document.querySelectorAll("button[frame]")
|
|
const dynmapFrame = document.querySelector("article.frame.dynmap > iframe")
|
|
const capesSelector = document.querySelector("article.capes > div.capes")
|
|
const logsContainer = document.querySelector("div.container.logs")
|
|
|
|
let viewerInstance = new skinview3d.SkinViewer({
|
|
canvas: document.getElementById("skin"),
|
|
width: 390,
|
|
height: 490,
|
|
skin: "https://yggdrasil.azures.fr/textures/texture/steve.png"
|
|
})
|
|
|
|
viewerInstance.animation = new skinview3d.IdleAnimation()
|
|
viewerInstance.animation.speed = 1
|
|
|
|
function wait(ms) {
|
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
}
|
|
|
|
function setActiveButton(frameIdentifier) {
|
|
for (const button of buttons) {
|
|
button.classList.remove("active")
|
|
if (button.getAttribute("frame") == frameIdentifier) {
|
|
button.classList.add("active")
|
|
}
|
|
}
|
|
}
|
|
|
|
function fixedTo(number, n) {
|
|
const k = Math.pow(10, n)
|
|
const result = (Math.round(number * k) / k)
|
|
return Number.isInteger(result) ? result.toFixed(2) : result
|
|
}
|
|
|
|
window.getPlayer = async function getPlayer() {
|
|
const result = await system.call("network::getPlayer")
|
|
console.log(result)
|
|
if (result.error) {
|
|
console.error("Impossible de récupéré le profil")
|
|
return null
|
|
}
|
|
return result
|
|
}
|
|
|
|
window.profile = await getPlayer()
|
|
|
|
window.refreshProfile = async function refreshProfile() {
|
|
window.profile = await getPlayer()
|
|
}
|
|
|
|
window.setting = {}
|
|
|
|
window.setting.set = async function settingSet(key, value) {
|
|
await system.call("settings::set", { key, value })
|
|
}
|
|
|
|
window.showPage = function showPage(frameIdentifier) {
|
|
showFrame(frameIdentifier)
|
|
setActiveButton(frameIdentifier)
|
|
}
|
|
|
|
window.initDynmap = async function initDynmap() {
|
|
const dynampUrl = await system.call("lentia::dynamp") || "http://azures.fr:8123/"
|
|
if (dynmapFrame.src != dynampUrl) {
|
|
dynmapFrame.src = dynampUrl
|
|
}
|
|
}
|
|
|
|
window.getRamInformation = async function getRamInformation() {
|
|
const $ram = await system.call("hardware::ram")
|
|
ram.setAttribute("max", Math.floor($ram.freeGb * 1024))
|
|
freeRam.innerText = `${$ram.totalGb} Gb`
|
|
totalRam.innerText = `${$ram.freeGb} Gb`
|
|
}
|
|
|
|
window.handleSettingsChanges = async function handleSettingsChanges(key, value) {
|
|
const span = document.querySelector(`span#${key.includes("ram") ? "currentRam" : key}`)
|
|
setting.set(key, value)
|
|
if (span) {
|
|
span.innerText = key.includes("ram") ? fixedTo(value / 1024, 2) + " G" : value
|
|
}
|
|
}
|
|
|
|
window.initSettings = async function initSettings() {
|
|
const settings = await system.call("settings::read")
|
|
ram.value = settings.ram.max
|
|
javaPath.value = settings.javaPath
|
|
currentRam.innerText = fixedTo(settings.ram.max / 1024, 2) + " G"
|
|
getRamInformation()
|
|
}
|
|
|
|
window.initSkin = async function initSkin() {
|
|
const container = document.querySelector(".skinview3d")
|
|
if (container.clientWidth === 0 || container.clientHeight === 0) {
|
|
requestAnimationFrame(initSkin)
|
|
return
|
|
}
|
|
|
|
viewerInstance = new skinview3d.SkinViewer({
|
|
canvas: document.getElementById("skin"),
|
|
width: container.clientWidth,
|
|
height: container.clientHeight,
|
|
skin: `https://yggdrasil.azures.fr/textures/${profile.skins.find(skin => skin.state == "ACTIVE").url.replace(/^\//, "")}`
|
|
})
|
|
|
|
const activeCape = window.profile.capes.find(s => s.state === "ACTIVE") || null
|
|
const capeUrl = activeCape == null ? null : `https://yggdrasil.azures.fr/textures/${activeCape.url.replace(/^\//, "")}?t=${Date.now()}`
|
|
|
|
viewerInstance.animation = new skinview3d.IdleAnimation()
|
|
viewerInstance.nameTag = profile.name
|
|
viewerInstance.zoom = 0.7
|
|
viewerInstance.loadCape(capeUrl)
|
|
|
|
|
|
const ro = new ResizeObserver(() => {
|
|
viewerInstance.width = container.clientWidth
|
|
viewerInstance.height = container.clientHeight
|
|
})
|
|
|
|
ro.observe(container)
|
|
}
|
|
|
|
window.selectSkin = async function selectSkin() {
|
|
const skin = await system.call("dialog::selectSkin")
|
|
if (!skin.success) {
|
|
return iziToast.error({ title: "Erreur", message: "Impossible d'envoyer le skin" })
|
|
}
|
|
return validateSkinSelection(skin.path)
|
|
}
|
|
|
|
window.validateSkinSelection = async function validateSkinSelection(localPath) {
|
|
const isSlim = confirm("Modèle Slim ?")
|
|
const variant = isSlim ? "slim" : "classic"
|
|
|
|
const result = await system.call("network::uploadSkin", {
|
|
path: localPath,
|
|
variant: variant
|
|
})
|
|
|
|
if (result.success && viewerInstance) {
|
|
await wait(500)
|
|
await refreshProfile()
|
|
const activeSkin = window.profile.skins.find(s => s.state === "ACTIVE")
|
|
const activeCape = window.profile.capes.find(s => s.state === "ACTIVE") || null
|
|
|
|
if (activeSkin) {
|
|
const skinUrl = `https://yggdrasil.azures.fr/textures/${activeSkin.url.replace(/^\//, "")}?t=${Date.now()}`
|
|
const capeUrl = activeCape == null ? null : `https://yggdrasil.azures.fr/textures/${activeCape.url.replace(/^\//, "")}?t=${Date.now()}`
|
|
await viewerInstance.loadSkin(skinUrl, {
|
|
model: variant.toLowerCase() === "slim" ? "slim" : "default"
|
|
})
|
|
await viewerInstance.loadCape(capeUrl)
|
|
}
|
|
}
|
|
}
|
|
|
|
window.initCapesSelector = async function initCapesSelector() {
|
|
capesSelector.innerHTML = ""
|
|
const blankCape = document.createElement("div")
|
|
blankCape.classList.add("cape")
|
|
blankCape.setAttribute("onclick", `hideCape()`)
|
|
blankCape.title = "Cacher ma cape"
|
|
capesSelector.appendChild(blankCape)
|
|
await viewerInstance.loadCape(null)
|
|
for (const cape of profile.capes) {
|
|
const $cape = document.createElement("div")
|
|
$cape.classList.add("cape")
|
|
$cape.setAttribute("title", cape.alias)
|
|
$cape.setAttribute("style", `background-image: url("https://yggdrasil.azures.fr/textures/${cape.url.replace(/^\//, "")}?t=${Date.now()}") !important;`)
|
|
$cape.setAttribute("onclick", `showCape("${cape.id}")`)
|
|
if (cape.state == "ACTIVE") {
|
|
$cape.classList.add("active")
|
|
await viewerInstance.loadCape(`https://yggdrasil.azures.fr/textures/${cape.url.replace(/^\//, "")}?t=${Date.now()}`)
|
|
}
|
|
capesSelector.appendChild($cape)
|
|
}
|
|
}
|
|
|
|
window.showCape = async function showCape(id) {
|
|
const result = await system.call("network::showCape", { capeId: id })
|
|
|
|
if (result.success) {
|
|
await refreshProfile()
|
|
await initCapesSelector()
|
|
|
|
if (typeof viewerInstance !== "undefined" && window.profile) {
|
|
const activeCape = window.profile.capes.find(c => c.state === "ACTIVE")
|
|
if (activeCape) {
|
|
const fullUrl = `https://yggdrasil.azures.fr/textures/${activeCape.url.replace(/^\//, "")}?t=${Date.now()}`
|
|
await viewerInstance.loadCape(fullUrl)
|
|
}
|
|
}
|
|
|
|
return result.data
|
|
} else {
|
|
alert("Erreur d'équipement : " + result.error)
|
|
}
|
|
}
|
|
|
|
window.hideCape = async function hideCape() {
|
|
const result = await system.call("network::hideCape")
|
|
|
|
if (result.success) {
|
|
await refreshProfile()
|
|
await initCapesSelector()
|
|
|
|
if (typeof viewerInstance !== "undefined") {
|
|
viewerInstance.loadCape(null)
|
|
}
|
|
|
|
return result.data
|
|
} else {
|
|
alert("Erreur lors du retrait : " + result.error)
|
|
}
|
|
}
|
|
|
|
window.changeUsername = async function changeUsername(newName) {
|
|
if (!newName || newName.length < 3) return alert("Pseudo trop court !");
|
|
|
|
const result = await system.call("network::changeUsername", {
|
|
username: newName
|
|
})
|
|
|
|
if (result.success) {
|
|
viewerInstance.nameTag = result.profile.name
|
|
window.profile = result.profile
|
|
} else {
|
|
alert("Erreur : " + result.error)
|
|
}
|
|
}
|
|
|
|
window.gamelog = {}
|
|
|
|
window.gamelog.put = async function put(log) {
|
|
const logElement = document.createElement("p")
|
|
logElement.innerText = log
|
|
logsContainer.appendChild(log)
|
|
}
|
|
|
|
window.gamelog.clear = async function clear() {
|
|
logsContainer.innerHTML = ""
|
|
}
|
|
|
|
await initSkin()
|
|
await initSettings()
|
|
await initCapesSelector()
|
|
showFrame("profile") |