fixed crash due to runtime constraints

This commit is contained in:
nikky 2018-07-11 00:30:09 +02:00
parent 4627a60c9d
commit 83501c867f
21 changed files with 152 additions and 99 deletions

View File

@ -48,7 +48,7 @@ object EventHandler {
user = e.player.displayName.unformattedText, user = e.player.displayName.unformattedText,
msg = e.message, msg = e.message,
event = "", event = "",
uuid = e.player.gameProfile.id.toString() uuid = e.player.gameProfile.id
) )
} }

View File

@ -65,9 +65,21 @@ object MatterLink : IMatterLink() {
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendChatMsg(TextComponentString(msg)) FMLCommonHandler.instance().minecraftServerInstance.playerList.sendChatMsg(TextComponentString(msg))
} }
override fun wrappedSendToPlayer(user: String, msg: String) { override fun wrappedSendToPlayer(username: String, msg: String) {
val profile = profileByName(user) ?: profileByUUID(user) ?: run { val profile = profileByName(username) ?: run {
error("cannot find player by name or uuid $user") error("cannot find player by name $username")
return
}
val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online")
return
}
player.sendMessage(TextComponentString(msg))
}
override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
@ -82,8 +94,8 @@ object MatterLink : IMatterLink() {
private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? = FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id) private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? = FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id)
private fun profileByUUID(uuid: String): GameProfile? = try { private fun profileByUUID(uuid: UUID): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(UUID.fromString(uuid)) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by uuid $uuid") warn("cannot find profile by uuid $uuid")
null null
@ -96,11 +108,9 @@ object MatterLink : IMatterLink() {
null null
} }
override fun nameToUUID(username: String) = profileByName(username)?.id?.toString() override fun nameToUUID(username: String): UUID? = profileByName(username)?.id
override fun uuidToName(uuid: String?): String? { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
return uuid?.let { profileByUUID(it)?.name }
}
override fun log(level: String, formatString: String, vararg data: Any) = override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO), formatString, *data) logger.log(Level.toLevel(level, Level.INFO), formatString, *data)

View File

@ -49,7 +49,7 @@ object EventHandler {
user = e.player.displayName.unformattedText, user = e.player.displayName.unformattedText,
msg = e.message, msg = e.message,
event = "", event = "",
uuid = e.player.gameProfile.id.toString() uuid = e.player.gameProfile.id
) )
} }

View File

@ -65,9 +65,21 @@ object MatterLink : IMatterLink() {
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg)) FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg))
} }
override fun wrappedSendToPlayer(user: String, msg: String) { override fun wrappedSendToPlayer(username: String, msg: String) {
val profile = profileByName(user) ?: profileByUUID(user) ?: run { val profile = profileByName(username) ?: run {
error("cannot find player by name or uuid $user") error("cannot find player by name $username")
return
}
val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online")
return
}
player.sendMessage(TextComponentString(msg))
}
override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
@ -82,8 +94,8 @@ object MatterLink : IMatterLink() {
private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? = FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id) private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? = FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id)
private fun profileByUUID(uuid: String): GameProfile? = try { private fun profileByUUID(uuid: UUID): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(UUID.fromString(uuid)) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by uuid $uuid") warn("cannot find profile by uuid $uuid")
null null
@ -96,11 +108,9 @@ object MatterLink : IMatterLink() {
null null
} }
override fun nameToUUID(username: String) = profileByName(username)?.id?.toString() override fun nameToUUID(username: String): UUID? = profileByName(username)?.id
override fun uuidToName(uuid: String?): String? { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
return uuid?.let { profileByUUID(it)?.name }
}
override fun log(level: String, formatString: String, vararg data: Any) = override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO), formatString, *data) logger.log(Level.toLevel(level, Level.INFO), formatString, *data)

View File

@ -41,7 +41,7 @@ object EventHandler {
user = e.player.displayName.unformattedText, user = e.player.displayName.unformattedText,
msg = e.message, msg = e.message,
event = "", event = "",
uuid = e.player.gameProfile.id.toString() uuid = e.player.gameProfile.id
) )
} }

