mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
account storage
This commit is contained in:
parent
ac63265e12
commit
fd17575bf2
@ -17,8 +17,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedMapOf
|
||||
import de.bixilon.kutil.latch.AbstractLatch
|
||||
import de.bixilon.kutil.observer.DataObserver.Companion.observed
|
||||
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer
|
||||
import de.bixilon.minosoft.config.profile.storage.ProfileStorage
|
||||
import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
@ -27,6 +27,7 @@ import java.util.*
|
||||
|
||||
abstract class Account(
|
||||
val username: String,
|
||||
@get:JsonIgnore var storage: ProfileStorage?,
|
||||
) {
|
||||
abstract val id: String
|
||||
abstract val type: ResourceLocation
|
||||
@ -62,15 +63,7 @@ abstract class Account(
|
||||
}
|
||||
|
||||
fun save() {
|
||||
// ToDo: Optimize
|
||||
profiles@ for (profile in AccountProfileManager.profiles.values) {
|
||||
for ((_, account) in profile.entries) {
|
||||
if (account === this) {
|
||||
profile.storage?.invalidate()
|
||||
break@profiles
|
||||
}
|
||||
}
|
||||
}
|
||||
storage?.invalidate()
|
||||
}
|
||||
|
||||
open fun fetchKey(latch: AbstractLatch?): MinecraftPrivateKey? = null
|
||||
|
@ -21,6 +21,7 @@ import de.bixilon.kutil.latch.AbstractLatch
|
||||
import de.bixilon.kutil.latch.AbstractLatch.Companion.child
|
||||
import de.bixilon.kutil.time.TimeUtil.millis
|
||||
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
|
||||
import de.bixilon.minosoft.config.profile.storage.ProfileStorage
|
||||
import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.data.accounts.AccountStates
|
||||
import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties
|
||||
@ -39,12 +40,13 @@ import java.util.*
|
||||
|
||||
class MicrosoftAccount(
|
||||
override val uuid: UUID,
|
||||
storage: ProfileStorage?,
|
||||
username: String,
|
||||
@field:JsonProperty private var msa: MicrosoftTokens,
|
||||
@field:JsonProperty private var minecraft: MinecraftTokens,
|
||||
@field:JsonProperty var key: MinecraftPrivateKey? = null,
|
||||
override val properties: PlayerProperties?,
|
||||
) : Account(username) {
|
||||
) : Account(username, storage) {
|
||||
override val id: String = uuid.toString()
|
||||
override val type: ResourceLocation = identifier
|
||||
|
||||
|
@ -45,7 +45,7 @@ class MojangAccount(
|
||||
val email: String,
|
||||
@field:JsonProperty private var accessToken: String,
|
||||
override val properties: PlayerProperties?,
|
||||
) : Account(username) {
|
||||
) : Account(username, null) {
|
||||
@Transient
|
||||
private var refreshed: Boolean = false
|
||||
override val type: ResourceLocation get() = identifier
|
||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.accounts.types.offline
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import de.bixilon.kutil.latch.AbstractLatch
|
||||
import de.bixilon.minosoft.config.profile.storage.ProfileStorage
|
||||
import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.data.accounts.AccountStates
|
||||
import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties
|
||||
@ -23,7 +24,7 @@ import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import java.util.*
|
||||
|
||||
class OfflineAccount(username: String) : Account(username) {
|
||||
class OfflineAccount(username: String, storage: ProfileStorage?) : Account(username, storage) {
|
||||
override val id: String = username
|
||||
override val uuid: UUID = UUID("OfflinePlayer:$username".hashCode().toLong(), 0L) // ToDo
|
||||
override val type: ResourceLocation = identifier
|
||||
|
@ -78,6 +78,7 @@ class MicrosoftAddController(
|
||||
|
||||
try {
|
||||
val account = MicrosoftOAuthUtils.loginToMicrosoftAccount(response, latch)
|
||||
account.storage = profile.storage
|
||||
profile.entries[account.id] = account
|
||||
if (this.account == null) {
|
||||
profile.selected = account
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -80,9 +80,10 @@ class OfflineAddController(
|
||||
if (addButtonFX.isDisable) {
|
||||
return
|
||||
}
|
||||
val account = OfflineAccount(usernameFX.text)
|
||||
accountProfile.entries[account.id] = account
|
||||
accountProfile.selected = account
|
||||
val profile = accountProfile
|
||||
val account = OfflineAccount(usernameFX.text, profile.storage)
|
||||
profile.entries[account.id] = account
|
||||
profile.selected = account
|
||||
|
||||
accountController.refreshList()
|
||||
close()
|
||||
|
@ -58,7 +58,7 @@ object AccountManageCommand : Command {
|
||||
if (!ProtocolDefinition.MINECRAFT_NAME_VALIDATOR.matcher(name).matches()) throw CommandException("Invalid username: $name")
|
||||
val profile = AccountProfileManager.selected
|
||||
if (profile.entries.containsKey(name)) throw CommandException("Account does already exist!")
|
||||
val account = OfflineAccount(name)
|
||||
val account = OfflineAccount(name, profile.storage)
|
||||
profile.entries[account.id] = account
|
||||
profile.selected = account
|
||||
stack.print.print("Successfully created and selected offline account ${account.username}!")
|
||||
@ -72,6 +72,7 @@ object AccountManageCommand : Command {
|
||||
stack.print.print("Logging in into microsoft account...")
|
||||
val account = MicrosoftOAuthUtils.loginToMicrosoftAccount(it)
|
||||
val profile = AccountProfileManager.selected
|
||||
account.storage = profile.storage
|
||||
profile.entries[account.id] = account
|
||||
profile.selected = account
|
||||
|
||||
|
@ -147,6 +147,7 @@ object MicrosoftOAuthUtils {
|
||||
|
||||
val account = MicrosoftAccount(
|
||||
uuid = profile.uuid,
|
||||
storage = null,
|
||||
username = profile.name,
|
||||
msa = msaTokens,
|
||||
minecraft = minecraftToken,
|
||||
|
Loading…
x
Reference in New Issue
Block a user