add colorcode stripping

fix potential infinite crash loop
This commit is contained in:
nikky 2018-05-24 03:45:17 +02:00
parent 25627c138a
commit 68144ae512
20 changed files with 103 additions and 66 deletions

View File

@ -1,6 +1,6 @@
package matterlink
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.api.ApiMessage.Companion.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

View File

@ -1,6 +1,6 @@
package matterlink
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.api.ApiMessage.Companion.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

View File

@ -1,6 +1,6 @@
package matterlink
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.api.ApiMessage.Companion.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

View File

@ -3,7 +3,7 @@ package matterlink
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.gameevent.PlayerEvent
import cpw.mods.fml.common.gameevent.TickEvent
import matterlink.api.ApiMessage.USER_ACTION
import matterlink.api.ApiMessage.Companion.USER_ACTION
import matterlink.config.cfg
import matterlink.handlers.*
import net.minecraft.command.server.CommandBroadcast

View File

@ -5,12 +5,12 @@
- [Features](#features)
- [Setup](#setup)
A MatterBridge endpoint for MC servers!
A Matterbridge endpoint for MC servers!
THIS MOD REQUIRES YOU TO ALSO RUN A MATTERBRIDGE RELAY
https://github.com/42wim/matterbridge
Chat with us on IRC: [#matterbridge @ irc.esper.net](irc://irc.esper.net/matterbridge)
Chat with us on IRC: [#matterlink @ irc.esper.net](irc://irc.esper.net/matterlink)
## Downloads
@ -20,17 +20,17 @@ Chat with us on IRC: [#matterbridge @ irc.esper.net](irc://irc.esper.net/matterb
[![Files](https://curse.nikky.moe/api/img/287323/files?logo&style=for-the-badge&version=1.12.2)](https://minecraft.curseforge.com/projects/287323/files)
[![Download](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.12.2)](https://curse.nikky.moe/api/url/287323?version=1.12.2)
[![Download 1.12.2](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.12.2)](https://curse.nikky.moe/api/url/287323?version=1.12.2)
[![Download](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.11.2)](https://curse.nikky.moe/api/url/287323?version=1.11.2)
[![Download 1.11.2](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.11.2)](https://curse.nikky.moe/api/url/287323?version=1.11.2)
[![Download](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.10.2)](https://curse.nikky.moe/api/url/287323?version=1.10.2)
[![Download 1.10.2](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.10.2)](https://curse.nikky.moe/api/url/287323?version=1.10.2)
[![Download](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.7.10)](https://curse.nikky.moe/api/url/287323?version=1.7.10)
[![Download 1.7.10](https://curse.nikky.moe/api/img/287323?logo&style=for-the-badge&version=1.7.10)](https://curse.nikky.moe/api/url/287323?version=1.7.10)
## Dependencies
[![Files](https://curse.nikky.moe/api/img/248453/files?logo&style=for-the-badge)](https://minecraft.curseforge.com/projects/248453/files)
[![Forgelin Files](https://curse.nikky.moe/api/img/248453/files?logo&style=for-the-badge)](https://minecraft.curseforge.com/projects/248453/files)
## Features
@ -96,7 +96,7 @@ Requires the matterbridge config api section to be setup along these lines:
[api.local]
BindAddress="0.0.0.0:4242" # or listen only to localhost: 127.0.0.1:4242
#OPTIONAL (no authorization if token is empty)
Token="mytoken" # leave this empty if you know its going to run on the same machine as the minecraft server
Token="mytoken" # leave this empty if you know its going to run on localhost only
Buffer=1000
RemoteNickFormat="{NICK}"
ShowJoinPart = true

2
api

@ -1 +1 @@
Subproject commit 444536373a5fa091c9254a433472971a5b5cc342
Subproject commit 063ad04b24623b28a2850eb1543ae07a2608e87a

View File

@ -1,5 +1,5 @@
plugins {
id "org.jetbrains.kotlin.jvm" version '1.2.21'
id "org.jetbrains.kotlin.jvm" version '1.2.41'
id 'idea'
}
@ -19,18 +19,16 @@ subprojects {
}
}
if (name != "core") {
repositories {
jcenter()
maven {
name = "unascribed"
url = 'http://unascribed.com/maven/releases'
}
maven {
name = "shadowfacts"
url = "http://maven.shadowfacts.net/"
}
repositories {
jcenter()
maven {
name = "unascribed"
url = 'http://unascribed.com/maven/releases'
}
maven {
name = "shadowfacts"
url = "http://maven.shadowfacts.net/"
}
}
}

View File

@ -18,7 +18,7 @@ abstract class IMatterLink {
abstract fun wrappedSendToPlayers(msg: String)
fun start() {
MessageHandlerInst.setLogger({ level, msg ->
MessageHandlerInst.logger = { level, msg ->
when (level) {
"FATAL" -> fatal(msg)
"ERROR" -> error(msg)
@ -27,7 +27,7 @@ abstract class IMatterLink {
"DEBUG" -> debug(msg)
"TRACE" -> trace(msg)
}
})
}
serverStartTime = System.currentTimeMillis()
if (cfg.connect.autoConnect)

View File

@ -1,5 +1,7 @@
package matterlink
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
import java.io.PrintWriter
import java.io.StringWriter
@ -32,6 +34,14 @@ fun String.lazyFormat(env: Map<String, () -> String>): String {
return result
}
val String.stripColor: String
get() =
if (cfg.outgoing.stripColors)
this.replace("§.".toRegex(), "")
else
this
val Exception.stackTraceString: String
get() {
val sw = StringWriter()

View File

@ -20,7 +20,9 @@ data class CustomCommand(
val alias: String
get() = BridgeCommandRegistry.getName(this)!!
@Transient private var lastUsed: Int = 0
@Transient
private var lastUsed: Int = 0
override fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean {
if (!allowArgs && args.isNotBlank()) return false
@ -30,8 +32,10 @@ data class CustomCommand(
}
if (!canExecute(userId, server)) {
MessageHandlerInst.transmit(ApiMessage()
.setText("$user is not permitted to perform command: $alias")
MessageHandlerInst.transmit(
ApiMessage(
text = "$user is not permitted to perform command: $alias"
)
)
return false
}
@ -47,8 +51,10 @@ data class CustomCommand(
commandSender.execute(cmd) || commandSender.reply.isNotBlank()
}
CommandType.RESPONSE -> {
MessageHandlerInst.transmit(ApiMessage()
.setText((response ?: "").lazyFormat(getReplacements(user, userId, server, args)))
MessageHandlerInst.transmit(
ApiMessage(
text = (response?.lazyFormat(getReplacements(user, userId, server, args)) ?: "")
)
)
true
}

View File

@ -15,8 +15,10 @@ object HelpCommand : IBridgeCommand {
"$it: ${BridgeCommandRegistry.getHelpString(it)}"
}
}
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
MessageHandlerInst.transmit(
ApiMessage(
text = msg
)
)
return true
}

View File

@ -23,8 +23,10 @@ abstract class IMinecraftCommandSender(val user: String, val userId: String, val
fun sendReply(text: String) {
reply = text
MessageHandlerInst.transmit(ApiMessage()
.setText(text)
MessageHandlerInst.transmit(
ApiMessage(
text = text
)
)
}
}

View File

@ -1,6 +1,7 @@
package matterlink.config
import matterlink.bridge.MessageHandlerInst
import matterlink.stripColor
import java.io.File
import java.util.regex.Pattern
@ -48,8 +49,9 @@ abstract class BaseConfig(rootDir: File) {
var announceConnect: Boolean = true,
var announceDisconnect: Boolean = true,
val advancements: Boolean = true,
var death: DeathOptions = DeathOptions(),
var stripColors: Boolean = true,
var death: DeathOptions = DeathOptions(),
var joinPart: JoinPartOptions = JoinPartOptions()
)
@ -223,6 +225,12 @@ abstract class BaseConfig(rootDir: File) {
category,
outgoing.announceConnect,
"announce intention to disconnect / reconnect"
),
stripColors = getBoolean(
"stripColors",
category,
outgoing.stripColors,
"strip colors from nicknames and messages"
)
)
@ -308,7 +316,6 @@ abstract class BaseConfig(rootDir: File) {
MessageHandlerInst.config.systemUser = outgoing.systemUser
MessageHandlerInst.config.announceConnect = outgoing.announceConnect
MessageHandlerInst.config.announceDisconnect = outgoing.announceDisconnect
}
abstract fun load(): BaseConfig

View File

@ -3,15 +3,16 @@ package matterlink.handlers
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.instance
import matterlink.stripColor
object ChatProcessor {
fun sendToBridge(user: String, msg: String, event: String) {
val message = msg.trim()
when {
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage()
.setUsername(user)
.setText(message)
.setEvent(event)
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage(
username = user.stripColor,
text = message.stripColor,
event = event)
)
else -> instance.warn("WARN: dropped blank message by '$user'")
}

View File

@ -4,6 +4,7 @@ import matterlink.antiping
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
import matterlink.stripColor
import java.util.*
object DeathHandler {
@ -15,16 +16,14 @@ object DeathHandler {
damageType: String
) {
if (cfg.outgoing.death.enable) {
var msg = deathMessage.replace(player, player.antiping)
var msg = deathMessage.replace(player, player.stripColor.antiping)
if (cfg.outgoing.death.damageType) {
val emojis = cfg.outgoing.death.damageTypeMapping[damageType]?.split(' ')
?: listOf("\uD83D\uDC7B unknown type '$damageType'")
val damageEmoji = emojis[random.nextInt(emojis.size)]
msg += " $damageEmoji"
}
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
)
MessageHandlerInst.transmit(ApiMessage(text = msg))
}
}
}

View File

@ -2,23 +2,26 @@ package matterlink.handlers
import matterlink.antiping
import matterlink.api.ApiMessage
import matterlink.api.ApiMessage.JOIN_LEAVE
import matterlink.api.ApiMessage.Companion.JOIN_LEAVE
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
import matterlink.mapFormat
import matterlink.stripColor
object JoinLeaveHandler {
fun handleJoin(player: String) {
if (cfg.outgoing.joinPart.enable) {
val msg = cfg.outgoing.joinPart.joinServer.mapFormat(
mapOf(
"{username}" to player,
"{username:antiping}" to player.antiping
"{username}" to player.stripColor,
"{username:antiping}" to player.stripColor.antiping
)
)
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
.setEvent(ApiMessage.JOIN_LEAVE)
MessageHandlerInst.transmit(
ApiMessage(
text = msg,
event = JOIN_LEAVE
)
)
}
}
@ -27,13 +30,15 @@ object JoinLeaveHandler {
if (cfg.outgoing.joinPart.enable) {
val msg = cfg.outgoing.joinPart.partServer.mapFormat(
mapOf(
"{username}" to player,
"{username:antiping}" to player.antiping
"{username}" to player.stripColor,
"{username:antiping}" to player.stripColor.antiping
)
)
MessageHandlerInst.transmit(ApiMessage()
.setText(msg)
.setEvent(JOIN_LEAVE)
MessageHandlerInst.transmit(
ApiMessage(
text = msg,
event = JOIN_LEAVE
)
)
}
}

View File

@ -4,14 +4,17 @@ import matterlink.antiping
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg
import matterlink.stripColor
object ProgressHandler {
fun handleProgress(name: String, message: String, display: String) {
if (!cfg.outgoing.advancements) return
val usr = name.antiping
MessageHandlerInst.transmit(ApiMessage()
.setText("$usr $message $display")
val usr = name.stripColor.antiping
MessageHandlerInst.transmit(
ApiMessage(
text = "$usr $message $display".stripColor
)
)
}
}

View File

@ -1,5 +1,7 @@
package matterlink.bridge
package matterlink.handlers
import com.sun.xml.internal.ws.util.StringUtils
import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.format
import matterlink.config.cfg
@ -15,7 +17,7 @@ object ServerChatHandler {
instance.debug("incoming: " + MessageHandlerInst.queue.toString())
val nextMessage = MessageHandlerInst.queue.poll()
if (nextMessage != null && nextMessage.gateway == cfg.connect.gateway) {
if (nextMessage.gateway == cfg.connect.gateway) {
if (!nextMessage.text.isBlank()) {
val message = when (nextMessage.event) {
"user_action" -> nextMessage.format(cfg.incoming.action)

View File

@ -108,8 +108,10 @@ class UpdateChecker : Thread() {
}
instance.warn("Mod out of date! New $version available at ${latest.downloadURL}")
MessageHandlerInst.transmit(ApiMessage()
.setText("MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}")
MessageHandlerInst.transmit(
ApiMessage(
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"
)
)
}
}

View File

@ -1,5 +1,5 @@
mod_name = MatterLink
mod_version = 1.5.9
mod_version = 1.6.0
forgelin_version = 1.6.0
curse_id = 287323
curse_release_type = beta