View File

@ -68,9 +68,21 @@ object MatterLink : IMatterLink() {
FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg)) FMLCommonHandler.instance().minecraftServerInstance.playerList.sendMessage(TextComponentString(msg))
} }
override fun wrappedSendToPlayer(user: String, msg: String) { override fun wrappedSendToPlayer(username: String, msg: String) {
val profile = profileByName(user) ?: profileByUUID(user) ?: run { val profile = profileByName(username) ?: run {
error("cannot find player by name or uuid $user") error("cannot find player by name $username")
return
}
val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online")
return
}
player.sendMessage(TextComponentString(msg))
}
override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
@ -82,12 +94,11 @@ object MatterLink : IMatterLink() {
override fun isOnline(username: String) = FMLCommonHandler.instance().minecraftServerInstance.onlinePlayerNames.contains(username) override fun isOnline(username: String) = FMLCommonHandler.instance().minecraftServerInstance.onlinePlayerNames.contains(username)
private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? private fun playerByProfile(gameProfile: GameProfile): EntityPlayerMP? = FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id)
= FMLCommonHandler.instance().minecraftServerInstance.playerList.getPlayerByUUID(gameProfile.id)
private fun profileByUUID(uuid: String): GameProfile? = try { private fun profileByUUID(uuid: UUID): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(UUID.fromString(uuid)) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by uuid $uuid") warn("cannot find profile by uuid $uuid")
null null
@ -100,11 +111,9 @@ object MatterLink : IMatterLink() {
null null
} }
override fun nameToUUID(username: String) = profileByName(username)?.id?.toString() override fun nameToUUID(username: String): UUID? = profileByName(username)?.id
override fun uuidToName(uuid: String?): String? { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
return uuid?.let { profileByUUID(it)?.name }
}
override fun log(level: String, formatString: String, vararg data: Any) = override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO), formatString, *data) logger.log(Level.toLevel(level, Level.INFO), formatString, *data)

View File

@ -45,7 +45,7 @@ object EventHandler {
user = e.player.displayName, user = e.player.displayName,
msg = e.message, msg = e.message,
event = "", event = "",
uuid = e.player.gameProfile.id.toString() uuid = e.player.gameProfile.id
) )
} }

View File

@ -67,9 +67,21 @@ class MatterLink : IMatterLink() {
MinecraftServer.getServer().configurationManager.sendChatMsg(ChatComponentText(msg)) MinecraftServer.getServer().configurationManager.sendChatMsg(ChatComponentText(msg))
} }
override fun wrappedSendToPlayer(user: String, msg: String) { override fun wrappedSendToPlayer(username: String, msg: String) {
val profile = profileByName(user) ?: profileByUUID(user) ?: run { val profile = profileByName(username) ?: run {
error("cannot find player by name or uuid $user") error("cannot find player by name $username")
return
}
val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online")
return
}
player.addChatMessage(ChatComponentText(msg))
}
override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
@ -86,8 +98,8 @@ class MatterLink : IMatterLink() {
return FMLCommonHandler.instance().minecraftServerInstance.configurationManager.createPlayerForUser(gameProfile) return FMLCommonHandler.instance().minecraftServerInstance.configurationManager.createPlayerForUser(gameProfile)
} }
private fun profileByUUID(uuid: String): GameProfile? = try { private fun profileByUUID(uuid: UUID): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.func_152652_a(UUID.fromString(uuid)) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.func_152652_a(uuid)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by uuid $uuid") warn("cannot find profile by uuid $uuid")
null null
@ -100,11 +112,9 @@ class MatterLink : IMatterLink() {
null null
} }
override fun nameToUUID(username: String) = profileByName(username)?.id?.toString() override fun nameToUUID(username: String): UUID? = profileByName(username)?.id
override fun uuidToName(uuid: String?): String? { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
return uuid?.let { profileByUUID(it)?.name }
}
override fun log(level: String, formatString: String, vararg data: Any) = override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO), formatString, *data) logger.log(Level.toLevel(level, Level.INFO), formatString, *data)

@ -1 +1 @@
Subproject commit 9504df0618d2826aefd98db80445d5d68484b606 Subproject commit bb136c12e3ae50498b3435fc11dbd833efdb6a1c

View File

@ -6,6 +6,7 @@ import matterlink.bridge.command.IBridgeCommand
import matterlink.bridge.command.IMinecraftCommandSender import matterlink.bridge.command.IMinecraftCommandSender
import matterlink.config.cfg import matterlink.config.cfg
import matterlink.update.UpdateChecker import matterlink.update.UpdateChecker
import java.util.*
lateinit var instance: IMatterLink lateinit var instance: IMatterLink
@ -18,10 +19,11 @@ abstract class IMatterLink {
abstract fun wrappedSendToPlayers(msg: String) abstract fun wrappedSendToPlayers(msg: String)
abstract fun wrappedSendToPlayer(user: String, msg: String) abstract fun wrappedSendToPlayer(username: String, msg: String)
abstract fun wrappedSendToPlayer(uuid: UUID, msg: String)
abstract fun isOnline(username: String): Boolean abstract fun isOnline(username: String): Boolean
abstract fun nameToUUID(username: String): String? abstract fun nameToUUID(username: String): UUID?
abstract fun uuidToName(uuid: String?): String? abstract fun uuidToName(uuid: UUID): String?
fun start() { fun start() {
MessageHandlerInst.logger = { level, msg -> MessageHandlerInst.logger = { level, msg ->

View File

@ -41,27 +41,27 @@ object PasteUtil {
?: "invalid" ?: "invalid"
) )
} }
.registerSerializer { paste: Paste, marshaller: Marshaller -> // .registerSerializer { paste: Paste, marshaller: Marshaller ->
JsonObject().apply { // JsonObject().apply {
with(paste) { // with(paste) {
if (description.isNotBlank()) // if (description.isNotBlank())
this@apply["description"] = marshaller.serialize(description) // this@apply["description"] = marshaller.serialize(description)
if (encrypted) // if (encrypted)
this@apply["encrypted"] = marshaller.serialize(encrypted) // this@apply["encrypted"] = marshaller.serialize(encrypted)
this@apply["sections"] = marshaller.serialize(sections) // this@apply["sections"] = marshaller.serialize(sections)
} // }
} // }
} // }
.registerSerializer { section: PasteSection, marshaller: Marshaller -> // .registerSerializer { section: PasteSection, marshaller: Marshaller ->
JsonObject().apply { // JsonObject().apply {
with(section) { // with(section) {
if (name.isNotBlank()) // if (name.isNotBlank())
this@apply["name"] = marshaller.serialize(name) // this@apply["name"] = marshaller.serialize(name)
this@apply["syntax"] = marshaller.serialize(syntax) // this@apply["syntax"] = marshaller.serialize(syntax)
this@apply["contents"] = marshaller.serialize(contents.replace("\n", "\\n")) // this@apply["contents"] = marshaller.serialize(contents.replace("\n", "\\n"))
} // }
} // }
} // }
.build() .build()
fun paste(paste: Paste, key: String = ""): PasteResponse { fun paste(paste: Paste, key: String = ""): PasteResponse {

View File

@ -8,6 +8,7 @@ import blue.endless.jankson.impl.Marshaller
import matterlink.config.cfg import matterlink.config.cfg
import java.io.PrintWriter import java.io.PrintWriter
import java.io.StringWriter import java.io.StringWriter
import java.lang.Thread.yield
import java.util.* import java.util.*
import kotlin.streams.asSequence import kotlin.streams.asSequence
@ -62,10 +63,8 @@ val Exception.stackTraceString: String
return sw.toString() return sw.toString()
} }
fun randomString(length: Long = 6, source: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ") = Random().ints(length, 0, source.length) fun randomString(length: Int = 6): String =
.asSequence() java.util.UUID.randomUUID().toString().replace("-", "").take(length)
.map(source::get)
.joinToString("")
fun <T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T { fun <T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T {
// instance.info("type: ${default.javaClass.name} key: $key json: >>>${this.getObject(key)?.toJson()}<<< default: $default") // instance.info("type: ${default.javaClass.name} key: $key json: >>>${this.getObject(key)?.toJson()}<<< default: $default")

View File

@ -3,13 +3,14 @@ package matterlink.bridge
import matterlink.* import matterlink.*
import matterlink.api.ApiMessage import matterlink.api.ApiMessage
import matterlink.api.MessageHandler import matterlink.api.MessageHandler
import matterlink.config.cfg
object MessageHandlerInst : MessageHandler() { object MessageHandlerInst : MessageHandler() {
override fun transmit(msg: ApiMessage) { override fun transmit(msg: ApiMessage) {
transmit(msg, cause = "") transmit(msg, cause = "")
} }
fun transmit(msg: ApiMessage, cause: String, maxLines: Int = 3) { fun transmit(msg: ApiMessage, cause: String, maxLines: Int = cfg.outgoing.inlineLimit) {
if (msg.text.count { it == '\n' } >= maxLines) { if (msg.text.count { it == '\n' } >= maxLines) {
try { try {
val response = PasteUtil.paste( val response = PasteUtil.paste(
@ -19,13 +20,13 @@ object MessageHandlerInst : MessageHandler() {
PasteSection( PasteSection(
name = "log.txt", name = "log.txt",
syntax = "text", syntax = "text",
contents = msg.text contents = msg.text.replace("\n", "\\n")
) )
) )
) )
) )
msg.text = msg.text.substringBefore('\n') msg.text = msg.text.substringBefore('\n')
.take(15) + "... " + response.link .take(20) + "... " + response.link
} catch(e: Exception) { } catch(e: Exception) {
instance.error(e.stackTraceString) instance.error(e.stackTraceString)
} }

View File

@ -5,6 +5,7 @@ import matterlink.config.IdentitiesConfig
import matterlink.config.cfg import matterlink.config.cfg
import matterlink.instance import matterlink.instance
import matterlink.randomString import matterlink.randomString
import java.util.*
object AuthBridgeCommand : IBridgeCommand() { object AuthBridgeCommand : IBridgeCommand() {
val syntax = "Syntax: auth [username]" val syntax = "Syntax: auth [username]"
@ -18,9 +19,10 @@ object AuthBridgeCommand : IBridgeCommand() {
return true return true
} }
if (env.uuid != null) { val uuid = env.uuid
val name = instance.uuidToName(env.uuid) if (uuid != null) {
env.respond("you are already authenticated as name: $name uuid: ${env.uuid}") val name = instance.uuidToName(uuid)
env.respond("you are already authenticated as name: $name uuid: $uuid")
return true return true
} }
@ -34,8 +36,8 @@ object AuthBridgeCommand : IBridgeCommand() {
var targetUserName = target var targetUserName = target
val targetUUid: String = instance.nameToUUID(target) ?: run { val targetUUid: String = instance.nameToUUID(target)?.toString() ?: run {
targetUserName = instance.uuidToName(target) ?: run { targetUserName = instance.uuidToName(UUID.fromString(target)) ?: run {
env.respond("cannot find player by username/uuid $target") env.respond("cannot find player by username/uuid $target")
return true return true
} }

View File

@ -45,7 +45,7 @@ object BridgeCommandRegistry {
} ?: false } ?: false
} }
fun handleCommand(text: String, username: String, uuid: String): Boolean { fun handleCommand(text: String, username: String, uuid: UUID): Boolean {
if (!cfg.command.enable || text.isBlank()) return false if (!cfg.command.enable || text.isBlank()) return false
if (text[0] != cfg.command.prefix || text.length < 2) return false if (text[0] != cfg.command.prefix || text.length < 2) return false

View File

@ -3,7 +3,6 @@ package matterlink.bridge.command
import matterlink.instance import matterlink.instance
import matterlink.lazyFormat import matterlink.lazyFormat
import matterlink.stripColorIn import matterlink.stripColorIn
import matterlink.stripColorOut
data class CustomCommand( data class CustomCommand(
val type: CommandType = CommandType.RESPONSE, val type: CommandType = CommandType.RESPONSE,
@ -70,8 +69,8 @@ data class CustomCommand(
}, },
"{uuid}" to { "{uuid}" to {
when (env) { when (env) {
is CommandEnvironment.BridgeEnv -> env.uuid is CommandEnvironment.BridgeEnv -> env.uuid.toString()
is CommandEnvironment.GameEnv -> env.uuid is CommandEnvironment.GameEnv -> env.uuid.toString()
} }
}, },
"{username}" to { "{username}" to {

View File

@ -7,6 +7,7 @@ import matterlink.config.cfg
import matterlink.handlers.TickHandler import matterlink.handlers.TickHandler
import matterlink.instance import matterlink.instance
import matterlink.stripColorOut import matterlink.stripColorOut
import java.util.*
abstract class IBridgeCommand { abstract class IBridgeCommand {
abstract val help: String abstract val help: String
@ -14,25 +15,26 @@ abstract class IBridgeCommand {
open val timeout: Int = 20 open val timeout: Int = 20
sealed class CommandEnvironment { sealed class CommandEnvironment {
abstract val uuid: String? abstract val uuid: UUID?
abstract val username: String? abstract val username: String?
data class BridgeEnv( data class BridgeEnv(
val name: String, val name: String,
val userId: String, val userId: String,
val platform: String, val platform: String,
override val uuid: String? override val uuid: UUID?
) : CommandEnvironment() { ) : CommandEnvironment() {
override val username: String? override val username: String?
get() = instance.uuidToName(uuid) get() = uuid?.let { instance.uuidToName(uuid) }
} }
data class GameEnv( data class GameEnv(
override val username: String, override val username: String,
override val uuid: String override val uuid: UUID
) : CommandEnvironment() ) : CommandEnvironment()
fun respond(text: String, cause: String = "") { fun respond(text: String, cause: String = "") {
when(this) { when (this) {
is BridgeEnv -> { is BridgeEnv -> {
MessageHandlerInst.transmit( MessageHandlerInst.transmit(
ApiMessage( ApiMessage(
@ -69,7 +71,7 @@ abstract class IBridgeCommand {
*/ */
abstract fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean abstract fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean
fun canExecute(uuid: String?): Boolean { fun canExecute(uuid: UUID?): Boolean {
instance.trace("canExecute this: $this uuid: $uuid permLevel: $permLevel") instance.trace("canExecute this: $this uuid: $uuid permLevel: $permLevel")
val canExec = getPermLevel(uuid) >= permLevel val canExec = getPermLevel(uuid) >= permLevel
instance.trace("canExecute return $canExec") instance.trace("canExecute return $canExec")
@ -79,9 +81,9 @@ abstract class IBridgeCommand {
open fun validate() = true open fun validate() = true
companion object { companion object {
fun getPermLevel(uuid: String?): Double { fun getPermLevel(uuid: UUID?): Double {
if(uuid == null) return cfg.command.defaultPermUnauthenticated if (uuid == null) return cfg.command.defaultPermUnauthenticated
return PermissionConfig.perms[uuid] ?: cfg.command.defaultPermAuthenticated return PermissionConfig.perms[uuid.toString()] ?: cfg.command.defaultPermAuthenticated
} }
} }
} }

View File

@ -70,6 +70,7 @@ data class BaseConfig(val rootDir: File) {
val advancements: Boolean = true, val advancements: Boolean = true,
val stripColors: Boolean = true, val stripColors: Boolean = true,
val pasteEEKey: String = "", val pasteEEKey: String = "",
val inlineLimit: Int = 5,
val joinPart: JoinPartOptions = JoinPartOptions(), val joinPart: JoinPartOptions = JoinPartOptions(),
val death: DeathOptions = DeathOptions() val death: DeathOptions = DeathOptions()
@ -294,6 +295,11 @@ data class BaseConfig(val rootDir: File) {
pasteEEKey, pasteEEKey,
"paste.ee api key, leave empty to use application default" "paste.ee api key, leave empty to use application default"
), ),
inlineLimit = it.getOrDefault(
"inlineLimit",
inlineLimit,
"messages with more lines than this will get shortened via paste.ee"
),
death = it.getOrDefault( death = it.getOrDefault(
"death", "death",
DeathOptions(), DeathOptions(),
@ -386,7 +392,7 @@ data class BaseConfig(val rootDir: File) {
configFile.createNewFile() configFile.createNewFile()
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
} }
instance.info("finished loading $jsonObject") instance.info("finished loading base config")
val tmpCfg = try { val tmpCfg = try {
//cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true)) //cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true))

View File

@ -11,6 +11,7 @@ import matterlink.getOrDefault
import matterlink.instance import matterlink.instance
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
typealias IdentMap = Map<String, Map<String, List<String>>> typealias IdentMap = Map<String, Map<String, List<String>>>
@ -114,13 +115,13 @@ object IdentitiesConfig {
} }
//TODO: rewrite, store ident map differently in memory //TODO: rewrite, store ident map differently in memory
fun getUUID(platform: String, userid: String): String? { fun getUUID(platform: String, userid: String): UUID? {
return idents.entries.firstOrNull { (uuid, usermap) -> return idents.entries.firstOrNull { (uuid, usermap) ->
usermap.entries.any { (_platform, userids) -> usermap.entries.any { (_platform, userids) ->
if (platform.equals(_platform, true)) if (platform.equals(_platform, true))
instance.info("platform: $_platform userids: $userids") instance.info("platform: $_platform userids: $userids")
platform.equals(_platform, true) && userids.contains(userid) platform.equals(_platform, true) && userids.contains(userid)
} }
}?.key }?.key?.let { UUID.fromString(it) }
} }
} }

View File

@ -9,12 +9,13 @@ import matterlink.getReified
import matterlink.instance import matterlink.instance
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
typealias PermissionMap = Map<String, Double> typealias PermissionMap = Map<String, Double>
data class PermissionRequest( data class PermissionRequest(
val uuid: String, val uuid: UUID,
val user: String, val user: String,
val nonce: String, val nonce: String,
val powerlevel: Double? = null val powerlevel: Double? = null
@ -77,8 +78,8 @@ object PermissionConfig {
configFile.writeText(jsonObject.toJson(true, true)) configFile.writeText(jsonObject.toJson(true, true))
} }
fun add(uuid: String, powerlevel: Double, comment: String? = null) { fun add(uuid: UUID, powerlevel: Double, comment: String? = null) {
jsonObject.putDefault(uuid, powerlevel, comment) jsonObject.putDefault(uuid.toString(), powerlevel, comment)
load() load()
} }
} }

View File

@ -5,12 +5,13 @@ import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.command.BridgeCommandRegistry import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.instance import matterlink.instance
import matterlink.stripColorOut import matterlink.stripColorOut
import java.util.*
object ChatProcessor { object ChatProcessor {
/** /**
* @return cancel message flag * @return cancel message flag
*/ */
fun sendToBridge(user: String, msg: String, event: String, uuid: String? = null): Boolean { fun sendToBridge(user: String, msg: String, event: String, uuid: UUID? = null): Boolean {
val message = msg.trim() val message = msg.trim()
if(uuid != null && BridgeCommandRegistry.handleCommand(message, user, uuid)) return true if(uuid != null && BridgeCommandRegistry.handleCommand(message, user, uuid)) return true
when { when {